Search in sources :

Example 1 with TaskInstanceId

use of edu.iu.dsc.tws.tsched.spi.taskschedule.TaskInstanceId in project twister2 by DSC-SPIDAL.

the class TaskSchedulePlanBuilder method buildContainerPlans.

private Set<TaskSchedulePlan.ContainerPlan> buildContainerPlans(Map<Integer, Container> containerValue, Map<String, Double> taskrammap, Map<String, Double> taskdiskmap, Map<String, Double> taskcpumap, Resource instdefaultresourcevalue, int containerPadding) {
    Set<TaskSchedulePlan.ContainerPlan> containerPlans = 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<TaskSchedulePlan.TaskInstancePlan> taskInstancePlans = new HashSet<>();
            for (TaskSchedulePlan.TaskInstancePlan taskInstancePlan : container.getTaskInstances()) {
                TaskInstanceId instanceId = new TaskInstanceId(taskInstancePlan.getTaskName(), taskInstancePlan.getTaskId(), taskInstancePlan.getTaskIndex());
                Double instanceRAMValue;
                Double instanceDiskValue;
                Double instanceCPUValue;
                if (taskrammap.containsKey(instanceId.getTaskName())) {
                    instanceRAMValue = taskrammap.get(instanceId.getTaskName());
                } else {
                    instanceRAMValue = instdefaultresourcevalue.getRam();
                }
                containerRAMValue += instanceRAMValue;
                LOG.info("ResourceContainer Ram Value:" + containerRAMValue);
                if (taskdiskmap.containsKey(instanceId.getTaskName())) {
                    instanceDiskValue = instdefaultresourcevalue.getDisk();
                } else {
                    instanceDiskValue = instdefaultresourcevalue.getDisk();
                }
                containerDiskValue += instanceDiskValue;
                LOG.info("ResourceContainer Disk Value:" + containerDiskValue);
                if (taskcpumap.containsKey(instanceId.getTaskName())) {
                    instanceCPUValue = instdefaultresourcevalue.getCpu();
                } else {
                    instanceCPUValue = instdefaultresourcevalue.getCpu();
                }
                containerCPUValue += instanceCPUValue;
                Resource resource = new Resource(instanceRAMValue, instanceDiskValue, instanceCPUValue);
                taskInstancePlans.add(new TaskSchedulePlan.TaskInstancePlan(instanceId.getTaskName(), instanceId.getTaskId(), instanceId.getTaskIndex(), resource));
            /*taskInstancePlans.add(new TaskSchedulePlan.TaskInstancePlan (instanceId,
                new ResourceContainer(instanceRAMValue, instanceDiskValue, instanceCPUValue)));*/
            }
            LOG.info("ResourceContainer CPU Value:" + containerCPUValue);
            /* containerCpu += (paddingPercentage * containerCpu) / 100;
          containerRam = containerRam.increaseBy(paddingPercentage);
          containerDiskInBytes = containerDiskInBytes.increaseBy(paddingPercentage); */
            Resource resource = new Resource(containerRAMValue, containerDiskValue, containerCPUValue);
            TaskSchedulePlan.ContainerPlan containerPlan = new TaskSchedulePlan.ContainerPlan(containerId, taskInstancePlans, resource);
            containerPlans.add(containerPlan);
        }
    } catch (NullPointerException ne) {
        ne.printStackTrace();
    }
    return containerPlans;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Resource(edu.iu.dsc.tws.tsched.spi.taskschedule.Resource) TaskInstanceId(edu.iu.dsc.tws.tsched.spi.taskschedule.TaskInstanceId) TaskSchedulePlan(edu.iu.dsc.tws.tsched.spi.taskschedule.TaskSchedulePlan) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Resource (edu.iu.dsc.tws.tsched.spi.taskschedule.Resource)1 TaskInstanceId (edu.iu.dsc.tws.tsched.spi.taskschedule.TaskInstanceId)1 TaskSchedulePlan (edu.iu.dsc.tws.tsched.spi.taskschedule.TaskSchedulePlan)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1