Search in sources :

Example 11 with ClusterController

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

the class AbstractClusterCommand method createClusterController.

/**
 * Create the specified service
 */
protected ClusterController createClusterController(String serviceName) {
    ClusterController controller = factory.create(serviceName);
    if (controller == null) {
        LOG.warn("Unable to find service {}, using default.", serviceName);
        controller = factory.create(null);
    }
    return controller;
}
Also used : ClusterController(org.apache.whirr.ClusterController)

Example 12 with ClusterController

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

the class Activator method start.

/**
 * Called when this bundle is started so the Framework can perform the
 * bundle-specific activities necessary to start this bundle. This method
 * can be used to register services or to allocate any resources that this
 * bundle needs.
 * <p/>
 * <p/>
 * This method must complete and return to its caller in a timely manner.
 *
 * @param context The execution context of the bundle being started.
 * @throws Exception If this method throws an exception, this
 *                   bundle is marked as stopped and the Framework will remove this
 *                   bundle's listeners, unregister all services registered by this
 *                   bundle, and release all services used by this bundle.
 */
@Override
public void start(BundleContext context) throws Exception {
    // Initialize OSGi based FunctionLoader
    functionLoader = new BundleFunctionLoader(context);
    functionLoader.start();
    defaultClusterController.setHandlerMapFactory(handlerMapFactory);
    byonClusterController.setHandlerMapFactory(handlerMapFactory);
    // Register services
    clusterControllerFactoryRegistration = context.registerService(ClusterControllerFactory.class.getName(), clusterControllerFactory, null);
    handlerMapFactoryRegistration = context.registerService(DynamicHandlerMapFactory.class.getName(), handlerMapFactory, null);
    // Start tracking
    clusterControllerTracker = new ServiceTracker(context, ClusterController.class.getName(), null) {

        @Override
        public Object addingService(ServiceReference reference) {
            Object service = super.addingService(reference);
            clusterControllerFactory.bind((ClusterController) service);
            return service;
        }

        @Override
        public void removedService(ServiceReference reference, Object service) {
            clusterControllerFactory.unbind((ClusterController) service);
            super.removedService(reference, service);
        }
    };
    clusterControllerTracker.open();
    computeServiceTracker = new ServiceTracker(context, ComputeService.class.getName(), null) {

        @Override
        public Object addingService(ServiceReference reference) {
            Object service = context.getService(reference);
            dynamicComputeCache.bind((ComputeService) service);
            return service;
        }

        @Override
        public void removedService(ServiceReference reference, Object service) {
            dynamicComputeCache.unbind((ComputeService) service);
            super.removedService(reference, service);
        }
    };
    computeServiceTracker.open();
    handlerTracker = new ServiceTracker(context, ClusterActionHandler.class.getName(), null) {

        @Override
        public Object addingService(ServiceReference reference) {
            Object service = context.getService(reference);
            handlerMapFactory.bind((ClusterActionHandler) service);
            return service;
        }

        @Override
        public void removedService(ServiceReference reference, Object service) {
            handlerMapFactory.unbind((ClusterActionHandler) service);
            super.removedService(reference, service);
        }
    };
    handlerTracker.open();
    Properties defaultClusterControllerProperties = new Properties();
    defaultClusterControllerProperties.setProperty("name", "default");
    defaultClusterControllerRegistration = context.registerService(ClusterController.class.getName(), defaultClusterController, defaultClusterControllerProperties);
    Properties byonClusterControllerProperties = new Properties();
    byonClusterControllerProperties.setProperty("name", "byon");
    byonClusterControllerRegistration = context.registerService(ClusterController.class.getName(), byonClusterController, byonClusterControllerProperties);
}
Also used : BundleFunctionLoader(org.jclouds.scriptbuilder.functionloader.osgi.BundleFunctionLoader) ClusterController(org.apache.whirr.ClusterController) ByonClusterController(org.apache.whirr.ByonClusterController) ClusterActionHandler(org.apache.whirr.service.ClusterActionHandler) ServiceTracker(org.osgi.util.tracker.ServiceTracker) Properties(java.util.Properties) ComputeService(org.jclouds.compute.ComputeService) ServiceReference(org.osgi.framework.ServiceReference)

Example 13 with ClusterController

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

the class ListClusterCommandTest 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);
    NodeMetadata node1 = new NodeMetadataBuilder().name("name1").ids("id1").location(new LocationBuilder().scope(LocationScope.PROVIDER).id("location-id1").description("location-desc1").build()).imageId("image-id").status(NodeMetadata.Status.RUNNING).publicAddresses(Lists.newArrayList("127.0.0.1")).privateAddresses(Lists.newArrayList("127.0.0.1")).build();
    NodeMetadata node2 = new NodeMetadataBuilder().name("name2").ids("id2").location(new LocationBuilder().scope(LocationScope.PROVIDER).id("location-id2").description("location-desc2").build()).imageId("image-id").status(NodeMetadata.Status.RUNNING).publicAddresses(Lists.newArrayList("127.0.0.2")).privateAddresses(Lists.newArrayList("127.0.0.2")).build();
    when(controller.getNodes((ClusterSpec) any())).thenReturn((Set) Sets.newLinkedHashSet(Lists.newArrayList(node1, node2)));
    when(controller.getInstances((ClusterSpec) any(), (ClusterStateStore) any())).thenCallRealMethod();
    ClusterStateStore memStore = new MemoryClusterStateStore();
    memStore.save(createTestCluster(new String[] { "id1", "id2" }, new String[] { "role1", "role2" }));
    ClusterStateStoreFactory stateStoreFactory = mock(ClusterStateStoreFactory.class);
    when(stateStoreFactory.create((ClusterSpec) any())).thenReturn(memStore);
    ListClusterCommand command = new ListClusterCommand(factory, stateStoreFactory);
    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", "--identity", "myusername", "--quiet", "--private-key-file", keys.get("private").getAbsolutePath()));
    assertThat(rc, is(0));
    assertThat(outBytes.toString(), is("id1\timage-id\t127.0.0.1\t127.0.0.1\tRUNNING\tlocation-id1\trole1\n" + "id2\timage-id\t127.0.0.2\t127.0.0.2\tRUNNING\tlocation-id2\trole2\n"));
    verify(factory).create("test-service");
}
Also used : MemoryClusterStateStore(org.apache.whirr.state.MemoryClusterStateStore) ClusterStateStore(org.apache.whirr.state.ClusterStateStore) Matchers.containsString(org.hamcrest.Matchers.containsString) NodeMetadata(org.jclouds.compute.domain.NodeMetadata) NodeMetadataBuilder(org.jclouds.compute.domain.NodeMetadataBuilder) ClusterController(org.apache.whirr.ClusterController) MemoryClusterStateStore(org.apache.whirr.state.MemoryClusterStateStore) ClusterStateStoreFactory(org.apache.whirr.state.ClusterStateStoreFactory) LocationBuilder(org.jclouds.domain.LocationBuilder) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) File(java.io.File) Test(org.junit.Test)

Example 14 with ClusterController

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

the class RunScriptCommandTest method testRunScriptByRole.

@Test
public void testRunScriptByRole() throws Exception {
    ClusterControllerFactory factory = mock(ClusterControllerFactory.class);
    ClusterController controller = mock(ClusterController.class);
    when(factory.create((String) any())).thenReturn(controller);
    ClusterStateStore memStore = new MemoryClusterStateStore();
    memStore.save(createTestCluster(new String[] { "reg/A", "reg/B" }, new String[] { "A", "B" }));
    ClusterStateStoreFactory stateStoreFactory = mock(ClusterStateStoreFactory.class);
    when(stateStoreFactory.create((ClusterSpec) any())).thenReturn(memStore);
    RunScriptCommand command = new RunScriptCommand(factory, stateStoreFactory);
    Map<String, File> keys = KeyPair.generateTemporaryFiles();
    int rc = command.run(null, out, System.err, Lists.newArrayList("--instance-templates", "1 noop", "--script", "/dev/null", "--roles", "A", "--cluster-name", "test-cluster", "--provider", "provider", "--identity", "myusername", "--credential", "mypassword", "--private-key-file", keys.get("private").getAbsolutePath()));
    assertThat(rc, is(0));
    ArgumentCaptor<Predicate> predicate = ArgumentCaptor.forClass(Predicate.class);
    verify(controller).runScriptOnNodesMatching((ClusterSpec) any(), predicate.capture(), (Statement) any());
    // check predicate equality by using the object string representation
    Predicate<NodeMetadata> expected = Predicates.and(Predicates.<NodeMetadata>alwaysTrue(), withIds("reg/A"));
    assertThat(predicate.getValue().toString(), is(expected.toString()));
}
Also used : MemoryClusterStateStore(org.apache.whirr.state.MemoryClusterStateStore) ClusterStateStore(org.apache.whirr.state.ClusterStateStore) Matchers.containsString(org.hamcrest.Matchers.containsString) Predicate(com.google.common.base.Predicate) NodeMetadata(org.jclouds.compute.domain.NodeMetadata) ClusterController(org.apache.whirr.ClusterController) MemoryClusterStateStore(org.apache.whirr.state.MemoryClusterStateStore) ClusterStateStoreFactory(org.apache.whirr.state.ClusterStateStoreFactory) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) File(java.io.File) Test(org.junit.Test)

Example 15 with ClusterController

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

the class DestroyInstanceCommand method run.

public int run(InputStream in, PrintStream out, PrintStream err, ClusterSpec clusterSpec, String instanceId) throws Exception {
    ClusterController controller = createClusterController(clusterSpec.getServiceName());
    controller.destroyInstance(clusterSpec, instanceId);
    return 0;
}
Also used : ClusterController(org.apache.whirr.ClusterController)

Aggregations

ClusterController (org.apache.whirr.ClusterController)42 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)23 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)22 Test (org.junit.Test)12 ClusterSpec (org.apache.whirr.ClusterSpec)10 ClusterControllerFactory (org.apache.whirr.ClusterControllerFactory)9 HadoopProxy (org.apache.whirr.service.hadoop.HadoopProxy)9 Before (org.junit.Before)8 File (java.io.File)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)7 BeforeClass (org.junit.BeforeClass)7 Cluster (org.apache.whirr.Cluster)6 DryRun (org.apache.whirr.service.DryRunModule.DryRun)5 Collection (java.util.Collection)3 Configuration (org.apache.commons.configuration.Configuration)3 Configuration (org.apache.hadoop.conf.Configuration)3 JobClient (org.apache.hadoop.mapred.JobClient)3 JobConf (org.apache.hadoop.mapred.JobConf)3 ClusterStateStore (org.apache.whirr.state.ClusterStateStore)3