Search in sources :

Example 11 with NodeTask

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;
    }
}
Also used : TaskID(org.apache.mesos.Protos.TaskID) TaskStatus(org.apache.mesos.Protos.TaskStatus) NodeTask(org.apache.myriad.state.NodeTask) TaskState(org.apache.mesos.Protos.TaskState)

Example 12 with NodeTask

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());
}
Also used : OfferBuilder(org.apache.myriad.scheduler.offer.OfferBuilder) NodeTask(org.apache.myriad.state.NodeTask) ResourceOfferContainer(org.apache.myriad.scheduler.resource.ResourceOfferContainer) Protos(org.apache.mesos.Protos) Test(org.junit.Test) BaseConfigurableTest(org.apache.myriad.BaseConfigurableTest)

Example 13 with NodeTask

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);
}
Also used : OfferBuilder(org.apache.myriad.scheduler.offer.OfferBuilder) NodeTask(org.apache.myriad.state.NodeTask) ResourceOfferContainer(org.apache.myriad.scheduler.resource.ResourceOfferContainer) ServiceConfiguration(org.apache.myriad.configuration.ServiceConfiguration) Protos(org.apache.mesos.Protos) Test(org.junit.Test) BaseConfigurableTest(org.apache.myriad.BaseConfigurableTest)

Example 14 with NodeTask

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());
}
Also used : Offer(org.apache.mesos.Protos.Offer) NodeTask(org.apache.myriad.state.NodeTask) Test(org.junit.Test) BaseConfigurableTest(org.apache.myriad.BaseConfigurableTest)

Example 15 with NodeTask

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;
}
Also used : NodeTask(org.apache.myriad.state.NodeTask) LikeConstraint(org.apache.myriad.scheduler.constraints.LikeConstraint)

Aggregations

NodeTask (org.apache.myriad.state.NodeTask)20 LikeConstraint (org.apache.myriad.scheduler.constraints.LikeConstraint)8 Protos (org.apache.mesos.Protos)6 Test (org.junit.Test)6 BaseConfigurableTest (org.apache.myriad.BaseConfigurableTest)5 Constraint (org.apache.myriad.scheduler.constraints.Constraint)5 Offer (org.apache.mesos.Protos.Offer)4 ServiceResourceProfile (org.apache.myriad.scheduler.ServiceResourceProfile)3 ResourceOfferContainer (org.apache.myriad.scheduler.resource.ResourceOfferContainer)3 ByteBuffer (java.nio.ByteBuffer)2 HashSet (java.util.HashSet)2 TaskID (org.apache.mesos.Protos.TaskID)2 ServiceConfiguration (org.apache.myriad.configuration.ServiceConfiguration)2 OfferBuilder (org.apache.myriad.scheduler.offer.OfferBuilder)2 TreeMap (java.util.TreeMap)1 MyriadFileSystemRMStateStore (org.apache.hadoop.yarn.server.resourcemanager.recovery.MyriadFileSystemRMStateStore)1 Status (org.apache.mesos.Protos.Status)1 TaskInfo (org.apache.mesos.Protos.TaskInfo)1 TaskState (org.apache.mesos.Protos.TaskState)1 TaskStatus (org.apache.mesos.Protos.TaskStatus)1