use of edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException in project twister2 by DSC-SPIDAL.
the class TaskSchedulePlanBuilder method getContainers.
/**
* Get the containers based on the task schedule plan
*/
private Map<Integer, Container> getContainers(TaskSchedulePlan previoustaskschedulePlan) throws TaskSchedulerException {
Map<Integer, Container> containerMap = new HashMap<>();
Resource resource = previoustaskschedulePlan.getMaxContainerResources();
for (WorkerSchedulePlan currentWorkerSchedulePlan : previoustaskschedulePlan.getContainers()) {
Container container = new Container(currentWorkerSchedulePlan.getContainerId(), resource, requestedContainerPadding);
for (TaskInstancePlan instancePlan : currentWorkerSchedulePlan.getTaskInstances()) {
try {
addToContainer(container, instancePlan, taskIndexes, taskIds);
} catch (TaskSchedulerException e) {
throw new TaskSchedulerException(String.format("Insufficient container resources to add instancePlan %s to container %s", instancePlan, container), e);
}
}
containerMap.put(currentWorkerSchedulePlan.getContainerId(), container);
}
return containerMap;
}
use of edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException in project twister2 by DSC-SPIDAL.
the class TaskSchedulePlanBuilder method getContainers.
/**
* Get the containers based on the task schedule plan
* @param previoustaskschedulePlan
* @return
* @throws TaskSchedulerException
*/
private Map<Integer, Container> getContainers(TaskSchedulePlan previoustaskschedulePlan, int containerPadding, Map<String, TreeSet<Integer>> taskindexes, TreeSet<Integer> taskids) throws TaskSchedulerException {
Map<Integer, Container> containerMap = new HashMap<>();
Resource resource = previoustaskschedulePlan.getMaxContainerResources();
for (WorkerSchedulePlan currentWorkerSchedulePlan : previoustaskschedulePlan.getContainers()) {
Container container = new Container(currentWorkerSchedulePlan.getContainerId(), resource, containerPadding);
for (TaskInstancePlan instancePlan : currentWorkerSchedulePlan.getTaskInstances()) {
try {
addToContainer(container, instancePlan, taskindexes, taskids);
} catch (TaskSchedulerException e) {
throw new TaskSchedulerException(String.format("Insufficient container resources to add instancePlan %s to container %s", instancePlan, container), e);
}
}
containerMap.put(currentWorkerSchedulePlan.getContainerId(), container);
}
return containerMap;
}
use of edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException in project twister2 by DSC-SPIDAL.
the class TaskSchedulePlanBuilder method buildContainerPlans.
private Set<WorkerSchedulePlan> buildContainerPlans(Map<Integer, Container> containerValue, Map<String, Double> taskramMap, Resource instdefaultresourcevalue) {
Set<WorkerSchedulePlan> workerSchedulePlans = new LinkedHashSet<>();
try {
for (Integer containerId : containerValue.keySet()) {
Container container = containerValue.get(containerId);
if (container.getTaskInstances().size() == 0) {
continue;
}
double containerRAMValue = 0.0;
double containerDiskValue = 0.0;
double containerCPUValue = 0.0;
Set<TaskInstancePlan> taskInstancePlans = new HashSet<>();
for (TaskInstancePlan taskInstancePlan : container.getTaskInstances()) {
TaskInstanceId taskInstanceId = new TaskInstanceId(taskInstancePlan.getTaskName(), taskInstancePlan.getTaskId(), taskInstancePlan.getTaskIndex());
double instanceRAMValue;
if (taskramMap.containsKey(taskInstanceId.getTaskName())) {
instanceRAMValue = taskramMap.get(taskInstanceId.getTaskName());
} else {
instanceRAMValue = instdefaultresourcevalue.getRam();
}
containerRAMValue += instanceRAMValue;
double instanceDiskValue = instdefaultresourcevalue.getDisk();
containerDiskValue += instanceDiskValue;
double instanceCPUValue = instdefaultresourcevalue.getCpu();
containerCPUValue += instanceCPUValue;
LOG.fine("Resource Container Values:" + "Ram Value:" + containerRAMValue + "\t" + "Cpu Value:" + containerCPUValue + "\t" + "Disk Value:" + containerDiskValue);
Resource resource = new Resource(instanceRAMValue, instanceDiskValue, instanceCPUValue);
taskInstancePlans.add(new TaskInstancePlan(taskInstanceId.getTaskName(), taskInstanceId.getTaskId(), taskInstanceId.getTaskIndex(), resource));
}
containerCPUValue += (requestedContainerPadding * containerCPUValue) / 100;
containerRAMValue += containerRAMValue + requestedContainerPadding;
containerDiskValue += containerDiskValue + requestedContainerPadding;
Resource resource = new Resource(containerRAMValue, containerDiskValue, containerCPUValue);
WorkerSchedulePlan workerSchedulePlan = new WorkerSchedulePlan(containerId, taskInstancePlans, resource);
workerSchedulePlans.add(workerSchedulePlan);
}
} catch (TaskSchedulerException ne) {
throw new RuntimeException("Exception Occured" + ne.getMessage());
}
return workerSchedulePlans;
}
use of edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException in project twister2 by DSC-SPIDAL.
the class TaskScheduler method generateTaskSchedulePlans.
private Map<String, TaskSchedulePlan> generateTaskSchedulePlans(String className) {
Class<?> taskSchedulerClass;
Method method;
Map<String, TaskSchedulePlan> taskSchedulePlanMap;
try {
taskSchedulerClass = getClass().getClassLoader().loadClass(className);
Object newInstance = taskSchedulerClass.newInstance();
method = taskSchedulerClass.getMethod("initialize", new Class<?>[] { Config.class });
method.invoke(newInstance, config);
method = taskSchedulerClass.getMethod("schedule", new Class<?>[] { WorkerPlan.class, ComputeGraph[].class });
taskSchedulePlanMap = (Map<String, TaskSchedulePlan>) method.invoke(newInstance, new Object[] { workerPlan, computeGraphs });
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException | InstantiationException | ClassNotFoundException | TaskSchedulerException e) {
throw new Twister2RuntimeException(e);
}
return taskSchedulePlanMap;
}
use of edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException in project twister2 by DSC-SPIDAL.
the class BatchTaskScheduler method batchSchedulingAlgorithm.
private Map<Integer, List<TaskInstanceId>> batchSchedulingAlgorithm(ComputeGraph graph, int numberOfContainers) throws TaskSchedulerException {
Set<Vertex> taskVertexSet = new LinkedHashSet<>(graph.getTaskVertexSet());
TreeSet<Vertex> orderedTaskSet = new TreeSet<>(new VertexComparator());
orderedTaskSet.addAll(taskVertexSet);
IntStream.range(0, numberOfContainers).forEach(i1 -> batchTaskAllocation.put(i1, new ArrayList<>()));
int globalTaskIndex = 0;
if (dependentGraphs) {
for (Vertex vertex : taskVertexSet) {
INode iNode = vertex.getTask();
if (iNode instanceof Receptor) {
validateReceptor(graph, vertex);
}
dependentTaskWorkerAllocation(graph, vertex, numberOfContainers, globalTaskIndex);
globalTaskIndex++;
}
} else {
for (Vertex vertex : taskVertexSet) {
INode iNode = vertex.getTask();
if (iNode instanceof Collector) {
((Collector) iNode).getCollectibleNames().forEach(key -> collectibleNameMap.put(key, vertex.getParallelism()));
} else if (iNode instanceof Receptor) {
((Receptor) iNode).getReceivableNames().forEach(key -> receivableNameMap.put(key, vertex.getParallelism()));
validateParallelism();
}
independentTaskWorkerAllocation(graph, vertex, numberOfContainers, globalTaskIndex);
globalTaskIndex++;
}
}
return batchTaskAllocation;
}
Aggregations