Exemplo n.º 1
0
        private void AddNode(Job job, string module, TreeNode inTreeNode)
        {
            TreeNode tNode;
            int i;

            IModule m = (IModule)job.Modules[module];
            IDependency<IModule> d = (IDependency<IModule>)job.Dependencies[module];

            // Loop through the XML nodes until the leaf is reached.
            // Add the nodes to the TreeView during the looping process.
            if (d.Children != null && d.Children.Count() > 0)
            {
                IDependencySet<IModule> dset = d.Children;
                for (i = 0; i <= dset.Count() - 1; i++)
                {
                    IDependency<IModule> child = dset[i];
                    inTreeNode.Nodes.Add(new TreeNode(child.Name));
                    tNode = inTreeNode.Nodes[i];
                    tNode.ContextMenuStrip = FormsManager.JobsMenu;
                    AddNode(job, child.Name, tNode);
                }
            }
            else
            {
                // Here you need to pull the data from the XmlNode based on the
                // type of node, whether attribute values are required, and so forth.
                //inTreeNode.Text = (inXmlNode.OuterXml).Trim();
            }
        }
Exemplo n.º 2
0
        public void Build(ref Job job)
        {
            PerfTimer hpt = new PerfTimer();
            hpt.Start();

            try
            {
                if (job.Modules.ContainsKey(job.JobName))
                {
                    root = new Dependency<IModule>((IModule)job.Modules[job.JobName], job.JobName);
                    job.Dependencies.Add(root.Name.Trim(), root);

                    foreach (string key in job.OrderedModuleList)
                    {
                        if (key.Equals(job.JobName))
                        {
                            continue;
                        }

                        IModule m = (IModule)job.Modules[key];
                        Dependency<IModule> d = new Dependency<IModule>(m, m.Name);

                        if (m.Inputs == null)
                        {
                            root.Children.AddDependency(d);
                            job.Dependencies.Add(d.Name.Trim(), d);
                        }
                        else
                        {
                            foreach (string s in m.Inputs)
                            {
                                if (job.Dependencies.ContainsKey(s.Trim()))
                                {
                                    ((Dependency<IModule>)job.Dependencies[s.Trim()]).Children.AddDependency(d);
                                }
                            }
                            job.Dependencies.Add(d.Name.Trim(), d);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

            hpt.Stop();
            log.InfoFormat("Building job {0} took {1} seconds.", job.JobName, hpt.Duration);
        }
Exemplo n.º 3
0
 internal JobExeWrapper(Job _job)
 {
     if (_job == null) throw new ArgumentNullException("_job");
     job = _job;
     jobGlobalState = _job.JobState;
 }
Exemplo n.º 4
0
        private ErrorCode ProcessJob(Job job, DateTime jobkey, JobExeWrapper jobWrapper)
        {
            ErrorCode retval = ErrorCode.SUCCESS;

            if (job.Dependencies.ContainsKey(job.JobName))
            {
                IDependency<IModule> dep = job.Dependencies[job.JobName] as IDependency<IModule>;
                retval = ProcessJobFromRoot(jobWrapper, jobkey, dep);

                UpdateJobDetailsForGui(jobWrapper, State.CurrentStateEnum.WaitState);
            }
            else
                log.WarnFormat("Root job dependency for {0} not found", job.JobName);

            return retval;
        }
Exemplo n.º 5
0
        private void LaunchJob(Object _jobWrapper)
        {
            PerfTimer hpt = new PerfTimer();
            hpt.Start();

            JobExeWrapper jobWrapper = _jobWrapper as JobExeWrapper;
            if (jobWrapper != null)
            {
                try
                {
                    lock (jobWrapper)
                    {
                        ((State)jobWrapper.JobGlobalState).SourceFileName = jobWrapper.SourceFileName;
                        DateTime jobkey = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        jobWrapper.StartTime = jobkey;
                        jobWrapper.Job.Key = jobkey;
                        jobWrapper.Job.KeyCode = String.Format("{0}{1}", jobWrapper.Job.JobName, jobkey).GetHashCode();
                        ((State)jobWrapper.JobGlobalState).HistoricalJobCode = jobkey;
                        if (jobKeyCodes.ContainsKey(jobWrapper.Job.JobName + "\\" + jobkey.ToString("yyyy-MM-dd HH:mm:ss")) == false)
                            jobKeyCodes.Add(jobWrapper.Job.JobName + "\\" + jobkey.ToString("yyyy-MM-dd HH:mm:ss"), jobWrapper.Job.KeyCode);

                        jobWrappers[jobWrapper.Job.JobName].HistoricalJobs[jobkey] = jobWrapper.Job;
                        jobsToResetState.Clear();

                        string[] jobWrapperStatesKeys = new string[jobWrapper.States.Keys.Count];
                        jobWrapper.States.Keys.CopyTo(jobWrapperStatesKeys, 0);
                        foreach (string job in jobWrapperStatesKeys)
                        {
                            lock (jobsWaitingForExecution)
                            {
                                if (jobWrapper.States[job] == State.CurrentStateEnum.WaitState)
                                {
                                    ((IModule)jobWrapper.Job.Modules[job]).Inputs = new string[] { jobWrapper.SourceFileName };

                                    if (!jobsWaitingForExecution.ContainsKey(job))
                                        jobsWaitingForExecution.Add(job, State.CurrentStateEnum.WaitState);
                                }
                                else if (jobWrapper.States[job] == State.CurrentStateEnum.ExecutionSuccessful)
                                    jobsToResetState.Add(job);
                            }
                        }

                        foreach (string _job in jobsToResetState)
                            jobWrapper.States[_job] = State.CurrentStateEnum.PendingExecution;
                        ((State)jobWrapper.JobGlobalState).CurrentState = State.CurrentStateEnum.Executing;

                        string[] waitStateJobs = new string[jobsWaitingForExecution.Count];
                        jobsWaitingForExecution.Keys.CopyTo(waitStateJobs, 0);
                        foreach (string _job in waitStateJobs)
                        {
                            if (jobsWaitingForExecution.ContainsKey(_job) && jobWrapper.States.ContainsKey(_job))
                            {
                                if (jobsWaitingForExecution[_job].Equals(State.CurrentStateEnum.WaitState))
                                {

                                    //skip suspended jobs
                                    if (guiJobStatus.ContainsKey(_job) && guiJobStatus[_job].Equals("Suspended"))
                                        continue;

                                    UpdateJobDetailsForGui(jobWrapper, State.CurrentStateEnum.Executing);

                                    ProcessJobFromRoot(jobWrapper, jobkey, ((IDependency<IModule>)jobWrapper.Job.Dependencies[_job]));

                                    jobWrapper.Job.ResetOutputs();

                                    UpdateJobDetailsForGui(jobWrapper, State.CurrentStateEnum.WaitState);
                                }
                            }
                        }

                        hpt.Stop();
                        jobWrapper.DurationSecs = hpt.Duration;

                        Job jobCopy = new Job(jobWrapper.Job);
                        jobWrappers[jobWrapper.Job.JobName].HistoricalJobs[jobkey] = jobCopy;
                        ((State)jobWrapper.JobGlobalState).CurrentState = State.CurrentStateEnum.WaitState;
                        if (jobWrapper.Job.JobDetails.RunOnce && jobWrapper.OkToRemove)
                        {
                            RemoveJob(jobWrapper.Job.JobName, false);
                        }

                        log.InfoFormat("Completed executing job {0} in {1} mode in {2} secs.", jobWrapper.Job.JobName, jobWrapper.Mode.ToString(), hpt.Duration);

                    }
                }
                catch (Exception ex)
                {
                    ThreadAbortException tex = ex as ThreadAbortException;
                    if (tex != null)
                        log.Error(tex);
                    else
                        log.Error(ex);
                }
            }
        }
Exemplo n.º 6
0
	    private ErrorCode ProcessJobFromRoot(JobExeWrapper jobWrapper, Job job, IDependency<IModule> dep)
		{
			ErrorCode returnCode = ErrorCode.SUCCESS;

			if (killJobs.Contains(job.JobName))
                killJobs.Remove(job.JobName);

			// pick enumeration type
			IEnumerator<IDependency<IModule>> iEnumerator =
				dep.GetBreadthFirstEnumerator(); //default mode

			//execution
            log.InfoFormat(job.KeyHash, "Beginning executing job {0} in {1} mode.", job.JobName, jobWrapper.DependencyState.ToString());

			ArrayList trackWaitState = new ArrayList();

            job.StartStats();
            iEnumerator = GetDependencyEnumerator(jobWrapper, dep, iEnumerator);
			while (iEnumerator.MoveNext())
			{
				IDependency<IModule> d = iEnumerator.Current;
				if (d.Name.Equals(job.JobName))
					continue;
				if (!jobWrapper.DependencyStates.ContainsKey(d.Name))
					jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.PendingInitialization;
			}

			iEnumerator = GetDependencyEnumerator(jobWrapper, dep, iEnumerator);
            while (iEnumerator.MoveNext() && returnCode.Equals(ErrorCode.ABORT_JOB) == false)
			{
				IDependency<IModule> d = iEnumerator.Current;

				if (killJobs.Contains(job.JobName))
				{
                    killJobs.Remove(job.JobName);
					ReenableJob(jobWrapper, trackWaitState, d);

                    log.WarnFormat(job.KeyHash, "Killing job {0} ", job.JobName);

					Thread.CurrentThread.Abort();
					break;
				}

                if (d.Name.Equals(job.JobName))
					continue;

                if ((jobWrapper.DependencyState.Equals(StateEnums.ExecutionMode.Initialization) &&
						!jobWrapper.DependencyStates[d.Name].Equals(StateEnums.ExecutionState.InitializationSuccessful)) ||
                     (jobWrapper.DependencyState.Equals(StateEnums.ExecutionMode.Execution) &&
						!jobWrapper.DependencyStates[d.Name].Equals(StateEnums.ExecutionState.ExecutionSuccessful) &&
						!jobWrapper.Job.Limiter.ifWaitingForFirstTrigger))
				{

					bool ifAllParentsAreReady = true;
					foreach (IDependency<IModule> dParent in d.Parents)
					{
						if (!dParent.Name.Equals(jobWrapper.Job.JobName))
						{
                            if (jobWrapper.DependencyState == StateEnums.ExecutionMode.Initialization)
							{
								if (!jobWrapper.DependencyStates[dParent.Name].Equals(StateEnums.ExecutionState.WaitState) &&
									!jobWrapper.DependencyStates[dParent.Name].Equals(StateEnums.ExecutionState.InitializationSuccessful))
								{
									ifAllParentsAreReady = false;
									break;
								}
							}
                            else if (jobWrapper.DependencyState == StateEnums.ExecutionMode.Execution)
							{
								if (!jobWrapper.DependencyStates[dParent.Name].Equals(StateEnums.ExecutionState.WaitState) &&
									!jobWrapper.DependencyStates[dParent.Name].Equals(StateEnums.ExecutionState.ExecutionSuccessful))
								{
									ifAllParentsAreReady = false;
									break;
								}
							}
						}
					}

					if (ifAllParentsAreReady)
					{
                        #region Status Update
                        if (jobWrapper.DependencyState.Equals(StateEnums.ExecutionMode.Initialization))
                            job.JobState.CurrentStatusCollection[d.Name].Status = StateEnums.Status.Initializing;
                        else
                        {
                            job.JobState.CurrentStatusCollection[d.Name].Status = StateEnums.Status.Running;
                            //Required for UpdateStatus (Dashboard)
                            job.JobState.CurrentStatusCollection[d.Name].StartTime = DateTime.Now;
                        }

                        OnStatusEvent(job);
                        #endregion

                        //Begin dependency/module processing...
						StateEnums.Status result = ProcessDependency(jobWrapper, job, d);

                        #region Status Update
                        switch (result)
                        {
                            #region Normal Cases
                            case StateEnums.Status.Success:
                                if (jobWrapper.DependencyState.Equals(StateEnums.ExecutionMode.Initialization))
                                    jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.InitializationSuccessful;
                                else
                                {
                                    jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.ExecutionSuccessful;
                                    job.JobState.CurrentStatusCollection[d.Name].EndTime = DateTime.Now;
                                }
                                job.JobState.CurrentStatusCollection[d.Name].Status = StateEnums.Status.Success;
                                break;
                            case StateEnums.Status.WaitingForSqlNotification:
                                jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.WaitState;
                                job.JobState.CurrentStatusCollection[d.Name].Status = StateEnums.Status.WaitingForSqlNotification;
                                break;
                            case StateEnums.Status.WaitingForFile:
                                jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.WaitState;
                                job.JobState.CurrentStatusCollection[d.Name].Status = StateEnums.Status.WaitingForFile;
                                break;
                            #endregion

                            #region Abnormal Cases
                            case StateEnums.Status.Warnings:
                                if (jobWrapper.DependencyState.Equals(StateEnums.ExecutionMode.Initialization))
                                    jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.InitializationSuccessful;
                                else
                                {
                                    jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.ExecutionSuccessful;
                                    job.JobState.CurrentStatusCollection[d.Name].EndTime = DateTime.Now;
                                }
                                job.JobState.CurrentStatusCollection[d.Name].Status = StateEnums.Status.Warnings;
                                break;
                            case StateEnums.Status.Error:
                                if (jobWrapper.DependencyState.Equals(StateEnums.ExecutionMode.Initialization))
                                    jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.InitializationSuccessful;
                                else
                                {
                                    //jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.ExecutionSuccessful;
                                    jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.ExecutionFailed;
                                    job.JobState.CurrentStatusCollection[d.Name].EndTime = DateTime.Now;
                                }
                                job.JobState.CurrentStatusCollection[d.Name].Status = StateEnums.Status.Error;
                                returnCode = ErrorCode.ABORT_JOB;
                                break;
                            default:
                                if (jobWrapper.DependencyState.Equals(StateEnums.ExecutionMode.Initialization))
                                    jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.InitializationSuccessful;
                                else
                                {
                                    jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.ExecutionSuccessful;
                                    job.JobState.CurrentStatusCollection[d.Name].EndTime = DateTime.Now;
                                }
                                job.JobState.CurrentStatusCollection[d.Name].Status = StateEnums.Status.Error;
                                returnCode = ErrorCode.MODULE_FAILED;
                                break;
                            #endregion
                        }
                        OnStatusEvent(job);
                        #endregion

                        if ( !returnCode.Equals(ErrorCode.ABORT_JOB))
							ReenableJob(jobWrapper, trackWaitState, d);

						log.DebugFormat(job.KeyHash,"Processed {0}", d.ToString());
					}
				}
			}
            job.StopStats();

			foreach (string jobName in trackWaitState)
			{
                if (jobWrapper.DependencyStates.ContainsKey(jobName))
                    jobWrapper.DependencyStates[jobName] = StateEnums.ExecutionState.WaitState;
			}

            return returnCode;
		}
Exemplo n.º 7
0
        private void LaunchJob(Object _jobWrapper)
        {
            JobExeWrapper jobWrapper = _jobWrapper as JobExeWrapper;
            if (jobWrapper == null)
            {
                //early return
                log.ErrorFormat("Tried LaunchJob with null job wrapper.");
                return;
            }

            //ensure that the job is fully initialized before executing
            if ( !jobWrapper.IsInititalized && jobWrapper.DependencyState.Equals(StateEnums.ExecutionMode.Execution))
            {
                //throw error if not initialized (Timer Service and File Service should prevent non-initialized jobs from being launched 
                //in execute mode)
                log.ErrorFormat(jobWrapper.Job.KeyHash, "Unable to initialize job for execution.  " +
                                                        "" +
                                                        "Aborting execution.");
                foreach( string s in jobWrapper.DependencyStates.Keys)
                {
                    log.DebugFormat("Module: {0}\t\tState: {1}", s, jobWrapper.DependencyStates[s]);
                }
                return;
            }

            try
            {
                lock (jobWrapper)
                {
                    //  Make a copy of the Job from the JobWrapper's job
                    Job job = new Job(jobWrapper.Job);
                    job.Key = DateTime.Now;
                    job.JobState.CurrentJobCode = job.Key;
                    job.JobState.CurrentJobHash = job.KeyHash;

                    // bubble up key info to jobwrapper global state
                    ((State)jobWrapper.JobGlobalState).CurrentJobCode = job.Key;
                    ((State)jobWrapper.JobGlobalState).CurrentJobHash = job.KeyHash;

                    //update global list of job keys
                    if (jobKeyCodes.ContainsKey(job.KeyString)==false)
                        jobKeyCodes.Add(job.KeyString, job.KeyHash);                    

                    // Set the values for the Dynamic Parameters (ie the RunTime metatags)
                    MetaTagReplacerInputDates inputDates = new MetaTagReplacerInputDates(DateTime.Now);
                    if (!string.IsNullOrEmpty(job.JobDetails.InDate))
                    {
                        DateTime jobProcessDate = DateTime.MinValue;
                        string jobInDate = MetaTagReplacer.GetMetaTagValue(job.JobDetails.InDate, inputDates, null);
                        
                        if (jobInDate == null)
                            jobInDate = job.JobDetails.InDate;

                        if (DateTime.TryParse(jobInDate, out jobProcessDate))
                            inputDates = new MetaTagReplacerInputDates(jobProcessDate);
                    }
                    job.JobState.CurrentParameters.ProcessInputDates = inputDates;
                    PropertyBag jobParameters = job.JobState.CurrentParameters.CurrentParameters;
                    MetaTagReplacer.SetParametersValuesPB(ref jobParameters, ConfigUtils.MetatagMode.All, inputDates, new object[] { job.JobState });
                    JobImpl.SetModulesRunTimeParameters(job, false);
                    JobImpl.InitializeBusData(job, ((State)jobWrapper.JobGlobalState).StartupBusData);

                    //MetaTagReplacerInputDates inputDates = new MetaTagReplacerInputDates(DateTime.Now);
                    //jobWrapper.Job.JobState.CurrentParameters.ProcessInputDates = inputDates;
                    //PropertyBag jobParameters = jobWrapper.Job.JobState.CurrentParameters.CurrentParameters;
                    //MetaTagReplacer.SetParametersValuesPB(ref jobParameters, ConfigUtils.MetatagMode.All, inputDates);
                    //JobImpl.SetModulesRunTimeParameters(jobWrapper.Job);

                    // add the new copy to the Historical job instances.  
                    jobWrappers[jobWrapper.Job.JobName].HistoricalJobs[job.Key] = job;                  

                    // prepare to run the job instance
                    jobsToResetState.Clear();
                    string[] jobWrapperStatesKeys = new string[jobWrapper.DependencyStates.Keys.Count];

                    jobWrapper.DependencyStates.Keys.CopyTo(jobWrapperStatesKeys, 0);
                    foreach (string key in jobWrapperStatesKeys)
                    {
                        lock (jobsWaitingForExecution)
                        {
                            if (jobWrapper.DependencyStates[key] == StateEnums.ExecutionState.WaitState)
                            {
                                //  TODO Introduce this when exposing WCF interface
                                //((IModule)jobWrapper.Job.Modules[key]).Inputs = new string[] { ((State)jobWrapper.JobGlobalState).SourceFileName };

                                if (!jobsWaitingForExecution.ContainsKey(key))
                                    jobsWaitingForExecution.Add(key, StateEnums.ExecutionState.WaitState);
                            }
                            else if (jobWrapper.DependencyStates[key] == StateEnums.ExecutionState.ExecutionSuccessful)
                                jobsToResetState.Add(key);
                        }
                    }

                    foreach (string _jobname in jobsToResetState)
                        jobWrapper.DependencyStates[_jobname] = StateEnums.ExecutionState.PendingExecution;
                    ((State) jobWrapper.JobGlobalState).ExecutionState = StateEnums.ExecutionState.Executing;

                    string[] waitStateJobs = new string[jobsWaitingForExecution.Count];
                    jobsWaitingForExecution.Keys.CopyTo(waitStateJobs, 0);
                    foreach (string _jobname in waitStateJobs)
                    {
                        if (jobsWaitingForExecution.ContainsKey(_jobname) && jobWrapper.DependencyStates.ContainsKey(_jobname))
                        {
                            if (jobsWaitingForExecution[_jobname].Equals(StateEnums.ExecutionState.WaitState))
                            {

                                //skip suspended jobs
                                if (guiJobStatus.ContainsKey(_jobname) && guiJobStatus[_jobname].Equals(StateEnums.Status.Suspended))
                                    continue;

                                //ProcessJobFromRoot(jobWrapper, ((IDependency<IModule>)jobWrapper.Job.Dependencies[_jobname]));
                                //Attempt alotted number of retries should the job failed with Abort return code
                                //ProcessJobFromRoot(jobWrapper, job, ((IDependency<IModule>)jobWrapper.Job.Dependencies[_jobname]));
                                int max_retries = job.JobDetails.MaxRetries;
                                int num_retries = 0;
                                while (num_retries < max_retries)
                                {
                                    ErrorCode returnCode = ProcessJobFromRoot(jobWrapper, job, ((IDependency<IModule>)jobWrapper.Job.Dependencies[_jobname]));
                                    if (returnCode != ErrorCode.ABORT_JOB)
                                        break;
                                    else
                                    {
                                        System.Threading.Thread.Sleep(job.JobDetails.DelayBetweenRetries);
                                        if (job.JobDetails.RetryFromTop)
                                        {
                                            IDependency<IModule> dep = (IDependency<IModule>) jobWrapper.Job.Dependencies[_jobname];
                                            IEnumerator<IDependency<IModule>> iEnumerator = GetDependencyEnumerator(jobWrapper, dep, dep.GetBreadthFirstEnumerator());
                                            while (iEnumerator.MoveNext())
                                            {
                                                IDependency<IModule> d = iEnumerator.Current;
                                                if (!d.Name.Equals(job.JobName))
                                                    jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.PendingExecution;
                                            }
                                        }
                                        num_retries++;
                                        if ((max_retries - num_retries) > 0)
                                            log.ErrorFormat(job.KeyHash,"Job {0}, ID {1} failed due to critical error. Will try to run {2} more times.", job.JobName, job.KeyHash, (max_retries - num_retries));
                                        else
										{
                                            log.ErrorFormat(job.KeyHash,"Job {0}, ID {1} failed due to critical error and is aborted with no retries left.", job.JobName, job.KeyHash);
                                            log.ErrorFormat(job.KeyHash,"Completed executing job {0}, failed due to critical error and is aborted with no retries left.", job.JobName);
										}
                                    }
                                }

                                //((Job)jobWrapper.HistoricalJobs[jobkey]).ResetOutputs();
                                job.ResetOutputs();
                                UpdateJobDetailsForGui(job);
                            }
                        }
                    }

                    ((State) jobWrapper.JobGlobalState).ExecutionState = StateEnums.ExecutionState.WaitState;
                    if (jobWrapper.Job.JobDetails.RunOnce && jobWrapper.OkToRemove)
                    {
                        RemoveJob(job.JobName, false);
                    }

                    log.InfoFormat(job.KeyHash,"Completed executing job {0} in {1} mode in {2} secs.", job.JobName, jobWrapper.DependencyState.ToString(), jobWrapper.Job.JobStats.Duration);

                    if (job.JobDetails.RunOnce)
                        ((State)jobWrapper.JobGlobalState).ExecutionState = StateEnums.ExecutionState.Complete;
                        
                    //job.JobState.ExecutionState = StateEnums.ExecutionState.Complete;
                    //ExecuteJobCallback ejb = new ExecuteJobCallback(ProcessJobCallback);
                    //ejb.BeginInvoke(job, null, null);
                }
            }
            catch (Exception ex)
            {
                ThreadAbortException tex = ex as ThreadAbortException;
                if (tex != null)
                    log.Error(tex);
                else
                    log.Error(ex);
            }
        }
Exemplo n.º 8
0
        private void UpdateJobStatus(Job job)
        {
            try
            {
                UpdateJobDetailsForGui(job);


                Hashtable ht = new Hashtable();
                ht["Date"] = DateTime.Now.Date;
                ht["JobName"] = job.JobName.Replace("_Job", "");

                if (job.JobState.CurrentDependency != null)
                    ht["ModuleName"] = job.JobState.CurrentDependency.Module.Name;
                else
                    ht["ModuleName"] = DBNull.Value;

                if (!job.JobState.CurrentJobCode.Equals(DateTime.MinValue))
                    ht["HistoricalJobKey"] = job.JobState.CurrentJobCode;
                else
                    ht["HistoricalJobKey"] = DBNull.Value;

                ht["JobKeyCode"] = job.JobState.CurrentJobHash;

                if (!String.IsNullOrEmpty(job.JobState.SourceFileName))
                    ht["SourceFile"] = job.JobState.SourceFileName;
                else
                    ht["SourceFile"] = DBNull.Value;

                ht["ProcessId"] = DBNull.Value;
                ht["ScheduleId"] = DBNull.Value;
                ht["StatusId"] = job.JobState.CurrentStatus;

                if (job.JobState.CurrentDependency != null &&
                    !job.JobState.CurrentStatusCollection[job.JobState.CurrentDependency.Module.Name].StartTime.Equals(DateTime.MinValue))
                    ht["StartTime"] = job.JobState.CurrentStatusCollection[job.JobState.CurrentDependency.Module.Name].StartTime;
                else
                    ht["StartTime"] = DBNull.Value;

                if (job.JobState.CurrentDependency != null &&
                    !job.JobState.CurrentStatusCollection[job.JobState.CurrentDependency.Module.Name].EndTime.Equals(DateTime.MinValue))
                    ht["EndTime"] = job.JobState.CurrentStatusCollection[job.JobState.CurrentDependency.Module.Name].EndTime;
                else
                    ht["EndTime"] = DBNull.Value;

                Repository.GetRepository("Dashboard").ExecuteScalar("Dashboard.UpdateJobStatus", ht);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
Exemplo n.º 9
0
 private void OnStatusEvent(Job job)
 {
     if (StatusEvent != null)
         StatusEvent(job);
 }
Exemplo n.º 10
0
        private void UpdateJobDetailsForGui(Job job)
        {
            lock (guiJobStatus)
            {
                if (guiJobStatus.ContainsKey(job.JobName) == false)
                    guiJobStatus.Add(job.JobName, job.JobState.CurrentStatus);
                else
                    guiJobStatus[job.JobName] = job.JobState.CurrentStatus;

                if (guiJobHistories.ContainsKey(job.JobName) == false)
                    guiJobHistories.Add(job.JobName, new Dictionary<DateTime, StateEnums.Status>());

                guiJobHistories[job.JobName][job.Key] = job.JobState.CurrentStatus;
            }
		}
Exemplo n.º 11
0
        private StateEnums.Status ProcessDependency(JobExeWrapper jobWrapper, Job job, IDependency<IModule> d)
        {
            log.DebugFormat(job.KeyHash,"Considering dependency {0}-[{1}] for {2}.", job.JobName, d.Name, jobWrapper.DependencyState.ToString());
            StateEnums.Status retval = StateEnums.Status.Unknown;

            if (((State)jobWrapper.JobGlobalState).ExecutionState.CompareTo(StateEnums.ExecutionState.Suspended) == 0)
                return 0;

            job.JobState.CurrentDependency = d; //Required for status updates

            log.DebugFormat(job.KeyHash,"Starting {2}: {0}-[{1}].", job.JobName, d.Name, jobWrapper.DependencyState);
            switch (jobWrapper.DependencyState)
            {
                case StateEnums.ExecutionMode.Initialization:

                    try
                    {
                        jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.Initializing;
                        retval = d.Module.Initialize(job as IJob, flatFileLoader, timeManager, datamonitorManager);
                    }
                    catch (Exception ex)
                    {
                        log.ErrorFormat(job.KeyHash,"Module Initialization Error: {0}", ex.Message);
						log.Error(job.KeyHash, ex);
						retval = StateEnums.Status.Error;
                    }

                    switch (retval)
                    {
                        case StateEnums.Status.Success:
                            jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.InitializationSuccessful;
                            break;
                        case StateEnums.Status.WaitingForSqlNotification:
                        case StateEnums.Status.WaitingForFile:
                            jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.WaitState;
                            break;
                        default:
                            jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.InitializationFailed;
                            break;
                    }
                    break;

                case StateEnums.ExecutionMode.Execution:

                    log.DebugFormat(job.KeyHash,"Starting {2} on {0}-[{1}].", job.JobName, d.Name, jobWrapper.DependencyState.ToString());

                    try
                    {
                        jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.Executing;
                        if (d.Name == job.JobName) break;

                        //job.de

                        // Handle data bus (pass all objects along to next dependency)
                        // and add the outputdata from Initial Bus Data
                        Hashtable inputData = new Hashtable();
                        if (d.Module.OutputData != null && d.Module.OutputData.Count > 0)
                            foreach (string key in d.Module.OutputData.Keys)
                                inputData[key] = d.Module.OutputData[key];

                        Hashtable outputData = new Hashtable();
                        if (d.Module.Inputs != null && d.Parents != null)
                        {
                            foreach (IDependency<IModule> p in d.Parents)
                            {
                                // add the outputdata from parent modules running in this instance
                                outputData = ((IModule)jobWrapper.HistoricalJobs[job.Key].Modules[p.Module.Name]).OutputData;
                                foreach (string key in outputData.Keys)
                                    inputData[key] = outputData[key];
                            }
                        }

                        inputData["JobStatsSummary"] = String.Format("Job: {0} [{1}] <br># Modules: {2}<br>Duration: {3} secs",
                                                       job.JobName,
                                                       job.Key,
                                                       job.JobStats.ModuleCount,
                                                       job.JobStats.Duration.ToString("#.000"));

                        //  THIS IS THE MAIN [ONLY!] ENTRY POINT TO MODULE EXECUTION
                        retval = d.Module.Execute(this, job.JobState, inputData);

                    }
                    catch (Exception ex)
                    {
                        log.ErrorFormat(job.KeyHash, "Module Execution Error: {0}", ex);
                        retval = StateEnums.Status.Error;
                    }
                    finally
                    {
                        //log.InfoFormat(job.KeyHash, "Completed {0}: {1}:{2}", jobWrapper.DependencyState.ToString(), job.JobName, d.Name);

                        ((IModule)jobWrapper.HistoricalJobs[job.Key].Modules[d.Module.Name]).OutputData = d.Module.OutputData;

                        if (jobsWaitingForExecution.ContainsKey(d.Name))
                            if (d.Parents[0].Parents.Count != 0)
                                jobsWaitingForExecution.Remove(d.Name);
                            else
                                jobWrapper.DependencyStates[d.Name] = StateEnums.ExecutionState.WaitState; //importatn; reset job back to wait state

                        jobWrapper.Job.Modules[d.Name] = d.Module as IModule;
                    }

                    break;
            }
            log.InfoFormat(job.KeyHash,"Completed {0}: {1}:{2}", jobWrapper.DependencyState.ToString(), job.JobName, d.Name);
            return retval;
        }
Exemplo n.º 12
0
        public static Job BuildJobFromXml(JobDetails detail)
        {
            Job job = null;

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(detail.Xml);

                XmlNode jobNode = doc.SelectSingleNode("Job");

                if (jobNode.Attributes["isHistoricalMode"] != null)
                    detail.IsHistoricalMode = Convert.ToBoolean(jobNode.Attributes["isHistoricalMode"].Value);

                if (jobNode.Attributes["ifWaitingForFirstTrigger"] != null)
                    detail.IfWaitingForFirstTrigger = Convert.ToBoolean(jobNode.Attributes["ifWaitingForFirstTrigger"].Value);

                if (jobNode.Attributes["skipTodayIfPassed"] != null)
                    detail.SkipTodayIfPassed = Convert.ToBoolean(jobNode.Attributes["skipTodayIfPassed"].Value);

                if (jobNode.Attributes["runOnce"] != null)
                    detail.RunOnce = Convert.ToBoolean(jobNode.Attributes["runOnce"].Value);

                if (jobNode.Attributes["limitTrigger"] != null)
                {
                    detail.UserLimit = Convert.ToInt32(jobNode.Attributes["limitTrigger"].Value);
                }

                if (jobNode.Attributes["inDate"] != null || jobNode.Attributes["runDate"] != null)
                {
                    if (jobNode.Attributes["inDate"] != null)
                        detail.InDate = Convert.ToString(jobNode.Attributes["inDate"].Value);
                    else if (jobNode.Attributes["runDate"] != null)
                        detail.InDate = Convert.ToString(jobNode.Attributes["runDate"].Value);
                }

                if (jobNode.Attributes["MaxRetries"] != null)
                    detail.MaxRetries = Convert.ToInt32(jobNode.Attributes["MaxRetries"].Value);
                if (jobNode.Attributes["DelayBetweenRetries"] != null)
                    detail.DelayBetweenRetries = Convert.ToInt32(jobNode.Attributes["DelayBetweenRetries"].Value);
                if (jobNode.Attributes["RetryFromTop"] != null)
                    detail.RetryFromTop = Convert.ToBoolean(jobNode.Attributes["RetryFromTop"].Value);

                job = new Job(
                    jobNode.Attributes["name"].Value.ToString().Trim(),
                    jobNode.Attributes["dependencyTraversalMode"].Value.ToString().Trim(),
                    detail,
                    ConfigUtils.GlobalConfig);

                IModule root = BuildModule(job.JobName, "NullModule");

                job.Modules.Add(root.Name.Trim(), root);

                XmlNodeList modules = doc.SelectNodes("Job/Module");
                foreach (XmlNode moduleNode in modules)
                {
                    string moduleTypeName = moduleNode.Attributes["moduleType"].Value.ToString();

                    PropertyBag moduleOriginalPropertyValues = new PropertyBag();
                    IModule module = BuildModule(moduleNode, moduleTypeName, moduleOriginalPropertyValues);
                    job.OrderedModuleList.Add(module.Name);

                    if (job.Modules.ContainsKey(module.Name))
                        job.Modules.Remove(module.Name);
                    job.Modules.Add(module.Name, module);
                    job.JobState.CurrentParameters.SetOriginalModulePropertyValuesPB(module.Name, moduleOriginalPropertyValues);
                    job.JobState.CurrentStatusCollection.Add(module.Name, new DependencyStatus());

                    log.DebugFormat("Job {0}: Instantiated module {1}", job.JobName, moduleNode.Attributes["name"].Value.ToString());
                }

                DependencyEngine dsb = new DependencyEngine();
                dsb.Build(ref job);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
            return job;
        }
Exemplo n.º 13
0
        public static void InitializeBusData(Job job, InitialBusData initialBusData)
        {
            //Clear cached module output before infusion of initial bus and (later on) carry over of the module 
            //output to downstream dependant moduiles
            foreach (object moduleName in job.OrderedModuleList)
            {
                IModule module = job.Modules[moduleName.ToString()] as IModule;
                if (module != null)
                    module.OutputData.Clear();
            }

            foreach (string moduleName in initialBusData.BusData.Names)
            {
                if (!job.OrderedModuleList.Contains(moduleName))
                {
                    //log.WarnFormat("Cannot initialize job's bus data.  {0} {1} not found.", job.JobName, moduleName);
                    log.WarnFormat(job.JobState.CurrentJobHash, "Cannot initialize job's bus data.  {0} {1} not found.", job.JobName, moduleName);
                    continue;
                }

                IModule module = job.Modules[moduleName.ToString()] as IModule;
                if (module != null)
                {
                    if (module.OutputData.ContainsKey(moduleName))
                        module.OutputData.Remove(moduleName);
                    module.OutputData.Add(moduleName, initialBusData.BusData[moduleName]);
                    //log.InfoFormat("Added initial bus data to {0} {1}.", job.JobName, moduleName);
                    log.InfoFormat(job.JobState.CurrentJobHash, "Added initial bus data to {0} {1}.", job.JobName, moduleName);
                }
            }
        }
Exemplo n.º 14
0
        public static void SetModulesRunTimeParameters(Job job, bool historicalRun)
        {
            PropertyBag currentJobParameters = job.JobState.CurrentParameters.CurrentParameters;

            //This collection is to contain binding between Meta Tag and module to render "ModuleOutputAdded" event ("Donor");
            Dictionary<string, object> moduleOutputEventBindings = job.JobState.CurrentParameters.ModuleOutputEventDonors;  //new Dictionary<string, object>();
            //This collection is to contain EventHandlers that will be fired by Donors and update some Module Propery ("Consumers");
            Dictionary<string, EventHandler> moduleOutputEventRecepients = job.JobState.CurrentParameters.ModuleOutputEventConsumers;

            //New Job launch - erase module level dynamic parameters overrides
            if (!historicalRun)
                job.JobState.CurrentParameters.ClearOverrideParameters();

            foreach (object moduleName in job.OrderedModuleList)
            {
                IModule module = job.Modules[moduleName.ToString()] as IModule;
                if (module != null)
                {
                    PropertyBag propertyOriginalValues = job.JobState.CurrentParameters.GetOriginalModulePropertyValuesPB(moduleName.ToString());
                    PropertyInfo[] pis = module.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
                    MetaTagReplacerInputDates moduleInDatesOverride = null;
                    //
                    if (historicalRun)
                    {
                        //Use module parameters overrides preserved with job historical instance
                        moduleInDatesOverride = job.JobState.CurrentParameters.GetModuleInDatesOverride(module.Name);
                    }
                    else
                    {
                        //Check for special case of RunDate property which enforces module-level dates override
                        //if (!string.IsNullOrEmpty(module.RunDate))
                        string runDateOriginalValue = propertyOriginalValues["RunDate"] as string;
                        if (!string.IsNullOrEmpty(runDateOriginalValue))
                        {
                            //Create a module level meta tag overrides based on module's InDate meta tag 
                            DateTime moduleProcessDate = DateTime.MinValue;
                            //string moduleInDate = MetaTagReplacer.GetMetaTagValue(module.RunDate,
                            //                                                                                             job.JobState.CurrentParameters.ProcessInputDates,
                            //                                                                                             null);
                            string moduleInDate = MetaTagReplacer.GetMetaTagValue(runDateOriginalValue,
                                                                                                                         job.JobState.CurrentParameters.ProcessInputDates,
                                                                                                                         null);
                            if (!string.IsNullOrEmpty(moduleInDate))
                            {
                                if (DateTime.TryParse(moduleInDate, out moduleProcessDate))
                                {
                                    module.RunDate = moduleInDate;
                                    moduleInDatesOverride = new MetaTagReplacerInputDates(moduleProcessDate);
                                    job.JobState.CurrentParameters.SetModuleInDatesOverride(module.Name, moduleInDatesOverride);
                                    log.InfoFormat(job.JobState.CurrentJobHash, "Job {0}, Module {1}: Property RunDate was set to run-time value <{2}> from <{3}> and will be used to compute module-level overrides",
                                                   job.JobName, module.Name, moduleInDate, runDateOriginalValue);
                                }
                            }
                        }
                    }
                    //
                    if (pis.Length > 0 && propertyOriginalValues.Count() > 0 && currentJobParameters.Count() > 0)
                    {
                        foreach (PropertyInfo pi in pis)
                        {
                            #region  Metatag replacement/assignment

                            string propOriginalValue = propertyOriginalValues[pi.Name] as string;
                            if (
                                    propOriginalValue != null
                                    &&
                                    !pi.Name.Equals("RunDate") //Exclude special case of RunDate since it is already populated
                                )
                            {
                                string propValue = propOriginalValue;
                                PropertyBag modulePropertyPB = currentJobParameters;
                                //PropertyBag modulePropertyPBOverride = new PropertyBag();
                                bool forceSetPropertyValueToOriginal = false;

                                if (historicalRun)
                                {
                                    //Use module parameters overrides preserved with job historical instance
                                    //modulePropertyPBOverride = job.JobState.CurrentParameters.GetModulePropertyOverridesPB(module.Name, pi.Name);
                                    modulePropertyPB = job.JobState.CurrentParameters.GetModulePropertyOverridesPB(module.Name, pi.Name);
                                    if (modulePropertyPB == null)
                                        modulePropertyPB = currentJobParameters;
                                }
                                else
                                {
                                    if (moduleInDatesOverride != null)
                                    {
                                        //use this module's RunDate (e.g. process date) parameter to override ALL job-level meta tags
                                        modulePropertyPB = MetaTagReplacer.GetJobParametersPB(string.Format("{0}_ {1}_{2}_MetaTagOverride", job.JobName, module.Name, pi.Name),
                                                                                                                                         propOriginalValue);
                                        if (modulePropertyPB.Count() > 0)
                                        {
                                            if (MetaTagReplacer.SetParametersValuesPB(ref modulePropertyPB,
                                                                                                                        ConfigUtils.MetatagMode.All,
                                                                                                                        moduleInDatesOverride,
                                                                                                                        new object[] { module }))
                                                job.JobState.CurrentParameters.SetModulePropertyOverridesPB(module.Name, pi.Name, modulePropertyPB);
                                        }
                                    }
                                    else
                                    {
                                        PropertyBag modulePropertyPBOverride = MetaTagReplacer.GetJobParametersPB(string.Format("{0}_ {1}_{2}_MetaTagOverride", job.JobName, module.Name, pi.Name),
                                                                                                                                         propOriginalValue);
                                        //Remove MetaTags that have not been filled by Job level replacement
                                        foreach (string mtKey in modulePropertyPB.Names)
                                        {
                                            if (modulePropertyPB[mtKey] != null && modulePropertyPBOverride.Contains(mtKey))
                                                modulePropertyPBOverride.Remove(mtKey);
                                        }
                                        //Fill the remainder of MT values
                                        if (modulePropertyPBOverride.Count() > 0)
                                        {
                                            //If there are meta tags in Original property value always force reset
                                            //as otherwise if MT function return 'null' property may contain stale value
                                            //if as result of replacement new property value equials original
                                            forceSetPropertyValueToOriginal = true; 
                                            MetaTagReplacer.SetParametersValuesPB(ref modulePropertyPBOverride,
                                                                                                                        ConfigUtils.MetatagMode.All,
                                                                                                                        job.JobState.CurrentParameters.ProcessInputDates,
                                                                                                                        new object[] { module, pi.Name, moduleOutputEventBindings, moduleOutputEventRecepients });
                                            //job.JobState.CurrentParameters.SetModulePropertyOverridesPB(module.Name, pi.Name, modulePropertyPBOverride);
                                            //Put these module-property-metatag values back into main job-level PropertyBag
                                            //to be potentiall referred by other modules
                                            foreach (string mtKey in modulePropertyPBOverride.Names)
                                            {
                                                if (modulePropertyPBOverride[mtKey] != null && modulePropertyPB.Contains(mtKey))
                                                    modulePropertyPB[mtKey] = modulePropertyPBOverride[mtKey];
                                            }
                                        }
                                    }
                                }

                                //Replace meta tags using finalized property bag
                                propValue = MetaTagReplacer.InlineMetatagSubstitution(propOriginalValue, modulePropertyPB);
                                //
                                if (propValue.CompareTo(propOriginalValue) != 0 || forceSetPropertyValueToOriginal)
                                {
                                    if (SetModulePropertyValueFromString(module, pi, propValue))
                                    {
                                        log.InfoFormat(job.JobState.CurrentJobHash, "Job {0}, Module {1}: Set property {2} to run-time value <{3}> from original <{4}>",
                                                       job.JobName, module.Name, pi.Name, propValue, propOriginalValue);
                                    }
                                    else
                                    {
                                        log.WarnFormat(job.JobState.CurrentJobHash, "Job {0}, Module {1}: Unable to set Property {2} to run-time value {3}",
                                                       job.JobName, module.Name, pi.Name, propValue);
                                    }
                                }
                            }
                            #endregion

                            #region Folder Override

                            SetModulePropertyValueRunTimeProtections(module, pi);

                            #endregion
                        }
                    }
                }
            }
        }
Exemplo n.º 15
0
        public Job(Job oJob)
        {
            key = oJob.key;
            jobName = oJob.jobName;
            dependencyTraversalMode = oJob.dependencyTraversalMode;

            jobStats = new JobStats(this);
            jobDetails = oJob.jobDetails;
            jobState = new State(oJob.JobState);

            config = oJob.config;
            arrModules = oJob.arrModules;
            modules = oJob.modules;
            dependencies = oJob.dependencies;
            limiter = oJob.limiter;
        }
Exemplo n.º 16
0
 public JobStats(Job _job)
 {
     moduleCount = _job.Modules.Count;
 }