Пример #1
0
        /// <summary>
        /// retrieves a list of jobs based on the specified filters
        /// </summary>
        /// <returns></returns>
        public List <ISchedulerJob> GetJobList(IFilterCollection filters, ISortCollection sorts)
        {
            List <ISchedulerJob> jobs = new List <ISchedulerJob>();

            foreach (ISchedulerJob schedulerJob in _scheduler.GetNodeList(filters, sorts))
            {
                jobs.Add(schedulerJob);
            }

            return(jobs);
        }
Пример #2
0
        /// <summary>
        /// retrieves node list based on the specified filters
        /// </summary>
        /// <param name="filters"></param>
        /// <param name="sorts"></param>
        /// <returns></returns>
        public List <ISchedulerNode> GetNodeList(IFilterCollection filters, ISortCollection sorts)
        {
            List <ISchedulerNode> nodes = new List <ISchedulerNode>();

            foreach (ISchedulerNode schedulerNode in _scheduler.GetNodeList(filters, sorts))
            {
                nodes.Add(schedulerNode);
            }

            return(nodes);
        }
Пример #3
0
        static int iRoundToSecondsMinimum = 10;  // If a TimeSpan takes more than 10 seconds, round off the milliseconds

        /// <summary>
        /// Command Line entrypoint
        /// </summary>
        /// <param name="args">parsed parameter string</param>
        /// <returns></returns>
        static int Main(string[] args)
        {
            // In case it has been renamed, find out what the current name in use is
            // Filename for Help or Error messages
            Location l = new Location();

            sExeFilename = Path.GetFileNameWithoutExtension(Path.GetFileName(l.locationFullPath));

            if (ParseParameters(args) == false)
            {
                return(-1);
            }

            // If no job id or user is defined, give help message
            if ((jobId == 0) && (userName == null))
            {
                help(sExeFilename);
                return(-1);
            }

            try {
                using (IScheduler scheduler = new Scheduler()) {
                    ISchedulerCollection jobs   = null;
                    IFilterCollection    filter = null;
                    ISortCollection      sort   = null;

                    scheduler.Connect(clusterName);

                    // Filter the jobs requested by the parameters, either a single job or a range, and/or a user
                    filter = scheduler.CreateFilterCollection();
                    if (jobIdRange != 0)
                    {
                        filter.Add(FilterOperator.GreaterThanOrEqual, JobPropertyIds.Id, jobId);
                        filter.Add(FilterOperator.LessThanOrEqual, JobPropertyIds.Id, jobIdRange);
                    }
                    else
                    {
                        filter.Add(FilterOperator.Equal, JobPropertyIds.Id, jobId);
                    }

                    if (userName != null)
                    {
                        filter.Add(FilterOperator.Equal, JobPropertyIds.Owner, userName);
                    }

                    // Sort the jobs relative to when they were created
                    sort = scheduler.CreateSortCollection();
                    sort.Add(SortProperty.SortOrder.Ascending, PropId.Job_CreateTime);

                    jobs = scheduler.GetJobList(filter, sort);

                    // Be sure the job(s) can be found
                    if (jobs.Count == 0)
                    {
                        Console.Error.WriteLine(sExeFilename + NOJOBSFOUND);
                        return(-1);
                    }
                    else
                    {
                        foreach (ISchedulerJob job in jobs)
                        {
                            if (bVerbose)
                            {
                                Console.WriteLine("job {0} project: {1}", job.Id, job.Project);
                            }

                            // Is the job part of the project?
                            if ((projectName != null) && (job.Project != projectName))
                            {
                                continue;
                            }
                            else if ((projectNameIgnore != null) && (job.Project.Equals(projectNameIgnore, StringComparison.InvariantCultureIgnoreCase) == false))
                            {
                                continue;
                            }
                            else    // Exact match overrides StartsWith and Contains, only test them if previous tests are not attempted
                            {
                                if ((projectNameBegins != null) && (job.Project.StartsWith(projectNameBegins, StringComparison.InvariantCultureIgnoreCase) == false))
                                {
                                    continue;
                                }
                                if ((projectNameContains != null) && (job.Project.Contains(projectNameContains) == false))
                                {
                                    continue;
                                }
                            }
                            iFilteredJobs++;

                            Console.WriteLine("Job {0} - {1}", job.Id, job.State);
                            Console.WriteLine(job.Name);
                            collectAllocatedInfo(job);
                        }
                    }

                    // Jobs were found within the range, but none had the appropriate project criteria
                    if (iFilteredJobs <= 0)
                    {
                        Console.Error.WriteLine(sExeFilename + NOJOBSFOUND);
                        return(-1);
                    }
                    // Round up/down to seconds if greater than minimum
                    if (tsAllJobUsage.TotalSeconds >= iRoundToSecondsMinimum)
                    {
                        if (tsAllJobUsage.Milliseconds >= 500)
                        {
                            tsAllJobUsage = tsAllJobUsage.Add(TimeSpan.FromMilliseconds(1000 - tsAllJobUsage.Milliseconds));
                        }
                        else
                        {
                            tsAllJobUsage = tsAllJobUsage.Subtract(TimeSpan.FromMilliseconds(tsAllJobUsage.Milliseconds));
                        }
                    }

                    // If a range of jobs was given, or other criteria created selected multiple jobs, show summary
                    if ((jobIdRange > 0) || (iFilteredJobs > 1))
                    {
                        Console.WriteLine("Number of jobs:  {0}", iFilteredJobs);
                        Console.WriteLine("Number of {0}: {1}", bNodesOnly ? "nodes" : "cores", iAllJobThreads);
                        Console.WriteLine("{0} usage across all jobs: {1}", bNodesOnly ? "Node" : "Core", tsAllJobUsage);
                    }
                }
            } catch (Exception e) {
                Console.Error.WriteLine("Exception!");
                Console.Error.WriteLine(e.Message);
            }

            return(iFilteredJobs);
        }