예제 #1
0
파일: JobSummary.cs 프로젝트: xyuan/Dryad
 /// <summary>
 /// Initialize a job summary.
 /// </summary>
 /// <param name="cluster">Cluster where the job ran.</param>
 /// <param name="clusterType">A string corresponding to the type of ClusterConfiguration.</param>
 /// <param name="machine">Machine where job manager ran.</param>
 /// <param name="jobId">Id of job.</param>
 /// <param name="jmProcessGuid">Guid of job manager process.</param>
 /// <param name="clusterJobId">Id of job on the cluster.</param>
 /// <param name="friendlyname">Friendly name used.</param>
 /// <param name="username">Who ran the job.</param>
 /// <param name="date">Start date (not completion date).</param>
 /// <param name="status">Job status.</param>
 /// <param name="endTime">Estimated end running time.</param>
 /// <param name="virtualcluster">Virtual cluster where job ran.</param>
 public DryadLinqJobSummary(
     string cluster,
     ClusterConfiguration.ClusterType clusterType,
     string virtualcluster,
     string machine,
     string jobId,
     string clusterJobId,
     DryadProcessIdentifier jmProcessGuid,
     string friendlyname,
     string username,
     DateTime date,
     DateTime endTime,
     ClusterJobInformation.ClusterJobStatus status)
 {
     this.VirtualCluster     = virtualcluster;
     this.Cluster            = cluster;
     this.ClusterType        = clusterType;
     this.Machine            = machine;
     this.Name               = friendlyname;
     this.User               = username;
     this.Date               = date;
     this.EndTime            = endTime;
     this.Status             = status;
     this.ManagerProcessGuid = jmProcessGuid;
     this.JobID              = jobId;
     this.ClusterJobId       = clusterJobId;
 }
예제 #2
0
        /// <summary>
        /// Extract the job information from a folder with logs on the local machine.
        /// </summary>
        /// <param name="jobRootFolder">Folder with logs for the specified job.</param>
        /// <returns>The job information, or null if not found.</returns>
        private ClusterJobInformation GetJobInfo(string jobRootFolder)
        {
            Uri  uri = DfsFile.UriFromPath(this.config.JobsFolderUri, jobRootFolder);
            long time;
            long size;

            this.config.DfsClient.GetFileStatus(uri, out time, out size);

            DateTime date = DfsFile.TimeFromLong(time);

            ClusterJobInformation.ClusterJobStatus status = ClusterJobInformation.ClusterJobStatus.Unknown;
            string jobName = Path.GetFileName(jobRootFolder);

            string errorMsg = "";

            try
            {
                var jobinfo   = this.yarnClient.QueryJob(jobName, uri);
                var jobstatus = jobinfo.GetStatus();
                errorMsg = jobinfo.ErrorMsg;
                switch (jobstatus)
                {
                case JobStatus.NotSubmitted:
                case JobStatus.Waiting:
                    status = ClusterJobInformation.ClusterJobStatus.Unknown;
                    break;

                case JobStatus.Running:
                    status = ClusterJobInformation.ClusterJobStatus.Running;
                    break;

                case JobStatus.Success:
                    status = ClusterJobInformation.ClusterJobStatus.Succeeded;
                    break;

                case JobStatus.Cancelled:
                    status = ClusterJobInformation.ClusterJobStatus.Cancelled;
                    break;

                case JobStatus.Failure:
                    status = ClusterJobInformation.ClusterJobStatus.Failed;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (Exception)
            {
            }

            TimeSpan running = TimeSpan.Zero;
            var      info    = new ClusterJobInformation(config.Name, "", jobName, jobName, Environment.UserName, date, running, status);

            return(info);
        }
예제 #3
0
        /// <summary>
        /// Extract the job information from a folder with logs on the local machine.
        /// </summary>
        /// <param name="jobRootFolder">Folder with logs for the specified job.</param>
        /// <returns>The job information, or null if not found.</returns>
        private ClusterJobInformation GetJobInfo(string jobRootFolder)
        {
            DateTime date          = DateTime.MinValue;
            DateTime lastHeartBeat = DateTime.MinValue;

            ClusterJobInformation.ClusterJobStatus status = ClusterJobInformation.ClusterJobStatus.Unknown;
            bool found = false;

            Uri uri         = AzureDfsFile.UriFromPath(this.config, jobRootFolder);
            var jobsFolders = this.config.AzureClient.ExpandFileOrDirectory(uri).ToList();

            jobRootFolder = GetBlobName(this.config.Container, jobRootFolder);
            string jobName = jobRootFolder;

            foreach (var file in jobsFolders)
            {
                if (file.AbsolutePath.EndsWith("heartbeat"))
                {
                    string blobName = GetBlobName(this.config.Container, file.AbsolutePath);
                    var    blob     = this.config.AzureClient.Container.GetPageBlobReference(blobName);
                    blob.FetchAttributes();
                    var props = blob.Metadata;
                    if (props.ContainsKey("status"))
                    {
                        var st = props["status"];
                        switch (st)
                        {
                        case "failure":
                            status = ClusterJobInformation.ClusterJobStatus.Failed;
                            break;

                        case "success":
                            status = ClusterJobInformation.ClusterJobStatus.Succeeded;
                            break;

                        case "running":
                            status = ClusterJobInformation.ClusterJobStatus.Running;
                            break;

                        case "killed":
                            status = ClusterJobInformation.ClusterJobStatus.Cancelled;
                            break;

                        default:
                            Console.WriteLine("Unknown status " + st);
                            break;
                        }
                    }
                    if (props.ContainsKey("heartbeat"))
                    {
                        var hb = props["heartbeat"];
                        if (DateTime.TryParse(hb, out lastHeartBeat))
                        {
                            lastHeartBeat = lastHeartBeat.ToLocalTime();
                            if (status == ClusterJobInformation.ClusterJobStatus.Running &&
                                DateTime.Now - lastHeartBeat > TimeSpan.FromSeconds(40))
                            {
                                // job has in fact crashed
                                status = ClusterJobInformation.ClusterJobStatus.Failed;
                            }
                        }
                    }
                    if (props.ContainsKey("jobname"))
                    {
                        jobName = props["jobname"];
                    }
                    if (props.ContainsKey("starttime"))
                    {
                        var t = props["starttime"];
                        if (DateTime.TryParse(t, out date))
                        {
                            date = date.ToLocalTime();
                        }
                    }

                    found = true;
                }
                else if (file.AbsolutePath.Contains("DryadLinqProgram__") &&
                         // newer heartbeats contain the date
                         date != DateTime.MinValue)
                {
                    var blob = this.config.AzureClient.Container.GetBlockBlobReference(AzureDfsFile.PathFromUri(this.config, file));
                    blob.FetchAttributes();
                    var props = blob.Properties;
                    if (props.LastModified.HasValue)
                    {
                        date = props.LastModified.Value.DateTime;
                        date = date.ToLocalTime();
                    }
                }
            }

            if (!found)
            {
                return(null);
            }

            TimeSpan running = TimeSpan.Zero;

            if (date != DateTime.MinValue && lastHeartBeat != DateTime.MinValue)
            {
                running = lastHeartBeat - date;
            }
            var info = new ClusterJobInformation(this.config.Name, "", jobRootFolder, jobName, Environment.UserName, date, running, status);

            return(info);
        }