@Test(enabled = true, dependsOnMethods = "testCreateTwoNodesWithRunScript") public void testCreateTwoNodesWithOneSpecifiedName() throws Exception { template = buildTemplate(client.templateBuilder()); template.getOptions().nodeNames(ImmutableSet.of("first-node")); Set<? extends NodeMetadata> nodes; try { nodes = newTreeSet(client.createNodesInGroup(group, 2, template)); } catch (RunNodesException e) { nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet())); throw e; } assertEquals(nodes.size(), 2, "expected two nodes but was " + nodes); NodeMetadata node1 = Iterables.getFirst(nodes, null); NodeMetadata node2 = Iterables.getLast(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"); this.nodes.addAll(nodes); }
@Test(enabled = true, dependsOnMethods = "testConcurrentUseOfComputeServiceToCreateNodes") public void testCreateTwoNodesWithRunScript() throws Exception { try { client.destroyNodesMatching(inGroup(group)); } catch (NoSuchElementException e) { } refreshTemplate(); try { nodes = newTreeSet(client.createNodesInGroup(group, 2, template)); } catch (RunNodesException e) { nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet())); throw e; } assertEquals(nodes.size(), 2, "expected two nodes but was " + nodes); checkNodes(nodes, group, "bootstrap"); NodeMetadata node1 = nodes.first(); NodeMetadata node2 = nodes.last(); // credentials aren't always the same // assertEquals(node1.getCredentials(), node2.getCredentials()); assertLocationSameOrChild( checkNotNull(node1.getLocation(), "location of %s", node1), template.getLocation()); assertLocationSameOrChild( checkNotNull(node2.getLocation(), "location of %s", node2), template.getLocation()); checkImageIdMatchesTemplate(node1); checkImageIdMatchesTemplate(node2); checkOsMatchesTemplate(node1); checkOsMatchesTemplate(node2); }
public void testStartCCInstance() throws Exception { Template template = view.getComputeService() .templateBuilder() .fromHardware(EC2HardwareBuilder.cc2_8xlarge().build()) .osFamily(OsFamily.AMZN_LINUX) .build(); assert template != null : "The returned template was null, but it should have a value."; assertEquals(template.getHardware().getProviderId(), InstanceType.CC2_8XLARGE); assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "ebs"); assertEquals(template.getImage().getUserMetadata().get("virtualizationType"), "hvm"); assertEquals(template.getImage().getUserMetadata().get("hypervisor"), "xen"); template .getOptions() .runScript(Statements.newStatementList(AdminAccess.standard(), InstallJDK.fromOpenJDK())); String group = PREFIX + "cccluster"; view.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group)); // TODO make this not lookup an explicit region client .getPlacementGroupApi() .get() .deletePlacementGroupInRegion(null, "jclouds#" + group + "#us-east-1"); try { Set<? extends NodeMetadata> nodes = view.getComputeService().createNodesInGroup(group, 1, template); NodeMetadata node = getOnlyElement(nodes); getOnlyElement( getOnlyElement( client.getInstanceApi().get().describeInstancesInRegion(null, node.getProviderId()))); } catch (RunNodesException e) { System.err.println(e.getNodeErrors().keySet()); Throwables.propagate(e); } finally { view.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group)); } }
@Override protected Object doExecute() throws Exception { ComputeService service = null; try { service = getComputeService(); } catch (Throwable t) { System.err.println(t.getMessage()); return null; } TemplateBuilder builder = service.templateBuilder(); builder.any(); if (smallest) { builder.smallest(); } if (fastest) { builder.fastest(); } if (biggest) { builder.biggest(); } if (locationId != null) { builder.locationId(locationId); } if (imageId != null) { builder.imageId(imageId); } if (hardwareId != null) { builder.hardwareId(hardwareId); } if (osFamily != null) { builder.osFamily(OsFamily.fromValue(osFamily)); } if (osVersion != null) { builder.osVersionMatches(osVersion); } TemplateOptions options = service.templateOptions(); List<Statement> statements = Lists.newLinkedList(); if (adminAccess) { statements.add(AdminAccess.standard()); } if (recipes != null) { for (String recipe : recipes) { statements.add(recipeManager.createStatement(recipe, group)); } } if (ec2SecurityGroups != null) { options.as(EC2TemplateOptions.class).securityGroups(ec2SecurityGroups); } if (ec2KeyPair != null) { options.as(EC2TemplateOptions.class).keyPair(ec2KeyPair); } if (ec2NoKeyPair != null) { options.as(EC2TemplateOptions.class).noKeyPair(); } Set<? extends NodeMetadata> metadatas = null; if (!statements.isEmpty()) { options.runScript(new StatementList(statements)); } try { metadatas = service.createNodesInGroup(group, number, builder.options(options).build()); } catch (RunNodesException ex) { System.out.println("Failed to create nodes:" + ex.getMessage()); } if (metadatas != null && !metadatas.isEmpty()) { System.out.println("Created nodes:"); printNodes(service, metadatas, System.out); for (NodeMetadata node : metadatas) { for (String cacheKey : ServiceHelper.findCacheKeysForService(service)) { cacheProvider .getProviderCacheForType(Constants.ACTIVE_NODE_CACHE) .put(cacheKey, node.getId()); cacheProvider .getProviderCacheForType(Constants.INACTIVE_NODE_CACHE) .put(cacheKey, node.getId()); cacheProvider .getProviderCacheForType(Constants.SUSPENDED_NODE_CACHE) .put(cacheKey, node.getId()); } } } return null; }