@Test public void testPutObjectOk() throws IOException, InterruptedException, ArchiveReferentialException { WriteOrderCreator writeOrderCreator = new WriteOrderCreator( archiveReferentialRepository, readWriteQueue); BackupFileStorage backupFileStorage = new BackupFileStorage(archiveReferentialRepository, writeOrderCreator, BucketTopologyHelper.BACKUP_BUCKET, BucketTopologyHelper.BACKUP_FILE_BUCKET, temporaryFolder.newFolder().getPath()); AdminTapeResource adminTapeResource = new AdminTapeResource(backupFileStorage); InputStream backupStream = PropertiesUtils.getResourceAsStream("backup.zip"); String objectId = "2019-01-01.backup.mongoc.zip"; adminTapeResource.putObject(objectId, backupStream); Optional<TapeArchiveReferentialEntity> archiveReference = archiveReferentialRepository.find(objectId); Assertions.assertThat(archiveReference).isPresent(); Assertions.assertThat(archiveReference.get().getLocation()).isInstanceOf( TapeLibraryBuildingOnDiskArchiveStorageLocation.class); writeOrderCreator.startListener(); Thread.sleep(500); Assertions.assertThat(queueCollection.count()).isEqualTo(1); archiveReference = archiveReferentialRepository.find(objectId); Assertions.assertThat(archiveReference).isPresent(); Assertions.assertThat(archiveReference.get().getLocation()).isInstanceOf( TapeLibraryReadyOnDiskArchiveStorageLocation.class); }
@PUT @Path("/backup/{objectId:.+}") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_JSON) public Response putObject(@PathParam("objectId") String objectId, InputStream input) { final Digest digest = new Digest(VitamConfiguration.getDefaultDigestType()); try (final SizedInputStream sis = new SizedInputStream(input); final InputStream digestInputStream = digest.getDigestInputStream(sis)) { LOGGER.info("Writing backup '" + objectId); SanityChecker.checkParameter(objectId); backupFileStorage.writeFile(objectId, digestInputStream); ObjectNode response = JsonHandler.createObjectNode().put("digest", digest.digestHex()).put("size", sis.getSize()); return Response.status(Response.Status.CREATED) .entity(response) .build(); } catch (Exception exc) { LOGGER.error("Cannot create object", exc); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } finally { StreamUtils.closeSilently(input); } }
AdminTapeResource extends ApplicationStatusResource { @PUT @Path("/backup/{objectId:.+}") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_JSON) public Response putObject(@PathParam("objectId") String objectId, InputStream input) { final Digest digest = new Digest(VitamConfiguration.getDefaultDigestType()); try (final SizedInputStream sis = new SizedInputStream(input); final InputStream digestInputStream = digest.getDigestInputStream(sis)) { LOGGER.info("Writing backup '" + objectId); SanityChecker.checkParameter(objectId); backupFileStorage.writeFile(objectId, digestInputStream); ObjectNode response = JsonHandler.createObjectNode().put("digest", digest.digestHex()).put("size", sis.getSize()); return Response.status(Response.Status.CREATED) .entity(response) .build(); } catch (Exception exc) { LOGGER.error("Cannot create object", exc); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } finally { StreamUtils.closeSilently(input); } } }
AdminTapeResource extends ApplicationStatusResource { @PUT @Path("/backup/{objectId:.+}") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_JSON) public Response putObject(@PathParam("objectId") String objectId, InputStream input) { final Digest digest = new Digest(VitamConfiguration.getDefaultDigestType()); try (final SizedInputStream sis = new SizedInputStream(input); final InputStream digestInputStream = digest.getDigestInputStream(sis)) { LOGGER.info("Writing backup '" + objectId); SanityChecker.checkParameter(objectId); backupFileStorage.writeFile(objectId, digestInputStream); ObjectNode response = JsonHandler.createObjectNode().put("digest", digest.digestHex()).put("size", sis.getSize()); return Response.status(Response.Status.CREATED) .entity(response) .build(); } catch (Exception exc) { LOGGER.error("Cannot create object", exc); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } finally { StreamUtils.closeSilently(input); } } @VisibleForTesting  AdminTapeResource(BackupFileStorage backupFileStorage);  AdminTapeResource(); }
AdminTapeResource extends ApplicationStatusResource { @PUT @Path("/backup/{objectId:.+}") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_JSON) public Response putObject(@PathParam("objectId") String objectId, InputStream input) { final Digest digest = new Digest(VitamConfiguration.getDefaultDigestType()); try (final SizedInputStream sis = new SizedInputStream(input); final InputStream digestInputStream = digest.getDigestInputStream(sis)) { LOGGER.info("Writing backup '" + objectId); SanityChecker.checkParameter(objectId); backupFileStorage.writeFile(objectId, digestInputStream); ObjectNode response = JsonHandler.createObjectNode().put("digest", digest.digestHex()).put("size", sis.getSize()); return Response.status(Response.Status.CREATED) .entity(response) .build(); } catch (Exception exc) { LOGGER.error("Cannot create object", exc); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } finally { StreamUtils.closeSilently(input); } } @VisibleForTesting  AdminTapeResource(BackupFileStorage backupFileStorage);  AdminTapeResource(); @PUT @Path("/backup/{objectId:.+}") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_JSON) Response putObject(@PathParam("objectId") String objectId, InputStream input); }
AdminTapeResource extends ApplicationStatusResource { @PUT @Path("/backup/{objectId:.+}") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_JSON) public Response putObject(@PathParam("objectId") String objectId, InputStream input) { final Digest digest = new Digest(VitamConfiguration.getDefaultDigestType()); try (final SizedInputStream sis = new SizedInputStream(input); final InputStream digestInputStream = digest.getDigestInputStream(sis)) { LOGGER.info("Writing backup '" + objectId); SanityChecker.checkParameter(objectId); backupFileStorage.writeFile(objectId, digestInputStream); ObjectNode response = JsonHandler.createObjectNode().put("digest", digest.digestHex()).put("size", sis.getSize()); return Response.status(Response.Status.CREATED) .entity(response) .build(); } catch (Exception exc) { LOGGER.error("Cannot create object", exc); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } finally { StreamUtils.closeSilently(input); } } @VisibleForTesting  AdminTapeResource(BackupFileStorage backupFileStorage);  AdminTapeResource(); @PUT @Path("/backup/{objectId:.+}") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_JSON) Response putObject(@PathParam("objectId") String objectId, InputStream input);  }