Search in sources :

Example 1 with NodeTask

use of org.apache.myriad.state.NodeTask in project incubator-myriad by apache.

the class TestObjectFactory method getNodeTask.

/**
 * Returns a NodeTask with either a ServiceResourceProfile or an ExtendedResourceProfile,
 * depending upon whether execCores and execMemory are null or non-null, respectively
 *
 * @param profileName
 * @param hostName
 * @param cores
 * @param memory
 * @param execCores
 * @param execMemory
 * @return NodeTask
 */
public static NodeTask getNodeTask(String profileName, String hostName, Double cores, Double memory, Long execCores, Long execMemory) {
    NodeTask task = new NodeTask(getServiceResourceProfile(profileName, cores, memory, execCores, execMemory), new LikeConstraint(hostName, "host-[0-9]*.example.com"));
    task.setHostname(hostName);
    task.setTaskPrefix("nm");
    task.setSlaveId(SlaveID.newBuilder().setValue(profileName + "-" + 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)

Example 2 with NodeTask

use of org.apache.myriad.state.NodeTask in project incubator-myriad by apache.

the class SchedulerStateResourceTest method getSchedulerState.

private SchedulerState getSchedulerState() throws Exception {
    SchedulerState state = new SchedulerState(new MyriadFileSystemRMStateStore());
    idOne = Protos.TaskID.newBuilder().setValue("nt-1").build();
    idTwo = Protos.TaskID.newBuilder().setValue("nt-2").build();
    idThree = Protos.TaskID.newBuilder().setValue("nt-3").build();
    TreeMap<String, Long> ports = new TreeMap<>();
    state.addTask(idOne, new NodeTask(new ServiceResourceProfile("profile1", 0.2, 1024.0, ports), new LikeConstraint("localhost", "host-[0-9]*.example.com")));
    state.addTask(idTwo, new NodeTask(new ServiceResourceProfile("profile2", 0.4, 2048.0, ports), new LikeConstraint("localhost", "host-[0-9]*.example.com")));
    state.addTask(idThree, new NodeTask(new ServiceResourceProfile("profile3", 0.6, 3072.0, ports), new LikeConstraint("localhost", "host-[0-9]*.example.com")));
    state.setFrameworkId(FrameworkID.newBuilder().setValue("mock-framework").build());
    state.makeTaskActive(idOne);
    state.makeTaskPending(idTwo);
    state.makeTaskStaging(idThree);
    return state;
}
Also used : SchedulerState(org.apache.myriad.state.SchedulerState) MyriadFileSystemRMStateStore(org.apache.hadoop.yarn.server.resourcemanager.recovery.MyriadFileSystemRMStateStore) ServiceResourceProfile(org.apache.myriad.scheduler.ServiceResourceProfile) TreeMap(java.util.TreeMap) NodeTask(org.apache.myriad.state.NodeTask) LikeConstraint(org.apache.myriad.scheduler.constraints.LikeConstraint)

Example 3 with NodeTask

use of org.apache.myriad.state.NodeTask in project incubator-myriad by apache.

the class ByteBufferSupport method toNodeTask.

/**
 * ByteBuffer is expected to have a NodeTask at its next position.
 *
 * @param bb
 * @return NodeTask or null if buffer is empty. Can throw a RuntimeException
 * if the buffer is not formatted correctly.
 */
public static NodeTask toNodeTask(ByteBuffer bb) {
    NodeTask nt = null;
    if (byteBufferNotEmpty(bb)) {
        nt = new NodeTask(getServiceResourceProfile(bb), getConstraint(bb));
        nt.setHostname(toString(bb));
        nt.setSlaveId(toSlaveId(bb));
        nt.setTaskStatus(toTaskStatus(bb));
        nt.setExecutorInfo(toExecutorInfo(bb));
        nt.setTaskPrefix(toString(bb));
    }
    return nt;
}
Also used : NodeTask(org.apache.myriad.state.NodeTask)

Example 4 with NodeTask

use of org.apache.myriad.state.NodeTask in project incubator-myriad by apache.

the class StoreContext method getTasks.

/**
 * De-serialize the internal ByteBuffers back into a Task map.
 *
 * @return
 */
public Map<Protos.TaskID, NodeTask> getTasks() {
    Map<Protos.TaskID, NodeTask> map = null;
    if (taskIds != null) {
        map = new HashMap<Protos.TaskID, NodeTask>(taskIds.size());
        int idx = 0;
        for (ByteBuffer bb : taskIds) {
            final Protos.TaskID taskId = ByteBufferSupport.toTaskId(bb);
            final NodeTask task = ByteBufferSupport.toNodeTask(taskNodes.get(idx++));
            if (task.getTaskPrefix() == null && taskId != null) {
                String taskPrefix = taskIdPattern.split(taskId.getValue())[0];
                task.setTaskPrefix(taskPrefix);
            }
            map.put(taskId, task);
        }
    } else {
        map = new HashMap<Protos.TaskID, NodeTask>(0);
    }
    return map;
}
Also used : TaskID(org.apache.mesos.Protos.TaskID) Protos(org.apache.mesos.Protos) TaskID(org.apache.mesos.Protos.TaskID) NodeTask(org.apache.myriad.state.NodeTask) ByteBuffer(java.nio.ByteBuffer)

Example 5 with NodeTask

use of org.apache.myriad.state.NodeTask in project incubator-myriad by apache.

the class MyriadOperations method flexUpAService.

/**
 * Flexup a service
 *
 * @param instances
 * @param serviceName
 *
 * @throws MyriadBadConfigurationException if total number of instances in active, staging, and pending
 *                                         states exceeds the ServiceConfiguration.maxInstances
 */
public void flexUpAService(int instances, String serviceName) throws MyriadBadConfigurationException {
    final ServiceConfiguration auxTaskConf = cfg.getServiceConfiguration(serviceName).get();
    if (auxTaskConf.getMaxInstances().isPresent()) {
        // If total number of current and flex instances exceed maxInstances, throw an exception
        int totalflexInstances = instances + getFlexibleInstances(serviceName);
        Integer maxInstances = auxTaskConf.getMaxInstances().get();
        if (maxInstances > 0) {
            if (totalflexInstances > maxInstances) {
                LOGGER.error("Current number of active, staging, pending and requested instances: {}" + ", while it is greater then max instances allowed: {}", totalflexInstances, maxInstances);
                throw new MyriadBadConfigurationException("Current number of active, staging, pending instances and requested: " + totalflexInstances + ", while it is greater then max instances allowed: " + maxInstances);
            }
        }
    }
    final Double cpu = auxTaskConf.getCpus();
    final Double mem = auxTaskConf.getJvmMaxMemoryMB();
    Collection<NodeTask> nodes = new HashSet<>();
    for (int i = 0; i < instances; i++) {
        NodeTask nodeTask = new NodeTask(new ServiceResourceProfile(serviceName, cpu, mem, auxTaskConf.getPorts()), null);
        nodeTask.setTaskPrefix(serviceName);
        nodes.add(nodeTask);
    }
    LOGGER.info("Adding {} {} instances to cluster", nodes.size(), serviceName);
    this.schedulerState.addNodes(nodes);
}
Also used : ServiceConfiguration(org.apache.myriad.configuration.ServiceConfiguration) MyriadBadConfigurationException(org.apache.myriad.configuration.MyriadBadConfigurationException) NodeTask(org.apache.myriad.state.NodeTask) LikeConstraint(org.apache.myriad.scheduler.constraints.LikeConstraint) Constraint(org.apache.myriad.scheduler.constraints.Constraint) HashSet(java.util.HashSet)

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