use of org.apache.whirr.Cluster.Instance in project whirr by apache.
the class HamaMasterClusterActionHandler method beforeConfigure.
@Override
protected void beforeConfigure(ClusterActionEvent event) throws IOException, InterruptedException {
ClusterSpec clusterSpec = event.getClusterSpec();
Cluster cluster = event.getCluster();
LOG.info("Authorizing firewall");
Instance instance = cluster.getInstanceMatching(role(ROLE));
InetAddress masterPublicAddress = instance.getPublicAddress();
event.getFirewallManager().addRules(Rule.create().destination(instance).ports(MASTER_WEB_UI_PORT), Rule.create().destination(instance).ports(MASTER_PORT));
handleFirewallRules(event);
String hamaConfigureFunction = getConfiguration(clusterSpec).getString(HamaConstants.KEY_CONFIGURE_FUNCTION, HamaConstants.FUNCTION_POST_CONFIGURE);
String master = masterPublicAddress.getHostName();
String quorum = ZooKeeperCluster.getHosts(cluster);
String tarurl = prepareRemoteFileUrl(event, getConfiguration(clusterSpec).getString(HamaConstants.KEY_TARBALL_URL));
addStatement(event, call("retry_helpers"));
addStatement(event, call(hamaConfigureFunction, ROLE, HamaConstants.PARAM_MASTER, master, HamaConstants.PARAM_QUORUM, quorum, HamaConstants.PARAM_TARBALL_URL, tarurl));
String hamaStartFunction = getConfiguration(clusterSpec).getString(HamaConstants.KEY_START_FUNCTION, HamaConstants.FUNCTION_START);
addStatement(event, call(hamaStartFunction, ROLE, HamaConstants.PARAM_TARBALL_URL, tarurl));
}
use of org.apache.whirr.Cluster.Instance in project whirr by apache.
the class HamaMasterClusterActionHandler method afterConfigure.
@Override
protected void afterConfigure(ClusterActionEvent event) throws IOException {
ClusterSpec clusterSpec = event.getClusterSpec();
Cluster cluster = event.getCluster();
LOG.info("Completed configuration of {}", clusterSpec.getClusterName());
Instance instance = cluster.getInstanceMatching(role(ROLE));
InetAddress masterPublicAddress = instance.getPublicAddress();
LOG.info("BSPMaster web UI available at http://{}:{}", masterPublicAddress.getHostName(), MASTER_WEB_UI_PORT);
String quorum = ZooKeeperCluster.getHosts(cluster);
Properties config = createClientSideProperties(masterPublicAddress, quorum);
createClientSideHadoopSiteFile(clusterSpec, config);
createProxyScript(clusterSpec, cluster);
event.setCluster(new Cluster(cluster.getInstances(), config));
}
use of org.apache.whirr.Cluster.Instance in project whirr by apache.
the class PuppetServiceTest method testHttpAvailable.
@Test(timeout = TestConstants.ITEST_TIMEOUT)
public void testHttpAvailable() throws Exception {
// check that the http server started
for (Instance instance : cluster.getInstances()) {
// first, check the socket
HostAndPort socket = HostAndPort.fromParts(instance.getPublicAddress().getHostAddress(), 80);
assert socketTester.apply(socket) : instance;
// then, try a GET
URI httpUrl = URI.create("http://" + instance.getPublicAddress().getHostAddress());
Strings2.toStringAndClose(httpUrl.toURL().openStream());
}
}
use of org.apache.whirr.Cluster.Instance in project whirr by apache.
the class ClusterActionHandlerSupport method addClusterToEtcHostsAndFirewall.
public static void addClusterToEtcHostsAndFirewall(ClusterActionEvent event) throws IOException {
if (event.getClusterSpec().isStoreClusterInEtcHosts()) {
addStatement(event, exec("echo -e '\\n' >> /etc/hosts"));
for (Instance instance : event.getCluster().getInstances()) {
// Remove any existing references to this IP from /etc/hosts
addStatement(event, exec(String.format("sed -i -e '/%s/d' /etc/hosts", instance.getPublicIp())));
// Add this IP to /etc/hosts
addStatement(event, exec(String.format("echo -e '\\n%s %s' >> /etc/hosts", instance.getPublicIp(), instance.getPublicHostName())));
// Allow access to this host on all ports from this public IP
addStatement(event, exec(String.format("iptables -I INPUT 1 -p tcp --source %s -j ACCEPT || true", instance.getPublicIp())));
if (instance.getPrivateIp() != null) {
// Allow access to this host on all ports from this private IP
addStatement(event, exec(String.format("iptables -I INPUT 1 -p tcp --source %s -j ACCEPT || true", instance.getPrivateIp())));
}
}
addStatement(event, exec("test -f /etc/hostname && echo $PUBLIC_HOST_NAME > /etc/hostname || true"));
addStatement(event, exec("test -f /etc/sysconfig/network && sed -i -e \"s/HOSTNAME=.*/HOSTNAME=$PUBLIC_HOST_NAME/\" /etc/sysconfig/network || true"));
addStatement(event, exec("test -f /etc/init.d/hostname && /etc/init.d/hostname restart || hostname $PUBLIC_HOST_NAME"));
addStatement(event, exec("sleep 2"));
addStatement(event, exec("iptables-save || true"));
}
}
use of org.apache.whirr.Cluster.Instance in project whirr by apache.
the class ScriptBasedClusterAction method runScripts.
protected void runScripts(Map<InstanceTemplate, ClusterActionEvent> eventMap) throws InterruptedException, IOException {
final String phaseName = getAction();
final Collection<Future<ExecResponse>> futures = Sets.newHashSet();
final ClusterSpec clusterSpec = eventMap.values().iterator().next().getClusterSpec();
final RunScriptOptions options = overrideLoginCredentials(LoginCredentials.builder().user(clusterSpec.getClusterUser()).privateKey(clusterSpec.getPrivateKey()).build());
for (Map.Entry<InstanceTemplate, ClusterActionEvent> entry : eventMap.entrySet()) {
if (shouldIgnoreInstanceTemplate(entry.getKey())) {
// skip if not in the target
continue;
}
Cluster cluster = entry.getValue().getCluster();
StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();
if (statementBuilder.isEmpty()) {
// skip execution if we have an empty list
continue;
}
Set<Instance> instances = cluster.getInstancesMatching(Predicates.<Instance>and(onlyRolesIn(entry.getKey().getRoles()), not(instanceIsNotInTarget())));
LOG.info("Starting to run scripts on cluster for phase {} " + "on instances: {}", phaseName, asString(instances));
for (Instance instance : instances) {
futures.add(runStatementOnInstanceInCluster(statementBuilder, instance, clusterSpec, options));
}
}
for (Future<ExecResponse> future : futures) {
try {
future.get();
} catch (ExecutionException e) {
throw new IOException(e.getCause());
}
}
LOG.info("Finished running {} phase scripts on all cluster instances", phaseName);
}
Aggregations