public QuerySigner getQuerySigner() { return context.utils().injector().getInstance(QuerySigner.class); }
public static String getFirstReachableAddress(ComputeServiceContext context, NodeMetadata node) { // To pick the address, it relies on jclouds `sshForNode().apply(Node)` to check all IPs of node (private+public), // to find one that is reachable. It does `openSocketFinder.findOpenSocketOnNode(node, node.getLoginPort(), ...)`. // This keeps trying for time org.jclouds.compute.reference.ComputeServiceConstants.Timeouts.portOpen. // TODO Want to configure this timeout here. // // TODO We could perhaps instead just set `templateOptions.blockOnPort(loginPort, 120)`, but need // to be careful to only set that if config WAIT_FOR_SSHABLE is true. For some advanced networking examples // (e.g. using DNAT on CloudStack), the brooklyn machine won't be able to reach the VM until some additional // setup steps have been done. See links from Andrea: // https://github.com/jclouds/jclouds/pull/895 // https://issues.apache.org/jira/browse/WHIRR-420 // jclouds.ssh.max-retries // jclouds.ssh.retry-auth final SshClient client = context.utils().sshForNode().apply(node); return client.getHostAddress(); }
protected void checkHttpGet(NodeMetadata node) { ComputeTestUtils.checkHttpGet(view.utils().http(), node, 8080); }
@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(); }
@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 protected Injector clientFrom(CloudStackContext context) { return context.utils().injector(); } }
private void uploadToNode(ComputeServiceContext context, NodeMetadata node, LoginCredentials credentials, URL url, String path) { Utils utils = context.utils(); SshClient ssh = credentials != null ? utils .sshForNode() .apply(NodeMetadataBuilder.fromNodeMetadata(nodeMetadata) .credentials(credentials).build()) : utils.sshForNode().apply(node); try (InputStream is = url.openStream(); ) { ssh.connect(); File distro = Files.createTempFile("/tmp"); Files.copy(is, new FileOutputStream(distro)); ssh.put(path, Payloads.newFilePayload(distro)); distro.delete(); } catch (IOException e) { LOGGER.warn("Failed to upload. Will attempt downloading distribution via maven."); } finally { if (ssh != null) { ssh.disconnect(); } } } }
protected void checkHttpGet(NodeMetadata node) { ComputeTestUtils.checkHttpGet(view.utils().http(), node, 8080); }
protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String group, String taskName) throws IOException { for (NodeMetadata node : nodes) { assertNotNull(node.getProviderId()); assertNotNull(node.getGroup()); assertEquals(node.getGroup(), group); assertEquals(node.getStatus(), Status.RUNNING); Credentials fromStore = view.utils().credentialStore().get("node#" + node.getId()); assertEquals(fromStore, node.getCredentials()); assert node.getPublicAddresses().size() >= 1 || node.getPrivateAddresses().size() >= 1 : "no ips in" + node; assertNotNull(node.getCredentials()); if (node.getCredentials().identity != null) { assertNotNull(node.getCredentials().identity); assertNotNull(node.getCredentials().credential); sshPing(node, taskName); } } }
@Override public Injector apply(ComputeServiceContext input) { return input.utils().injector(); }
private void checkReachable(NodeMetadata node) { SshClient client = view.utils().sshForNode().apply(node); assertTrue(retry(new Predicate<SshClient>() { @Override public boolean apply(SshClient input) { input.connect(); if (input.exec("id").getExitStatus() == 0) { return true; } return false; } }, getSpawnNodeMaxWait(), 1l, SECONDS).apply(client)); } }
@Test(enabled = true, dependsOnMethods = "testRegisterTemplate") public void testExtractTemplate() throws Exception { // Initiate the extraction and wait for it to complete AsyncCreateResponse response = client.getTemplateClient().extractTemplate(registeredTemplate.getId(), ExtractMode.HTTP_DOWNLOAD, registeredTemplate.getZoneId()); assertTrue(jobComplete.apply(response.getJobId()), registeredTemplate.toString()); // Get the result AsyncJob<TemplateExtraction> asyncJob = client.getAsyncJobClient().getAsyncJob(response.getJobId()); TemplateExtraction extract = asyncJob.getResult(); assertNotNull(extract); // Check that the URL can be retrieved String extractUrl = extract.getUrl(); assertNotNull(extractUrl); URI uri = new URI(URLDecoder.decode(extractUrl, "utf-8")); assertTrue(cloudStackContext.utils().http().exists(uri), "does not exist: " + uri); }
@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(); } }
@Override public void init() { super.init(); ComputeServiceContext context = jcloudsParent.getComputeService().getContext(); runScriptFactory = context.utils().injector().getInstance(RunScriptOnNode.Factory.class); }
private void checkReachable(NodeMetadata node) { SshClient client = view.utils().sshForNode().apply(node); assertTrue(retry(new Predicate<SshClient>() { @Override public boolean apply(SshClient input) { input.connect(); if (input.exec("id").getExitStatus() == 0) { return true; } return false; } }, getSpawnNodeMaxWait(), 1L, SECONDS).apply(client)); }
@Test(enabled = true, dependsOnMethods = "testRegisterTemplate") public void testExtractTemplate() throws Exception { // Initiate the extraction and wait for it to complete AsyncCreateResponse response = client.getTemplateApi().extractTemplate(registeredTemplate.getId(), ExtractMode.HTTP_DOWNLOAD, registeredTemplate.getZoneId()); assertTrue(jobComplete.apply(response.getJobId()), registeredTemplate.toString()); // Get the result AsyncJob<TemplateExtraction> asyncJob = client.getAsyncJobApi().getAsyncJob(response.getJobId()); TemplateExtraction extract = asyncJob.getResult(); assertNotNull(extract); // Check that the URL can be retrieved String extractUrl = extract.getUrl(); assertNotNull(extractUrl); URI uri = new URI(URLDecoder.decode(extractUrl, "utf-8")); assertTrue(cloudStackContext.utils().http().exists(uri), "does not exist: " + uri); }
protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String group, String taskName) throws IOException { for (NodeMetadata node : nodes) { assertNotNull(node.getProviderId()); assertNotNull(node.getGroup()); assertEquals(node.getGroup(), group); assertEquals(node.getStatus(), Status.RUNNING); Credentials fromStore = view.utils().credentialStore().get("node#" + node.getId()); assertEquals(fromStore, node.getCredentials()); assert node.getPublicAddresses().size() >= 1 || node.getPrivateAddresses().size() >= 1 : "no ips in" + node; assertNotNull(node.getCredentials()); if (node.getCredentials().identity != null) { assertNotNull(node.getCredentials().identity); sshPing(node, taskName); } } }
@Override protected Injector clientFrom(CloudStackContext context) { return context.utils().injector(); } }
/** * Upload a file on a selected node * @param sourcePath path to the file to be uploaded * @param destinationPath path to the file to be created * @param nodeId Id of a node * @param login user login * @param key key to connect */ public void uploadFile(String sourcePath, String destinationPath, String nodeId, String login, String key){ try { String contentKey=FileUtils.readFileToString(new File(key)); SshClient ssh = compute.getContext().getUtils().sshForNode().apply(NodeMetadataBuilder.fromNodeMetadata(getNodeById(nodeId)).credentials(new LoginCredentials(login, null, contentKey, true)).build()); try { ssh.connect(); ssh.put(destinationPath, Payloads.newPayload(new File(sourcePath))); } finally { if (ssh != null) ssh.disconnect(); journal.log(Level.INFO, ">> File uploaded!"); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }