HADOOP-9918. Add addIfService to CompositeService (Karthik Kambatla via Sandy Ryza)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1519129 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6d100eb794
commit
236b8530bd
|
@ -399,6 +399,9 @@ Release 2.1.1-beta - UNRELEASED
|
||||||
HADOOP-9906. Move HAZKUtil to o.a.h.util.ZKUtil and make inner-classes
|
HADOOP-9906. Move HAZKUtil to o.a.h.util.ZKUtil and make inner-classes
|
||||||
public (Karthik Kambatla via Sandy Ryza)
|
public (Karthik Kambatla via Sandy Ryza)
|
||||||
|
|
||||||
|
HADOOP-9918. Add addIfService to CompositeService (Karthik Kambatla via
|
||||||
|
Sandy Ryza)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
|
@ -64,6 +64,11 @@ public class CompositeService extends AbstractService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the passed {@link Service} to the list of services managed by this
|
||||||
|
* {@link CompositeService}
|
||||||
|
* @param service the {@link Service} to be added
|
||||||
|
*/
|
||||||
protected void addService(Service service) {
|
protected void addService(Service service) {
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("Adding service " + service.getName());
|
LOG.debug("Adding service " + service.getName());
|
||||||
|
@ -73,6 +78,21 @@ public class CompositeService extends AbstractService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the passed object is an instance of {@link Service},
|
||||||
|
* add it to the list of services managed by this {@link CompositeService}
|
||||||
|
* @param object
|
||||||
|
* @return true if a service is added, false otherwise.
|
||||||
|
*/
|
||||||
|
protected boolean addIfService(Object object) {
|
||||||
|
if (object instanceof Service) {
|
||||||
|
addService((Service) object);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected synchronized boolean removeService(Service service) {
|
protected synchronized boolean removeService(Service service) {
|
||||||
synchronized (serviceList) {
|
synchronized (serviceList) {
|
||||||
return serviceList.add(service);
|
return serviceList.add(service);
|
||||||
|
|
|
@ -626,12 +626,6 @@ public class MRAppMaster extends CompositeService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addIfService(Object object) {
|
|
||||||
if (object instanceof Service) {
|
|
||||||
addService((Service) object);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected EventHandler<JobHistoryEvent> createJobHistoryHandler(
|
protected EventHandler<JobHistoryEvent> createJobHistoryHandler(
|
||||||
AppContext context) {
|
AppContext context) {
|
||||||
this.jobHistoryEventHandler = new JobHistoryEventHandler(context,
|
this.jobHistoryEventHandler = new JobHistoryEventHandler(context,
|
||||||
|
|
|
@ -19,11 +19,14 @@
|
||||||
package org.apache.hadoop.yarn.util;
|
package org.apache.hadoop.yarn.util;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
import org.apache.hadoop.service.AbstractService;
|
||||||
import org.apache.hadoop.service.BreakableService;
|
import org.apache.hadoop.service.BreakableService;
|
||||||
import org.apache.hadoop.service.CompositeService;
|
import org.apache.hadoop.service.CompositeService;
|
||||||
import org.apache.hadoop.service.Service;
|
import org.apache.hadoop.service.Service;
|
||||||
|
@ -314,6 +317,26 @@ public class TestCompositeService {
|
||||||
composite.init(new Configuration());
|
composite.init(new Configuration());
|
||||||
assertInState(STATE.INITED, child);
|
assertInState(STATE.INITED, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test (timeout = 1000)
|
||||||
|
public void testAddIfService() {
|
||||||
|
CompositeService testService = new CompositeService("TestService") {
|
||||||
|
Service service;
|
||||||
|
@Override
|
||||||
|
public void serviceInit(Configuration conf) {
|
||||||
|
Integer notAService = new Integer(0);
|
||||||
|
assertFalse("Added an integer as a service",
|
||||||
|
addIfService(notAService));
|
||||||
|
|
||||||
|
service = new AbstractService("Service") {};
|
||||||
|
assertTrue("Unable to add a service", addIfService(service));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
testService.init(new Configuration());
|
||||||
|
assertEquals("Incorrect number of services",
|
||||||
|
1, testService.getServices().size());
|
||||||
|
}
|
||||||
|
|
||||||
public static class CompositeServiceAddingAChild extends CompositeService{
|
public static class CompositeServiceAddingAChild extends CompositeService{
|
||||||
Service child;
|
Service child;
|
||||||
|
|
|
@ -85,7 +85,6 @@ import org.apache.hadoop.yarn.server.nodemanager.NMAuditLogger;
|
||||||
import org.apache.hadoop.yarn.server.nodemanager.NMAuditLogger.AuditConstants;
|
import org.apache.hadoop.yarn.server.nodemanager.NMAuditLogger.AuditConstants;
|
||||||
import org.apache.hadoop.yarn.server.nodemanager.NodeManager;
|
import org.apache.hadoop.yarn.server.nodemanager.NodeManager;
|
||||||
import org.apache.hadoop.yarn.server.nodemanager.NodeStatusUpdater;
|
import org.apache.hadoop.yarn.server.nodemanager.NodeStatusUpdater;
|
||||||
import org.apache.hadoop.yarn.server.nodemanager.NodeStatusUpdaterImpl;
|
|
||||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application;
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application;
|
||||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationContainerInitEvent;
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationContainerInitEvent;
|
||||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationEvent;
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationEvent;
|
||||||
|
@ -193,12 +192,6 @@ public class ContainerManagerImpl extends CompositeService implements
|
||||||
super.serviceInit(conf);
|
super.serviceInit(conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addIfService(Object object) {
|
|
||||||
if (object instanceof Service) {
|
|
||||||
addService((Service) object);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected LogHandler createLogHandler(Configuration conf, Context context,
|
protected LogHandler createLogHandler(Configuration conf, Context context,
|
||||||
DeletionService deletionService) {
|
DeletionService deletionService) {
|
||||||
if (conf.getBoolean(YarnConfiguration.LOG_AGGREGATION_ENABLED,
|
if (conf.getBoolean(YarnConfiguration.LOG_AGGREGATION_ENABLED,
|
||||||
|
|
|
@ -33,7 +33,6 @@ import org.apache.hadoop.security.SecurityUtil;
|
||||||
import org.apache.hadoop.security.UserGroupInformation;
|
import org.apache.hadoop.security.UserGroupInformation;
|
||||||
import org.apache.hadoop.service.AbstractService;
|
import org.apache.hadoop.service.AbstractService;
|
||||||
import org.apache.hadoop.service.CompositeService;
|
import org.apache.hadoop.service.CompositeService;
|
||||||
import org.apache.hadoop.service.Service;
|
|
||||||
import org.apache.hadoop.util.ExitUtil;
|
import org.apache.hadoop.util.ExitUtil;
|
||||||
import org.apache.hadoop.util.ReflectionUtils;
|
import org.apache.hadoop.util.ReflectionUtils;
|
||||||
import org.apache.hadoop.util.ShutdownHookManager;
|
import org.apache.hadoop.util.ShutdownHookManager;
|
||||||
|
@ -302,12 +301,6 @@ public class ResourceManager extends CompositeService implements Recoverable {
|
||||||
return new AsyncDispatcher();
|
return new AsyncDispatcher();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addIfService(Object object) {
|
|
||||||
if (object instanceof Service) {
|
|
||||||
addService((Service) object);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected AMRMTokenSecretManager createAMRMTokenSecretManager(
|
protected AMRMTokenSecretManager createAMRMTokenSecretManager(
|
||||||
Configuration conf) {
|
Configuration conf) {
|
||||||
return new AMRMTokenSecretManager(conf);
|
return new AMRMTokenSecretManager(conf);
|
||||||
|
|
Loading…
Reference in New Issue