/** {@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; }
private static FluentIterable<String> checkNodeHasIps(NodeMetadata node) { FluentIterable<String> ips = FluentIterable.from(concat(node.getPublicAddresses(), node.getPrivateAddresses())); checkState(size(ips) > 0, "node does not have IP addresses configured: " + node); return ips; }
@Override public boolean apply(NodeMetadata arg0) { return contains( concat(arg0.getPrivateAddresses(), arg0.getPublicAddresses()), address); } }
private static FluentIterable<String> checkNodeHasIps(NodeMetadata node) { FluentIterable<String> ips = FluentIterable.from(concat(node.getPublicAddresses(), node.getPrivateAddresses())); checkState(size(ips) > 0, "node does not have IP addresses configured: " + node); return ips; }
public static String getInstanceIp(NodeMetadata node) { if (node.getPublicAddresses().size() > 0) { return node.getPublicAddresses().iterator().next(); } else if (node.getPrivateAddresses().size() > 0) { return node.getPrivateAddresses().iterator().next(); } else { log.warn("No ip was found"); return null; } }
@VisibleForTesting static FluentIterable<String> checkNodeHasIps(NodeMetadata node, AllowedInterfaces allowedInterfaces) { ImmutableSet.Builder<String> ipsBuilder = ImmutableSet.builder(); if (allowedInterfaces.scanPublic) { ipsBuilder.addAll(node.getPublicAddresses()); } if (allowedInterfaces.scanPrivate) { ipsBuilder.addAll(node.getPrivateAddresses()); } ImmutableSet<String> ips = ipsBuilder.build(); checkState(!ips.isEmpty(), "node does not have IP addresses configured: %s", node); return FluentIterable.from(ips); }
public Properties getProperties(String id) throws Exception { Properties result = new Properties(); NodeMetadata nodeMetadata = getNodeMetadataForRunningNodeWithTag(m_tagPrefix + id); if (nodeMetadata == null) { return null; } result.put("id", id); result.put("node-id", nodeMetadata.getId()); result.put("ip", nodeMetadata.getPublicAddresses().iterator().next()); return result; }
@Override public Instance apply(NodeMetadata node) { String publicIp = get(node.getPublicAddresses().size() > 0 ? node.getPublicAddresses() : node.getPrivateAddresses(), 0); return new Instance( credentials, roles, publicIp, publicIp, node.getId(), node ); } }
@Override public Instance apply(NodeMetadata node) { String publicIp = get(node.getPublicAddresses().size() > 0 ? node.getPublicAddresses() : node.getPrivateAddresses(), 0); return new Instance( credentials, roles, publicIp, publicIp, node.getId(), node ); } }
public static void checkHttpGet(HttpClient client, NodeMetadata node, int port) { for (int i = 0; i < 5; i++) try { assert client.get(URI.create(String.format("http://%s:%d", get(node.getPublicAddresses(), 0), port))) != null; break; } catch (UndeclaredThrowableException e) { assertEquals(e.getCause().getClass(), TimeoutException.class); try { Thread.sleep(1000); } catch (InterruptedException e1) { } } }
@Override public void updateVMMetadata(VMInstance a) { ComputeMetadata cm= getVMByName(a.getName()); if(cm != null){ a.setPublicAddress(getVMById(cm.getId()).getPublicAddresses().iterator().next()); a.setId(cm.getId()); } }
/** * Update the runtime metadata of a node if already deployed * @param a description of a node */ public void updateNodeMetadata(NodeInstance a){ ComputeMetadata cm= getNodeByName(a.getName()); if(cm != null){ a.setPublicAddress(getNodeById(cm.getId()).getPublicAddresses().iterator().next()); a.setId(cm.getId()); } }
@Test public void testReturnsSameNodeWhenNotFoundInCache() throws Exception { RegionAndName key = new RegionAndName("us-east-1", node.getProviderId()); String val = null; LoadingCache<RegionAndName, String> cache = cacheOf(key, val); AddElasticIpsToNodemetadata fn = new AddElasticIpsToNodemetadata(cache); assertEquals(fn.apply(node).getPublicAddresses(), ImmutableSet.of("174.129.173.155")); }
@Test public void testReturnsNodeWithElasticIpWhenFoundInCacheAndNodeHadAPublicIp() throws Exception { RegionAndName key = new RegionAndName("us-east-1", node.getProviderId()); String val = "1.1.1.1"; LoadingCache<RegionAndName, String> cache = cacheOf(key, val); AddElasticIpsToNodemetadata fn = new AddElasticIpsToNodemetadata(cache); assertEquals(fn.apply(node).getPublicAddresses(), ImmutableSet.of("1.1.1.1")); }
private void logDetails(ComputeService computeService, ComputeMetadata node) { NodeMetadata metadata = node instanceof NodeMetadata ? NodeMetadata.class.cast(node) : computeService .getNodeMetadata(node.getId()); log(String.format(" node id=%s, name=%s, group=%s, location=%s, state=%s, publicIp=%s, privateIp=%s, hardware=%s", metadata.getProviderId(), metadata.getName(), metadata.getGroup(), metadata.getLocation(), formatStatus(metadata), ComputeTaskUtils.ipOrEmptyString(metadata.getPublicAddresses()), ipOrEmptyString(metadata.getPrivateAddresses()), metadata.getHardware())); }
@Test public void testReturnsNodeWithIpWhenFoundInCacheAndNodeHadNoPublicIp() throws Exception { RegionAndName key = new RegionAndName("us-east-1", node.getProviderId()); String val = "1.1.1.1"; LoadingCache<RegionAndName, String> cache = cacheOf(key, val); AddElasticIpsToNodemetadata fn = new AddElasticIpsToNodemetadata(cache); assertEquals(fn.apply( NodeMetadataBuilder.fromNodeMetadata(node).publicAddresses(ImmutableSet.<String> of()).build()) .getPublicAddresses(), ImmutableSet.of("1.1.1.1")); }
private void addNodeDetailsAsProjectProperties(NodeMetadata createdNode) { if (nodeElement.getIdproperty() != null) getProject().setProperty(nodeElement.getIdproperty(), createdNode.getProviderId()); if (nodeElement.getHostproperty() != null) getProject().setProperty(nodeElement.getHostproperty(), ipOrEmptyString(createdNode.getPublicAddresses())); if (nodeElement.getPasswordproperty() != null && !CredentialUtils.isPrivateKeyCredential(createdNode.getCredentials())) getProject().setProperty(nodeElement.getPasswordproperty(), createdNode.getCredentials().credential); if (nodeElement.getUsernameproperty() != null) getProject().setProperty(nodeElement.getUsernameproperty(), createdNode.getCredentials().identity); }
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()); }