Examples of BlobStoreContext


Examples of org.jclouds.blobstore.BlobStoreContext

    {
        File file = new File(filename);
        String container = getContainer(config);
        String provider = getProvider(config);
        String blobName = System.nanoTime() + "/" + file.getName();
        BlobStoreContext context = getContext(config, spec);
        try
        {
            InputStreamMap map = context.createInputStreamMap(container);
            map.putFile(blobName, file);
            // TODO: magic! in order to expose the blob as public, we need to dive into provider specific APIs
            // the hope is that permissions are encapsulated in jclouds in the future
            if (provider.equals("s3"))
            {
                S3Client sss = context.<S3Client,S3AsyncClient>getProviderSpecificContext().getApi();
                String ownerId = sss.getObjectACL(container, blobName).getOwner().getId();
                sss.putObjectACL(container,
                                 blobName,
                                 AccessControlList.fromCannedAccessPolicy(CannedAccessPolicy.PUBLIC_READ, ownerId));
            }
            else
                LOG.warn(provider + " may not be properly supported for tarball transfer.");
            // resolve the full URI of the blob (see http://code.google.com/p/jclouds/issues/detail?id=431)
            BlobMetadata blob = context.getBlobStore().blobMetadata(container, blobName);
            URI uri = context.getProviderSpecificContext().getEndpoint().resolve("/" + container + "/" + blob.getName());
            return new Pair<BlobMetadata, URI>(blob, uri);
        }
        finally
        {
            context.close();
        }
    }
View Full Code Here

Examples of org.jclouds.blobstore.BlobStoreContext

    }

    public static void deleteBlob(Configuration config, ClusterSpec spec, BlobMetadata blob)
    {
        String container = getContainer(config);
        BlobStoreContext context = getContext(config, spec);
        try
        {
            context.getBlobStore().removeBlob(container, blob.getName());
        }
        finally
        {
            context.close();
        }
    }
View Full Code Here

Examples of org.jclouds.blobstore.BlobStoreContext

        }
    }

    private BlobStore createBlobStore(String providerOrApi, String identity, String credential, Iterable<? extends Module> modules, Properties props) {
        ContextBuilder builder = ContextBuilder.newBuilder(providerOrApi).credentials(identity, credential).modules(modules).overrides(props);
        BlobStoreContext context = builder.build(BlobStoreContext.class);
        BlobStore blobStore = context.getBlobStore();
        return blobStore;
    }
View Full Code Here

Examples of org.jclouds.blobstore.BlobStoreContext

     * Strategy to perform any pre setup, before {@link org.apache.camel.CamelContext} is created
     */
    @Override
    protected void doPreSetup() throws Exception {
        BlobStoreContextFactory contextFactory = new BlobStoreContextFactory();
        BlobStoreContext blobStoreContext = contextFactory.createContext("transient", "identity", "credential");
        BlobStore blobStore = blobStoreContext.getBlobStore();
        blobStore.createContainerInLocation(null, TEST_CONTAINER);
        blobStore.clearContainer(TEST_CONTAINER);
    }
View Full Code Here

Examples of org.jclouds.blobstore.BlobStoreContext

    }
  }

  public String initSession() throws StorageCloudException {
    try{
    BlobStoreContext context = (BlobStoreContext) ContextBuilder.newBuilder("azureblob")
        .credentials(accessKey, secretKey)
        .buildView(BlobStoreContext.class);
    storage = context.getBlobStore();
    storage.createContainerInLocation(null, bucketname);
    }catch(Exception e){
      System.out.println("Cannot connect with Windows Azure.");
      //e.printStackTrace();
      throw new StorageCloudException(StorageCloudException.INVALID_SESSION);
View Full Code Here

Examples of org.jclouds.blobstore.BlobStoreContext

  public String initSession() throws StorageCloudException {

    try{
      String location = "cloudfiles-uk";
      BlobStoreContext context = (BlobStoreContext) ContextBuilder.newBuilder(location)
          .credentials(accessKey, secretKey)
          .buildView(BlobStoreContext.class);

      storage = context.getBlobStore();
      swift = context.unwrap();
      swift.getApi().createContainer(bucketName);

    }catch(Exception e){
      System.out.println("Cannot connect with RackSpace.");
      //e.printStackTrace();
View Full Code Here

Examples of org.jclouds.blobstore.BlobStoreContext

  @Test(timeout = TestConstants.ITEST_TIMEOUT)
  public void testStoreAndLoadState() throws Exception {
    ClusterSpec spec = getTestClusterSpec();

    BlobStoreContext context = BlobStoreContextBuilder.build(spec);
    String container = generateRandomContainerName(context);
    try {
      spec.setStateStore("blob");
      spec.setStateStoreContainer(container);

      Cluster expected = createTestCluster(new String[]{"region/id1", "region/id2"},
          new String[]{"role1", "role2"});

      BlobClusterStateStore store = new BlobClusterStateStore(spec);
      store.save(expected);

      /* load and check the stored state */
      Cluster stored = store.load();
      Cluster.Instance first = Iterables.getFirst(stored.getInstances(), null);
      assertNotNull(first);

      assertThat(first.getId(), is("region/id1"));
      assertThat(first.getRoles().contains("role1"), is(true));
      assertThat(stored.getInstances().size(), is(2));

      /* destroy stored state and check it no longer exists */
      store.destroy();
      expected = store.load();
      assertNull(expected);

    } finally {
      LOG.info("Removing temporary container '{}'", container);
      context.getBlobStore().deleteContainer(container);
    }
  }
View Full Code Here

Examples of org.jclouds.blobstore.BlobStoreContext

  @Test
  public void testSpecifyCacheContainerInConfig() throws Exception {
    ClusterSpec spec = getTestClusterSpec();

    BlobStoreContext context = BlobStoreContextBuilder.build(spec);
    String container = generateRandomContainerName(context);
    LOG.info("Created temporary container '{}'", container);

    try {
      spec.setBlobStoreCacheContainer(container);

      BlobCache cache = BlobCache.getInstance(ComputeCache.INSTANCE, spec);
      assertThat(cache.getContainer(), is(container));
      cache.dropAndClose();

      assertThat(context.getBlobStore().containerExists(container), is(true));

    } finally {
      LOG.info("Removing temporary container '{}'", container);
      context.getBlobStore().deleteContainer(container);
    }
  }
View Full Code Here

Examples of org.jclouds.blobstore.BlobStoreContext

     * Strategy to perform any pre setup, before {@link org.apache.camel.CamelContext} is created
     */
    @Override
    protected void doPreSetup() throws Exception {
        BlobStoreContextFactory contextFactory = new BlobStoreContextFactory();
        BlobStoreContext blobStoreContext = contextFactory.createContext("transient", "identity", "credential");
        BlobStore blobStore = blobStoreContext.getBlobStore();
        blobStore.createContainerInLocation(null, TEST_CONTAINER);
        blobStore.clearContainer(TEST_CONTAINER);
    }
View Full Code Here

Examples of org.jclouds.blobstore.BlobStoreContext

     * Strategy to perform any pre setup, before {@link org.apache.camel.CamelContext} is created
     */
    @Override
    protected void doPreSetup() throws Exception {
        BlobStoreContextFactory contextFactory = new BlobStoreContextFactory();
        BlobStoreContext blobStoreContext = contextFactory.createContext("transient", "identity", "credential");
        BlobStore blobStore = blobStoreContext.getBlobStore();
        blobStore.createContainerInLocation(null, TEST_CONTAINER);
        blobStore.clearContainer(TEST_CONTAINER);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.