org.jclouds.blobstore.BlobStore类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(161)

本文整理了Java中org.jclouds.blobstore.BlobStore类的一些代码示例,展示了BlobStore类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BlobStore类的具体详情如下:
包路径:org.jclouds.blobstore.BlobStore
类名称:BlobStore

BlobStore介绍

[英]Synchronous access to a BlobStore such as Amazon S3
[中]对BlobStore(如AmazonS3)的同步访问

代码示例

代码示例来源:origin: apache/usergrid

BlobStore blobStore = context.getBlobStore();
if ( blobStore.createContainerInLocation(null, bucketName) ) {
  logger.info( "Created bucket {}", bucketName );
BlobStore blobStore = context.getBlobStore();
BlobBuilder blobBuilder = blobStore.blobBuilder( filename )
  .payload( ephemeral )
  .contentMD5(Files.hash( ephemeral, Hashing.md5() ))
  .contentType("application/json");
Blob blob = blobBuilder.build();
final String uploadedFile = blobStore.putBlob(
  bucketName, blob, PutOptions.Builder.multipart() );

代码示例来源:origin: gaul/s3proxy

@Override
protected void after() {
  logger.debug("S3 proxy is stopping");
  try {
    s3Proxy.stop();
    BlobStore blobStore = blobStoreContext.getBlobStore();
    for (StorageMetadata metadata : blobStore.list()) {
      blobStore.deleteContainer(metadata.getName());
    }
    blobStoreContext.close();
  } catch (Exception e) {
    throw new RuntimeException("Unable to stop S3 proxy", e);
  }
  FileUtils.deleteQuietly(blobStoreLocation);
  logger.debug("S3 proxy has stopped");
}

代码示例来源:origin: apache/usergrid

.prepareOutputFileName(organization.getName(), "applications");
blobStore = context.getBlobStore();
if (!blobStore.blobExists(bucketName, expectedFileName)) {
  blobStore.deleteContainer(bucketName);
  Assert.fail("Blob does not exist: " + expectedFileName);
Blob bo = blobStore.getBlob(bucketName, expectedFileName);
Long numOfFiles = blobStore.countBlobs(bucketName);
Long numWeWant = 1L;
blobStore.deleteContainer(bucketName);
assertEquals(numOfFiles, numWeWant);
assertNotNull(bo);
blobStore.deleteContainer(bucketName);

代码示例来源:origin: apache/usergrid

.overrides(overrides).buildView(BlobStoreContext.class);
BlobStore blobStore = context.getBlobStore();
final PageSet<? extends StorageMetadata> blobStoreList = blobStore.list();
      blobStore.deleteContainer(s.getName());
    } catch ( ContainerNotFoundException cnfe ) {
      logger.warn("Attempted to delete bucket {} but it is already deleted", cnfe );

代码示例来源:origin: gaul/s3proxy

@Override
  public String call() {
    Blob nearBlob = writeStore.getBlob(containerName, nearName);
    String farETag = delegate().putBlob(containerName,
        nearBlob, options);
    return farETag;
  }
});

代码示例来源:origin: jclouds/legacy-jclouds

@Test
public void testSignPutBlobWithTime() throws Exception {
 BlobStore signPutBloblWithTime = requestsSendResponses(init());
 Blob blob = signPutBloblWithTime.blobBuilder(name).payload(text).contentType("text/plain").build();
 HttpRequest compare = putBlobWithTime();
 compare.setPayload(blob.getPayload());
 assertEquals(signPutBloblWithTime.getContext().getSigner().signPutBlob(container, blob, 3l /* seconds */),
    compare);
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test
  public void testSignRemoveUrl() throws Exception {
   String name = "hello";
   String text = "fooooooooooooooooooooooo";

   Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
   String container = getContainerName();
   try {
     view.getBlobStore().putBlob(container, blob);
     assertConsistencyAwareContainerSize(container, 1);
     HttpRequest request = view.getSigner().signRemoveBlob(container, name);
     assertEquals(request.getFilters().size(), 0);
     view.utils().http().invoke(request);
     assert !view.getBlobStore().blobExists(container, name);
   } finally {
     returnContainer(container);
   }
  }
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test(groups = { "integration", "live" })
public void testListContainer() throws InterruptedException, ExecutionException, TimeoutException {
 String containerName = getContainerName();
 try {
   add15UnderRoot(containerName);
   Set<? extends StorageMetadata> container = view.getBlobStore().list(containerName);
   assertEquals(container.size(), 15);
 } finally {
   returnContainer(containerName);
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test
public void testSignPutBlob() throws Exception {
 BlobStore signPutBlob = requestsSendResponses(init());
 Blob blob = signPutBlob.blobBuilder("name").forSigning().contentLength(2l).contentMD5(new byte[] { 0, 2, 4, 8 })
    .contentType("text/plain").expires(new Date(1000)).build();
 HttpRequest compare = putBlob();
 compare.setPayload(blob.getPayload());
 assertEquals(signPutBlob.getContext().getSigner().signPutBlob(container, blob), compare);
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test(groups = { "integration", "live" })
public void deleteObjectNoContainer() {
 try {
   view.getBlobStore().removeBlob("donb", "test");
 } catch (HttpResponseException e) {
   assertEquals(e.getResponse().getStatusCode(), 404);
 } catch (ContainerNotFoundException e) {
 }
}

代码示例来源:origin: apache/jclouds

@Test(dataProvider = "ignoreOnMacOSX")
public void testGetDirectoryBlob() throws IOException {
  blobStore.createContainerInLocation(null, CONTAINER_NAME);
  String blobKey = TestUtils.createRandomBlobKey("a/b/c/directory-", "/");
  blobStore.putBlob(CONTAINER_NAME, createDirBlob(blobKey));
  assertTrue(blobStore.blobExists(CONTAINER_NAME, blobKey));
  Blob blob = blobStore.getBlob(CONTAINER_NAME, blobKey);
  assertEquals(blob.getMetadata().getName(), blobKey, "Created blob name is different");
  assertTrue(!blobStore.blobExists(CONTAINER_NAME,
      blobKey.substring(0, blobKey.length() - 1)));
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test(groups = "live")
public void testPublicAccess() throws InterruptedException, MalformedURLException, IOException {
 final String containerName = getScratchContainerName();
 try {
   view.getBlobStore().createContainerInLocation(null, containerName, publicRead());
   assertConsistencyAwareContainerExists(containerName);
   defaultLocation = Iterables.find(view.getBlobStore().list(), new Predicate<StorageMetadata>() {
    @Override
    public boolean apply(@Nullable StorageMetadata input) {
      return input.getName().equals(containerName);
    }
   }).getLocation();
   view.getBlobStore().putBlob(containerName,
       view.getBlobStore().blobBuilder("hello").payload(TEST_STRING).build());
   assertConsistencyAwareContainerSize(containerName, 1);
   BlobMetadata metadata = view.getBlobStore().blobMetadata(containerName, "hello");
   assert metadata.getPublicUri() != null : metadata;
   assertEquals(Strings2.toStringAndClose(view.utils().http().get(metadata.getPublicUri())), TEST_STRING);
 } finally {
   // this container is now public, so we can't reuse it directly
   recycleContainer(containerName);
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test(groups = { "integration", "live" })
  public void testDuplicateCreateContainer() {
   BlobStore blobStore = view.getBlobStore();
   Location location = null;
   String container = "container";
   boolean created;

   created = blobStore.createContainerInLocation(location, container);
   assertTrue(created);

   created = blobStore.createContainerInLocation(location, container);
   assertFalse(created);
  }
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test(groups = { "integration", "live" })
public void testPutTwiceIsOkAndDoesntOverwrite() throws InterruptedException {
 String containerName = getContainerName();
 try {
   view.getBlobStore().createContainerInLocation(null, containerName);
   Blob blob = view.getBlobStore().blobBuilder("hello").payload(TEST_STRING).build();
   view.getBlobStore().putBlob(containerName, blob);
   view.getBlobStore().createContainerInLocation(null, containerName);
   assertEquals(view.getBlobStore().countBlobs(containerName), 1);
 } finally {
   returnContainer(containerName);
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test(groups = { "integration", "live" })
public void deleteObjectNotFound() throws InterruptedException {
 String container = getContainerName();
 String name = "test";
 try {
   view.getBlobStore().removeBlob(container, name);
 } finally {
   returnContainer(container);
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test(groups = { "integration", "live" })
public void testGetTwoRanges() throws InterruptedException, IOException {
 String container = getContainerName();
 try {
   String name = "apples";
   addObjectAndValidateContent(container, name);
   Blob blob = view.getBlobStore().getBlob(container, name, range(0, 5).range(6, TEST_STRING.length()));
   validateMetadata(blob.getMetadata(), container, name);
   assertEquals(getContentAsStringOrNullAndClose(blob), TEST_STRING);
 } finally {
   returnContainer(container);
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test
public void testListAllWhenOnePage() throws Exception {
 BlobStore blobStore = createMock(BlobStore.class);
 ListContainerOptions options = ListContainerOptions.NONE;
 StorageMetadata v1 = createMock(StorageMetadata.class);
 PageSet<StorageMetadata> pageSet = new PageSetImpl<StorageMetadata>(ImmutableList.of(v1), null);
 EasyMock.<PageSet<? extends StorageMetadata>> expect(blobStore.list(containerName, options)).andReturn(pageSet)
      .once();
 EasyMock.replay(blobStore);
 Iterable<StorageMetadata> iterable = BlobStores.listAll(blobStore, containerName, options);
 assertEquals(ImmutableList.copyOf(iterable), ImmutableList.of(v1));
}

代码示例来源:origin: apache/jclouds

@Test(dataProvider = "ignoreOnMacOSX")
public void testListDirectoryBlobs() {
  blobStore.createContainerInLocation(null, CONTAINER_NAME);
  checkForContainerContent(CONTAINER_NAME, null);
  Set<String> dirs = ImmutableSet.of(TestUtils.createRandomBlobKey("directory-", File.separator));
  for (String d : dirs) {
    blobStore.putBlob(CONTAINER_NAME, createDirBlob(d));
    assertTrue(blobStore.blobExists(CONTAINER_NAME, d));
  }
  checkForContainerContent(CONTAINER_NAME, dirs);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-locations-jclouds

public void testCreateListDestroyContainer() throws IOException {
  context.getBlobStore().createContainerInLocation(null, testContainerName);
  context.getBlobStore().list(testContainerName);
  PageSet<? extends StorageMetadata> ps = context.getBlobStore().list();
  assertHasItemNamed(ps, testContainerName);
  
  Blob b = context.getBlobStore().blobBuilder("my-blob-1").payload(Streams.newInputStreamWithContents("hello world")).build();
  context.getBlobStore().putBlob(testContainerName, b);
  
  Blob b2 = context.getBlobStore().getBlob(testContainerName, "my-blob-1");
  Assert.assertEquals(Streams.readFullyStringAndClose(b2.getPayload().openStream()), "hello world");
  
  context.getBlobStore().deleteContainer(testContainerName);
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test(groups = { "integration", "live" })
public void containerDoesntExist() {
 assert !view.getBlobStore().containerExists("forgetaboutit");
 assert !view.getBlobStore().containerExists("cloudcachestorefunctionalintegrationtest-first");
}

相关文章