.authorizePublicKey(clusterSpec.getPublicKey()));
TemplateBuilderStrategy strategy = new HadoopTemplateBuilderStrategy();
strategy.configureTemplateBuilder(clusterSpec, masterTemplateBuilder);
Template masterTemplate = masterTemplateBuilder.build();
InstanceTemplate instanceTemplate = clusterSpec.getInstanceTemplate(MASTER_ROLE);
checkNotNull(instanceTemplate);
checkArgument(instanceTemplate.getNumberOfInstances() == 1);
Set<? extends NodeMetadata> nodes;
try {
LOG.info("Starting master node");
nodes = computeService.runNodesWithTag(
clusterSpec.getClusterName(), 1, masterTemplate);
LOG.info("Master node started: {}", nodes);
} catch (RunNodesException e) {
// TODO: can we do better here (retry?)
throw new IOException(e);
}
NodeMetadata node = Iterables.getOnlyElement(nodes);
InetAddress namenodePublicAddress = InetAddress.getByName(Iterables.get(node.getPublicAddresses(),0));
InetAddress jobtrackerPublicAddress = InetAddress.getByName(Iterables.get(node.getPublicAddresses(),0));
LOG.info("Authorizing firewall");
FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
WEB_PORT);
FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
NAMENODE_WEB_UI_PORT);
FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
JOBTRACKER_WEB_UI_PORT);
FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
namenodePublicAddress.getHostAddress(), NAMENODE_PORT);
FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
namenodePublicAddress.getHostAddress(), JOBTRACKER_PORT);
if (!namenodePublicAddress.equals(jobtrackerPublicAddress)) {
FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
jobtrackerPublicAddress.getHostAddress(), NAMENODE_PORT);
FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
jobtrackerPublicAddress.getHostAddress(), JOBTRACKER_PORT);
}
// Launch slaves (DN and TT)
Payload slaveBootScript = newStringPayload(runUrls(clusterSpec.getRunUrlBase(),
String.format("util/configure-hostnames -c %s", clusterSpec.getProvider()),
"sun/java/install",
String.format("%s dn,tt -n %s -j %s -c %s",
hadoopInstallRunUrl,
namenodePublicAddress.getHostName(),
jobtrackerPublicAddress.getHostName(),
clusterSpec.getProvider())));
TemplateBuilder slaveTemplateBuilder = computeService.templateBuilder()
.options(runScript(slaveBootScript)
.installPrivateKey(clusterSpec.getPrivateKey())
.authorizePublicKey(clusterSpec.getPublicKey()));
slaveTemplateBuilder.fromTemplate(masterTemplate); // base on master
slaveTemplateBuilder.locationId(masterTemplate.getLocation().getId());
Template slaveTemplate = slaveTemplateBuilder.build();
instanceTemplate = clusterSpec.getInstanceTemplate(WORKER_ROLE);
checkNotNull(instanceTemplate);
Set<? extends NodeMetadata> workerNodes;