예제 #1
0
        public IEnumerable <JobInstance> FindJobInstances(Guid userGuid, Guid queueInstanceGuid, HashSet <Guid> jobDefinitionGuids, JobExecutionState jobExecutionStatus)
        {
            string sql = "spFindJobInstance_byDetails";

            using (SqlCommand cmd = Context.CreateStoredProcedureCommand(sql))
            {
                cmd.Parameters.Add("@UserGuid", SqlDbType.UniqueIdentifier).Value = Context.UserGuid;
                cmd.Parameters.Add("@ShowHidden", SqlDbType.Bit).Value            = Context.ShowHidden;
                cmd.Parameters.Add("@ShowDeleted", SqlDbType.Bit).Value           = Context.ShowDeleted;
                cmd.Parameters.Add("@From", SqlDbType.Int).Value         = DBNull.Value;
                cmd.Parameters.Add("@Max", SqlDbType.Int).Value          = DBNull.Value;
                cmd.Parameters.Add("@RowCount", SqlDbType.Int).Direction = ParameterDirection.Output;

                cmd.Parameters.Add("@JobUserGuid", SqlDbType.UniqueIdentifier).Value       = userGuid == Guid.Empty ? DBNull.Value : (object)userGuid;
                cmd.Parameters.Add("@QueueInstanceGuid", SqlDbType.UniqueIdentifier).Value = queueInstanceGuid == Guid.Empty ? DBNull.Value : (object)queueInstanceGuid;
                cmd.Parameters.Add("@JobDefinitionGuids", SqlDbType.Structured).Value      = CreateGuidListTable(jobDefinitionGuids);
                cmd.Parameters.Add("@JobExecutionStatus", SqlDbType.Int).Value             = jobExecutionStatus;

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        JobInstance item = new JobInstance(Context);
                        item.LoadFromDataReader(dr);
                        yield return(item);
                    }
                    dr.Close();
                }
            }
        }
예제 #2
0
        public JobInstance CreateJobInstance(string queueName, ScheduleType scheduleType)
        {
            JobInstance job = new JobInstance(Context);

            job.Name = GenerateJobID();
            // TODO: delete if works job.JobDefinitionReference.Name = GetFullyQualifiedName();
            job.JobDefinition        = this;
            job.ParentReference.Name = queueName;
            job.WorkflowTypeName     = this.workflowTypeName;
            job.JobExecutionStatus   = Jhu.Graywulf.Registry.JobExecutionState.Scheduled;
            job.ScheduleType         = scheduleType;

            // Create workflow parameters
            var rh = JobReflectionHelper.CreateInstance(this.workflowTypeName);

            foreach (JobDefinitionParameter par in rh.GetParameters().Values)
            {
                job.Parameters.Add(par.Name, new JobInstanceParameter()
                {
                    Name      = par.Name,
                    Direction = par.Direction,
                });
            }

            return(job);
        }
예제 #3
0
        private void RenderResults(JobInstance ji)
        {
            var q = (QueryBase)ji.Parameters["Query"].Value;

            var codegen = new SqlServerCodeGenerator();

            string sql = codegen.GenerateSelectStarQuery(q.Destination.GetTable(), 100);

            using (var cn = new SqlConnection())
            {
                cn.ConnectionString = MyDBDataset.ConnectionString;
                cn.Open();

                using (var cmd = cn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    cmd.CommandType = CommandType.Text;

                    using (var dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
                    {
                        RenderTable(dr);
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Reschedules the job instance if it's a recurring job.
        /// </summary>
        /// <returns>The new job instance that is in the queue now.</returns>
        /// <remarks>
        /// The completed job is marked as completed and is stored for reference, so a new
        /// job instance is created with updated properties.
        /// </remarks>
        public JobInstance RescheduleIfRecurring()
        {
            if ((jobExecutionStatus == Registry.JobExecutionState.Completed ||
                 jobExecutionStatus == Registry.JobExecutionState.Failed ||
                 jobExecutionStatus == Registry.JobExecutionState.Cancelled) &&
                scheduleType == ScheduleType.Recurring)
            {
                // Create a copy first
                JobInstance newjob = new JobInstance(this);

                // Reset properties
                newjob.Guid               = Guid.Empty;
                newjob.Name               = GenerateRecurringJobID();
                newjob.dateStarted        = DateTime.MinValue;
                newjob.dateFinished       = DateTime.MinValue;
                newjob.JobExecutionStatus = JobExecutionState.Scheduled;
                newjob.ScheduleTime       = GetNextScheduleTime();
                newjob.workflowInstanceId = Guid.Empty;
                newjob.adminRequestTime   = DateTime.MinValue;
                newjob.adminRequestData   = null;
                newjob.adminRequestResult = -1;
                newjob.exceptionMessage   = null;

                // Save new job
                newjob.Save();

                return(newjob);
            }
            else
            {
                return(null);
            }
        }
예제 #5
0
        protected void RenderOutput()
        {
            Response.Expires = -1;

            try
            {
                var ji = new JobInstance(RegistryContext);
                ji.Guid = LastQueryJobGuid;
                ji.Load();

                switch (ji.JobExecutionStatus)
                {
                    case JobExecutionState.Completed:
                        RenderResults(ji);
                        break;
                    case JobExecutionState.Scheduled:
                    case JobExecutionState.Starting:
                    case JobExecutionState.Executing:
                        RenderExecuting();
                        break;
                    default:
                        RenderFailed(ji);
                        break;
                }
            }
            catch (Exception ex)
            {
                RenderException(ex);
            }
        }
예제 #6
0
        public IEnumerable<JobInstance> FindJobInstances(Guid userGuid, Guid queueInstanceGuid, HashSet<Guid> jobDefinitionGuids, JobExecutionState jobExecutionStatus)
        {
            string sql = "spFindJobInstance_byDetails";

            using (SqlCommand cmd = Context.CreateStoredProcedureCommand(sql))
            {
                cmd.Parameters.Add("@UserGuid", SqlDbType.UniqueIdentifier).Value = Context.UserGuid;
                cmd.Parameters.Add("@ShowHidden", SqlDbType.Bit).Value = Context.ShowHidden;
                cmd.Parameters.Add("@ShowDeleted", SqlDbType.Bit).Value = Context.ShowDeleted;
                cmd.Parameters.Add("@From", SqlDbType.Int).Value = DBNull.Value;
                cmd.Parameters.Add("@Max", SqlDbType.Int).Value = DBNull.Value;
                cmd.Parameters.Add("@RowCount", SqlDbType.Int).Direction = ParameterDirection.Output;

                cmd.Parameters.Add("@JobUserGuid", SqlDbType.UniqueIdentifier).Value = userGuid == Guid.Empty ? DBNull.Value : (object)userGuid;
                cmd.Parameters.Add("@QueueInstanceGuid", SqlDbType.UniqueIdentifier).Value = queueInstanceGuid == Guid.Empty ? DBNull.Value : (object)queueInstanceGuid;
                cmd.Parameters.Add("@JobDefinitionGuids", SqlDbType.Structured).Value = CreateGuidListTable(jobDefinitionGuids);
                cmd.Parameters.Add("@JobExecutionStatus", SqlDbType.Int).Value = jobExecutionStatus;

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        JobInstance item = new JobInstance(Context);
                        item.LoadFromDataReader(dr);
                        yield return item;
                    }
                    dr.Close();
                }
            }
        }
예제 #7
0
        protected void CancelJob(Guid guid)
        {
            using (var context = ContextManager.Instance.CreateContext(ConnectionMode.AutoOpen, TransactionMode.AutoCommit))
            {
                var job = new JobInstance(context);
                job.Guid = guid;
                job.Load();

                job.Cancel();
            }
        }
예제 #8
0
        private void LoadJob()
        {
            job = new JobInstance(RegistryContext);
            job.Guid = guid;
            job.Load();

            // Check user ID
            if (job.UserGuidOwner != UserGuid)
            {
                throw new Registry.SecurityException("Access denied.");
            }

            // Get query details
            qj = JobDescriptionFactory.GetJob(job, QueryFactory);
        }
예제 #9
0
        private void LoadJob()
        {
            job = new JobInstance(RegistryContext);
            job.Guid = guid;
            job.Load();

            // Check user ID
            if (IsAuthenticatedUser(job.UserGuidOwner))
            {
                throw new Registry.SecurityException("Access denied.");  // TODO
            }

            // Get query details
            ej = JobDescriptionFactory.GetJobDescription(job);
        }
예제 #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (filter.UserGuid != Guid.Empty)
            {
                user = new Registry.User(((PageBase)Page).RegistryContext);
                user.Guid = filter.UserGuid;
                user.Load();

                linkUser.EntityReference.Value = user;
                linkUser.Visible = true;
            }
            else
            {
                linkUser.Visible = false;
            }

            if (filter.JobGuid != Guid.Empty)
            {
                job = new JobInstance(((PageBase)Page).RegistryContext);
                job.Guid = filter.JobGuid;
                job.Load();

                linkJob.EntityReference.Value = job;
                linkJob.Visible = true;
            }
            else
            {
                linkJob.Visible = false;
            }

            if (filter.EntityGuid != Guid.Empty)
            {
                entity = new Entity(((PageBase)Page).RegistryContext);
                entity.Guid = filter.EntityGuid;
                entity.Load();

                linkEntity.EntityReference.Value = entity;
                linkEntity.Visible = true;
            }
            else
            {
                linkEntity.Visible = false;
            }
        }
예제 #11
0
 /// <summary>
 /// Creates a deep copy of the passed object.
 /// </summary>
 /// <param name="old">A <b>Database Definition</b> object to create the deep copy from.</param>
 private void CopyMembers(JobInstance old)
 {
     this.workflowTypeName   = old.workflowTypeName;
     this.dateStarted        = old.dateStarted;
     this.dateFinished       = old.dateFinished;
     this.jobExecutionStatus = old.jobExecutionStatus;
     this.suspendTimeout     = old.suspendTimeout;
     this.scheduleType       = old.scheduleType;
     this.scheduleTime       = old.scheduleTime;
     this.recurringPeriod    = old.recurringPeriod;
     this.recurringInterval  = old.recurringInterval;
     this.recurringMask      = old.recurringMask;
     this.workflowInstanceId = old.workflowInstanceId;
     this.adminRequestTime   = old.adminRequestTime;
     this.adminRequestData   = old.adminRequestData == null ? null : new JobAdminRequestData(old.adminRequestData);
     this.adminRequestResult = old.adminRequestResult;
     this.exceptionMessage   = old.exceptionMessage;
     this.parameters         = new ParameterCollection(old.parameters);
 }
예제 #12
0
        private void RedirectToDetails(Guid guid)
        {
            var job = new JobInstance(RegistryContext);
            job.Guid = guid;
            job.Load();

            var wjob = JobDescriptionFactory.GetJob(job, QueryFactory);

            switch (wjob.JobType)
            {
                case JobType.Query:
                    Response.Redirect(QueryJobDetails.GetUrl(guid));
                    break;
                case JobType.ExportTable:
                    Response.Redirect(ExportJobDetails.GetUrl(guid));
                    break;
                default:
                    throw new NotImplementedException();
            }
        }
예제 #13
0
        private void LoadJobs()
        {
            jobs = new List<JobInstance>();

            foreach (var guid in guids)
            {
                var job = new JobInstance(RegistryContext);
                job.Guid = guid;
                job.Load();

                if (job.UserGuidOwner != UserGuid)
                {
                    throw new System.Security.SecurityException("Access denied.");  // TODO
                }

                if (job.CanCancel)
                {
                    jobs.Add(job);
                }
            }
        }
예제 #14
0
        protected void Button_Command(object sender, CommandEventArgs e)
        {
            if (IsValid)
            {
                var guid = new Guid(JobList.SelectedDataKeys.First());
                var guids = JobList.SelectedDataKeys.Select(i => new Guid(i)).ToArray();

                switch (e.CommandName)
                {
                    case "Download":
                        var job = new JobInstance(RegistryContext);
                        job.Guid = guid;
                        job.Load();

                        if (job.JobExecutionStatus == JobExecutionState.Completed)
                        {
                            // Get query details
                            var ej = JobDescriptionFactory.GetJob(job, QueryFactory);

                            Response.Redirect(GetExportUrl(ej));
                        }
                        else
                        {
                            JobNotCompleteValidator.IsValid = false;
                        }
                        break;
                    case "View":
                        Response.Redirect(Jhu.Graywulf.Web.UI.Jobs.ExportJobDetails.GetUrl(guid));
                        break;
                    case "Cancel":
                        Response.Redirect(Jhu.Graywulf.Web.UI.Jobs.CancelJob.GetUrl(guids));
                        break;
                    default:
                        throw new NotImplementedException();
                }
            }
        }
예제 #15
0
        /// <summary>
        /// Gets the next available job from the queue.
        /// </summary>
        /// <returns>The next available job or null if there are no queued jobs.</returns>
        public JobInstance GetNextJobInstance()
        {
            string sql = "spFindJobInstance_Next";

            using (SqlCommand cmd = Context.CreateStoredProcedureCommand(sql))
            {
                cmd.Parameters.Add("@UserGuid", SqlDbType.UniqueIdentifier).Value            = Context.UserGuid;
                cmd.Parameters.Add("@QueueInstanceGuid", SqlDbType.UniqueIdentifier).Value   = this.Guid;
                cmd.Parameters.Add("@JobInstanceGuid", SqlDbType.UniqueIdentifier).Direction = ParameterDirection.Output;

                cmd.ExecuteNonQuery();

                if (cmd.Parameters["@JobInstanceGuid"].Value != DBNull.Value)
                {
                    JobInstance j = new JobInstance(Context);
                    j.Guid = (Guid)cmd.Parameters["@JobInstanceGuid"].Value;
                    j.Load();

                    return(j);
                }
            }

            return(null);
        }
예제 #16
0
        /// <summary>
        /// Gets the next available job from the queue.
        /// </summary>
        /// <returns>The next available job or null if there are no queued jobs.</returns>
        public JobInstance GetNextJobInstance()
        {
            string sql = "spFindJobInstance_Next";

            using (SqlCommand cmd = Context.CreateStoredProcedureCommand(sql))
            {
                cmd.Parameters.Add("@UserGuid", SqlDbType.UniqueIdentifier).Value = Context.UserGuid;
                cmd.Parameters.Add("@QueueInstanceGuid", SqlDbType.UniqueIdentifier).Value = this.Guid;
                cmd.Parameters.Add("@JobInstanceGuid", SqlDbType.UniqueIdentifier).Direction = ParameterDirection.Output;

                cmd.ExecuteNonQuery();

                if (cmd.Parameters["@JobInstanceGuid"].Value != DBNull.Value)
                {
                    JobInstance j = new JobInstance(Context);
                    j.Guid = (Guid)cmd.Parameters["@JobInstanceGuid"].Value;
                    j.Load();

                    return j;
                }
            }

            return null;
        }
예제 #17
0
        private void CancelOrTimeOutJob(Job job, bool timeout)
        {
            using (Context context = ContextManager.Instance.CreateContext(ConnectionMode.AutoOpen, TransactionMode.AutoCommit))
            {
                context.JobGuid = job.Guid;
                context.ContextGuid = contextGuid;

                var ji = new JobInstance(context);
                ji.Guid = job.Guid;
                ji.Load();

                // Update registry
                ji.JobExecutionStatus = JobExecutionState.Cancelling;

                ji.Save();
            }

            // Update job status
            if (timeout)
            {
                job.Status = JobStatus.TimedOut;
                appDomains[job.AppDomainID].TimeOutJob(job);
            }
            else
            {
                job.Status = JobStatus.Cancelled;
                appDomains[job.AppDomainID].CancelJob(job);
            }
        }
예제 #18
0
        protected JobInstance LoadJob(Guid guid)
        {
            using (var context = ContextManager.Instance.CreateContext(ConnectionMode.AutoOpen, TransactionMode.DirtyRead))
            {
                var job = new JobInstance(context);
                job.Guid = guid;
                job.Load();
                job.LoadParameters();

                return job;
            }
        }
예제 #19
0
 /// <summary>
 /// Copy contructor for doing deep copy of the <b>Database Definition</b> objects.
 /// </summary>
 /// <param name="old">The <b>Database Definition</b> to copy from.</param>
 public JobInstance(JobInstance old)
     : base(old)
 {
     CopyMembers(old);
 }
예제 #20
0
        /// <summary>
        /// Creates a deep copy of the passed object.
        /// </summary>
        /// <param name="old">A <b>Database Definition</b> object to create the deep copy from.</param>
        private void CopyMembers(JobInstance old)
        {
            this.workflowTypeName = old.workflowTypeName;
            this.dateStarted = old.dateStarted;
            this.dateFinished = old.dateFinished;
            this.jobExecutionStatus = old.jobExecutionStatus;
            this.suspendTimeout = old.suspendTimeout;
            this.scheduleType = old.scheduleType;
            this.scheduleTime = old.scheduleTime;
            this.recurringPeriod = old.recurringPeriod;
            this.recurringInterval = old.recurringInterval;
            this.recurringMask = old.recurringMask;
            this.workflowInstanceId = old.workflowInstanceId;
            this.adminRequestTime = old.adminRequestTime;
            this.adminRequestData = old.adminRequestData == null ? null : new JobAdminRequestData(old.adminRequestData);
            this.adminRequestResult = old.adminRequestResult;
            this.exceptionMessage = old.exceptionMessage;

            // TODO: do deep copy here?
            this.parameters = new Dictionary<string, JobParameter>(old.parameters);
            this.checkpoints = new List<JobCheckpoint>(old.checkpoints);
        }
예제 #21
0
        /// <summary>
        /// Reschedules the job instance if it's a recurring job.
        /// </summary>
        /// <returns>The new job instance that is in the queue now.</returns>
        /// <remarks>
        /// The completed job is marked as completed and is stored for reference, so a new
        /// job instance is created with updated properties.
        /// </remarks>
        public JobInstance RescheduleIfRecurring()
        {
            if ((jobExecutionStatus == Registry.JobExecutionState.Completed ||
                jobExecutionStatus == Registry.JobExecutionState.Failed ||
                jobExecutionStatus == Registry.JobExecutionState.Cancelled)
                && scheduleType == ScheduleType.Recurring)
            {
                // Create a copy first
                JobInstance newjob = new JobInstance(this);

                // Reset properties
                newjob.Guid = Guid.Empty;
                newjob.Name = GenerateRecurringJobID();
                newjob.dateStarted = DateTime.MinValue;
                newjob.dateFinished = DateTime.MinValue;
                newjob.JobExecutionStatus = JobExecutionState.Scheduled;
                newjob.ScheduleTime = GetNextScheduleTime();
                newjob.workflowInstanceId = Guid.Empty;
                newjob.adminRequestTime = DateTime.MinValue;
                newjob.adminRequestData = null;
                newjob.adminRequestResult = -1;
                newjob.exceptionMessage = null;

                // Save new job
                newjob.Save();

                return newjob;
            }
            else
            {
                return null;
            }
        }
예제 #22
0
        private static void GetQueryJobDescription(JobInstance job, JobDescription jobDescription)
        {
            jobDescription.JobType = JobType.Query;

            // debug code
            if (job.Parameters.ContainsKey("Query"))
            {
                var xml = new XmlDocument();
                xml.LoadXml(job.Parameters["Query"].XmlValue);

                jobDescription.Query = GetXmlInnerText(xml, "Query/QueryString");
                jobDescription.SchemaName = GetXmlInnerText(xml, "Query/Destination/SchemaName");
                jobDescription.ObjectName = GetXmlInnerText(xml, "Query/Destination/TableName");
            }
            else
            {
                // This is probably a wrong job in the database
            }
        }
예제 #23
0
        /// <summary>
        /// Starts a single job
        /// </summary>
        /// <param name="job"></param>
        private void StartOrResumeJob(Job job)
        {
            AppDomainHost adh = null;

            using (Context context = ContextManager.Instance.CreateContext(ConnectionMode.AutoOpen, TransactionMode.AutoCommit))
            {
                context.JobGuid = job.Guid;
                context.ContextGuid = contextGuid;

                JobInstance ji = new JobInstance(context);
                ji.Guid = job.Guid;
                ji.Load();

                // Lock the job, so noone else can pick it up
                ji.DateStarted = DateTime.Now;
                ji.ObtainLock();

                ji.Save();
            }

            // Schedule job in the appropriate app domain
            adh = GetOrCreateAppDomainHost(job);

            // Check if job is a new instance or previously persisted and
            // has to be resumed
            switch (job.Status)
            {
                case JobStatus.Starting:
                    if (interactive)
                    {
                        Console.WriteLine("Starting job: {0}", job.Guid);
                    }

                    job.WorkflowInstanceId = adh.PrepareStartJob(job);
                    break;
                case JobStatus.Resuming:
                    if (interactive)
                    {
                        Console.WriteLine("Resuming job: {0}", job.Guid);
                    }

                    job.WorkflowInstanceId = adh.PrepareResumeJob(job);
                    break;
                default:
                    throw new NotImplementedException();
            }

            // Update job status
            job.TimeStarted = DateTime.Now;
            job.Status = JobStatus.Executing;
            job.AppDomainID = adh.ID;

            // TODO: this has to happen before starting the job
            lock (runningJobs)
            {
                runningJobs.Add(job.WorkflowInstanceId, job);
            }

            adh.RunJob(job);
        }
예제 #24
0
        protected void Ok_Click(object sender, EventArgs e)
        {
            string templatefile;
            Exception ex = null;
            long eventid = 0;

            if (mode == Mode.Error && Session[Constants.SessionException] != null)
            {
                ex = (Exception)Session[Constants.SessionException];
                eventid = (long)Session[Constants.SessionExceptionEventID];

                templatefile = "~/Templates/ErrorFeedbackEmail.xml";
            }
            else if (mode == Mode.JobError)
            {

                templatefile = "~/Templates/ErrorFeedbackEmail.xml";
            }
            else
            {
                templatefile = "~/Templates/FeedbackEmail.xml";
            }

            var template = File.ReadAllText(MapPath(templatefile));
            string subject;
            string body;

            EmailTemplateUtility.LoadEmailTemplate(template, out subject, out body);

            EmailTemplateUtility.ReplaceEmailToken(ref subject, "[$ShortTitle]", Federation.ShortTitle);
            EmailTemplateUtility.ReplaceEmailToken(ref subject, "[$Subject]", Subject.Text);

            EmailTemplateUtility.ReplaceEmailToken(ref body, "[$ShortTitle]", Federation.ShortTitle);
            EmailTemplateUtility.ReplaceEmailToken(ref body, "[$Name]", Name.Text);
            EmailTemplateUtility.ReplaceEmailToken(ref body, "[$Email]", Email.Text);
            EmailTemplateUtility.ReplaceEmailToken(ref body, "[$Subject]", Subject.Text);
            EmailTemplateUtility.ReplaceEmailToken(ref body, "[$Comments]", Comments.Text);

            if (mode == Mode.Error && Session[Constants.SessionException] != null)
            {
                EmailTemplateUtility.ReplaceEmailToken(ref body, "[$ErrorMessage]", ex.Message);
                EmailTemplateUtility.ReplaceEmailToken(ref body, "[$JobGUID]", "-");
                EmailTemplateUtility.ReplaceEmailToken(ref body, "[$EventID]", eventid.ToString());
            }
            else if (mode == Mode.JobError)
            {
                var job = new JobInstance(RegistryContext);
                job.Guid = jobGuid;
                job.Load();

                EmailTemplateUtility.ReplaceEmailToken(ref body, "[$ErrorMessage]", job.ExceptionMessage);
                EmailTemplateUtility.ReplaceEmailToken(ref body, "[$JobGUID]", job.Guid.ToString());
                EmailTemplateUtility.ReplaceEmailToken(ref body, "[$EventID]", "-");
            }

            var msg = EmailTemplateUtility.CreateMessage(
                Federation.Email, Federation.ShortTitle,
                Federation.Email, Federation.ShortTitle,
                subject, body);

            // Append stack trace
            if (mode == Mode.Error && Session[Constants.SessionException] != null)
            {
                System.Net.Mail.Attachment att;

                using (var mem = new MemoryStream(Encoding.UTF8.GetBytes(new HttpUnhandledException(ex.Message, ex).GetHtmlErrorMessage())))
                {
                    att = new System.Net.Mail.Attachment(mem, "error.html");

                    msg.Attachments.Add(att);
                    EmailTemplateUtility.SendMessage(msg);
                }
            }
            else
            {
                EmailTemplateUtility.SendMessage(msg);
            }

            FeedbackForm.Visible = false;
            SuccessForm.Visible = true;
        }
예제 #25
0
 private void RenderFailed(JobInstance ji)
 {
     Response.Output.WriteLine("<p>An exception occured: {0}</p>", ji.ExceptionMessage);
 }
예제 #26
0
        public static JobDescription GetJob(JobInstance job, QueryFactory queryFactory)
        {
            // In this function, we don't directly deserialize query parameters because
            // that could break old job definitions once the job format changes. It's
            // save to read parameters from the xml representation directly.

            var res = new JobDescription();
            res.Job = job;

            if (queryJobDefinitions.ContainsKey(job.JobDefinitionReference.Guid))
            {
                res.JobType = JobType.Query;

                // debug code
                if (job.Parameters.ContainsKey("Query"))
                {
                    var xml = new XmlDocument();
                    xml.LoadXml(job.Parameters["Query"].XmlValue);

                    res.Query = GetXmlInnerText(xml, "Query/QueryString");
                    res.SchemaName = GetXmlInnerText(xml, "Query/Destination/Table/SchemaName");
                    res.ObjectName = GetXmlInnerText(xml, "Query/Destination/Table/ObjectName");
                }
                else
                {
                    // This is probably a wrong job in the database
                }
            }
            else if (exportJobDefinitions.ContainsKey(job.JobDefinitionReference.Guid))
            {
                res.JobType = JobType.ExportTable;

                if (job.Parameters.ContainsKey("Parameters"))
                {
                    var xml = new XmlDocument();
                    xml.LoadXml(job.Parameters["Parameters"].XmlValue);

                    res.SchemaName = GetXmlInnerText(xml, "ExportTable/Source/SchemaName");
                    res.ObjectName = GetXmlInnerText(xml, "ExportTable/Source/ObjectName");
                    res.Path = GetXmlInnerText(xml, "ExportTable/Destination/Path");
                }
            }
            else
            {
                res.JobType = JobType.Unknown;
            }

            return res;
        }
예제 #27
0
        private JobInstance LoadJobInstance(Context context, Job job)
        {
            var ji = new JobInstance(context);
            ji.Guid = job.Guid;
            ji.Load();

            return ji;
        }
예제 #28
0
        public static JobDescription GetJobDescription(JobInstance job)
        {
            // In this function, we don't directly deserialize query parameters because
            // that could break old job definitions once the job format changes. It's
            // save to read parameters from the xml representation directly.

            var jobDescription = new JobDescription();
            jobDescription.Job = job;

            try
            {
                if (queryJobDefinitions.ContainsKey(job.JobDefinitionReference.Guid))
                {
                    GetQueryJobDescription(job, jobDescription);
                }
                else if (exportJobDefinitions.ContainsKey(job.JobDefinitionReference.Guid))
                {
                    GetExportJobDescription(job, jobDescription);
                }
                else
                {
                    jobDescription.JobType = JobType.Unknown;
                }
            }
            catch (Exception)
            {
                jobDescription.JobType = JobType.Unknown;
            }

            return jobDescription;
        }
예제 #29
0
        /// <summary>
        /// Finished the execution of a job and records the results in the registry.
        /// </summary>
        /// <param name="workflowInstanceId"></param>
        /// <param name="eventType"></param>
        private void FinishJob(Job job, HostEventArgs e)
        {
            using (Context context = ContextManager.Instance.CreateContext(ConnectionMode.AutoOpen, TransactionMode.AutoCommit))
            {
                context.JobGuid = job.Guid;
                context.ContextGuid = contextGuid;

                JobInstance ji = new JobInstance(context);
                ji.Guid = job.Guid;
                ji.Load();

                // Update execution status, error message and finish time
                switch (e.EventType)
                {
                    case WorkflowEventType.Completed:
                        ji.JobExecutionStatus = JobExecutionState.Completed;
                        break;
                    case WorkflowEventType.Cancelled:
                        ji.JobExecutionStatus = JobExecutionState.Cancelled;
                        break;
                    case WorkflowEventType.TimedOut:
                        ji.JobExecutionStatus = JobExecutionState.TimedOut;
                        break;
                    case WorkflowEventType.Persisted:
                        ji.JobExecutionStatus = JobExecutionState.Persisted;
                        break;
                    case WorkflowEventType.Failed:
                        ji.JobExecutionStatus = JobExecutionState.Failed;
                        ji.ExceptionMessage = e.ExceptionMessage;
                        break;
                }

                // Update registry
                ji.DateFinished = DateTime.Now;
                ji.Save();

                ji.ReleaseLock(false);
                ji.RescheduleIfRecurring();

                // Do local bookkeeping
                lock (runningJobs)
                {
                    lock (Cluster.Queues[job.QueueGuid].Jobs)
                    {
                        Cluster.Queues[job.QueueGuid].Jobs.Remove(job.Guid);
                    }

                    runningJobs.Remove(job.WorkflowInstanceId);
                }

                if (interactive)
                {
                    Console.WriteLine("Finishing job: {0}", ji.Guid);
                }
            }
        }
예제 #30
0
        public JobInstance CreateJobInstance(string queueName, ScheduleType scheduleType)
        {
            JobInstance job = new JobInstance(Context);

            job.Name = GenerateJobID();
            job.JobDefinitionReference.Name = GetFullyQualifiedName();
            job.ParentReference.Name = queueName;
            job.WorkflowTypeName = this.workflowTypeName;
            job.JobExecutionStatus = Jhu.Graywulf.Registry.JobExecutionState.Scheduled;
            job.ScheduleType = scheduleType;

            // Create workflow parameters
            var rh = JobReflectionHelper.CreateInstance(this.workflowTypeName);
            foreach (var par in rh.GetParameters().Values)
            {
                job.Parameters.Add(par.Name, new JobParameter(par));
            }

            return job;
        }
예제 #31
0
        private void PersistJob(Job job)
        {
            using (Context context = ContextManager.Instance.CreateContext(ConnectionMode.AutoOpen, TransactionMode.AutoCommit))
            {
                context.JobGuid = job.Guid;
                context.ContextGuid = contextGuid;

                var ji = new JobInstance(context);
                ji.Guid = job.Guid;
                ji.Load();

                // Update registry
                ji.JobExecutionStatus = JobExecutionState.Persisting;

                ji.Save();
            }

            // Update job status
            job.Status = JobStatus.Persisted;

            appDomains[job.AppDomainID].PersistJob(job);
        }
예제 #32
0
 /// <summary>
 /// Copy contructor for doing deep copy of the <b>Database Definition</b> objects.
 /// </summary>
 /// <param name="old">The <b>Database Definition</b> to copy from.</param>
 public JobInstance(JobInstance old)
     : base(old)
 {
     CopyMembers(old);
 }
예제 #33
0
 private void InitializeMembers()
 {
     this.job = null;
     this.jobType = JobType.Unknown;
     this.query = null;
     this.schemaName = null;
     this.objectName = null;
     this.path = null;
 }
예제 #34
0
        private static void GetExportJobDescription(JobInstance job, JobDescription jobDescription)
        {
            jobDescription.JobType = JobType.ExportTable;

            if (job.Parameters.ContainsKey("Parameters"))
            {
                var xml = new XmlDocument();
                xml.LoadXml(job.Parameters["Parameters"].XmlValue);

                jobDescription.SchemaName = GetXmlInnerText(xml, "ExportTables/Sources/TableOrView/SchemaName");
                jobDescription.ObjectName = GetXmlInnerText(xml, "ExportTables/Sources/TableOrView/ObjectName");
                jobDescription.Path = GetXmlInnerText(xml, "ExportTables/Destinations/DataFileBase/Uri");
            }
        }