in aliyun-ecs/src/main/java/org/jclouds/aliyun/ecs/compute/functions/InstanceToNodeMetadata.java [76:116]
public NodeMetadata apply(Instance from) {
NodeMetadataBuilder builder = new NodeMetadataBuilder();
Optional<? extends Image> image = findImage(from.imageId());
if (image.isPresent()) {
builder.imageId(image.get().getId());
builder.operatingSystem(image.get().getOperatingSystem());
} else {
logger.info(">> image with id %s for instance %s was not found. "
+ "This might be because the image that was used to create the instance has a new id.",
from.instanceType(), from.id());
}
Optional<? extends Hardware> hardware = findHardware(from.instanceType());
if (hardware.isPresent()) {
builder.hardware(hardware.get());
} else {
logger.info(">> hardware with id %s for instance %s was not found. "
+ "This might be because the image that was used to create the instance has a new id.",
from.instanceType(), from.id());
}
builder.id(RegionAndId.slashEncodeRegionAndId(from.regionId(), from.id()));
builder.providerId(from.id());
builder.name(from.name());
builder.hostname(String.format("%s", from.hostname()));
builder.group(groupNamingConvention.extractGroup(from.name()));
builder.status(toPortableStatus.apply(from.status()));
builder.privateAddresses(from.innerIpAddress().entrySet().iterator().next().getValue());
builder.publicAddresses(from.publicIpAddress().entrySet().iterator().next().getValue());
builder.location(from(locations.get()).firstMatch(LocationPredicates.idEquals(from.regionId())).orNull());
if (from.tags() != null && !from.tags().isEmpty()) {
ImmutableMap.Builder tagsBuilder = new ImmutableMap.Builder();
for (Tag tag : from.tags().entrySet().iterator().next().getValue()) {
tagsBuilder.put(tag.key(), tag.value());
}
addMetadataAndParseTagsFromValuesOfEmptyString(builder, tagsBuilder.build());
}
NodeMetadata nodeMetadata = builder.build();
return nodeMetadata;
}