protected Set<RunningInstance> createNodesInRegionAndZone(String region, String zone, String group, int count, Template template, RunInstancesOptions instanceOptions) { int countStarted = 0; int tries = 0; Set<RunningInstance> started = ImmutableSet.<RunningInstance> of(); int maxCount = EC2TemplateOptions.class.cast(template.getOptions()).getMaxCount(); int countToProvision; if (maxCount == 0) { maxCount = count; countToProvision = 1; } else { countToProvision = count; } while (countStarted < count && tries++ < count) { if (logger.isDebugEnabled()) logger.debug(">> running %d instance region(%s) zone(%s) ami(%s) params(%s)", count - countStarted, region, zone, template.getImage().getProviderId(), instanceOptions.buildFormParameters()); started = ImmutableSet.copyOf(concat( started, client.getInstanceApi().get().runInstancesInRegion(region, zone, template.getImage().getProviderId(), countToProvision, maxCount - countStarted, instanceOptions))); countStarted = size(started); if (countStarted < count) logger.debug(">> not enough instances (%d/%d) started, attempting again", countStarted, count); } return started; }
protected Set<RunningInstance> createNodesInRegionAndZone(String region, String zone, String group, int count, Template template, RunInstancesOptions instanceOptions) { int countStarted = 0; int tries = 0; Set<RunningInstance> started = ImmutableSet.<RunningInstance> of(); int maxCount = EC2TemplateOptions.class.cast(template.getOptions()).getMaxCount(); int countToProvision; if (maxCount == 0) { maxCount = count; countToProvision = 1; } else { countToProvision = count; } while (countStarted < count && tries++ < count) { if (logger.isDebugEnabled()) logger.debug(">> running %d instance region(%s) zone(%s) ami(%s) params(%s)", count - countStarted, region, zone, template.getImage().getProviderId(), instanceOptions.buildFormParameters()); started = ImmutableSet.copyOf(concat( started, client.getInstanceApi().get().runInstancesInRegion(region, zone, template.getImage().getProviderId(), countToProvision, maxCount - countStarted, instanceOptions))); countStarted = size(started); if (countStarted < count) logger.debug(">> not enough instances (%d/%d) started, attempting again", countStarted, count); } return started; }
protected Set<RunningInstance> createNodesInRegionAndZone(String region, String zone, String group, int count, Template template, RunInstancesOptions instanceOptions) { int countStarted = 0; int tries = 0; Set<RunningInstance> started = ImmutableSet.<RunningInstance> of(); int maxCount = EC2TemplateOptions.class.cast(template.getOptions()).getMaxCount(); int countToProvision; if (maxCount == 0) { maxCount = count; countToProvision = 1; } else { countToProvision = count; } while (countStarted < count && tries++ < count) { if (logger.isDebugEnabled()) logger.debug(">> running %d instance region(%s) zone(%s) ami(%s) params(%s)", count - countStarted, region, zone, template.getImage().getProviderId(), instanceOptions.buildFormParameters()); started = ImmutableSet.copyOf(concat( started, client.getInstanceApi().get().runInstancesInRegion(region, zone, template.getImage().getProviderId(), countToProvision, maxCount - countStarted, instanceOptions))); countStarted = size(started); if (countStarted < count) logger.debug(">> not enough instances (%d/%d) started, attempting again", countStarted, count); } return started; }
protected Snapshot createSnapshot() throws RunNodesException { String instanceId = null; try { RunningInstance instance = getOnlyElement(concat(ec2Api.getInstanceApi().get().runInstancesInRegion( regionId, null, imageId, 1, 1))); instanceId = instance.getId(); assertTrue(runningTester.apply(instance), instanceId + "didn't achieve the state running!"); instance = getOnlyElement(concat(ec2Api.getInstanceApi().get().describeInstancesInRegion(regionId, instanceId))); BlockDevice device = instance.getEbsBlockDevices().get("/dev/sda1"); assertNotNull(device, "device: /dev/sda1 not present on: " + instance); Snapshot snapshot = ec2Api.getElasticBlockStoreApi().get().createSnapshotInRegion(regionId, device.getVolumeId()); snapshotsToDelete.add(snapshot.getId()); Predicate<Snapshot> snapshotted = retry(new SnapshotCompleted(ec2Api.getElasticBlockStoreApi().get()), 600, 10, SECONDS); assert snapshotted.apply(snapshot); return snapshot; } finally { if (instanceId != null) ec2Api.getInstanceApi().get().terminateInstancesInRegion(regionId, instanceId); } }
private RunningInstance createInstance(String imageId) throws UnknownHostException { RunningInstance instance = null; while (instance == null) { try { System.out.printf("%d: running instance%n", System.currentTimeMillis()); Reservation<? extends RunningInstance> reservation = client.getInstanceApi().get().runInstancesInRegion( null, null, // allow ec2 to chose an availability zone imageId, 1, // minimum instances 1, // maximum instances withKeyName(keyPair.getKeyName()) // key created above .asType(InstanceType.M1_SMALL) // smallest instance size .withSecurityGroup(securityGroupName)); // group created above instance = Iterables.getOnlyElement(reservation); } catch (HttpResponseException htpe) { if (htpe.getResponse().getStatusCode() == 400) continue; throw htpe; } } assertNotNull(instance.getId()); assertEquals(instance.getInstanceState(), InstanceState.PENDING); instance = blockUntilWeCanSshIntoInstance(instance); return instance; }
.<BlockDeviceMapping> of(mapping)); RunningInstance instance = getOnlyElement(concat(ec2Api.getInstanceApi().get().runInstancesInRegion( regionId, null, imageId, 1, 1, options))); instanceId = instance.getId();
expect(input.template.getImage()).andReturn(input.image).atLeastOnce(); expect(input.image.getProviderId()).andReturn(imageId).atLeastOnce(); expect(instanceClient.runInstancesInRegion(region, zone, imageId, 1, input.count, ec2Options)).andReturn( Reservation.class.cast(reservation)); expect(instance.getId()).andReturn(instanceCreatedId).atLeastOnce();
strategy.elasticIpCache.put(new RegionAndName(region, instanceCreatedId), "1.1.1.1"); expect(instanceClient.runInstancesInRegion(region, zone, imageId, 1, input.count, ec2Options)).andReturn( Reservation.class.cast(reservation)); expect(instance.getId()).andReturn(instanceCreatedId).atLeastOnce();
Reservation<? extends RunningInstance> reservation = client.getInstanceApi().get().runInstancesInRegion(