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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations