return functions;
}
@Override
public String render(OsFamily family) {
ScriptBuilder scriptBuilder = new ScriptBuilder();
Map<String, String> metadataMap = Maps.newLinkedHashMap();
metadataMap.putAll(
ImmutableMap.of(
"clusterName", clusterSpec.getClusterName(),
"cloudProvider", clusterSpec.getProvider()
)
);
if (instance != null) {
metadataMap.putAll(
ImmutableMap.of(
"roles", Joiner.on(",").join(instance.getRoles()),
"publicIp", instance.getPublicIp(),
"privateIp", instance.getPrivateIp()
)
);
if (!clusterSpec.isStub()) {
try {
metadataMap.putAll(
ImmutableMap.of(
"publicHostName", instance.getPublicHostName(),
"privateHostName", instance.getPrivateHostName()
)
);
} catch (IOException e) {
LOG.warn("Could not resolve hostname for " + instance, e);
}
}
}
for (Iterator<?> it = clusterSpec.getConfiguration().getKeys("whirr.env"); it.hasNext(); ) {
String key = (String)it.next();
String value = clusterSpec.getConfiguration().getString(key);
metadataMap.put(key.substring("whirr.env.".length()), value);
}
metadataMap.putAll(exports);
// Write export statements out directly
// Using InitBuilder would be a possible improvement
String writeVariableExporters = Utils.writeVariableExporters(metadataMap, family);
scriptBuilder.addStatement(exec(writeVariableExporters));
for (Statement statement : statements) {
scriptBuilder.addStatement(statement);
}
return scriptBuilder.render(family);
}