/** {@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(NodeMetadata nodeMetadata) { return nodeMetadata.getStatus() == Status.RUNNING; }
@Override public boolean apply(NodeMetadata nodeMetadata) { return nodeMetadata.getStatus() == Status.TERMINATED; }
@Override public boolean apply(NodeMetadata node) { return !node.getStatus().equals(NodeMetadata.Status.RUNNING); } }
private void checkStateAvailable(NodeMetadata node) { checkState(node != null && node.getStatus() != Status.TERMINATED, "node %s terminated or unavailable! current status: %s", node, formatStatus(node)); }
@Override public boolean apply(HostAndPort input) { if (input.getHostText().indexOf(publicIpPrefix) == -1) return false; String id = input.getHostText().replace(publicIpPrefix, ""); NodeMetadata node = nodes.get(id); return node != null && node.getStatus() == Status.RUNNING; }
@Override public boolean apply(HostAndPort input) { if (input.getHostText().indexOf(publicIpPrefix) == -1) return false; String id = input.getHostText().replace(publicIpPrefix, ""); NodeMetadata node = nodes.get(id); return node != null && node.getStatus() == Status.RUNNING; }
@Override public boolean apply(HostAndPort input) { if (input.getHostText().indexOf(publicIpPrefix) == -1) return false; String id = input.getHostText().replace(publicIpPrefix, ""); NodeMetadata node = nodes.get(id); return node != null && node.getStatus() == Status.RUNNING; }
@Override public void resumeNode(String id) { NodeMetadata node = nodes.get(id); if (node == null) throw new ResourceNotFoundException("node not found: " + id); if (node.getStatus() == Status.RUNNING) return; if (node.getStatus() != Status.SUSPENDED) throw new IllegalStateException("to resume a node, it must be in suspended status, not: " + formatStatus(node)); setStateOnNode(Status.PENDING, node); setStateOnNodeAfterDelay(Status.RUNNING, node, 50); }
@Override public void suspendNode(String id) { NodeMetadata node = nodes.get(id); if (node == null) throw new ResourceNotFoundException("node not found: " + id); if (node.getStatus() == Status.SUSPENDED) return; if (node.getStatus() != Status.RUNNING) throw new IllegalStateException("to suspend a node, it must be in running status, not: " + formatStatus(node)); setStateOnNode(Status.PENDING, node); setStateOnNodeAfterDelay(Status.SUSPENDED, node, 50); }
@Override public void resumeNode(String id) { NodeMetadata node = nodes.get(id); if (node == null) throw new ResourceNotFoundException("node not found: " + id); if (node.getStatus() == Status.RUNNING) return; if (node.getStatus() != Status.SUSPENDED) throw new IllegalStateException("to resume a node, it must be in suspended status, not: " + formatStatus(node)); setStateOnNode(Status.PENDING, node); setStateOnNodeAfterDelay(Status.RUNNING, node, 50); }
@Override public void suspendNode(String id) { NodeMetadata node = nodes.get(id); if (node == null) throw new ResourceNotFoundException("node not found: " + id); if (node.getStatus() == Status.SUSPENDED) return; if (node.getStatus() != Status.RUNNING) throw new IllegalStateException("to suspend a node, it must be in running status, not: " + formatStatus(node)); setStateOnNode(Status.PENDING, node); setStateOnNodeAfterDelay(Status.SUSPENDED, node, 50); }
@Test public void testNodeRunningReturnsTrueWhenRunning() { expect(node.getStatus()).andReturn(Status.RUNNING).atLeastOnce(); expect(node.getBackendStatus()).andReturn(null).atLeastOnce(); replay(node); replay(computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); AtomicReference<NodeMetadata> reference = Atomics.newReference(node); Assert.assertTrue(nodeRunning.apply(reference)); Assert.assertEquals(reference.get(), node); }
@Test(expectedExceptions = IllegalStateException.class) public void testNodeRunningFailsOnError() { expect(node.getStatus()).andReturn(Status.ERROR).atLeastOnce(); expect(node.getBackendStatus()).andReturn(null).atLeastOnce(); replay(node); replay(computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); AtomicReference<NodeMetadata> reference = Atomics.newReference(node); nodeRunning.apply(reference); Assert.assertEquals(reference.get(), node); } }
@Test(expectedExceptions = IllegalStateException.class) public void testNodeRunningFailsOnTerminated() { expect(node.getStatus()).andReturn(Status.TERMINATED).atLeastOnce(); expect(node.getBackendStatus()).andReturn(null).atLeastOnce(); replay(node); replay(computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); AtomicReference<NodeMetadata> reference = Atomics.newReference(node); nodeRunning.apply(reference); Assert.assertEquals(reference.get(), node); }
@Test(enabled = true, dependsOnMethods = { "testListNodes", "testGetNodesWithDetails", "testListNodesByIds" }) public void testDestroyNodes() { int toDestroy = refreshNodes().size(); Set<? extends NodeMetadata> destroyed = client.destroyNodesMatching(inGroup(group)); assertEquals(toDestroy, destroyed.size()); for (NodeMetadata node : filter(client.listNodesDetailsMatching(all()), inGroup(group))) { assert node.getStatus() == Status.TERMINATED : node; assert view.utils().credentialStore().get("node#" + node.getId()) == null : "credential should have been null for " + "node#" + node.getId(); } }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }