From 512eb0139c532a68e125b0533ce737110cb4fe3a Mon Sep 17 00:00:00 2001 From: Mattias Holmqvist Date: Thu, 25 Nov 2010 23:29:26 +0100 Subject: [PATCH] Fixing issue 406. Handling the NullPointerException (NullOutputException) from MapMaker$ComputingMapAdapter.get() call. --- .../RunningInstanceToNodeMetadata.java | 19 ++++++-- .../RunningInstanceToNodeMetadataTest.java | 45 +++++++++++++++++-- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java index e73e225ddf..c3a9daaf15 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java @@ -101,9 +101,20 @@ public class RunningInstanceToNodeMetadata implements Function nullReturningFunction = new Function() { + + @Override + public Image apply(@Nullable RegionAndName from) { + return null; + } + }; + Map instanceToImage = new MapMaker().makeComputingMap(nullReturningFunction); + + RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.of(m1_small().build()), ImmutableSet + .of(provider), ImmutableMap + .of(), EC2ComputeServiceDependenciesModule.instanceToNodeState, instanceToImage); + + RunningInstance server = firstInstanceFromResource("/ec2/describe_instances_nova.xml"); + + assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.TERMINATED).privateAddresses( + ImmutableSet.of("10.128.207.5")).tag("NOTAG-i-9slweygo").imageId("us-east-1/ami-25CB1213").id( + "us-east-1/i-9slweygo").providerId("i-9slweygo").hardware(m1_small().build()).location( + provider).build()); + } + + protected RunningInstance firstInstanceFromResource(String resource) { RunningInstance server = Iterables.get(Iterables.get(DescribeInstancesResponseHandlerTest - .parseRunningInstances(resource), 0), 0); + .parseRunningInstances(resource), 0), 0); return server; } protected RunningInstanceToNodeMetadata createNodeParser(final ImmutableSet hardware, - final ImmutableSet locations, Set images, - Map credentialStore) { + final ImmutableSet locations, + Set images, + Map credentialStore) { Map instanceToNodeState = EC2ComputeServiceDependenciesModule.instanceToNodeState; Map instanceToImage = Maps.uniqueIndex(images, new Function() { @@ -159,6 +191,13 @@ public class RunningInstanceToNodeMetadataTest { } }); + + return createNodeParser(hardware, locations, credentialStore, instanceToNodeState, instanceToImage); + } + + private RunningInstanceToNodeMetadata createNodeParser(final ImmutableSet hardware, final + ImmutableSet locations, Map credentialStore, Map + instanceToNodeState, Map instanceToImage) { Supplier> locationSupplier = new Supplier>() { @Override