org.jclouds.domain.LocationScope Java Examples

The following examples show how to use org.jclouds.domain.LocationScope. 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: StubbedComputeServiceRegistry.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #2
Source File: AwsAvailabilityZoneExtensionTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@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);
        }
    }
}
 
Example #3
Source File: JCloudsAppStorageService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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;
}
 
Example #4
Source File: JCloudsFileResourceContentStore.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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;
}
 
Example #5
Source File: BlobStoreManagedLedgerOffloader.java    From pulsar with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example #6
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #7
Source File: JcloudsStubTemplateBuilder.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #8
Source File: GenerateTempURL.java    From jclouds-examples with Apache License 2.0 5 votes vote down vote up
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);
   }
}
 
Example #9
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
protected String extractAvailabilityZone(ConfigBag setup, NodeMetadata node) {
    return extractNodeLocationId(setup, node, LocationScope.ZONE);
}
 
Example #10
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
protected String extractRegion(ConfigBag setup, NodeMetadata node) {
    return extractNodeLocationId(setup, node, LocationScope.REGION);
}
 
Example #11
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
protected String extractProvider(ConfigBag setup, NodeMetadata node) {
    return extractNodeLocationId(setup, node, LocationScope.PROVIDER);
}
 
Example #12
Source File: JcloudsRebindStubTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@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());
}