public static String createNodeErrorMessage(Map<? extends NodeMetadata, ? extends Throwable> failedNodes) { Formatter fmt = new Formatter().format("Node failures:%n%n"); int index = 1; for (Entry<? extends NodeMetadata, ? extends Throwable> errorMessage : failedNodes.entrySet()) { fmt.format("%s) %s on node %s:%n%s%n%n", index++, errorMessage.getValue().getClass().getSimpleName(), errorMessage.getKey().getId(), getStackTraceAsString(errorMessage.getValue())); } return fmt.format("%s error[s]", failedNodes.size()).toString(); }
@Override public ListenableFuture<Void> apply(NodeMetadata from) { suspendNode(from.getId()); return immediateFuture(null); }
@Override public ListenableFuture<Void> apply(NodeMetadata from) { rebootNode(from.getId()); return immediateFuture(null); }
@Override public boolean apply(T input) { if (!nodeRunning.apply(newReference(node))) { throw new IllegalStateException(node.getId() + " is no longer running; aborting socket open loop"); } return false; }
@Override public String toString() { return Objects.toStringHelper(this).add("node", node.getId()).add("name", init.getInstanceName()) .add("runAsRoot", runAsRoot).toString(); }
@Override public ListenableFuture<Void> apply(NodeMetadata from) { resumeNode(from.getId()); return immediateFuture(null); }
@Override public NodeMetadata getNode(String input) { Assert.assertEquals(input, node.getId()); return node; }
@Override public SshClient apply(NodeMetadata node) { checkState(sshFactory != null, "ssh requested, but no SshModule configured"); checkNotNull(node.getCredentials(), "no credentials found for node %s", node.getId()); checkNotNull(node.getCredentials().identity, "no login identity found for node %s", node.getId()); checkNotNull(node.getCredentials().credential, "no credential found for %s on node %s", node .getCredentials().identity, node.getId()); HostAndPort socket = openSocketFinder.findOpenSocketOnNode(node, node.getLoginPort(), timeoutMs, TimeUnit.MILLISECONDS); return sshFactory.create(socket, node.getCredentials()); } }
@Override public NodeMetadata apply(NodeMetadata input) { input = super.apply(input); if (input.getCredentials() != null) credentialStore.put("node#" + input.getId(), input.getCredentials()); return input; }
public BlockUntilInitScriptStatusIsZeroThenReturnOutput future() { ExecResponse returnVal = super.doCall(); if (returnVal.getExitStatus() != 0) { IllegalStateException e = new IllegalStateException(String.format( "instance: %s on node: %s had non-zero exit status: %s", init.getInstanceName(), getNode().getId(), returnVal)); eventBus.post(new StatementOnNodeFailure(init, node, e)); throw e; } return statusFactory.create(this).init(); }
@Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired") public void testCredentialsCache() throws Exception { initializeContext(); for (NodeMetadata node : nodes) assert (view.utils().credentialStore().get("node#" + node.getId()) != null) : "credentials for " + node.getId(); }
@Override public NodeMetadata apply(NodeMetadata input) { if (statement == null) return input; Credentials credentials = CredentialsFromAdminAccess.INSTANCE.apply(statement); if (credentials != null) { LoginCredentials creds = LoginCredentials.fromCredentials(credentials); input = NodeMetadataBuilder.fromNodeMetadata(input).credentials(creds).build(); credentialStore.put("node#" + input.getId(), input.getCredentials()); } return input; }
@BeforeMethod public void setUp() throws Exception { node = createMock(NodeMetadata.class); computeService = createMock(GetNodeMetadataStrategy.class); expect(node.getId()).andReturn("myid").anyTimes(); expect(computeService.getNode("myid")).andReturn(node).anyTimes(); expect(node.getLocation()).andReturn(null).anyTimes(); }
@Override protected void interruptTask() { logger.debug("<< cancelled(%s)", commandRunner.getStatement().getInstanceName()); ExecResponse returnVal = commandRunner.refreshAndRunAction("stop"); CancellationException e = new CancellationException(String.format( "cancelled %s on node: %s; stop command had exit status: %s", getCommandRunner().getStatement() .getInstanceName(), getCommandRunner().getNode().getId(), returnVal)); eventBus.post(new StatementOnNodeFailure(getCommandRunner().getStatement(), getCommandRunner().getNode(), e)); super.interruptTask(); }
@Override public AtomicReference<NodeMetadata> call() throws Exception { NodeMetadata node = null; logger.debug(">> adding node location(%s) name(%s) image(%s) hardware(%s)", template.getLocation().getId(), name, template.getImage().getProviderId(), template.getHardware().getProviderId()); node = addNodeWithGroupStrategy.createNodeWithGroupEncodedIntoName(group, name, template); logger.debug("<< %s node(%s)", formatStatus(node), node.getId()); return new AtomicReference<NodeMetadata>(node); }
@Test(groups = { "integration", "live" }, singleThreaded = true, dependsOnMethods = "testCreateImage") public void testSpawnNodeFromImage() throws RunNodesException { ComputeService computeService = view.getComputeService(); Optional<? extends Image> optImage = getImage(); assertTrue(optImage.isPresent()); NodeMetadata node = Iterables.getOnlyElement(computeService.createNodesInGroup("test-create-image", 1, view .getComputeService() // fromImage does not use the arg image's id (but we do need to set location) .templateBuilder().imageId(optImage.get().getId()).fromImage(optImage.get()).build())); checkReachable(node); view.getComputeService().destroyNode(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()); }