@Before public void beforeRunningTestMethod() throws IOException { // Create a bucket and transfer object to BP using ObjectInputStreamBuilder HELPERS.ensureBucketExists(BUCKET_NAME, envDataPolicyId); final Ds3Object obj = new Ds3Object(OBJ_NAME, OBJ_BYTES.length); final Ds3ClientHelpers.Job job = HELPERS.startWriteJob(BUCKET_NAME, Lists.newArrayList(obj)); job.transfer( new ObjectInputStreamBuilder() { @Override public InputStream buildInputStream(final String key) { return new ByteArrayInputStream(OBJ_BYTES); } }); }
private String clearObjects() throws SignatureException, SSLSetupException, CommandException { // TODO when the multi object delete command has been added to DS3 // Get the list of objects from the bucket LOG.debug("Deleting objects in bucket first"); final Ds3Client client = getClient(); final Ds3ClientHelpers helper = Ds3ClientHelpers.wrap(client); try { final Iterable<Contents> fileList = helper.listObjects(bucketName); client.deleteObjects(new DeleteObjectsRequest(bucketName, fileList)); LOG.debug("Deleting bucket"); getClient().deleteBucket(new DeleteBucketRequest(bucketName)); } catch (final IOException e) { throw new CommandException( "Error: Request failed with the following error: " + e.getMessage(), e); } return "Success: Deleted " + bucketName + " and all the objects contained in it."; }
public static void main(final String[] args) { try { final Arguments arguments = new Arguments(args); // turn root log wide open, filters will be set to argument levels configureLogging(arguments.getConsoleLogLevel(), arguments.getFileLogLevel()); LOG.info("Version: {}", arguments.getVersion()); LOG.info("Command line args: {}", Joiner.on(", ").join(args)); LOG.info("Console log level: {}", arguments.getConsoleLogLevel().toString()); LOG.info("Log file log level: {}", arguments.getFileLogLevel().toString()); LOG.info(CliCommand.getPlatformInformation()); LOG.info(arguments.getArgumentLog()); if (arguments.isHelp()) { // no need to connect to vend help final Ds3Cli runner = new Ds3Cli(null, arguments, null); final CommandResponse response = runner.getCommandHelp(); System.out.println(response.getMessage()); System.exit(response.getReturnCode()); } final Ds3Client client = createClient(arguments); if (!Utils.isVersionSupported(client)) { System.out.println( String.format( "ERROR: Minimum Black Pearl supported is %s", Utils.MINIMUM_VERSION_SUPPORTED)); System.exit(2); } final Ds3Provider provider = new Ds3ProviderImpl(client, Ds3ClientHelpers.wrap(client)); final FileUtils fileUtils = new FileUtilsImpl(); final Ds3Cli runner = new Ds3Cli(provider, arguments, fileUtils); final CommandResponse response = runner.call(); System.out.println(response.getMessage()); System.exit(response.getReturnCode()); } catch (final FailedRequestException e) { System.out.println("ERROR: " + e.getMessage()); LOG.info("Stack trace: ", e); LOG.info("Printing out the response from the server:"); LOG.info(e.getResponseString()); System.exit(2); } catch (final Exception e) { System.out.println("ERROR: " + e.getMessage()); LOG.info("Stack trace: ", e); System.exit(2); } }
@Test public void objectOutputStreamBuilder_Test() throws IOException, URISyntaxException { // Retrieve the object on the BP using ObjectOutputStreamBuilder and verify contents final Ds3Object obj = new Ds3Object(OBJ_NAME, OBJ_BYTES.length); final Ds3ClientHelpers.Job job = HELPERS.startReadJob(BUCKET_NAME, Lists.newArrayList(obj)); final ByteArrayOutputStream stream = new ByteArrayOutputStream(); job.transfer( new ObjectOutputStreamBuilder() { @Override public OutputStream buildOutputStream(final String key) throws IOException { return stream; } }); assertThat(stream.toByteArray(), is(OBJ_BYTES)); }
public class ObjectStreamBuilder_Test { private static final Ds3Client client = Util.fromEnv(); private static final Ds3ClientHelpers HELPERS = Ds3ClientHelpers.wrap(client); private static final String TEST_ENV_NAME = "object_stream_builder_test"; private static final String BUCKET_NAME = "object_stream_builder_bucket"; private static final String OBJ_NAME = "stream_object_test.txt"; private static final String OBJ_CONTENT = "Content of stream object"; private static final byte[] OBJ_BYTES = OBJ_CONTENT.getBytes(); private static TempStorageIds envStorageIds; private static UUID envDataPolicyId; @BeforeClass public static void startup() throws IOException { envDataPolicyId = TempStorageUtil.setupDataPolicy(TEST_ENV_NAME, false, ChecksumType.Type.MD5, client); envStorageIds = TempStorageUtil.setup(TEST_ENV_NAME, envDataPolicyId, client); } @AfterClass public static void teardown() throws IOException { TempStorageUtil.teardown(TEST_ENV_NAME, envStorageIds, client); client.close(); } @Before public void beforeRunningTestMethod() throws IOException { // Create a bucket and transfer object to BP using ObjectInputStreamBuilder HELPERS.ensureBucketExists(BUCKET_NAME, envDataPolicyId); final Ds3Object obj = new Ds3Object(OBJ_NAME, OBJ_BYTES.length); final Ds3ClientHelpers.Job job = HELPERS.startWriteJob(BUCKET_NAME, Lists.newArrayList(obj)); job.transfer( new ObjectInputStreamBuilder() { @Override public InputStream buildInputStream(final String key) { return new ByteArrayInputStream(OBJ_BYTES); } }); } @After public void afterRunningTestMethod() throws IOException { deleteAllContents(client, BUCKET_NAME); } @Test public void objectInputStreamBuilder_Test() throws IOException, URISyntaxException { // Verify that the object was transferred correctly to the BP in beforeRunningTestMethod final GetObjectDetailsSpectraS3Request objectDetailsRequest = new GetObjectDetailsSpectraS3Request(OBJ_NAME, BUCKET_NAME); final GetObjectDetailsSpectraS3Response objectDetailsResponse = client.getObjectDetailsSpectraS3(objectDetailsRequest); assertThat(objectDetailsResponse.getS3ObjectResult().getName(), is(OBJ_NAME)); } @Test public void objectOutputStreamBuilder_Test() throws IOException, URISyntaxException { // Retrieve the object on the BP using ObjectOutputStreamBuilder and verify contents final Ds3Object obj = new Ds3Object(OBJ_NAME, OBJ_BYTES.length); final Ds3ClientHelpers.Job job = HELPERS.startReadJob(BUCKET_NAME, Lists.newArrayList(obj)); final ByteArrayOutputStream stream = new ByteArrayOutputStream(); job.transfer( new ObjectOutputStreamBuilder() { @Override public OutputStream buildOutputStream(final String key) throws IOException { return stream; } }); assertThat(stream.toByteArray(), is(OBJ_BYTES)); } }