Search in sources :

Example 6 with RunId

use of com.continuuity.weave.api.RunId in project weave by continuuity.

the class ControllerTest method testControllerListener.

// Test controller listener receive first state change without state transition from service
@Test
public void testControllerListener() throws InterruptedException {
    InMemoryZKServer zkServer = InMemoryZKServer.builder().build();
    zkServer.startAndWait();
    LOG.info("ZKServer: " + zkServer.getConnectionStr());
    try {
        RunId runId = RunIds.generate();
        ZKClientService zkClientService = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
        zkClientService.startAndWait();
        Service service = createService(zkClientService, runId);
        service.startAndWait();
        final CountDownLatch runLatch = new CountDownLatch(1);
        WeaveController controller = getController(zkClientService, runId);
        controller.addListener(new ServiceListenerAdapter() {

            @Override
            public void running() {
                runLatch.countDown();
            }
        }, Threads.SAME_THREAD_EXECUTOR);
        Assert.assertTrue(runLatch.await(2, TimeUnit.SECONDS));
        service.stopAndWait();
        zkClientService.stopAndWait();
    } finally {
        zkServer.stopAndWait();
    }
}
Also used : ZKClientService(com.continuuity.weave.zookeeper.ZKClientService) AbstractIdleService(com.google.common.util.concurrent.AbstractIdleService) ZKClientService(com.continuuity.weave.zookeeper.ZKClientService) Service(com.google.common.util.concurrent.Service) WeaveController(com.continuuity.weave.api.WeaveController) ServiceListenerAdapter(com.continuuity.weave.common.ServiceListenerAdapter) RunId(com.continuuity.weave.api.RunId) CountDownLatch(java.util.concurrent.CountDownLatch) InMemoryZKServer(com.continuuity.weave.internal.zookeeper.InMemoryZKServer) Test(org.junit.Test)

Example 7 with RunId

use of com.continuuity.weave.api.RunId in project weave by continuuity.

the class ZKServiceDecoratorTest method testStateTransition.

@Test
public void testStateTransition() throws InterruptedException, ExecutionException, TimeoutException {
    InMemoryZKServer zkServer = InMemoryZKServer.builder().build();
    zkServer.startAndWait();
    try {
        final String namespace = Joiner.on('/').join("/weave", RunIds.generate(), "runnables", "Runner1");
        final ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
        zkClient.startAndWait();
        zkClient.create(namespace, null, CreateMode.PERSISTENT).get();
        try {
            JsonObject content = new JsonObject();
            content.addProperty("containerId", "container-123");
            content.addProperty("host", "localhost");
            RunId runId = RunIds.generate();
            final Semaphore semaphore = new Semaphore(0);
            ZKServiceDecorator service = new ZKServiceDecorator(ZKClients.namespace(zkClient, namespace), runId, Suppliers.ofInstance(content), new AbstractIdleService() {

                @Override
                protected void startUp() throws Exception {
                    Preconditions.checkArgument(semaphore.tryAcquire(5, TimeUnit.SECONDS), "Fail to start");
                }

                @Override
                protected void shutDown() throws Exception {
                    Preconditions.checkArgument(semaphore.tryAcquire(5, TimeUnit.SECONDS), "Fail to stop");
                }
            });
            final String runnablePath = namespace + "/" + runId.getId();
            final AtomicReference<String> stateMatch = new AtomicReference<String>("STARTING");
            watchDataChange(zkClient, runnablePath + "/state", semaphore, stateMatch);
            Assert.assertEquals(Service.State.RUNNING, service.start().get(5, TimeUnit.SECONDS));
            stateMatch.set("STOPPING");
            Assert.assertEquals(Service.State.TERMINATED, service.stop().get(5, TimeUnit.SECONDS));
        } finally {
            zkClient.stopAndWait();
        }
    } finally {
        zkServer.stopAndWait();
    }
}
Also used : ZKServiceDecorator(com.continuuity.weave.internal.ZKServiceDecorator) ZKClientService(com.continuuity.weave.zookeeper.ZKClientService) JsonObject(com.google.gson.JsonObject) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(java.util.concurrent.Semaphore) AbstractIdleService(com.google.common.util.concurrent.AbstractIdleService) RunId(com.continuuity.weave.api.RunId) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) InMemoryZKServer(com.continuuity.weave.internal.zookeeper.InMemoryZKServer) Test(org.junit.Test)

Example 8 with RunId

use of com.continuuity.weave.api.RunId in project weave by continuuity.

the class RunningContainers method start.

void start(String runnableName, ContainerInfo containerInfo, WeaveContainerLauncher launcher) {
    containerLock.lock();
    try {
        int instanceId = getStartInstanceId(runnableName);
        RunId runId = getRunId(runnableName, instanceId);
        WeaveContainerController controller = launcher.start(runId, instanceId, WeaveContainerMain.class, "$HADOOP_CONF_DIR");
        containers.put(runnableName, containerInfo.getId(), controller);
        WeaveRunResources resources = new DefaultWeaveRunResources(instanceId, containerInfo.getId(), containerInfo.getVirtualCores(), containerInfo.getMemoryMB(), containerInfo.getHost().getHostName());
        resourceReport.addRunResources(runnableName, resources);
        if (startSequence.isEmpty() || !runnableName.equals(startSequence.peekLast())) {
            startSequence.addLast(runnableName);
        }
        containerChange.signalAll();
    } finally {
        containerLock.unlock();
    }
}
Also used : DefaultWeaveRunResources(com.continuuity.weave.internal.DefaultWeaveRunResources) WeaveContainerController(com.continuuity.weave.internal.WeaveContainerController) RunId(com.continuuity.weave.api.RunId) WeaveRunResources(com.continuuity.weave.api.WeaveRunResources) DefaultWeaveRunResources(com.continuuity.weave.internal.DefaultWeaveRunResources)

Example 9 with RunId

use of com.continuuity.weave.api.RunId in project weave by continuuity.

the class ApplicationMasterMain method main.

/**
   * Starts the application master.
   */
public static void main(String[] args) throws Exception {
    String zkConnect = System.getenv(EnvKeys.WEAVE_ZK_CONNECT);
    File weaveSpec = new File(Constants.Files.WEAVE_SPEC);
    RunId runId = RunIds.fromString(System.getenv(EnvKeys.WEAVE_RUN_ID));
    ZKClientService zkClientService = ZKClientServices.delegate(ZKClients.reWatchOnExpire(ZKClients.retryOnFailure(ZKClientService.Builder.of(zkConnect).build(), RetryStrategies.fixDelay(1, TimeUnit.SECONDS))));
    Configuration conf = new YarnConfiguration(new HdfsConfiguration(new Configuration()));
    Service service = new ApplicationMasterService(runId, zkClientService, weaveSpec, new VersionDetectYarnAMClientFactory(conf), createAppLocation(conf));
    new ApplicationMasterMain(String.format("%s/%s/kafka", zkConnect, runId.getId())).doMain(zkClientService, service);
}
Also used : ZKClientService(com.continuuity.weave.zookeeper.ZKClientService) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ZKClientService(com.continuuity.weave.zookeeper.ZKClientService) Service(com.google.common.util.concurrent.Service) RunId(com.continuuity.weave.api.RunId) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) File(java.io.File) VersionDetectYarnAMClientFactory(com.continuuity.weave.internal.yarn.VersionDetectYarnAMClientFactory)

Example 10 with RunId

use of com.continuuity.weave.api.RunId in project weave by continuuity.

the class YarnWeaveRunnerService method prepare.

@Override
public WeavePreparer prepare(WeaveApplication application) {
    Preconditions.checkState(isRunning(), "Service not start. Please call start() first.");
    final WeaveSpecification weaveSpec = application.configure();
    final String appName = weaveSpec.getName();
    return new YarnWeavePreparer(yarnConfig, weaveSpec, yarnAppClient, zkClientService, locationFactory, Suppliers.ofInstance(jvmOptions), new YarnWeaveControllerFactory() {

        @Override
        public YarnWeaveController create(RunId runId, Iterable<LogHandler> logHandlers, Callable<ProcessController<YarnApplicationReport>> startUp) {
            ZKClient zkClient = ZKClients.namespace(zkClientService, "/" + appName);
            YarnWeaveController controller = listenController(new YarnWeaveController(runId, zkClient, logHandlers, startUp));
            synchronized (YarnWeaveRunnerService.this) {
                Preconditions.checkArgument(!controllers.contains(appName, runId), "Application %s with runId %s is already running.", appName, runId);
                controllers.put(appName, runId, controller);
            }
            return controller;
        }
    });
}
Also used : LogHandler(com.continuuity.weave.api.logging.LogHandler) ProcessController(com.continuuity.weave.internal.ProcessController) ZKClient(com.continuuity.weave.zookeeper.ZKClient) WeaveSpecification(com.continuuity.weave.api.WeaveSpecification) RunId(com.continuuity.weave.api.RunId)

Aggregations

RunId (com.continuuity.weave.api.RunId)11 ZKClientService (com.continuuity.weave.zookeeper.ZKClientService)6 Service (com.google.common.util.concurrent.Service)5 InMemoryZKServer (com.continuuity.weave.internal.zookeeper.InMemoryZKServer)4 AbstractIdleService (com.google.common.util.concurrent.AbstractIdleService)4 Test (org.junit.Test)4 WeaveController (com.continuuity.weave.api.WeaveController)3 ServiceListenerAdapter (com.continuuity.weave.common.ServiceListenerAdapter)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 WeaveSpecification (com.continuuity.weave.api.WeaveSpecification)2 WeaveContainerController (com.continuuity.weave.internal.WeaveContainerController)2 JsonObject (com.google.gson.JsonObject)2 File (java.io.File)2 Configuration (org.apache.hadoop.conf.Configuration)2 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)2 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)2 LocalFile (com.continuuity.weave.api.LocalFile)1 SecureStore (com.continuuity.weave.api.SecureStore)1 WeaveRunResources (com.continuuity.weave.api.WeaveRunResources)1 WeaveRunnableSpecification (com.continuuity.weave.api.WeaveRunnableSpecification)1