|
@@ -32,9 +32,11 @@ import org.apache.hadoop.service.AbstractService;
|
|
|
import org.apache.hadoop.service.Service;
|
|
|
import org.apache.hadoop.service.ServiceStateChangeListener;
|
|
|
import org.apache.hadoop.util.ReflectionUtils;
|
|
|
-import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
|
import org.apache.hadoop.yarn.event.EventHandler;
|
|
|
+import org.apache.hadoop.yarn.server.api.ApplicationTerminationContext;
|
|
|
+import org.apache.hadoop.yarn.server.api.AuxiliaryService;
|
|
|
+import org.apache.hadoop.yarn.server.api.ApplicationInitializationContext;
|
|
|
|
|
|
public class AuxServices extends AbstractService
|
|
|
implements ServiceStateChangeListener, EventHandler<AuxServicesEvent> {
|
|
@@ -42,13 +44,13 @@ public class AuxServices extends AbstractService
|
|
|
private static final Log LOG = LogFactory.getLog(AuxServices.class);
|
|
|
|
|
|
protected final Map<String,AuxiliaryService> serviceMap;
|
|
|
- protected final Map<String,ByteBuffer> serviceMeta;
|
|
|
+ protected final Map<String,ByteBuffer> serviceMetaData;
|
|
|
|
|
|
public AuxServices() {
|
|
|
super(AuxServices.class.getName());
|
|
|
serviceMap =
|
|
|
Collections.synchronizedMap(new HashMap<String,AuxiliaryService>());
|
|
|
- serviceMeta =
|
|
|
+ serviceMetaData =
|
|
|
Collections.synchronizedMap(new HashMap<String,ByteBuffer>());
|
|
|
// Obtain services from configuration in init()
|
|
|
}
|
|
@@ -69,11 +71,11 @@ public class AuxServices extends AbstractService
|
|
|
* If a service has not been started no metadata will be available. The key
|
|
|
* is the name of the service as defined in the configuration.
|
|
|
*/
|
|
|
- public Map<String, ByteBuffer> getMeta() {
|
|
|
+ public Map<String, ByteBuffer> getMetaData() {
|
|
|
Map<String, ByteBuffer> metaClone = new HashMap<String, ByteBuffer>(
|
|
|
- serviceMeta.size());
|
|
|
- synchronized (serviceMeta) {
|
|
|
- for (Entry<String, ByteBuffer> entry : serviceMeta.entrySet()) {
|
|
|
+ serviceMetaData.size());
|
|
|
+ synchronized (serviceMetaData) {
|
|
|
+ for (Entry<String, ByteBuffer> entry : serviceMetaData.entrySet()) {
|
|
|
metaClone.put(entry.getKey(), entry.getValue().duplicate());
|
|
|
}
|
|
|
}
|
|
@@ -121,9 +123,9 @@ public class AuxServices extends AbstractService
|
|
|
String name = entry.getKey();
|
|
|
service.start();
|
|
|
service.registerServiceListener(this);
|
|
|
- ByteBuffer meta = service.getMeta();
|
|
|
+ ByteBuffer meta = service.getMetaData();
|
|
|
if(meta != null) {
|
|
|
- serviceMeta.put(name, meta);
|
|
|
+ serviceMetaData.put(name, meta);
|
|
|
}
|
|
|
}
|
|
|
super.serviceStart();
|
|
@@ -140,7 +142,7 @@ public class AuxServices extends AbstractService
|
|
|
}
|
|
|
}
|
|
|
serviceMap.clear();
|
|
|
- serviceMeta.clear();
|
|
|
+ serviceMetaData.clear();
|
|
|
}
|
|
|
} finally {
|
|
|
super.serviceStop();
|
|
@@ -167,12 +169,13 @@ public class AuxServices extends AbstractService
|
|
|
// TODO kill all containers waiting on Application
|
|
|
return;
|
|
|
}
|
|
|
- service.initApp(event.getUser(), event.getApplicationID(),
|
|
|
- event.getServiceData());
|
|
|
+ service.initializeApplication(new ApplicationInitializationContext(event
|
|
|
+ .getUser(), event.getApplicationID(), event.getServiceData()));
|
|
|
break;
|
|
|
case APPLICATION_STOP:
|
|
|
for (AuxiliaryService serv : serviceMap.values()) {
|
|
|
- serv.stopApp(event.getApplicationID());
|
|
|
+ serv.stopApplication(new ApplicationTerminationContext(event
|
|
|
+ .getApplicationID()));
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
@@ -180,18 +183,4 @@ public class AuxServices extends AbstractService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public interface AuxiliaryService extends Service {
|
|
|
- void initApp(String user, ApplicationId appId, ByteBuffer data);
|
|
|
- void stopApp(ApplicationId appId);
|
|
|
- /**
|
|
|
- * Retreive metadata for this service. This is likely going to be contact
|
|
|
- * information so that applications can access the service remotely. Ideally
|
|
|
- * each service should provide a method to parse out the information to a usable
|
|
|
- * class. This will only be called after the services start method has finished.
|
|
|
- * the result may be cached.
|
|
|
- * @return metadata for this service that should be made avaiable to applications.
|
|
|
- */
|
|
|
- ByteBuffer getMeta();
|
|
|
- }
|
|
|
-
|
|
|
}
|