Search in sources :

Example 26 with ClusterSpec

use of org.apache.whirr.ClusterSpec in project whirr by apache.

the class HadoopNameNodeClusterActionHandler method afterConfigure.

@Override
protected void afterConfigure(ClusterActionEvent event) throws IOException {
    ClusterSpec clusterSpec = event.getClusterSpec();
    Cluster cluster = event.getCluster();
    // TODO: wait for TTs to come up (done in test for the moment)
    LOG.info("Completed configuration of {} role {}", clusterSpec.getClusterName(), getRole());
    InetAddress namenodePublicAddress = HadoopCluster.getNamenodePublicAddress(cluster);
    InetAddress jobtrackerPublicAddress = HadoopCluster.getJobTrackerPublicAddress(cluster);
    LOG.info("Namenode web UI available at http://{}:{}", namenodePublicAddress.getHostName(), HadoopCluster.NAMENODE_WEB_UI_PORT);
    Properties config = createClientSideProperties(clusterSpec, namenodePublicAddress, jobtrackerPublicAddress);
    createClientSideHadoopSiteFile(clusterSpec, config);
    createProxyScript(clusterSpec, cluster);
    Properties combined = new Properties();
    combined.putAll(cluster.getConfiguration());
    combined.putAll(config);
    event.setCluster(new Cluster(cluster.getInstances(), combined));
}
Also used : Cluster(org.apache.whirr.Cluster) ClusterSpec(org.apache.whirr.ClusterSpec) Properties(java.util.Properties) InetAddress(java.net.InetAddress)

Example 27 with ClusterSpec

use of org.apache.whirr.ClusterSpec in project whirr by apache.

the class HadoopJobTrackerClusterActionHandler method afterConfigure.

@Override
protected void afterConfigure(ClusterActionEvent event) throws IOException {
    ClusterSpec clusterSpec = event.getClusterSpec();
    Cluster cluster = event.getCluster();
    LOG.info("Completed configuration of {} role {}", clusterSpec.getClusterName(), getRole());
    InetAddress jobtrackerPublicAddress = HadoopCluster.getJobTrackerPublicAddress(cluster);
    LOG.info("Jobtracker web UI available at http://{}:{}", jobtrackerPublicAddress.getHostName(), HadoopCluster.JOBTRACKER_WEB_UI_PORT);
}
Also used : Cluster(org.apache.whirr.Cluster) ClusterSpec(org.apache.whirr.ClusterSpec) InetAddress(java.net.InetAddress)

Example 28 with ClusterSpec

use of org.apache.whirr.ClusterSpec in project whirr by apache.

the class BootstrapClusterAction method doAction.

@Override
protected void doAction(Map<InstanceTemplate, ClusterActionEvent> eventMap) throws IOException, InterruptedException {
    LOG.info("Bootstrapping cluster");
    ExecutorService executorService = Executors.newCachedThreadPool();
    Map<InstanceTemplate, Future<Set<? extends NodeMetadata>>> futures = Maps.newHashMap();
    // initialize startup processes per InstanceTemplates
    for (Entry<InstanceTemplate, ClusterActionEvent> entry : eventMap.entrySet()) {
        final InstanceTemplate instanceTemplate = entry.getKey();
        final ClusterSpec clusterSpec = entry.getValue().getClusterSpec();
        final int maxNumberOfRetries = clusterSpec.getMaxStartupRetries();
        StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();
        ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec);
        final ComputeService computeService = computeServiceContext.getComputeService();
        final Template template = BootstrapTemplate.build(clusterSpec, computeService, statementBuilder, entry.getKey());
        Future<Set<? extends NodeMetadata>> nodesFuture = executorService.submit(new StartupProcess(clusterSpec.getClusterName(), instanceTemplate.getNumberOfInstances(), instanceTemplate.getMinNumberOfInstances(), maxNumberOfRetries, instanceTemplate.getRoles(), computeService, template, executorService, nodeStarterFactory));
        futures.put(instanceTemplate, nodesFuture);
    }
    Set<Instance> instances = Sets.newLinkedHashSet();
    for (Entry<InstanceTemplate, Future<Set<? extends NodeMetadata>>> entry : futures.entrySet()) {
        Set<? extends NodeMetadata> nodes;
        try {
            nodes = entry.getValue().get();
        } catch (ExecutionException e) {
            // nodes after retries
            throw new IOException(e);
        }
        Set<String> roles = entry.getKey().getRoles();
        instances.addAll(getInstances(roles, nodes));
    }
    Cluster cluster = new Cluster(instances);
    for (ClusterActionEvent event : eventMap.values()) {
        event.setCluster(cluster);
    }
}
Also used : Set(java.util.Set) Instance(org.apache.whirr.Cluster.Instance) ClusterActionEvent(org.apache.whirr.service.ClusterActionEvent) InstanceTemplate(org.apache.whirr.InstanceTemplate) Template(org.jclouds.compute.domain.Template) BootstrapTemplate(org.apache.whirr.compute.BootstrapTemplate) StartupProcess(org.apache.whirr.compute.StartupProcess) ExecutionException(java.util.concurrent.ExecutionException) Cluster(org.apache.whirr.Cluster) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) ClusterSpec(org.apache.whirr.ClusterSpec) IOException(java.io.IOException) ComputeService(org.jclouds.compute.ComputeService) NodeMetadata(org.jclouds.compute.domain.NodeMetadata) StatementBuilder(org.apache.whirr.service.jclouds.StatementBuilder) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) InstanceTemplate(org.apache.whirr.InstanceTemplate)

Example 29 with ClusterSpec

use of org.apache.whirr.ClusterSpec in project whirr by apache.

the class DestroyClusterCommandTest method testAllOptions.

@Test
public void testAllOptions() throws Exception {
    ClusterControllerFactory factory = mock(ClusterControllerFactory.class);
    ClusterController controller = mock(ClusterController.class);
    when(factory.create((String) any())).thenReturn(controller);
    DestroyClusterCommand command = new DestroyClusterCommand(factory);
    Map<String, File> keys = KeyPair.generateTemporaryFiles();
    int rc = command.run(null, out, null, Lists.newArrayList("--instance-templates", "1 noop", "--service-name", "test-service", "--cluster-name", "test-cluster", "--provider", "rackspace", "--identity", "myusername", "--credential", "mypassword", "--private-key-file", keys.get("private").getAbsolutePath(), "--version", "version-string"));
    assertThat(rc, is(0));
    Configuration conf = new PropertiesConfiguration();
    conf.addProperty("whirr.version", "version-string");
    conf.addProperty("whirr.instance-templates", "1 noop");
    ClusterSpec expectedClusterSpec = ClusterSpec.withTemporaryKeys(conf);
    expectedClusterSpec.setServiceName("test-service");
    expectedClusterSpec.setProvider("rackspace");
    expectedClusterSpec.setIdentity("myusername");
    expectedClusterSpec.setCredential("mypassword");
    expectedClusterSpec.setClusterName("test-cluster");
    expectedClusterSpec.setPrivateKey(keys.get("private"));
    expectedClusterSpec.setPublicKey(keys.get("public"));
    verify(factory).create("test-service");
    verify(controller).destroyCluster(expectedClusterSpec);
}
Also used : ClusterController(org.apache.whirr.ClusterController) Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Matchers.containsString(org.hamcrest.Matchers.containsString) ClusterSpec(org.apache.whirr.ClusterSpec) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Test(org.junit.Test)

Example 30 with ClusterSpec

use of org.apache.whirr.ClusterSpec in project whirr by apache.

the class ClusterActionHandlerSupport method handleFirewallRules.

/**
 * Handles firewall rules for a given event.
 */
public static void handleFirewallRules(ClusterActionEvent event) {
    ClusterSpec clusterSpec = event.getClusterSpec();
    for (Statement statement : event.getFirewallManager().getRulesAsStatements()) {
        addStatement(event, statement);
    }
    event.getFirewallManager().authorizeAllRules();
}
Also used : Statement(org.jclouds.scriptbuilder.domain.Statement) RunUrlStatement(org.apache.whirr.service.jclouds.RunUrlStatement) ClusterSpec(org.apache.whirr.ClusterSpec)

Aggregations

ClusterSpec (org.apache.whirr.ClusterSpec)98 Configuration (org.apache.commons.configuration.Configuration)39 Cluster (org.apache.whirr.Cluster)35 Test (org.junit.Test)34 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)16 Instance (org.apache.whirr.Cluster.Instance)14 ClusterController (org.apache.whirr.ClusterController)10 InetAddress (java.net.InetAddress)9 DryRun (org.apache.whirr.service.DryRunModule.DryRun)9 OptionSet (joptsimple.OptionSet)8 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)8 ZooKeeperCluster (org.apache.whirr.service.zookeeper.ZooKeeperCluster)8 IOException (java.io.IOException)7 ComputeService (org.jclouds.compute.ComputeService)7 File (java.io.File)6 ClusterControllerFactory (org.apache.whirr.ClusterControllerFactory)6 ComputeServiceContext (org.jclouds.compute.ComputeServiceContext)6 Set (java.util.Set)5 Stack (java.util.Stack)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5