Java源码示例:org.jclouds.domain.LocationScope
示例1
@Override
protected NodeMetadata newNode(String group, Template template) {
int suffix = counter.getAndIncrement();
org.jclouds.domain.Location region = new LocationBuilder()
.scope(LocationScope.REGION)
.id("us-east-1")
.description("us-east-1")
.parent(new LocationBuilder()
.scope(LocationScope.PROVIDER)
.id("aws-ec2")
.description("aws-ec2")
.build())
.build();
NodeMetadata result = new NodeMetadataBuilder()
.id("mynodeid"+suffix)
.credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build())
.loginPort(22)
.status(Status.RUNNING)
.publicAddresses(ImmutableList.of("173.194.32."+suffix))
.privateAddresses(ImmutableList.of("172.168.10."+suffix))
.location(region)
.build();
return result;
}
示例2
@Test(groups={"Live"})
public void testSubLocationIsUsable() throws Exception {
String zoneName = REGION_NAME+"b";
List<Location> subLocations = zoneExtension.getSubLocationsByName(Predicates.equalTo(zoneName), Integer.MAX_VALUE);
JcloudsLocation subLocation = (JcloudsLocation) Iterables.getOnlyElement(subLocations);
JcloudsSshMachineLocation machine = null;
try {
machine = (JcloudsSshMachineLocation)subLocation.obtain(ImmutableMap.builder()
.put(JcloudsLocation.IMAGE_ID, US_EAST_IMAGE_ID)
.put(JcloudsLocation.HARDWARE_ID, SMALL_HARDWARE_ID)
.put(JcloudsLocation.INBOUND_PORTS, ImmutableList.of(22))
.build());
org.jclouds.domain.Location machineLoc = machine.getNode().getLocation();
assertEquals(machineLoc.getScope(), LocationScope.ZONE, "machineLoc="+machineLoc);
assertEquals(machineLoc.getId(), zoneName, "machineLoc="+machineLoc);
} finally {
if (machine != null) {
subLocation.release(machine);
}
}
}
示例3
private static Location createRegionLocation( BlobStoreProperties config, Location provider )
{
return config.location != null ?
new LocationBuilder()
.scope( LocationScope.REGION )
.id( config.location )
.description( config.location )
.parent( provider )
.build() : null;
}
示例4
private static Location createRegionLocation( BlobStoreProperties config, Location provider )
{
return config.location != null ?
new LocationBuilder()
.scope( LocationScope.REGION )
.id( config.location )
.description( config.location )
.parent( provider )
.build() : null;
}
示例5
BlobStoreManagedLedgerOffloader(String driver, String container, OrderedScheduler scheduler,
int maxBlockSize, int readBufferSize,
String endpoint, String region, Supplier<Credentials> credentials,
Map<String, String> userMetadata) {
this.offloadDriverName = driver;
this.scheduler = scheduler;
this.readBufferSize = readBufferSize;
this.writeBucket = container;
this.writeRegion = region;
this.writeEndpoint = endpoint;
this.maxBlockSize = maxBlockSize;
this.userMetadata = userMetadata;
this.credentials = credentials;
if (!Strings.isNullOrEmpty(region)) {
this.writeLocation = new LocationBuilder()
.scope(LocationScope.REGION)
.id(region)
.description(region)
.build();
} else {
this.writeLocation = null;
}
log.info("Constructor offload driver: {}, host: {}, container: {}, region: {} ",
driver, endpoint, container, region);
Pair<BlobStoreLocation, BlobStore> blobStore = createBlobStore(
driver, region, endpoint, credentials, maxBlockSize
);
this.writeBlobStore = blobStore.getRight();
this.readBlobStores.put(blobStore.getLeft(), blobStore.getRight());
}
示例6
protected String extractNodeLocationId(ConfigBag setup, NodeMetadata node, LocationScope scope) {
org.jclouds.domain.Location nodeLoc = node.getLocation();
if(nodeLoc == null) return null;
do {
if (nodeLoc.getScope() == scope) return nodeLoc.getId();
nodeLoc = nodeLoc.getParent();
} while (nodeLoc != null);
return null;
}
示例7
public JcloudsStubTemplateBuilder(String providerName, String regionName) {
this.providerName = providerName;
this.regionName = regionName;
this.provider = new LocationBuilder().scope(LocationScope.PROVIDER).id(providerName).description(providerName).build();
this.jcloudsDomainLocation = new LocationBuilder().scope(LocationScope.REGION).id(this.regionName).description(this.regionName)
.parent(provider).build();
}
示例8
private void createContainer() throws IOException {
// Ensure that the container exists
Location location = new LocationBuilder().scope(LocationScope.REGION).id(REGION).description("region").build();
if (!blobStore.containerExists(CONTAINER)) {
blobStore.createContainerInLocation(location, CONTAINER);
System.out.format("Created container in %s%n", REGION);
}
}
示例9
protected String extractAvailabilityZone(ConfigBag setup, NodeMetadata node) {
return extractNodeLocationId(setup, node, LocationScope.ZONE);
}
示例10
protected String extractRegion(ConfigBag setup, NodeMetadata node) {
return extractNodeLocationId(setup, node, LocationScope.REGION);
}
示例11
protected String extractProvider(ConfigBag setup, NodeMetadata node) {
return extractNodeLocationId(setup, node, LocationScope.PROVIDER);
}
示例12
@Test(groups={"Live", "Live-sanity"})
public void testRebind() throws Exception {
LocationImpl locImpl = new LocationImpl(
LocationScope.REGION,
"myLocId",
"myLocDescription",
null,
ImmutableList.<String>of(), // iso3166Codes
ImmutableMap.<String,Object>of()); // metadata
NodeMetadata node = new NodeMetadataImpl(
"softlayer",
"myname",
"123", // ids in SoftLayer are numeric
locImpl,
URI.create("http://myuri.com"),
ImmutableMap.<String, String>of(), // userMetadata
ImmutableSet.<String>of(), // tags
"mygroup",
new HardwareImpl(
"myHardwareProviderId",
"myHardwareName",
"myHardwareId",
locImpl,
URI.create("http://myuri.com"),
ImmutableMap.<String, String>of(), // userMetadata
ImmutableSet.<String>of(), // tags
ImmutableList.<Processor>of(),
1024,
ImmutableList.<Volume>of(),
Predicates.<Image>alwaysTrue(), // supportsImage,
(String)null, // hypervisor
false),
IMAGE_ID,
new OperatingSystem(
OsFamily.CENTOS,
"myOsName",
"myOsVersion",
"myOsArch",
"myDescription",
true), // is64Bit
Status.RUNNING,
"myBackendStatus",
22, // login-port
ImmutableList.of("1.2.3.4"), // publicAddresses,
ImmutableList.of("10.2.3.4"), // privateAddresses,
LoginCredentials.builder().identity("myidentity").password("mypassword").build(),
"myHostname");
StubbedComputeServiceRegistry computeServiceRegistry = new StubbedComputeServiceRegistry(node);
JcloudsLocation origJcloudsLoc = newJcloudsLocation(computeServiceRegistry);
JcloudsSshMachineLocation origMachine = (JcloudsSshMachineLocation) obtainMachine(origJcloudsLoc, ImmutableMap.of("imageId", IMAGE_ID));
String origHostname = origMachine.getHostname();
NodeMetadata origNode = origMachine.getNode();
rebind();
// Check the machine is as before.
// Call to getOptionalNode() will cause it to try to resolve this node in Softlayer; but it won't find it.
JcloudsSshMachineLocation newMachine = (JcloudsSshMachineLocation) newManagementContext.getLocationManager().getLocation(origMachine.getId());
JcloudsLocation newJcloudsLoc = newMachine.getParent();
String newHostname = newMachine.getHostname();
String newNodeId = newMachine.getJcloudsId();
Optional<NodeMetadata> newNode = newMachine.getOptionalNode();
Optional<Template> newTemplate = newMachine.getOptionalTemplate();
assertEquals(newHostname, origHostname);
assertEquals(origNode.getId(), newNodeId);
assertFalse(newNode.isPresent(), "newNode="+newNode);
assertFalse(newTemplate.isPresent(), "newTemplate="+newTemplate);
assertEquals(newJcloudsLoc.getProvider(), origJcloudsLoc.getProvider());
}