Examples of BlobStoreContext


Examples of org.jclouds.blobstore.BlobStoreContext

   @Test
   void testContextImpl() {

      Injector injector = createInjector();
      BlobStoreContext handler = injector.getInstance(BlobStoreContext.class);
      assertEquals(handler.getClass(), BlobStoreContextImpl.class);
      ContainsValueInListStrategy valueList = injector
               .getInstance(ContainsValueInListStrategy.class);

      assertEquals(valueList.getClass(), FindMD5InUserMetadata.class);
   }
View Full Code Here

Examples of org.jclouds.blobstore.BlobStoreContext

    @EndpointInject(uri = "mock:result-bar")
    protected MockEndpoint resultBar;

    @BeforeClass
    public static void setUpClass() throws Exception {
        BlobStoreContext context = new BlobStoreContextFactory().createContext("transient", "id", "credential");
        context.getBlobStore().createContainerInLocation(null, "foo");
        context.getBlobStore().createContainerInLocation(null, "bar");
    }
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 CloudFilesPublisher() {
        Properties overrides = new Properties();
        overrides.setProperty(LocationConstants.PROPERTY_ZONE, ZONE);

        BlobStoreContext context = ContextBuilder.newBuilder(PROVIDER)
                .credentials(USERNAME, API_KEY)
                .overrides(overrides)
                .buildView(BlobStoreContext.class);
        blobStore = context.getBlobStore();
    }
View Full Code Here

Examples of org.jclouds.blobstore.BlobStoreContext

        this.batchSize = batchSize;
    }

    public synchronized boolean hasNewFiles() {
        // see if there are any files since lastMarker.
        BlobStoreContext ctx = ContextBuilder.newBuilder(provider)
                .credentials(user, key)
                .overrides(new Properties() {{
                    setProperty(LocationConstants.PROPERTY_ZONE, zone);
                }})
                .buildView(BlobStoreContext.class);
       
        BlobStore store = ctx.getBlobStore();
        ListContainerOptions options = new ListContainerOptions().maxResults(batchSize).afterMarker(lastMarker);
        PageSet<? extends StorageMetadata> pages = store.list(container, options);
       
        log.debug("Saw {} new files since {}", pages.size() == batchSize ? "many" : Integer.toString(pages.size()), lastMarker);
        boolean emptiness = getBlobsWithinRange(pages).isEmpty();
View Full Code Here

Examples of org.jclouds.blobstore.BlobStoreContext

    }
   
    public synchronized void downloadNewFiles(File downloadDir) {
        log.info("Downloading new files since {}", lastMarker);
       
        BlobStoreContext ctx = ContextBuilder.newBuilder(provider)
                .credentials(user, key)
                .overrides(new Properties() {{
                    setProperty(LocationConstants.PROPERTY_ZONE, zone);
                }})
                .buildView(BlobStoreContext.class);

        // threadsafe according to https://jclouds.apache.org/documentation/userguide/blobstore-guide/
        BlobStore store = ctx.getBlobStore();
        ListContainerOptions options = new ListContainerOptions().maxResults(batchSize).afterMarker(lastMarker);
        PageSet<? extends StorageMetadata> pages = store.list(container, options);

        //Gets key within the time range specified
        NavigableMap<Long, String> mapWithinRange = getBlobsWithinRange(pages);
View Full Code Here

Examples of org.jclouds.blobstore.BlobStoreContext

        // blob name and checksum of the file
        String blobName = System.nanoTime() + "/" + file.getName();
        String blobNameChecksum = blobName + ".md5";

        BlobStoreContext context = getContext(config, spec);

        File checksumFile;

        try
        {
            checksumFile = File.createTempFile("dtchecksum", "md5");
            checksumFile.deleteOnExit();

            FileWriter checksumWriter = new FileWriter(checksumFile);

            String checksum = FBUtilities.bytesToHex(Files.getDigest(file, MessageDigest.getInstance("MD5")));

            checksumWriter.write(String.format("%s  %s", checksum, file.getName()));
            checksumWriter.close();
        }
        catch (IOException e)
        {
            throw new RuntimeException("Can't create a checksum of the file: " + filename);
        }
        catch (NoSuchAlgorithmException e)
        {
            throw new RuntimeException(e.getMessage());
        }

        try
        {
            InputStreamMap map = context.createInputStreamMap(container);

            map.putFile(blobName, file);
            map.putFile(blobNameChecksum, checksumFile);

            // 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.contains("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));

                sss.putObjectACL(container,
                                 blobNameChecksum,
                                 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

    * @return
    */
   public InputSupplier<InputStream> getBlobInputStream(BlobStore blobStore, String containerName, String blobName, boolean signedRequest)
         throws Exception {
      if (signedRequest) {
         BlobStoreContext context = blobStore.getContext();
         HttpRequest request = context.getSigner().signGetBlob(containerName, blobName);
         HttpClient httpClient = context.utils().http();
         HttpResponse response = httpClient.invoke(request);
         int statusCode = response.getStatusCode();
         if (statusCode != 200) {
            throw new IOException(response.getStatusLine());
         }
View Full Code Here

Examples of org.jclouds.blobstore.BlobStoreContext

            blobStore.createDirectory(bucket, directory);
         }
      }

      if (signedRequest) {
         BlobStoreContext context = blobStore.getContext();
         HttpRequest request = context.getSigner().signPutBlob(bucket, blob);
         HttpClient httpClient = context.utils().http();
         HttpResponse response = httpClient.invoke(request);
         int statusCode = response.getStatusCode();
         if (statusCode != 200 && statusCode != 201) {
            throw new IOException(response.getStatusLine());
         }
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.