Ejemplo n.º 1
0
        public ITimeManager Start(string[] args, GlobalConfigDetails _globalConfig)
        {
            globalConfig = _globalConfig;

            PerfTimer hptStartup = new PerfTimer();
            hptStartup.Start();

            #region Configuration section

            log.Info("Reading configuration for Time Manager service.");

            log.Info("Reading configuration done");

            #endregion

            log.Info("Starting BITS Time Manager service");

            this.CanStop = true;
            this.CanShutdown = true;
            TimeManager.InstanceOf(globalConfig).Start();

            hptStartup.Stop();
            log.InfoFormat("BITS Time Manager has started in {0} seconds.", hptStartup.Duration);

            return TimeManager.InstanceOf();
        }
Ejemplo n.º 2
0
        public bool Start(string[] args, IFlatFileLoader _flatFileLoader, ITimeManager _timeManager, IDataMonitorManager _sqldManager)
        {
            PerfTimer hptStartup = new PerfTimer();
            hptStartup.Start();

            flatFileLoader = _flatFileLoader;
            timeManager = _timeManager;
            dmManager = _sqldManager;

            this.CanStop = true;
            this.CanShutdown = true;

            log.Info("Starting BITS State Manager service...");

            log.Info("Establishing connection to NB service...");
            if (ExecutionEngine.InstanceOf().EstablishBrokerConnections() == false)
            {
                log.Error("Cannot connect to NB service.  Quitting...");
                return false;
            }

            log.Info("Creating Module Factory instance...");
            ModuleFactory mFactory = new ModuleFactory();

            log.Info("Starting to load Module type definitions...");
            LoadAdapters();
            //AutoLoadAdapters(AppDomain.CurrentDomain.BaseDirectory + "modules");

            log.Info("Looking for startup jobs to build...");
            ExecuteStartupJobs();

            hptStartup.Stop();
            log.InfoFormat("BITS State Manager service has started in {0} seconds.", hptStartup.Duration);
            return true;
        }
Ejemplo n.º 3
0
 public ModuleFactory()
 {
     PerfTimer hpt = new PerfTimer();
     hpt.Start();
 
     AdapterRegistration.LoadTypes(Assembly.GetAssembly(typeof(ModuleFactory)));
                             
     hpt.Stop();
     log.InfoFormat("Module Factory initialized in {0} secs.", hpt.Duration);
 }
Ejemplo n.º 4
0
 public AnalyticFactory()
 {
     PerfTimer hpt = new PerfTimer();
     hpt.Start();
 
     AnalyticRegistration.LoadTypes(Assembly.GetAssembly(typeof(AnalyticFactory)));
                             
     hpt.Stop();
     log.InfoFormat("Analytic Factory initialized in {0} secs.", hpt.Duration);
 }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public IDataMonitorManager Start(string[] args, GlobalConfigDetails _globalConfig)
        {
            globalConfig = _globalConfig;

            PerfTimer hptStartup = new PerfTimer();
            hptStartup.Start();

            log.Info("Starting BITS Time Manager service");

            this.CanStop = true;
            this.CanShutdown = true;
            DataMonitorManager.InstanceOf(globalConfig).Start();

            hptStartup.Stop();
            log.InfoFormat("BITS Time Manager has started in {0} seconds.", hptStartup.Duration);

            return DataMonitorManager.InstanceOf();
        }
Ejemplo n.º 7
0
        public IFlatFileLoader Start(string[] args, GlobalConfigDetails _globalConfig)
        {
            globalConfig = _globalConfig;
            FlatFileLoader.InstanceOf().GlobalConfig = _globalConfig;

            log.Info("Starting BITS File Manager service");

            PerfTimer hptStartup = new PerfTimer();
            hptStartup.Start();

            this.CanStop = true;
            this.CanShutdown = true;
            FlatFileLoader.InstanceOf().Start();

            hptStartup.Stop();
            log.InfoFormat("BITS File Manager service has started in {0} seconds.", hptStartup.Duration);

            return (IFlatFileLoader)FlatFileLoader.InstanceOf();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Called internally, except for JobLauncher module
        /// </summary>
        /// <param name="oJobDetail"></param>
        /// <returns></returns>
        public  ErrorCode ExecuteJob(object oJobDetail)
        {
            ErrorCode retval = ErrorCode.SUCCESS;

            #region execution

            PerfTimer hpt = new PerfTimer();
            hpt.Start();

            JobExeWrapper jobWrapper = null;
            JobDetails jobDetail = oJobDetail as JobDetails;

            if (jobDetail == null)
            {
                log.ErrorFormat("Job detail is invalid.  Failed to execute job.");
                return ErrorCode.JOB_DETAIL_INVALID;
            }

            if (jobDetail.Xml.Equals(String.Empty))
            {
                jobDetail.Xml = globalConfig.Hierarchy.GetValueAtLevel("appgroup\\BITS_JOB_SPEC", jobDetail.Name.Replace("_Job", ""), "");

                if (jobDetail.Xml.Equals(String.Empty))
                {
                    log.ErrorFormat("No job spec found for {0}.  Skipping request to build job.", jobDetail.Name);
                    return ErrorCode.JOB_SPEC_NOT_FOUND;
                }
            }

            Job job = (Job)JobImpl.BuildJobFromXml(jobDetail);
            if (job == null)
            {
                log.ErrorFormat("Unable to build job from job spec for {0}.  Skipping request to build job.", jobDetail.Name);
                return ErrorCode.UNABLE_TO_BUILD_JOB_FROM_SPEC;
            }
            else
            {
                job.Key = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
                job.Config.RunInstance = globalConfig.RunInstance;
                job.Config.SuppressEmail = globalConfig.SuppressEmail;
            }

            if (jobWrappers.ContainsKey(job.JobName))
            {
                //replaces job with new definition from xml
                jobWrapper = jobWrappers[job.JobName];
                jobWrapper.Job = job;
                lock (jobWrappers)
                {
                    jobWrappers[job.JobName] = jobWrapper;
                }
            }
            else
            {
                jobWrapper = new JobExeWrapper(job);
                lock (jobWrappers)
                {
                    jobWrappers[job.JobName] = jobWrapper;
                }
            }

            lock (jobWrappers[job.JobName].HistoricalJobs)
            {
                if (!jobWrappers[job.JobName].HistoricalJobs.ContainsKey(job.Key))
                {
                    jobWrappers[job.JobName].HistoricalJobs.Add(job.Key, job);

                    jobWrapper.Job = job;
                    jobWrapper.States.Clear();
                    jobWrapper.ChangeMode(State.ExecutionModeEnum.Initialization);

                    retval = ProcessJob(job, job.Key, jobWrapper);
                }
                else
                    log.WarnFormat("Job already exists, aborting new job execution for {0} {1}", job.JobName, job.Key);
            }

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

            #endregion

            #region Wrap-up

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

            if (log.IsInfoEnabled)
            {
                log.InfoFormat("Publishing job {0}", job.JobName);
                job.PublishDependencies();
            }

            #endregion

            return retval;
        }
Ejemplo n.º 9
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);
                }
            }
        }
Ejemplo n.º 10
0
        public override StateEnums.Status Execute(Object o, Hashtable inputData)
        {
            DataSet ds = null;
            DbConnectionDetail dbConnDetail;
            StateEnums.Status retValue = StateEnums.Status.Warnings;

            UpdateProcessStatus(Enums.ProcessStatus.Starting, "", (State) o);

            if (IfResetOnEachRun)
                ResetOutput();

            PassAlongOutputs(inputData);

            PerfTimer hpt = new PerfTimer();
            hpt.Start();

            try
            {

                //Get connection string for database 
                if (connection.Equals(String.Empty) ||
                    ConfigUtils.GlobalConfig.ConnectionSettings.Connections.ContainsKey(connection) == false)
                    throw new ApplicationException(String.Format("Connection {0} is not defined.  Please add to config file and restart the service.", connection));


                // Establish connection to database
                dbConnDetail = (DbConnectionDetail) ConfigUtils.GlobalConfig.ConnectionSettings.Connections[connection];
                if (!DatabaseUtils.Connect(dbConnDetail.DefaultConnectString))
                    throw new ApplicationException("Database connection not established.");

                DataTable dt;
                SqlParameter[] parameters;
                StringBuilder sb = new StringBuilder();

                switch (dbmode)
                {
                    case dbMode.SQLBIND:

                        #region Sql Bind (dynamic binding of one datatable to another)

                        DataTable dtSchema = DatabaseUtils.GetSchema(tableName);

                        #endregion

                        break;

                    case dbMode.BULKINSERT:

                        #region Bulk Insert

                        // get table data for bulk insert
                        if (InputToProcess.CompareTo(String.Empty) != 0)
                            dt = inputData[InputToProcess] as DataTable;
                        else
                            dt = inputData[0] as DataTable;

                        if (dt == null)
                        {
                            log.Warn(((State)o).CurrentJobHash, "Data table is null");
                            break;
                        }

                        if (!tableName.Equals(String.Empty))
                            dt.TableName = tableName;
                        else if (dt.TableName.Equals(String.Empty) && tableName.Equals(String.Empty))
                            tableName = "Table0";

                        // [optional] add a column to [front of] the datatable using a datetime as a key
                        if (ifAddDatetimeAsKey)
                        {
                            log.InfoFormat(((State)o).CurrentJobHash, "Adding timestamp column to front of datatable.");

                            DateTime key = DateTime.Now;
                            DataTable dtMod = new DataTable(dt.TableName);
                            dtMod.Columns.Add("TimeStamp", typeof (Double));
                            foreach (DataColumn dc in dt.Columns)
                                dtMod.Columns.Add(dc.ColumnName, dc.DataType);
                            foreach (DataRow dr in dt.Rows)
                            {
                                DataRow drr = dtMod.NewRow();
                                drr["TimeStamp"] = Convert.ToDouble(String.Format("{0}{1}{2}{3}{4}{5}", key.Year, key.Month, key.Day, key.Hour, key.Minute, key.Second));
                                foreach (DataColumn dc in dt.Columns)
                                    drr[dc.ColumnName] = dr[dc.ColumnName];
                                dtMod.Rows.Add(drr);
                            }
                            dt = dtMod.Copy();
                            log.InfoFormat(((State)o).CurrentJobHash, "Transformation completed:  {0} columns, {1} rows", dt.Columns.Count, dt.Rows.Count);
                        }

                        // perform the bulk insert

                        string cstr = ((DbConnectionDetail)ConfigUtils.GlobalConfig.ConnectionSettings.Connections[connection]).DefaultConnectString;
                        using (SqlBulkCopy bulkCopy = new SqlBulkCopy(cstr, SqlBulkCopyOptions.TableLock))
                        {

                            log.InfoFormat(((State)o).CurrentJobHash, "Using: {0}", cstr);
                            log.InfoFormat(((State)o).CurrentJobHash, "Executing Bulk Copy To: {0}", dt.TableName);
                            log.InfoFormat(((State)o).CurrentJobHash, "Timeout: {0}", bulkCopyTimeout);

                            for (int i = 0; i < dt.Columns.Count; i++)
                                bulkCopy.ColumnMappings.Add(i, i);
                            bulkCopy.DestinationTableName = dt.TableName;
                            bulkCopy.BulkCopyTimeout = bulkCopyTimeout;
                            bulkCopy.WriteToServer(dt);
                        }

                        log.InfoFormat("Bulk insert into {0} completed.", dt.TableName);

                        #endregion

                        break;

                    case dbMode.INSERT:

                        #region Insert

                        // get table data for insert
                        if (InputToProcess.CompareTo(String.Empty) != 0)
                            dt = inputData[InputToProcess] as DataTable;
                        else
                            dt = inputData[0] as DataTable;

                        if (dt != null && !tableName.Equals(String.Empty))
                            dt.TableName = tableName;
                        else if (tableName.Equals(String.Empty))
                            tableName = "Table0";

                        // call Insert sproc row-by-row (note: this must be defined specifically for each datatable)
                        foreach (DataRow dr in dt.Rows)
                        {
                            parameters = GetParmsFromDataRow(((State)o).CurrentJobHash, dr);

                            log.InfoFormat(((State)o).CurrentJobHash, "Executing {0} {1} using {2}", sproc, parameters, dbConnDetail.DefaultConnectString);
                            ds = DatabaseUtils.ExecuteStoredProc(sproc, parameters, tableName);
                            retValue = 0;
                        }

                        #endregion

                        break;

                    case dbMode.SELECT:
                    case dbMode.SCALAR:

                        #region Select or Scalar

                        parameters = ParseParameters(inputData);

                        #region logging

                        if (parameters != null)
                        {
                            foreach (SqlParameter sp in parameters)
                                sb.AppendFormat("{0}={1};", sp.ParameterName, sp.Value);
                        }

                        log.InfoFormat(((State)o).CurrentJobHash, "Using: {0}", dbConnDetail.DefaultConnectString);
                        log.InfoFormat(((State)o).CurrentJobHash, "Executing: {0}", sproc);
                        log.InfoFormat(((State)o).CurrentJobHash, "Parameters: {0}", sb.ToString().TrimEnd(';'));

                        #endregion

                        DatabaseUtils.jobKeyCode = ((State)o).CurrentJobHash;
                        ds = DatabaseUtils.ExecuteStoredProc(sproc, parameters, tableName);
                        DatabaseUtils.jobKeyCode = 0; //resetting ??

                        int dtIndx = 0;
                        string dname = this.Name;
                        string tname = "";
                        if (ds != null && ds.Tables.Count > 0)
                        {
                            foreach (DataTable dtt in ds.Tables)
                            {
                                if (dtt.Rows.Count > 0)
                                {

                                    if (dtt.TableName.Equals(String.Empty))
                                        tname = String.Format("Table{0}", dtIndx);
                                    else
                                        tname = dtt.TableName;

                                    AddToOutputs(String.Format("{0}_{1}", dname, tname), dtt);
                                    log.InfoFormat(((State)o).CurrentJobHash, "Added datatable {0}_{1}  to outputs ({2} records)", dname, tname, dtt.Rows.Count);

                                    recCountTotal += dtt.Rows.Count;
                                    dtIndx++;
                                }
                            }
                        }
                        recCountSuccess = recCountTotal;

                        #endregion

                        break;

                    case dbMode.SQL:

                        #region SQL

                        //Dynamic run-time parameters should be replaced by Job Launcher
						//sql = ConfigUtils.MetaTagReplacer( sql, inputData );
						//sql = ConfigUtils.MetaTagReplacer( sql );

                        #region logging

                        log.InfoFormat(((State)o).CurrentJobHash, "Using: {0}", dbConnDetail.DefaultConnectString);
                        log.InfoFormat(((State)o).CurrentJobHash, "Executing: \"{0}\"", sql);

                        #endregion

                        if (ds == null)
                            ds = new DataSet();
                        DatabaseUtils.ExecuteSQL(sql, ref ds, tableName);

                        if (ds != null && ds.Tables.Count > 0)
                        {
                            //Realistically there should always be 1 table resulting from dbMode.SQL option
                            //keep logic below for consistency with SELECT/SCALAR
                            string dt_name = (tableName.Equals(string.Empty) ? this.Name : tableName);
                            for (int dt_index = 0; dt_index < ds.Tables.Count; dt_index++ )
                            {
                                DataTable dtt = ds.Tables[dt_index];
                                if (dtt.TableName.Equals(String.Empty))
                                    dtt.TableName = String.Format("{0}_{1}", dt_name, dt_index);
                                if (dtt.Rows.Count > 0)
                                {
                                    AddToOutputs(dtt.TableName, dtt);
                                    log.InfoFormat(((State)o).CurrentJobHash,
                                                                "Added datatable {0} to outputs ({1} records)",
                                                                dtt.TableName, dtt.Rows.Count);

                                    recCountTotal += dtt.Rows.Count;
                                }
                            }
                        }
                        recCountSuccess = recCountTotal;

                        #endregion

                        break;
                }

                retValue = StateEnums.Status.Success;
                if (recCountTotal > 0 && ds != null && ds.Tables.Count > 0 && ds.Tables.Count > 0)
                {
                    #region mailer output

                    String mailEnvelop = "";
                    switch (InputToProcess)
                    {
                        case "PROD_OptionExpiryReport":
                            mailEnvelop = String.Format("Option Expiry Phase 1 Summary:\r\n<br>");
                            mailEnvelop += String.Format("\t{0} expiring options records were reported\r\n<br>", ds.Tables[0].Rows.Count);
                            AddToOutputs("MailEnvelop", mailEnvelop);
                            break;
                        case "PROD_OptionExpiryExerciseBuyGet":
                            mailEnvelop = String.Format("Option Expiry Phase 1 Summary:\r\n<br>");
                            mailEnvelop += String.Format("\t{0} expiring options records were reported\r\n<br>", ds.Tables[0].Rows.Count);
                            AddToOutputs("MailEnvelop", mailEnvelop);
                            break;
                        case "PROD_OptionExpiryExerciseSellShortGet":
                            mailEnvelop = String.Format("Option Expiry Phase 1 Summary:\r\n<br>");
                            mailEnvelop += String.Format("\t{0} expiring options records were reported\r\n<br>", ds.Tables[0].Rows.Count);
                            AddToOutputs("MailEnvelop", mailEnvelop);
                            break;
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                log.Error(((State)o).CurrentJobHash, ex);
                recCountSuccess = recCountFailed = recCountTotal = 0;
                retValue = StateEnums.Status.Error ;
            }

            int activityIdEnding = UpdateProcessStatus(Enums.ProcessStatus.Success, "", (State) o);
            UpdateRecordCount(activityIdEnding, recCountTotal, recCountSuccess, recCountFailed);

            hpt.Stop();
            log.InfoFormat(((State)o).CurrentJobHash, "DbSqlAdapter completed in {0} seconds.", hpt.Duration);

            return retValue;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Called internally, except for JobLauncher module
        /// </summary>
        /// <param name="oJobDetail"></param>
        /// <returns></returns>
        public ErrorCode ExecuteJob(object oJobDetail)
        {
            ErrorCode retval = ErrorCode.SUCCESS;

            #region execution

            PerfTimer hpt = new PerfTimer();
            hpt.Start();

            JobDetails jobDetail = oJobDetail as JobDetails;

            #region sanity checks and prep

            if (jobDetail == null)
            {
                log.ErrorFormat("Job detail is invalid.  Failed to execute job.");
                return ErrorCode.JOB_DETAIL_INVALID;
            }

            if (jobDetail.Xml.Equals(String.Empty))
            {
                jobDetail.Xml = globalConfig.Hierarchy.GetValueAtLevel("app\\BITS_JOB_SPEC", jobDetail.Name.Replace("_Job", ""), "");

                if (jobDetail.Xml.Equals(String.Empty))
                {
                    log.ErrorFormat("No job spec found for {0}.  Skipping request to build job.", jobDetail.Name);
                    return ErrorCode.JOB_SPEC_NOT_FOUND;
                }
            }

            if (jobWrappers.ContainsKey(jobDetail.Name) && jobDetail.Name.Contains("ADHOC") == false)
            {
                return ErrorCode.JOB_CODE_NOT_UNIQUE;
            }

            // Set up job spec for "Run Once."  This means that the start time will be set to *IMMEDIATELY*, the 
            // weekly schedule will be set to SMTWTFS. 
            if (jobDetail.RunOnce)
            {
                XmlDocument xdocAdhoc = Job.SetRunOnceAttributes(jobDetail.Xml, true);
                jobDetail.Xml = xdocAdhoc.InnerXml;
            }

            #endregion

            // Obtain a new PropertyBag for the job's metatags (ie the job's Dynamic Parameters).  In this PropertyBag, 
            // the parameters that were identified as Environmental will have been set.  Those that are not Environmental,
            // (ie Runtime) will have a value of null;
            PropertyBag jobMetaTags = MetaTagReplacer.GetJobParametersPB(jobDetail.Name, jobDetail.Xml);
            MetaTagReplacer.SetParametersValuesPB(ref jobMetaTags, ConfigUtils.MetatagMode.Environment, null, null);

            // Use the Dynamic Parameters PropertyBag to define the job spec at Enable-time.  Only Environment parameters
            // will be determined at this time.
            jobDetail.Xml = MetaTagReplacer.InlineMetatagSubstitution(jobDetail.Xml, jobMetaTags);

            // Create the job.  This step instantiates the job's modules and sets up the job's dependencies 
            Job job = (Job)JobImpl.BuildJobFromXml(jobDetail);
            if (job == null)
            {
                log.ErrorFormat("Unable to build job from job spec for {0}.  Skipping request to build job.", jobDetail.Name);
                return ErrorCode.UNABLE_TO_BUILD_JOB_FROM_SPEC;
            }
            //job.Key = DateTime.Now;
            job.Config.RunInstance = globalConfig.RunInstance;
            job.Config.SuppressEmail = globalConfig.SuppressEmail;
            job.JobState.CurrentParameters.CurrentParameters = jobMetaTags;
            //job.JobState.CurrentJobCode = job.Key;

            foreach (JobDetailsData jdd in jobDetail.Data)
            {
                ((IModule)job.Modules[jdd.ModuleName]).OutputData.Add(jdd.DataName, jdd.Data);
            }

            // Job will be enabled after this...
            JobExeWrapper jobWrapper = null;
            lock (jobWrappers)
            {
                if (jobWrappers.ContainsKey(job.JobName))
                    jobWrapper = jobWrappers[job.JobName];
                else
                    jobWrapper = new JobExeWrapper(job);

                jobWrapper.Job = job;
                jobWrapper.ResetState();
                jobWrappers[job.JobName] = jobWrapper;
            }

            retval = ProcessJob(jobWrapper);

            hpt.Stop();

            #endregion

            #region Wrap-up

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

            if (log.IsInfoEnabled)
            {
                log.DebugFormat("Publishing job {0}", job.JobName);
                job.PublishDependencies();
            }

            #endregion

            return retval;
        }
Ejemplo n.º 12
0
        public override StateEnums.Status Execute(Object o, Hashtable inputData)
        {
            log.InfoFormat(((State)o).CurrentJobHash, "Module {0} received {1} inputs.", name, inputData != null ? inputData.Count.ToString() : "no");
            StateEnums.Status retval = 0;
            State state = o as State;

            if (IfResetOnEachRun)
                ResetOutput();

            PassAlongOutputs(inputData);

            PerfTimer hpt = new PerfTimer();
            hpt.Start();

            UpdateProcessStatus(Enums.ProcessStatus.Starting, "", (State) o);

            DataTable dtOut = new DataTable();

            try
            {
                BamSvcMgrAdapter bsm = new BamSvcMgrAdapter();
                bsm.Timeout = timeout;

                #region Logging
                //New Meta Tag replacememt logic
                //string cmd = ConfigUtils.MetaTagReplacer(request, runDate);
                string cmd = MetaTagReplacer.InlineMetatagSubstitution(request, runDate);
                log.InfoFormat(((State)o).CurrentJobHash, "Sending: {0}", cmd);                
                #endregion

                Response = bsm.Send(((State)o).CurrentJobHash, cmd);

                #region Logging
                log.InfoFormat(((State)o).CurrentJobHash, "Received {0} bytes.", response.Length);
                #endregion

                if (String.IsNullOrEmpty(Response) == false)
                {
                    dtOut = ConvertToDataTable(((State)o).CurrentJobHash, TableName, Response);

                    AddToOutputs(this.Name, Response);
                    AddToOutputs(this.Name + "_" + dtOut.TableName, dtOut);
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat(((State)o).CurrentJobHash, "Error in SOAP Select module: {0}", ex);
                retval = StateEnums.Status.Error;
            }

            hpt.Stop();

            UpdateProcessStatus(Enums.ProcessStatus.Success, "", (State) o);

            log.InfoFormat(((State)o).CurrentJobHash, "GenevaSvcMgrClient completed in {0} seconds.", hpt.Duration);

            return retval;
        }