Search in sources :

Example 1 with ServiceManager

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

the class SingleTaskRunner method getServices.

private void getServices() {
    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 2 with ServiceManager

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

the class JobConfigFileMonitorTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    this.jobConfigDir = Files.createTempDirectory(String.format("gobblin-test_%s_job-conf", this.getClass().getSimpleName())).toString();
    FileUtils.forceDeleteOnExit(new File(this.jobConfigDir));
    FileUtils.copyDirectory(new File(JOB_CONFIG_FILE_DIR), new File(jobConfigDir));
    Properties properties = new Properties();
    try (Reader schedulerPropsReader = new FileReader("gobblin-test/resource/gobblin.test.properties")) {
        properties.load(schedulerPropsReader);
    }
    properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY, jobConfigDir);
    properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, jobConfigDir);
    properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_MONITOR_POLLING_INTERVAL_KEY, "1000");
    properties.setProperty(ConfigurationKeys.METRICS_ENABLED_KEY, "false");
    SchedulerService quartzService = new SchedulerService(new Properties());
    this.jobScheduler = new JobScheduler(properties, quartzService);
    this.serviceManager = new ServiceManager(Lists.newArrayList(quartzService, this.jobScheduler));
    this.serviceManager.startAsync().awaitHealthy(10, TimeUnit.SECONDS);
    ;
}
Also used : ServiceManager(com.google.common.util.concurrent.ServiceManager) Reader(java.io.Reader) FileReader(java.io.FileReader) FileReader(java.io.FileReader) Properties(java.util.Properties) File(java.io.File) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with ServiceManager

use of com.google.common.util.concurrent.ServiceManager in project graylog2-server by Graylog2.

the class ServerBootstrap method startCommand.

@Override
protected void startCommand() {
    final AuditEventSender auditEventSender = injector.getInstance(AuditEventSender.class);
    final NodeId nodeId = injector.getInstance(NodeId.class);
    final String systemInformation = Tools.getSystemInformation();
    final Map<String, Object> auditEventContext = ImmutableMap.of("version", version.toString(), "java", systemInformation, "node_id", nodeId.toString());
    auditEventSender.success(AuditActor.system(nodeId), NODE_STARTUP_INITIATE, auditEventContext);
    final OS os = OS.getOs();
    LOG.info("Graylog {} {} starting up", commandName, version);
    LOG.info("JRE: {}", systemInformation);
    LOG.info("Deployment: {}", configuration.getInstallationSource());
    LOG.info("OS: {}", os.getPlatformName());
    LOG.info("Arch: {}", os.getArch());
    try {
        if (configuration.isLeader() && configuration.runMigrations()) {
            runMigrations();
        }
    } catch (Exception e) {
        LOG.warn("Exception while running migrations", e);
        System.exit(1);
    }
    final ServerStatus serverStatus = injector.getInstance(ServerStatus.class);
    serverStatus.initialize();
    startNodeRegistration(injector);
    final ActivityWriter activityWriter;
    final ServiceManager serviceManager;
    final Service leaderElectionService;
    try {
        activityWriter = injector.getInstance(ActivityWriter.class);
        serviceManager = injector.getInstance(ServiceManager.class);
        leaderElectionService = injector.getInstance(Key.get(Service.class, Names.named("LeaderElectionService")));
    } catch (ProvisionException e) {
        LOG.error("Guice error", e);
        annotateProvisionException(e);
        auditEventSender.failure(AuditActor.system(nodeId), NODE_STARTUP_INITIATE, auditEventContext);
        System.exit(-1);
        return;
    } catch (Exception e) {
        LOG.error("Unexpected exception", e);
        auditEventSender.failure(AuditActor.system(nodeId), NODE_STARTUP_INITIATE, auditEventContext);
        System.exit(-1);
        return;
    }
    Runtime.getRuntime().addShutdownHook(new Thread(injector.getInstance(shutdownHook())));
    // propagate default size to input plugins
    MessageInput.setDefaultRecvBufferSize(configuration.getUdpRecvBufferSizes());
    // Start services.
    final ServiceManagerListener serviceManagerListener = injector.getInstance(ServiceManagerListener.class);
    serviceManager.addListener(serviceManagerListener, MoreExecutors.directExecutor());
    try {
        leaderElectionService.startAsync().awaitRunning();
        serviceManager.startAsync().awaitHealthy();
    } catch (Exception e) {
        try {
            serviceManager.stopAsync().awaitStopped(configuration.getShutdownTimeout(), TimeUnit.MILLISECONDS);
        } catch (TimeoutException timeoutException) {
            LOG.error("Unable to shutdown properly on time. {}", serviceManager.servicesByState());
        }
        LOG.error("Graylog startup failed. Exiting. Exception was:", e);
        auditEventSender.failure(AuditActor.system(nodeId), NODE_STARTUP_INITIATE, auditEventContext);
        System.exit(-1);
    }
    LOG.info("Services started, startup times in ms: {}", serviceManager.startupTimes());
    activityWriter.write(new Activity("Started up.", Main.class));
    LOG.info("Graylog " + commandName + " up and running.");
    auditEventSender.success(AuditActor.system(nodeId), NODE_STARTUP_COMPLETE, auditEventContext);
    // Block forever.
    try {
        Thread.currentThread().join();
    } catch (InterruptedException e) {
        return;
    }
}
Also used : OS(org.jsoftbiz.utils.OS) PreflightCheckService(org.graylog2.bootstrap.preflight.PreflightCheckService) Service(com.google.common.util.concurrent.Service) Activity(org.graylog2.shared.system.activities.Activity) TimeoutException(java.util.concurrent.TimeoutException) ProvisionException(com.google.inject.ProvisionException) ProvisionException(com.google.inject.ProvisionException) AuditEventSender(org.graylog2.audit.AuditEventSender) ServiceManager(com.google.common.util.concurrent.ServiceManager) ServerStatus(org.graylog2.plugin.ServerStatus) NodeId(org.graylog2.plugin.system.NodeId) ServiceManagerListener(org.graylog2.shared.initializers.ServiceManagerListener) ActivityWriter(org.graylog2.shared.system.activities.ActivityWriter) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with ServiceManager

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

the class ServiceBasedAppLauncher method start.

/**
 * Starts the {@link ApplicationLauncher} by starting all associated services. This method also adds a shutdown hook
 * that invokes {@link #stop()} and the {@link #close()} methods. So {@link #stop()} and {@link #close()} need not be
 * called explicitly; they can be triggered during the JVM shutdown.
 */
@Override
public synchronized void start() {
    if (this.hasStarted) {
        LOG.warn("ApplicationLauncher has already started");
        return;
    }
    this.hasStarted = true;
    this.serviceManager = new ServiceManager(this.services);
    // A listener that shutdowns the application if any service fails.
    this.serviceManager.addListener(new ServiceManager.Listener() {

        @Override
        public void failure(Service service) {
            super.failure(service);
            LOG.error(String.format("Service %s has failed.", service.getClass().getSimpleName()), service.failureCause());
            try {
                service.stopAsync();
                ServiceBasedAppLauncher.this.stop();
            } catch (ApplicationException ae) {
                LOG.error("Could not shutdown services gracefully. This may cause the application to hang.");
            }
        }
    });
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            try {
                ServiceBasedAppLauncher.this.stop();
            } catch (ApplicationException e) {
                LOG.error("Failed to shutdown application", e);
            } finally {
                try {
                    ServiceBasedAppLauncher.this.close();
                } catch (IOException e) {
                    LOG.error("Failed to close application", e);
                }
            }
        }
    });
    LOG.info("Starting the Gobblin application and all its associated Services");
    // Start the application
    this.serviceManager.startAsync().awaitHealthy();
}
Also used : ServiceManager(com.google.common.util.concurrent.ServiceManager) JMXReportingService(org.apache.gobblin.runtime.services.JMXReportingService) MetricsReportingService(org.apache.gobblin.runtime.services.MetricsReportingService) Service(com.google.common.util.concurrent.Service) IOException(java.io.IOException)

Example 5 with ServiceManager

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

the class GobblinYarnAppLauncher method launch.

/**
 * Launch a new Gobblin instance on Yarn.
 *
 * @throws IOException if there's something wrong launching the application
 * @throws YarnException if there's something wrong launching the application
 */
public void launch() throws IOException, YarnException {
    this.eventBus.register(this);
    String clusterName = this.config.getString(GobblinClusterConfigurationKeys.HELIX_CLUSTER_NAME_KEY);
    HelixUtils.createGobblinHelixCluster(this.config.getString(GobblinClusterConfigurationKeys.ZK_CONNECTION_STRING_KEY), clusterName);
    LOGGER.info("Created Helix cluster " + clusterName);
    connectHelixManager();
    startYarnClient();
    this.applicationId = getApplicationId();
    this.applicationStatusMonitor.scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            try {
                eventBus.post(new ApplicationReportArrivalEvent(yarnClient.getApplicationReport(applicationId.get())));
            } catch (YarnException | IOException e) {
                LOGGER.error("Failed to get application report for Gobblin Yarn application " + applicationId.get(), e);
                eventBus.post(new GetApplicationReportFailureEvent(e));
            }
        }
    }, 0, this.appReportIntervalMinutes, TimeUnit.MINUTES);
    List<Service> services = Lists.newArrayList();
    if (this.config.hasPath(GobblinYarnConfigurationKeys.KEYTAB_FILE_PATH)) {
        LOGGER.info("Adding YarnAppSecurityManager since login is keytab based");
        services.add(buildYarnAppSecurityManager());
    }
    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.getAppWorkDirPath(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");
    }
    this.serviceManager = Optional.of(new ServiceManager(services));
    // Start all the services running in the ApplicationMaster
    this.serviceManager.get().startAsync();
}
Also used : Path(org.apache.hadoop.fs.Path) ApplicationReportArrivalEvent(org.apache.gobblin.yarn.event.ApplicationReportArrivalEvent) ServiceManager(com.google.common.util.concurrent.ServiceManager) 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) GetApplicationReportFailureEvent(org.apache.gobblin.yarn.event.GetApplicationReportFailureEvent)

Aggregations

ServiceManager (com.google.common.util.concurrent.ServiceManager)7 Service (com.google.common.util.concurrent.Service)4 Properties (java.util.Properties)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 ConfigurationLoadingException (co.cask.cdap.filetailer.config.exception.ConfigurationLoadingException)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 ProvisionException (com.google.inject.ProvisionException)1 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 Field (java.lang.reflect.Field)1