public TemplateBuilder apply(TemplateBuilder b) { return b.hardwareId(hardwareId); }}); return (T)this;
public void testParse_hardwareId() { TemplateBuilderSpec spec = parse("hardwareId=m1.small"); assertEquals(spec.hardwareId, "m1.small"); assertNull(spec.minCores); assertNull(spec.minRam); assertNull(spec.minDisk); assertNull(spec.hypervisorMatches); assertNull(spec.imageId); assertNull(spec.imageNameMatches); assertNull(spec.osFamily); assertNull(spec.osVersionMatches); assertNull(spec.os64Bit); assertNull(spec.osArchMatches); assertNull(spec.osDescriptionMatches); assertNull(spec.loginUser); assertNull(spec.authenticateSudo); assertNull(spec.locationId); assertTemplateBuilderEquivalence(templateBuilders.get().hardwareId("m1.small"), templateBuilders.get().from(spec)); }
public void testParse_hardwareId() { TemplateBuilderSpec spec = parse("hardwareId=m1.small"); assertEquals(spec.hardwareId, "m1.small"); assertNull(spec.minCores); assertNull(spec.minRam); assertNull(spec.minDisk); assertNull(spec.hypervisorMatches); assertNull(spec.imageId); assertNull(spec.imageNameMatches); assertNull(spec.osFamily); assertNull(spec.osVersionMatches); assertNull(spec.os64Bit); assertNull(spec.osArchMatches); assertNull(spec.osDescriptionMatches); assertNull(spec.loginUser); assertNull(spec.authenticateSudo); assertNull(spec.locationId); assertNull(spec.forceCacheReload); assertTemplateBuilderEquivalence(templateBuilders.get().hardwareId("m1.small"), templateBuilders.get().from(spec)); }
.hardwareId(instanceType) .locationId(region) .imageId(fullId)
/** * Create a node with the specified group. */ protected void createNode(Exchange exchange) throws CamelException { String group = getGroup(exchange); String imageId = getImageId(exchange); String locationId = getLocationId(exchange); String hardwareId = getHardwareId(exchange); if (ObjectHelper.isEmpty(group)) { throw new CamelExchangeException("Group must be specific in the URI or as exchange property for the destroy node operation.", exchange); } TemplateBuilder builder = computeService.templateBuilder(); builder.any(); if (ObjectHelper.isNotEmpty(locationId)) { builder.locationId(locationId); } if (ObjectHelper.isNotEmpty(imageId)) { builder.imageId(imageId); } if (ObjectHelper.isNotEmpty(hardwareId)) { builder.hardwareId(hardwareId); } try { Set<? extends NodeMetadata> nodeMetadatas = computeService.createNodesInGroup(group, 1, builder.build()); exchange.getOut().setBody(nodeMetadatas); exchange.getOut().setHeaders(exchange.getIn().getHeaders()); } catch (RunNodesException e) { throw new CamelExchangeException("Error creating jclouds node.", exchange, e); } }
@Test(dataProvider = "onlyIfAutomaticHardwareSupported", groups = {"integration", "live"}) public void testAutoGeneratedHardwareFromId() { Template template = view.getComputeService().templateBuilder() .hardwareId("automatic:cores=2;ram=1024").build(); assertThat(template.getHardware().getId()).isEqualTo("automatic:cores=2.0;ram=1024"); assertThat(template.getHardware().getRam()).isEqualTo(1024); assertThat(template.getHardware().getProcessors().get(0).getCores()).isEqualTo(2); }
private static void applyInstanceType(TemplateBuilder builder, CreateJCloudsContainerOptions options) { //If no options about hardware has been specified ... if (options.getInstanceType() == null && Strings.isNullOrEmpty(options.getHardwareId())) { builder.minRam(1024); } else if (!Strings.isNullOrEmpty(options.getHardwareId())) { builder.hardwareId(options.getHardwareId()); } else if (options.getInstanceType() != null) { switch (options.getInstanceType()) { case Smallest: builder.smallest(); break; case Biggest: builder.biggest(); break; case Fastest: builder.fastest(); break; default: builder.fastest(); } } }
@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 testAutoGeneratedHardwareFromId() { Template template = view.getComputeService().templateBuilder() .hardwareId("automatic:cores=2;ram=1024").build(); assertThat(template.getHardware().getId()).isEqualTo(template.getLocation() .getDescription() + "/machineTypes/custom-2-1024"); assertThat(template.getHardware().getRam()).isEqualTo(1024); assertThat(template.getHardware().getProcessors().get(0).getCores()).isEqualTo(2); assertThat(template.getHardware().getUri()).isEqualTo(URI.create(template.getLocation() .getDescription() + "/machineTypes/custom-2-1024")); }
@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")); } }
@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")); } }
public void start(String id) throws Exception { ComputeService computeService = m_computeServiceContext.getComputeService(); Template template = computeService.templateBuilder() .imageId(m_location + "/" + m_amiId) .hardwareId(InstanceType.C1_MEDIUM) .locationId(m_location) .build(); int[] extraPorts = parseExtraPorts(m_extraPorts); int[] inboundPorts = mergePorts(DEFAULT_PORTS, extraPorts); template.getOptions().as(EC2TemplateOptions.class).inboundPorts(inboundPorts); template.getOptions().blockOnComplete(false); template.getOptions().runAsRoot(m_runAsRoot); Set<? extends NodeMetadata> tag = computeService.createNodesInGroup(m_tagPrefix + id, 1, template); System.out.println("In case you need it, this is the key to ssh to " + id + ":\n" + tag.iterator().next().getCredentials().credential); computeService.runScriptOnNodesMatching(runningInGroup(m_tagPrefix + id), Statements.exec(buildStartupScript(id)), RunScriptOptions.Builder.blockOnComplete(false)); }
@Test public void testTemplateBuilderMicro() throws IOException { Template microTemplate = view.getComputeService().templateBuilder().hardwareId(InstanceType.T1_MICRO) .osFamily(OsFamily.UBUNTU).osVersionMatches("10.10").os64Bit(true).build(); assert microTemplate.getImage().getProviderId().startsWith("ami-") : microTemplate; assertEquals(microTemplate.getImage().getOperatingSystem().getVersion(), "10.10"); assertEquals(microTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(microTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(microTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs"); assertEquals(microTemplate.getLocation().getId(), "us-east-1"); assertEquals(getCores(microTemplate.getHardware()), 1.0d); assertEquals(microTemplate.getImage().getOperatingSystem().getArch(), "paravirtual"); }
/** * Verifies that {@link TemplateBuilderImpl} would choose the correct size of the instance, based * on {@link org.jclouds.compute.domain.Hardware} from {@link EC2Hardware}. * * Expected size: m2.xlarge */ @Test public void testTemplateChoiceForInstanceByhardwareId() throws Exception { Template template = newTemplateBuilder().os64Bit(true).hardwareId("m2.xlarge").locationId("us-east-1").build(); assert template != null : "The returned template was null, but it should have a value."; // assert m2_xlarge().build().equals(template.getHardware()) : format( // "Incorrect image determined by the template. Expected: %s. Found: %s.", "m2.xlarge", // String.valueOf(template.getHardware())); assertEquals(m2_xlarge().build().getId(), template.getHardware().getId()); }
.hardwareId(ec2Client.getInstanceType()) .locationId(ec2Client.getRegion()) .imageId(fullId).options(TemplateOptions.NONE)
/** * Verifies that {@link TemplateBuilderImpl} would choose the correct size of the instance, based * on {@link org.jclouds.compute.domain.Hardware} from {@link EC2Hardware}. * * Expected size: m2.xlarge */ @Test public void testTemplateChoiceForInstanceByHardwareId() throws Exception { Template template = newTemplateBuilder().os64Bit(true).hardwareId("m2.xlarge").locationId("us-east-1").build(); assert template != null : "The returned template was null, but it should have a value."; // assert m2_xlarge().build().equals(template.getHardware()) : format( // "Incorrect image determined by the template. Expected: %s. Found: %s.", "m2.xlarge", // String.valueOf(template.getHardware())); assertEquals(template.getHardware().getId(), m2_xlarge().build().getId()); }
@Test public void testTemplateBuilderCanUseImageIdAndHardwareIdAndAZ() { Template template = view.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5") .hardwareId(InstanceType.M2_2XLARGE).locationId("us-east-1b").build(); assert template.getImage().getProviderId().startsWith("ami-") : template; assertEquals(template.getImage().getOperatingSystem().getVersion(), "5.4"); assertEquals(template.getImage().getOperatingSystem().is64Bit(), true); assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS); assertEquals(template.getImage().getVersion(), "4.4.10"); assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); assertEquals(template.getLocation().getId(), "us-east-1b"); assertEquals(template.getImage().getLocation().getId(), "us-east-1"); assertEquals(getCores(template.getHardware()), 4.0d); assertEquals(template.getHardware().getId(), InstanceType.M2_2XLARGE); assertEquals(template.getImage().getOperatingSystem().getArch(), "paravirtual"); }
@Test public void testTemplateBuilderM1MEDIUMWithNegativeLookaroundDoesntMatchTestImages() { Template template = view.getComputeService().templateBuilder().hardwareId(InstanceType.M1_MEDIUM) // need to select versions with double-digits so that lexicographic // doesn't end up prefering 9.x vs 11.x .osVersionMatches("1[012].[10][04]") // negative lookahead for daily and testing, but ensure match // ubuntu-images // http://www.regular-expressions.info/lookaround.html .imageDescriptionMatches("^(?!.*(daily|testing)).*ubuntu-images.*$").osFamily(OsFamily.UBUNTU).build(); assert template.getImage().getProviderId().startsWith("ami-") : template; assert template.getImage().getDescription().indexOf("test") == -1 : template; assert template.getImage().getDescription().indexOf("daily") == -1 : template; assertEquals(template.getImage().getVersion(), "20100224"); assertEquals(template.getImage().getOperatingSystem().getVersion(), "10.04"); assertEquals(template.getImage().getOperatingSystem().is64Bit(), false); assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); assertEquals(template.getLocation().getId(), "us-east-1"); assertEquals(getCores(template.getHardware()), 1.0d); assertEquals(template.getHardware().getId(), InstanceType.M1_MEDIUM); assertEquals(template.getImage().getOperatingSystem().getArch(), "paravirtual"); }
TemplateBuilder templateBuilder = templateBuilderProvider.get().hardwareId("m1.small").imageId("us-east-2/ami-ffff");
TemplateBuilder templateBuilder = templateBuilderProvider.get().hardwareId("m1.small").imageId("us-east-2/ami-ffff");