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);
}
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);
;
}
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;
}
}
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();
}
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();
}
Aggregations