public Map<String, String> getDeviceMappings(ClusterSpec clusterSpec, Instance instance) { Map<String, String> mappings = Maps.newLinkedHashMap(); int number = 0; Hardware hardware = instance.getNodeMetadata().getHardware(); /* null when using the BYON jclouds compute provider */ if (hardware != null) { List<? extends Volume> volumes = instance.getNodeMetadata().getHardware().getVolumes(); for (Volume volume : volumes) { if (volume.isBootDevice()) { continue; } mappings.put(MOUNT_PREFIX + number++, volume.getDevice()); } } return mappings; }
public Map<String, String> getDeviceMappings(ClusterSpec clusterSpec, Instance instance) { Map<String, String> mappings = Maps.newLinkedHashMap(); int number = 0; Hardware hardware = instance.getNodeMetadata().getHardware(); /* null when using the BYON jclouds compute provider */ if (hardware != null) { List<? extends Volume> volumes = instance.getNodeMetadata().getHardware().getVolumes(); boolean foundBootDevice = false; SortedSet<String> volumeDevicesSansBoot = new TreeSet<String>(); for (Volume volume : volumes) { if (!volume.isBootDevice()) { volumeDevicesSansBoot.add(volume.getDevice()); } else { foundBootDevice = true; } } // if no boot device is reported from the cloud provider (as is sometimes the case) // assume it is the first in the natural order list of devices if (!foundBootDevice && !volumeDevicesSansBoot.isEmpty()) { volumeDevicesSansBoot.remove(volumeDevicesSansBoot.iterator().next()); } for (String device : volumeDevicesSansBoot) { mappings.put(MOUNT_PREFIX + number++, device); } } return mappings; }
/** * Create a snapshot of the volume attached to the VM * @param vmi a VMInstance */ public String createSnapshot(VMInstance vmi){ NodeMetadata nm=getVMById(vmi.getId()); ElasticBlockStoreApi ebsClient = ec2api.getElasticBlockStoreApi().get(); journal.log(Level.INFO, ">> Creating snapshot of VM: "+vmi.getName()); Snapshot snapshot = ebsClient.createSnapshotInRegion("eu-west-1", nm.getHardware().getVolumes().get(0).getId()); String status=""; while (!status.toLowerCase().equals("completed")){ for(Snapshot s:ebsClient.describeSnapshotsInRegion("eu-west-1")) if(s.getId().equals(snapshot.getId())){ status=s.getStatus().name(); } try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } } journal.log(Level.INFO, ">> Snapshot created with ID: "+snapshot.getId()); return snapshot.getId(); }
.getNodeMetadata().getHardware();
@Override @Test(dataProvider = "onlyIfAutomaticHardwareSupported", groups = {"integration", "live"}) public void testCreateNodeWithCustomHardware() throws Exception { Template template = buildTemplate(templateBuilder() .hardwareId("automatic:cores=2;ram=2048;disk=10")); try { NodeMetadata node = getOnlyElement(client.createNodesInGroup(group + "custom", 1, template)); assertThat(node.getHardware().getRam()).isEqualTo(2048); assertThat(node.getHardware().getProcessors().get(0).getCores()).isEqualTo(2); assertThat(node.getHardware().getVolumes().get(0).getSize()).isEqualTo(10); assertThat(node.getHardware().getId()).isEqualTo("cpu=2,ram=2048,disk=10"); } finally { client.destroyNodesMatching(inGroup(group + "custom")); } }
@Test(dataProvider = "onlyIfAutomaticHardwareSupported", groups = {"integration", "live"}) public void testCreateNodeWithCustomHardwareUsingMins() throws Exception { Template template = buildTemplate(templateBuilder() .minCores(2).minRam(2048).minDisk(10)); try { NodeMetadata node = getOnlyElement(client.createNodesInGroup(group + "custom", 1, template)); assertThat(node.getHardware().getRam()).isEqualTo(2048); assertThat(node.getHardware().getProcessors().get(0).getCores()).isEqualTo(2); assertThat(node.getHardware().getVolumes().get(0).getSize()).isEqualTo(10); assertThat(node.getHardware().getId()).isEqualTo("cpu=2,ram=2048,disk=10"); } finally { client.destroyNodesMatching(inGroup(group + "custom")); } }
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(dataProvider = "onlyIfAutomaticHardwareSupported", groups = {"integration", "live"}) public void testCreateNodeWithCustomHardware() throws Exception { Template template = buildTemplate(templateBuilder() .hardwareId("automatic:cores=2;ram=4096")); try { NodeMetadata node = getOnlyElement(client.createNodesInGroup(group + "custom", 1, template)); assertThat(node.getHardware().getRam()).isEqualTo(4096); assertThat(node.getHardware().getProcessors().get(0).getCores()).isEqualTo(2); } finally { client.destroyNodesMatching(inGroup(group + "custom")); } }
@Override @Test(dataProvider = "onlyIfAutomaticHardwareSupported", groups = {"integration", "live"}) public void testCreateNodeWithCustomHardware() throws Exception { Template template = buildTemplate(templateBuilder() .hardwareId("automatic:cores=2;ram=4096")); try { NodeMetadata node = getOnlyElement(client.createNodesInGroup(group + "custom", 1, template)); assertThat(node.getHardware().getRam()).isEqualTo(4096); assertThat(node.getHardware().getProcessors().get(0).getCores()).isEqualTo(2); assertThat(node.getHardware().getId()).isEqualTo(node.getLocation().getDescription() + "/machineTypes/custom-2-4096"); } finally { client.destroyNodesMatching(inGroup(group + "custom")); } }
private Cluster newCluster(int numberOfWorkers) { DnsResolver fakeDnsResolver = new FakeDnsResolver(); NodeMetadata node = mock(NodeMetadata.class); List<Processor> processors = ImmutableList.of(new Processor(4, 1.0)); Hardware hardware = new HardwareImpl(null, null, "id", null, null, ImmutableMap.<String,String>of(), ImmutableSet.<String>of(), processors, 1024, ImmutableList.<Volume>of(), null, "xen"); when(node.getHardware()).thenReturn(hardware); Builder<Instance> instances = ImmutableSet.<Instance>builder(); Instance master = new Instance(new Credentials("", ""), ImmutableSet.of(HadoopNameNodeClusterActionHandler.ROLE, HadoopJobTrackerClusterActionHandler.ROLE), "10.0.0.1", "10.0.0.1", "1", node, fakeDnsResolver); instances.add(master); for (int i = 0; i < numberOfWorkers; i++) { int id = i + 2; instances.add(new Instance(new Credentials("", ""), ImmutableSet.of(HadoopDataNodeClusterActionHandler.ROLE, HadoopTaskTrackerClusterActionHandler.ROLE), "10.0.0." + id, "10.0.0." + id, id + "", node, fakeDnsResolver)); } return new Cluster(instances.build()); }
@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); }
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); } }
private static void assertNodeEquals(NodeMetadata actual, NodeMetadata expected) { assertEquals(actual, expected); // NodeMetadata equals method does not use all fields in equals. It assumes that same ids in same locations // determine the equivalence assertEquals(actual.getStatus(), expected.getStatus()); assertEquals(actual.getBackendStatus(), expected.getBackendStatus()); assertEquals(actual.getLoginPort(), expected.getLoginPort()); assertEquals(actual.getPublicAddresses(), expected.getPublicAddresses()); assertEquals(actual.getPrivateAddresses(), expected.getPrivateAddresses()); assertEquals(actual.getCredentials(), expected.getCredentials()); assertEquals(actual.getGroup(), expected.getGroup()); assertEquals(actual.getImageId(), expected.getImageId()); assertEquals(actual.getHardware(), expected.getHardware()); assertEquals(actual.getOperatingSystem(), expected.getOperatingSystem()); assertEquals(actual.getHostname(), expected.getHostname()); }
assertEquals(convertedNodeMetadata.getOperatingSystem(), expectedOs); assertEquals(convertedNodeMetadata.getHardware(), expectedHardware);
@Override public Map<String, String> toMetadataRecord() { Hardware hardware = node.getHardware(); List<? extends Processor> processors = (hardware != null) ? hardware.getProcessors() : null; ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.putAll(super.toMetadataRecord()); putIfNotNull(builder, "provider", getParent().getProvider()); putIfNotNull(builder, "account", getParent().getIdentity()); putIfNotNull(builder, "serverId", node.getProviderId()); putIfNotNull(builder, "imageId", node.getImageId()); putIfNotNull(builder, "instanceTypeName", (hardware != null ? hardware.getName() : null)); putIfNotNull(builder, "instanceTypeId", (hardware != null ? hardware.getProviderId() : null)); putIfNotNull(builder, "ram", "" + (hardware != null ? hardware.getRam() : null)); putIfNotNull(builder, "cpus", "" + (processors != null ? processors.size() : null)); putIfNotNull(builder, "osName", getOsDetails().getName()); putIfNotNull(builder, "osArch", getOsDetails().getArch()); putIfNotNull(builder, "64bit", getOsDetails().is64bit() ? "true" : "false"); return builder.build(); }
assertEquals(converted.getPublicAddresses(), expected.getPublicAddresses()); assertEquals(converted.getImageId(), expected.getImageId()); assertEquals(converted.getHardware(), expected.getHardware()); assertEquals(converted.getCredentials(), expected.getCredentials()); assertEquals(converted.getGroup(), expected.getGroup());
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()); }