コード例 #1
0
 @AfterClass
 public static void tearDownClass() throws Exception {
   if (ctx != null) {
     ctx.getBlobStore().deleteContainer(DEFAULT_CONTAINER);
     ctx.close();
   }
 }
コード例 #2
0
 @Override
 public BlobStoreContext call() throws Exception {
   BlobStoreContext context =
       new BlobStoreContextFactory()
           .createContext("filesystem", "", "", ImmutableSet.<Module>of(), overrides);
   context.getBlobStore().createContainerInLocation(null, CREDENTIALS_STORE);
   return context;
 }
コード例 #3
0
 public ListContainers(String username, String apiKey) {
   BlobStoreContext context =
       ContextBuilder.newBuilder(PROVIDER)
           .credentials(username, apiKey)
           .buildView(BlobStoreContext.class);
   blobStore = context.getBlobStore();
   swift = context.unwrap();
 }
コード例 #4
0
 private BlobStore getBlobStore() {
   BlobStoreContext context =
       ContextBuilder.newBuilder("transient")
           .name("test-transient")
           .credentials("user", "pass")
           .build(BlobStoreContext.class);
   return context.getBlobStore();
 }
コード例 #5
0
  private void copyToS3(String fileName) {

    String bucketName = (String) properties.get(BUCKET_PROPNAME);
    String accessId = (String) properties.get(ACCESS_ID_PROPNAME);
    String secretKey = (String) properties.get(SECRET_KEY_PROPNAME);

    Properties overrides = new Properties();
    overrides.setProperty("s3" + ".identity", accessId);
    overrides.setProperty("s3" + ".credential", secretKey);

    final Iterable<? extends Module> MODULES =
        ImmutableSet.of(
            new JavaUrlHttpCommandExecutorServiceModule(),
            new Log4JLoggingModule(),
            new NettyPayloadModule());

    BlobStoreContext context =
        ContextBuilder.newBuilder("s3")
            .credentials(accessId, secretKey)
            .modules(MODULES)
            .overrides(overrides)
            .buildView(BlobStoreContext.class);

    // Create Container (the bucket in s3)
    try {
      AsyncBlobStore blobStore = context.getAsyncBlobStore(); // it can be changed to sync
      // BlobStore (returns false if it already exists)
      ListenableFuture<Boolean> container = blobStore.createContainerInLocation(null, bucketName);
      if (container.get()) {
        LOG.info("Created bucket " + bucketName);
      }
    } catch (Exception ex) {
      logger.error("Could not start binary service: {}", ex.getMessage());
      throw new RuntimeException(ex);
    }

    try {
      File file = new File(fileName);
      AsyncBlobStore blobStore = context.getAsyncBlobStore();
      BlobBuilder blobBuilder =
          blobStore
              .blobBuilder(file.getName())
              .payload(file)
              .calculateMD5()
              .contentType("text/plain")
              .contentLength(file.length());

      Blob blob = blobBuilder.build();

      ListenableFuture<String> futureETag =
          blobStore.putBlob(bucketName, blob, PutOptions.Builder.multipart());

      LOG.info("Uploaded file etag=" + futureETag.get());
    } catch (Exception e) {
      LOG.error("Error uploading to blob store", e);
    }
  }
コード例 #6
0
 private void uploadMultipleParts(
     BlobStoreContext context,
     InputStream in,
     BlobStore blobStore,
     String container,
     String storagePath)
     throws IOException {
   AWSS3Client client = context.unwrapApi(AWSS3Client.class);
   String uploadId =
       client.initiateMultipartUpload(
           container, ObjectMetadataBuilder.create().key(storagePath).build());
   Map<Integer, String> parts = new HashMap<>();
   int partNumber = 1;
   do {
     parts.put(
         partNumber,
         client.uploadPart(container, storagePath, partNumber, uploadId, createPayload()));
     partNumber++;
   } while (fillBuffers(in));
   if (count > 0)
     parts.put(
         partNumber,
         client.uploadPart(container, storagePath, partNumber, uploadId, createPayload()));
   client.completeMultipartUpload(container, storagePath, uploadId, parts);
 }
コード例 #7
0
 @BeforeGroups(groups = {"live"})
 public void setupClient() {
   setupCredentials();
   Properties overrides = setupProperties();
   context =
       new BlobStoreContextFactory()
           .createContext(provider, ImmutableSet.<Module>of(new Log4JLoggingModule()), overrides);
   client = (AzureBlobClient) context.getProviderSpecificContext().getApi();
 }
コード例 #8
0
 @BeforeMethod
 protected void setUp() throws Exception {
   // create context for filesystem container
   Properties prop = new Properties();
   prop.setProperty(FilesystemConstants.PROPERTY_BASEDIR, TestUtils.TARGET_BASE_DIR);
   context = ContextBuilder.newBuilder(PROVIDER).overrides(prop).build(BlobStoreContext.class);
   // create a container in the default location
   blobStore = context.getBlobStore();
   new File(TestUtils.TARGET_BASE_DIR).mkdir();
   TestUtils.createResources();
 }
コード例 #9
0
  /** Test that BlobRequestSigner creates expected URIs. */
  public void testBlobRequestSigner() throws Exception {
    String containerName = "container";
    String blobName = "blob";
    URI endPoint =
        new URI(
            "http",
            "localhost",
            String.format("/transient/%s/%s", containerName, blobName),
            /*fragment=*/ null);
    BlobRequestSigner signer = context.getSigner();
    HttpRequest request;
    HttpRequest expected;

    request = signer.signGetBlob(containerName, blobName);
    expected =
        HttpRequest.builder()
            .method("GET")
            .endpoint(endPoint)
            .headers(request.getHeaders())
            .build();
    assertEquals(expected, request);

    request = signer.signRemoveBlob(containerName, blobName);
    expected =
        HttpRequest.builder()
            .method("DELETE")
            .endpoint(endPoint)
            .headers(request.getHeaders())
            .build();
    assertEquals(expected, request);

    Blob blob = blobStore.blobBuilder(blobName).forSigning().build();
    request = signer.signPutBlob(containerName, blob);
    expected =
        HttpRequest.builder()
            .method("PUT")
            .endpoint(endPoint)
            .headers(request.getHeaders())
            .payload(new PhantomPayload())
            .build();
    assertEquals(expected, request);
  }
コード例 #10
0
public class JcloudsBlobStoreProducerTest extends CamelTestSupport {

  private static final String TEST_CONTAINER = "testContainer";
  private static final String TEST_BLOB_IN_DIR = "/dir/testBlob";
  private static final String MESSAGE = "<test>This is a test</test>";

  BlobStoreContext blobStoreContext =
      ContextBuilder.newBuilder("transient")
          .credentials("identity", "credential")
          .build(BlobStoreContext.class);
  BlobStore blobStore = blobStoreContext.getBlobStore();

  @Test
  public void testBlobStorePut() throws InterruptedException {
    MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:results", MockEndpoint.class);
    mockEndpoint.expectedMessageCount(1);
    template.sendBody("direct:put", "Some message");
    mockEndpoint.assertIsSatisfied();
  }

  @Test
  public void testBlobStorePutAndGet() throws InterruptedException {
    String message = "Some message";
    template.sendBody("direct:put-and-get", message);
    Object result =
        template.requestBodyAndHeader(
            "direct:put-and-get",
            null,
            JcloudsConstants.OPERATION,
            JcloudsConstants.GET,
            String.class);
    assertEquals(message, result);
  }

  @Test
  public void testBlobStorePutWithStreamAndGet() throws InterruptedException, TransformerException {
    ByteArrayInputStream inputStream = new ByteArrayInputStream(MESSAGE.getBytes());
    Exchange exchange = new DefaultExchange(context);
    StreamCache streamCache =
        StreamCacheConverter.convertToStreamCache(
            new SAXSource(new InputSource(inputStream)), exchange);
    template.sendBody("direct:put-and-get", streamCache);
    Object result =
        template.requestBodyAndHeader(
            "direct:put-and-get",
            null,
            JcloudsConstants.OPERATION,
            JcloudsConstants.GET,
            String.class);
    assertEquals(MESSAGE, result);
  }

  @Override
  protected RouteBuilder createRouteBuilder() throws Exception {
    blobStore.createContainerInLocation(null, TEST_CONTAINER);
    ((JcloudsComponent) context.getComponent("jclouds"))
        .setBlobStores(Lists.newArrayList(blobStore));

    return new RouteBuilder() {
      public void configure() {
        from("direct:put")
            .setHeader(JcloudsConstants.BLOB_NAME, constant(TEST_BLOB_IN_DIR))
            .setHeader(JcloudsConstants.CONTAINER_NAME, constant(TEST_CONTAINER))
            .to("jclouds:blobstore:transient")
            .to("mock:results");

        from("direct:put-and-get")
            .setHeader(JcloudsConstants.BLOB_NAME, constant(TEST_BLOB_IN_DIR))
            .setHeader(JcloudsConstants.CONTAINER_NAME, constant(TEST_CONTAINER))
            .to("jclouds:blobstore:transient");
      }
    };
  }
}
コード例 #11
0
 @AfterMethod
 protected void tearDown() throws IOException {
   context.close();
   Utils.deleteRecursively(new File(TestUtils.TARGET_BASE_DIR));
 }
コード例 #12
0
 public void update() {
   ctx.createInputStreamMap(DEFAULT_CONTAINER).putAllStrings(UPDATE);
 }
コード例 #13
0
 @Before
 public void initial() {
   ctx.createInputStreamMap(DEFAULT_CONTAINER).putAllStrings(INITIAL);
 }
コード例 #14
0
 @BeforeClass
 public static void setUpClass() {
   ctx = ContextBuilder.newBuilder("transient").buildView(BlobStoreContext.class);
   System.setProperty("com.netflix.config.blobstore.containerName", DEFAULT_CONTAINER);
   ctx.getBlobStore().createContainerInLocation(null, DEFAULT_CONTAINER);
 }
コード例 #15
0
 protected BlobMap createMap(
     BlobStoreContext context, String bucket, ListContainerOptions options) {
   return context.createBlobMap(bucket, options);
 }