public TemplateBuilder apply(TemplateBuilder b) { return b.minRam(megabytes); }}); return (T)this;
public void testParse_minDisk() { TemplateBuilderSpec spec = parse("minDisk=10"); assertNull(spec.hardwareId); assertNull(spec.minCores); assertNull(spec.minRam); assertEquals(spec.minDisk.doubleValue(), 10.0); 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().minRam(10), templateBuilders.get().from(spec)); }
public void testParse_minRam() { TemplateBuilderSpec spec = parse("minRam=10"); assertNull(spec.hardwareId); assertNull(spec.minCores); assertEquals(spec.minRam.intValue(), 10); 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().minRam(10), templateBuilders.get().from(spec)); }
public void testParse_minRam() { TemplateBuilderSpec spec = parse("minRam=10"); assertNull(spec.hardwareId); assertNull(spec.minCores); assertEquals(spec.minRam.intValue(), 10); 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().minRam(10), templateBuilders.get().from(spec)); }
public void testParse_minDisk() { TemplateBuilderSpec spec = parse("minDisk=10"); assertNull(spec.hardwareId); assertNull(spec.minCores); assertNull(spec.minRam); assertEquals(spec.minDisk.doubleValue(), 10.0); 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().minRam(10), templateBuilders.get().from(spec)); }
public void testParse_whitespaceAllowed() { TemplateBuilderSpec spec = parse(" minRam=10,\nosFamily=UBUNTU"); assertNull(spec.hardwareId); assertNull(spec.minCores); assertEquals(spec.minRam.intValue(), 10); assertNull(spec.minDisk); assertNull(spec.hypervisorMatches); assertNull(spec.imageId); assertNull(spec.imageNameMatches); assertEquals(spec.osFamily, OsFamily.UBUNTU); assertNull(spec.osVersionMatches); assertNull(spec.os64Bit); assertNull(spec.osArchMatches); assertNull(spec.osDescriptionMatches); assertNull(spec.loginUser); assertNull(spec.authenticateSudo); assertNull(spec.locationId); TemplateBuilder expected = templateBuilders.get().minRam(10).osFamily(OsFamily.UBUNTU); assertTemplateBuilderEquivalence(expected, templateBuilders.get().from(spec)); }
public void testParse_whitespaceAllowed() { TemplateBuilderSpec spec = parse(" minRam=10,\nosFamily=UBUNTU"); assertNull(spec.hardwareId); assertNull(spec.minCores); assertEquals(spec.minRam.intValue(), 10); assertNull(spec.minDisk); assertNull(spec.hypervisorMatches); assertNull(spec.imageId); assertNull(spec.imageNameMatches); assertEquals(spec.osFamily, OsFamily.UBUNTU); assertNull(spec.osVersionMatches); assertNull(spec.os64Bit); assertNull(spec.osArchMatches); assertNull(spec.osDescriptionMatches); assertNull(spec.loginUser); assertNull(spec.authenticateSudo); assertNull(spec.locationId); assertNull(spec.forceCacheReload); TemplateBuilder expected = templateBuilders.get().minRam(10).osFamily(OsFamily.UBUNTU); assertTemplateBuilderEquivalence(expected, templateBuilders.get().from(spec)); }
public void testTemplateBuilderFrom_string() { TemplateBuilder fromString = templateBuilders.get().from("minRam=10,osFamily=UBUNTU"); TemplateBuilder expected = templateBuilders.get().minCores(30).minRam(10).osFamily(OsFamily.UBUNTU); assertTemplateBuilderEquivalence(expected, fromString); }
public void testTemplateBuilderFrom_string() { TemplateBuilder fromString = templateBuilders.get().from("minRam=10,osFamily=UBUNTU"); TemplateBuilder expected = templateBuilders.get().minCores(30).minRam(10).osFamily(OsFamily.UBUNTU); assertTemplateBuilderEquivalence(expected, fromString); }
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"}, expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "No hardware profile matching the given criteria was found. " + "If you want to use exact values, please set the minCores and minRam values") public void testAutoGeneratedHardwareWithOnlyMinRamNotMatchHardwareProfile() { if (view.getComputeService().listHardwareProfiles().isEmpty()) { view.getComputeService().templateBuilder().minRam(4096).build(); } else { throw new SkipException("Hardware profile list not empty."); } }
@Test(dataProvider = "onlyIfAutomaticHardwareSupported", groups = {"integration", "live"}) public void testAutoGeneratedHardwareWithOnlyMinRamMatchHardwareProfile() { if (!view.getComputeService().listHardwareProfiles().isEmpty()) { Template template = view.getComputeService().templateBuilder().minRam(4096).build(); assertThat(AutomaticHardwareIdSpec.isAutomaticId(template.getHardware().getId())).isFalse(); assertThat(template.getHardware().getRam()).isGreaterThanOrEqualTo(4096); } else { throw new SkipException("Hardware profile list is empty, this provider can not match any hardware profile" + "to the specified minRam and minCores."); } }
@Test(dataProvider = "onlyIfAutomaticHardwareSupported", groups = {"integration", "live"}) public void testAutoGeneratedHardwareWithMinCoresAndMinRam() { if (view.getComputeService().listHardwareProfiles().isEmpty()) { Template template = view.getComputeService().templateBuilder() .minRam(2048).minCores(2).build(); assertThat(AutomaticHardwareIdSpec.isAutomaticId(template.getHardware().getId())).isTrue(); assertThat(template.getHardware().getRam()).isEqualTo(2048); assertThat(template.getHardware().getProcessors().get(0).getCores()).isEqualTo(2); } else { throw new SkipException("Hardware profile list not empty."); } }
@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")); } }
/** * Verifies that {@link TemplateBuilderImpl} would choose the correct size of the instance, based * on physical attributes (# of cores, ram, etc). * * Expected size: CC1_4XLARGE */ @Test public void testTemplateChoiceForInstanceByAttributes() throws Exception { Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.5).smallest().locationId( "us-east-1").build(); assert template != null : "The returned template was null, but it should have a value."; assertEquals(template.getHardware().getId(), "cc1.4xlarge"); }
@Test(dataProvider = "onlyIfAutomaticHardwareSupported", groups = {"integration", "live"}) public void testAutoGeneratedHardwareMatchHardwareProfile() { if (!view.getComputeService().listHardwareProfiles().isEmpty()) { Template template = view.getComputeService().templateBuilder() .minRam(2048).minCores(2).build(); assertThat(AutomaticHardwareIdSpec.isAutomaticId(template.getHardware().getId())).isFalse(); assertThat(template.getHardware().getRam()).isGreaterThanOrEqualTo(2048); assertThat(template.getHardware().getProcessors().get(0).getCores()).isGreaterThanOrEqualTo(2); } else { throw new SkipException("Hardware profile list is empty, this provider can not match any hardware profile" + "to the specified minRam and minCores."); } }
/** * Negative test version of {@link #testTemplateChoiceForInstanceByAttributes}. * * Verifies that {@link TemplateBuilderImpl} would not choose the insufficient size of the * instance, based on physical attributes (# of cores, ram, etc). * * Expected size: anything but m2.xlarge */ @Test public void testNegativeTemplateChoiceForInstanceByAttributes() throws Exception { Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.7).smallest().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: not %s. Found: %s.", "m2.xlarge", template .getHardware().getId()); }
/** * Negative test version of {@link #testTemplateChoiceForInstanceByAttributes}. * * Verifies that {@link TemplateBuilderImpl} would not choose the insufficient size of the * instance, based on physical attributes (# of cores, ram, etc). * * Expected size: anything but m2.xlarge */ @Test public void testNegativeTemplateChoiceForInstanceByAttributes() throws Exception { Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.7).smallest().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: not %s. Found: %s.", "m2.xlarge", template .getHardware().getId()); }
/** * Verifies that {@link TemplateBuilderImpl} would choose the correct size of the instance, based * on physical attributes (# of cores, ram, etc). * * Expected size: CC1_4XLARGE */ @Test public void testTemplateChoiceForInstanceByAttributes() throws Exception { Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.5).smallest().locationId( "us-east-1").build(); assert template != null : "The returned template was null, but it should have a value."; assertEquals(template.getHardware().getId(), m2_4xlarge().build().getId()); }
public NodeMetadata createNodeWithAdminUserAndJDKInGroupOpeningPortAndMinRam(String group, int port, int minRam) { ImmutableMap<String, String> userMetadata = ImmutableMap.<String, String> of("Name", group); // we want everything as defaults except ram Template defaultTemplate = compute.templateBuilder().build(); Template minecraft = compute.templateBuilder().fromTemplate(defaultTemplate).minRam(minRam).build(); // setup the template to customize the node with jdk, etc. also opening ports. Statement bootstrap = newStatementList(AdminAccess.standard(), InstallJDK.fromOpenJDK()); minecraft.getOptions().inboundPorts(22, port).userMetadata(userMetadata).runScript(bootstrap); // example of using a cloud-specific hook if (minecraft.getOptions() instanceof AWSEC2TemplateOptions) minecraft.getOptions().as(AWSEC2TemplateOptions.class).enableMonitoring(); logger.info(">> creating node type(%s) in group %s, opening ports 22, %s with admin user and jdk", minecraft .getHardware().getId(), group, port); try { NodeMetadata node = getOnlyElement(compute.createNodesInGroup(group, 1, minecraft)); logger.info("<< available node(%s) os(%s) publicAddresses%s", node.getId(), node.getOperatingSystem(), node.getPublicAddresses()); return node; } catch (RunNodesException e) { throw destroyBadNodesAndPropagate(e); } }