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
|
||||
public (Karthik Kambatla via Sandy Ryza)
|
||||
|
||||
HADOOP-9918. Add addIfService to CompositeService (Karthik Kambatla via
|
||||
Sandy Ryza)
|
||||
|
||||
OPTIMIZATIONS
|
||||
|
||||
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) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
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) {
|
||||
synchronized (serviceList) {
|
||||
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(
|
||||
AppContext context) {
|
||||
this.jobHistoryEventHandler = new JobHistoryEventHandler(context,
|
||||
|
|
|
@ -19,11 +19,14 @@
|
|||
package org.apache.hadoop.yarn.util;
|
||||
|
||||
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 org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.service.AbstractService;
|
||||
import org.apache.hadoop.service.BreakableService;
|
||||
import org.apache.hadoop.service.CompositeService;
|
||||
import org.apache.hadoop.service.Service;
|
||||
|
@ -314,6 +317,26 @@ public class TestCompositeService {
|
|||
composite.init(new Configuration());
|
||||
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{
|
||||
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.NodeManager;
|
||||
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.ApplicationContainerInitEvent;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationEvent;
|
||||
|
@ -193,12 +192,6 @@ public class ContainerManagerImpl extends CompositeService implements
|
|||
super.serviceInit(conf);
|
||||
}
|
||||
|
||||
private void addIfService(Object object) {
|
||||
if (object instanceof Service) {
|
||||
addService((Service) object);
|
||||
}
|
||||
}
|
||||
|
||||
protected LogHandler createLogHandler(Configuration conf, Context context,
|
||||
DeletionService deletionService) {
|
||||
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.service.AbstractService;
|
||||
import org.apache.hadoop.service.CompositeService;
|
||||
import org.apache.hadoop.service.Service;
|
||||
import org.apache.hadoop.util.ExitUtil;
|
||||
import org.apache.hadoop.util.ReflectionUtils;
|
||||
import org.apache.hadoop.util.ShutdownHookManager;
|
||||
|
@ -302,12 +301,6 @@ public class ResourceManager extends CompositeService implements Recoverable {
|
|||
return new AsyncDispatcher();
|
||||
}
|
||||
|
||||
protected void addIfService(Object object) {
|
||||
if (object instanceof Service) {
|
||||
addService((Service) object);
|
||||
}
|
||||
}
|
||||
|
||||
protected AMRMTokenSecretManager createAMRMTokenSecretManager(
|
||||
Configuration conf) {
|
||||
return new AMRMTokenSecretManager(conf);
|
||||
|
|
Loading…
Reference in New Issue