@Override public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) { if (checkNotNull(regionAndIds, "regionAndIds").isEmpty()) return ImmutableSet.of(); if (any(regionAndIds, compose(containsPattern("sir-"), nameFunction()))) return getSpots(regionAndIds); return super.apply(regionAndIds); }
@SuppressWarnings("unchecked") @Test public void testWhenInstancesPresentSingleCall() { EC2Client client = createMock(EC2Client.class); InstanceClient instanceClient = createMock(InstanceClient.class); expect(client.getInstanceServices()).andReturn(instanceClient); // avoid imatcher fail. if you change this, be sure to check multiple jres expect(instanceClient.describeInstancesInRegion("us-east-1", "i-aaaa", "i-bbbb")).andReturn( Set.class.cast(ImmutableSet.of(Reservation.builder().region("us-east-1") .instances(ImmutableSet.of(instance1, instance2)).build()))); replay(client, instanceClient); PresentInstances fn = new PresentInstances(client); assertEquals(fn.apply(ImmutableSet.of(new RegionAndName("us-east-1", "i-aaaa"), new RegionAndName("us-east-1", "i-bbbb"))), ImmutableSet.of(instance1, instance2)); verify(client, instanceClient); }
@SuppressWarnings("unchecked") @Test public void testWhenInstancesPresentSingleCall() { EC2Api client = createMock(EC2Api.class); InstanceApi instanceClient = createMock(InstanceApi.class); expect(client.getInstanceApi()).andReturn((Optional) Optional.of(instanceClient)); // avoid imatcher fail. if you change this, be sure to check multiple jres expect(instanceClient.describeInstancesInRegion("us-east-1", "i-aaaa", "i-bbbb")).andReturn( Set.class.cast(ImmutableSet.of(Reservation.builder().region("us-east-1") .instances(ImmutableSet.of(instance1, instance2)).build()))); replay(client, instanceClient); PresentInstances fn = new PresentInstances(client); assertEquals(fn.apply(ImmutableSet.of(new RegionAndName("us-east-1", "i-aaaa"), new RegionAndName("us-east-1", "i-bbbb"))), ImmutableSet.of(instance1, instance2)); verify(client, instanceClient); }
@Override public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) { if (checkNotNull(regionAndIds, "regionAndIds").isEmpty()) return ImmutableSet.of(); if (any(regionAndIds, compose(containsPattern("sir-"), nameFunction()))) return getSpots(regionAndIds); return super.apply(regionAndIds); }
@Override public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) { if (checkNotNull(regionAndIds, "regionAndIds").isEmpty()) return ImmutableSet.of(); if (any(regionAndIds, Predicates.compose(containsPattern("sir-"), nameFunction()))) return getSpots(regionAndIds); return super.apply(regionAndIds); }
/** * attempts to start the specified count of instances. eventual consistency might cause a problem where instances * aren't immediately visible to the api. This method will warn when that occurs. */ private Set<RunningInstance> runInstancesAndWarnOnInvisible(String group, int count, Template mutableTemplate) { Set<RunningInstance> started = createKeyPairAndSecurityGroupsAsNeededThenRunInstances(group, count, mutableTemplate); Set<RegionAndName> startedIds = ImmutableSet.copyOf(transform(started, instanceToRegionAndName)); if (startedIds.size() == 0) { return ImmutableSet.copyOf(started); } logger.debug("<< started instances(%s)", startedIds); Set<RunningInstance> visible = presentInstances.apply(startedIds); Set<RegionAndName> visibleIds = ImmutableSet.copyOf(transform(visible, instanceToRegionAndName)); logger.trace("<< visible instances(%s)", visibleIds); // add an exception for each of the nodes we cannot customize Set<RegionAndName> invisibleIds = difference(startedIds, visibleIds); if (invisibleIds.size() > 0) { logger.warn("<< not api visible instances(%s)", invisibleIds); } return started; }
/** * attempts to start the specified count of instances. eventual consistency might cause a problem where instances * aren't immediately visible to the api. This method will warn when that occurs. */ private Set<RunningInstance> runInstancesAndWarnOnInvisible(String group, int count, Template mutableTemplate) { Set<RunningInstance> started = createKeyPairAndSecurityGroupsAsNeededThenRunInstances(group, count, mutableTemplate); Set<RegionAndName> startedIds = ImmutableSet.copyOf(transform(started, instanceToRegionAndName)); if (startedIds.isEmpty()) { return ImmutableSet.copyOf(started); } logger.debug("<< started instances(%s)", startedIds); Set<RunningInstance> visible = presentInstances.apply(startedIds); Set<RegionAndName> visibleIds = ImmutableSet.copyOf(transform(visible, instanceToRegionAndName)); logger.trace("<< visible instances(%s)", visibleIds); // add an exception for each of the nodes we cannot customize Set<RegionAndName> invisibleIds = difference(startedIds, visibleIds); if (!invisibleIds.isEmpty()) { logger.warn("<< not api visible instances(%s)", invisibleIds); } return started; }
/** * attempts to start the specified count of instances. eventual consistency might cause a problem where instances * aren't immediately visible to the api. This method will warn when that occurs. */ private Set<RunningInstance> runInstancesAndWarnOnInvisible(String group, int count, Template mutableTemplate) { Set<RunningInstance> started = createKeyPairAndSecurityGroupsAsNeededThenRunInstances(group, count, mutableTemplate); Set<RegionAndName> startedIds = ImmutableSet.copyOf(transform(started, instanceToRegionAndName)); if (startedIds.isEmpty()) { return ImmutableSet.copyOf(started); } logger.debug("<< started instances(%s)", startedIds); Set<RunningInstance> visible = presentInstances.apply(startedIds); Set<RegionAndName> visibleIds = ImmutableSet.copyOf(transform(visible, instanceToRegionAndName)); logger.trace("<< visible instances(%s)", visibleIds); // add an exception for each of the nodes we cannot customize Set<RegionAndName> invisibleIds = difference(startedIds, visibleIds); if (!invisibleIds.isEmpty()) { logger.warn("<< not api visible instances(%s)", invisibleIds); } return started; }
/** * attempts to start the specified count of instances. eventual consistency might cause a problem where instances * aren't immediately visible to the api. This method will warn when that occurs. */ private Set<RunningInstance> runInstancesAndWarnOnInvisible(String group, int count, Template mutableTemplate) { Set<RunningInstance> started = createKeyPairAndSecurityGroupsAsNeededThenRunInstances(group, count, mutableTemplate); Set<RegionAndName> startedIds = ImmutableSet.copyOf(transform(started, instanceToRegionAndName)); if (startedIds.size() == 0) { return ImmutableSet.copyOf(started); } logger.debug("<< started instances(%s)", startedIds); Set<RunningInstance> visible = presentInstances.apply(startedIds); Set<RegionAndName> visibleIds = ImmutableSet.copyOf(transform(visible, instanceToRegionAndName)); logger.trace("<< visible instances(%s)", visibleIds); // add an exception for each of the nodes we cannot customize Set<RegionAndName> invisibleIds = difference(startedIds, visibleIds); if (invisibleIds.size() > 0) { logger.warn("<< not api visible instances(%s)", invisibleIds); } return started; }
/** * attempts to start the specified count of instances. eventual consistency might cause a problem where instances * aren't immediately visible to the api. This method will warn when that occurs. */ private Set<RunningInstance> runInstancesAndWarnOnInvisible(String group, int count, Template mutableTemplate) { Set<RunningInstance> started = createKeyPairAndSecurityGroupsAsNeededThenRunInstances(group, count, mutableTemplate); Set<RegionAndName> startedIds = ImmutableSet.copyOf(transform(started, instanceToRegionAndName)); if (startedIds.isEmpty()) { return ImmutableSet.copyOf(started); } logger.debug("<< started instances(%s)", startedIds); Set<RunningInstance> visible = presentInstances.apply(startedIds); Set<RegionAndName> visibleIds = ImmutableSet.copyOf(transform(visible, instanceToRegionAndName)); logger.trace("<< visible instances(%s)", visibleIds); // add an exception for each of the nodes we cannot customize Set<RegionAndName> invisibleIds = difference(startedIds, visibleIds); if (!invisibleIds.isEmpty()) { logger.warn("<< not api visible instances(%s)", invisibleIds); } return started; }
expect(strategy.credentialStore.put("node#" + region + "/" + instanceCreatedId, creds)).andReturn(null); expect(strategy.presentInstances.apply(ImmutableSet.of(new RegionAndName(region, instanceCreatedId)))).andReturn(ImmutableSet.of(instance)); expect(input.template.getOptions()).andReturn(input.options).atLeastOnce(); expect(input.options.getLoginUser()).andReturn(null);
expect(strategy.credentialStore.put("node#" + region + "/" + instanceCreatedId, creds)).andReturn(null); expect(strategy.presentInstances.apply(ImmutableSet.of(new RegionAndName(region, instanceCreatedId)))).andReturn(ImmutableSet.of(instance)); expect(input.template.getOptions()).andReturn(input.options).atLeastOnce(); expect(input.options.getLoginUser()).andReturn(null);
expect(strategy.credentialStore.put("node#" + region + "/" + instanceCreatedId, creds)).andReturn(null); expect(strategy.presentInstances.apply(ImmutableSet.of(new RegionAndName(region, instanceCreatedId)))).andReturn(ImmutableSet.of(instance)); expect(input.template.getOptions()).andReturn(input.options).atLeastOnce(); expect(input.options.getLoginUser()).andReturn(null);
expect(strategy.credentialStore.put("node#" + region + "/" + instanceCreatedId, creds)).andReturn(null); expect(strategy.presentInstances.apply(ImmutableSet.of(new RegionAndName(region, instanceCreatedId)))).andReturn(ImmutableSet.of(instance)); expect(input.template.getOptions()).andReturn(input.options).atLeastOnce(); expect(input.options.getLoginUser()).andReturn(null);