Example #1
0
        public void Run(TaskSchedule schedule, IEnumerable<Resource> resources)
        {
            lock (_taskLock)
            {
                try
                {
                    var execStarted = DateTime.Now;
                    CurrentSchedule = schedule;

                    Params[CONST.Params.Method] = Method;

                    var resource = resources.First(r => r.ResourceName == schedule.ResourceName);
                    string incarnatedFtpFolder = GetFtpFolder(schedule.Nodes.First(), resource, CopyPhase.In);

                    if (PackageBaseProxy.GetSupportedPackageNames()
                            .Any(name => String.Equals(name, Package, StringComparison.InvariantCultureIgnoreCase))
                       )
                    {
                        //ProcessInputs();

                        Time.AddToOverheads(TaskTimeOverheads.InputFilesCopy, () =>
                        {
                            Log.Debug("Uploading incarnated inputs");
                            foreach (var file in Incarnation.FilesToCopy)
                            {
                                Log.Debug(file.FileName + ": started");
                                IOProxy.Ftp.MakePath(incarnatedFtpFolder + Path.GetDirectoryName(file.FileName).Replace("\\", "/"));
                                Log.Debug(file.FileName + ": path been made");
                                IOProxy.Storage.Download(file.StorageId, incarnatedFtpFolder + file.FileName);
                                Log.Debug(file.FileName + ": downloaded");
                            }
                            Log.Debug("Uploading incarnated inputs done");
                        });
                    }

                    Incarnation.PackageName = Package;
                    Incarnation.UserCert = UserCert;

                    if (String.IsNullOrWhiteSpace(Incarnation.CommandLine))
                        throw new Exception("Impossible to run task with empty command line");

                    if (!Incarnation.CommandLine.Contains("{0}") &&
                        Incarnation.CommandLine.StartsWith(Package, StringComparison.InvariantCultureIgnoreCase))
                    {
                        Incarnation.CommandLine = "{0}" + Incarnation.CommandLine.Substring(Package.Length);
                    }

                    Log.Stats("T_adapters", this.WfId, this.TaskId, DateTime.Now - execStarted);

                    Time.AddToOverheads(TaskTimeOverheads.Provider, () =>
                    {
                        //var provider = Broker.ProviderByName(resource.ProviderName);
                        var controller = Discovery.GetControllerFarm(resource);

                        try
                        {
                            //Incarnation.ProvidedTaskId = provider.Run(this.TaskId, this.Incarnation, resource, schedule.Nodes);
                            var runContext = new ServiceProxies.ControllerFarmService.TaskRunContext()
                            {
                                TaskId      = this.TaskId,

                                //Incarnation = this.Incarnation,
                                UserCert = this.UserCert,
                                PackageName = this.Incarnation.PackageName,
                                CommandLine = this.Incarnation.CommandLine,

                                InputFiles  = this.Incarnation.FilesToCopy.Select(f => new ServiceProxies.ControllerFarmService.FileContext()
                                {
                                    FileName  = f.FileName,
                                    StorageId = f.StorageId,
                                }).ToList(),//.ToArray(),

                                ExpectedOutputFileNames = this.Incarnation.ExpectedOutputFileNames.ToList(),

                                NodesConfig = schedule.Nodes.Select(n => new ServiceProxies.ControllerFarmService.NodeRunConfig()
                                {
                                    ResourceName = n.ResourceName,
                                    NodeName     = n.NodeName,
                                    Cores        = n.Cores
                                }).ToList(),//ToArray()
                            };

                            Log.Debug("Running task on controller: " + TaskId.ToString());
                            controller.Run(runContext);
                            Log.Debug("Run done: " + TaskId.ToString());

                            controller.Close();
                        }
                        catch (Exception e)
                        {
                            controller.Abort();
                            Log.Error("Exception on Task.Run for task " + this.TaskId + ": " + e.ToString());

                            throw;
                        }
                    });

                    State = TaskState.Started;
                    Time.Started(TaskTimeMetric.Calculation);

                    Log.Stats("T_clust_start", this.WfId, this.TaskId, DateTime.Now);
                    _lastEvent = Eventing.EventType.TaskStarted;
                }
                catch (Exception e)
                {
                    Log.Error(String.Format("Error on executing task {0}: {1}\n{2}",
                        TaskId, e.Message, e.StackTrace
                    ));

                    Fail(reason: e.Message);
                }
            }
        }
Example #2
0
        public void Run(TaskSchedule schedule, IEnumerable <Resource> resources)
        {
            lock (_taskLock)
            {
                try
                {
                    var execStarted = DateTime.Now;
                    CurrentSchedule = schedule;

                    Params[CONST.Params.Method] = Method;

                    var    resource            = resources.First(r => r.ResourceName == schedule.ResourceName);
                    string incarnatedFtpFolder = GetFtpFolder(schedule.Nodes.First(), resource, CopyPhase.In);

                    if (PackageBaseProxy.GetSupportedPackageNames()
                        .Any(name => String.Equals(name, Package, StringComparison.InvariantCultureIgnoreCase))
                        )
                    {
                        //ProcessInputs();

                        Time.AddToOverheads(TaskTimeOverheads.InputFilesCopy, () =>
                        {
                            Log.Debug("Uploading incarnated inputs");
                            foreach (var file in Incarnation.FilesToCopy)
                            {
                                Log.Debug(file.FileName + ": started");
                                IOProxy.Ftp.MakePath(incarnatedFtpFolder + Path.GetDirectoryName(file.FileName).Replace("\\", "/"));
                                Log.Debug(file.FileName + ": path been made");
                                IOProxy.Storage.Download(file.StorageId, incarnatedFtpFolder + file.FileName);
                                Log.Debug(file.FileName + ": downloaded");
                            }
                            Log.Debug("Uploading incarnated inputs done");
                        });
                    }
                    else
                    {
                        //ApplyAdapters(Broker.Adapters.Where(a => a.Type == AdapterType.Machine), incarnatedFtpFolder);
                        //ApplyAdapters(Broker.Adapters.Where(a => a.Type == AdapterType.Package), incarnatedFtpFolder);
                        //ApplyAdapters(Broker.Adapters.Where(a => a.Type == AdapterType.Mixed), incarnatedFtpFolder);
                    }

                    Incarnation.PackageName = Package;
                    Incarnation.UserCert    = UserCert;

                    if (String.IsNullOrWhiteSpace(Incarnation.CommandLine))
                    {
                        throw new Exception("Impossible to run task with empty command line");
                    }

                    if (!Incarnation.CommandLine.Contains("{0}") &&
                        Incarnation.CommandLine.StartsWith(Package, StringComparison.InvariantCultureIgnoreCase))
                    {
                        Incarnation.CommandLine = "{0}" + Incarnation.CommandLine.Substring(Package.Length);
                    }

                    Log.Stats("T_adapters", this.WfId, this.TaskId, DateTime.Now - execStarted);

                    Time.AddToOverheads(TaskTimeOverheads.Provider, () =>
                    {
                        //var provider = Broker.ProviderByName(resource.ProviderName);
                        var controller = Discovery.GetControllerFarm(resource);

                        try
                        {
                            //Incarnation.ProvidedTaskId = provider.Run(this.TaskId, this.Incarnation, resource, schedule.Nodes);
                            var runContext = new ServiceProxies.ControllerFarmService.TaskRunContext()
                            {
                                TaskId = this.TaskId,

                                //Incarnation = this.Incarnation,
                                UserCert    = this.UserCert,
                                PackageName = this.Incarnation.PackageName,
                                CommandLine = this.Incarnation.CommandLine,

                                InputFiles = this.Incarnation.FilesToCopy.Select(f => new ServiceProxies.ControllerFarmService.FileContext()
                                {
                                    FileName  = f.FileName,
                                    StorageId = f.StorageId,
                                }).ToArray(),

                                ExpectedOutputFileNames = this.Incarnation.ExpectedOutputFileNames.ToArray(),


                                NodesConfig = schedule.Nodes.Select(n => new ServiceProxies.ControllerFarmService.NodeRunConfig()
                                {
                                    ResourceName = n.ResourceName,
                                    NodeName     = n.NodeName,
                                    Cores        = n.Cores
                                }).ToArray()
                            };

                            Log.Debug("Running task on controller: " + TaskId.ToString());
                            controller.Run(runContext);
                            Log.Debug("Run done: " + TaskId.ToString());

                            controller.Close();
                        }
                        catch (Exception e)
                        {
                            controller.Abort();
                            Log.Error("Exception on Task.Run for task " + this.TaskId + ": " + e.ToString());

                            throw;
                        }
                    });

                    State = TaskState.Started;
                    Time.Started(TaskTimeMetric.Calculation);

                    Log.Stats("T_clust_start", this.WfId, this.TaskId, DateTime.Now);
                    _lastEvent = Eventing.EventType.TaskStarted;
                }
                catch (Exception e)
                {
                    Log.Error(String.Format("Error on executing task {0}: {1}\n{2}",
                                            TaskId, e.Message, e.StackTrace
                                            ));

                    Fail(reason: e.Message);
                }
            }
        }
Example #3
0
 public void Run(ServiceProxies.ControllerFarmService.TaskRunContext task)
 {
     base.Channel.Run(task);
 }