コード例 #1
0
ファイル: JobWatcher.cs プロジェクト: sebbalex/PITre
        public override void Execute()
        {
            _LogManager.Info("About to execute JobWatcher. Total jobs to watch: " + (JobCacheMngr.Instance().GetJobCacheCount() + JobCacheMngr.Instance().GetJobWatchCacheCount()).ToString());
            DirectorWSAWrapper wrapper  = new DirectorWSAWrapper();
            string             response = "";
            bool init = wrapper.InitializeGenericConnector(ref response);

            if (!init)
            {
                wrapper.LogManager().Error("JobWatcher failed to initialize DirectorWSAWrapper: " + response);
                return;
            }
            List <Guid> guidList = new List <Guid>();
            List <JobManagementService.JobStatusResponse> jobStatusResponse = null;

            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            int count = 0;

            Thread.Sleep(500); //let everybody else to start
            while (NeedStop() == false)
            {
                count = 0;
                if (guidList != null && guidList.Count > 0)
                {
                    guidList.Clear();
                }
                if (NeedStop() == true)
                {
                    break;
                }
                try
                {
                    if (JobCacheMngr.Instance().GetJobWatchCacheCount() > 0)
                    {
                        //old heavy way

                        /*
                         * watch.Reset();
                         * watch.Start();
                         * Guid[] arr = wrapper.GetJobsId(ViewJobs.Completed);
                         * watch.Stop();
                         * long getIdsDuration = watch.ElapsedMilliseconds;
                         *
                         * if (arr != null && arr.Length > 0)
                         * {
                         *  guidList = new List<Guid>(arr);
                         * }
                         * if (guidList != null)
                         * {
                         *  count = guidList.Count();
                         * }
                         * if (count > 0)
                         * {
                         *  _LogManager.Info(string.Format("JobWatcher found {0} completed jobs. Each will be quered for details and released after. GetJobsId duration: {1}ms", count, getIdsDuration));
                         *
                         *  foreach (Guid jobId in guidList)
                         *  {
                         *      try
                         *      {
                         *          JobRequest job = JobCacheMngr.Instance().GetJobByJobIdFromWatchCache(jobId);
                         *          if (job != null)
                         *          {
                         *              JobCacheMngr.Instance().AddToJobReleaseCache(job);
                         *              //JobCacheMngr.Instance().RemoveJobByJobIdFromWatchCache(jobId);
                         *          }
                         *      }
                         *      catch (Exception je)
                         *      {
                         *          _LogManager.Warn("Failed to move job for release: " + je.Message);
                         *      }
                         *  }
                         * }
                         * */

                        //using new ligther call
                        List <Guid> ids = JobCacheMngr.Instance().GetJobWatchIdList();
                        watch.Reset();
                        watch.Start();
                        if (ids != null && ids.Count > 0)
                        {
                            jobStatusResponse = wrapper.GetJobsStatusInfo(ids);
                        }
                        watch.Stop();
                        long getIdsDuration = watch.ElapsedMilliseconds;
                        if (jobStatusResponse != null)
                        {
                            count = jobStatusResponse.Count();
                        }
                        if (count > 0)
                        {
                            int countCompleted = 0;
                            foreach (JobManagementService.JobStatusResponse rs in jobStatusResponse)
                            {
                                if (rs.JobStatus == JobManagementService.JobStatus.CompletedCancelled ||
                                    rs.JobStatus == JobManagementService.JobStatus.CompletedFailed ||
                                    rs.JobStatus == JobManagementService.JobStatus.CompletedResubmissionFailed ||
                                    rs.JobStatus == JobManagementService.JobStatus.CompletedSuccessful ||
                                    rs.JobStatus == JobManagementService.JobStatus.CompletedUncommitted)
                                {
                                    try
                                    {
                                        JobRequest job = JobCacheMngr.Instance().GetJobByJobIdFromWatchCache(rs.JobId);
                                        if (job != null)
                                        {
                                            JobCacheMngr.Instance().AddToJobReleaseCache(job);
                                            //JobCacheMngr.Instance().RemoveJobByJobIdFromWatchCache(jobId);
                                        }
                                    }
                                    catch (Exception je)
                                    {
                                        _LogManager.Warn("Failed to move job for release: " + je.Message);
                                    }
                                    countCompleted++;
                                }
                            }

                            if (countCompleted > 0)
                            {
                                _LogManager.Info(string.Format("JobWatcher found {0} completed jobs (out of {2} queued). Each will be queued for details and released after. GetJobsStatus duration: {1}ms ({2} total queued jobs)", countCompleted, getIdsDuration, count));
                            }
                        }
                    }

                    if (NeedStop() == true)
                    {
                        break;
                    }
                    if (JobCacheMngr.Instance().GetJobWatchCacheCount() == 0 &&
                        JobCacheMngr.Instance().GetJobCacheCount() == 0)
                    {
                        _LogManager.Info("Exiting JobWatcher, because there are no more jobs to submit.");
                        break;
                    }
                    //sleep anyway before next query
                    if (JobCacheMngr.Instance().GetJobReleaseCacheCount() > 100)
                    {
                        Thread.Sleep(1000);
                    }
                    else if (JobCacheMngr.Instance().GetJobWatchCacheCount() == 0)
                    {
                        Thread.Sleep(1000);
                    }
                    else
                    {
                        Thread.Sleep(500);
                    }
                }
                catch (Exception ee)
                {
                    _LogManager.Warn("Failed to release job: " + ee.Message);
                }
                finally
                {
                }
            }
        }
コード例 #2
0
ファイル: JobSubmitter.cs プロジェクト: sebbalex/PITre
        public override void Execute()
        {
            _LogManager.Info("About to execute JobSubmitter. Total jobs to submit: " + JobCacheMngr.Instance().GetJobCacheCount());
            JobRequest         job      = null;
            Guid               jobId    = Guid.Empty;
            DirectorWSAWrapper wrapper  = new DirectorWSAWrapper();
            string             response = "";
            bool               init     = wrapper.InitializeGenericConnector(ref response);

            if (!init)
            {
                wrapper.LogManager().Error("JobSubmitter failed to initialize DirectorWSAWrapper: " + response);
                return;
            }
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            string fullPath   = wrapper.DirectorSettings.CustomUncPathForInputDocs;
            int    currentJob = 0;
            string subfolder  = _ThreadTag;

            if (_MaxNumberFilesInSubfolder > 0)
            {
                subfolder = _ThreadTag + "\\" + DateTime.Now.ToString(DefaultTimeFormat);
                fullPath  = System.IO.Path.Combine(wrapper.DirectorSettings.CustomUncPathForInputDocs, subfolder);
                System.IO.Directory.CreateDirectory(fullPath);
            }
            Thread.Sleep(500); //let everybody else to start
            while (NeedStop() == false)
            {
                job   = null;
                jobId = Guid.Empty;
                if (NeedStop() == true)
                {
                    break;
                }
                if (_SleepBetweenJobs > 0)
                {
                    System.Threading.Thread.Sleep(_SleepBetweenJobs);
                }
                try
                {
                    job = JobCacheMngr.Instance().GetNextJobFromCache();
                    if (job == null)
                    {
                        _LogManager.Info("Exiting JobSubmitter, because there are no more jobs to submit.");
                        break;
                    }

                    if (_MaxNumberFilesInSubfolder > 0 && currentJob >= _MaxNumberFilesInSubfolder)
                    {
                        subfolder = _ThreadTag + "\\" + DateTime.Now.ToString(DefaultTimeFormat);
                        fullPath  = System.IO.Path.Combine(wrapper.DirectorSettings.CustomUncPathForInputDocs, subfolder);
                        System.IO.Directory.CreateDirectory(fullPath);
                        currentJob = 0;
                    }

                    watch.Reset();
                    watch.Start();
                    string tempSubfolder = subfolder;
                    if (!string.IsNullOrEmpty(job.NickName))
                    {
                        if (!string.IsNullOrEmpty(tempSubfolder))
                        {
                            tempSubfolder += "\\";
                        }
                        tempSubfolder += job.NickName;
                    }
                    if (job.SubmitAsOneCall)
                    {
                        jobId = wrapper.SubmitJobSimple(job.InputFileList, job.MetadataList, tempSubfolder, Guid.NewGuid());
                    }
                    else
                    {
                        jobId = wrapper.SubmitDocuments(job.InputFileList, job.MetadataList, false, tempSubfolder);
                    }
                    currentJob++;
                    watch.Stop();
                    if (jobId == Guid.Empty)
                    {
                        _LogManager.Error("JobSubmitter failed to submit job. See log for details.");
                    }
                    else
                    {
                        job.JobId = jobId;
                        JobCacheMngr.Instance().AddToJobWatchCache(job);
                        _LogManager.Info(string.Format("JobSubmitter added new job: {0}. Duration: {1}ms", jobId, watch.ElapsedMilliseconds));
                    }
                }
                catch (Exception ee)
                {
                    _LogManager.Warn("Failed to submit job: " + ee.Message);
                }
                finally
                {
                }
            }
        }
コード例 #3
0
        public override void Execute()
        {
            _LogManager.Info("About to execute JobFinalizer. Total jobs to watch: " + (JobCacheMngr.Instance().GetJobCacheCount() + JobCacheMngr.Instance().GetJobWatchCacheCount() + JobCacheMngr.Instance().GetJobReleaseCacheCount()).ToString());
            DirectorWSAWrapper wrapper = new DirectorWSAWrapper();
            List <JobManagementService.Metadata> metadataList = new List <JobManagementService.Metadata>();

            metadataList.Add(new JobManagementService.Metadata
            {
                Name  = "Adlib.Job.Release.Light",
                Value = ""
            });
            string response = "";
            bool   init     = wrapper.InitializeGenericConnector(ref response);

            if (!init)
            {
                wrapper.LogManager().Error("JobFinalizer failed to initialize DirectorWSAWrapper: " + response);
                return;
            }
            //JobManagementService.JobDetailResponse jobDetails = null;
            List <JobManagementService.JobCompletionInfoResponse> jobCompletionInfoResponse = null;

            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            int        count = 0;
            JobRequest job   = null;

            Thread.Sleep(500); //let everybody else to start
            while (NeedStop() == false)
            {
                count = 0;

                if (NeedStop() == true)
                {
                    break;
                }
                try
                {
                    count = JobCacheMngr.Instance().GetJobReleaseCacheCount();
                    if (count > 0)
                    {
                        if (count > 0)
                        {
                            job = JobCacheMngr.Instance().GetNextJobFromReleaseCache();
                            while (job != null)
                            {
                                try
                                {
                                    //emulate quering job details
                                    watch.Reset();
                                    watch.Start();
                                    //heavy call
                                    //jobDetails = wrapper.GetJobDetails(job.JobId);
                                    //lighter call
                                    jobCompletionInfoResponse = wrapper.GetJobsCompletionInfo(new List <Guid>()
                                    {
                                        job.JobId
                                    });
                                    //print message here
                                    watch.Stop();
                                    long getDetailsDuration = watch.ElapsedMilliseconds;

                                    if (jobCompletionInfoResponse != null &&
                                        jobCompletionInfoResponse.Count == 1 && jobCompletionInfoResponse[0] != null)
                                    {
                                        _LogManager.Info(string.Format("Job Completion Info for job {0}: ResultCode: {1}, ResultMessage: {2}.", job.JobId,
                                                                       jobCompletionInfoResponse[0].ResultCode, jobCompletionInfoResponse[0].ResultMessage));
                                    }
                                    else
                                    {
                                        _LogManager.Error(string.Format("Failed to get Completion Info for: {0}.", job.JobId));
                                    }
                                    watch.Reset();
                                    watch.Start();
                                    if (_DeleteFolderOnRelease && jobCompletionInfoResponse != null &&
                                        jobCompletionInfoResponse.Count == 1 && jobCompletionInfoResponse[0] != null)
                                    {
                                        if (jobCompletionInfoResponse[0].JobDocumentsInfo != null && jobCompletionInfoResponse[0].JobDocumentsInfo.DocumentInputs != null &&
                                            jobCompletionInfoResponse[0].JobDocumentsInfo.DocumentInputs.Length > 0)
                                        {
                                            JobManagementService.DocumentInput di = jobCompletionInfoResponse[0].JobDocumentsInfo.DocumentInputs[0];
                                            if (di != null && !string.IsNullOrEmpty(di.Folder))
                                            {
                                                try
                                                {
                                                    Adlib.Common.IO.IOTools.DeleteFolderContents(di.Folder, true);
                                                    System.IO.Directory.Delete(di.Folder, true);
                                                }
                                                catch (Exception ioE2)
                                                {
                                                    _LogManager.Error(string.Format("Failed to delete folder for: {0}. Folder: {1}. Error: {2}", jobCompletionInfoResponse[0].JobId, di.Folder, ioE2.Message));
                                                }
                                            }
                                        }
                                    }
                                    watch.Stop();
                                    long deleteDuration = watch.ElapsedMilliseconds;
                                    watch.Start();
                                    JobManagementService.JobResponse[] rs = wrapper.ReleaseJobs(new List <Guid> {
                                        job.JobId
                                    }, metadataList);
                                    watch.Stop();
                                    long releaseDuration = watch.ElapsedMilliseconds;
                                    watch.Reset();
                                    _LogManager.Info(string.Format("JobFinalizer {0} released job: {1}. Result: {2}. GetJobsCompletionInfo duration: {3}ms, ReleaseJob duration: {4}ms. JobReleaseCacheCount: {5}. Delete folder duration: {6}", this._ThreadTag, job.JobId, rs[0].ResultCode, getDetailsDuration, releaseDuration, JobCacheMngr.Instance().GetJobReleaseCacheCount(), deleteDuration));
                                }
                                catch (Exception je)
                                {
                                    _LogManager.Warn("Failed to get job details or release it: " + je.Message);
                                }
                                job = JobCacheMngr.Instance().GetNextJobFromReleaseCache();
                            }
                        }
                    }

                    if (NeedStop() == true)
                    {
                        break;
                    }
                    if (JobCacheMngr.Instance().GetJobWatchCacheCount() == 0 &&
                        JobCacheMngr.Instance().GetJobCacheCount() == 0 &&
                        JobCacheMngr.Instance().GetJobReleaseCacheCount() == 0)
                    {
                        _LogManager.Info("Exiting JobFinalizer, because there are no more jobs to release.");
                        break;
                    }
                    //sleep anyway before next query
                    if (JobCacheMngr.Instance().GetJobReleaseCacheCount() == 0)
                    {
                        Thread.Sleep(1000);
                    }
                    else
                    {
                        Thread.Sleep(5);
                    }
                }
                catch (Exception ee)
                {
                    _LogManager.Warn("Failed to release job: " + ee.Message);
                }
                finally
                {
                }
            }
        }
コード例 #4
0
        public static void DoWork()
        {
            bool result = false;
            List <JobDownloadRecord> jobList = null;

            while (true)
            {
                if (_stopWork)
                {
                    break;
                }
                jobList = GetJobIdsForDownload();
                if (jobList != null && jobList.Count > 0)
                {
                    foreach (JobDownloadRecord jobRecord in jobList)
                    {
                        if (_DirectorWrapper != null)
                        {
                            try
                            {
                                Adlib.Director.DirectorWSAWrapper.DirectorWSA.JobDetailResponse response = _DirectorWrapper.GetJobDetails(jobRecord.JobId);
                                if (response != null)
                                {
                                    if (response.JobStatus == Adlib.Director.DirectorWSAWrapper.DirectorWSA.JobStatus.CompletedSuccessful)
                                    {
                                        result = _DirectorWrapper.DownloadOutputDocuments(jobRecord.JobId, jobRecord.UseFileRepository, 2 /*2Mb chunks*/);
                                        if (result == false)
                                        {
                                            _DirectorWrapper.LogManager().Info(string.Format("Failed to download outputs for job with JobId: {0}. See log for details.", jobRecord.JobId));
                                        }
                                        else
                                        {
                                            _DirectorWrapper.LogManager().Info(string.Format("Outputs were successfully downloaded for job with JobId: {0}.", jobRecord.JobId));
                                        }
                                        RemoveJobIdFromDownload(jobRecord.JobId);
                                    }
                                    else
                                    if (response.JobStatus == Adlib.Director.DirectorWSAWrapper.DirectorWSA.JobStatus.CompletedCancelled ||
                                        response.JobStatus == Adlib.Director.DirectorWSAWrapper.DirectorWSA.JobStatus.CompletedFailed ||
                                        response.JobStatus == Adlib.Director.DirectorWSAWrapper.DirectorWSA.JobStatus.CompletedResubmissionFailed)
                                    {
                                        _DirectorWrapper.LogManager().Info(string.Format("Removing job with JobId: {0} from download list because it's status is {1}", jobRecord.JobId, response.JobStatus.ToString()));
                                        RemoveJobIdFromDownload(jobRecord.JobId);
                                    }
                                }
                                else
                                {
                                    _DirectorWrapper.LogManager().Error(string.Format("Can't find Job with JobId: {0} to download outputs. Deleting job from queue.", jobRecord.JobId));
                                    RemoveJobIdFromDownload(jobRecord.JobId);
                                }
                            }
                            catch (Exception e)
                            {
                            }
                        }

                        if (_stopWork)
                        {
                            break;
                        }
                        System.Threading.Thread.Sleep(1000);
                    }
                }

                if (_stopWork)
                {
                    break;
                }
                System.Threading.Thread.Sleep(5000);
            }
        }
コード例 #5
0
        private void UpdateSettings()
        {
            try
            {
                if (_DirectorWrapper != null)
                {
                    try
                    {
                        _DirectorWrapper.DirectorSettings.SubmitterComponentId = new Guid(_ClientComponentID);
                    }
                    catch (Exception e)
                    {
                        _DirectorWrapper.LogManager().ErrorException("Failed to convert SubmitterComponentId to Guid.", e);
                        _DirectorWrapper.DirectorSettings.SubmitterComponentId = Guid.Empty;
                    }
                    _DirectorWrapper.DirectorSettings.CustomUncPathForInputDocs         = _UncPathForInputs;
                    _DirectorWrapper.DirectorSettings.JobManagementServiceUrl           = _DirectorWSAUrl;
                    _DirectorWrapper.DirectorSettings.OutputDocumentsPathAfterCompleted = _FolderForOutputDocuments;
                    try
                    {
                        _DirectorWrapper.DirectorSettings.RepositoryId = new Guid(_RepositoryID);
                    }
                    catch (Exception e)
                    {
                        _DirectorWrapper.LogManager().ErrorException("Failed to convert RepositoryId to Guid.", e);
                        _DirectorWrapper.DirectorSettings.RepositoryId = Guid.Empty;
                    }

                    _DirectorWrapper.DirectorSettings.UserDefinedId  = _UserDefinedID;
                    _DirectorWrapper.DirectorSettings.UseObjectLock  = _UseObjectLock;
                    _DirectorWrapper.DirectorSettings.ExcapeMetadata = _EscapeMetadata;

                    try
                    {
                        _DirectorWrapper.DirectorSettings.AdminScopeId = new Guid(_AdminScopeId);
                    }
                    catch (Exception e)
                    {
                        _DirectorWrapper.LogManager().ErrorException("Failed to convert AdminScopeId to Guid.", e);
                        _DirectorWrapper.DirectorSettings.AdminScopeId = Guid.Empty;
                    }
                    try
                    {
                        _DirectorWrapper.DirectorSettings.WorkspaceId = new Guid(_workspace);
                    }
                    catch (Exception e)
                    {
                        _DirectorWrapper.LogManager().ErrorException("Failed to convert WorkspaceVersionId to Guid.", e);
                        _DirectorWrapper.DirectorSettings.WorkspaceId = Guid.Empty;
                    }
                    _DirectorWrapper.SaveSettings();
                }
            }
            catch (Exception ex)
            {
                _DirectorWrapper.LogManager().ErrorException("Failed to save settings to file.", ex);
            }
            finally
            {
            }
        }