Ejemplo n.º 1
0
 public void AddToJobWatchCache(JobRequest request)
 {
     if (request != null)
     {
         lock (_SyncInstanceObject)
         {
             _JobWatchCache.Add(request.JobId, request);
         }
     }
 }
Ejemplo n.º 2
0
 public void AddToJobReleaseCache(JobRequest request)
 {
     if (request != null)
     {
         lock (_SyncInstanceObject)
         {
             _JobReleaseCache.Add(request);
         }
     }
 }
Ejemplo n.º 3
0
        public JobRequest Clone()
        {
            JobRequest newJR = new JobRequest();

            newJR._Enable = this._Enable;
            newJR._MetadataFileNameList = new List <MetadataFile>(this._MetadataFileNameList);
            newJR._MetadataList         = new List <Metadata>(this._MetadataList);
            newJR.SubmitAsOneCall       = this.SubmitAsOneCall;
            newJR.NickName  = this.NickName;
            newJR.InputFile = this.InputFile;
            return(newJR);
        }
Ejemplo n.º 4
0
        public JobRequest GetNextJobFromReleaseCache()
        {
            JobRequest job = null;

            lock (_SyncInstanceObject)
            {
                if (_JobReleaseCache.Count > 0)
                {
                    job = _JobReleaseCache[0];
                    _JobReleaseCache.RemoveAt(0);
                }
            }
            return(job);
        }
Ejemplo n.º 5
0
        public void RemoveJobByJobIdFromWatchCache(Guid jobId)
        {
            JobRequest job = null;

            lock (_SyncInstanceObject)
            {
                if (_JobWatchCache.Count > 0)
                {
                    job = _JobWatchCache[jobId];
                    if (job != null)
                    {
                        _JobWatchCache.Remove(jobId);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public JobRequest GetJobByJobIdFromWatchCache(Guid jobId)
        {
            JobRequest job = null;

            lock (_SyncInstanceObject)
            {
                if (_JobWatchCache.Count > 0)
                {
                    if (_JobWatchCache.ContainsKey(jobId))
                    {
                        job = _JobWatchCache[jobId];
                        if (job != null)
                        {
                            _JobWatchCache.Remove(jobId);
                        }
                    }
                }
            }
            return(job);
        }
Ejemplo n.º 7
0
        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
                {
                }
            }
        }
Ejemplo n.º 8
0
        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
                {
                }
            }
        }
Ejemplo n.º 9
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
                {
                }
            }
        }