Ejemplo n.º 1
0
 internal void AddQueueInstance(QueueInstance qi)
 {
     if (qi.QueueInstanceID != 0)
     {
         _actions.Remove(qi.QueueInstanceID.ToString());
         _actions.Add(qi.QueueInstanceID.ToString(), qi);
     }
     else
     {
         _actions.Add("", qi);
     }
 }
Ejemplo n.º 2
0
        protected override void Execute(CodeActivityContext context)
        {
            // Get the connection string
            DBConnection ext = context.GetExtension <DBConnection>();

            if (ext == null)
            {
                throw new InvalidProgramException("No connection string available");
            }

            // Lookup the QueueInstance
            UserTasksDataContext dc = new UserTasksDataContext(ext.ConnectionString);

            dc.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, dc.QueueInstances);
            QueueInstance qi = dc.QueueInstances.SingleOrDefault(x => x.QueueInstanceKey == QueueInstanceKey.Get(context));

            if (qi == null)
            {
                throw new InvalidProgramException("The specified request (" + QueueInstanceKey.Get(context) + ") was not found");
            }

            if (qi.AssignedOperatorID != null)
            {
                qi.AssignedOperatorID = null;
                qi.AssignedDate       = null;

                // Update the QueueInstance record
                PersistQueueInstance persist = context.GetExtension <PersistQueueInstance>();
                persist.AddQueueInstance(qi);
            }

            // Add a custom track record
            CustomTrackingRecord userRecord = new CustomTrackingRecord("UnAssign")
            {
                Data =
                {
                    { "QueueInstanceKey", qi.QueueInstanceKey  },
                    { "SubQueueID",       qi.CurrentSubQueueID },
                    { "QC",               qi.QC                }
                }
            };

            // Emit the custom tracking record
            context.Track(userRecord);
        }
Ejemplo n.º 3
0
        protected override void Execute(CodeActivityContext context)
        {
            // Get the connection string
            DBConnection ext = context.GetExtension <DBConnection>();

            if (ext == null)
            {
                throw new InvalidProgramException("No connection string available");
            }

            UserTasksDataContext dc = new UserTasksDataContext(ext.ConnectionString);

            // Lookup the QueueInstance
            dc.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, dc.QueueInstances);
            QueueInstance qi = dc.QueueInstances.SingleOrDefault(x => x.QueueInstanceKey == QueueInstanceKey.Get(context));

            if (qi == null)
            {
                throw new InvalidProgramException("The specified request (" + QueueInstanceKey.Get(context) + ") was not found");
            }

            QueueInstance.Set(context, qi);
            ConnectionString.Set(context, ext.ConnectionString);
        }
Ejemplo n.º 4
0
        protected override void Execute(CodeActivityContext context)
        {
            // Get the connection string
            DBConnection ext = context.GetExtension <DBConnection>();

            if (ext == null)
            {
                throw new InvalidProgramException("No connection string available");
            }

            // Lookup the Queue
            UserTasksDataContext dc = new UserTasksDataContext(ext.ConnectionString);
            Queue q = dc.Queues.SingleOrDefault(x => x.QueueName == QueueName.Get(context));

            if (q == null)
            {
                throw new InvalidProgramException("The specified queue (" + QueueName.Get(context) + ") was not found");
            }

            SubQueue s = dc.SubQueues
                         .SingleOrDefault(x => x.QueueID == q.QueueID &&
                                          x.SubQueueName == SubQueueName.Get(context));

            if (s == null)
            {
                throw new InvalidProgramException("The specified sub-queue (" + SubQueueName.Get(context) + ") was not found");
            }

            // Create and initialize a QueueInstance object
            QueueInstance qi = new QueueInstance();

            qi.QueueInstanceKey  = Guid.NewGuid();
            qi.CurrentSubQueueID = s.SubQueueID;
            qi.CreateDate        = DateTime.UtcNow;
            qi.InstanceID        = context.WorkflowInstanceId;

            // Setup the initial values
            qi.AssignedDate       = null;
            qi.AssignedOperatorID = null;
            qi.QC       = false;
            qi.Priority = null;

            // Insert the Request record
            PersistQueueInstance persist = context.GetExtension <PersistQueueInstance>();

            persist.AddQueueInstance(qi);

            // Return the QueueInstance object
            QueueInstanceKey.Set(context, qi.QueueInstanceKey);

            CustomTrackingRecord userRecord = new CustomTrackingRecord("Start")
            {
                Data =
                {
                    { "QueueInstanceKey", qi.QueueInstanceKey  },
                    { "SubQueueID",       qi.CurrentSubQueueID }
                }
            };

            // Emit the custom tracking record
            context.Track(userRecord);
        }
Ejemplo n.º 5
0
        protected override void Execute(CodeActivityContext context)
        {
            // Get the connection string
            DBConnection ext = context.GetExtension <DBConnection>();

            if (ext == null)
            {
                throw new InvalidProgramException("No connection string available");
            }

            UserTasksDataContext dc = new UserTasksDataContext(ext.ConnectionString);

            Queue    q          = null;
            SubQueue sq         = null;
            int      queueID    = 0;
            int      subQueueID = 0;

            if (QueueName.Get(context) != "" && SubQueueName.Get(context) != "None")
            {
                // Lookup the queue and subqueue
                q = dc.Queues.SingleOrDefault(x => x.QueueName == QueueName.Get(context));
                if (q == null)
                {
                    throw new InvalidProgramException("The specified queue (" + QueueName.Get(context) + ") was not found");
                }

                sq = dc.SubQueues.SingleOrDefault(x => x.QueueID == q.QueueID &&
                                                  x.SubQueueName == SubQueueName.Get(context));
                if (sq == null)
                {
                    throw new InvalidProgramException("The specified subqueue (" +
                                                      QueueName.Get(context) + " - " +
                                                      SubQueueName.Get(context) + ") was not found");
                }

                queueID    = q.QueueID;
                subQueueID = sq.SubQueueID;
            }

            // Lookup the QueueInstance
            dc.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, dc.QueueInstances);
            QueueInstance qi = dc.QueueInstances.SingleOrDefault(x => x.QueueInstanceKey == QueueInstanceKey.Get(context));

            if (qi == null)
            {
                throw new InvalidProgramException("The specified request (" + QueueInstanceKey.Get(context) + ") was not found");
            }

            // Assign the QueueInstance to this subqueue
            if (sq != null)
            {
                qi.CurrentSubQueueID = sq.SubQueueID;
            }
            else
            {
                qi.CurrentSubQueueID = null;
            }

            qi.AssignedDate       = null;
            qi.AssignedOperatorID = null;
            qi.QC       = false;
            qi.Priority = null;

            // Update the QueueInstance record
            PersistQueueInstance persist = context.GetExtension <PersistQueueInstance>();

            persist.AddQueueInstance(qi);

            // Add a custom track record
            CustomTrackingRecord userRecord = new CustomTrackingRecord("Route")
            {
                Data =
                {
                    { "QueueInstanceKey", qi.QueueInstanceKey  },
                    { "SubQueueID",       qi.CurrentSubQueueID }
                }
            };

            // Emit the custom tracking record
            context.Track(userRecord);
        }
Ejemplo n.º 6
0
        public Cluster Install(bool system, string clusterName, string username, string email, string password)
        {
            cluster = new Cluster(Context)
            {
                Name   = clusterName,
                System = system,
            };
            cluster.Save();

            // Create machine roles and machines

            //      -- controller role
            var mrcont = new MachineRole(cluster)
            {
                Name            = Constants.ControllerMachineRoleName,
                System          = system,
                MachineRoleType = MachineRoleType.StandAlone,
            };

            mrcont.Save();

            var sv = new ServerVersion(mrcont)
            {
                Name   = Constants.ServerVersionName,
                System = system,
            };

            sv.Save();

            var mcont = new Machine(mrcont)
            {
                Name = Constants.ControllerMachineName,
            };

            mcont.Save();

            var sicont = new ServerInstance(mcont)
            {
                Name          = Constants.ServerInstanceName,
                ServerVersion = sv,
            };

            sicont.Save();


            //      -- node role
            var mrnode = new MachineRole(cluster)
            {
                Name            = Constants.NodeMachineRoleName,
                MachineRoleType = MachineRoleType.MirroredSet,
            };

            mrnode.Save();

            var nodesv = new ServerVersion(mrnode)
            {
                Name = Constants.ServerVersionName,
            };

            nodesv.Save();

            //      -- Create a node

            /*
             * Machine mnode = new Machine(Context, mrnode);
             * mnode.Name = Constants.NodeMachineName;
             * mnode.Save();
             *
             * si = new ServerInstance(Context, mnode);
             * si.Name = Constants.ServerInstanceName;
             * si.ServerVersionReference.Value = sv;
             * si.Save();*/

            // Create the shared domain for cluster level databases and users
            var domain = new Domain(cluster)
            {
                Name   = Constants.SharedDomainName,
                Email  = email,
                System = system,
            };

            domain.Save();

            // Create administrator group and user
            GenerateAdminGroup(system);
            GenerateAdmin(system, username, email, password);

            // Create the shared feredation
            var federation = new Federation(domain)
            {
                Name                       = Constants.SharedFederationName,
                Email                      = email,
                System                     = system,
                ControllerMachine          = mcont,
                SchemaSourceServerInstance = sicont,
            };

            federation.Save();

            // Temp database definition
            var tempdd = new DatabaseDefinition(federation)
            {
                Name       = Constants.TempDbName,
                System     = system,
                LayoutType = DatabaseLayoutType.Monolithic,
                DatabaseInstanceNamePattern = Constants.TempDbInstanceNamePattern,
                DatabaseNamePattern         = Constants.TempDbNamePattern,
                SliceCount     = 1,
                PartitionCount = 1,
            };

            tempdd.Save();

            var tempddi = new DatabaseDefinitionInstaller(tempdd);

            tempddi.GenerateDefaultChildren(nodesv, Constants.TempDbName);

            // Create cluster level jobs and queues

            //      -- admin queue definition
            QueueDefinition qd = new QueueDefinition(cluster)
            {
                Name   = Constants.MaintenanceQueueDefinitionName,
                System = system,
            };

            qd.Save();

            QueueInstance qi = new QueueInstance(mcont)
            {
                Name         = Constants.MaintenanceQueueName,
                RunningState = Registry.RunningState.Running,
            };

            qi.QueueDefinitionReference.Value = qd;
            qi.Save();

            //      -- long queue definition
            qd = new QueueDefinition(cluster)
            {
                Name = Constants.LongQueueDefinitionName
            };
            qd.Save();

            qi = new QueueInstance(mcont)
            {
                Name         = Constants.LongQueueName,
                RunningState = Registry.RunningState.Running,
            };
            qi.QueueDefinitionReference.Value = qd;
            qi.Save();

            //      -- quick queue definition
            qd = new QueueDefinition(cluster)
            {
                Name = Constants.QuickQueueDefinitionName,
            };
            qd.Save();

            qi = new QueueInstance(mcont)
            {
                Name         = Constants.QuickQueueName,
                RunningState = Registry.RunningState.Running,
            };
            qi.QueueDefinitionReference.Value = qd;
            qi.Save();

            //      -- database mirror job
            var jd = new JobDefinition(federation)
            {
                Name             = typeof(Jhu.Graywulf.Jobs.MirrorDatabase.MirrorDatabaseJob).Name,
                System           = system,
                WorkflowTypeName = typeof(Jhu.Graywulf.Jobs.MirrorDatabase.MirrorDatabaseJob).AssemblyQualifiedName,
            };

            jd.DiscoverWorkflowParameters();
            jd.Save();

            //      -- test job
            jd = new JobDefinition(federation)
            {
                Name             = typeof(Jhu.Graywulf.Jobs.Test.TestJob).Name,
                System           = system,
                WorkflowTypeName = typeof(Jhu.Graywulf.Jobs.Test.TestJob).AssemblyQualifiedName,
            };
            jd.DiscoverWorkflowParameters();
            jd.Save();

            return(cluster);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Updates the queue information based on the values
 /// read from the registry.
 /// </summary>
 /// <param name="q"></param>
 public void Update(QueueInstance q)
 {
     this.guid    = q.Guid;
     this.timeout = TimeSpan.FromSeconds(q.Timeout);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Queries the registry for new jobs to schedule
        /// </summary>
        private void PollNewJobs()
        {
            List <Job> temp = new List <Job>();

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

                foreach (var queue in Cluster.Queues.Values)
                {
                    var qi = new QueueInstance(context);
                    qi.Guid = queue.Guid;
                    qi.Load();

                    var ji = qi.GetNextJobInstance();

                    if (ji != null)
                    {
                        var user = new User(context);
                        user.Guid = ji.UserGuidOwner;
                        user.Load();

                        var job = new Job()
                        {
                            Guid             = ji.Guid,
                            JobID            = ji.JobID,
                            UserGuid         = user.Guid,
                            UserName         = user.Name,
                            QueueGuid        = ji.ParentReference.Guid,
                            WorkflowTypeName = ji.WorkflowTypeName,
                        };

                        if ((ji.JobExecutionStatus & JobExecutionState.Scheduled) != 0)
                        {
                            job.Status            = JobStatus.Starting;
                            ji.JobExecutionStatus = JobExecutionState.Starting;
                        }
                        else if ((ji.JobExecutionStatus & JobExecutionState.Persisted) != 0)
                        {
                            // Save cancel requested flag here
                            ji.JobExecutionStatus ^= JobExecutionState.Persisted;
                            ji.JobExecutionStatus |= JobExecutionState.Starting;

                            job.Status = JobStatus.Resuming;
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }

                        ji.Save();

                        lock (queue)
                        {
                            queue.Jobs.Add(job.Guid, job);
                        }

                        temp.Add(job);
                    }
                }
            }

            foreach (var job in temp)
            {
                StartOrResumeJob(job);
            }
        }
Ejemplo n.º 9
0
        protected override void Execute(CodeActivityContext context)
        {
            // Get the connection string
            DBConnection ext = context.GetExtension <DBConnection>();

            if (ext == null)
            {
                throw new InvalidProgramException("No connection string available");
            }

            // Lookup the operator
            UserTasksDataContext dc = new UserTasksDataContext(ext.ConnectionString);
            OperatorConfig       oc = dc.OperatorConfigs.SingleOrDefault(x => x.OperatorKey == OperatorKey.Get(context));

            if (oc == null)
            {
                oc                     = new OperatorConfig();
                oc.OperatorKey         = OperatorKey.Get(context);
                oc.UnderEvaluation     = false;
                oc.Frequency           = 5;
                oc.NumberSinceLastEval = 0;

                dc.OperatorConfigs.InsertOnSubmit(oc);
                dc.SubmitChanges();
            }

            // Determine the Queue info
            char[]   delimiter = { '|' };
            string[] values    = QueueKey.Get(context).Split(delimiter, 3);

            // Lookup the queue and subqueue
            Queue q = dc.Queues.SingleOrDefault(x => x.QueueName == values[0]);

            if (q == null)
            {
                throw new InvalidProgramException("The specified queue (" + values[0] + ") was not found");
            }

            SubQueue sq = dc.SubQueues.SingleOrDefault(x => x.QueueID == q.QueueID &&
                                                       x.SubQueueName == values[1]);

            if (sq == null)
            {
                throw new InvalidProgramException("The specified subqueue (" +
                                                  values[0] + " - " +
                                                  values[1] + ") was not found");
            }

            bool bQC = bool.Parse(values[2]);

            if (sq.AllowSelection)
            {
                // Return all the available instances
                IEnumerable <QueueInstance> instances;

                if (bQC)
                {
                    instances = dc.QueueInstances
                                .Where(x => x.CurrentSubQueueID == sq.SubQueueID &&
                                       x.QC == bQC &&
                                       (x.AssignedOperatorID == null ||
                                        x.AssignedOperatorID == oc.OperatorConfigID))
                                .OrderBy(x => x.Priority.Value)
                                .OrderBy(x => x.CreateDate);
                }
                else
                {
                    instances = dc.QueueInstances
                                .Where(x => x.CurrentSubQueueID == sq.SubQueueID &&
                                       x.QC == bQC &&
                                       (x.AssignedOperatorID == null ||
                                        x.AssignedOperatorID == oc.OperatorConfigID))
                                .OrderBy(x => x.CreateDate);
                }

                if (instances.Count() > 0)
                {
                    QueueInstance[] qiList = new QueueInstance[instances.Count()];
                    int             i      = 0;
                    foreach (QueueInstance r in instances)
                    {
                        qiList[i++] = r;
                    }

                    QueueInstanceList.Set(context, qiList);
                }
            }
            else
            {
                // Return the oldest instance
                IEnumerable <QueueInstance> instances;
                if (bQC)
                {
                    instances = dc.QueueInstances
                                .Where(x => x.CurrentSubQueueID == sq.SubQueueID &&
                                       x.QC == bQC &&
                                       (x.AssignedOperatorID == null ||
                                        x.AssignedOperatorID == oc.OperatorConfigID))
                                .OrderBy(x => x.Priority.Value)
                                .OrderBy(x => x.CreateDate)
                                .Take(1);
                }
                else
                {
                    instances = dc.QueueInstances
                                .Where(x => x.CurrentSubQueueID == sq.SubQueueID &&
                                       x.QC == bQC &&
                                       (x.AssignedOperatorID == null ||
                                        x.AssignedOperatorID == oc.OperatorConfigID))
                                .OrderBy(x => (x.Priority.HasValue ? 1 : 0) * x.Priority.Value * (bQC ? 1 : 0))
                                .OrderBy(x => x.CreateDate)
                                .Take(1);
                }

                if (instances.Count() > 0)
                {
                    QueueInstance qi = instances.First <QueueInstance>();
                    qi.AssignedOperatorID = oc.OperatorConfigID;
                    dc.SubmitChanges();

                    QueueInstance[] qiList = new QueueInstance[1];
                    qiList[0] = qi;

                    QueueInstanceList.Set(context, qiList);
                }
            }
        }
Ejemplo n.º 10
0
        protected override void CollectValues
            (out IDictionary <XName, object> readWriteValues,
            out IDictionary <XName, object> writeOnlyValues)
        {
            // We're not actually providing data to the caller
            readWriteValues = null;
            writeOnlyValues = null;

            //_actions.Clear();

            // See if there is any work to do...
            if (_actions.Count > 0)
            {
                // Get the current transaction
                Transaction t = System.Transactions.Transaction.Current;

                // Setup the DataContext
                UserTasksDataContext dc = new UserTasksDataContext(_connectionString);

                // Open the connection, if necessary
                if (dc.Connection.State == System.Data.ConnectionState.Closed)
                {
                    dc.Connection.Open();
                }

                if (t != null)
                {
                    dc.Connection.EnlistTransaction(t);
                }

                // Process each object in our work queue
                foreach (KeyValuePair <string, QueueInstance> kvp in _actions)
                {
                    QueueInstance qi = kvp.Value as QueueInstance;

                    // Perform the insert
                    if (kvp.Key == "")
                    {
                        dc.QueueInstances.InsertOnSubmit(qi);
                    }

                    // Perform the update
                    else
                    {
                        dc.Refresh(RefreshMode.OverwriteCurrentValues, dc.QueueInstances);
                        QueueInstance qiTmp = dc.QueueInstances.SingleOrDefault <QueueInstance>
                                                  (x => x.QueueInstanceID == qi.QueueInstanceID);

                        if (qiTmp != null)
                        {
                            qiTmp.InstanceID         = qi.InstanceID;
                            qiTmp.AssignedDate       = qi.AssignedDate;
                            qiTmp.AssignedOperatorID = qi.AssignedOperatorID;
                            qiTmp.CurrentSubQueueID  = qi.CurrentSubQueueID;
                            qiTmp.QC = qi.QC;
                        }
                    }
                }

                // Submit all the changes to the database
                dc.SubmitChanges();

                // Remove all objects since the changes have been submitted
                _actions.Clear();
            }
        }