@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()); }
@Override public NodeMetadata apply(Server from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getName()); Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(from.getDatacenter().getId() + "")); builder.location(location); builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName())); builder.hardware(parseHardware(from)); builder.imageId(from.getImage().getId() + ""); Image image = parseImage(from); if (image != null) builder.operatingSystem(image.getOperatingSystem()); builder.status(serverStateToNodeStatus.get(from.getState())); builder.publicAddresses(ImmutableSet.of(from.getIp().getIp())); return builder.build(); }
@Override public NodeMetadata apply(Server from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getName()); Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(from.getDatacenter().getId() + "")); builder.location(location); builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName())); builder.hardware(parseHardware(from)); builder.imageId(from.getImage().getId() + ""); Image image = parseImage(from); if (image != null) builder.operatingSystem(image.getOperatingSystem()); builder.status(serverStateToNodeStatus.get(from.getState())); builder.publicAddresses(ImmutableSet.of(from.getIp().getIp())); return builder.build(); }
@Override public NodeMetadata apply(org.jclouds.deltacloud.domain.Instance from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getHref().toASCIIString()); builder.name(from.getName()); builder.location(parseLocation(from)); builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName())); builder.imageId(from.getImage().toASCIIString()); builder.operatingSystem(parseOperatingSystem(from)); builder.hardware(parseHardware(from)); builder.status(instanceToNodeStatus.get(from.getState())); builder.publicAddresses(from.getPublicAddresses()); builder.privateAddresses(from.getPrivateAddresses()); return builder.build(); } }
@Override protected NodeMetadata newNode(String group, Template template) { NodeMetadata result = new NodeMetadataBuilder() .id("myNodeId") .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build()) .loginPort(serverSocket.getLocalPort()) .status(Status.RUNNING) .publicAddresses(ImmutableList.of(serverSocket.getInetAddress().getHostAddress())) .privateAddresses(ImmutableList.of("1.2.3.4")) .imageId(template.getImage().getId()) .tags(template.getOptions().getTags()) .hardware(includeNodeHardwareMetadata ? template.getHardware() : null) .group(template.getOptions().getGroups().isEmpty() ? "myGroup" : Iterables.get(template.getOptions().getGroups(), 0)) .build(); return result; } };
@Override public NodeMetadata apply(Server from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getName()); builder.hostname(from.getName()); builder.location(new LocationBuilder().scope(LocationScope.HOST).id(from.getHostId()).description( from.getHostId()).parent(location.get()).build()); addMetadataAndParseTagsFromCommaDelimitedValue(builder, from.getMetadata()); builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName())); builder.imageId(from.getImageId() + ""); builder.operatingSystem(parseOperatingSystem(from)); builder.hardware(parseHardware(from)); builder.status(serverToNodeStatus.get(from.getStatus())); builder.publicAddresses(from.getAddresses().getPublicAddresses()); builder.privateAddresses(from.getAddresses().getPrivateAddresses()); return builder.build(); }
@Test public void testApplyWhereVirtualIsBad() { // notice if we've already parsed this properly here, we can rely on it. VirtualGuest guest = new ParseBadVirtualGuest().expected(); // no location here Supplier<Set<? extends Location>> locationSupplier = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet .<Location> of()); VirtualGuestToNodeMetadata parser = new VirtualGuestToNodeMetadata(locationSupplier, new GetHardwareForVirtualGuestMock(), new GetImageForVirtualGuestMock(), namingConvention); NodeMetadata node = parser.apply(guest); assertEquals( node, new NodeMetadataBuilder().ids("413348").name("foo-ef4").hostname("foo-ef4").group("foo") .status(Status.PENDING).hardware(new GetHardwareForVirtualGuestMock().getHardware(guest)) .imageId(new GetImageForVirtualGuestMock().getImage(guest).getId()) .operatingSystem(new GetImageForVirtualGuestMock().getImage(guest).getOperatingSystem()).build()); }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }