@Test public void getObjectWith2SegmentsOK() throws ObjectReferentialException, IOException, ContentAddressableStorageNotFoundException, ContentAddressableStorageServerException, ArchiveReferentialException { int fileSize = 6; String tarId = "20190702131434269-84970e20-402d-4a88-b1df-ae05281ec7e6.tar"; TapeLibraryObjectReferentialId objectReferentialId = new TapeLibraryObjectReferentialId("0_object", "aeaaaaaaaafklihzablkmallwljiqoiaaaaq"); TapeLibraryTarObjectStorageLocation tarObjectStorageLocation = new TapeLibraryTarObjectStorageLocation( Arrays.asList( new TarEntryDescription( tarId, "0_object/aeaaaaaaaafklihzablkmallwljiqoiaaaaq-aeaaaaaaaafklihzabqb2allwljjpiaaaaaq-0", 2048, 3, "b551ea951724d66921f7e4991ee3b86e883921abf6a14552c73a4032cc87fa4900b2faa27d1cca5139d71a12937797cd29b589561fcc7fbb60dca460141afa65" ), new TarEntryDescription( tarId, "0_object/aeaaaaaaaafklihzablkmallwljiqoiaaaaq-aeaaaaaaaafklihzabqb2allwljjpiaaaaaq-1", 3072, 3, "2da4d0d9a4a1b2c0a27d10d6d7e92dd3e6db3b1b187e2419a044c21d5b20256cc8d87d438873837063d18ec7b6fe05a3050532611b21071ed3b736f09db905c4" ))); Optional<TapeObjectReferentialEntity> objectReferentialEntity = Optional.of(new TapeObjectReferentialEntity( objectReferentialId, fileSize, "SHA-512", "664ac614a819df2a97d2a5df57dcad91d6ec38b0fffc793e80c56b4553a14ac7a5f0bce3bb71af419b0bb8f151ad3d512867454eeb818e01818a31989c13319b", "aeaaaaaaaafklihzablkmallwljiqoiaaaaq-aeaaaaaaaafklihzabqb2allwljjpiaaaaaq", tarObjectStorageLocation, null, null)); Optional<TapeArchiveReferentialEntity> tarReferentialEntity = Optional.of( new TapeArchiveReferentialEntity(tarId, new TapeLibraryOnTapeArchiveStorageLocation("VIT002L6", 248), 5120L, "60566c5d1821190fe9d1df5a7c112ff7b9ff3aec0fbcc6b9934cbebc3f9b33ef1c0aef1c1acd2291c8adb23e6cdcd36b34a2cf9fa564e9f686ea3baf5447e222", null) ); Files.copy(PropertiesUtils.getResourcePath("tar/" + tarId), Paths.get(outputTarsPath + "/" + tarId)); when(objectReferentialRepository.find(anyString(), anyString())).thenReturn(objectReferentialEntity); when(archiveReferentialRepository.find(anyString())).thenReturn(tarReferentialEntity); ObjectContent response = tapeLibraryContentAddressableStorage.getObject("0_object", "aeaaaaaaaafklihzablkmallwljiqoiaaaaq"); assertThat(response).isNotNull(); assertThat(response.getSize()).isEqualTo(fileSize); assertThat(IOUtils.toString(response.getInputStream(), StandardCharsets.UTF_8.name())).isEqualTo("test 2"); }
@Override public ObjectContent getObject(String containerName, String objectName) throws ContentAddressableStorageNotFoundException, ContentAddressableStorageServerException { LOGGER.debug(String.format("Download object %s from container %s", objectName, containerName)); Optional<TapeObjectReferentialEntity> objectReferentialEntity; try { objectReferentialEntity = objectReferentialRepository.find(containerName, objectName); } catch (ObjectReferentialException e) { throw new ContentAddressableStorageServerException(e); } if (!objectReferentialEntity.isPresent()) { throw new ContentAddressableStorageNotFoundException( ErrorMessage.OBJECT_NOT_FOUND + containerName + "/" + objectName); } TapeLibraryObjectStorageLocation location = objectReferentialEntity.get().getLocation(); if (!(location instanceof TapeLibraryTarObjectStorageLocation)) { throw new UnsupportedOperationException("Object stored in tar. Not implemented yet"); } List<TarEntryDescription> tarEntryDescriptions = ((TapeLibraryTarObjectStorageLocation) location).getTarEntries(); if (tarEntryDescriptions == null || tarEntryDescriptions.isEmpty()) { throw new IllegalStateException("empty TAR description for object : " + containerName + "/" + objectName); } List<InputStream> inputStreams = tarEntryDescriptions.stream(). map(tarEntry -> entryInputStreamSupplier(containerName, objectName, tarEntry)) .collect(Collectors.toList()); InputStream fullInputStream = new SequenceInputStream(new Vector<>(inputStreams).elements()); try { return new ObjectContent( new ExactDigestValidatorInputStream( new ExactSizeInputStream(fullInputStream, objectReferentialEntity.get().getSize()), VitamConfiguration.getDefaultDigestType(), objectReferentialEntity.get().getDigest()) , objectReferentialEntity.get().getSize()); } catch (IOException e) { throw new ContentAddressableStorageServerException(e); } }
TapeLibraryContentAddressableStorage implements ContentAddressableStorage { @Override public ObjectContent getObject(String containerName, String objectName) throws ContentAddressableStorageNotFoundException, ContentAddressableStorageServerException { LOGGER.debug(String.format("Download object %s from container %s", objectName, containerName)); Optional<TapeObjectReferentialEntity> objectReferentialEntity; try { objectReferentialEntity = objectReferentialRepository.find(containerName, objectName); } catch (ObjectReferentialException e) { throw new ContentAddressableStorageServerException(e); } if (!objectReferentialEntity.isPresent()) { throw new ContentAddressableStorageNotFoundException( ErrorMessage.OBJECT_NOT_FOUND + containerName + "/" + objectName); } TapeLibraryObjectStorageLocation location = objectReferentialEntity.get().getLocation(); if (!(location instanceof TapeLibraryTarObjectStorageLocation)) { throw new UnsupportedOperationException("Object stored in tar. Not implemented yet"); } List<TarEntryDescription> tarEntryDescriptions = ((TapeLibraryTarObjectStorageLocation) location).getTarEntries(); if (tarEntryDescriptions == null || tarEntryDescriptions.isEmpty()) { throw new IllegalStateException("empty TAR description for object : " + containerName + "/" + objectName); } List<InputStream> inputStreams = tarEntryDescriptions.stream(). map(tarEntry -> entryInputStreamSupplier(containerName, objectName, tarEntry)) .collect(Collectors.toList()); InputStream fullInputStream = new SequenceInputStream(new Vector<>(inputStreams).elements()); try { return new ObjectContent( new ExactDigestValidatorInputStream( new ExactSizeInputStream(fullInputStream, objectReferentialEntity.get().getSize()), VitamConfiguration.getDefaultDigestType(), objectReferentialEntity.get().getDigest()) , objectReferentialEntity.get().getSize()); } catch (IOException e) { throw new ContentAddressableStorageServerException(e); } } }
TapeLibraryContentAddressableStorage implements ContentAddressableStorage { @Override public ObjectContent getObject(String containerName, String objectName) throws ContentAddressableStorageNotFoundException, ContentAddressableStorageServerException { LOGGER.debug(String.format("Download object %s from container %s", objectName, containerName)); Optional<TapeObjectReferentialEntity> objectReferentialEntity; try { objectReferentialEntity = objectReferentialRepository.find(containerName, objectName); } catch (ObjectReferentialException e) { throw new ContentAddressableStorageServerException(e); } if (!objectReferentialEntity.isPresent()) { throw new ContentAddressableStorageNotFoundException( ErrorMessage.OBJECT_NOT_FOUND + containerName + "/" + objectName); } TapeLibraryObjectStorageLocation location = objectReferentialEntity.get().getLocation(); if (!(location instanceof TapeLibraryTarObjectStorageLocation)) { throw new UnsupportedOperationException("Object stored in tar. Not implemented yet"); } List<TarEntryDescription> tarEntryDescriptions = ((TapeLibraryTarObjectStorageLocation) location).getTarEntries(); if (tarEntryDescriptions == null || tarEntryDescriptions.isEmpty()) { throw new IllegalStateException("empty TAR description for object : " + containerName + "/" + objectName); } List<InputStream> inputStreams = tarEntryDescriptions.stream(). map(tarEntry -> entryInputStreamSupplier(containerName, objectName, tarEntry)) .collect(Collectors.toList()); InputStream fullInputStream = new SequenceInputStream(new Vector<>(inputStreams).elements()); try { return new ObjectContent( new ExactDigestValidatorInputStream( new ExactSizeInputStream(fullInputStream, objectReferentialEntity.get().getSize()), VitamConfiguration.getDefaultDigestType(), objectReferentialEntity.get().getDigest()) , objectReferentialEntity.get().getSize()); } catch (IOException e) { throw new ContentAddressableStorageServerException(e); } } TapeLibraryContentAddressableStorage(
        BasicFileStorage basicFileStorage,
        ObjectReferentialRepository objectReferentialRepository,
        ArchiveReferentialRepository archiveReferentialRepository,
        ReadRequestReferentialRepository readRequestReferentialRepository,
        FileBucketTarCreatorManager fileBucketTarCreatorManager,
        QueueRepository readWriteQueue, TapeCatalogService tapeCatalogService,
        String outputTarStorageFolder,
        ArchiveOutputRetentionPolicy archiveOutputRetentionPolicy); }
TapeLibraryContentAddressableStorage implements ContentAddressableStorage { @Override public ObjectContent getObject(String containerName, String objectName) throws ContentAddressableStorageNotFoundException, ContentAddressableStorageServerException { LOGGER.debug(String.format("Download object %s from container %s", objectName, containerName)); Optional<TapeObjectReferentialEntity> objectReferentialEntity; try { objectReferentialEntity = objectReferentialRepository.find(containerName, objectName); } catch (ObjectReferentialException e) { throw new ContentAddressableStorageServerException(e); } if (!objectReferentialEntity.isPresent()) { throw new ContentAddressableStorageNotFoundException( ErrorMessage.OBJECT_NOT_FOUND + containerName + "/" + objectName); } TapeLibraryObjectStorageLocation location = objectReferentialEntity.get().getLocation(); if (!(location instanceof TapeLibraryTarObjectStorageLocation)) { throw new UnsupportedOperationException("Object stored in tar. Not implemented yet"); } List<TarEntryDescription> tarEntryDescriptions = ((TapeLibraryTarObjectStorageLocation) location).getTarEntries(); if (tarEntryDescriptions == null || tarEntryDescriptions.isEmpty()) { throw new IllegalStateException("empty TAR description for object : " + containerName + "/" + objectName); } List<InputStream> inputStreams = tarEntryDescriptions.stream(). map(tarEntry -> entryInputStreamSupplier(containerName, objectName, tarEntry)) .collect(Collectors.toList()); InputStream fullInputStream = new SequenceInputStream(new Vector<>(inputStreams).elements()); try { return new ObjectContent( new ExactDigestValidatorInputStream( new ExactSizeInputStream(fullInputStream, objectReferentialEntity.get().getSize()), VitamConfiguration.getDefaultDigestType(), objectReferentialEntity.get().getDigest()) , objectReferentialEntity.get().getSize()); } catch (IOException e) { throw new ContentAddressableStorageServerException(e); } } TapeLibraryContentAddressableStorage(
        BasicFileStorage basicFileStorage,
        ObjectReferentialRepository objectReferentialRepository,
        ArchiveReferentialRepository archiveReferentialRepository,
        ReadRequestReferentialRepository readRequestReferentialRepository,
        FileBucketTarCreatorManager fileBucketTarCreatorManager,
        QueueRepository readWriteQueue, TapeCatalogService tapeCatalogService,
        String outputTarStorageFolder,
        ArchiveOutputRetentionPolicy archiveOutputRetentionPolicy); @Override void createContainer(String containerName); @Override boolean isExistingContainer(String containerName); @Override String putObject(String containerName, String objectName, InputStream stream, DigestType digestType,
        Long size); @Override ObjectContent getObject(String containerName, String objectName); @Override String createReadOrderRequest(String containerName, List<String> objectsIds); @Override void removeReadOrderRequest(String readRequestID); @Override void deleteObject(String containerName, String objectName); @Override boolean isExistingObject(String containerName, String objectName); @Override String getObjectDigest(String containerName, String objectName, DigestType algo, boolean noCache); @Override ContainerInformation getContainerInformation(String containerName); @Override MetadatasObject getObjectMetadata(String containerName, String objectName, boolean noCache); @Override void listContainer(String containerName, ObjectListingListener objectListingListener); @Override void close(); }
TapeLibraryContentAddressableStorage implements ContentAddressableStorage { @Override public ObjectContent getObject(String containerName, String objectName) throws ContentAddressableStorageNotFoundException, ContentAddressableStorageServerException { LOGGER.debug(String.format("Download object %s from container %s", objectName, containerName)); Optional<TapeObjectReferentialEntity> objectReferentialEntity; try { objectReferentialEntity = objectReferentialRepository.find(containerName, objectName); } catch (ObjectReferentialException e) { throw new ContentAddressableStorageServerException(e); } if (!objectReferentialEntity.isPresent()) { throw new ContentAddressableStorageNotFoundException( ErrorMessage.OBJECT_NOT_FOUND + containerName + "/" + objectName); } TapeLibraryObjectStorageLocation location = objectReferentialEntity.get().getLocation(); if (!(location instanceof TapeLibraryTarObjectStorageLocation)) { throw new UnsupportedOperationException("Object stored in tar. Not implemented yet"); } List<TarEntryDescription> tarEntryDescriptions = ((TapeLibraryTarObjectStorageLocation) location).getTarEntries(); if (tarEntryDescriptions == null || tarEntryDescriptions.isEmpty()) { throw new IllegalStateException("empty TAR description for object : " + containerName + "/" + objectName); } List<InputStream> inputStreams = tarEntryDescriptions.stream(). map(tarEntry -> entryInputStreamSupplier(containerName, objectName, tarEntry)) .collect(Collectors.toList()); InputStream fullInputStream = new SequenceInputStream(new Vector<>(inputStreams).elements()); try { return new ObjectContent( new ExactDigestValidatorInputStream( new ExactSizeInputStream(fullInputStream, objectReferentialEntity.get().getSize()), VitamConfiguration.getDefaultDigestType(), objectReferentialEntity.get().getDigest()) , objectReferentialEntity.get().getSize()); } catch (IOException e) { throw new ContentAddressableStorageServerException(e); } } TapeLibraryContentAddressableStorage(
        BasicFileStorage basicFileStorage,
        ObjectReferentialRepository objectReferentialRepository,
        ArchiveReferentialRepository archiveReferentialRepository,
        ReadRequestReferentialRepository readRequestReferentialRepository,
        FileBucketTarCreatorManager fileBucketTarCreatorManager,
        QueueRepository readWriteQueue, TapeCatalogService tapeCatalogService,
        String outputTarStorageFolder,
        ArchiveOutputRetentionPolicy archiveOutputRetentionPolicy); @Override void createContainer(String containerName); @Override boolean isExistingContainer(String containerName); @Override String putObject(String containerName, String objectName, InputStream stream, DigestType digestType,
        Long size); @Override ObjectContent getObject(String containerName, String objectName); @Override String createReadOrderRequest(String containerName, List<String> objectsIds); @Override void removeReadOrderRequest(String readRequestID); @Override void deleteObject(String containerName, String objectName); @Override boolean isExistingObject(String containerName, String objectName); @Override String getObjectDigest(String containerName, String objectName, DigestType algo, boolean noCache); @Override ContainerInformation getContainerInformation(String containerName); @Override MetadatasObject getObjectMetadata(String containerName, String objectName, boolean noCache); @Override void listContainer(String containerName, ObjectListingListener objectListingListener); @Override void close();  }