Search in sources :

Example 66 with ClusterSpec

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

the class ZooKeeperClusterActionHandler method afterConfigure.

@Override
protected void afterConfigure(ClusterActionEvent event) {
    ClusterSpec clusterSpec = event.getClusterSpec();
    Cluster cluster = event.getCluster();
    LOG.info("Completed configuration of {}", clusterSpec.getClusterName());
    String hosts = Joiner.on(',').join(getHosts(cluster.getInstancesMatching(role(ZOOKEEPER_ROLE))));
    LOG.info("Hosts: {}", hosts);
}
Also used : Cluster(org.apache.whirr.Cluster) ClusterSpec(org.apache.whirr.ClusterSpec)

Example 67 with ClusterSpec

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

the class BootstrapClusterActionTest method testSubroleInvoked.

@Test
@SuppressWarnings("unchecked")
public void testSubroleInvoked() 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 puppet:module::manifest+something-else");
    conf.addProperty("whirr.provider", "ec2");
    config.addConfiguration(conf);
    ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(conf);
    Set<String> nn = new HashSet<String>();
    nn.add("puppet:module::manifest");
    nn.add("something-else");
    TestNodeStarterFactory nodeStarterFactory = null;
    ClusterActionHandlerFactory puppetHandlerFactory = mock(ClusterActionHandlerFactory.class);
    ClusterActionHandler handler = mock(ClusterActionHandler.class);
    when(puppetHandlerFactory.getRolePrefix()).thenReturn("puppet:");
    when(puppetHandlerFactory.create("module::manifest")).thenReturn(handler);
    when(handler.getRole()).thenReturn("something-else");
    LoadingCache<String, ClusterActionHandler> handlerMap = new HandlerMapFactory().create(ImmutableSet.of(puppetHandlerFactory), ImmutableSet.of(handler));
    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);
    Map<Set<String>, Stack<Integer>> reaction = Maps.newHashMap();
    Stack<Integer> nnStack = new Stack<Integer>();
    nnStack.push(new Integer(1));
    reaction.put(nn, nnStack);
    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) TemplateBuilder(org.jclouds.compute.domain.TemplateBuilder) TemplateOptions(org.jclouds.compute.options.TemplateOptions) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) HandlerMapFactory(org.apache.whirr.HandlerMapFactory) Template(org.jclouds.compute.domain.Template) ClusterActionHandlerFactory(org.apache.whirr.service.ClusterActionHandlerFactory) HashSet(java.util.HashSet) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) ClusterSpec(org.apache.whirr.ClusterSpec) ComputeService(org.jclouds.compute.ComputeService) Stack(java.util.Stack) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClusterActionHandler(org.apache.whirr.service.ClusterActionHandler) TypeToken(com.google.common.reflect.TypeToken) Test(org.junit.Test)

Example 68 with ClusterSpec

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

the class BootstrapClusterActionTest method testSubroleNotSupported.

@SuppressWarnings("unchecked")
@Test(expected = IllegalArgumentException.class)
public /**
 * test is the same as previous (SubroleInvoked) except it knows puppet, not puppet:, as the role;
 * the colon in the role def'n is the indication it accepts subroles,
 * so this should throw IllegalArgument when we refer to puppet:module...
 */
void testSubroleNotSupported() 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 puppet:module::manifest+something-else");
    conf.addProperty("whirr.provider", "ec2");
    config.addConfiguration(conf);
    ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(conf);
    Set<String> nn = new HashSet<String>();
    nn.add("puppet:module::manifest");
    nn.add("something-else");
    TestNodeStarterFactory nodeStarterFactory = null;
    ClusterActionHandlerFactory puppetHandlerFactory = mock(ClusterActionHandlerFactory.class);
    ClusterActionHandler handler = mock(ClusterActionHandler.class);
    when(puppetHandlerFactory.getRolePrefix()).thenReturn("puppet");
    when(handler.getRole()).thenReturn("something-else");
    LoadingCache<String, ClusterActionHandler> handlerMap = new HandlerMapFactory().create(ImmutableSet.of(puppetHandlerFactory), ImmutableSet.of(handler));
    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);
    when(getCompute.apply(clusterSpec)).thenReturn(serviceContext);
    when(serviceContext.getComputeService()).thenReturn(computeService);
    when(computeService.templateBuilder()).thenReturn(templateBuilder);
    when(templateBuilder.from((TemplateBuilderSpec) any())).thenReturn(templateBuilder);
    when(templateBuilder.options((TemplateOptions) any())).thenReturn(templateBuilder);
    when(templateBuilder.build()).thenReturn(template);
    Map<Set<String>, Stack<Integer>> reaction = Maps.newHashMap();
    Stack<Integer> nnStack = new Stack<Integer>();
    nnStack.push(1);
    reaction.put(nn, nnStack);
    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) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ComputeService(org.jclouds.compute.ComputeService) HandlerMapFactory(org.apache.whirr.HandlerMapFactory) Template(org.jclouds.compute.domain.Template) Stack(java.util.Stack) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClusterActionHandler(org.apache.whirr.service.ClusterActionHandler) ClusterActionHandlerFactory(org.apache.whirr.service.ClusterActionHandlerFactory) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 69 with ClusterSpec

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

the class DryRunModuleTest method testExecuteOnlyBootstrapForNoop.

@Test
public void testExecuteOnlyBootstrapForNoop() throws Exception {
    CompositeConfiguration config = new CompositeConfiguration();
    config.setProperty("whirr.provider", "stub");
    config.setProperty("whirr.cluster-name", "stub-test");
    config.setProperty("whirr.instance-templates", "1 noop");
    config.setProperty("whirr.state-store", "memory");
    ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(config);
    ClusterController controller = new ClusterController();
    DryRun dryRun = getDryRunInControllerForCluster(controller, clusterSpec);
    dryRun.reset();
    controller.launchCluster(clusterSpec);
    controller.destroyCluster(clusterSpec);
    ListMultimap<NodeMetadata, Statement> perNodeExecutions = dryRun.getExecutions();
    for (Entry<NodeMetadata, Collection<Statement>> entry : perNodeExecutions.asMap().entrySet()) {
        assertSame("An incorrect number of scripts was executed in the node " + entry, entry.getValue().size(), 1);
    }
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) ClusterController(org.apache.whirr.ClusterController) Statement(org.jclouds.scriptbuilder.domain.Statement) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) DryRun(org.apache.whirr.service.DryRunModule.DryRun) Collection(java.util.Collection) ClusterSpec(org.apache.whirr.ClusterSpec) Test(org.junit.Test)

Example 70 with ClusterSpec

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

the class StatementBuilderTest method testDeduplication.

@Test
public void testDeduplication() throws Exception {
    ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys();
    clusterSpec.setClusterName("test-cluster");
    clusterSpec.setProvider("test-provider");
    StatementBuilder builder = new StatementBuilder();
    builder.addStatement(new RunUrlStatement(false, "http://example.org/", "a/b", "c"));
    builder.addStatement(new RunUrlStatement(false, "http://example.org/", "d/e", "f"));
    builder.addStatement(new RunUrlStatement(false, "http://example.org/", "a/b", "c"));
    String script = builder.name("foo").build(clusterSpec).render(OsFamily.UNIX);
    int first = script.indexOf("runurl http://example.org/a/b c");
    assertThat(first, greaterThan(-1));
    int second = script.indexOf("runurl http://example.org/a/b c", first + 1);
    assertThat("No second occurrence", second, is(-1));
    assertThat(script, containsString("runurl http://example.org/d/e f"));
}
Also used : ClusterSpec(org.apache.whirr.ClusterSpec) Matchers.containsString(org.hamcrest.Matchers.containsString) 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