@Test public void testServerDetailsRequest() { ServerDetailsToNodeMetadata toTest = injectorForKnownArgumentsAndConstantPassword( ImmutableMap .<HttpRequest, HttpResponse> builder() .put(HttpRequest .builder() .method("POST") .endpoint("https: .addHeader("Accept", "application/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") .payload( newUrlEncodedFormPayload(ImmutableMultimap.<String, String> builder() .put("serverid", "xm3276891").build())).build(), HttpResponse .builder() .statusCode(200) .payload(payloadFromResource("/server_details.json")) .build()).build() ).getInstance(ServerDetailsToNodeMetadata.class); NodeMetadata actual = toTest.apply(ServerApiExpectTest.expectedServerDetails()); assertNotNull(actual); assertEquals( actual.toString(), new NodeMetadataBuilder() .ids("vz1840356") .name("glesys-s") .hostname("glesys-s") .group("glesys") .imageId("Ubuntu 10.04 LTS 32-bit") .operatingSystem( OperatingSystem.builder().name("Ubuntu 10.04 LTS 32-bit").family(OsFamily.UBUNTU).version("10.04") .is64Bit(false).description("Ubuntu 10.04 LTS 32-bit").build()) .publicAddresses(ImmutableSet.of("31.192.231.254")) .hardware( new HardwareBuilder().ids("vz1840356").ram(512) .processors(ImmutableList.of(new Processor(1, 1.0))) .volumes(ImmutableList.<Volume> of(new VolumeImpl(5f, true, true))).hypervisor("OpenVZ") .build()).status(Status.RUNNING).build().toString()); }
@Override public NodeMetadata apply(ServerDetails from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getHostname()); builder.hostname(from.getHostname()); Location location = FluentIterable.from(locations.get()).firstMatch(idEquals(from.getDatacenter())).orNull(); checkState(location != null, "no location matched ServerDetails %s", from); Map<String, String> metadataMap; if (!isNullOrEmpty(from.getDescription()) && from.getDescription().matches("^[0-9A-Fa-f]+$")) { String decoded = new String(base16().lowerCase().decode(from.getDescription()), UTF_8); metadataMap = Splitter.on('\n').withKeyValueSeparator("=").split(decoded); addMetadataAndParseTagsFromCommaDelimitedValue(builder, metadataMap); } else { metadataMap = ImmutableMap.of(); } builder.group(groupFromMapOrName(metadataMap, from.getHostname(), nodeNamingConvention)); builder.imageId(from.getTemplateName() + ""); builder.operatingSystem(parseOperatingSystem(from)); builder.hardware(new HardwareBuilder().ids(from.getId() + "").ram(from.getMemorySizeMB()) .processors(ImmutableList.of(new Processor(from.getCpuCores(), 1.0))) .volumes(ImmutableList.<Volume> of(new VolumeImpl((float) from.getDiskSizeGB(), true, true))) .hypervisor(from.getPlatform()).build()); builder.status(serverStateToNodeStatus.get(from.getState())); Iterable<String> addresses = Iterables.filter(Iterables.transform(from.getIps(), new Function<Ip, String>() { @Override public String apply(Ip arg0) { return Strings.emptyToNull(arg0.getIp()); } }), Predicates.notNull()); builder.publicAddresses(Iterables.filter(addresses, Predicates.not(IsPrivateIPAddress.INSTANCE))); builder.privateAddresses(Iterables.filter(addresses, IsPrivateIPAddress.INSTANCE)); return builder.build(); }
ServerDetailsToNodeMetadata implements Function<ServerDetails, NodeMetadata> { @Override public NodeMetadata apply(ServerDetails from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getHostname()); builder.hostname(from.getHostname()); Location location = FluentIterable.from(locations.get()).firstMatch(idEquals(from.getDatacenter())).orNull(); checkState(location != null, "no location matched ServerDetails %s", from); Map<String, String> metadataMap; if (!isNullOrEmpty(from.getDescription()) && from.getDescription().matches("^[0-9A-Fa-f]+$")) { String decoded = new String(base16().lowerCase().decode(from.getDescription()), UTF_8); metadataMap = Splitter.on('\n').withKeyValueSeparator("=").split(decoded); addMetadataAndParseTagsFromCommaDelimitedValue(builder, metadataMap); } else { metadataMap = ImmutableMap.of(); } builder.group(groupFromMapOrName(metadataMap, from.getHostname(), nodeNamingConvention)); builder.imageId(from.getTemplateName() + ""); builder.operatingSystem(parseOperatingSystem(from)); builder.hardware(new HardwareBuilder().ids(from.getId() + "").ram(from.getMemorySizeMB()) .processors(ImmutableList.of(new Processor(from.getCpuCores(), 1.0))) .volumes(ImmutableList.<Volume> of(new VolumeImpl((float) from.getDiskSizeGB(), true, true))) .hypervisor(from.getPlatform()).build()); builder.status(serverStateToNodeStatus.get(from.getState())); Iterable<String> addresses = Iterables.filter(Iterables.transform(from.getIps(), new Function<Ip, String>() { @Override public String apply(Ip arg0) { return Strings.emptyToNull(arg0.getIp()); } }), Predicates.notNull()); builder.publicAddresses(Iterables.filter(addresses, Predicates.not(IsPrivateIPAddress.INSTANCE))); builder.privateAddresses(Iterables.filter(addresses, IsPrivateIPAddress.INSTANCE)); return builder.build(); } }
ServerDetailsToNodeMetadata implements Function<ServerDetails, NodeMetadata> { @Override public NodeMetadata apply(ServerDetails from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getHostname()); builder.hostname(from.getHostname()); Location location = FluentIterable.from(locations.get()).firstMatch(idEquals(from.getDatacenter())).orNull(); checkState(location != null, "no location matched ServerDetails %s", from); Map<String, String> metadataMap; if (!isNullOrEmpty(from.getDescription()) && from.getDescription().matches("^[0-9A-Fa-f]+$")) { String decoded = new String(base16().lowerCase().decode(from.getDescription()), UTF_8); metadataMap = Splitter.on('\n').withKeyValueSeparator("=").split(decoded); addMetadataAndParseTagsFromCommaDelimitedValue(builder, metadataMap); } else { metadataMap = ImmutableMap.of(); } builder.group(groupFromMapOrName(metadataMap, from.getHostname(), nodeNamingConvention)); builder.imageId(from.getTemplateName() + ""); builder.operatingSystem(parseOperatingSystem(from)); builder.hardware(new HardwareBuilder().ids(from.getId() + "").ram(from.getMemorySizeMB()) .processors(ImmutableList.of(new Processor(from.getCpuCores(), 1.0))) .volumes(ImmutableList.<Volume> of(new VolumeImpl((float) from.getDiskSizeGB(), true, true))) .hypervisor(from.getPlatform()).build()); builder.status(serverStateToNodeStatus.get(from.getState())); Iterable<String> addresses = Iterables.filter(Iterables.transform(from.getIps(), new Function<Ip, String>() { @Override public String apply(Ip arg0) { return Strings.emptyToNull(arg0.getIp()); } }), Predicates.notNull()); builder.publicAddresses(Iterables.filter(addresses, Predicates.not(IsPrivateIPAddress.INSTANCE))); builder.privateAddresses(Iterables.filter(addresses, IsPrivateIPAddress.INSTANCE)); return builder.build(); } @Inject  ServerDetailsToNodeMetadata(@Memoized Supplier<Set<? extends Location>> locations,
         @Memoized Supplier<Set<? extends Image>> images, GroupNamingConvention.Factory namingConvention); }
ServerDetailsToNodeMetadata implements Function<ServerDetails, NodeMetadata> { @Override public NodeMetadata apply(ServerDetails from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getHostname()); builder.hostname(from.getHostname()); Location location = FluentIterable.from(locations.get()).firstMatch(idEquals(from.getDatacenter())).orNull(); checkState(location != null, "no location matched ServerDetails %s", from); Map<String, String> metadataMap; if (!isNullOrEmpty(from.getDescription()) && from.getDescription().matches("^[0-9A-Fa-f]+$")) { String decoded = new String(base16().lowerCase().decode(from.getDescription()), UTF_8); metadataMap = Splitter.on('\n').withKeyValueSeparator("=").split(decoded); addMetadataAndParseTagsFromCommaDelimitedValue(builder, metadataMap); } else { metadataMap = ImmutableMap.of(); } builder.group(groupFromMapOrName(metadataMap, from.getHostname(), nodeNamingConvention)); builder.imageId(from.getTemplateName() + ""); builder.operatingSystem(parseOperatingSystem(from)); builder.hardware(new HardwareBuilder().ids(from.getId() + "").ram(from.getMemorySizeMB()) .processors(ImmutableList.of(new Processor(from.getCpuCores(), 1.0))) .volumes(ImmutableList.<Volume> of(new VolumeImpl((float) from.getDiskSizeGB(), true, true))) .hypervisor(from.getPlatform()).build()); builder.status(serverStateToNodeStatus.get(from.getState())); Iterable<String> addresses = Iterables.filter(Iterables.transform(from.getIps(), new Function<Ip, String>() { @Override public String apply(Ip arg0) { return Strings.emptyToNull(arg0.getIp()); } }), Predicates.notNull()); builder.publicAddresses(Iterables.filter(addresses, Predicates.not(IsPrivateIPAddress.INSTANCE))); builder.privateAddresses(Iterables.filter(addresses, IsPrivateIPAddress.INSTANCE)); return builder.build(); } @Inject  ServerDetailsToNodeMetadata(@Memoized Supplier<Set<? extends Location>> locations,
         @Memoized Supplier<Set<? extends Image>> images, GroupNamingConvention.Factory namingConvention); @Override NodeMetadata apply(ServerDetails from); }
ServerDetailsToNodeMetadata implements Function<ServerDetails, NodeMetadata> { @Override public NodeMetadata apply(ServerDetails from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getHostname()); builder.hostname(from.getHostname()); Location location = FluentIterable.from(locations.get()).firstMatch(idEquals(from.getDatacenter())).orNull(); checkState(location != null, "no location matched ServerDetails %s", from); Map<String, String> metadataMap; if (!isNullOrEmpty(from.getDescription()) && from.getDescription().matches("^[0-9A-Fa-f]+$")) { String decoded = new String(base16().lowerCase().decode(from.getDescription()), UTF_8); metadataMap = Splitter.on('\n').withKeyValueSeparator("=").split(decoded); addMetadataAndParseTagsFromCommaDelimitedValue(builder, metadataMap); } else { metadataMap = ImmutableMap.of(); } builder.group(groupFromMapOrName(metadataMap, from.getHostname(), nodeNamingConvention)); builder.imageId(from.getTemplateName() + ""); builder.operatingSystem(parseOperatingSystem(from)); builder.hardware(new HardwareBuilder().ids(from.getId() + "").ram(from.getMemorySizeMB()) .processors(ImmutableList.of(new Processor(from.getCpuCores(), 1.0))) .volumes(ImmutableList.<Volume> of(new VolumeImpl((float) from.getDiskSizeGB(), true, true))) .hypervisor(from.getPlatform()).build()); builder.status(serverStateToNodeStatus.get(from.getState())); Iterable<String> addresses = Iterables.filter(Iterables.transform(from.getIps(), new Function<Ip, String>() { @Override public String apply(Ip arg0) { return Strings.emptyToNull(arg0.getIp()); } }), Predicates.notNull()); builder.publicAddresses(Iterables.filter(addresses, Predicates.not(IsPrivateIPAddress.INSTANCE))); builder.privateAddresses(Iterables.filter(addresses, IsPrivateIPAddress.INSTANCE)); return builder.build(); } @Inject  ServerDetailsToNodeMetadata(@Memoized Supplier<Set<? extends Location>> locations,
         @Memoized Supplier<Set<? extends Image>> images, GroupNamingConvention.Factory namingConvention); @Override NodeMetadata apply(ServerDetails from); static final Map<ServerDetails.State, Status> serverStateToNodeStatus; }