String group = groupFromMapOrName(input.getMetadata().getItems(),
input.getName(), nodeNamingConvention);
FluentIterable<String> tags = FluentIterable.from(input.getTags().getItems())
.filter(Predicates.not(firewallTagNamingConvention.get(group).isFirewallTag()));
NodeMetadataBuilder builder = new NodeMetadataBuilder();
builder.id(SlashEncodedIds.fromTwoIds(checkNotNull(locations.get().get(input.getZone()),
"location for %s", input.getZone())
.getId(), input.getName()).slashEncode())
.name(input.getName())
.providerId(input.getId())
.hostname(input.getName())
.location(checkNotNull(locations.get().get(input.getZone()), "location for %s", input.getZone()))
.hardware(checkNotNull(hardwares.get().get(input.getMachineType()), "hardware type for %s",
input.getMachineType().toString()))
.status(toPortableNodeStatus.get(input.getStatus()))
.tags(tags)
.uri(input.getSelfLink())
.userMetadata(input.getMetadata().getItems())
.group(group)
.privateAddresses(collectPrivateAddresses(input))
.publicAddresses(collectPublicAddresses(input));
if (input.getMetadata().getItems().containsKey(GCE_IMAGE_METADATA_KEY)) {
try {
URI imageUri = URI.create(input.getMetadata().getItems()
.get(GCE_IMAGE_METADATA_KEY));
Map<URI, ? extends Image> imagesMap = images.get();
Image image = checkNotNull(imagesMap.get(imageUri),
"no image for %s. images: %s", imageUri,
imagesMap.values());
builder.imageId(image.getId());
} catch (IllegalArgumentException e) {
// Swallow any exception here - it just means we don't actually have a valid image URI, so we skip it.
}
}
return builder.build();
}