public synchronized String getPublicHostName() throws IOException { if (publicHostName == null) { if ((nodeMetadata instanceof ResourceMetadataImpl) && ((ResourceMetadataImpl) nodeMetadata).getLocation() != null && "stub".equals(((ResourceMetadataImpl) nodeMetadata).getLocation().getId()) && nodeMetadata.getName() != null && !nodeMetadata.getName().isEmpty()) { LOG.debug("assuming stub public hostname of {} to {}", new Object[] { this, nodeMetadata.getName() }); publicHostName = nodeMetadata.getName(); } else { LOG.debug("resolving public hostname of {} (public {}, private {})", new Object[] { this, publicIp, privateIp }); publicHostName = dnsResolver.apply(publicIp); LOG.debug("resolved public hostname of {} as {}", this, publicHostName); if (publicHostName.matches("[0-9\\.]+") && nodeMetadata.getName() != null && !nodeMetadata.getName().isEmpty()) { LOG.debug("overriding public hostname of {} from {} (unresolved) to {}", new Object[] { this, publicHostName, nodeMetadata.getName() }); publicHostName = nodeMetadata.getName(); } } } return publicHostName; }
public synchronized String getPublicHostName() throws IOException { if (publicHostName == null) { if ((nodeMetadata instanceof ResourceMetadataImpl) && ((ResourceMetadataImpl) nodeMetadata).getLocation() != null && "stub".equals(((ResourceMetadataImpl) nodeMetadata).getLocation().getId()) && nodeMetadata.getName() != null && !nodeMetadata.getName().isEmpty()) { LOG.debug("assuming stub public hostname of {} to {}", new Object[] { this, nodeMetadata.getName() }); publicHostName = nodeMetadata.getName(); } else { LOG.debug("resolving public hostname of {} (public {}, private {})", new Object[] { this, publicIp, privateIp }); publicHostName = dnsResolver.apply(publicIp); LOG.debug("resolved public hostname of {} as {}", this, publicHostName); if (publicHostName.matches("[0-9\\.]+") && nodeMetadata.getName() != null && !nodeMetadata.getName().isEmpty()) { LOG.debug("overriding public hostname of {} from {} (unresolved) to {}", new Object[] { this, publicHostName, nodeMetadata.getName() }); publicHostName = nodeMetadata.getName(); } } } return publicHostName; }
/** * Release allocated EC2 resources. Method will delete created servers. */ public void releaseResources() { log.info("Releasing allocated EC2 resources."); for (int i = serverRegister.size() - 1; i >= 0; i--) { final NodeMetadata server = serverRegister.get(i); log.info("Terminating server: " + server.getName()); ec2Api.terminateInstancesInRegion(region, server.getId().split("/")[1]); serverRegister.remove(i); } log.info("All Ec2 resources have been released successfully"); }
@Override public String toString() { return String.format("%s#%s@%s:%d", node.getName(), creds.identity, socket.getHostText(), socket.getPort()); } }
@Override public String toString() { return String.format("%s#%s@%s:%d", node.getName(), creds.identity, socket.getHostText(), socket.getPort()); } }
public void exec() { List<MonitoredVm> list = new ArrayList<MonitoredVm>(); //get all servers Set<NodeMetadata> jCloudsNodes = (Set<NodeMetadata>) connector.listOfVMs(); Iterator<NodeMetadata> iterator = jCloudsNodes.iterator(); while (iterator.hasNext()) { NodeMetadata current = iterator.next(); String name = (current.getName()); MonitoredVm temp = new MonitoredVm(current.getId(), name, toState(current.getStatus())); list.add(temp); } ListManager.listManager(list, VMs, coord); }
public void exec() { List<MonitoredVm> list = new ArrayList<MonitoredVm>(); //get all servers Set<NodeMetadata> jCloudsNodes = (Set<NodeMetadata>) connector.listOfVMs(); Iterator<NodeMetadata> iterator = jCloudsNodes.iterator(); while (iterator.hasNext()) { NodeMetadata current = iterator.next(); String name = (current.getName()); MonitoredVm temp = new MonitoredVm(current.getId(), name, toState(current.getStatus())); list.add(temp); } ListManager.listManager(list, VMs, coord); }
@Override public void customize(JcloudsLocation location, ComputeService computeService, JcloudsMachineLocation machine) { JcloudsSshMachineLocation ssh = (JcloudsSshMachineLocation) machine; String name = ssh.getOptionalNode().get().getName(); List<String> commands = ImmutableList.of( String.format("echo %s | ( %s )", name, BashCommands.sudo("tee /etc/hostname")), String.format("echo 127.0.0.1 localhost | ( %s )", BashCommands.sudo("tee /etc/hosts"))); DynamicTasks.queue(SshEffectorTasks.ssh(commands) .machine(ssh) .requiringExitCodeZero()).block(); LOG.debug("Set {} hostname to {}", new Object[] { ssh, name }); } }
@Test(enabled = true, dependsOnMethods = "testDestroyNodes", alwaysRun = true) public void testCreateTwoNodesWithOneSpecifiedName() throws Exception { template = buildTemplate(templateBuilder()); template.getOptions().nodeNames(ImmutableSet.of("first-node")); try { this.nodes = newTreeSet(client.createNodesInGroup(group, 2, template)); } catch (RunNodesException e) { this.nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet())); throw e; } assertEquals(this.nodes.size(), 2, "expected two nodes but was " + nodes); NodeMetadata node1 = Iterables.getFirst(this.nodes, null); NodeMetadata node2 = Iterables.getLast(this.nodes, null); // credentials aren't always the same // assertEquals(node1.getCredentials(), node2.getCredentials()); assertTrue(node1.getName().equals("first-node") || node2.getName().equals("first-node"), "one node should be named 'first-node'"); assertFalse(node1.getName().equals("first-node") && node2.getName().equals("first-node"), "one node should be named something other than 'first-node"); }
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())); }
private void assertNodeMetadata(NodeMetadata result, org.jclouds.compute.domain.OperatingSystem os, String imageId, NodeMetadata.Status status, ImmutableSet<String> privateIpAddresses, ImmutableSet<String> publicIpAddresses) { assertNotNull(result); assertEquals(result.getId(), serverWithExternalIp.server().id()); assertEquals(result.getName(), serverWithExternalIp.server().name()); assertEquals(result.getHostname(), serverWithExternalIp.server().description()); assertEquals(result.getGroup(), "[" + serverName + "]"); assertEquals(result.getHardware(), hardware); assertEquals(result.getOperatingSystem(), os); assertEquals(result.getLocation(), location); assertEquals(result.getImageId(), imageId); assertEquals(result.getStatus(), status); assertEquals(result.getPrivateAddresses(), privateIpAddresses); assertEquals(result.getPublicAddresses(), publicIpAddresses); } }
@Test public void testVirtualGuestToNodeMetadata() { VirtualGuest virtualGuest = createVirtualGuest(); NodeMetadata nodeMetadata = new VirtualGuestToNodeMetadata(locationSupplier, namingConvention, virtualGuestToImage, virtualGuestToHardware).apply(virtualGuest); assertNotNull(nodeMetadata); assertEquals(nodeMetadata.getName(), virtualGuest.getHostname()); assertNotNull(nodeMetadata.getLocation()); assertEquals(nodeMetadata.getLocation().getId(), location.getId()); assertEquals(nodeMetadata.getHostname(), virtualGuest.getFullyQualifiedDomainName()); assertEquals(nodeMetadata.getHardware().getRam(), virtualGuest.getMaxMemory()); assertTrue(nodeMetadata.getHardware().getProcessors().size() == 1); assertEquals(Iterables.get(nodeMetadata.getHardware().getProcessors(), 0).getCores(), (double) virtualGuest.getStartCpus()); assertEquals(nodeMetadata.getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(nodeMetadata.getOperatingSystem().getVersion(), "12.04"); assertEquals(nodeMetadata.getOperatingSystem().is64Bit(), true); }
@Test public void testCreateImage() throws RunNodesException { NodeMetadata node = getOnlyElement(view.getComputeService().createNodesInGroup(group, 1, resourceGroup(group))); IdReference vmIdRef = IdReference.create(node.getProviderId()); view.getComputeService().suspendNode(node.getId()); api.getVirtualMachineApi(group).generalize(node.getName()); image = imageApi.createOrUpdate(imageName, location, ImageProperties.builder() .sourceVirtualMachine(vmIdRef).build()); assertNotNull(image); }
public void testCreatePreemptibleNodeWithSsd() throws Exception { String group = this.group + "ssd"; try { TemplateOptions options = client.templateOptions(); options.as(GoogleComputeEngineTemplateOptions.class).bootDiskType("pd-ssd").preemptible(true); // create a node Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, options); assertEquals(nodes.size(), 1, "One node should have been created"); // Verify the disk on the instance is an ssd. NodeMetadata node = Iterables.get(nodes, 0); GoogleComputeEngineApi api = client.getContext().unwrapApi(GoogleComputeEngineApi.class); Instance instance = api.instancesInZone(node.getLocation().getId()).get(node.getName()); Disk disk = api.disksInZone(node.getLocation().getId()).get(toName(instance.disks().get(0).source())); assertTrue(disk.type().toString().endsWith("pd-ssd")); assertTrue(instance.scheduling().preemptible()); } finally { client.destroyNodesMatching(inGroup(group)); } } /**
@Override public NodeMetadata apply(@Nullable org.jclouds.compute.domain.NodeMetadata input) { if (input == null) { return null; } return NodeMetadata.builder().id(input.getId()).name(input.getName()).status(input.getStatus().name()) .hostname(input.getHostname()) .loginPort(input.getLoginPort()).group(input.getGroup()) .tags(input.getTags()).metadata(input.getUserMetadata()) .locationId(input.getLocation() != null ? input.getLocation().getId() : null) .imageId(input.getImageId()) .defaultCredentials(ToLoginCredentials.INSTANCE.apply(input.getCredentials())).build(); } }
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()); }
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()); }