@SuppressWarnings("unchecked") @Test public void testWhenInstancesPresentSingleCall() { EC2Api client = createMock(EC2Api.class); InstanceApi instanceClient = createMock(InstanceApi.class); expect(client.getInstanceApi()).andReturn((Optional) Optional.of(instanceClient)); 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(); Builder<RunningInstance> builder = ImmutableSet.<RunningInstance> builder(); Multimap<String, String> regionToInstanceIds = transformValues(index(regionAndIds, regionFunction()), nameFunction()); for (Map.Entry<String, Collection<String>> entry : regionToInstanceIds.asMap().entrySet()) { String region = entry.getKey(); Collection<String> instanceIds = entry.getValue(); logger.trace("looking for instances %s in region %s", instanceIds, region); builder.addAll(concat(client.getInstanceApi().get().describeInstancesInRegion(region, toArray(instanceIds, String.class)))); } return builder.build(); }
PresentInstances implements Function<Set<RegionAndName>, Set<RunningInstance>> { @Override public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) { if (checkNotNull(regionAndIds, "regionAndIds").isEmpty()) return ImmutableSet.of(); Builder<RunningInstance> builder = ImmutableSet.<RunningInstance> builder(); Multimap<String, String> regionToInstanceIds = transformValues(index(regionAndIds, regionFunction()), nameFunction()); for (Map.Entry<String, Collection<String>> entry : regionToInstanceIds.asMap().entrySet()) { String region = entry.getKey(); Collection<String> instanceIds = entry.getValue(); logger.trace("looking for instances %s in region %s", instanceIds, region); builder.addAll(concat(client.getInstanceApi().get().describeInstancesInRegion(region, toArray(instanceIds, String.class)))); } return builder.build(); } }
PresentInstances implements Function<Set<RegionAndName>, Set<RunningInstance>> { @Override public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) { if (checkNotNull(regionAndIds, "regionAndIds").isEmpty()) return ImmutableSet.of(); Builder<RunningInstance> builder = ImmutableSet.<RunningInstance> builder(); Multimap<String, String> regionToInstanceIds = transformValues(index(regionAndIds, regionFunction()), nameFunction()); for (Map.Entry<String, Collection<String>> entry : regionToInstanceIds.asMap().entrySet()) { String region = entry.getKey(); Collection<String> instanceIds = entry.getValue(); logger.trace("looking for instances %s in region %s", instanceIds, region); builder.addAll(concat(client.getInstanceApi().get().describeInstancesInRegion(region, toArray(instanceIds, String.class)))); } return builder.build(); } @Inject  PresentInstances(EC2Api client); }
PresentInstances implements Function<Set<RegionAndName>, Set<RunningInstance>> { @Override public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) { if (checkNotNull(regionAndIds, "regionAndIds").isEmpty()) return ImmutableSet.of(); Builder<RunningInstance> builder = ImmutableSet.<RunningInstance> builder(); Multimap<String, String> regionToInstanceIds = transformValues(index(regionAndIds, regionFunction()), nameFunction()); for (Map.Entry<String, Collection<String>> entry : regionToInstanceIds.asMap().entrySet()) { String region = entry.getKey(); Collection<String> instanceIds = entry.getValue(); logger.trace("looking for instances %s in region %s", instanceIds, region); builder.addAll(concat(client.getInstanceApi().get().describeInstancesInRegion(region, toArray(instanceIds, String.class)))); } return builder.build(); } @Inject  PresentInstances(EC2Api client); @Override Set<RunningInstance> apply(Set<RegionAndName> regionAndIds); @Override String toString(); }
PresentInstances implements Function<Set<RegionAndName>, Set<RunningInstance>> { @Override public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) { if (checkNotNull(regionAndIds, "regionAndIds").isEmpty()) return ImmutableSet.of(); Builder<RunningInstance> builder = ImmutableSet.<RunningInstance> builder(); Multimap<String, String> regionToInstanceIds = transformValues(index(regionAndIds, regionFunction()), nameFunction()); for (Map.Entry<String, Collection<String>> entry : regionToInstanceIds.asMap().entrySet()) { String region = entry.getKey(); Collection<String> instanceIds = entry.getValue(); logger.trace("looking for instances %s in region %s", instanceIds, region); builder.addAll(concat(client.getInstanceApi().get().describeInstancesInRegion(region, toArray(instanceIds, String.class)))); } return builder.build(); } @Inject  PresentInstances(EC2Api client); @Override Set<RunningInstance> apply(Set<RegionAndName> regionAndIds); @Override String toString();  }