Search in sources :

Example 11 with Service

use of com.google.common.util.concurrent.Service in project cdap by caskdata.

the class AbstractProgramRuntimeServiceTest method testUpdateDeadLock.

@Test(timeout = 5000L)
public void testUpdateDeadLock() {
    // This test is for testing (CDAP-3716)
    // Create a service to simulate an existing running app.
    Service service = new TestService();
    ProgramId programId = NamespaceId.DEFAULT.app("dummyApp").program(ProgramType.WORKER, "dummy");
    RunId runId = RunIds.generate();
    ProgramRuntimeService.RuntimeInfo extraInfo = createRuntimeInfo(service, programId, runId);
    service.startAndWait();
    ProgramRunnerFactory runnerFactory = createProgramRunnerFactory();
    TestProgramRuntimeService runtimeService = new TestProgramRuntimeService(CConfiguration.create(), runnerFactory, null, extraInfo);
    runtimeService.startAndWait();
    // The lookup will get deadlock for CDAP-3716
    Assert.assertNotNull(runtimeService.lookup(programId, runId));
    service.stopAndWait();
    runtimeService.stopAndWait();
}
Also used : AbstractExecutionThreadService(com.google.common.util.concurrent.AbstractExecutionThreadService) AbstractIdleService(com.google.common.util.concurrent.AbstractIdleService) Service(com.google.common.util.concurrent.Service) ProgramId(co.cask.cdap.proto.id.ProgramId) RunId(org.apache.twill.api.RunId) Test(org.junit.Test)

Example 12 with Service

use of com.google.common.util.concurrent.Service in project cdap by caskdata.

the class AppFabricTestBase method initializeAndStartServices.

protected static void initializeAndStartServices(CConfiguration cConf, @Nullable SConfiguration sConf) throws Exception {
    injector = Guice.createInjector(Modules.override(new AppFabricTestModule(cConf, sConf)).with(new AbstractModule() {

        @Override
        protected void configure() {
            // needed because we set Kerberos to true in DefaultNamespaceAdminTest
            bind(UGIProvider.class).to(CurrentUGIProvider.class);
        }
    }));
    messagingService = injector.getInstance(MessagingService.class);
    if (messagingService instanceof Service) {
        ((Service) messagingService).startAndWait();
    }
    txManager = injector.getInstance(TransactionManager.class);
    txManager.startAndWait();
    dsOpService = injector.getInstance(DatasetOpExecutor.class);
    dsOpService.startAndWait();
    remoteSysOpService = injector.getInstance(RemoteSystemOperationsService.class);
    remoteSysOpService.startAndWait();
    datasetService = injector.getInstance(DatasetService.class);
    datasetService.startAndWait();
    appFabricServer = injector.getInstance(AppFabricServer.class);
    appFabricServer.startAndWait();
    DiscoveryServiceClient discoveryClient = injector.getInstance(DiscoveryServiceClient.class);
    ServiceDiscovered appFabricHttpDiscovered = discoveryClient.discover(Constants.Service.APP_FABRIC_HTTP);
    EndpointStrategy endpointStrategy = new RandomEndpointStrategy(appFabricHttpDiscovered);
    port = endpointStrategy.pick(1, TimeUnit.SECONDS).getSocketAddress().getPort();
    txClient = injector.getInstance(TransactionSystemClient.class);
    metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
    metricsCollectionService.startAndWait();
    metricsService = injector.getInstance(MetricsQueryService.class);
    metricsService.startAndWait();
    streamService = injector.getInstance(StreamService.class);
    streamService.startAndWait();
    serviceStore = injector.getInstance(ServiceStore.class);
    serviceStore.startAndWait();
    metadataService = injector.getInstance(MetadataService.class);
    metadataService.startAndWait();
    locationFactory = getInjector().getInstance(LocationFactory.class);
    streamClient = new StreamClient(getClientConfig(discoveryClient, Constants.Service.STREAMS));
    datasetClient = new DatasetClient(getClientConfig(discoveryClient, Constants.Service.DATASET_MANAGER));
    createNamespaces();
}
Also used : StreamService(co.cask.cdap.data.stream.service.StreamService) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) MetricsQueryService(co.cask.cdap.metrics.query.MetricsQueryService) MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) AppFabricServer(co.cask.cdap.internal.app.services.AppFabricServer) MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) MetadataService(co.cask.cdap.metadata.MetadataService) Service(com.google.common.util.concurrent.Service) MessagingService(co.cask.cdap.messaging.MessagingService) MetricsQueryService(co.cask.cdap.metrics.query.MetricsQueryService) StreamService(co.cask.cdap.data.stream.service.StreamService) RemoteSystemOperationsService(co.cask.cdap.gateway.handlers.meta.RemoteSystemOperationsService) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) DatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor) RemoteSystemOperationsService(co.cask.cdap.gateway.handlers.meta.RemoteSystemOperationsService) ServiceDiscovered(org.apache.twill.discovery.ServiceDiscovered) MetadataService(co.cask.cdap.metadata.MetadataService) AbstractModule(com.google.inject.AbstractModule) MessagingService(co.cask.cdap.messaging.MessagingService) LocationFactory(org.apache.twill.filesystem.LocationFactory) TransactionSystemClient(org.apache.tephra.TransactionSystemClient) DatasetClient(co.cask.cdap.client.DatasetClient) ServiceStore(co.cask.cdap.app.store.ServiceStore) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy) EndpointStrategy(co.cask.cdap.common.discovery.EndpointStrategy) StreamClient(co.cask.cdap.client.StreamClient) TransactionManager(org.apache.tephra.TransactionManager) CurrentUGIProvider(co.cask.cdap.security.impersonation.CurrentUGIProvider) AppFabricTestModule(co.cask.cdap.internal.guice.AppFabricTestModule) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy)

Example 13 with Service

use of com.google.common.util.concurrent.Service in project cdap by caskdata.

the class CommandPortServiceTest method testCommandPortServer.

@Test
public void testCommandPortServer() throws Exception {
    IncrementCommandHandler handler = new IncrementCommandHandler();
    final CommandPortService server = CommandPortService.builder("test").addCommandHandler("increment", "Increments a counter", handler).build();
    final CountDownLatch stopLatch = new CountDownLatch(1);
    Futures.addCallback(server.start(), new FutureCallback<Service.State>() {

        @Override
        public void onSuccess(Service.State result) {
            stopLatch.countDown();
        }

        @Override
        public void onFailure(Throwable t) {
            stopLatch.countDown();
        }
    });
    // wait a bit for service to start
    TimeUnit.SECONDS.sleep(1);
    try {
        for (int i = 0; i < 10; i++) {
            Socket clientSocket = new Socket("localhost", server.getPort());
            try {
                BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream(), "UTF-8"));
                BufferedReader reader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream(), "UTF-8"));
                writer.write("increment");
                writer.newLine();
                writer.flush();
                String response = reader.readLine();
                Assert.assertEquals(i + 1, Integer.parseInt(response));
            } finally {
                clientSocket.close();
            }
        }
    } finally {
        server.stopAndWait();
    }
    Assert.assertEquals(10, handler.getCounter());
    Assert.assertTrue(stopLatch.await(3, TimeUnit.SECONDS));
    Assert.assertEquals(Service.State.TERMINATED, server.state());
}
Also used : InputStreamReader(java.io.InputStreamReader) Service(com.google.common.util.concurrent.Service) CountDownLatch(java.util.concurrent.CountDownLatch) BufferedWriter(java.io.BufferedWriter) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) Socket(java.net.Socket) Test(org.junit.Test)

Example 14 with Service

use of com.google.common.util.concurrent.Service in project cdap by caskdata.

the class SystemMetadataAuditPublishTest method setup.

@BeforeClass
public static void setup() {
    cConf = CConfiguration.create();
    cConf.setBoolean(Constants.Audit.ENABLED, true);
    Injector injector = AppFabricTestHelper.getInjector(cConf, new AbstractModule() {

        @Override
        protected void configure() {
            bind(MetadataStore.class).to(DefaultMetadataStore.class);
            install(new AuditModule().getInMemoryModules());
        }
    });
    auditPublisher = injector.getInstance(InMemoryAuditPublisher.class);
    namespaceAdmin = injector.getInstance(NamespaceAdmin.class);
    scheduler = injector.getInstance(Scheduler.class);
    if (scheduler instanceof Service) {
        ((Service) scheduler).startAndWait();
    }
}
Also used : InMemoryAuditPublisher(co.cask.cdap.data2.audit.InMemoryAuditPublisher) Injector(com.google.inject.Injector) Scheduler(co.cask.cdap.scheduler.Scheduler) NamespaceAdmin(co.cask.cdap.common.namespace.NamespaceAdmin) Service(com.google.common.util.concurrent.Service) AuditModule(co.cask.cdap.data2.audit.AuditModule) DefaultMetadataStore(co.cask.cdap.data2.metadata.store.DefaultMetadataStore) AbstractModule(com.google.inject.AbstractModule) BeforeClass(org.junit.BeforeClass)

Example 15 with Service

use of com.google.common.util.concurrent.Service in project cdap by caskdata.

the class DefaultPreviewManager method start.

@Override
public ApplicationId start(NamespaceId namespace, AppRequest<?> appRequest) throws Exception {
    ApplicationId previewApp = namespace.app(PREFIX + System.currentTimeMillis());
    Injector injector = createPreviewInjector(previewApp);
    PreviewRunner runner = injector.getInstance(PreviewRunner.class);
    if (runner instanceof Service) {
        ((Service) runner).startAndWait();
    }
    try {
        runner.startPreview(new PreviewRequest<>(getProgramIdFromRequest(previewApp, appRequest), appRequest));
    } catch (Exception e) {
        if (runner instanceof Service) {
            stopQuietly((Service) runner);
        }
        removePreviewDir(previewApp);
        throw e;
    }
    appInjectors.put(previewApp, injector);
    return previewApp;
}
Also used : Injector(com.google.inject.Injector) PreviewRunner(co.cask.cdap.app.preview.PreviewRunner) DiscoveryService(org.apache.twill.discovery.DiscoveryService) Service(com.google.common.util.concurrent.Service) ApplicationId(co.cask.cdap.proto.id.ApplicationId) BadRequestException(co.cask.cdap.common.BadRequestException) IOException(java.io.IOException) NotFoundException(co.cask.cdap.common.NotFoundException)

Aggregations

Service (com.google.common.util.concurrent.Service)43 MessagingService (co.cask.cdap.messaging.MessagingService)15 AbstractIdleService (com.google.common.util.concurrent.AbstractIdleService)15 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)14 Test (org.junit.Test)14 IOException (java.io.IOException)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ProgramId (co.cask.cdap.proto.id.ProgramId)7 ProgramContextAware (co.cask.cdap.data.ProgramContextAware)6 DatasetService (co.cask.cdap.data2.datafabric.dataset.service.DatasetService)6 BasicProgramContext (co.cask.cdap.internal.app.runtime.BasicProgramContext)6 ProgramType (co.cask.cdap.proto.ProgramType)6 RunId (org.apache.twill.api.RunId)6 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)5 CConfiguration (co.cask.cdap.common.conf.CConfiguration)5 Injector (com.google.inject.Injector)5 PluginInstantiator (co.cask.cdap.internal.app.runtime.plugin.PluginInstantiator)4 RunId (com.continuuity.weave.api.RunId)4 ZKClientService (com.continuuity.weave.zookeeper.ZKClientService)4 Configuration (org.apache.hadoop.conf.Configuration)4