Пример #1
0
        public virtual object Clone()
        {
            var result = new LaunchPlan();

            result.EstimatedExecutionTime = EstimatedExecutionTime;
            result.NodesTimings           = NodesTimings == null ? null : NodesTimings.Select(nt => nt.Clone() as TaskScheduler.NodeAvailabilityTime).ToList();
            result.Plan = Plan == null ? null : Plan.Select(t => t.Clone() as ActiveEstimatedTask).ToList();
            return(result);
        }
Пример #2
0
 private void PrintLaunchPlanToLog(LaunchPlan plan)
 {
     logger.Info("==============Current resulted Plan Start===============");
     foreach (var p in plan.Plan)
     {
         var str = string.Format("Id:{0} .ResName:{1} NodeName: {2} State: {3}", p.Id, p.Estimation.Destination.ResourceName,
             p.Estimation.Destination.NodeNames[0], p.State.ToString());
         logger.Info(str);
     }
     logger.Info("===============Current resulted Plan End===============");
 }
Пример #3
0
        public Scheduler.Estimated.LaunchPlan RescheduleEstimated(Scheduler.Estimated.EstimatedWorkflow workflow)
        {
            logger.Debug(string.Format(debugPrefixNameString, "RescheduleEstimated"));

            try
            {
                var wfs = ConstructWorkflows(workflow).ToList();

                DeleteFinishedWorkflows(ref wfs);

                if (scheduledWfCount == 0)
                {
                    //firstCall = DateTime.Now;
                    ReadWindows();
                    PrintActiveToLog(wfs);
                    PrintEstimatedToLog(wfs);
                    // wfId, (taskId1, nodeId1, startTime), ..., (taskIdN, nodeIdN, startTime) for all WFs to be scheduled
                    schedule = new Dictionary<int, List<Tuple<int, int, int>>>();
                    // nodeId, (wfId, taskId, startTime according to schedule)
                    nodeQueues = new Dictionary<int, List<Tuple<int, int, int>>>();
                    // (wf.Item1, wfId)
                    wfIDs = new Dictionary<string, int>();
                    // (nodeId, (wfId, currentTaskId)) - we suppose that one node can execute only one task at time!!!
                    nodeCurrent = new Dictionary<int, Tuple<int, int>>();
                    // read number of nodes from resFile
                    int nodesCount = ReadNodesCount();
                    if (nodesCount == -1)
                        logger.Info("ReadNodesCount(). Wrong nodes count");
                    for (int i = 1; i <= nodesCount; i++)
                    {
                        nodeCurrent.Add(i, null);
                        nodeQueues.Add(i, new List<Tuple<int, int, int>>());
                    }
                        // (wfId, taskId)

                    // (wfId, taskId)
                    taskIDs = new Dictionary<ulong, Tuple<int, int>>();
                    // clear from previous runs
                    _scheduledWfs.Clear();

                    wasActive = new Dictionary<ulong, bool>();
                    foreach (var wf in wfs)
                    {
                        if (!tasksCount.ContainsKey(wf.Item1))
                            tasksCount.Add(wf.Item1, wf.Item3.Count());
                        foreach (var task in wf.Item3)
                        {
                            wasActive.Add(task.Id, false);
                        }
                    }
                 }

                PrintActiveToLog(wfs);
                SetActive(ref wfs);
                //PrintEstimatedToLog(wfs);

                var result = new LaunchPlan();

                if (ConfigurationManager.AppSettings["SchedMethod"] == "second"){

                    //DeleteFinishedTasksFromQueues(ref wfs);
                    //logger.Info("DeleteFinishedTasksFromQueues() ended");
                    DeleteFinishedTasksFromQueues(ref wfs);
                    logger.Info("DeleteFinishedTasksFromQueues() ended");
                    DeleteFinishedWorkflows(ref wfs);
                    logger.Info("DeleteFinishedWorkflows() ended");
                    //logger.Info("RescheduleEstimated(). Keys of scheduled workflows: ");
                    //foreach (var wf in _scheduledWfs)
                    //{
                    //    logger.Info("Workflow " + wf.Key);
                    //}

                    // (wfKey, wfDep, wfActiveEstimated)
                    var wfResults = new Dictionary<string, Tuple<IEnumerable<Scheduler.Estimated.TasksDepenendency>, List<ActiveEstimatedTask>>>();

                    //logger.Info("Wf ids: ");
                    foreach (var wf in wfs)
                    {
                        // if workflow was already scheduled, copy previous schedule

                        if (_scheduledWfs.ContainsKey(wf.Item1))
                        {
                            wfResults.Add(wf.Item1, new Tuple<IEnumerable<Scheduler.Estimated.TasksDepenendency>, List<ActiveEstimatedTask>>(wf.Item4, _scheduledWfs[wf.Item1].Plan));
                        }
                     }

                    //logger.Info("Scheduled WFs count: " + _scheduledWfs.Count());
                    //logger.Info("Current plan after already scheduled wf's addition");

                    //PrintLaunchPlanToLog(result);

                    var tosched = wfs.Where(wf => !_scheduledWfs.ContainsKey(wf.Item1)).ToArray();

                    if (tosched.Count() != 0)
                    {

                        // wf ids scheduled on current step
                        List<int> schedWFIds = new List<int>();

                        int idToAdd = 0;

                        if (wfIDs.Count == 0)
                            idToAdd = 0;
                        else idToAdd = wfIDs.ElementAt(wfIDs.Count - 1).Value;

                        foreach (var wf in tosched)
                        {
                            wfIDs.Add(wf.Item1, idToAdd);
                            schedWFIds.Add(idToAdd);
                            foreach (var task in wf.Item3)
                            {
                                taskIDs.Add(task.Id, new Tuple<int, int>(idToAdd, Int32.Parse(task.Parameters["id"])));
                            }

                            idToAdd++;
                        }
                        // removing old *.dat files if they exist

                        // generating *.dat files for each unscheduled wf
                        for (int i = 0; i < tosched.Length; i++)
                        {
                            //logger.Info("To sched key: {0}", tosched[i].Item1);
                            GenerateWorkflowInfo(ref tosched[i], wfIDs[tosched[i].Item1], i);
                        }

                        try
                        {
                            Process proc = new Process();
                            proc.StartInfo.UseShellExecute = false;
                            proc.StartInfo.RedirectStandardOutput = true;
                            proc.StartInfo.RedirectStandardError = true;
                            string fullPathToScheduler = ConfigurationManager.AppSettings["SchedPath"] + "\\WFSched.exe";
                            logger.Info("Starting " + fullPathToScheduler + "...");
                            proc.StartInfo.FileName = fullPathToScheduler;
                            proc.Start();
                            string output = proc.StandardOutput.ReadToEnd();
                            string error = proc.StandardError.ReadToEnd();
                            proc.WaitForExit();
                            var exitCode = proc.ExitCode;
                            logger.Info("Scheduler was exit with code " + exitCode.ToString());
                            //logger.Info("Output: " + output);
                            //logger.Info("Error: " + error);
                        }
                        catch (Exception e)
                        {
                            logger.Info("WFSched exception: " + e.Message);
                        }

                        ReadScheduleFromFile(ref schedule);

                        // add information to resource queues
                        AddSchedWfToQueues(ref schedule, ref schedWFIds);

                        foreach (var wf in tosched)
                        {
                            var tasks = wf.Item3;
                            var wfID = wfIDs[wf.Item1];

                            ResourceEstimation[] estimations = null;
                            estimations = new ResourceEstimation[tasks.Count()];
                            foreach (var task in tasks)
                            {
                                ResourceEstimation estimation = new ResourceEstimation();

                                var localTaskID = int.Parse(task.Parameters["id"]) - 1;
                                //logger.Info("Task WFID:", localTaskID);
                                var taskNode = schedule[wfID].Where(t => t.Item1 == localTaskID);
                                //logger.Info("Before: wfID " + wfID + " localTaskID: " + localTaskID);
                                var nodeIndex = taskNode.First().Item2;
                                //logger.Info("After");

                                try
                                {
                                    estimation = task.Estimations[nodeIndex];
                                    estimations[localTaskID] = estimation;
                                }
                                catch (Exception ex)
                                {
                                    logger.ErrorException("Exception in getting estimations", ex);
                                }
                                scheduledWfCount++;
                            }
                            try
                            {
                                var activeestimated = processUnscheduledWfsSeq(wf, estimations);
                                wfResults.Add(wf.Item1, new Tuple<IEnumerable<Scheduler.Estimated.TasksDepenendency>, List<ActiveEstimatedTask>>(wf.Item4, activeestimated));
                            }
                            catch (Exception ex)
                            {
                                logger.ErrorException("Exception in processUnscheduledWFsSeq", ex);
                            }
                        }

                      }

                    // update status
                    UpdateTaskStatus(ref wfResults);

                    SetStatusToFinishedTasks(ref wfResults);

                    try
                    {
                        foreach (var wf in wfResults)
                        {
                            var wfResult = new LaunchPlan();
                            wfResult.Plan.AddRange(wf.Value.Item2);
                            result.Plan.AddRange(wf.Value.Item2);

                            if (_scheduledWfs.ContainsKey(wf.Key))
                            {
                                _scheduledWfs[wf.Key] = wfResult;
                            }
                            else
                            {
                                _scheduledWfs.Add(wf.Key, wfResult);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.ErrorException("Add final plan error. " + ex.Message, ex);
                    }

                }
                if (isFirstActive)
                    logger.Info("Current time: " + GetTime());
                //logger.Info("Current plan: " + _scheduledWfs.Count());
                PrintLaunchPlanToLog(result);
                //logger.Info("Workflows tasks count");
                foreach (var wf in wfs)
                {
                    logger.Info(wf.Item1 + " active: " + wf.Item2.Count() + " estimated: " + wf.Item3.Count());
                }

                //prevCall = DateTime.Now;

                if (!isFirstActive)
                    CheckFirstActive(ref wfs);

                return result;
            }
            catch (Exception ex)
            {
                logger.ErrorException("Exception in scheduling. " + ex.Message, ex);
                throw;
            }
        }
Пример #4
0
 public virtual object Clone()
 {
     var result = new LaunchPlan();
     result.EstimatedExecutionTime = EstimatedExecutionTime;
     result.NodesTimings = NodesTimings == null ? null : NodesTimings.Select(nt => nt.Clone() as TaskScheduler.NodeAvailabilityTime).ToList();
     result.Plan = Plan == null ? null : Plan.Select(t => t.Clone() as ActiveEstimatedTask).ToList();
     return result;
 }
Пример #5
0
 public LaunchPlan(LaunchPlan other)
 {
     EstimatedExecutionTime = other.EstimatedExecutionTime;
     NodesTimings = other.NodesTimings == null ? null : other.NodesTimings.Select(nt => nt.Clone() as TaskScheduler.NodeAvailabilityTime).ToList();
     Plan = other.Plan == null ? null : other.Plan.Select(t => t.Clone() as ActiveEstimatedTask).ToList();
 }
Пример #6
0
 public LaunchPlan(LaunchPlan other)
 {
     EstimatedExecutionTime = other.EstimatedExecutionTime;
     NodesTimings           = other.NodesTimings == null ? null : other.NodesTimings.Select(nt => nt.Clone() as TaskScheduler.NodeAvailabilityTime).ToList();
     Plan = other.Plan == null ? null : other.Plan.Select(t => t.Clone() as ActiveEstimatedTask).ToList();
 }
Пример #7
0
        public Estimated.LaunchPlan RescheduleEstimated(EstimatedWorkflow workflow)
        {
            Estimated.LaunchPlan mostTrueResult;
            if (!workflow.IsUrgent)
            {
                var h = CreateTaskBasedHeuristics(GetDefaultHName());
                workflow.UpdateDependencies();
                var wrappers    = GenerateWrappers(workflow);
                var estimations = MakeOverallEstimations(workflow, wrappers);
                var result      = new Estimated.LaunchPlan();
                var roots       = workflow.Tasks.Where(t => !t.IsScheduled && t.IsReady);

                {
                    var busyWrappers = wrappers.Where(w => w.GetAvailabilityTime() > E).ToArray();
                    var freeWrappers = wrappers.Except(busyWrappers).ToArray();
                    for (var i = 0; i < estimations.Count; i++)
                    {
                        if (estimations[i].Count() > 1)
                        {
                            /*var estimationsOnFreeNodes = estimations[i].Where(e => e.Estimation.Destination.NodeNames.All(n => freeWrappers.Any(fw => fw.ResourceName == e.Estimation.Destination.ResourceName && fw.NodeName == n))).OrderBy(t => t.Estimation.NodesTimings.Max(n => n.GetAvailabilityTime()) + t.Estimation.Result.Time);
                             * var otherEstimations = estimations[i].Except(estimationsOnFreeNodes).OrderBy(t => t.Estimation.NodesTimings.Max(n => n.GetAvailabilityTime()) + t.Estimation.Result.Time);
                             * estimations[i] = new List<ActiveEstimatedTask>();
                             * ((List<ActiveEstimatedTask>)estimations[i]).AddRange(estimationsOnFreeNodes);
                             * ((List<ActiveEstimatedTask>)estimations[i]).AddRange(otherEstimations);*/
                            estimations[i] = estimations[i].OrderBy(t => t.Estimation.NodesTimings.Max(n => n.GetAvailabilityTime()) + t.Estimation.Result.Time).ToList();
                        }
                    }
                }

                while (roots.Count() > 0)
                {
                    var rootIds = roots.Select(r => r.Id);
                    var effectiveEstimations = estimations.Where(e => rootIds.Contains(e.First().Id)).ToList();
                    var prevInstance         = h.ChooseTask(workflow, effectiveEstimations);
                    //var nodeWrappers = wrappers.Where(w => w.ResourceName == prevInstance.Estimation.Destination.ResourceName && prevInstance.Estimation.Destination.NodeNames.Contains(w.NodeName));
                    var task            = workflow.Tasks.Single(t => t.Id == prevInstance.Id);
                    var depsWaitingTime = task.RequiresDependencies.Count == 0 ? 0 : task.RequiresDependencies.Max(d => d.ScheduledInstance.Estimation.LaunchTime + d.ScheduledInstance.Estimation.Result.Time);
                    prevInstance.Estimation.LaunchTime = Math.Max(depsWaitingTime, prevInstance.Estimation.NodesTimings.Max(n => n.GetAvailabilityTime()));
                    prevInstance.State = prevInstance.Estimation.LaunchTime > E || prevInstance.Estimation.NodesTimings.Any(w => w.GetAvailabilityTime() > E) ? TaskState.SCHEDULED : TaskState.LAUNCHED;
                    var clonedInstance = new ActiveEstimatedTask(prevInstance);

                    foreach (var node in prevInstance.Estimation.NodesTimings)
                    {
                        node.AssignTask(clonedInstance);
                    }
                    var seq = estimations.Single(e => e.First().Id == prevInstance.Id);
                    estimations.Remove(seq);
                    result.Plan.Add(clonedInstance);
                    task.ScheduledInstance = clonedInstance;
                    roots = workflow.Tasks.Where(t => !t.IsScheduled && t.IsReady);
                    var busyWrappers = wrappers.Where(w => w.GetAvailabilityTime() > E);
                    var freeWrappers = wrappers.Except(busyWrappers);
                    for (var i = 0; i < estimations.Count; i++)
                    {
                        if (estimations[i].Count() > 1)
                        {
                            /*var estimationsOnFreeNodes = estimations[i].Where(e => e.Estimation.Destination.NodeNames.All(n => freeWrappers.Any(fw => fw.ResourceName == e.Estimation.Destination.ResourceName && fw.NodeName == n))).OrderBy(t => t.Estimation.NodesTimings.Max(n => n.GetAvailabilityTime()) + t.Estimation.Result.Time);
                             * var otherEstimations = estimations[i].Except(estimationsOnFreeNodes).OrderBy(t => t.Estimation.NodesTimings.Max(n => n.GetAvailabilityTime()) + t.Estimation.Result.Time);
                             * estimations[i] = new List<ActiveEstimatedTask>();
                             * ((List<ActiveEstimatedTask>)estimations[i]).AddRange(estimationsOnFreeNodes);
                             * ((List<ActiveEstimatedTask>)estimations[i]).AddRange(otherEstimations);*/
                            estimations[i] = estimations[i].OrderBy(t => t.Estimation.NodesTimings.Max(n => n.GetAvailabilityTime()) + t.Estimation.Result.Time).ToList();
                        }
                    }
                }
                result.NodesTimings           = wrappers.ToList();
                result.EstimatedExecutionTime = result.Plan.Any() ? result.Plan.Max(t => t.Estimation.LaunchTime + t.Estimation.Result.Time) : 0;
                Debug.Assert(workflow.Tasks.All(t => t.IsScheduled));
                mostTrueResult = result;
            }
            else
            {
                var uwf = (EstimatedUrgentWorkflow)workflow;
                var h   = CreateUrgentHeuristics(GetDefaultUHName());
                mostTrueResult = h.MakePlan(uwf);
            }
            var hasPlanDups = mostTrueResult.Plan.Any(t => t.State == TaskState.LAUNCHED && mostTrueResult.Plan.Any(t2 => t2.Id != t.Id && t2.State == TaskState.LAUNCHED && t.Estimation.Destination.IsLike(t2.Estimation.Destination)));
            var hasWfDups   = mostTrueResult.Plan.Any(t => t.State == TaskState.LAUNCHED && workflow.ActiveTasks.Any(t2 => t.Id != t2.Id && t2.State == TaskState.LAUNCHED && t.Estimation.Destination.IsLike(t2.Estimation.Destination)));

            return((Scheduler.Estimated.LaunchPlan)mostTrueResult);
        }