protected Hardware parseHardware(final RunningInstance instance) { Hardware hardware = getHardwareForInstance(instance); if (hardware != null) { hardware = HardwareBuilder.fromHardware(hardware).volumes(addEBS(instance, hardware.getVolumes())).build(); } return hardware; }
private Location getLocationForAvailabilityZoneOrRegion(final RunningInstance instance) { Location location = findLocationWithId(instance.getAvailabilityZone()); if (location == null) location = findLocationWithId(instance.getRegion()); return location; }
@VisibleForTesting String getGroupForInstance(final RunningInstance instance) { String group = parseGroupFrom(instance, instance.getGroupNames()); if(group == null && instance.getKeyName() != null) { // when not using a generated security group, e.g. in VPC, try from key: group = parseGroupFrom(instance, Sets.newHashSet(instance.getKeyName())); } return group; }
builder.providerId(instance.getId()); builder.id(instance.getRegion() + "/" + instance.getId()); String group = getGroupForInstance(instance); builder.group(group); addCredentialsForInstance(builder, instance); builder.status(instanceToNodeStatus.get(instance.getInstanceState())); builder.backendStatus(instance.getRawState()); builder.hardware(parseHardware(instance)); Location location = getLocationForAvailabilityZoneOrRegion(instance); builder.location(location); builder.imageId(instance.getRegion() + "/" + instance.getImageId());
protected Hardware parseHardware(RunningInstance instance) { Hardware in = super.parseHardware(instance); if (in == null) return null; AWSRunningInstance awsInstance = AWSRunningInstance.class.cast(instance); return HardwareBuilder.fromHardware(in).hypervisor(awsInstance.getHypervisor().toString()).build(); }
private void checkGroupName(RunningInstance instance) { assertEquals("groupname", createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet .<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of()) .apply(instance).getGroup()); }
private RunningInstanceToNodeMetadata createNodeParser(final ImmutableSet<Hardware> hardware, final ImmutableSet<Location> locations, Map<String, Credentials> credentialStore, Map<InstanceState, Status> instanceToNodeStatus, LoadingCache<RegionAndName, Image> instanceToImage) { Supplier<Set<? extends Location>> locationSupplier = new Supplier<Set<? extends Location>>() { @Override public Set<? extends Location> get() { return locations; } }; Supplier<Set<? extends Hardware>> hardwareSupplier = new Supplier<Set<? extends Hardware>>() { @Override public Set<? extends Hardware> get() { return hardware; } }; GroupNamingConvention.Factory namingConvention = Guice.createInjector(new AbstractModule() { @Override protected void configure() { Names.bindProperties(binder(),new EC2ApiMetadata().getDefaultProperties()); } }).getInstance(GroupNamingConvention.Factory.class); RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(instanceToNodeStatus, credentialStore, Suppliers.<LoadingCache<RegionAndName, ? extends Image>> ofInstance(instanceToImage), locationSupplier, hardwareSupplier, namingConvention); return parser; }
builder.providerId(instance.getId()); builder.id(instance.getRegion() + "/" + instance.getId()); String group = getGroupForInstance(instance); builder.group(group); addCredentialsForInstance(builder, instance); builder.status(instanceToNodeStatus.get(instance.getInstanceState())); builder.backendStatus(instance.getRawState()); builder.hardware(parseHardware(instance)); Location location = getLocationForAvailabilityZoneOrRegion(instance); builder.location(location); builder.imageId(instance.getRegion() + "/" + instance.getImageId());
protected Hardware parseHardware(RunningInstance instance) { Hardware in = super.parseHardware(instance); if (in == null) return null; AWSRunningInstance awsInstance = AWSRunningInstance.class.cast(instance); return HardwareBuilder.fromHardware(in).hypervisor(awsInstance.getHypervisor().toString()).build(); }
private void checkGroupName(RunningInstance instance) { assertEquals("groupname", createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet .<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of()) .apply(instance).getGroup()); }
private RunningInstanceToNodeMetadata createNodeParser(final ImmutableSet<Hardware> hardware, final ImmutableSet<Location> locations, Map<String, Credentials> credentialStore, Map<InstanceState, Status> instanceToNodeStatus, LoadingCache<RegionAndName, Image> instanceToImage) { Supplier<Set<? extends Location>> locationSupplier = new Supplier<Set<? extends Location>>() { @Override public Set<? extends Location> get() { return locations; } }; Supplier<Set<? extends Hardware>> hardwareSupplier = new Supplier<Set<? extends Hardware>>() { @Override public Set<? extends Hardware> get() { return hardware; } }; GroupNamingConvention.Factory namingConvention = Guice.createInjector(new AbstractModule() { @Override protected void configure() { Names.bindProperties(binder(), new EC2ApiMetadata().getDefaultProperties()); } }).getInstance(GroupNamingConvention.Factory.class); RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(instanceToNodeStatus, credentialStore, Suppliers.<LoadingCache<RegionAndName, ? extends Image>> ofInstance(instanceToImage), locationSupplier, hardwareSupplier, namingConvention); return parser; }
builder.providerId(instance.getId()); builder.id(instance.getRegion() + "/" + instance.getId()); String group = getGroupForInstance(instance); builder.group(group); addCredentialsForInstance(builder, instance); builder.status(instanceToNodeStatus.get(instance.getInstanceState())); builder.backendStatus(instance.getRawState()); builder.hardware(parseHardware(instance)); Location location = getLocationForAvailabilityZoneOrRegion(instance); builder.location(location); builder.imageId(instance.getRegion() + "/" + instance.getImageId());
protected Hardware parseHardware(final RunningInstance instance) { Hardware hardware = getHardwareForInstance(instance); if (hardware != null) { hardware = HardwareBuilder.fromHardware(hardware).volumes(addEBS(instance, hardware.getVolumes())).build(); } return hardware; }
protected Hardware parseHardware(RunningInstance instance) { Hardware in = super.parseHardware(instance); if (in == null) return null; AWSRunningInstance awsInstance = AWSRunningInstance.class.cast(instance); return HardwareBuilder.fromHardware(in).hypervisor(awsInstance.getHypervisor().toString()).build(); }
@Test public void testApplyWhereTagDoesntMatchAndImageHardwareAndLocationNotFound() throws UnknownHostException { RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet .<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of()); RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); assertEquals(parser.apply(server).toString(), new NodeMetadataBuilder().hostname("ip-10-243-42-70").status(Status.RUNNING).backendStatus("running") .publicAddresses(ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.243.42.70")) .publicAddresses(ImmutableSet.of("174.129.81.68")).imageId("us-east-1/ami-82e4b5c7") .id("us-east-1/i-0799056f").providerId("i-0799056f").build().toString()); }
@VisibleForTesting String getGroupForInstance(final RunningInstance instance) { String group = parseGroupFrom(instance, instance.getGroupNames()); if (group == null && instance.getKeyName() != null) { // when not using a generated security group, e.g. in VPC, try from key: group = parseGroupFrom(instance, Sets.newHashSet(instance.getKeyName())); } return group; }
private Location getLocationForAvailabilityZoneOrRegion(final RunningInstance instance) { Location location = findLocationWithId(instance.getAvailabilityZone()); if (location == null) location = findLocationWithId(instance.getRegion()); return location; }
builder.providerId(instance.getId()); builder.id(instance.getRegion() + "/" + instance.getId()); String group = getGroupForInstance(instance); builder.group(group); addCredentialsForInstance(builder, instance); builder.status(instanceToNodeStatus.get(instance.getInstanceState())); builder.backendStatus(instance.getRawState()); builder.hardware(parseHardware(instance)); Location location = getLocationForAvailabilityZoneOrRegion(instance); builder.location(location); builder.imageId(instance.getRegion() + "/" + instance.getImageId());
protected Hardware parseHardware(final RunningInstance instance) { Hardware hardware = getHardwareForInstance(instance); if (hardware != null) { hardware = HardwareBuilder.fromHardware(hardware).volumes(addEBS(instance, hardware.getVolumes())).build(); } return hardware; }
@Test public void testApplyWhereTagDoesntMatchAndLocationFoundAndImageAndHardwareNotFound() throws UnknownHostException { RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet.of(provider), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of()); RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); NodeMetadata expected = new NodeMetadataBuilder().hostname("ip-10-243-42-70").status(Status.RUNNING).backendStatus("running") .privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")) .imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f") .location(provider).build(); assertEquals(parser.apply(server).toString(), expected.toString()); }