Search in sources :

Example 1 with ClusterSpec

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

the class ListCluster method doExecute.

@Override
protected Object doExecute() throws Exception {
    validateInput();
    ListClusterCommand command = new ListClusterCommand(clusterControllerFactory);
    ClusterSpec clusterSpec = getClusterSpec();
    if (clusterSpec != null) {
        command.run(System.in, System.out, System.err, clusterSpec);
    }
    return null;
}
Also used : ListClusterCommand(org.apache.whirr.cli.command.ListClusterCommand) ClusterSpec(org.apache.whirr.ClusterSpec)

Example 2 with ClusterSpec

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

the class BlobCacheTest method testSelectBestLocation.

@Test
public void testSelectBestLocation() throws Exception {
    ClusterSpec spec = getTestClusterSpec();
    if (!spec.getProvider().equals("aws") && !spec.getProvider().equals("aws-ec2")) {
        // this test can be executed only on amazon but the internal
        return;
    // location selection mechanism should work for any cloud provider
    }
    spec.setTemplate(TemplateBuilderSpec.parse("locationId=eu-west-1"));
    BlobCache cache = BlobCache.getInstance(ComputeCache.INSTANCE, spec);
    assertThat(cache.getLocation().getId(), is("EU"));
}
Also used : BlobCache(org.apache.whirr.util.BlobCache) ClusterSpec(org.apache.whirr.ClusterSpec) Test(org.junit.Test)

Example 3 with ClusterSpec

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

the class BlobCacheTest method testSpecifyCacheContainerInConfig.

@Test
public void testSpecifyCacheContainerInConfig() throws Exception {
    ClusterSpec spec = getTestClusterSpec();
    BlobStoreContext context = BlobStoreContextBuilder.build(spec);
    String container = generateRandomContainerName(context);
    LOG.info("Created temporary container '{}'", container);
    try {
        spec.setBlobStoreCacheContainer(container);
        BlobCache cache = BlobCache.getInstance(ComputeCache.INSTANCE, spec);
        assertThat(cache.getContainer(), is(container));
        cache.dropAndClose();
        assertThat(context.getBlobStore().containerExists(container), is(true));
    } finally {
        LOG.info("Removing temporary container '{}'", container);
        context.getBlobStore().deleteContainer(container);
    }
}
Also used : BlobCache(org.apache.whirr.util.BlobCache) ClusterSpec(org.apache.whirr.ClusterSpec) BlobStoreContext(org.jclouds.blobstore.BlobStoreContext) Test(org.junit.Test)

Example 4 with ClusterSpec

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

the class BootstrapTemplateTest method testDifferentPrices.

@Test
public void testDifferentPrices() throws Exception {
    ClusterSpec clusterSpec = buildClusterSpecWith(ImmutableMap.of("whirr.instance-templates", "1 role1, 1 role2", "whirr.aws-ec2-spot-price", "0.1", "whirr.templates.role2.aws-ec2-spot-price", "0.3"));
    assertSpotPriceIs(clusterSpec, "role1", 0.1f);
    assertSpotPriceIs(clusterSpec, "role2", 0.3f);
}
Also used : ClusterSpec(org.apache.whirr.ClusterSpec) Test(org.junit.Test)

Example 5 with ClusterSpec

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

the class BootstrapClusterActionTest method testDoActionRetriesSucceed.

@SuppressWarnings("unchecked")
@Test
public void testDoActionRetriesSucceed() throws Exception {
    CompositeConfiguration config = new CompositeConfiguration();
    if (System.getProperty("config") != null) {
        config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
    }
    Configuration conf = new PropertiesConfiguration();
    conf.addProperty("whirr.service-name", "test-service");
    conf.addProperty("whirr.cluster-name", "test-cluster");
    conf.addProperty("whirr.instance-templates", "1 hadoop-namenode+hadoop-jobtracker,4 hadoop-datanode+hadoop-tasktracker");
    conf.addProperty("whirr.instance-templates-max-percent-failures", "60 hadoop-datanode+hadoop-tasktracker");
    conf.addProperty("whirr.provider", "ec2");
    config.addConfiguration(conf);
    ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(conf);
    Set<String> jtnn = new HashSet<String>();
    jtnn.add("hadoop-jobtracker");
    jtnn.add("hadoop-namenode");
    Set<String> dntt = new HashSet<String>();
    dntt.add("hadoop-datanode");
    dntt.add("hadoop-tasktracker");
    TestNodeStarterFactory nodeStarterFactory = null;
    ClusterActionHandler handler = mock(ClusterActionHandler.class);
    LoadingCache<String, ClusterActionHandler> handlerMap = convertMapToLoadingCache(ImmutableMap.<String, ClusterActionHandler>builder().put("hadoop-jobtracker", handler).put("hadoop-namenode", handler).put("hadoop-datanode", handler).put("hadoop-tasktracker", handler).build());
    Function<ClusterSpec, ComputeServiceContext> getCompute = mock(Function.class);
    ComputeServiceContext serviceContext = mock(ComputeServiceContext.class);
    ComputeService computeService = mock(ComputeService.class);
    TemplateBuilder templateBuilder = mock(TemplateBuilder.class);
    Template template = mock(Template.class);
    TemplateOptions templateOptions = mock(TemplateOptions.class);
    when(getCompute.apply(clusterSpec)).thenReturn(serviceContext);
    when(serviceContext.getComputeService()).thenReturn(computeService);
    when(computeService.getContext()).thenReturn(serviceContext);
    when(serviceContext.getBackendType()).thenReturn(TypeToken.class.cast(TypeToken.of(Context.class)));
    when(computeService.templateBuilder()).thenReturn(templateBuilder);
    when(templateBuilder.from((TemplateBuilderSpec) any())).thenReturn(templateBuilder);
    when(templateBuilder.options((TemplateOptions) any())).thenReturn(templateBuilder);
    when(templateBuilder.build()).thenReturn(template);
    when(template.getOptions()).thenReturn(templateOptions);
    // here is a scenario when jt+nn fails once, then the retry is successful
    // and from the dn+tt one node fails, then the retry is successful
    Map<Set<String>, Stack<Integer>> reaction = Maps.newHashMap();
    Stack<Integer> jtnnStack = new Stack<Integer>();
    // then ok
    jtnnStack.push(1);
    // initially fail
    jtnnStack.push(0);
    reaction.put(jtnn, jtnnStack);
    Stack<Integer> ddttStack = new Stack<Integer>();
    // 3 from 4, just enough
    ddttStack.push(3);
    reaction.put(dntt, ddttStack);
    nodeStarterFactory = new TestNodeStarterFactory(reaction);
    BootstrapClusterAction bootstrapper = new BootstrapClusterAction(getCompute, handlerMap, nodeStarterFactory);
    bootstrapper.execute(clusterSpec, null);
    if (nodeStarterFactory != null) {
        nodeStarterFactory.validateCompletion();
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) TemplateBuilder(org.jclouds.compute.domain.TemplateBuilder) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) ClusterSpec(org.apache.whirr.ClusterSpec) TemplateOptions(org.jclouds.compute.options.TemplateOptions) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ComputeService(org.jclouds.compute.ComputeService) Template(org.jclouds.compute.domain.Template) Stack(java.util.Stack) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClusterActionHandler(org.apache.whirr.service.ClusterActionHandler) TypeToken(com.google.common.reflect.TypeToken) HashSet(java.util.HashSet) Test(org.junit.Test)

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