Search in sources :

Example 6 with TaskSchedulerException

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;
}
Also used : WorkerSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan) HashMap(java.util.HashMap) TaskInstancePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan) Resource(edu.iu.dsc.tws.api.compute.schedule.elements.Resource) TaskSchedulerException(edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException)

Example 7 with TaskSchedulerException

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;
}
Also used : WorkerSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan) HashMap(java.util.HashMap) TaskInstancePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan) Resource(edu.iu.dsc.tws.api.compute.schedule.elements.Resource) TaskSchedulerException(edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException)

Example 8 with TaskSchedulerException

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Resource(edu.iu.dsc.tws.api.compute.schedule.elements.Resource) TaskSchedulerException(edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException) TaskInstanceId(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstanceId) WorkerSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan) TaskInstancePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 9 with TaskSchedulerException

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;
}
Also used : Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) Config(edu.iu.dsc.tws.api.config.Config) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) TaskSchedulerException(edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException) WorkerPlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerPlan) TaskSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskSchedulePlan)

Example 10 with TaskSchedulerException

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IntStream(java.util.stream.IntStream) TaskInstanceId(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstanceId) ComputeGraph(edu.iu.dsc.tws.api.compute.graph.ComputeGraph) TaskAttributes(edu.iu.dsc.tws.tsched.utils.TaskAttributes) INode(edu.iu.dsc.tws.api.compute.nodes.INode) HashMap(java.util.HashMap) Config(edu.iu.dsc.tws.api.config.Config) TaskSchedulerContext(edu.iu.dsc.tws.tsched.spi.common.TaskSchedulerContext) Resource(edu.iu.dsc.tws.api.compute.schedule.elements.Resource) TreeSet(java.util.TreeSet) Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) WorkerSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan) TaskInstanceMapCalculation(edu.iu.dsc.tws.tsched.spi.taskschedule.TaskInstanceMapCalculation) TaskSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskSchedulePlan) Receptor(edu.iu.dsc.tws.api.compute.modifiers.Receptor) Map(java.util.Map) TaskInstancePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan) Collector(edu.iu.dsc.tws.api.compute.modifiers.Collector) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) Logger(java.util.logging.Logger) Vertex(edu.iu.dsc.tws.api.compute.graph.Vertex) List(java.util.List) ITaskScheduler(edu.iu.dsc.tws.api.compute.schedule.ITaskScheduler) Worker(edu.iu.dsc.tws.api.compute.schedule.elements.Worker) WorkerPlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerPlan) Edge(edu.iu.dsc.tws.api.compute.graph.Edge) Comparator(java.util.Comparator) TaskSchedulerException(edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException) Vertex(edu.iu.dsc.tws.api.compute.graph.Vertex) INode(edu.iu.dsc.tws.api.compute.nodes.INode) Receptor(edu.iu.dsc.tws.api.compute.modifiers.Receptor) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Collector(edu.iu.dsc.tws.api.compute.modifiers.Collector)

Aggregations

TaskSchedulerException (edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException)16 TaskInstanceId (edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstanceId)8 Resource (edu.iu.dsc.tws.api.compute.schedule.elements.Resource)7 TaskInstancePlan (edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan)6 ArrayList (java.util.ArrayList)6 WorkerSchedulePlan (edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan)5 TreeSet (java.util.TreeSet)5 Vertex (edu.iu.dsc.tws.api.compute.graph.Vertex)4 TaskAttributes (edu.iu.dsc.tws.tsched.utils.TaskAttributes)4 HashMap (java.util.HashMap)4 LinkedHashSet (java.util.LinkedHashSet)4 List (java.util.List)4 TaskSchedulePlan (edu.iu.dsc.tws.api.compute.schedule.elements.TaskSchedulePlan)3 WorkerPlan (edu.iu.dsc.tws.api.compute.schedule.elements.WorkerPlan)3 Config (edu.iu.dsc.tws.api.config.Config)3 Twister2RuntimeException (edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 ComputeGraph (edu.iu.dsc.tws.api.compute.graph.ComputeGraph)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2