Search in sources :

Example 1 with CloudFilesApi

use of org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi in project druid by druid-io.

the class CloudFilesStorageDruidModule method getCloudFilesApi.

@Provides
@LazySingleton
public CloudFilesApi getCloudFilesApi(final CloudFilesAccountConfig config) {
    log.info("Building Cloud Files Api...");
    Iterable<com.google.inject.Module> modules = null;
    if (config.getUseServiceNet()) {
        log.info("Configuring Cloud Files Api to use the internal service network...");
        modules = ImmutableSet.<com.google.inject.Module>of(new SLF4JLoggingModule(), new InternalUrlModule());
    } else {
        log.info("Configuring Cloud Files Api to use the public network...");
        modules = ImmutableSet.<com.google.inject.Module>of(new SLF4JLoggingModule());
    }
    ProviderRegistry.registerProvider(CloudFilesUSProviderMetadata.builder().build());
    ProviderRegistry.registerProvider(CloudFilesUKProviderMetadata.builder().build());
    ContextBuilder cb = ContextBuilder.newBuilder(config.getProvider()).credentials(config.getUserName(), config.getApiKey()).modules(modules);
    CloudFilesApi cfa = cb.buildApi(CloudFilesApi.class);
    log.info("Cloud Files Api built.");
    return cfa;
}
Also used : InternalUrlModule(org.jclouds.openstack.v2_0.config.InternalUrlModule) SLF4JLoggingModule(org.jclouds.logging.slf4j.config.SLF4JLoggingModule) ContextBuilder(org.jclouds.ContextBuilder) CloudFilesApi(org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi) Module(com.fasterxml.jackson.databind.Module) SLF4JLoggingModule(org.jclouds.logging.slf4j.config.SLF4JLoggingModule) InternalUrlModule(org.jclouds.openstack.v2_0.config.InternalUrlModule) DruidModule(io.druid.initialization.DruidModule) LazySingleton(io.druid.guice.LazySingleton) Provides(com.google.inject.Provides)

Example 2 with CloudFilesApi

use of org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi in project druid by druid-io.

the class CloudFilesDataSegmentPusherTest method testPush.

@Test
public void testPush() throws Exception {
    ObjectApi objectApi = EasyMock.createStrictMock(ObjectApi.class);
    EasyMock.expect(objectApi.put(EasyMock.anyString(), EasyMock.<Payload>anyObject())).andReturn(null).atLeastOnce();
    EasyMock.replay(objectApi);
    CloudFilesApi api = EasyMock.createStrictMock(CloudFilesApi.class);
    EasyMock.expect(api.getObjectApi(EasyMock.anyString(), EasyMock.anyString())).andReturn(objectApi).atLeastOnce();
    EasyMock.replay(api);
    CloudFilesDataSegmentPusherConfig config = new CloudFilesDataSegmentPusherConfig();
    config.setRegion("region");
    config.setContainer("container");
    config.setBasePath("basePath");
    CloudFilesDataSegmentPusher pusher = new CloudFilesDataSegmentPusher(api, config, new DefaultObjectMapper());
    // Create a mock segment on disk
    File tmp = tempFolder.newFile("version.bin");
    final byte[] data = new byte[] { 0x0, 0x0, 0x0, 0x1 };
    Files.write(data, tmp);
    final long size = data.length;
    DataSegment segmentToPush = new DataSegment("foo", new Interval("2015/2016"), "0", Maps.<String, Object>newHashMap(), Lists.<String>newArrayList(), Lists.<String>newArrayList(), NoneShardSpec.instance(), 0, size);
    DataSegment segment = pusher.push(tempFolder.getRoot(), segmentToPush);
    Assert.assertEquals(segmentToPush.getSize(), segment.getSize());
    EasyMock.verify(api);
}
Also used : ObjectApi(org.jclouds.openstack.swift.v1.features.ObjectApi) Payload(org.jclouds.io.Payload) CloudFilesApi(org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) File(java.io.File) DataSegment(io.druid.timeline.DataSegment) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 3 with CloudFilesApi

use of org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi in project druid by druid-io.

the class CloudFilesObjectApiProxyTest method getTest.

@Test
public void getTest() {
    final String path = "path";
    final String region = "region";
    final String container = "container";
    CloudFilesApi cloudFilesApi = createMock(CloudFilesApi.class);
    ObjectApi objectApi = createMock(ObjectApi.class);
    SwiftObject swiftObject = createMock(SwiftObject.class);
    Payload payload = createMock(Payload.class);
    expect(cloudFilesApi.getObjectApi(region, container)).andReturn(objectApi);
    expect(objectApi.get(path)).andReturn(swiftObject);
    expect(swiftObject.getPayload()).andReturn(payload);
    replayAll();
    CloudFilesObjectApiProxy cfoApiProxy = new CloudFilesObjectApiProxy(cloudFilesApi, region, container);
    CloudFilesObject cloudFilesObject = cfoApiProxy.get(path);
    assertEquals(cloudFilesObject.getPayload(), payload);
    assertEquals(cloudFilesObject.getRegion(), region);
    assertEquals(cloudFilesObject.getContainer(), container);
    assertEquals(cloudFilesObject.getPath(), path);
    verifyAll();
}
Also used : ObjectApi(org.jclouds.openstack.swift.v1.features.ObjectApi) SwiftObject(org.jclouds.openstack.swift.v1.domain.SwiftObject) CloudFilesApi(org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi) Payload(org.jclouds.io.Payload) Test(org.junit.Test)

Aggregations

CloudFilesApi (org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi)3 Payload (org.jclouds.io.Payload)2 ObjectApi (org.jclouds.openstack.swift.v1.features.ObjectApi)2 Test (org.junit.Test)2 Module (com.fasterxml.jackson.databind.Module)1 Provides (com.google.inject.Provides)1 LazySingleton (io.druid.guice.LazySingleton)1 DruidModule (io.druid.initialization.DruidModule)1 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)1 DataSegment (io.druid.timeline.DataSegment)1 File (java.io.File)1 ContextBuilder (org.jclouds.ContextBuilder)1 SLF4JLoggingModule (org.jclouds.logging.slf4j.config.SLF4JLoggingModule)1 SwiftObject (org.jclouds.openstack.swift.v1.domain.SwiftObject)1 InternalUrlModule (org.jclouds.openstack.v2_0.config.InternalUrlModule)1 Interval (org.joda.time.Interval)1