use of org.apache.myriad.state.NodeTask in project incubator-myriad by apache.
the class StatusUpdateEventHandler method onEvent.
/**
* Encapsulates the logic to log and respond to the incoming StatusUpdateEvent per the
* Event TaskStatus state:
*
* 1. TASK_STAGING: mark task as staging wtihin SchedulerState
* 2. TASK_STARTING: mark task as staging within SchedulerState
* 3. TASK_RUNNING: mark task as active within SchedulerState
* 4. TASK_FINISHED: decline outstanding offers and remove task from SchedulerState
* 5. TASK_FAILED: decline outstanding offers, remove failed, killable tasks from SchedulerState,
* mark as pending non-killable, failed tasks
* 6. TASK_KILLED: decline outstanding offers, removed killed tasks from SchedulerState
* 7. TASK_LOST: decline outstanding offers, remove killable, lost tasks from SchedulerState,
* mark as pending non-killable, lost tasks
*/
@Override
public void onEvent(StatusUpdateEvent event, long sequence, boolean endOfBatch) throws Exception {
TaskStatus status = event.getStatus();
this.schedulerState.updateTask(status);
TaskID taskId = status.getTaskId();
NodeTask task = schedulerState.getTask(taskId);
if (task == null) {
LOGGER.warn("Task: {} not found, status: {}", taskId.getValue(), status.getState());
schedulerState.removeTask(taskId);
return;
}
LOGGER.info("Status Update for task: {} | state: {}", taskId.getValue(), status.getState());
TaskState state = status.getState();
switch(state) {
case TASK_STAGING:
schedulerState.makeTaskStaging(taskId);
break;
case TASK_STARTING:
schedulerState.makeTaskStaging(taskId);
break;
case TASK_RUNNING:
schedulerState.makeTaskActive(taskId);
break;
case TASK_FINISHED:
cleanupTask(taskId, task, "finished");
break;
case TASK_FAILED:
cleanupFailedTask(taskId, task, "failed");
break;
case TASK_KILLED:
cleanupTask(taskId, task, "killed");
break;
case TASK_LOST:
cleanupFailedTask(taskId, task, "lost");
break;
default:
LOGGER.error("Invalid state: {}", state);
break;
}
}
use of org.apache.myriad.state.NodeTask in project incubator-myriad by apache.
the class TestNMTaskFactory method testNMTaskFactory.
@Test
public void testNMTaskFactory() {
NMExecutorCommandLineGenerator clGenerator = new NMExecutorCommandLineGenerator(cfgWithDocker);
TaskUtils taskUtils = new TaskUtils(cfgWithDocker);
Protos.Offer offer = new OfferBuilder("test.com").addScalarResource("cpus", 10.0).addScalarResource("mem", 16000).addRangeResource("ports", 3500, 3505).build();
ServiceResourceProfile profile = new ExtendedResourceProfile(new NMProfile("tooMuchCpu", 7L, 8000L), taskUtils.getNodeManagerCpus(), taskUtils.getNodeManagerMemory(), taskUtils.getNodeManagerPorts());
NodeTask nodeTask = new NodeTask(profile, null);
ResourceOfferContainer roc = new ResourceOfferContainer(offer, profile, null);
NMTaskFactory taskFactory = new NMTaskFactory(cfgWithDocker, taskUtils, clGenerator);
Protos.TaskInfo taskInfo = taskFactory.createTask(roc, frameworkId, makeTaskId("nm.zero"), nodeTask);
assertFalse("taskInfo should not have a container", taskInfo.hasContainer());
assertTrue("The container should have an executor", taskInfo.hasExecutor());
Protos.ExecutorInfo executorInfo = taskInfo.getExecutor();
assertTrue("executorInfo should have container", executorInfo.hasContainer());
Protos.ContainerInfo containerInfo = executorInfo.getContainer();
assertTrue("There should be two volumes", containerInfo.getVolumesCount() == 2);
assertTrue("The first volume should be read only", containerInfo.getVolumes(0).getMode().equals(Protos.Volume.Mode.RO));
assertTrue("The first volume should be read write", containerInfo.getVolumes(1).getMode().equals(Protos.Volume.Mode.RW));
assertTrue("There should be a docker image", containerInfo.getDocker().hasImage());
assertTrue("The docker image should be mesos/myraid", containerInfo.getDocker().getImage().equals("mesos/myriad"));
assertTrue("Should be using host networking", containerInfo.getDocker().getNetwork().equals(Protos.ContainerInfo.DockerInfo.Network.HOST));
assertTrue("There should be two parameters", containerInfo.getDocker().getParametersList().size() == 2);
assertTrue("Privledged mode should be false", !containerInfo.getDocker().getPrivileged());
}
use of org.apache.myriad.state.NodeTask in project incubator-myriad by apache.
the class TestServiceTaskFactory method testServiceTaskFactory.
@Test
public void testServiceTaskFactory() {
ServiceCommandLineGenerator clGenerator = new ServiceCommandLineGenerator(cfgWithDocker);
TaskUtils taskUtils = new TaskUtils(cfgWithDocker);
Protos.Offer offer = new OfferBuilder("test.com").addScalarResource("cpus", 10.0).addScalarResource("mem", 16000).addRangeResource("ports", 3400, 3410).build();
Map<String, ServiceConfiguration> stringServiceConfigurationMap = cfgWithDocker.getServiceConfigurations();
System.out.print(stringServiceConfigurationMap);
ServiceConfiguration serviceConfiguration = cfgWithDocker.getServiceConfigurations().get("jobhistory");
ServiceResourceProfile profile = new ServiceResourceProfile("jobhistory", serviceConfiguration.getCpus(), serviceConfiguration.getJvmMaxMemoryMB(), serviceConfiguration.getPorts());
NodeTask nodeTask = new NodeTask(profile, null);
nodeTask.setTaskPrefix("jobhistory");
ResourceOfferContainer roc = new ResourceOfferContainer(offer, profile, null);
System.out.print(roc.getPorts());
ServiceTaskFactory taskFactory = new ServiceTaskFactory(cfgWithDocker, taskUtils, clGenerator);
Protos.TaskInfo taskInfo = taskFactory.createTask(roc, frameworkId, makeTaskId("jobhistory"), nodeTask);
assertTrue("taskInfo should have a container", taskInfo.hasContainer());
assertFalse("The container should not have an executor", taskInfo.hasExecutor());
Protos.ContainerInfo containerInfo = taskInfo.getContainer();
assertTrue("There should be two volumes", containerInfo.getVolumesCount() == 2);
assertTrue("The first volume should be read only", containerInfo.getVolumes(0).getMode().equals(Protos.Volume.Mode.RO));
assertTrue("The first volume should be read write", containerInfo.getVolumes(1).getMode().equals(Protos.Volume.Mode.RW));
assertTrue("There should be a docker image", containerInfo.getDocker().hasImage());
assertTrue("The docker image should be mesos/myraid", containerInfo.getDocker().getImage().equals("mesos/myriad"));
assertTrue("Should be using host networking", containerInfo.getDocker().getNetwork().equals(Protos.ContainerInfo.DockerInfo.Network.HOST));
assertTrue("There should be two parameters", containerInfo.getDocker().getParametersList().size() == 2);
assertTrue("Privledged mode should be false", containerInfo.getDocker().getPrivileged() == false);
}
use of org.apache.myriad.state.NodeTask in project incubator-myriad by apache.
the class YarnNodeCapacityManagerTest method testHandleContainerAllocation.
@Test
public void testHandleContainerAllocation() throws Exception {
Offer offer = TestObjectFactory.getOffer("zero-localhost-one", "slave-one", "mock-framework", "offer-one", 0.1, 512.0);
sNodeOne.allocateContainer(containerOne);
NodeTask task = TestObjectFactory.getNodeTask("small", "localhost-one", Double.valueOf(0.1), Double.valueOf(512.0), Long.parseLong("1"), Long.parseLong("256"));
state.addNodes(Lists.newArrayList(task));
olManager.addOffers(offer);
olManager.markAsConsumed(offer);
manager.handleContainerAllocation(nodeOne);
store.getNode("localhost-one").snapshotRunningContainers();
assertEquals(1, store.getNode("localhost-one").getNode().getRunningContainers().size());
assertEquals(1, store.getNode("localhost-one").getContainerSnapshot().size());
}
use of org.apache.myriad.state.NodeTask in project incubator-myriad by apache.
the class TestObjectFactory method getNodeTask.
/**
* Returns a NodeTask given a ServiceResourceProfile and hostname
*
* @param hostName
* @param profile
* @return
*/
public static NodeTask getNodeTask(String hostName, ServiceResourceProfile profile) {
NodeTask task = new NodeTask(profile, new LikeConstraint(hostName, "host-[0-9]*.example.com"));
task.setHostname(hostName);
task.setTaskPrefix("nm");
task.setSlaveId(SlaveID.newBuilder().setValue(profile.getName() + "-" + hostName).build());
task.setExecutorInfo(ExecutorInfo.newBuilder().setExecutorId(ExecutorID.newBuilder().setValue("exec")).setCommand(org.apache.mesos.Protos.CommandInfo.newBuilder().setValue("command")).build());
return task;
}
Aggregations