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;
}
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();
}
}
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();
}
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);
}
}
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.");
}
}
Aggregations