@Test public void testServerWithoutImage() { Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f216543fd") .providerId("52415800-8b69-11e0-9b19-734f216543fd").location(region).build(); Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54") .operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build()) .providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").status(Image.Status.AVAILABLE) .location(region).build(); Server serverToConvert = new ParseServerWithoutImageTest().expected(); ServerInRegion serverInRegionToConvert = new ServerInRegion(serverToConvert, "az-1.region-a.geo-1"); ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata( NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.of(existingImage)), Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet.of(existingHardware)), namingConvention); NodeMetadata convertedNodeMetadata = converter.apply(serverInRegionToConvert); assertNull(convertedNodeMetadata.getImageId()); }
@Override public NodeMetadata apply(ServerInRegion serverInRegion) { Location region = locationIndex.get().get(serverInRegion.getRegion()); checkState(region != null, "location %s not in locationIndex: %s", serverInRegion.getRegion(), locationIndex.get()); Server from = serverInRegion.getServer(); NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.id(serverInRegion.slashEncode()); builder.providerId(from.getId()); builder.name(from.getName()); builder.hostname(from.getName()); builder.location(from.getHostId() != null ? new LocationBuilder().scope(LocationScope.HOST).id(from.getHostId()) .description(from.getHostId()).parent(region).build() : region); builder.group(groupFromMapOrName(from.getMetadata(), from.getName(), nodeNamingConvention)); addMetadataAndParseTagsFromCommaDelimitedValue(builder, from.getMetadata()); if (from.getImage() != null) { builder.imageId(RegionAndId.fromRegionAndId(serverInRegion.getRegion(), from.getImage().getId()).slashEncode()); } builder.operatingSystem(findOperatingSystemForServerOrNull(serverInRegion)); builder.hardware(findHardwareForServerOrNull(serverInRegion)); builder.status(toPortableNodeStatus.get(from.getStatus())); Set<Address> addresses = newHashSet(from.getAddresses().values()); if (from.getAccessIPv4() != null) { addresses.add(createV4(from.getAccessIPv4())); } if (from.getAccessIPv6() != null) { addresses.add(createV6(from.getAccessIPv6())); } builder.publicAddresses( filter( transform( filter(addresses, or(isFloatingAddress, not(isPrivateAddress))), AddressToStringTransformationFunction.INSTANCE), isInet4Address)); builder.privateAddresses( filter( transform( filter(addresses, and(not(isFloatingAddress), isPrivateAddress)), AddressToStringTransformationFunction.INSTANCE), isInet4Address)); for (Link link : from.getLinks()) { if (link.getRelation().equals(Link.Relation.SELF)) { builder.uri(link.getHref()); } } return builder.build(); }
ServerInRegionToNodeMetadata implements Function<ServerInRegion, NodeMetadata> { @Override public NodeMetadata apply(ServerInRegion serverInRegion) { Location region = locationIndex.get().get(serverInRegion.getRegion()); checkState(region != null, "location %s not in locationIndex: %s", serverInRegion.getRegion(), locationIndex.get()); Server from = serverInRegion.getServer(); NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.id(serverInRegion.slashEncode()); builder.providerId(from.getId()); builder.name(from.getName()); builder.hostname(from.getName()); builder.location(from.getHostId() != null ? new LocationBuilder().scope(LocationScope.HOST).id(from.getHostId()) .description(from.getHostId()).parent(region).build() : region); builder.group(groupFromMapOrName(from.getMetadata(), from.getName(), nodeNamingConvention)); addMetadataAndParseTagsFromCommaDelimitedValue(builder, from.getMetadata()); if (from.getImage() != null) { builder.imageId(RegionAndId.fromRegionAndId(serverInRegion.getRegion(), from.getImage().getId()).slashEncode()); } builder.operatingSystem(findOperatingSystemForServerOrNull(serverInRegion)); builder.hardware(findHardwareForServerOrNull(serverInRegion)); builder.status(toPortableNodeStatus.get(from.getStatus())); Set<Address> addresses = newHashSet(from.getAddresses().values()); if (from.getAccessIPv4() != null) { addresses.add(createV4(from.getAccessIPv4())); } if (from.getAccessIPv6() != null) { addresses.add(createV6(from.getAccessIPv6())); } builder.publicAddresses( filter( transform( filter(addresses, or(isFloatingAddress, not(isPrivateAddress))), AddressToStringTransformationFunction.INSTANCE), isInet4Address)); builder.privateAddresses( filter( transform( filter(addresses, and(not(isFloatingAddress), isPrivateAddress)), AddressToStringTransformationFunction.INSTANCE), isInet4Address)); for (Link link : from.getLinks()) { if (link.getRelation().equals(Link.Relation.SELF)) { builder.uri(link.getHref()); } } return builder.build(); } }
ServerInRegionToNodeMetadata implements Function<ServerInRegion, NodeMetadata> { @Override public NodeMetadata apply(ServerInRegion serverInRegion) { Location region = locationIndex.get().get(serverInRegion.getRegion()); checkState(region != null, "location %s not in locationIndex: %s", serverInRegion.getRegion(), locationIndex.get()); Server from = serverInRegion.getServer(); NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.id(serverInRegion.slashEncode()); builder.providerId(from.getId()); builder.name(from.getName()); builder.hostname(from.getName()); builder.location(from.getHostId() != null ? new LocationBuilder().scope(LocationScope.HOST).id(from.getHostId()) .description(from.getHostId()).parent(region).build() : region); builder.group(groupFromMapOrName(from.getMetadata(), from.getName(), nodeNamingConvention)); addMetadataAndParseTagsFromCommaDelimitedValue(builder, from.getMetadata()); if (from.getImage() != null) { builder.imageId(RegionAndId.fromRegionAndId(serverInRegion.getRegion(), from.getImage().getId()).slashEncode()); } builder.operatingSystem(findOperatingSystemForServerOrNull(serverInRegion)); builder.hardware(findHardwareForServerOrNull(serverInRegion)); builder.status(toPortableNodeStatus.get(from.getStatus())); Set<Address> addresses = newHashSet(from.getAddresses().values()); if (from.getAccessIPv4() != null) { addresses.add(createV4(from.getAccessIPv4())); } if (from.getAccessIPv6() != null) { addresses.add(createV6(from.getAccessIPv6())); } builder.publicAddresses( filter( transform( filter(addresses, or(isFloatingAddress, not(isPrivateAddress))), AddressToStringTransformationFunction.INSTANCE), isInet4Address)); builder.privateAddresses( filter( transform( filter(addresses, and(not(isFloatingAddress), isPrivateAddress)), AddressToStringTransformationFunction.INSTANCE), isInet4Address)); for (Link link : from.getLinks()) { if (link.getRelation().equals(Link.Relation.SELF)) { builder.uri(link.getHref()); } } return builder.build(); } @Inject  ServerInRegionToNodeMetadata(Map<Server.Status, NodeMetadata.Status> toPortableNodeStatus,
            Supplier<Map<String, Location>> locationIndex, @Memoized Supplier<Set<? extends Image>> images,
            @Memoized Supplier<Set<? extends Hardware>> hardwares, GroupNamingConvention.Factory namingConvention); }
ServerInRegionToNodeMetadata implements Function<ServerInRegion, NodeMetadata> { @Override public NodeMetadata apply(ServerInRegion serverInRegion) { Location region = locationIndex.get().get(serverInRegion.getRegion()); checkState(region != null, "location %s not in locationIndex: %s", serverInRegion.getRegion(), locationIndex.get()); Server from = serverInRegion.getServer(); NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.id(serverInRegion.slashEncode()); builder.providerId(from.getId()); builder.name(from.getName()); builder.hostname(from.getName()); builder.location(from.getHostId() != null ? new LocationBuilder().scope(LocationScope.HOST).id(from.getHostId()) .description(from.getHostId()).parent(region).build() : region); builder.group(groupFromMapOrName(from.getMetadata(), from.getName(), nodeNamingConvention)); addMetadataAndParseTagsFromCommaDelimitedValue(builder, from.getMetadata()); if (from.getImage() != null) { builder.imageId(RegionAndId.fromRegionAndId(serverInRegion.getRegion(), from.getImage().getId()).slashEncode()); } builder.operatingSystem(findOperatingSystemForServerOrNull(serverInRegion)); builder.hardware(findHardwareForServerOrNull(serverInRegion)); builder.status(toPortableNodeStatus.get(from.getStatus())); Set<Address> addresses = newHashSet(from.getAddresses().values()); if (from.getAccessIPv4() != null) { addresses.add(createV4(from.getAccessIPv4())); } if (from.getAccessIPv6() != null) { addresses.add(createV6(from.getAccessIPv6())); } builder.publicAddresses( filter( transform( filter(addresses, or(isFloatingAddress, not(isPrivateAddress))), AddressToStringTransformationFunction.INSTANCE), isInet4Address)); builder.privateAddresses( filter( transform( filter(addresses, and(not(isFloatingAddress), isPrivateAddress)), AddressToStringTransformationFunction.INSTANCE), isInet4Address)); for (Link link : from.getLinks()) { if (link.getRelation().equals(Link.Relation.SELF)) { builder.uri(link.getHref()); } } return builder.build(); } @Inject  ServerInRegionToNodeMetadata(Map<Server.Status, NodeMetadata.Status> toPortableNodeStatus,
            Supplier<Map<String, Location>> locationIndex, @Memoized Supplier<Set<? extends Image>> images,
            @Memoized Supplier<Set<? extends Hardware>> hardwares, GroupNamingConvention.Factory namingConvention); @Override NodeMetadata apply(ServerInRegion serverInRegion); T findObjectOfTypeForServerOrNull(Set<? extends T> supply, String type,
         final String objectId, final RegionAndId serverInRegion); }
ServerInRegionToNodeMetadata implements Function<ServerInRegion, NodeMetadata> { @Override public NodeMetadata apply(ServerInRegion serverInRegion) { Location region = locationIndex.get().get(serverInRegion.getRegion()); checkState(region != null, "location %s not in locationIndex: %s", serverInRegion.getRegion(), locationIndex.get()); Server from = serverInRegion.getServer(); NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.id(serverInRegion.slashEncode()); builder.providerId(from.getId()); builder.name(from.getName()); builder.hostname(from.getName()); builder.location(from.getHostId() != null ? new LocationBuilder().scope(LocationScope.HOST).id(from.getHostId()) .description(from.getHostId()).parent(region).build() : region); builder.group(groupFromMapOrName(from.getMetadata(), from.getName(), nodeNamingConvention)); addMetadataAndParseTagsFromCommaDelimitedValue(builder, from.getMetadata()); if (from.getImage() != null) { builder.imageId(RegionAndId.fromRegionAndId(serverInRegion.getRegion(), from.getImage().getId()).slashEncode()); } builder.operatingSystem(findOperatingSystemForServerOrNull(serverInRegion)); builder.hardware(findHardwareForServerOrNull(serverInRegion)); builder.status(toPortableNodeStatus.get(from.getStatus())); Set<Address> addresses = newHashSet(from.getAddresses().values()); if (from.getAccessIPv4() != null) { addresses.add(createV4(from.getAccessIPv4())); } if (from.getAccessIPv6() != null) { addresses.add(createV6(from.getAccessIPv6())); } builder.publicAddresses( filter( transform( filter(addresses, or(isFloatingAddress, not(isPrivateAddress))), AddressToStringTransformationFunction.INSTANCE), isInet4Address)); builder.privateAddresses( filter( transform( filter(addresses, and(not(isFloatingAddress), isPrivateAddress)), AddressToStringTransformationFunction.INSTANCE), isInet4Address)); for (Link link : from.getLinks()) { if (link.getRelation().equals(Link.Relation.SELF)) { builder.uri(link.getHref()); } } return builder.build(); } @Inject  ServerInRegionToNodeMetadata(Map<Server.Status, NodeMetadata.Status> toPortableNodeStatus,
            Supplier<Map<String, Location>> locationIndex, @Memoized Supplier<Set<? extends Image>> images,
            @Memoized Supplier<Set<? extends Hardware>> hardwares, GroupNamingConvention.Factory namingConvention); @Override NodeMetadata apply(ServerInRegion serverInRegion); T findObjectOfTypeForServerOrNull(Set<? extends T> supply, String type,
         final String objectId, final RegionAndId serverInRegion); static final Predicate<Address> isFloatingAddress; static final Predicate<Address> isPrivateAddress; static final Predicate<String> isInet4Address; }