예제 #1
0
 public void execute(String containerName, String directory) {
   Blob blob = connection.newBlob(directory + directorySuffix);
   blob.setPayload(Payloads.newByteArrayPayload(new byte[] {}));
   blob.getPayload().setContentType("application/directory");
   blob.getMetadata().setType(StorageType.RELATIVE_PATH);
   connection.putBlob(containerName, blob);
 }
예제 #2
0
  /** http://code.google.com/p/jclouds/issues/detail?id=992 */
  public void testUseBucketWithUpperCaseName() throws Exception {
    String bucketName = CONTAINER_PREFIX + "-TestBucket";
    String blobName = "TestBlob.txt";
    StorageMetadata container = null;
    BlobStore store = view.getBlobStore();

    // Create and use a valid bucket name with uppercase characters in the bucket name (US regions
    // only)
    try {
      store.createContainerInLocation(null, bucketName);

      for (StorageMetadata metadata : store.list()) {
        if (metadata.getName().equals(bucketName)) {
          container = metadata;
          break;
        }
      }

      assertNotNull(container);

      store.putBlob(
          bucketName,
          store.blobBuilder(blobName).payload("This is a test!").contentType("text/plain").build());

      assertNotNull(store.getBlob(bucketName, blobName));
    } finally {
      if (container != null) {
        store.deleteContainer(bucketName);
      }
    }

    // Try to create the same bucket successfully created above in one of the non-US regions to
    // ensure an error is
    // encountered as expected.
    Location location = null;

    for (Location pLocation : store.listAssignableLocations()) {
      if (!ImmutableSet.of(Region.US_STANDARD, Region.US_EAST_1, Region.US_WEST_1, Region.US_WEST_2)
          .contains(pLocation.getId())) {
        location = pLocation;
        break;
      }
    }

    try {
      store.createContainerInLocation(location, bucketName);
      fail("Should had failed because in non-US regions, mixed-case bucket names are invalid.");
    } catch (AWSResponseException e) {
      assertEquals("InvalidBucketName", e.getError().getCode());
    }
  }
  /** Create a blob with putBlob method */
  private void putBlobAndCheckIt(String blobKey) {
    Blob blob;

    TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + blobKey, false);

    // create the blob
    blob = createBlob(blobKey, TestUtils.getImageForBlobPayload());
    String eTag = blobStore.putBlob(CONTAINER_NAME, blob);
    assertNotNull(eTag, "putBlob result null");
    assertNotSame(eTag, "", "putBlob result empty");

    // checks if the blob exists
    TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + blobKey, true);
  }
  @Test
  void testToBlob() {
    assertNull(ToBlob.INSTANCE.apply(null));
    BlobStore blobStore = getBlobStore();
    blobStore.createContainerInLocation(null, "container");
    blobStore.createDirectory("container", "one");

    blobStore.putBlob(
        "container",
        blobStore.blobBuilder("myblob").payload(ByteSource.wrap("testcontent".getBytes())).build());
    Blob representation = ToBlob.INSTANCE.apply(blobStore.getBlob("container", "myblob"));
    assertNotNull(representation);
    assertNotNull(representation.getBlobMetadata());
  }
  /**
   * Upload a large object from a File using the BlobStore API.
   *
   * @throws ExecutionException
   * @throws InterruptedException
   */
  private void uploadLargeObjectFromFile(File largeFile)
      throws InterruptedException, ExecutionException {
    System.out.format("Upload Large Object From File%n");

    ByteSource source = Files.asByteSource(largeFile);
    // create the payload and set the content length
    Payload payload = Payloads.newByteSourcePayload(source);
    payload.getContentMetadata().setContentLength(largeFile.length());

    Blob blob = blobStore.blobBuilder(largeFile.getName()).payload(payload).build();

    // configure the blobstore to use multipart uploading of the file
    String eTag = blobStore.putBlob(CONTAINER, blob, multipart());

    System.out.format("  Uploaded %s eTag=%s", largeFile.getName(), eTag);
  }
예제 #6
0
  public void testMultipartChunkedFileStream() throws IOException, InterruptedException {

    File file = new File("target/const.txt");
    Files.copy(oneHundredOneConstitutions, file);
    String containerName = getContainerName();

    try {
      BlobStore blobStore = view.getBlobStore();
      blobStore.createContainerInLocation(null, containerName);
      Blob blob = blobStore.blobBuilder("const.txt").payload(file).build();
      blobStore.putBlob(containerName, blob, PutOptions.Builder.multipart());

    } finally {
      returnContainer(containerName);
    }
  }
예제 #7
0
  public void testPutWithReducedRedundancyStorage() throws InterruptedException {
    String containerName = getContainerName();
    try {
      String blobName = "test-rrs";
      BlobStore blobStore = view.getBlobStore();
      blobStore.createContainerInLocation(null, containerName);

      Blob blob = blobStore.blobBuilder(blobName).payload("something").build();
      blobStore.putBlob(containerName, blob, storageClass(StorageClass.REDUCED_REDUNDANCY));

      S3Client s3Client = S3Client.class.cast(view.unwrap(AWSS3ApiMetadata.CONTEXT_TOKEN).getApi());
      ListBucketResponse response = s3Client.listBucket(containerName, withPrefix(blobName));

      ObjectMetadata metadata = response.iterator().next();
      assertEquals(metadata.getStorageClass(), StorageClass.REDUCED_REDUNDANCY);

    } finally {
      returnContainer(containerName);
    }
  }
  public void testRanges() throws IOException {
    blobStore.createContainerInLocation(null, CONTAINER_NAME);
    String input = "abcdefgh";
    Payload payload;
    Blob blob = blobStore.blobBuilder("test").payload(new StringPayload(input)).build();
    blobStore.putBlob(CONTAINER_NAME, blob);

    GetOptions getOptionsRangeStartAt = new GetOptions();
    getOptionsRangeStartAt.startAt(1);
    Blob blobRangeStartAt =
        blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeStartAt);
    payload = blobRangeStartAt.getPayload();
    try {
      assertEquals(input.substring(1), Strings2.toString(payload));
    } finally {
      Closeables.closeQuietly(payload);
    }

    GetOptions getOptionsRangeTail = new GetOptions();
    getOptionsRangeTail.tail(3);
    Blob blobRangeTail =
        blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeTail);
    payload = blobRangeTail.getPayload();
    try {
      assertEquals(input.substring(5), Strings2.toString(payload));
    } finally {
      Closeables.closeQuietly(payload);
    }

    GetOptions getOptionsFragment = new GetOptions();
    getOptionsFragment.range(4, 6);
    Blob blobFragment =
        blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsFragment);
    payload = blobFragment.getPayload();
    try {
      assertEquals(input.substring(4, 7), Strings2.toString(payload));
    } finally {
      Closeables.closeQuietly(payload);
    }
  }
 private void uploadSinglePart(BlobStore blobStore, String container, String storagePath) {
   Blob blob = blobStore.blobBuilder(storagePath).payload(createPayload()).build();
   blobStore.putBlob(container, blob);
 }