this.credentialStore = checkNotNull(credentialStore, "credentialStore");
this.vAppStatusToNodeStatus = checkNotNull(vAppStatusToNodeStatus, "vAppStatusToNodeStatus");
}
public NodeMetadata apply(VApp from) {
NodeMetadataBuilder builder = new NodeMetadataBuilder();
builder.ids(from.getHref().toASCIIString());
builder.uri(from.getHref());
builder.name(from.getName());
String groupName = "";
Map<String, String> metadataMap;
if (!isNullOrEmpty(from.getDescription())
&& from.getDescription().indexOf('=') != -1
&& from.getDescription().indexOf('\n') != -1) {
try {
metadataMap = Splitter.on('\n').withKeyValueSeparator("=").split(from.getDescription());
addMetadataAndParseTagsFromCommaDelimitedValue(builder, metadataMap);
} catch (IllegalArgumentException iae) {
// no op
metadataMap = ImmutableMap.of();
}
} else {
metadataMap = ImmutableMap.of();
}
builder.hostname(from.getName());
builder.location(findLocationForResourceInVDC.apply(from.getVDC()));
builder.group(groupFromMapOrName(metadataMap, from.getName(), nodeNamingConvention));
builder.operatingSystem(toComputeOs(from, null));
builder.hardware(hardwareForVApp.apply(from));
builder.status(vAppStatusToNodeStatus.get(from.getStatus()));
Set<String> addresses = getIpsFromVApp(from);
builder.publicAddresses(filter(addresses, not(IsPrivateIPAddress.INSTANCE)));
builder.privateAddresses(filter(addresses, IsPrivateIPAddress.INSTANCE));
// normally, we don't affect the credential store when reading vApps.
// However, login user, etc, is actually in the metadata, so lets see
Credentials fromApi = getCredentialsFrom(from);
if (fromApi != null && !credentialStore.containsKey("node#" + from.getHref().toASCIIString()))
credentialStore.put("node#" + from.getHref().toASCIIString(), fromApi);
return builder.build();
}