/** {@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; }
/** * Find a node by its id. */ @Override public NodeMetadata getNodeMetadata(String id) { return computeService.getNodeMetadata(id); }
/** * Retrieve data about a VM * @param id id of a VM * @return Information about a VM */ public NodeMetadata getVMById(String id){ return compute.getNodeMetadata(id); }
/** * Find a node by its id. */ @Override public NodeMetadata getNodeMetadata(String id) { return computeService.getNodeMetadata(id); }
/** * Retrieve data about a node * @param id id of a node * @return Information about a node */ public NodeMetadata getNodeById(String id){ return compute.getNodeMetadata(id); }
/** * Retrieve data about a VM * @param id id of a VM * @return Information about a VM */ public NodeMetadata getVMById(String id){ return novaComputeService.getNodeMetadata(id); }
public NodeMetadata getVMById(String id){ return compute.getNodeMetadata(id); }
@Override public NodeMetadata getNodeMetadata(String id) { return delegate.getNodeMetadata(id); }
@Override protected Object doExecute() throws Exception { ComputeService service = null; try { service = getComputeService(); } catch (Throwable t) { System.err.println(t.getMessage()); t.printStackTrace(System.err); return null; } NodeMetadata node = service.getNodeMetadata(id); printNodeInfo(service, Sets.newHashSet(node), true, System.out); return null; } }
/** * Get Jclouds NodeMetadata associated with this Slave. * * @return {@link NodeMetadata} */ public NodeMetadata getNodeMetaData() { if (this.nodeMetaData == null) { final ComputeService compute = JCloudsCloud.getByName(cloudName).getCompute(); this.nodeMetaData = compute.getNodeMetadata(nodeId); } return nodeMetaData; }
@Override protected void doCall(ComputeService computeService, String indent) throws Exception { for (String instanceId : names) { NodeMetadata instance = computeService.getNodeMetadata(instanceId); if (instance == null) { stderr.println(indent+"Cannot terminate instance; could not find "+instanceId); } else { boolean confirmed = confirm(indent, "terminate "+instanceId+" ("+instance+")"); if (confirmed) { computeService.destroyNode(instanceId); } } } } }
/** * Execute a command on a specified node * @param id id of the node * @param command the command to be executed * @param login username * @param key sshkey for connection */ public void execCommand(String id, String command, String login, String key){ journal.log(Level.INFO, ">> executing command..."); journal.log(Level.INFO, ">> "+ command); /*org.jclouds.domain.LoginCredentials.Builder b=initCredentials(login, key); ExecResponse response = novaComputeService.runScriptOnNode( id, exec(command), overrideLoginCredentials(b.build()) .runAsRoot(false) .wrapInInitScript(false));// run command directly journal.log(Level.INFO, ">> "+response.getOutput()); */ NodeMetadata n = novaComputeService.getNodeMetadata(id); if(n != null) { SSHConnector sc = new SSHConnector(key, login, n.getPublicAddresses().iterator().next()); sc.execCommandSsh(command); } }
/** * destroy the node, given its id. If it is the only node in a tag set, the dependent resources * will also be destroyed. */ @Override public void destroyNode(String id) { NodeMetadata node = null; try { node = computeService.getNodeMetadata(id); } catch (Exception ex) { LOGGER.error("Error while retrieving node metadata.", ex); } computeService.destroyNode(id); try { for (NodeListener listener : getNodeListeners()) { listener.nodeDestroyed(node); } } catch (Exception ex) { LOGGER.error("Error while notifying node listeners.", ex); } }
/** * destroy the node, given its id. If it is the only node in a tag set, the dependent resources * will also be destroyed. */ @Override public void destroyNode(String id) { NodeMetadata node = null; try { node = computeService.getNodeMetadata(id); } catch (Exception ex) { LOGGER.error("Error while retrieving node metadata.", ex); } computeService.destroyNode(id); try { for (NodeListener listener : getNodeListeners()) { listener.nodeDestroyed(node); } } catch (Exception ex) { LOGGER.error("Error while notifying node listeners.", ex); } }
private NodeMetadata getNodeMetadataForRunningNodeWithTag(String tag) { for (ComputeMetadata node : m_computeServiceContext.getComputeService().listNodes()) { NodeMetadata candidate = m_computeServiceContext.getComputeService().getNodeMetadata(node.getId()); if (tag.equals(candidate.getGroup()) && candidate.getState().equals(NodeState.RUNNING)) { return candidate; } } return null; }
private void get(ComputeService computeService) { if (nodeElement.getId() != null) { log(String.format("get id: %s", nodeElement.getId())); logDetails(computeService, computeService.getNodeMetadata(nodeElement.getId())); } else { log(String.format("get group: %s", nodeElement.getGroup())); for (ComputeMetadata node : Iterables.filter(computeService.listNodesDetailsMatching(NodePredicates.all()), NodePredicates.inGroup(nodeElement.getGroup()))) { logDetails(computeService, node); } } }
/** * Destroy the node. * If stopOnTerminate is {@code true}, calls {@link ComputeService#suspendNode}, * otherwise {@link ComputeService#destroyNode}. */ @Override protected void _terminate(TaskListener listener) throws IOException, InterruptedException { final ComputeService compute = JCloudsCloud.getByName(cloudName).getCompute(); if (compute.getNodeMetadata(nodeId) != null && compute.getNodeMetadata(nodeId).getStatus().equals(NodeMetadata.Status.RUNNING)) { if (stopOnTerminate) { LOGGER.info("Suspending slave : " + getNodeName()); compute.suspendNode(nodeId); } else { LOGGER.info("Terminating slave : " + getNodeName()); compute.destroyNode(nodeId); } } else { LOGGER.info("Slave " + getNodeName() + " is already not running."); } ProvisioningActivity activity = CloudStatistics.get().getActivityFor(this); if (activity != null) { activity.enterIfNotAlready(ProvisioningActivity.Phase.COMPLETED); } }
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(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired") public void testGet() throws Exception { Map<String, ? extends NodeMetadata> metadataMap = newLinkedHashMap(uniqueIndex( filter(client.listNodesDetailsMatching(all()), and(inGroup(group), not(TERMINATED))), new Function<NodeMetadata, String>() { @Override public String apply(NodeMetadata from) { return from.getId(); } })); for (NodeMetadata node : nodes) { metadataMap.remove(node.getId()); NodeMetadata metadata = client.getNodeMetadata(node.getId()); assertEquals(metadata.getProviderId(), node.getProviderId()); assertEquals(metadata.getGroup(), node.getGroup()); assertLocationSameOrChild(checkNotNull(metadata.getLocation(), "location of %s", metadata), template.getLocation()); checkImageIdMatchesTemplate(metadata); checkOsMatchesTemplate(metadata); assert (metadata.getStatus() == Status.RUNNING) : metadata; // due to DHCP the addresses can actually change in-between runs. assertEquals(metadata.getPrivateAddresses().size(), node.getPrivateAddresses().size(), format( "[%s] didn't match: [%s]", metadata.getPrivateAddresses(), node.getPrivateAddresses().size())); assertEquals(metadata.getPublicAddresses().size(), node.getPublicAddresses().size(), format( "[%s] didn't match: [%s]", metadata.getPublicAddresses(), node.getPublicAddresses().size())); } assertNodeZero(metadataMap.values()); }
public Optional<RunScriptOptions> apply(CreateJCloudsContainerMetadata containerMetadata) { CreateJCloudsContainerOptions options = containerMetadata.getCreateOptions(); NodeMetadata nodeMetadata = computeService.getNodeMetadata(containerMetadata.getNodeId()); LoginCredentials credentials = nodeMetadata.getCredentials(); LoginCredentials.Builder loginBuilder; if (options.getUser() != null) { if (credentials == null) { loginBuilder = LoginCredentials.builder(); } else { loginBuilder = credentials.toBuilder(); } if (options.getPassword() != null) { credentials = loginBuilder.user(options.getUser()).password(options.getPassword()).build(); } else { credentials = loginBuilder.user(options.getUser()).build(); } } if (credentials != null) { return Optional.of(RunScriptOptions.Builder.overrideLoginCredentials(credentials).runAsRoot(false)); } else { return Optional.absent(); } } }