protected RunningInstanceToNodeMetadata createNodeParser(final ImmutableSet<Hardware> hardware, final ImmutableSet<Location> locations, final Set<org.jclouds.compute.domain.Image> images, Map<String, Credentials> credentialStore) { Map<InstanceState, Status> instanceToNodeStatus = EC2ComputeServiceDependenciesModule.toPortableNodeStatus; CacheLoader<RegionAndName, Image> getRealImage = new CacheLoader<RegionAndName, Image>() { @Override public Image load(@Nullable RegionAndName from) { return ImagesToRegionAndIdMap.imagesToMap(images).get(from); } }; LoadingCache<RegionAndName, Image> instanceToImage = CacheBuilder.newBuilder().build(getRealImage); return createNodeParser(hardware, locations, credentialStore, instanceToNodeStatus, instanceToImage); }
protected RunningInstanceToNodeMetadata createNodeParser(final ImmutableSet<Hardware> hardware, final ImmutableSet<Location> locations, final Set<org.jclouds.compute.domain.Image> images, Map<String, Credentials> credentialStore) { Map<InstanceState, Status> instanceToNodeStatus = EC2ComputeServiceDependenciesModule.toPortableNodeStatus; CacheLoader<RegionAndName, Image> getRealImage = new CacheLoader<RegionAndName, Image>() { @Override public Image load(@Nullable RegionAndName from) { return ImagesToRegionAndIdMap.imagesToMap(images).get(from); } }; LoadingCache<RegionAndName, Image> instanceToImage = CacheBuilder.newBuilder().build(getRealImage); return createNodeParser(hardware, locations, credentialStore, instanceToNodeStatus, instanceToImage); }
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 void checkGroupName(RunningInstance instance) { assertEquals("groupname", createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet .<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of()) .apply(instance).getGroup()); }
@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()); }
@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()); }
@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()); }
@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()); }
@Test public void testPrivateIpAddressIncorrectlyInPublicAddressFieldGoesToPrivateAddressCollection() { RunningInstance instance = RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small") .instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").ipAddress("10.1.1.1").build(); RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet .<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of()); assertEquals(parser.apply(instance).toString(), new NodeMetadataBuilder().status(Status.RUNNING).backendStatus("running").publicAddresses( ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.1.1.1")).id("us-east-1/id").imageId( "us-east-1/image").providerId("id").build().toString()); }
@Test public void testPublicIpAddressIncorrectlyInPrivateAddressFieldGoesToPublicAddressCollection() { RunningInstance instance = RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small") .instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").privateIpAddress("1.1.1.1").build(); RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet .<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of()); assertEquals(parser.apply(instance).toString(), new NodeMetadataBuilder().status(Status.RUNNING).backendStatus("running").privateAddresses( ImmutableSet.<String> of()).publicAddresses(ImmutableSet.of("1.1.1.1")).id("us-east-1/id").imageId( "us-east-1/image").providerId("id").build().toString()); }
@Test public void testApplyWhereTagDoesntMatchAndImageHardwareAndLocationNotFoundButCredentialsFound() throws UnknownHostException { LoginCredentials creds = LoginCredentials.builder().user("root").password("abdce").build(); RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet .<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of( "node#us-east-1/i-0799056f", creds)); RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); assertEquals( parser.apply(server).toString(), new NodeMetadataBuilder().status(Status.RUNNING).backendStatus("running").hostname("ip-10-243-42-70") .publicAddresses(ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.243.42.70")) .publicAddresses(ImmutableSet.of("174.129.81.68")).credentials(creds) .imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f").build().toString()); }
@Test public void testPrivateIpAddressIncorrectlyInPublicAddressFieldGoesToPrivateAddressCollection() { RunningInstance instance = RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small") .instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").ipAddress("10.1.1.1").build(); RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet .<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of()); assertEquals(parser.apply(instance).toString(), new NodeMetadataBuilder().status(Status.RUNNING).backendStatus("running").publicAddresses( ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.1.1.1")).id("us-east-1/id").imageId( "us-east-1/image").providerId("id").build().toString()); }
@Test public void testPublicIpAddressIncorrectlyInPrivateAddressFieldGoesToPublicAddressCollection() { RunningInstance instance = RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small") .instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").privateIpAddress("1.1.1.1").build(); RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet .<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of()); assertEquals(parser.apply(instance).toString(), new NodeMetadataBuilder().status(Status.RUNNING).backendStatus("running").privateAddresses( ImmutableSet.<String> of()).publicAddresses(ImmutableSet.of("1.1.1.1")).id("us-east-1/id").imageId( "us-east-1/image").providerId("id").build().toString()); }
@Test public void testApplyWhereTagDoesntMatchAndImageHardwareAndLocationNotFoundButCredentialsFound() throws UnknownHostException { LoginCredentials creds = LoginCredentials.builder().user("root").password("abdce").build(); RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet .<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of( "node#us-east-1/i-0799056f", creds)); RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); assertEquals( parser.apply(server).toString(), new NodeMetadataBuilder().status(Status.RUNNING).backendStatus("running").hostname("ip-10-243-42-70") .publicAddresses(ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.243.42.70")) .publicAddresses(ImmutableSet.of("174.129.81.68")).credentials(creds) .imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f").build().toString()); }
@Test public void testHandleMissingAMIs() { // Handle the case when the installed AMI no longer can be found in AWS. // Create a null-returning function to simulate that the AMI can't be found. CacheLoader<RegionAndName, Image> nullReturningFunction = new CacheLoader<RegionAndName, Image>() { @Override public Image load(@Nullable RegionAndName from) { return null; } }; LoadingCache<RegionAndName, Image> instanceToImage = CacheBuilder.newBuilder().build(nullReturningFunction); RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.of(m1_small().build()), ImmutableSet .of(provider), ImmutableMap.<String, Credentials> of(), EC2ComputeServiceDependenciesModule.toPortableNodeStatus, instanceToImage); 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") .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") .hardware(m1_small().build()).location(provider).build().toString()); }
@Test public void testHandleMissingAMIs() { // Handle the case when the installed AMI no longer can be found in AWS. // Create a null-returning function to simulate that the AMI can't be found. CacheLoader<RegionAndName, Image> nullReturningFunction = new CacheLoader<RegionAndName, Image>() { @Override public Image load(@Nullable RegionAndName from) { return null; } }; LoadingCache<RegionAndName, Image> instanceToImage = CacheBuilder.newBuilder().build(nullReturningFunction); RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.of(m1_small().build()), ImmutableSet .of(provider), ImmutableMap.<String, Credentials> of(), EC2ComputeServiceDependenciesModule.toPortableNodeStatus, instanceToImage); 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") .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") .hardware(m1_small().build()).location(provider).build().toString()); }
@Test public void testApplyWhereTagDoesntMatchAndImageAndLocationFoundAndHardwareNotFound() throws UnknownHostException { RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet.of(provider), EC2ImageParserTest.convertImages("/amzn_images.xml"), ImmutableMap.<String, Credentials> of()); RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); assertEquals( parser.apply(server).toString(), new NodeMetadataBuilder() .status(Status.RUNNING).backendStatus("running") .hostname("ip-10-243-42-70") .privateAddresses(ImmutableSet.of("10.243.42.70")) .publicAddresses(ImmutableSet.of("174.129.81.68")) .imageId("us-east-1/ami-82e4b5c7") .operatingSystem( new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual") .description("137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()) .id("us-east-1/i-0799056f").providerId("i-0799056f").location(provider).build().toString()); }
@Test public void testApplyWhereTagDoesntMatchAndImageAndLocationFoundAndHardwareNotFound() throws UnknownHostException { RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet.of(provider), EC2ImageParserTest.convertImages("/amzn_images.xml"), ImmutableMap.<String, Credentials> of()); RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); assertEquals( parser.apply(server).toString(), new NodeMetadataBuilder() .status(Status.RUNNING).backendStatus("running") .hostname("ip-10-243-42-70") .privateAddresses(ImmutableSet.of("10.243.42.70")) .publicAddresses(ImmutableSet.of("174.129.81.68")) .imageId("us-east-1/ami-82e4b5c7") .operatingSystem( new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual") .description("137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()) .id("us-east-1/i-0799056f").providerId("i-0799056f").location(provider).build().toString()); }
@Test public void testApplyWhereTagDoesntMatchAndImageHardwareAndLocationFound() throws UnknownHostException { RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.of(m1_small().build()), ImmutableSet .of(provider), EC2ImageParserTest.convertImages("/amzn_images.xml"), 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") .privateAddresses(ImmutableSet.of("10.243.42.70")) .publicAddresses(ImmutableSet.of("174.129.81.68")) .imageId("us-east-1/ami-82e4b5c7") .hardware(m1_small().build()) .operatingSystem( new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual") .description("137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()) .id("us-east-1/i-0799056f").providerId("i-0799056f").location(provider).build().toString()); }
@Test public void testApplyWhereTagDoesntMatchAndImageHardwareAndLocationFound() throws UnknownHostException { RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.of(m1_small().build()), ImmutableSet .of(provider), EC2ImageParserTest.convertImages("/amzn_images.xml"), 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") .privateAddresses(ImmutableSet.of("10.243.42.70")) .publicAddresses(ImmutableSet.of("174.129.81.68")) .imageId("us-east-1/ami-82e4b5c7") .hardware(m1_small().build()) .operatingSystem( new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual") .description("137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()) .id("us-east-1/i-0799056f").providerId("i-0799056f").location(provider).build().toString()); }