@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; } };
if (locationString != null) { for (Location loc : blobStore.listAssignableLocations()) { if (loc.getId().equalsIgnoreCase(locationString)) { location = loc; break;
@Override public String toString() { ToStringHelper helper = Objects.toStringHelper("").omitNullValues().add("scope", scope).add("id", id) .add("description", description); if (parent != null) helper.add("parent", parent.getId()); if (iso3166Codes.size() > 0) helper.add("iso3166Codes", iso3166Codes); if (metadata.size() > 0) helper.add("metadata", metadata); return helper.toString(); }
@Override public boolean apply(Location input) { ReferenceType defaultVDC = defaultVDCSupplier.get(); return input.getScope() == LocationScope.ZONE && input.getId().equals(defaultVDC.getHref().toASCIIString()); }
@Override public ListenableFuture<String> getBucketLocation(String bucketName) { Location location = containerToLocation.get(bucketName); return immediateFuture(location.getId()); }
@Override public ListenableFuture<Boolean> createContainerInLocation(Location location, String container, CreateContainerOptions options) { PutBucketOptions putBucketOptions = new PutBucketOptions(); if (options.isPublicRead()) putBucketOptions.withBucketAcl(CannedAccessPolicy.PUBLIC_READ); location = location != null ? location : defaultLocation.get(); return async.putBucketInRegion(location.getId(), container, putBucketOptions); }
@Override public boolean createContainerInLocation(Location location, String container, CreateContainerOptions options) { PutBucketOptions putBucketOptions = new PutBucketOptions(); if (options.isPublicRead()) putBucketOptions.withBucketAcl(CannedAccessPolicy.PUBLIC_READ); location = location != null ? location : defaultLocation.get(); return sync.putBucketInRegion(location.getId(), container, putBucketOptions); } }
@Override public boolean apply(ComputeMetadata nodeMetadata) { if (nodeMetadata.getLocation().getParent() == null) return false; return id.equals(nodeMetadata.getLocation().getParent().getId()); }
@Test public void testFindRegion() { Supplier<Set<? extends Location>> supplier = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet .<Location> of(provider, region, region2, zone)); OnlyLocationOrFirstRegionOptionallyMatchingRegionId fn = new OnlyLocationOrFirstRegionOptionallyMatchingRegionId( Suppliers.ofInstance(region2.getId()), supplier); assertEquals(fn.get(), region2); } }
@Override public boolean apply(Image input) { return input.getProviderId().equals(instance.getImage().getId() + "") && (input.getLocation() == null || input.getLocation().getId().equals( instance.getDatacenter().getId() + "")); } }
@Override public NodeAndInitialCredentials<Server> createNodeWithGroupEncodedIntoName(String tag, String name, Template template) { // create the backend object using parameters from the template. Server from = client.createServerInDC(template.getLocation().getId(), name, Integer.parseInt(template.getImage().getProviderId()), Integer.parseInt(template.getHardware().getProviderId())); return new NodeAndInitialCredentials<Server>(from, from.id + "", LoginCredentials.builder().user(from.loginUser) .password(from.password).build()); }
@Override public Map<?, ListenableFuture<Void>> execute(String tag, int count, Template template, Set<NodeMetadata> goodNodes, Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) { assert template.getLocation().getParent().getScope() == LocationScope.REGION : "template location should have a parent of org, which should be mapped to region: " + template.getLocation(); String orgId = template.getLocation().getParent().getId(); assert orgId.startsWith("http") : "parent id should be a rest url: " + template.getLocation().getParent(); createNewKeyPairUnlessUserSpecifiedOtherwise.execute(URI.create(orgId), tag, template.getImage() .getDefaultCredentials().identity, template.getOptions().as(TerremarkVCloudTemplateOptions.class)); return super.execute(tag, count, template, goodNodes, badNodes, customizationResponses); } }
private void checkTemplate(Template defaultTemplate) { assertEquals(defaultTemplate.getImage().getId(), "RegionOne/15"); assertEquals(defaultTemplate.getImage().getProviderId(), "15"); assertEquals(defaultTemplate.getHardware().getId(), "RegionOne/1"); assertEquals(defaultTemplate.getHardware().getProviderId(), "1"); assertEquals(defaultTemplate.getLocation().getId(), "RegionOne"); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); }
@Test public void testGetIso3166CodeNoCountryAndState() { Datacenter datacenter = Datacenter.builder().id(1).longName("Nowhere").build(); Location location = function.apply(datacenter); assertEquals(location.getId(), Long.toString(datacenter.getId())); Set<String> iso3166Codes = location.getIso3166Codes(); assertEquals(iso3166Codes.size(), 0); }
@Test public void testGetIso3166CodeCountryOnly() { Address address = Address.builder().country("US").description("This is North America!").build(); Datacenter datacenter = Datacenter.builder().id(1).longName("Nowhere").locationAddress(address).build(); Location location = function.apply(datacenter); assertEquals(location.getId(), Long.toString(datacenter.getId())); Set<String> iso3166Codes = location.getIso3166Codes(); assertEquals(iso3166Codes.size(), 1); assertTrue(iso3166Codes.contains("US")); }
@Test public void testGetIso3166CodeWhitespaceTrimmer() { Address address = Address.builder().country(" US ").state(" TX ").description("This is spaced out Texas") .build(); Datacenter datacenter = Datacenter.builder().id(1).longName("Nowhere").locationAddress(address).build(); Location location = function.apply(datacenter); assertEquals(location.getId(), Long.toString(datacenter.getId())); Set<String> iso3166Codes = location.getIso3166Codes(); assertEquals(iso3166Codes.size(), 1); assertTrue(iso3166Codes.contains("US-TX")); } }
@Test(enabled = true, dependsOnMethods = "testCorrectAuthException") public void testImagesResolveCorrectly() { Template defaultTemplate = client.templateBuilder().build(); assertEquals(defaultTemplate.getImage().getId(), defaultTemplate.getImage().getLocation().getId() + "/" + defaultTemplate.getImage().getProviderId()); Template byId = client.templateBuilder().imageId(defaultTemplate.getImage().getId()).build(); assertEquals(byId.getImage(), defaultTemplate.getImage()); }
@Test public void testTemplateBuilderCanUseImageId() throws Exception { Template defaultTemplate = view.getComputeService().templateBuilder().build(); view.close(); setupContext(); Template template = view.getComputeService().templateBuilder().imageId(defaultTemplate.getImage().getId()) .locationId(defaultTemplate.getLocation().getId()).build(); assertEquals(template.getImage(), defaultTemplate.getImage()); }