HttpHost httpAddress = new HttpHost(offer.getHostname(), portArray[0]);
HttpHost reportAddress = new HttpHost(offer.getHostname(), portArray[1]);
HttpHost jobTrackerAddress = new HttpHost(jobTracker.getHostname(),
jobTracker.getTrackerPort());
TaskID taskId = TaskID.newBuilder()
.setValue("Task_Tracker_" + launchedTrackers++).build();
LOG.info("Launching task " + taskId.getValue() + " on "
+ httpAddress.toString());
// Add this tracker to Mesos tasks.
mesosTrackers.put(httpAddress, new MesosTracker(httpAddress, taskId,
mapSlots, reduceSlots));
// Create the environment depending on whether the executor is going to be
// run locally.
// TODO(vinod): Do not pass the mapred config options as environment
// variables.
Protos.Environment.Builder envBuilder = Protos.Environment
.newBuilder()
.addVariables(
Protos.Environment.Variable
.newBuilder()
.setName("mapred.job.tracker")
.setValue(jobTrackerAddress.getHostName() + ':'
+ jobTrackerAddress.getPort()))
.addVariables(
Protos.Environment.Variable
.newBuilder()
.setName("mapred.task.tracker.http.address")
.setValue(
httpAddress.getHostName() + ':' + httpAddress.getPort()))
.addVariables(
Protos.Environment.Variable
.newBuilder()
.setName("mapred.task.tracker.report.address")
.setValue(reportAddress.getHostName() + ':'
+ reportAddress.getPort()))
.addVariables(
Protos.Environment.Variable.newBuilder()
.setName("mapred.map.child.java.opts")
.setValue("-Xmx" + slotJVMHeap + "m"))
.addVariables(
Protos.Environment.Variable.newBuilder()
.setName("mapred.reduce.child.java.opts")
.setValue("-Xmx" + slotJVMHeap + "m"))
.addVariables(
Protos.Environment.Variable.newBuilder()
.setName("HADOOP_HEAPSIZE")
.setValue("" + TASKTRACKER_JVM_HEAP));
// Set java specific environment, appropriately.
Map<String, String> env = System.getenv();
if (env.containsKey("JAVA_HOME")) {
envBuilder.addVariables(Protos.Environment.Variable.newBuilder()
.setName("JAVA_HOME")
.setValue(env.get("JAVA_HOME")));
}
if (env.containsKey("JAVA_LIBRARY_PATH")) {
envBuilder.addVariables(Protos.Environment.Variable.newBuilder()
.setName("JAVA_LIBRARY_PATH")
.setValue(env.get("JAVA_LIBRARY_PATH")));
}
// Command info differs when performing a local run.
CommandInfo commandInfo = null;
String master = conf.get("mapred.mesos.master", "local");
if (master.equals("local")) {
try {
commandInfo = CommandInfo.newBuilder()
.setEnvironment(envBuilder)
.setValue(new File("bin/mesos-executor").getCanonicalPath())
.build();
} catch (IOException e) {
LOG.fatal("Failed to find Mesos executor ", e);
System.exit(1);
}
} else {
String uri = conf.get("mapred.mesos.executor");
commandInfo = CommandInfo.newBuilder()
.setEnvironment(envBuilder)
.setValue("cd hadoop && ./bin/mesos-executor")
.addUris(CommandInfo.URI.newBuilder().setValue(uri)).build();
}
TaskInfo info = TaskInfo
.newBuilder()
.setName(taskId.getValue())
.setTaskId(taskId)
.setSlaveId(offer.getSlaveId())
.addResources(
Resource
.newBuilder()
.setName("cpus")
.setType(Value.Type.SCALAR)
.setScalar(Value.Scalar.newBuilder().setValue(
(mapSlots + reduceSlots) * slotCpus)))
.addResources(
Resource
.newBuilder()
.setName("mem")
.setType(Value.Type.SCALAR)
.setScalar(Value.Scalar.newBuilder().setValue(
(mapSlots + reduceSlots) * slotMem)))
.addResources(
Resource
.newBuilder()
.setName("disk")
.setType(Value.Type.SCALAR)
.setScalar(Value.Scalar.newBuilder().setValue(
(mapSlots + reduceSlots) * slotDisk)))
.addResources(
Resource
.newBuilder()
.setName("ports")
.setType(Value.Type.RANGES)
.setRanges(
Value.Ranges
.newBuilder()
.addRange(Value.Range.newBuilder()
.setBegin(httpAddress.getPort())
.setEnd(httpAddress.getPort()))
.addRange(Value.Range.newBuilder()
.setBegin(reportAddress.getPort())
.setEnd(reportAddress.getPort()))))
.setExecutor(
ExecutorInfo
.newBuilder()
.setExecutorId(ExecutorID.newBuilder().setValue(
"executor_" + taskId.getValue()))
.setName("Hadoop TaskTracker")
.setSource(taskId.getValue())
.addResources(
Resource
.newBuilder()
.setName("cpus")
.setType(Value.Type.SCALAR)