org.jclouds.logging.slf4j.config.SLF4JLoggingModule Java Examples

The following examples show how to use org.jclouds.logging.slf4j.config.SLF4JLoggingModule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ComputeServiceBuilderUtil.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public static ComputeService buildDefaultComputeService(IaasProvider iaasProvider) {

        Properties properties = new Properties();

        // load properties
        for (Map.Entry<String, String> entry : iaasProvider.getProperties().entrySet()) {
            properties.put(entry.getKey(), entry.getValue());
        }

        // set modules
        Iterable<Module> modules =
                ImmutableSet.<Module>of(new SshjSshClientModule(), new SLF4JLoggingModule(),
                        new EnterpriseConfigurationModule());

        // build context
        ContextBuilder builder =
                ContextBuilder.newBuilder(iaasProvider.getProvider())
                        .credentials(iaasProvider.getIdentity(), iaasProvider.getCredential()).modules(modules)
                        .overrides(properties);

        return builder.buildView(ComputeServiceContext.class).getComputeService();
    }
 
Example #2
Source File: MainApp.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
private static ChefApi initChefService(final String client, final String validator) {
    try {
        Properties chefConfig = new Properties();
        chefConfig.put(ChefProperties.CHEF_VALIDATOR_NAME, validator);
        chefConfig
                .put(ChefProperties.CHEF_VALIDATOR_CREDENTIAL, credentialForClient(validator));

        ContextBuilder builder = ContextBuilder.newBuilder(new ChefApiMetadata()) //
                .credentials(client, credentialForClient(client)) //
                .modules(ImmutableSet.<Module>of(new SLF4JLoggingModule())) //
                .overrides(chefConfig); //

        System.out.printf(">> initializing %s%n", builder.getApiMetadata());

        return builder.buildApi(ChefApi.class);
    } catch (Exception e) {
        System.err.println("error reading private key " + e.getMessage());
        System.exit(1);
        return null;
    }
}
 
Example #3
Source File: MainApp.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
private static ComputeService initComputeService(final String provider, final String identity,
                                                 final String credential) {
    // example of specific properties, in this case optimizing image list to
    // only amazon supplied
    Properties properties = new Properties();
    long scriptTimeout = TimeUnit.MILLISECONDS.convert(20, TimeUnit.MINUTES);
    properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, scriptTimeout + "");

    // example of injecting a ssh implementation
    Iterable<Module> modules =
            ImmutableSet.<Module>of(new SshjSshClientModule(), new SLF4JLoggingModule(),
                    new EnterpriseConfigurationModule());

    ContextBuilder builder =
            ContextBuilder.newBuilder(provider).credentials(identity, credential).modules(modules)
                    .overrides(properties);

    System.out.printf(">> initializing %s%n", builder.getApiMetadata());

    return builder.buildView(ComputeServiceContext.class).getComputeService();
}
 
Example #4
Source File: Utils.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
public static ComputeServiceContext getComputeApiFromCarinaDirectory(String path) throws IOException {
   // docker.ps1 contains the endpoint
   String endpoint = "https://" +
         Files.readFirstLine(new File(joinPath(path, "docker.ps1")),
               Charset.forName("UTF-8")).split("=")[1].replace("\"", "").substring(6);

   // enable logging and sshj
   Iterable<Module> modules = ImmutableSet.<Module> of(new SLF4JLoggingModule(), new SshjSshClientModule());
   Properties overrides = new Properties();

   // disable certificate checking for Carina
   overrides.setProperty("jclouds.trust-all-certs", "true");

   return ContextBuilder.newBuilder("docker")
         .credentials(joinPath(path, "cert.pem"), joinPath(path, "key.pem"))
         .modules(modules)
         .overrides(overrides)
         .endpoint(endpoint)
         .buildView(ComputeServiceContext.class);
}
 
Example #5
Source File: Utils.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
public static DockerApi getDockerApiFromCarinaDirectory(String path) throws IOException {
   // docker.ps1 contains the endpoint
   String endpoint = "https://" +
         Files.readFirstLine(new File(joinPath(path, "docker.ps1")),
               Charset.forName("UTF-8")).split("=")[1].replace("\"", "").substring(6);

   // enable logging
   Iterable<Module> modules = ImmutableSet.<Module> of(new SLF4JLoggingModule());
   Properties overrides = new Properties();

   // disable certificate checking for Carina
   overrides.setProperty("jclouds.trust-all-certs", "true");

   return ContextBuilder.newBuilder("docker")
         // Use the unencrypted credentials
         .credentials(joinPath(path, "cert.pem"), joinPath(path, "key.pem"))
         .overrides(overrides)
         .endpoint(endpoint)
         .modules(modules)
         .buildApi(DockerApi.class);
}
 
Example #6
Source File: AreWeConsistentYetTest.java    From are-we-consistent-yet with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    ContextBuilder builder = ContextBuilder
            .newBuilder("transient")
            .credentials("identity", "credential")
            .modules(ImmutableList.<Module>of(new SLF4JLoggingModule()));
    context = builder.build(BlobStoreContext.class);
    contextRead = builder.build(BlobStoreContext.class);

    BlobStore blobStore = context.getBlobStore();
    BlobStore blobStoreRead = contextRead.getBlobStore();

    String containerName = "container-name";
    Location location = null;
    blobStore.createContainerInLocation(location, containerName);
    blobStoreRead.createContainerInLocation(location, containerName);

    awcyStrong = new AreWeConsistentYet(blobStore,
            blobStore, containerName, ITERATIONS, OBJECT_SIZE);
    awcyEventual = new AreWeConsistentYet(blobStore,
            blobStoreRead, containerName, ITERATIONS, OBJECT_SIZE);
}
 
Example #7
Source File: AreWeConsistentYet.java    From are-we-consistent-yet with Apache License 2.0 6 votes vote down vote up
private static BlobStoreContext blobStoreContextFromProperties(
        Properties properties) {
    String provider = properties.getProperty(Constants.PROPERTY_PROVIDER);
    String identity = properties.getProperty(Constants.PROPERTY_IDENTITY);
    String credential = properties.getProperty(
            Constants.PROPERTY_CREDENTIAL);
    String endpoint = properties.getProperty(Constants.PROPERTY_ENDPOINT);
    if (provider == null || identity == null || credential == null) {
        System.err.println("Properties file must contain:\n" +
                Constants.PROPERTY_PROVIDER + "\n" +
                Constants.PROPERTY_IDENTITY + "\n" +
                Constants.PROPERTY_CREDENTIAL);
        System.exit(1);
    }

    ContextBuilder builder = ContextBuilder
            .newBuilder(provider)
            .credentials(identity, credential)
            .modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
            .overrides(properties);
    if (endpoint != null) {
        builder = builder.endpoint(endpoint);
    }
    return builder.build(BlobStoreContext.class);
}
 
Example #8
Source File: S3ProxyImpl.java    From pravega with Apache License 2.0 6 votes vote down vote up
public S3ProxyImpl(String endpoint, S3Config s3Config) {
    URI uri = URI.create(endpoint);

    Properties properties = new Properties();
    properties.setProperty("s3proxy.authorization", "none");
    properties.setProperty("s3proxy.endpoint", endpoint);
    properties.setProperty("jclouds.provider", "filesystem");
    properties.setProperty("jclouds.filesystem.basedir", "/tmp/s3proxy");

    ContextBuilder builder = ContextBuilder
            .newBuilder("filesystem")
            .credentials("x", "x")
            .modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
            .overrides(properties);
    BlobStoreContext context = builder.build(BlobStoreContext.class);
    BlobStore blobStore = context.getBlobStore();
    s3Proxy = S3Proxy.builder().awsAuthentication(AuthenticationType.AWS_V2_OR_V4, "x", "x")
                     .endpoint(uri)
                     .keyStore("", "")
                     .blobStore(blobStore)
                     .ignoreUnknownHeaders(true)
                     .build();
    client = new S3JerseyCopyPartClient(s3Config);
}
 
Example #9
Source File: InfrastructureConfiguration.java    From chaos-lemur with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnProperty("openstack.endpoint")
NovaApi novaApi(@Value("${openstack.endpoint}") String endpoint,
                @Value("${openstack.tenant}") String tenant,
                @Value("${openstack.username}") String username,
                @Value("${openstack.password}") String password) {

    String identity = String.format("%s:%s", tenant, username);

    // see https://issues.apache.org/jira/browse/JCLOUDS-816
    Properties overrides = new Properties();
    overrides.put(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
    overrides.put(Constants.PROPERTY_RELAX_HOSTNAME, "true");

    return ContextBuilder.newBuilder("openstack-nova")
        .endpoint(endpoint)
        .credentials(identity, password)
        .modules(Collections.singleton(new SLF4JLoggingModule()))
        .overrides(overrides)
        .buildApi(NovaApi.class);
}
 
Example #10
Source File: EventualBlobStoreTest.java    From s3proxy with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    containerName = createRandomContainerName();

    nearContext = ContextBuilder
            .newBuilder("transient")
            .credentials("identity", "credential")
            .modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
            .build(BlobStoreContext.class);
    nearBlobStore = nearContext.getBlobStore();
    nearBlobStore.createContainerInLocation(null, containerName);

    farContext = ContextBuilder
            .newBuilder("transient")
            .credentials("identity", "credential")
            .modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
            .build(BlobStoreContext.class);
    farBlobStore = farContext.getBlobStore();
    farBlobStore.createContainerInLocation(null, containerName);

    executorService = Executors.newScheduledThreadPool(1);

    eventualBlobStore = EventualBlobStore.newEventualBlobStore(
            nearBlobStore, farBlobStore, executorService, DELAY,
            DELAY_UNIT, 1.0);
}
 
Example #11
Source File: NovaContext.java    From karamel with Apache License 2.0 6 votes vote down vote up
public static ContextBuilder buildContext(NovaCredentials credentials) {
  Properties properties = new Properties();
  properties.setProperty(NovaProperties.AUTO_ALLOCATE_FLOATING_IPS, "true");
  Iterable<Module> modules = ImmutableSet.<Module>of(
          new SshjSshClientModule(),
          new SLF4JLoggingModule(),
          new EnterpriseConfigurationModule());

  ContextBuilder build = ContextBuilder.newBuilder("aws-ec2")
          .credentials(credentials.getAccountName(), credentials.getAccountPass())
          .endpoint(credentials.getEndpoint())
          .modules(modules)
          .overrides(properties);

  return build;
}
 
Example #12
Source File: SwiftFileSystemHandler.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Initiates the swift storage.
 */
public void init() {
    Iterable<Module> modules = ImmutableSet.<Module>of(new SLF4JLoggingModule());

    // The metadata must be registered because the ServiceLoader does not detect
    // the META-INF/services in each api JAR under Tomcat/Spring. Fortunately,
    // the registry is static and is not really OSGi specific for this use.
    ApiRegistry.registerApi(CLOUD_API_METADATA);

    swiftApi = ContextBuilder.newBuilder(CLOUD_API_METADATA)
            .endpoint(endpoint)
            .credentials(identity, credential)
            .modules(modules)
            .buildApi(SwiftApi.class);
}
 
Example #13
Source File: GceContext.java    From karamel with Apache License 2.0 5 votes vote down vote up
public GceContext(Credentials credentials) {
  ComputeServiceContext context = ContextBuilder.newBuilder("google-compute-engine")
      .modules(Arrays.asList(
              new SshjSshClientModule(),
              new EnterpriseConfigurationModule(),
              new SLF4JLoggingModule()))
      .credentials(credentials.identity, credentials.credential)
      .buildView(ComputeServiceContext.class);
  computeService = context.getComputeService();
  gceApi = context.unwrapApi(GoogleComputeEngineApi.class);
  fireWallApi = gceApi.firewalls();
  networkApi = gceApi.networks();
  routeApi = gceApi.routes();
  this.credentials = credentials;
}
 
Example #14
Source File: MainApp.java    From jclouds-examples with Apache License 2.0 5 votes vote down vote up
private static ComputeService initComputeService(String provider, String identity, String credential) {

      // example of specific properties, in this case optimizing image list to
      // only amazon supplied
      Properties properties = new Properties();
      properties.setProperty(PROPERTY_EC2_AMI_QUERY, "owner-id=137112412989;state=available;image-type=machine");
      properties.setProperty(PROPERTY_EC2_CC_AMI_QUERY, "");
      long scriptTimeout = TimeUnit.MILLISECONDS.convert(20, TimeUnit.MINUTES);
      properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, scriptTimeout + "");

      // set oauth endpoint property if set in system property
      String oAuthEndpoint = System.getProperty(PROPERTY_OAUTH_ENDPOINT);
      if (oAuthEndpoint != null) {
         properties.setProperty(PROPERTY_OAUTH_ENDPOINT, oAuthEndpoint);
      }

      // example of injecting a ssh implementation
      Iterable<Module> modules = ImmutableSet.<Module> of(
            new SshjSshClientModule(),
            new SLF4JLoggingModule(),
            new EnterpriseConfigurationModule());

      ContextBuilder builder = ContextBuilder.newBuilder(provider)
                                             .credentials(identity, credential)
                                             .modules(modules)
                                             .overrides(properties);

      System.out.printf(">> initializing %s%n", builder.getApiMetadata());

      return builder.buildView(ComputeServiceContext.class).getComputeService();
   }
 
Example #15
Source File: Logging.java    From jclouds-examples with Apache License 2.0 5 votes vote down vote up
public Logging(String username, String apiKey) {
   // The provider configures jclouds To use the Rackspace Cloud (US)
   // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-cloudservers-uk"
   String provider = System.getProperty("provider.cs", "rackspace-cloudservers-us");

   // This module is responsible for enabling logging
   Iterable<Module> modules = ImmutableSet.<Module> of(new SLF4JLoggingModule());

   nova = ContextBuilder.newBuilder(provider)
         .credentials(username, apiKey)
         .modules(modules) // don't forget to add the modules to your context!
         .buildApi(NovaApi.class);
}
 
Example #16
Source File: Ec2Context.java    From karamel with Apache License 2.0 5 votes vote down vote up
public Ec2Context(Ec2Credentials credentials) {
  this.credentials = credentials;
  Properties properties = new Properties();
  long scriptTimeout = TimeUnit.MILLISECONDS.convert(50, TimeUnit.MINUTES);
  properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, scriptTimeout + "");
  properties.setProperty(TIMEOUT_PORT_OPEN, scriptTimeout + "");
  properties.setProperty(PROPERTY_CONNECTION_TIMEOUT, scriptTimeout + "");
  properties.setProperty(PROPERTY_EC2_AMI_QUERY, "owner-id=137112412989;state=available;image-type=machine");
  properties.setProperty(PROPERTY_EC2_CC_AMI_QUERY, "");
  properties.setProperty(Constants.PROPERTY_MAX_RETRIES, Settings.JCLOUDS_PROPERTY_MAX_RETRIES + "");
  properties.setProperty(Constants.PROPERTY_RETRY_DELAY_START, Settings.JCLOUDS_PROPERTY_RETRY_DELAY_START + "");

  Iterable<Module> modules = ImmutableSet.<Module>of(
      new SshjSshClientModule(),
      new SLF4JLoggingModule(),
      new EnterpriseConfigurationModule());

  ContextBuilder build = ContextBuilder.newBuilder("aws-ec2")
      .credentials(credentials.getAccessKey(), credentials.getSecretKey())
      .modules(modules)
      .overrides(properties);
  ComputeServiceContext context = build.buildView(ComputeServiceContext.class);
  this.computeService = (AWSEC2ComputeService) context.getComputeService();
  this.ec2api = computeService.getContext().unwrapApi(EC2Api.class);
  this.securityGroupApi = ec2api.getSecurityGroupApi().get();
  this.keypairApi = (AWSKeyPairApi) ec2api.getKeyPairApi().get();

  vmBatchSize = Settings.AWS_VM_BATCH_SIZE();
}
 
Example #17
Source File: BlobStoreFileSystemHandler.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Initializes the BlobStore context.
 */
public void init() {
    Iterable<Module> modules = ImmutableSet.<Module>of(new SLF4JLoggingModule());

    // The metadata must be registered because the ServiceLoader does not detect
    // the META-INF/services in each api JAR under Tomcat/Spring. Fortunately,
    // the registry is static and is not really OSGi specific for this use.
    ApiRegistry.registerApi(new SwiftApiMetadata());
    ProviderRegistry.registerProvider(new AWSS3ProviderMetadata());

    context = ContextBuilder.newBuilder(provider)
            .credentials(identity, credential)
            .modules(modules)
            .buildView(BlobStoreContext.class);

    // There are some oddities with streaming larger files to the user,
    // so download to a temp file first. For now, call 100MB the threshold.
    maxBlobStreamSize = (long) serverConfigurationService.getInt("cloud.content.maxblobstream.size", 1024 * 1024 * 100);
    temporaryBlobDirectory = serverConfigurationService.getString("cloud.content.temporary.directory", null);
    
    if (temporaryBlobDirectory != null) {
        File baseDir = new File(temporaryBlobDirectory);
        if (!baseDir.exists()) {
            try {
                // Can't write into the preferred temp dir
                if (!baseDir.mkdirs()) {
                    temporaryBlobDirectory = null;
                }
            }
            catch (SecurityException se) {
                // JVM security hasn't whitelisted this dir
                temporaryBlobDirectory = null;
            }
        }
    }
}
 
Example #18
Source File: DeleteService.java    From jclouds-examples with Apache License 2.0 5 votes vote down vote up
public DeleteService(String username, String apiKey) {
   Iterable<Module> modules = ImmutableSet.<Module> of(new SLF4JLoggingModule());
   cdnApi = ContextBuilder.newBuilder(PROVIDER)
         .credentials(username, apiKey)
         .modules(modules)
         .buildApi(PoppyApi.class);

   serviceApi = cdnApi.getServiceApi();
}
 
Example #19
Source File: DeleteServerVlanAndNetworkDomain.java    From jclouds-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
{
    /*
     * Build an instance of the Dimension DataCloud Control Provider using the endpoint provided.
     * Typically the endpoint will be of the form https://api-GEO.dimensiondata.com/caas
     * We also need to provide authenticate details, a username and password.
     *
     * Internally the Dimension Data CloudControl Provider will use the org.jclouds.dimensiondata.cloudcontrol.features.AccountApi
     * to lookup the organization identifier so that it is used as part of the requests.
     *
     */
    String endpoint = args[0];
    String username = args[1];
    String password = args[2];

    try (ApiContext<DimensionDataCloudControlApi> ctx = ContextBuilder.newBuilder(DIMENSIONDATA_CLOUDCONTROL_PROVIDER)
            .endpoint(endpoint)
            .credentials(username, password)
            .modules(ImmutableSet.of(new SLF4JLoggingModule()))
            .build())
    {
        DimensionDataCloudControlApi api = ctx.getApi();

        /*
         * Referencing the asset created in org.jclouds.examples.dimensiondata.cloudcontrol.DeployNetworkDomainVlanAndServer
         */
        final String networkDomainName = "jclouds-example";
        String networkDomainId = getNetworkDomainId(api, networkDomainName);
        final String serverName = "jclouds-server";
        final String vlanName = "jclouds-example-vlan";

        deleteServer(api, serverName);
        deleteVlan(api, vlanName, networkDomainId);
        deleteNetworkDomain(api, networkDomainId);
        deleteTagKey(api, "jclouds");
    }
}
 
Example #20
Source File: DeployNetworkDomainVlanAndServer.java    From jclouds-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
{
    String endpoint = args[0];
    String username = args[1];
    String password = args[2];
    /*
     * Build an instance of the Dimension DataCloud Control Provider using the endpoint provided.
     * Typically the endpoint will be of the form https://api-GEO.dimensiondata.com/caas
     * We also need to provide authenticate details, a username and password.
     *
     * Internally the Dimension Data CloudControl Provider will use the org.jclouds.dimensiondata.cloudcontrol.features.AccountApi
     * to lookup the organization identifier so that it is used as part of the requests.
     *
     */
    try (ApiContext<DimensionDataCloudControlApi> ctx = ContextBuilder.newBuilder(DIMENSIONDATA_CLOUDCONTROL_PROVIDER)
            .endpoint(endpoint)
            .credentials(username, password)
            .modules(ImmutableSet.of(new SLF4JLoggingModule()))
            .build())
    {
        DimensionDataCloudControlApi api = ctx.getApi();

        /*
         * Create a tag key. We will use this to tag the assets that we create.
         */
        String tagKeyId = api.getTagApi().createTagKey("jclouds", "owner of the asset", true, false);

        String networkDomainId = deployNetworkDomain(api, tagKeyId);
        String vlanId = deployVlan(api, networkDomainId, tagKeyId);

        deployServer(api, networkDomainId, vlanId, tagKeyId);
    }

}
 
Example #21
Source File: CreateTenantAndUser.java    From jclouds-examples with Apache License 2.0 5 votes vote down vote up
public CreateTenantAndUser(String endpoint, String tenantName, String userName, String password) {
   System.out.format("%s%n", this.getClass().getName());

   Iterable<Module> modules = ImmutableSet.<Module>of(new SLF4JLoggingModule());

   String provider = "openstack-keystone";
   String identity = tenantName + ":"  + userName;

   keystoneApi = ContextBuilder.newBuilder(provider)
         .endpoint(endpoint)
         .credentials(identity, password)
         .modules(modules)
         .buildApi(KeystoneApi.class);
}
 
Example #22
Source File: LinkContextSupplier.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public Context get() {
    JcloudsContext jcloudsContext = conf.get(JcloudsLocationConfig.LINK_CONTEXT);
    String identity = MoreObjects.firstNonNull(jcloudsContext.getIdentity(), conf.get(CloudLocationConfig.ACCESS_IDENTITY));
    String credential = MoreObjects.firstNonNull(jcloudsContext.getCredential(), conf.get(CloudLocationConfig.ACCESS_CREDENTIAL));
    return ContextBuilder
            .newBuilder(jcloudsContext.getProviderOrApi())
            .credentials(identity, credential)
            .modules(ImmutableList.of(new SshjSshClientModule(), new SLF4JLoggingModule()))
            .overrides(getProperties(jcloudsContext, conf))
            .build();
}
 
Example #23
Source File: SwiftFileSystemHandler.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Initiates the swift storage.
 */
public void init() {
    Iterable<Module> modules = ImmutableSet.<Module>of(new SLF4JLoggingModule());

    // The metadata must be registered because the ServiceLoader does not detect
    // the META-INF/services in each api JAR under Tomcat/Spring. Fortunately,
    // the registry is static and is not really OSGi specific for this use.
    ApiRegistry.registerApi(CLOUD_API_METADATA);

    swiftApi = ContextBuilder.newBuilder(CLOUD_API_METADATA)
            .endpoint(endpoint)
            .credentials(identity, credential)
            .modules(modules)
            .buildApi(SwiftApi.class);
}
 
Example #24
Source File: BlobStoreFileSystemHandler.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Initializes the BlobStore context.
 */
public void init() {
    Iterable<Module> modules = ImmutableSet.<Module>of(new SLF4JLoggingModule());

    // The metadata must be registered because the ServiceLoader does not detect
    // the META-INF/services in each api JAR under Tomcat/Spring. Fortunately,
    // the registry is static and is not really OSGi specific for this use.
    ApiRegistry.registerApi(new SwiftApiMetadata());
    ProviderRegistry.registerProvider(new AWSS3ProviderMetadata());

    context = ContextBuilder.newBuilder(provider)
            .credentials(identity, credential)
            .modules(modules)
            .buildView(BlobStoreContext.class);

    // There are some oddities with streaming larger files to the user,
    // so download to a temp file first. For now, call 100MB the threshold.
    maxBlobStreamSize = (long) serverConfigurationService.getInt("cloud.content.maxblobstream.size", 1024 * 1024 * 100);
    temporaryBlobDirectory = serverConfigurationService.getString("cloud.content.temporary.directory", null);
    
    if (temporaryBlobDirectory != null) {
        File baseDir = new File(temporaryBlobDirectory);
        if (!baseDir.exists()) {
            try {
                // Can't write into the preferred temp dir
                if (!baseDir.mkdirs()) {
                    temporaryBlobDirectory = null;
                }
            }
            catch (SecurityException se) {
                // JVM security hasn't whitelisted this dir
                temporaryBlobDirectory = null;
            }
        }
    }
}
 
Example #25
Source File: NeutronNetworkingApi.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
private void buildNeutronApi() {

        String iaasProviderNullMsg = "IaasProvider is null. Unable to build neutron API";
        assertNotNull(iaasProvider, iaasProviderNullMsg);

        String region = ComputeServiceBuilderUtil.extractRegion(iaasProvider);
        String regionNullOrEmptyErrorMsg = String.format("Region is not set. Unable to build neutron API for the iaas provider %s",
                iaasProvider.getProvider());
        assertNotNullAndNotEmpty(region, regionNullOrEmptyErrorMsg);

        String endpoint = iaasProvider.getProperty(CloudControllerConstants.JCLOUDS_ENDPOINT);
        String endpointNullOrEmptyErrorMsg = String.format("Endpoint is not set. Unable to build neutorn API for the iaas provider %s",
                iaasProvider.getProvider());
        assertNotNullAndNotEmpty(endpoint, endpointNullOrEmptyErrorMsg);

        Iterable<Module> modules = ImmutableSet.<Module>of(new SLF4JLoggingModule());

        try {
            this.neutronApi = ContextBuilder.newBuilder(provider).credentials(iaasProvider.getIdentity(),
                    iaasProvider.getCredential()).endpoint(endpoint).modules(modules).buildApi(NeutronApi.class);
        } catch (Exception e) {
            String msg = String.format("Unable to build neutron API for [provider=%s, identity=%s, credential=%s, endpoint=%s]",
                    provider, iaasProvider.getIdentity(), iaasProvider.getCredential(), endpoint);
            log.error(msg, e);
            throw new CloudControllerException(msg, e);
        }

        this.portApi = neutronApi.getPortApi(region);
        String portApiNullOrEmptyErrorMessage = String.format("Unable to get port Api from neutron Api for region ", region);
        assertNotNull(portApi, portApiNullOrEmptyErrorMessage);

        this.floatingIPApi = neutronApi.getFloatingIPApi(region).get();
        String floatingIPApiNullOrEmptyErrorMessage = String.format("Unable to get floatingIP Api from neutron Api for region ", region);
        assertNotNull(floatingIPApi, floatingIPApiNullOrEmptyErrorMessage);
    }
 
Example #26
Source File: BlobStoreContextFactoryImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/** returns the jclouds modules we typically install */ 
protected ImmutableSet<Module> getCommonModules() {
    return ImmutableSet.<Module> of(
            new SshjSshClientModule(),
            new SLF4JLoggingModule(),
            new BouncyCastleCryptoModule());
}
 
Example #27
Source File: AbstractComputeServiceRegistry.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/**
 * returns the jclouds modules we typically install
 */
protected Iterable<? extends Module> commonModules() {
    return ImmutableSet.<Module>of(
            new SshjSshClientModule(),
            new SLF4JLoggingModule(),
            new BouncyCastleCryptoModule());
}
 
Example #28
Source File: ReadOnlyBlobStoreTest.java    From s3proxy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    containerName = createRandomContainerName();

    context = ContextBuilder
            .newBuilder("transient")
            .credentials("identity", "credential")
            .modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
            .build(BlobStoreContext.class);
    blobStore = context.getBlobStore();
    blobStore.createContainerInLocation(null, containerName);
    readOnlyBlobStore = ReadOnlyBlobStore.newReadOnlyBlobStore(blobStore);
}
 
Example #29
Source File: JcloudsUtil.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static Map<Integer, Integer> dockerPortMappingsFor(JcloudsLocation docker, String containerId) {
    ComputeServiceContext context = null;
    try {
        Properties properties = new Properties();
        properties.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, Boolean.toString(true));
        properties.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, Boolean.toString(true));
        context = ContextBuilder.newBuilder("docker")
                .endpoint(docker.getEndpoint())
                .credentials(docker.getIdentity(), docker.getCredential())
                .overrides(properties)
                .modules(ImmutableSet.<Module>of(new SLF4JLoggingModule(), new SshjSshClientModule()))
                .build(ComputeServiceContext.class);
        DockerApi api = context.unwrapApi(DockerApi.class);
        Container container = api.getContainerApi().inspectContainer(containerId);
        Map<Integer, Integer> portMappings = Maps.newLinkedHashMap();
        Map<String, List<Map<String, String>>> ports = container.networkSettings().ports();
        if (ports == null) ports = ImmutableMap.<String, List<Map<String,String>>>of();

        LOG.debug("Docker will forward these ports {}", ports);
        for (Map.Entry<String, List<Map<String, String>>> entrySet : ports.entrySet()) {
            String containerPort = Iterables.get(Splitter.on("/").split(entrySet.getKey()), 0);
            String hostPort = Iterables.getOnlyElement(Iterables.transform(entrySet.getValue(),
                    new Function<Map<String, String>, String>() {
                        @Override
                        public String apply(Map<String, String> hostIpAndPort) {
                            return hostIpAndPort.get("HostPort");
                        }
                    }));
            portMappings.put(Integer.parseInt(containerPort), Integer.parseInt(hostPort));
        }
        return portMappings;
    } finally {
        if (context != null) {
            context.close();
        }
    }
}
 
Example #30
Source File: NullBlobStoreTest.java    From s3proxy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    containerName = createRandomContainerName();

    context = ContextBuilder
            .newBuilder("transient")
            .credentials("identity", "credential")
            .modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
            .build(BlobStoreContext.class);
    blobStore = context.getBlobStore();
    blobStore.createContainerInLocation(null, containerName);

    nullBlobStore = NullBlobStore.newNullBlobStore(blobStore);
}