本文整理了Java中org.jclouds.compute.Utils
类的一些代码示例,展示了Utils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils
类的具体详情如下:
包路径:org.jclouds.compute.Utils
类名称:Utils
暂无
代码示例来源:origin: io.brooklyn.networking/brooklyn-networking-cloudstack
public QuerySigner getQuerySigner() {
return context.utils().injector().getInstance(QuerySigner.class);
}
代码示例来源:origin: io.brooklyn/brooklyn-locations-jclouds
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();
}
代码示例来源:origin: jclouds/legacy-jclouds
protected void checkHttpGet(NodeMetadata node) {
ComputeTestUtils.checkHttpGet(view.utils().http(), node, 8080);
}
代码示例来源:origin: jclouds/legacy-jclouds-examples
ComputeServiceContext context = builder.buildView(ComputeServiceContext.class);
context.utils().eventBus().register(ScriptLogger.INSTANCE);
return context.utils().injector().getInstance(MinecraftController.class);
代码示例来源:origin: jclouds/legacy-jclouds
@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();
}
代码示例来源:origin: apache/jclouds
@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();
}
代码示例来源:origin: jclouds/legacy-jclouds
@Override
protected Injector clientFrom(CloudStackContext context) {
return context.utils().injector();
}
}
代码示例来源:origin: io.fabric8/fabric-core-agent-jclouds
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();
}
}
}
}
代码示例来源:origin: apache/jclouds
protected void checkHttpGet(NodeMetadata node) {
ComputeTestUtils.checkHttpGet(view.utils().http(), node, 8080);
}
代码示例来源:origin: jclouds/legacy-jclouds
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);
}
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Override
public Injector apply(ComputeServiceContext input) {
return input.utils().injector();
}
代码示例来源:origin: jclouds/legacy-jclouds
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));
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@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);
}
代码示例来源:origin: jclouds/legacy-jclouds
@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();
}
}
代码示例来源:origin: io.brooklyn/brooklyn-locations-jclouds
@Override
public void init() {
super.init();
ComputeServiceContext context = jcloudsParent.getComputeService().getContext();
runScriptFactory = context.utils().injector().getInstance(RunScriptOnNode.Factory.class);
}
代码示例来源:origin: apache/jclouds
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));
}
代码示例来源:origin: apache/jclouds
@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);
}
代码示例来源:origin: apache/jclouds
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);
}
}
}
代码示例来源:origin: apache/jclouds
@Override
protected Injector clientFrom(CloudStackContext context) {
return context.utils().injector();
}
}
代码示例来源:origin: org.cloudml/deployer
/**
* 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();
}
}
内容来源于网络,如有侵权,请联系作者删除!