Search in sources :

Example 1 with Location

use of org.jclouds.domain.Location in project whirr by apache.

the class RunningInstanceToNodeMetadata method getLocationForAvailabilityZone.

private Location getLocationForAvailabilityZone(final RunningInstance instance) {
    final String locationId = instance.getAvailabilityZone();
    Location location = Iterables.find(locations, new Predicate<Location>() {

        @Override
        public boolean apply(Location input) {
            return input.getId().equals(locationId);
        }
    });
    return location;
}
Also used : Location(org.jclouds.domain.Location)

Example 2 with Location

use of org.jclouds.domain.Location in project legacy-jclouds-examples by jclouds.

the class MainApp method run.

private void run() throws Exception {
    Properties overrides = new Properties();
    overrides.put(AWSEC2Constants.PROPERTY_EC2_AMI_QUERY, "owner-id=" + arguments.getAmiOwner() + ";state=available;image-type=machine");
    ImmutableSet<Module> modules = ImmutableSet.<Module>of(// OverThere uses SLF4J so we will as well
    new SLF4JLoggingModule(), // needed to decrypt the password from EC2
    new BouncyCastleCryptoModule());
    context = ContextBuilder.newBuilder("aws-ec2").credentials(arguments.getIdentity(), arguments.getCredential()).overrides(overrides).modules(modules).build(ComputeServiceContext.class);
    try {
        computeService = context.getComputeService();
        Set<String> regions = Sets.newHashSet(Iterables.transform(Iterables.filter(computeService.listAssignableLocations(), LocationPredicates.isRegion()), new Function<Location, String>() {

            @Override
            public String apply(@Nullable Location location) {
                return (location != null) ? location.getId() : null;
            }
        }));
        if (!regions.contains(arguments.getRegion())) {
            System.err.println("Region \"" + arguments.getRegion() + "\" is not known. Known regions are:");
            for (String r : regions) {
                System.err.println("    " + r);
            }
            System.exit(1);
        }
        WindowsInstanceStarter app = new WindowsInstanceStarter(arguments, context);
        app.run();
    } finally {
        context.close();
    }
}
Also used : Function(com.google.common.base.Function) SLF4JLoggingModule(org.jclouds.logging.slf4j.config.SLF4JLoggingModule) BouncyCastleCryptoModule(org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) Properties(java.util.Properties) Module(com.google.inject.Module) SLF4JLoggingModule(org.jclouds.logging.slf4j.config.SLF4JLoggingModule) BouncyCastleCryptoModule(org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule) Nullable(javax.annotation.Nullable) Location(org.jclouds.domain.Location)

Example 3 with Location

use of org.jclouds.domain.Location in project legacy-jclouds-examples by jclouds.

the class CreateServer method getLocationId.

/**
 * This method uses the generic ComputeService.listAssignableLocations() to find the location.
 *
 * @return The first available Location
 */
private String getLocationId() {
    System.out.println("Locations");
    Set<? extends Location> locations = compute.listAssignableLocations();
    for (Location location : locations) {
        System.out.println("  " + location);
    }
    return locations.iterator().next().getId();
}
Also used : Location(org.jclouds.domain.Location)

Example 4 with Location

use of org.jclouds.domain.Location in project dhis2-core by dhis2.

the class JCloudsFileResourceContentStore method init.

// -------------------------------------------------------------------------
// Life cycle management
// -------------------------------------------------------------------------
@PostConstruct
public void init() {
    // ---------------------------------------------------------------------
    // Bootstrap config
    // ---------------------------------------------------------------------
    config = new BlobStoreProperties(configurationProvider.getProperty(ConfigurationKey.FILESTORE_PROVIDER), configurationProvider.getProperty(ConfigurationKey.FILESTORE_LOCATION), configurationProvider.getProperty(ConfigurationKey.FILESTORE_CONTAINER));
    Pair<Credentials, Properties> providerConfig = configureForProvider(config.provider, configurationProvider.getProperty(ConfigurationKey.FILESTORE_IDENTITY), configurationProvider.getProperty(ConfigurationKey.FILESTORE_SECRET));
    // ---------------------------------------------------------------------
    // Set up JClouds context
    // ---------------------------------------------------------------------
    blobStoreContext = ContextBuilder.newBuilder(config.provider).credentials(providerConfig.getLeft().identity, providerConfig.getLeft().credential).overrides(providerConfig.getRight()).build(BlobStoreContext.class);
    blobStore = blobStoreContext.getBlobStore();
    Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id(config.provider).description(config.provider).build();
    try {
        blobStore.createContainerInLocation(createRegionLocation(config, provider), config.container);
        log.info(String.format("File store configured with provider: '%s', container: '%s' and location: '%s'.", config.provider, config.container, config.location));
    } catch (HttpResponseException ex) {
        log.error(String.format("Could not configure file store with provider '%s' and container '%s'.\n" + "File storage will not be available.", config.provider, config.container), ex);
    } catch (AuthorizationException ex) {
        log.error(String.format("Could not authenticate with file store provider '%s' and container '%s'. " + "File storage will not be available.", config.provider, config.location), ex);
    }
}
Also used : LocationBuilder(org.jclouds.domain.LocationBuilder) AuthorizationException(org.jclouds.rest.AuthorizationException) HttpResponseException(org.jclouds.http.HttpResponseException) Credentials(org.jclouds.domain.Credentials) Location(org.jclouds.domain.Location) PostConstruct(javax.annotation.PostConstruct)

Example 5 with Location

use of org.jclouds.domain.Location in project ignite by apache.

the class TcpDiscoveryCloudIpFinder method initComputeService.

/**
 * Initializes Apache jclouds compute service.
 */
private void initComputeService() {
    if (initGuard.compareAndSet(false, true))
        try {
            if (provider == null)
                throw new IgniteSpiException("Cloud provider is not set.");
            if (identity == null)
                throw new IgniteSpiException("Cloud identity is not set.");
            if (credential != null && credentialPath != null)
                throw new IgniteSpiException("Both credential and credentialPath are set. Use only one method.");
            if (credentialPath != null)
                credential = getCredentialFromFile();
            try {
                ContextBuilder ctxBuilder = ContextBuilder.newBuilder(provider);
                ctxBuilder.credentials(identity, credential);
                Properties properties = new Properties();
                properties.setProperty(Constants.PROPERTY_SO_TIMEOUT, JCLOUD_CONNECTION_TIMEOUT);
                properties.setProperty(Constants.PROPERTY_CONNECTION_TIMEOUT, JCLOUD_CONNECTION_TIMEOUT);
                if (!F.isEmpty(regions))
                    properties.setProperty(LocationConstants.PROPERTY_REGIONS, keysSetToStr(regions));
                if (!F.isEmpty(zones))
                    properties.setProperty(LocationConstants.PROPERTY_ZONES, keysSetToStr(zones));
                ctxBuilder.overrides(properties);
                computeService = ctxBuilder.buildView(ComputeServiceContext.class).getComputeService();
                if (!F.isEmpty(zones) || !F.isEmpty(regions)) {
                    nodesFilter = new Predicate<ComputeMetadata>() {

                        @Override
                        public boolean apply(ComputeMetadata computeMetadata) {
                            String region = null;
                            String zone = null;
                            Location location = computeMetadata.getLocation();
                            while (location != null) {
                                switch(location.getScope()) {
                                    case ZONE:
                                        zone = location.getId();
                                        break;
                                    case REGION:
                                        region = location.getId();
                                        break;
                                }
                                location = location.getParent();
                            }
                            if (regions != null && region != null && !regions.contains(region))
                                return false;
                            if (zones != null && zone != null && !zones.contains(zone))
                                return false;
                            return true;
                        }
                    };
                }
            } catch (Exception e) {
                throw new IgniteSpiException("Failed to connect to the provider: " + provider, e);
            }
        } finally {
            initLatch.countDown();
        }
    else {
        try {
            U.await(initLatch);
        } catch (IgniteInterruptedCheckedException e) {
            throw new IgniteSpiException("Thread has been interrupted.", e);
        }
        if (computeService == null)
            throw new IgniteSpiException("Ip finder has not been initialized properly.");
    }
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ContextBuilder(org.jclouds.ContextBuilder) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ComputeMetadata(org.jclouds.compute.domain.ComputeMetadata) Properties(java.util.Properties) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException) Predicate(com.google.common.base.Predicate) Location(org.jclouds.domain.Location)

Aggregations

Location (org.jclouds.domain.Location)7 Properties (java.util.Properties)3 Credentials (org.jclouds.domain.Credentials)3 PostConstruct (javax.annotation.PostConstruct)2 ComputeServiceContext (org.jclouds.compute.ComputeServiceContext)2 LocationBuilder (org.jclouds.domain.LocationBuilder)2 HttpResponseException (org.jclouds.http.HttpResponseException)2 AuthorizationException (org.jclouds.rest.AuthorizationException)2 Function (com.google.common.base.Function)1 Predicate (com.google.common.base.Predicate)1 Module (com.google.inject.Module)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Nullable (javax.annotation.Nullable)1 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)1 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)1 ContextBuilder (org.jclouds.ContextBuilder)1 BlobStoreContext (org.jclouds.blobstore.BlobStoreContext)1 ComputeMetadata (org.jclouds.compute.domain.ComputeMetadata)1 Image (org.jclouds.compute.domain.Image)1