Ejemplo n.º 1
0
        public void SetData(ThreadStorageView thread)
        {
            try
            {
                this._thread = thread;

                btnStop.Enabled = (_thread.State != ThreadState.Dead && _thread.State!=ThreadState.Finished );

                this.lbName.Text = _thread.ThreadId.ToString();
                txApplication.Text = _thread.ApplicationId;

                txExecutor.Text = _thread.ExecutorId;

                if (_thread.TimeStarted!=DateTime.MinValue)
                    txCreated.Text = _thread.TimeStarted.ToString();

                if (_thread.TimeFinished!=DateTime.MinValue)
                    txCompleted.Text = _thread.TimeFinished.ToString();

                txState.Text = _thread.StateString;
                txPriority.Text = _thread.Priority.ToString();

                ExecutorStorageView executor = console.Manager.Admon_GetExecutor(console.Credentials, _thread.ExecutorId);
                if (executor != null && executor.HostName != null)
                {
                        txExecutor.Text = executor.HostName;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error getting thread properties:"+ex.Message, "Thread properties", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        public int AddThread(ThreadStorageView thread)
        {
            if (thread == null)
            {
                return -1;
            }

            IDataParameter timeStartedParameter = GetParameter(DatabaseParameterDecoration() + "time_started", thread.TimeStarted, DbType.DateTime);
            if (!thread.TimeStartedSet)
            {
                timeStartedParameter.Value = DBNull.Value;
            }

            IDataParameter timeFinishedParameter = GetParameter(DatabaseParameterDecoration() + "time_finished", thread.TimeFinished, DbType.DateTime);
            if (!thread.TimeFinishedSet)
            {
                timeFinishedParameter.Value = DBNull.Value;
            }

            IDataParameter executorIdParameter;

            if (thread.ExecutorId != null)
            {
                executorIdParameter = GetParameter(DatabaseParameterDecoration() + "executor_id", thread.ExecutorId, DbType.Guid);
            }
            else
            {
                executorIdParameter = GetParameter(DatabaseParameterDecoration() + "executor_id", DBNull.Value, DbType.Guid);
            }

            object threadIdObject = RunSqlReturnScalar(String.Format("insert into thread(application_id, executor_id, thread_id, state, time_started, time_finished, priority, failed) values ('{1}', {0}executor_id, {3}, {4}, {0}time_started, {0}time_finished, {5}, {6})",
                DatabaseParameterDecoration(),
                thread.ApplicationId,
                thread.ExecutorId,
                thread.ThreadId,
                (int)thread.State,
                thread.Priority,
                Convert.ToInt16(thread.Failed)
                ),
                executorIdParameter, timeStartedParameter, timeFinishedParameter);

            return Convert.ToInt32(threadIdObject);
        }
        private ThreadStorageView[] DecodeThreadFromDataReader(IDataReader dataReader)
        {
            if (dataReader == null)
            {
                return new ThreadStorageView[0];
            }

            ArrayList threads = new ArrayList();

            using(dataReader)
            {
                while(dataReader.Read())
                {
                    int internalThreadId = dataReader.GetInt32(dataReader.GetOrdinal("internal_thread_id"));

                    // in SQL the application ID is stored as a GUID so we use GetValue instead of GetString in order to maximize compatibility with other databases
                    string applicationId = dataReader.GetValue(dataReader.GetOrdinal("application_id")).ToString();
                    string executorId = dataReader.IsDBNull(dataReader.GetOrdinal("executor_id")) ? null : dataReader.GetValue(dataReader.GetOrdinal("executor_id")).ToString();

                    int threadId = dataReader.GetInt32(dataReader.GetOrdinal("thread_id"));
                    ThreadState state = (ThreadState)dataReader.GetInt32(dataReader.GetOrdinal("state"));

                    DateTime timeStarted = GetDateTime(dataReader, "time_started");
                    DateTime timeFinished = GetDateTime(dataReader, "time_finished");

                    int priority = dataReader.GetInt32(dataReader.GetOrdinal("priority"));
                    bool failed = dataReader.IsDBNull(dataReader.GetOrdinal("failed")) ? false : dataReader.GetBoolean(dataReader.GetOrdinal("failed"));

                    ThreadStorageView thread = new ThreadStorageView(
                        internalThreadId,
                        applicationId,
                        executorId,
                        threadId,
                        state,
                        timeStarted,
                        timeFinished,
                        priority,
                        failed
                        );

                    threads.Add(thread);
                }

                dataReader.Close();
            }

            return (ThreadStorageView[])threads.ToArray(typeof(ThreadStorageView));
        }
        public void UpdateThread(ThreadStorageView updatedThread)
        {
            if (updatedThread == null)
            {
                return;
            }

            IDataParameter timeStartedParameter = GetParameter(DatabaseParameterDecoration() + "time_started", updatedThread.TimeStarted, DbType.DateTime);
            if (!updatedThread.TimeStartedSet)
            {
                timeStartedParameter.Value = DBNull.Value;
            }

            IDataParameter timeFinishedParameter = GetParameter(DatabaseParameterDecoration() + "time_finished", updatedThread.TimeFinished, DbType.DateTime);
            if (!updatedThread.TimeFinishedSet)
            {
                timeFinishedParameter.Value = DBNull.Value;
            }

            IDataParameter executorIdParameter;

            if (updatedThread.ExecutorId != null)
            {
                executorIdParameter = GetParameter(DatabaseParameterDecoration() + "executor_id", updatedThread.ExecutorId, DbType.Guid);
            }
            else
            {
                executorIdParameter = GetParameter(DatabaseParameterDecoration() + "executor_id", DBNull.Value, DbType.Guid);
            }

            RunSql(String.Format("update thread set application_id = '{2}', executor_id = {0}executor_id, thread_id = {4}, state = {5}, time_started = {0}time_started, time_finished = {0}time_finished, priority = {6}, failed = {7} where internal_thread_id = {1}",
                DatabaseParameterDecoration(),
                updatedThread.InternalThreadId,
                updatedThread.ApplicationId,
                updatedThread.ExecutorId,
                updatedThread.ThreadId,
                (int)updatedThread.State,
                updatedThread.Priority,
                Convert.ToInt16(updatedThread.Failed)
                ),
                executorIdParameter, timeStartedParameter, timeFinishedParameter);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes this thread.
        /// </summary>
        /// <param name="primary">specifies if this thread is a primary thread. A thread is primary if it is created and scheduled by the same manager</param>
        public void Init(bool primary)
        {
            if (primary)
            {
                ThreadStorageView threadStorage = new ThreadStorageView(_AppId, _Id, ThreadState.Ready);

                ManagerStorageFactory.ManagerStorage().AddThread(threadStorage);
            }
            else
            {
                ApplicationStorageView applicationStorage = ManagerStorageFactory.ManagerStorage().GetApplication(_AppId);

                if (applicationStorage == null)
                {
                    applicationStorage = new ApplicationStorageView(
                        _AppId,
                        ApplicationState.AwaitingManifest,
                        DateTime.Now,
                        false,
                        ""/* TODO: What's the username here?*/);

                    ManagerStorageFactory.ManagerStorage().AddApplication(applicationStorage);
                }

                ThreadStorageView threadStorage = new ThreadStorageView(_AppId, _Id, ThreadState.Ready);

                ManagerStorageFactory.ManagerStorage().AddThread(threadStorage);
            }
        }
Ejemplo n.º 6
0
        public void DeleteThread(ThreadStorageView threadToDelete)
        {
            if (threadToDelete == null)
            {
                return;
            }

            ArrayList remainingThreads = new ArrayList();

            foreach (ThreadStorageView thread in _threads)
            {
                if (thread.ApplicationId != threadToDelete.ApplicationId || thread.ThreadId != threadToDelete.ThreadId)
                {
                    remainingThreads.Add(thread);
                }
            }

            _threads = remainingThreads;
        }
Ejemplo n.º 7
0
        public void UpdateThreadTest1()
        {
            string applicationId = Guid.NewGuid().ToString();
            string executorId1 = Guid.NewGuid().ToString();
            string executorId2 = Guid.NewGuid().ToString();

            int threadId = 122;

            // TB: due to rounding errors the milliseconds might be lost in the database storage.
            // TB: I think this is OK so we create a test DateTime without milliseconds
            DateTime now = DateTime.Now;
            DateTime timeStarted1 = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, 0);
            now = now.AddDays(1);
            DateTime timeFinished1 = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, 0);

            now = now.AddDays(1);
            DateTime timeStarted2 = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, 0);
            now = now.AddDays(1);
            DateTime timeFinished2 = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, 0);

            AddThread(applicationId, executorId1, threadId, ThreadState.Started, timeStarted1, timeFinished1, 4, true);

            // retrieve the newly added thread so we have the new internal thread id
            ThreadStorageView[] newThreads = ManagerStorage.GetThreads();

            ThreadStorageView updatedThread = new ThreadStorageView(newThreads[0].InternalThreadId, applicationId, executorId2, threadId, ThreadState.Dead, timeStarted2, timeFinished2, 7, false);

            ManagerStorage.UpdateThread(updatedThread);

            ThreadStorageView[] threads = ManagerStorage.GetThreads();

            Assert.AreEqual(1, threads.Length);
            Assert.AreEqual(applicationId, threads[0].ApplicationId);
            Assert.AreEqual(executorId2, threads[0].ExecutorId);
            Assert.AreEqual(threadId, threads[0].ThreadId);
            Assert.AreEqual(ThreadState.Dead, threads[0].State);
            Assert.AreEqual(timeStarted2, threads[0].TimeStarted);
            Assert.AreEqual(timeFinished2, threads[0].TimeFinished);
            Assert.AreEqual(7, threads[0].Priority);
            Assert.AreEqual(false, threads[0].Failed);
        }
Ejemplo n.º 8
0
        public int AddThread(ThreadStorageView thread)
        {
            if (thread == null)
            {
                return -1;
            }

            ArrayList threads = null;
            IObjectContainer container = GetStorage();
            try
            {
                IList<ArrayList> threadsList =
                    container.Query<ArrayList>(delegate(ArrayList threadsFinder)
                {
                    return true;
                });
                if (threadsList.Count > 0)
                    threads = threadsList[0];
                else
                    threads = new ArrayList();

                thread.InternalThreadId = threads.Count;
                threads.Add(thread);
                container.Set(threads);
            }
            finally
            {
                container.Close();
            }
            return thread.InternalThreadId;
        }
Ejemplo n.º 9
0
        public void AddThreadTestNullTimesAndExecutor()
        {
            string applicationId = Guid.NewGuid().ToString();
            int threadId = 23;

            ThreadStorageView thread = new ThreadStorageView(applicationId, threadId);

            ManagerStorage.AddThread(thread);
        }
Ejemplo n.º 10
0
        public void Admon_DeleteThread(SecurityCredentials sc, ThreadStorageView threadToDelete)
        {
            AuthenticateUser(sc);
            EnsurePermission(sc, Permission.ManageAllApps);

            logger.Debug(String.Format("Deleting thread {0}.", threadToDelete.ThreadId));

            ManagerStorageFactory.ManagerStorage().DeleteThread(threadToDelete);
        }
Ejemplo n.º 11
0
        private void AddThread(
            string applicationId,
            string executorId,
            int threadId,
            ThreadState state,
            DateTime timeStarted,
            DateTime timeFinished,
            int priority,
            bool failed
            )
        {
            ThreadStorageView thread = new ThreadStorageView(
                applicationId,
                executorId,
                threadId,
                state,
                timeStarted,
                timeFinished,
                priority,
                failed
                );

            ManagerStorage.AddThread(thread);
        }
Ejemplo n.º 12
0
        public void UpdateThreadTestNullExecutorIdAndTimes()
        {
            string applicationId = Guid.NewGuid().ToString();
            int threadId = 23;

            ThreadStorageView newThread = new ThreadStorageView(applicationId, threadId);

            ManagerStorage.AddThread(newThread);

            ThreadStorageView foundThread = ManagerStorage.GetThread(applicationId, threadId);

            foundThread.State = ThreadState.Started;

            ManagerStorage.UpdateThread(foundThread);

            ThreadStorageView thread = ManagerStorage.GetThread(applicationId, threadId);

            Assert.AreEqual(applicationId, thread.ApplicationId);
            Assert.IsNull(thread.ExecutorId);
            Assert.AreEqual(threadId, thread.ThreadId);
            Assert.AreEqual(ThreadState.Started, thread.State);
            Assert.IsFalse(thread.TimeStartedSet);
            Assert.IsFalse(thread.TimeFinishedSet);
            Assert.AreEqual(0, thread.Priority);
            Assert.AreEqual(false, thread.Failed);
        }
Ejemplo n.º 13
0
        public void UpdateThreadTest2()
        {
            string applicationId = Guid.NewGuid().ToString();
            string executorId = Guid.NewGuid().ToString();
            int threadId = 122;

            DateTime timeCreated = DateTime.Now.AddDays(1);

            ThreadStorageView updatedThread = new ThreadStorageView(applicationId, executorId, threadId, ThreadState.Dead, DateTime.Now, DateTime.Now.AddDays(1), 7, false);

            updatedThread.ThreadId = -1;

            ManagerStorage.UpdateThread(updatedThread);

            ThreadStorageView[] threads = ManagerStorage.GetThreads();

            Assert.AreEqual(0, threads.Length);
        }
        public void DeleteThread(ThreadStorageView threadToDelete)
        {
            if (threadToDelete == null)
            {
                return;
            }

            string sqlQuery;

            sqlQuery = string.Format("DELETE FROM thread WHERE application_id='{1}' and thread_id={0};",
                threadToDelete.ThreadId,
                threadToDelete.ApplicationId);

            logger.Debug(String.Format("Deleting thread {0} in application {1}.", threadToDelete.ThreadId, threadToDelete.ApplicationId));

            RunSql(sqlQuery);
        }
Ejemplo n.º 15
0
        public void UpdateThread(ThreadStorageView updatedThread)
        {
            if (updatedThread == null)
            {
                return;
            }

            ArrayList newThreadList = new ArrayList();

            foreach(ThreadStorageView thread in _threads)
            {
                if (thread.InternalThreadId == updatedThread.InternalThreadId)
                {
                    newThreadList.Add(updatedThread);
                }
                else
                {
                    newThreadList.Add(thread);
                }
            }

            _threads = newThreadList;
        }
Ejemplo n.º 16
0
        public void UpdateThread(ThreadStorageView updatedThread)
        {
            ThreadStorageView thread = null;
            IObjectContainer container = GetStorage();
            try
            {
                IList<ThreadStorageView> threads =
                    container.Query<ThreadStorageView>(delegate(ThreadStorageView threadFinder)
                {
                    return threadFinder.ThreadId == updatedThread.ThreadId;
                });

                if (threads.Count > 0)
                {
                    thread = threads[0];
                    container.Delete(thread);
                    container.Set(updatedThread);
                }
            }
            finally
            {
                container.Close();
            }
        }
Ejemplo n.º 17
0
        public int AddThread(ThreadStorageView thread)
        {
            if (thread == null)
            {
                return -1;
            }

            lock(_threads)
            {
                // generate the next threadID from the length, this will make sure the thread ID is unique
                // generating from the length also requires thread synchronization code here
                thread.InternalThreadId = _threads.Count;

                _threads.Add(thread);
            }

            return thread.InternalThreadId;
        }
Ejemplo n.º 18
0
        public void DeleteThread(ThreadStorageView threadToDelete)
        {
            if (threadToDelete == null)
            {
                return;
            }

            IObjectContainer container = GetStorage();
            try
            {
                IList<ThreadStorageView> threads =
                    container.Query<ThreadStorageView>(delegate(ThreadStorageView threadFinder)
                {
                    return threadFinder.ThreadId == threadToDelete.ThreadId;
                });

                if (threads.Count > 0)
                    container.Delete(threads[0]);
            }
            finally
            {
                container.Close();
            }
        }
Ejemplo n.º 19
0
        public void GetThreadsTestMinimumSetup()
        {
            string applicationId = Guid.NewGuid().ToString();
            int threadId = 125;

            ThreadStorageView newThread = new ThreadStorageView(applicationId, threadId);

            ManagerStorage.AddThread(newThread);

            ThreadStorageView thread = ManagerStorage.GetThread(applicationId, threadId);

            Assert.AreEqual(applicationId, thread.ApplicationId);
            Assert.IsNull(thread.ExecutorId);
            Assert.AreEqual(threadId, thread.ThreadId);
            Assert.AreEqual(ThreadState.Unknown, thread.State);
            Assert.IsFalse(thread.TimeStartedSet);
            Assert.IsFalse(thread.TimeFinishedSet);
            Assert.AreEqual(0, thread.Priority);
            Assert.AreEqual(false, thread.Failed);
        }