use of com.google.common.util.concurrent.Service 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.Service 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();
}
use of com.google.common.util.concurrent.Service in project helios by spotify.
the class SystemTestBase method baseTeardown.
@After
public void baseTeardown() throws Exception {
for (final HeliosClient client : clients) {
client.close();
}
clients.clear();
for (final Service service : services) {
try {
service.stopAsync();
} catch (Exception e) {
log.error("Uncaught exception", e);
}
}
for (final Service service : services) {
try {
service.awaitTerminated();
} catch (Exception e) {
log.error("Service failed", e);
}
}
services.clear();
// Clean up docker
try (final DockerClient dockerClient = getNewDockerClient()) {
final List<Container> containers = dockerClient.listContainers();
for (final Container container : containers) {
for (final String name : container.names()) {
if (name.contains(testTag)) {
try {
dockerClient.killContainer(container.id());
} catch (DockerException e) {
e.printStackTrace();
}
break;
}
}
}
} catch (Exception e) {
log.error("Docker client exception", e);
}
if (zk != null) {
zk.close();
}
listThreads();
}
Aggregations