Search in sources :

Example 6 with ServiceManager

use of com.google.common.util.concurrent.ServiceManager in project incubator-gobblin by apache.

the class GobblinYarnAppLauncher method addServices.

private void addServices() throws IOException {
    List<Service> services = Lists.newArrayList();
    if (this.securityManager.isPresent()) {
        LOGGER.info("Adding KeyManagerService since key management is enabled");
        services.add(this.securityManager.get());
    }
    if (!this.config.hasPath(GobblinYarnConfigurationKeys.LOG_COPIER_DISABLE_DRIVER_COPY) || !this.config.getBoolean(GobblinYarnConfigurationKeys.LOG_COPIER_DISABLE_DRIVER_COPY)) {
        services.add(buildLogCopier(this.config, new Path(this.sinkLogRootDir, this.applicationName + Path.SEPARATOR + this.applicationId.get().toString()), GobblinClusterUtils.getAppWorkDirPathFromConfig(this.config, this.fs, this.applicationName, this.applicationId.get().toString())));
    }
    if (config.getBoolean(ConfigurationKeys.JOB_EXECINFO_SERVER_ENABLED_KEY)) {
        LOGGER.info("Starting the job execution info server since it is enabled");
        Properties properties = ConfigUtils.configToProperties(config);
        JobExecutionInfoServer executionInfoServer = new JobExecutionInfoServer(properties);
        services.add(executionInfoServer);
        if (config.getBoolean(ConfigurationKeys.ADMIN_SERVER_ENABLED_KEY)) {
            LOGGER.info("Starting the admin UI server since it is enabled");
            services.add(ServiceBasedAppLauncher.createAdminServer(properties, executionInfoServer.getAdvertisedServerUri()));
        }
    } else if (config.getBoolean(ConfigurationKeys.ADMIN_SERVER_ENABLED_KEY)) {
        LOGGER.warn("NOT starting the admin UI because the job execution info server is NOT enabled");
    }
    if (services.size() > 0) {
        this.serviceManager = Optional.of(new ServiceManager(services));
        this.serviceManager.get().startAsync();
    } else {
        serviceManager = Optional.absent();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ServiceManager(com.google.common.util.concurrent.ServiceManager) GobblinHelixMessagingService(org.apache.gobblin.cluster.GobblinHelixMessagingService) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.google.common.util.concurrent.Service) JobExecutionInfoServer(org.apache.gobblin.rest.JobExecutionInfoServer) Properties(java.util.Properties)

Example 7 with ServiceManager

use of com.google.common.util.concurrent.ServiceManager in project cdap-ingest by caskdata.

the class FileTailerIT method mockMetricsProcessor.

private void mockMetricsProcessor(PipeManager manager) throws IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
    List<Pipe> pipeList = new ArrayList<Pipe>();
    StreamClient client = null;
    StreamWriter writer = null;
    try {
        Method method1 = manager.getClass().getDeclaredMethod("getPipeConfigs");
        method1.setAccessible(true);
        List<PipeConfiguration> pipeConfList = (List<PipeConfiguration>) method1.invoke(manager);
        for (PipeConfiguration pipeConf : pipeConfList) {
            FileTailerQueue queue = new FileTailerQueue(pipeConf.getQueueSize());
            client = pipeConf.getSinkConfiguration().getStreamClient();
            String streamName = pipeConf.getSinkConfiguration().getStreamName();
            Method method2 = manager.getClass().getDeclaredMethod("getStreamWriterForPipe", StreamClient.class, String.class);
            method2.setAccessible(true);
            writer = (StreamWriter) method2.invoke(manager, client, streamName);
            FileTailerStateProcessor stateProcessor = new FileTailerStateProcessorImpl(pipeConf.getDaemonDir(), pipeConf.getStateFile());
            FileTailerMetricsProcessor metricsProcessor = new FileTailerMetricsProcessor(pipeConf.getDaemonDir(), pipeConf.getStatisticsFile(), pipeConf.getStatisticsSleepInterval(), pipeConf.getPipeName(), pipeConf.getSourceConfiguration().getFileName()) {

                @Override
                public void onReadEventMetric(int eventSize) {
                    super.onReadEventMetric(eventSize);
                    read.incrementAndGet();
                }

                @Override
                public void onIngestEventMetric(int latency) {
                    super.onIngestEventMetric(latency);
                    ingest.incrementAndGet();
                }
            };
            pipeList.add(new Pipe(new LogTailer(pipeConf, queue, stateProcessor, metricsProcessor, null), new FileTailerSink(queue, writer, SinkStrategy.LOADBALANCE, stateProcessor, metricsProcessor, null, pipeConf.getSinkConfiguration().getPackSize()), metricsProcessor));
            client = null;
            writer = null;
        }
        Field field = manager.getClass().getDeclaredField("serviceManager");
        field.setAccessible(true);
        Field modifiersField = Field.class.getDeclaredField("modifiers");
        modifiersField.setAccessible(true);
        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(manager, new ServiceManager(pipeList));
    } finally {
        if (client != null) {
            client.close();
        }
        if (writer != null) {
            writer.close();
        }
    }
}
Also used : StreamWriter(co.cask.cdap.client.StreamWriter) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) FileTailerStateProcessor(co.cask.cdap.filetailer.state.FileTailerStateProcessor) FileTailerMetricsProcessor(co.cask.cdap.filetailer.metrics.FileTailerMetricsProcessor) Field(java.lang.reflect.Field) FileTailerStateProcessorImpl(co.cask.cdap.filetailer.state.FileTailerStateProcessorImpl) PipeConfiguration(co.cask.cdap.filetailer.config.PipeConfiguration) FileTailerQueue(co.cask.cdap.filetailer.queue.FileTailerQueue) StreamClient(co.cask.cdap.client.StreamClient) LogTailer(co.cask.cdap.filetailer.tailer.LogTailer) FileTailerSink(co.cask.cdap.filetailer.sink.FileTailerSink) ServiceManager(com.google.common.util.concurrent.ServiceManager) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with ServiceManager

use of com.google.common.util.concurrent.ServiceManager in project cdap-ingest by caskdata.

the class PipeManager method setupPipes.

/**
 * Pipes setup
 *
 * @throws IOException in case a client stream cannot be created
 */
private ServiceManager setupPipes() throws IOException {
    StreamClient client = null;
    StreamWriter writer = null;
    try {
        List<PipeConfiguration> pipeConfList = getPipeConfigs();
        for (PipeConfiguration pipeConf : pipeConfList) {
            FileTailerQueue queue = new FileTailerQueue(pipeConf.getQueueSize());
            client = pipeConf.getSinkConfiguration().getStreamClient();
            String streamName = pipeConf.getSinkConfiguration().getStreamName();
            writer = getStreamWriterForPipe(client, streamName);
            FileTailerStateProcessor stateProcessor = new FileTailerStateProcessorImpl(pipeConf.getDaemonDir(), pipeConf.getStateFile());
            FileTailerMetricsProcessor metricsProcessor = new FileTailerMetricsProcessor(pipeConf.getDaemonDir(), pipeConf.getStatisticsFile(), pipeConf.getStatisticsSleepInterval(), pipeConf.getPipeName(), pipeConf.getSourceConfiguration().getFileName());
            pipeList.add(new Pipe(new LogTailer(pipeConf, queue, stateProcessor, metricsProcessor, null), new FileTailerSink(queue, writer, SinkStrategy.LOADBALANCE, stateProcessor, metricsProcessor, null, pipeConf.getSinkConfiguration().getPackSize()), metricsProcessor));
            client = null;
            writer = null;
        }
        return new ServiceManager(pipeList);
    } catch (ConfigurationLoadingException e) {
        throw new ConfigurationLoadingException("Error during loading configuration from file: " + confFile.getAbsolutePath() + e.getMessage());
    } finally {
        if (client != null) {
            client.close();
        }
        if (writer != null) {
            writer.close();
        }
    }
}
Also used : StreamWriter(co.cask.cdap.client.StreamWriter) ConfigurationLoadingException(co.cask.cdap.filetailer.config.exception.ConfigurationLoadingException) FileTailerStateProcessor(co.cask.cdap.filetailer.state.FileTailerStateProcessor) FileTailerMetricsProcessor(co.cask.cdap.filetailer.metrics.FileTailerMetricsProcessor) FileTailerStateProcessorImpl(co.cask.cdap.filetailer.state.FileTailerStateProcessorImpl) PipeConfiguration(co.cask.cdap.filetailer.config.PipeConfiguration) FileTailerQueue(co.cask.cdap.filetailer.queue.FileTailerQueue) StreamClient(co.cask.cdap.client.StreamClient) LogTailer(co.cask.cdap.filetailer.tailer.LogTailer) FileTailerSink(co.cask.cdap.filetailer.sink.FileTailerSink) ServiceManager(com.google.common.util.concurrent.ServiceManager)

Example 9 with ServiceManager

use of com.google.common.util.concurrent.ServiceManager in project incubator-gobblin by apache.

the class SingleTaskRunner method initServices.

private void initServices() {
    final Properties properties = ConfigUtils.configToProperties(this.clusterConfig);
    this.taskExecutor = new TaskExecutor(properties);
    this.taskStateTracker = new GobblinHelixTaskStateTracker(properties);
    final List<Service> services = Lists.newArrayList(this.taskExecutor, this.taskStateTracker);
    this.serviceManager = new ServiceManager(services);
}
Also used : TaskExecutor(org.apache.gobblin.runtime.TaskExecutor) ServiceManager(com.google.common.util.concurrent.ServiceManager) Service(com.google.common.util.concurrent.Service) Properties(java.util.Properties)

Example 10 with ServiceManager

use of com.google.common.util.concurrent.ServiceManager in project incubator-gobblin by apache.

the class ObservingFSFlowEdgeTemplateCatalogTest method testModifyFlowTemplate.

@Test
public void testModifyFlowTemplate() throws Exception {
    ObservingFSFlowEdgeTemplateCatalog catalog = new ObservingFSFlowEdgeTemplateCatalog(this.templateCatalogCfg, new ReentrantReadWriteLock());
    ServiceManager serviceManager = new ServiceManager(Lists.newArrayList(catalog));
    serviceManager.startAsync().awaitHealthy(5, TimeUnit.SECONDS);
    // Check cached flow template is returned
    FlowTemplate flowTemplate1 = catalog.getFlowTemplate(new URI(FSFlowTemplateCatalogTest.TEST_TEMPLATE_DIR_URI));
    FlowTemplate flowTemplate2 = catalog.getFlowTemplate(new URI(FSFlowTemplateCatalogTest.TEST_TEMPLATE_DIR_URI));
    Assert.assertSame(flowTemplate1, flowTemplate2);
    // Update a file flow catalog and check that the getFlowTemplate returns the new value
    Path flowConfPath = new File(new File(this.templateDir, FSFlowTemplateCatalogTest.TEST_TEMPLATE_NAME), "flow.conf").toPath();
    List<String> lines = java.nio.file.Files.readAllLines(flowConfPath);
    for (int i = 0; i < lines.size(); i++) {
        if (lines.get(i).equals("gobblin.flow.edge.input.dataset.descriptor.0.format=avro")) {
            lines.set(i, "gobblin.flow.edge.input.dataset.descriptor.0.format=any");
            break;
        }
    }
    java.nio.file.Files.write(flowConfPath, lines);
    Function testFunction = new GetFlowTemplateConfigFunction(new URI(FSFlowTemplateCatalogTest.TEST_TEMPLATE_DIR_URI), catalog, "gobblin.flow.edge.input.dataset.descriptor.0.format");
    AssertWithBackoff.create().timeoutMs(10000).assertEquals(testFunction, "any", "flow template updated");
}
Also used : Path(java.nio.file.Path) Function(com.google.common.base.Function) FlowTemplate(org.apache.gobblin.service.modules.template.FlowTemplate) ServiceManager(com.google.common.util.concurrent.ServiceManager) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) URI(java.net.URI) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

ServiceManager (com.google.common.util.concurrent.ServiceManager)11 Service (com.google.common.util.concurrent.Service)5 Properties (java.util.Properties)4 TimeoutException (java.util.concurrent.TimeoutException)3 StreamClient (co.cask.cdap.client.StreamClient)2 StreamWriter (co.cask.cdap.client.StreamWriter)2 PipeConfiguration (co.cask.cdap.filetailer.config.PipeConfiguration)2 FileTailerMetricsProcessor (co.cask.cdap.filetailer.metrics.FileTailerMetricsProcessor)2 FileTailerQueue (co.cask.cdap.filetailer.queue.FileTailerQueue)2 FileTailerSink (co.cask.cdap.filetailer.sink.FileTailerSink)2 FileTailerStateProcessor (co.cask.cdap.filetailer.state.FileTailerStateProcessor)2 FileTailerStateProcessorImpl (co.cask.cdap.filetailer.state.FileTailerStateProcessorImpl)2 LogTailer (co.cask.cdap.filetailer.tailer.LogTailer)2 File (java.io.File)2 IOException (java.io.IOException)2 TaskExecutor (org.apache.gobblin.runtime.TaskExecutor)2 ConfigurationLoadingException (co.cask.cdap.filetailer.config.exception.ConfigurationLoadingException)1 RetryException (com.github.rholder.retry.RetryException)1 Function (com.google.common.base.Function)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1