/** {@inheritDoc} */ @Override public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException { initComputeService(); Collection<InetSocketAddress> addresses = new LinkedList<>(); try { Set<NodeMetadata> nodes; if (nodesFilter != null) nodes = (Set<NodeMetadata>)computeService.listNodesDetailsMatching(nodesFilter); else { nodes = new HashSet<>(); for (ComputeMetadata metadata : computeService.listNodes()) nodes.add(computeService.getNodeMetadata(metadata.getId())); } for (NodeMetadata metadata : nodes) { if (metadata.getStatus() != NodeMetadata.Status.RUNNING) continue; for (String addr : metadata.getPrivateAddresses()) addresses.add(new InetSocketAddress(addr, 0)); for (String addr : metadata.getPublicAddresses()) addresses.add(new InetSocketAddress(addr, 0)); } } catch (Exception e) { throw new IgniteSpiException("Failed to get registered addresses for the provider: " + provider, e); } return addresses; }
@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; } };
public static ComputeMetadataBuilder fromComputeMetadata(ComputeMetadata in) { return new ComputeMetadataBuilder(in.getType()).id(in.getId()).location(in.getLocation()).name(in.getName()) .uri(in.getUri()).userMetadata(in.getUserMetadata()).tags(in.getTags()); } }
/** * {@inheritDoc} */ @Override public int compareTo(ResourceMetadata<ComputeType> that) { if (that instanceof ComputeMetadata) { ComputeMetadata thatMetadata = ComputeMetadata.class.cast(that); return start() .compare(this.getId(), thatMetadata.getId()) .compare(this.getType(), thatMetadata.getType()) .compare(this.getName(), that.getName(), natural().nullsLast()) .result(); } else { return super.compareTo(that); } }
private void list(ComputeService computeService) { log("list"); for (ComputeMetadata node : computeService.listNodes()) { log(String.format(" location=%s, id=%s, group=%s", node.getLocation(), node.getProviderId(), node.getName())); } }
@Override public boolean apply(ComputeMetadata input) { return input.getName().equalsIgnoreCase(name); } });
@Test(enabled = true, dependsOnMethods = "testSuspendResume") public void testListNodes() throws Exception { for (ComputeMetadata node : client.listNodes()) { assert node.getProviderId() != null : node; assert node.getLocation() != null : node; assertEquals(node.getType(), ComputeType.NODE); } }
@Test(enabled = true, dependsOnMethods = "testGet") public void testReboot() throws Exception { Set<? extends NodeMetadata> rebootNodes = client.rebootNodesMatching(inGroup(group)); for (ComputeMetadata node : rebootNodes) { assertNotNull(node); assert node.getProviderId() != null : node; assert node.getLocation() != null : node; } // validation testGet(); }
@Override public String apply(ComputeMetadata from) { return from.getProviderId(); } };
@Override public boolean apply(ComputeMetadata nodeMetadata) { if (nodeMetadata == null) { return false; } if (tagPairs.size() > nodeMetadata.getUserMetadata().size()) { return false; } for (AbstractMap.SimpleImmutableEntry entry : tagPairs) { String value = nodeMetadata.getUserMetadata().get(entry.getKey()); if (value == null || !value.equals(entry.getValue())) { return false; } } return true; } };
public static ComputeMetadataBuilder fromComputeMetadata(ComputeMetadata in) { return new ComputeMetadataBuilder(in.getType()).id(in.getId()).location(in.getLocation()).name(in.getName()) .uri(in.getUri()).userMetadata(in.getUserMetadata()).tags(in.getTags()); } }
public void testListLocationsWhenResponseIs2xx() throws Exception { Map<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder() .put(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess) .put(extensionsOfNovaRequest, extensionsOfNovaResponse).put(listDetail, listDetailResponse) .put(listServers, listServersResponse).put(listFlavorsDetail, listFlavorsDetailResponse).build(); ComputeService apiWhenServersExist = requestsSendResponses(requestResponseMap); Set<? extends Location> locations = apiWhenServersExist.listAssignableLocations(); assertNotNull(locations); assertEquals(locations.size(), 1); assertEquals(locations.iterator().next().getId(), "az-1.region-a.geo-1"); assertNotNull(apiWhenServersExist.listNodes()); assertEquals(apiWhenServersExist.listNodes().size(), 1); assertEquals(apiWhenServersExist.listNodes().iterator().next().getId(), "az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f000004d2"); assertEquals(apiWhenServersExist.listNodes().iterator().next().getName(), "sample-server"); }
/** * {@inheritDoc} */ @Override public int compareTo(ResourceMetadata<ComputeType> that) { if (that instanceof ComputeMetadata) { ComputeMetadata thatMetadata = ComputeMetadata.class.cast(that); return start() .compare(this.getId(), thatMetadata.getId()) .compare(this.getType(), thatMetadata.getType()) .compare(this.getName(), that.getName(), natural().nullsLast()) .result(); } else { return super.compareTo(that); } }
@Override public boolean apply(ComputeMetadata input) { return name.equals(input.getName()); }
@Test(enabled = true, dependsOnMethods = "testSuspendResume") public void testListNodes() throws Exception { for (ComputeMetadata node : client.listNodes()) { assert node.getProviderId() != null : node; assert node.getLocation() != null : node; assertEquals(node.getType(), ComputeType.NODE); } }
@Test(enabled = true, dependsOnMethods = "testReboot") public void testSuspendResume() throws Exception { Set<? extends NodeMetadata> suspendedNodes = client.suspendNodesMatching(inGroup(group)); for (ComputeMetadata node : suspendedNodes) { assertNotNull(node); assert node.getProviderId() != null : node; assert node.getLocation() != null : node; } Set<? extends NodeMetadata> stoppedNodes = refreshNodes(); assert Iterables.all(stoppedNodes, new Predicate<NodeMetadata>() { @Override public boolean apply(NodeMetadata input) { boolean returnVal = input.getStatus() == Status.SUSPENDED; if (!returnVal) getAnonymousLogger().warning(format("node %s in state %s%n", input.getId(), input.getStatus())); return returnVal; } }) : stoppedNodes; Set<? extends NodeMetadata> resumedNodes = client.resumeNodesMatching(inGroup(group)); for (ComputeMetadata node : resumedNodes) { assertNotNull(node); assert node.getProviderId() != null : node; assert node.getLocation() != null : node; } testGet(); }
@Override public String apply(ComputeMetadata from) { return from.getProviderId(); } };
@Override public boolean apply(T nodeMetadata) { return search.contains(nodeMetadata.getId()); }
public static ComputeMetadataBuilder fromComputeMetadata(ComputeMetadata in) { return new ComputeMetadataBuilder(in.getType()).id(in.getId()).location(in.getLocation()).name(in.getName()) .uri(in.getUri()).userMetadata(in.getUserMetadata()).tags(in.getTags()); } }