public NodeMetadata apply(ServerInZone serverInZone) {
Location zone = locationIndex.get().get(serverInZone.getZone());
checkState(zone != null, "location %s not in locationIndex: %s", serverInZone.getZone(), locationIndex.get());
Server from = serverInZone.getServer();
NodeMetadataBuilder builder = new NodeMetadataBuilder();
builder.id(serverInZone.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(zone).build() : zone);
builder.group(groupFromMapOrName(from.getMetadata(), from.getName(), nodeNamingConvention));
addMetadataAndParseTagsFromCommaDelimitedValue(builder, from.getMetadata());
builder.imageId(ZoneAndId.fromZoneAndId(serverInZone.getZone(), from.getImage().getId()).slashEncode());
builder.operatingSystem(findOperatingSystemForServerOrNull(serverInZone));
builder.hardware(findHardwareForServerOrNull(serverInZone));
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, not(isPrivateAddress)),
AddressToStringTransformationFunction.INSTANCE),
isInet4Address));
builder.privateAddresses(
filter(
transform(
filter(addresses, isPrivateAddress),
AddressToStringTransformationFunction.INSTANCE),
isInet4Address));
for (Link link: from.getLinks()) {
if (link.getRelation().equals(Link.Relation.SELF)) {
builder.uri(link.getHref());
}
}
return builder.build();
}