from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler
# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/xmlrpc',)
# Create server
server = SimpleXMLRPCServer(("0.0.0.0", 9000),
requestHandler=RequestHandler)
server.register_introspection_functions()
def get_task():
return 42
server.register_function(get_task, 'GetTask')
server.serve_forever()
Then I put some xmlrps JARs to default CLASSPATH on ApplicationMaster machine (in furcher we should find a way to distribute them. May be via HDFS). And changed a ApplicationMasters code:
public void run() throws YarnException, IOException {
amRMClient = AMRMClientAsync.createAMRMClientAsync(1000, new RMCallbackHandler());
amRMClient.init(conf);
amRMClient.start();
RegisterApplicationMasterResponse response;
response = amRMClient.registerApplicationMaster(NetUtils.getHostname(), -1, "");
LOG.info("ApplicationMaster is registered with response: {}", response.toString());
// As a client!
YarnConfiguration conf = new YarnConfiguration();
YarnClient yarnClient = YarnClient.createYarnClient();
yarnClient.init(conf);
yarnClient.start();
List<NodeReport> nodeReports = yarnClient.getNodeReports();
int total_memory = 0;
for (NodeReport report :nodeReports) {
total_memory += report.getUsed().getMemory();
}
if (total_memory > 1000) {
// Get Task
XmlRpcClientConfigImpl metaSchedulerConfig = new XmlRpcClientConfigImpl();
metaSchedulerConfig.setServerURL(new URL("http://192.168.7.1:9000/xmlrpc"));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(metaSchedulerConfig);
try {
Integer result = (Integer) client.execute("GetTask", new Object[]{});
LOG.info("Got task: " + result.toString());
} catch (XmlRpcException e) {
e.printStackTrace();
}
}
yarnClient.stop();
LOG.info("Containers have all completed, so shutting down NMClient and AMRMClient...");
nmClient.stop();
amRMClient.unregisterApplicationMaster(FinalApplicationStatus.SUCCEEDED, "Application complete!", null);
amRMClient.stop();
}
Output:
14/07/27 19:37:14 INFO yarntest.ApplicationMaster: Got task: 42
Yes. This is a fake Python3 metascheduler:
Then I put some xmlrps JARs to default CLASSPATH on ApplicationMaster machine (in furcher we should find a way to distribute them. May be via HDFS). And changed a ApplicationMasters code:
Output: