Пример #1
0
        public void AvailableDedicatedExecutorsTestSimpleScenario()
        {
            // add one that is OK
            ExecutorStorageView executor1 = new ExecutorStorageView(true, true, DateTime.Now, "hostname", 10, "username", 1, 1, 1, 1);
            // add one that is timed out
            ExecutorStorageView executor2 = new ExecutorStorageView(true, true, DateTime.Now.AddDays((-1)), "hostname", 10, "username", 1, 1, 1, 1);
            // add one that is not connected
            ExecutorStorageView executor3 = new ExecutorStorageView(false, false, DateTime.Now, "hostname", 10, "username", 1, 1, 1, 1);

            string executorId1 = _managerStorage.AddExecutor(executor1);
            string executorId2 = _managerStorage.AddExecutor(executor2);
            string executorId3 = _managerStorage.AddExecutor(executor3);

            string applicationId = Guid.NewGuid().ToString();

            // add a few threads
            _managerStorage.AddThread(new ThreadStorageView(applicationId, executorId1, 1, ThreadState.Started, DateTime.Now, DateTime.Now, 1, false));
            _managerStorage.AddThread(new ThreadStorageView(applicationId, executorId2, 1, ThreadState.Dead, DateTime.Now, DateTime.Now, 1, false));
            _managerStorage.AddThread(new ThreadStorageView(applicationId, executorId3, 1, ThreadState.Started, DateTime.Now, DateTime.Now, 1, false));

            ExecutorStorageView[] executors = _executorCollection.AvailableDedicatedExecutors;

            Assert.AreEqual(1, executors.Length);
            Assert.AreEqual(executorId2, executors[0].ExecutorId);
        }
Пример #2
0
        /// <summary>
        /// Queries the database to return the next dedicated schedule.
        /// </summary>
        /// <returns>DedicatedSchedule</returns>
        public DedicatedSchedule ScheduleDedicated()
        {
            ExecutorStorageView executorStorage = GetNextAvailableExecutor();

            if (executorStorage == null)
            {
                return(null);
            }

            ThreadStorageView threadStorage = GetNextAvailableThread();

            if (threadStorage == null)
            {
                return(null);
            }

            DedicatedSchedule dsched     = null;
            string            executorId = executorStorage.ExecutorId;
            string            appid      = threadStorage.ApplicationId;
            int threadId = threadStorage.ThreadId;
            int priority = threadStorage.Priority;

            ThreadIdentifier ti = new ThreadIdentifier(appid, threadId, priority);

            dsched = new DedicatedSchedule(ti, executorId);

            return(dsched);
        }
Пример #3
0
        public void UpdateExecutor(ExecutorStorageView updatedExecutor)
        {
            ExecutorStorageView executor  = null;
            IObjectContainer    container = GetStorage();

            try
            {
                IList <ExecutorStorageView> executors =
                    container.Query <ExecutorStorageView>(delegate(ExecutorStorageView executorFinder)
                {
                    return(executorFinder.ExecutorId == updatedExecutor.ExecutorId);
                });

                if (executors.Count > 0)
                {
                    executor = executors[0];
                    container.Delete(executor);
                    container.Set(updatedExecutor);
                }
            }
            finally
            {
                container.Close();
            }
        }
Пример #4
0
        public String AddExecutor(ExecutorStorageView executor)
        {
            if (executor == null)
            {
                return(null);
            }

            if (m_executors == null)
            {
                m_executors = new ArrayList();
            }

            String executorId;

            if (executor.ExecutorId == null)
            {
                executorId = Guid.NewGuid().ToString();
            }
            else
            {
                executorId = executor.ExecutorId;
            }

            executor.ExecutorId = executorId;

            m_executors.Add(executor);

            return(executorId);
        }
Пример #5
0
        public string AddExecutor(ExecutorStorageView executor)
        {
            if (executor == null)
            {
                return(null);
            }

            string executorId;

            if (executor.ExecutorId == null)
            {
                executorId = Guid.NewGuid().ToString();
            }
            else
            {
                executorId = executor.ExecutorId;
            }

            executor.ExecutorId = executorId;

            IObjectContainer container = GetStorage();

            try
            {
                container.Set(executor);
            }
            finally
            {
                container.Close();
            }
            return(executorId);
        }
Пример #6
0
        public ExecutorStorageView[] GetExecutors()
        {
            ExecutorStorageView[] allExecutors;
            IObjectContainer      container = GetStorage();

            try
            {
                IList <ExecutorStorageView> executors =
                    container.Query <ExecutorStorageView>(delegate(ExecutorStorageView executorFinder)
                {
                    return(true);
                });


                if (executors.Count > 0)
                {
                    allExecutors = new ExecutorStorageView[executors.Count];
                    executors.CopyTo(allExecutors, 0);
                }
                else
                {
                    allExecutors = new ExecutorStorageView[0];
                }
            }
            finally
            {
                container.Close();
            }
            return(allExecutors);
        }
Пример #7
0
 public void SetData(ExecutorStorageView ex)
 {
     RefreshData(ex);
     InitSystemPlot();
     RefreshSystemPlot();
     tmRefreshSystem.Enabled = true;
 }
Пример #8
0
        /// <summary>
        /// Return the next available ExecutorId.
        /// For an executor to be available the following considions have to be met:
        /// - executor is dedicated
        /// - executor is conected
        /// - executor has no threads running or scheduled
        /// </summary>
        /// <returns></returns>
        protected ExecutorStorageView GetNextAvailableExecutor()
        {
            // [email protected]; gets next available executor without bias based upon position in executors list.
            ExecutorStorageView[] executors = store.GetExecutors(TriStateBoolean.True, TriStateBoolean.True);

            for (int i = 0; i < executors.Length; i++)
            {
                nextExecutorIndex++;
                if (nextExecutorIndex >= executors.Length)
                {
                    nextExecutorIndex = 0;
                }

                ExecutorStorageView executor = executors[nextExecutorIndex];
                int threadsOnExecutor        = store.GetExecutorThreadCount(executor.ExecutorId,
                                                                            ThreadState.Ready,
                                                                            ThreadState.Scheduled,
                                                                            ThreadState.Started);
                if (threadsOnExecutor < executors[nextExecutorIndex].NumberOfCpu)
                {
                    return(executor);
                }
            }

            return(null);
        }
Пример #9
0
        public ExecutorStorageView[] GetExecutors(TriStateBoolean dedicated, TriStateBoolean connected)
        {
            ExecutorStorageView[] allExecutors;
            IObjectContainer      container = GetStorage();

            try
            {
                IList <ExecutorStorageView> executors =
                    container.Query <ExecutorStorageView>(delegate(ExecutorStorageView executorFinder)
                {
                    return(((dedicated == TriStateBoolean.True && executorFinder.Dedicated) ||
                            dedicated == TriStateBoolean.Undefined) &&
                           ((connected == TriStateBoolean.True && executorFinder.Connected) ||
                            connected == TriStateBoolean.Undefined));
                });


                if (executors.Count > 0)
                {
                    allExecutors = new ExecutorStorageView[executors.Count];
                    executors.CopyTo(allExecutors, 0);
                }
                else
                {
                    allExecutors = new ExecutorStorageView[0];
                }
            }
            finally
            {
                container.Close();
            }
            return(allExecutors);
        }
Пример #10
0
        private void RefreshData(ExecutorStorageView ex)
        {
            if (ex == null)
            {
                return;
            }

            txId.Text   = ex.ExecutorId;
            lbName.Text = ex.HostName;

            this.Text = ex.HostName + " Properties";

            txPort.Text     = ex.Port.ToString();
            txUsername.Text = ex.Username;

            chkConnected.Checked = ex.Connected;
            chkDedicated.Checked = ex.Dedicated;

            txArch.Text = ex.Architecture;
            txOS.Text   = ex.OS;

            txMaxCPU.Text  = ex.MaxCpu.ToString();
            txMaxDisk.Text = ex.MaxDisk.ToString();
            txNumCPUs.Text = ex.NumberOfCpu.ToString();

            txPingTime.Text = GetDiff(ex.PingTime);
        }
Пример #11
0
        public void DeleteExecutor(ExecutorStorageView executor)
        {
            if (executor == null)
            {
                return;
            }

            IObjectContainer container = GetStorage();

            try
            {
                IList <ExecutorStorageView> executors =
                    container.Query <ExecutorStorageView>(delegate(ExecutorStorageView executorFinder)
                {
                    return(executorFinder.ExecutorId == executor.ExecutorId);
                });

                if (executors.Count > 0)
                {
                    container.Delete(executors[0]);
                }
            }
            finally
            {
                container.Close();
            }
        }
Пример #12
0
        /// <summary>
        /// Verify if the executor exists in the database and the remote endpoint host matches the database setting
        /// </summary>
        /// <param name="ep"></param>
        /// <returns></returns>
        private bool VerifyExists(RemoteEndPoint ep)
        {
            bool exists = false;

            try
            {
                logger.Debug("Checking if executor :" + _Id + " exists in db");

                ExecutorStorageView executorStorage = ManagerStorageFactory.ManagerStorage().GetExecutor(_Id);

                bool remoteEndPointNullOrHostIsSameAsExecutor;
                remoteEndPointNullOrHostIsSameAsExecutor =
                    ep == null || (ep != null && executorStorage.HostName == ep.Host);

                if (executorStorage != null && remoteEndPointNullOrHostIsSameAsExecutor)
                {
                    exists = true;
                }

                logger.Debug("Executor :" + _Id + " exists in db=" + exists);
            }
            catch (Exception ex)
            {
                logger.Error("Executor :" + _Id + " invalid id? ", ex);
                throw new InvalidExecutorException("The supplied Executor ID is invalid.", ex);
            }

            return(exists);
        }
Пример #13
0
        public void DisconnectTimedOutExecutorsTestSimpleScenario()
        {
            // add one that is OK
            ExecutorStorageView executor1 = new ExecutorStorageView(true, true, DateTime.Now, "hostname", 10, "username", 1, 1, 1, 1);
            // add one that is timed out
            ExecutorStorageView executor2 = new ExecutorStorageView(true, true, DateTime.Now.AddDays((-1)), "hostname", 10, "username", 1, 1, 1, 1);
            // add one that is not connected
            ExecutorStorageView executor3 = new ExecutorStorageView(false, false, DateTime.Now, "hostname", 10, "username", 1, 1, 1, 1);

            string executorId1 = _managerStorage.AddExecutor(executor1);
            string executorId2 = _managerStorage.AddExecutor(executor2);
            string executorId3 = _managerStorage.AddExecutor(executor3);

            // whatever was not responsive in the last 60 seconds should get lost
            TimeSpan timeSpan = new TimeSpan(0, 0, 60);

            //TODO: This is now moved to the "watchdog" class
            //need a seperate tester for that.
            //DisconnectTimedOutExecutors(timeSpan);
            Assert.Fail("DisconnectTimedOutExecutors(timeSpan) is moved to a seperate class now. Need a new test case.");

            // check what was disconnected
            Assert.IsTrue(_managerStorage.GetExecutor(executorId1).Connected);
            Assert.IsFalse(_managerStorage.GetExecutor(executorId2).Connected);
            Assert.IsFalse(_managerStorage.GetExecutor(executorId3).Connected);
        }
Пример #14
0
        /// <summary>
        /// Verify if the executor exists in the database and the remote endpoint host matches the database setting
        /// </summary>
        /// <param name="ep"></param>
        /// <returns></returns>
        private bool VerifyExists(EndPoint ep)
        {
            bool exists = false;

            //TODO: review the use of this method!
            try
            {
                ExecutorStorageView executorStorage = ManagerStorageFactory.ManagerStorage().GetExecutor(_Id);
                if (executorStorage != null)
                {
                    bool remoteEndPointNullOrHostIsSameAsExecutor;
                    remoteEndPointNullOrHostIsSameAsExecutor =
                        ep == null || (ep != null && executorStorage.HostName == ep.Host);

                    exists = remoteEndPointNullOrHostIsSameAsExecutor;
                }
            }
            catch (Exception ex)
            {
                logger.Error("Executor :" + _Id + " invalid id? ", ex);
                throw new InvalidExecutorException("The supplied Executor ID is invalid.", ex);
            }

            return(exists);
        }
Пример #15
0
        /// <summary>
        /// Connects to the executor in dedicated mode.
        /// </summary>
        /// <param name="ep">end point of the executor</param>
        public void ConnectDedicated(EndPoint ep)
        {
            logger.Debug("Trying to connect Dedicated to executor: " + _Id);
            if (!VerifyExists(ep))
            {
                logger.Debug("The supplied Executor ID does not exist.");
                throw new InvalidExecutorException("The supplied Executor ID does not exist.", null);
            }

            bool              success = false;
            IExecutor         executor;
            EndPointReference epr = null;

            try
            {
                epr      = GNode.GetRemoteRef(ep, typeof(IExecutor));
                executor = (IExecutor)epr.Instance;
                executor.PingExecutor(); //connect back to executor.
                success = true;
                logger.Debug("Connected dedicated. Executor_id=" + _Id);
                ExecutorStorageView executorStorage = ManagerStorageFactory.ManagerStorage().GetExecutor(_Id);

                executorStorage.Connected = success;
                executorStorage.Dedicated = true;
                executorStorage.HostName  = ep.Host;
                executorStorage.Port      = ep.Port;

                // update state in db (always happens even if cannnot connect back to executor
                ManagerStorageFactory.ManagerStorage().UpdateExecutor(executorStorage);

                logger.Debug("Updated db after ping back to executor. dedicated executor_id=" + _Id + ", dedicated = true, connected = " + success);
                // update hashtable
                //for thread-safety
                lock (_DedicatedExecutors)
                {
                    //TODO: change this collection to a collection of EndPointReferences of the connections will not be properly disposed.
                    if (!_DedicatedExecutors.ContainsKey(_Id))
                    {
                        _DedicatedExecutors.Add(_Id, executor);
                        logger.Debug("Added to list of dedicated executors: executor_id=" + _Id);
                    }
                    else
                    {
                        //WCF ( doesnt remoting do that to ) closes the connection if executor connects and disconects.
                        //So we must remove the old and add the new record
                        //Jure Subara
                        _DedicatedExecutors.Remove(_Id);
                        _DedicatedExecutors.Add(_Id, executor);
                        logger.Debug("Refreshed the record in list od dedicated executors: executor_id=" + _Id);
                    }
                }
            }
            catch (Exception e)
            {
                logger.Error("Error connecting to exec: " + _Id, e);
                throw new ExecutorCommException(_Id, e);
            }
        }
Пример #16
0
        /// <summary>
        /// Disconnect from the executor.
        /// (Updates the database to reflect the executor disconnection.)
        /// </summary>
        public void Disconnect()
        {
            // maybe should reset threads here as part of the disconnection rather than explicitly ...
            ExecutorStorageView executorStorage = ManagerStorageFactory.ManagerStorage().GetExecutor(_Id);

            executorStorage.Connected = false;

            ManagerStorageFactory.ManagerStorage().UpdateExecutor(executorStorage);
        }
Пример #17
0
        /// <summary>
        /// Updates the database with the heartbeat info of this executor
        /// </summary>
        /// <param name="info"></param>
        public void HeartbeatUpdate(HeartbeatInfo info)
        {
            // update ping time and other heartbeatinfo
            ExecutorStorageView executorStorage = ManagerStorageFactory.ManagerStorage().GetExecutor(_Id);

            executorStorage.PingTime       = DateTime.Now;
            executorStorage.Connected      = true;
            executorStorage.CpuUsage       = info.PercentUsedCpuPower;
            executorStorage.AvailableCpu   = info.PercentAvailCpuPower;
            executorStorage.TotalCpuUsage += info.Interval * (float)info.PercentUsedCpuPower / 100;

            ManagerStorageFactory.ManagerStorage().UpdateExecutor(executorStorage);
        }
Пример #18
0
        public void DeleteExecutor(ExecutorStorageView executorToDelete)
        {
            if (m_executors == null || executorToDelete == null)
            {
                return;
            }

            ArrayList newExecutorList = new ArrayList();

            foreach (ExecutorStorageView executor in m_executors)
            {
                if (executor.ExecutorId != executorToDelete.ExecutorId)
                {
                    newExecutorList.Add(executor);
                }
            }

            m_executors = newExecutorList;
        }
Пример #19
0
        /// <summary>
        /// Queries the database to return the next dedicated schedule.
        /// </summary>
        /// <returns>DedicatedSchedule</returns>
        public DedicatedSchedule ScheduleDedicated()
        {
            ExecutorStorageView executorStorage = GetNextAvailableExecutor();

            if (executorStorage == null)
            {
                return(null);
            }

            ThreadStorageView threadStorage = GetNextAvailableThread();

            if (threadStorage == null)
            {
                return(null);
            }

            DedicatedSchedule dsched = null;

            string executorId = executorStorage.ExecutorId;

            string appid = threadStorage.ApplicationId;

            int threadId = threadStorage.ThreadId;

            int priority = threadStorage.Priority;

//			if (priority == -1)
//			{
//				priority = 5; //DEFAULT PRIORITY - TODO: have to put this in some Constants.cs file or something...
//			}

            ThreadIdentifier ti = new ThreadIdentifier(appid, threadId, priority);

            logger.Debug(String.Format("Schedule dedicated. app_id={0},threadID={1}, executor-id={2}",
                                       appid,
                                       threadId,
                                       executorId)
                         );

            dsched = new DedicatedSchedule(ti, executorId);

            return(dsched);
        }
Пример #20
0
        /// <summary>
        /// Connects to the executor in dedicated mode.
        /// </summary>
        /// <param name="ep">end point of the executor</param>
        public void ConnectDedicated(RemoteEndPoint ep)
        {
            logger.Debug("Trying to connect Dedicated to executor: " + _Id);
            if (!VerifyExists(ep))
            {
                logger.Debug("The supplied Executor ID does not exist.");
                throw new InvalidExecutorException("The supplied Executor ID does not exist.", null);
            }

            bool      success = false;
            IExecutor executor;

            try
            {
                executor = (IExecutor)GNode.GetRemoteRef(ep, _Id);
                executor.PingExecutor(); //connect back to executor.
                success = true;
                logger.Debug("Connected dedicated. Executor_id=" + _Id);
                ExecutorStorageView executorStorage = ManagerStorageFactory.ManagerStorage().GetExecutor(_Id);

                executorStorage.Connected = success;
                executorStorage.Dedicated = true;
                executorStorage.HostName  = ep.Host;
                executorStorage.Port      = ep.Port;

                // update state in db (always happens even if cannnot connect back to executor
                ManagerStorageFactory.ManagerStorage().UpdateExecutor(executorStorage);

                logger.Debug("Updated db after ping back to executor. dedicated executor_id=" + _Id + ", dedicated = true, connected = " + success);
                // update hashtable
                if (!_DedicatedExecutors.ContainsKey(_Id))
                {
                    _DedicatedExecutors.Add(_Id, executor);
                    logger.Debug("Added to list of dedicated executors: executor_id=" + _Id);
                }
            }
            catch (Exception e)
            {
                logger.Error("Error connecting to exec: " + _Id, e);
                throw new ExecutorCommException(_Id, e);
            }
        }
Пример #21
0
        /// <summary>
        /// Connects to the executor in non-dedicated mode.
        /// </summary>
        public void ConnectNonDedicated(RemoteEndPoint ep)
        {
            logger.Debug("Trying to connect NON-Dedicated to executor: " + _Id);
            if (!VerifyExists(ep))
            {
                logger.Debug("The supplied Executor ID does not exist.");
                throw new InvalidExecutorException("The supplied Executor ID does not exist.", null);
            }

            //here we don't ping back, since we know non-dedicated nodes can't be pinged back.

            ExecutorStorageView executorStorage = ManagerStorageFactory.ManagerStorage().GetExecutor(_Id);

            executorStorage.Connected = true;
            executorStorage.Dedicated = false;

            // update state in db
            ManagerStorageFactory.ManagerStorage().UpdateExecutor(executorStorage);

            logger.Debug("Connected non-dedicated. Updated db. executor_id=" + _Id);
        }
Пример #22
0
        public void UpdateExecutor(ExecutorStorageView updatedExecutor)
        {
            if (m_executors == null || updatedExecutor == null)
            {
                return;
            }

            ArrayList newExecutorList = new ArrayList();

            foreach (ExecutorStorageView executor in m_executors)
            {
                if (executor.ExecutorId == updatedExecutor.ExecutorId)
                {
                    newExecutorList.Add(updatedExecutor);
                }
                else
                {
                    newExecutorList.Add(executor);
                }
            }

            m_executors = newExecutorList;
        }
Пример #23
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);
            }
        }
Пример #24
0
        public string AddExecutor(ExecutorStorageView executor)
        {
            if (executor == null)
            {
                return(null);
            }

            string executorId;

            if (executor.ExecutorId == null)
            {
                executorId = Guid.NewGuid().ToString();
            }
            else
            {
                executorId = executor.ExecutorId;
            }

            executor.ExecutorId = executorId;

            _executors.Add(executor);

            return(executorId);
        }
Пример #25
0
        public ExecutorStorageView GetExecutor(string executorId)
        {
            ExecutorStorageView executor  = null;
            IObjectContainer    container = GetStorage();

            try
            {
                IList <ExecutorStorageView> executors =
                    container.Query <ExecutorStorageView>(delegate(ExecutorStorageView executorFinder)
                {
                    return(executorFinder.ExecutorId == executorId);
                });

                if (executors.Count > 0)
                {
                    executor = executors[0];
                }
            }
            finally
            {
                container.Close();
            }
            return(executor);
        }
Пример #26
0
        /// <summary>
        /// Registers a new executor with the manager
        /// </summary>
        /// <param name="sc">security credentials used to perform this operation.</param>
        /// <param name="executorId">The preferred executor ID. Set it to null to generate a new ID.</param>
        /// <param name="info">information about the executor (see ExecutorInfo)</param>
        /// <returns></returns>
        public string RegisterNew(SecurityCredentials sc, string executorId, ExecutorInfo info)
        {
            //NOTE: when registering, all executors are initially set to non-dedicated.non-connected.
            //once they connect and can be pinged back, then these values are set accordingly.
            ExecutorStorageView executorStorage = new ExecutorStorageView(
                executorId,
                false,
                false,
                info.Hostname,
                sc.Username,
                info.MaxCpuPower,
                info.MaxMemory,
                info.MaxDiskSpace,
                info.NumberOfCpus,
                info.OS,
                info.Architecture
                );

            if (this[executorId].VerifyExists())
            {
                // executor already exists, just update the details
                ManagerStorageFactory.ManagerStorage().UpdateExecutor(executorStorage);

                logger.Debug("Updated executor details = " + executorId);

                return(executorId);
            }
            else
            {
                string newExecutorId = ManagerStorageFactory.ManagerStorage().AddExecutor(executorStorage);

                logger.Debug("Registered new executor id=" + newExecutorId);

                return(newExecutorId);
            }
        }
Пример #27
0
        public void DisconnectTimedOutExecutorsTestSimpleScenario()
        {
            // add one that is OK
            ExecutorStorageView executor1 = new ExecutorStorageView(true, true, DateTime.Now, "hostname", 10, "username", 1, 1, 1, 1);
            // add one that is timed out
            ExecutorStorageView executor2 = new ExecutorStorageView(true, true, DateTime.Now.AddDays((-1)), "hostname", 10, "username", 1, 1, 1, 1);
            // add one that is not connected
            ExecutorStorageView executor3 = new ExecutorStorageView(false, false, DateTime.Now, "hostname", 10, "username", 1, 1, 1, 1);

            String executorId1 = m_managerStorage.AddExecutor(executor1);
            String executorId2 = m_managerStorage.AddExecutor(executor2);
            String executorId3 = m_managerStorage.AddExecutor(executor3);

            // whatever was not responsive in the last 60 seconds should get lost
            TimeSpan timeSpan = new TimeSpan(0, 0, 60);

            DisconnectTimedOutExecutors(timeSpan);

            // check what was disconnected

            Assert.IsTrue(m_managerStorage.GetExecutor(executorId1).Connected);
            Assert.IsFalse(m_managerStorage.GetExecutor(executorId2).Connected);
            Assert.IsFalse(m_managerStorage.GetExecutor(executorId3).Connected);
        }
Пример #28
0
        /// THIS FUNCTIONALITY IS NOT FULLY IMPLEMENTED AND IT MIGHT BE DISCARDED ALTOGETHER
        ///
        /// Loading from an XML file is the perfect tool for complex storage setups which would be useful for more in-depth unit testing
        /// Saving to an XML file could be used to dump the current storage state for troubleshooting, for example to receive faulty storages from the field.


        /// <summary>
        /// Save the current storage state into an XML file.
        /// It is important that the file format is easily editable by humans so test cases can easily be maintained.
        /// For this reason we do not use the build-in persistence modules.
        /// </summary>
        /// <param name="filename"></param>
        public void SaveToHumanReadableXmlFile(String filename)
        {
            const String storageDocumentTemplate = "<storage><users/><groups/><group_permissions/><executors/><applications/><threads/></storage>";
            XmlDocument  storageDocument         = new XmlDocument();

            storageDocument.LoadXml(storageDocumentTemplate);

            XmlNode usersNode  = storageDocument.SelectSingleNode("/storage/users");
            XmlNode groupsNode = storageDocument.SelectSingleNode("/storage/groups");
            //XmlNode groupPermissionsNode = storageDocument.SelectSingleNode("/storage/group_permissions");
            XmlNode executorsNode    = storageDocument.SelectSingleNode("/storage/executors");
            XmlNode applicationsNode = storageDocument.SelectSingleNode("/storage/applications");
            XmlNode threadsNode      = storageDocument.SelectSingleNode("/storage/threads");

            if (m_users != null)
            {
                IEnumerator usersEnumerator = m_users.GetEnumerator();

                while (usersEnumerator.MoveNext())
                {
                    UserStorageView user = usersEnumerator.Current as UserStorageView;

                    XmlElement userElement = storageDocument.CreateElement("user");

                    userElement.SetAttribute("username", user.Username);
                    userElement.SetAttribute("password", user.Password);
                    userElement.SetAttribute("groupid", user.GroupId.ToString());

                    usersNode.AppendChild(userElement);
                }
            }

            if (m_groups != null)
            {
                IEnumerator groupsEnumerator = m_groups.GetEnumerator();

                while (groupsEnumerator.MoveNext())
                {
                    GroupStorageView group = groupsEnumerator.Current as GroupStorageView;

                    XmlElement groupElement = storageDocument.CreateElement("group");

                    groupElement.SetAttribute("groupname", group.GroupName);
                    groupElement.SetAttribute("groupid", group.GroupId.ToString());

                    groupsNode.AppendChild(groupElement);
                }
            }

            //		private Hashtable m_groupPermissions;
//			if (m_groupPermissions != null)
//			{
//				IEnumerator groupPermissionsEnumerator = m_groupPermissions.GetEnumerator();
//
//				while(groupPermissionsEnumerator.MoveNext())
//				{
//					GroupPermissionStorageView group = groupPermissionsEnumerator.Current as GroupStorageView;
//
//					XmlElement groupElement = storageDocument.CreateElement("group");
//
//					groupElement.SetAttribute("groupname", group.GroupName);
//					groupElement.SetAttribute("groupid", group.GroupId.ToString());
//
//					groupsNode.AppendChild(groupElement);
//				}
//			}


            if (m_executors != null)
            {
                IEnumerator executorsEnumerator = m_executors.GetEnumerator();

                while (executorsEnumerator.MoveNext())
                {
                    ExecutorStorageView executor = executorsEnumerator.Current as ExecutorStorageView;

                    XmlElement executorElement = storageDocument.CreateElement("executor");

                    executorElement.SetAttribute("executorid", executor.ExecutorId);
                    executorElement.SetAttribute("dedicated", executor.Dedicated.ToString());
                    executorElement.SetAttribute("connected", executor.Connected.ToString());
                    executorElement.SetAttribute("pingtime", executor.PingTime.ToString());
                    executorElement.SetAttribute("hostname", executor.HostName);
                    executorElement.SetAttribute("port", executor.Port.ToString());
                    executorElement.SetAttribute("username", executor.Username);
                    executorElement.SetAttribute("maxcpu", executor.MaxCpu.ToString());
                    executorElement.SetAttribute("cpuusage", executor.CpuUsage.ToString());
                    executorElement.SetAttribute("availablecpu", executor.AvailableCpu.ToString());
                    executorElement.SetAttribute("totalcpuusage", executor.TotalCpuUsage.ToString());
                    executorElement.SetAttribute("maxmemory", executor.MaxMemory.ToString());
                    executorElement.SetAttribute("maxdisk", executor.MaxDisk.ToString());
                    executorElement.SetAttribute("numberofcpu", executor.NumberOfCpu.ToString());
                    executorElement.SetAttribute("os", executor.Os);
                    executorElement.SetAttribute("architecture", executor.Architecture);

                    executorsNode.AppendChild(executorElement);
                }
            }

            if (m_applications != null)
            {
                IEnumerator applicationsEnumerator = m_applications.GetEnumerator();

                while (applicationsEnumerator.MoveNext())
                {
                    ApplicationStorageView application = applicationsEnumerator.Current as ApplicationStorageView;

                    XmlElement applicationElement = storageDocument.CreateElement("application");

                    applicationElement.SetAttribute("applicationid", application.ApplicationId);
                    applicationElement.SetAttribute("state", application.State.ToString());
                    applicationElement.SetAttribute("timecreated", application.TimeCreated.ToString());
                    applicationElement.SetAttribute("primary", application.Primary.ToString());
                    applicationElement.SetAttribute("username", application.Username.ToString());
                    applicationElement.SetAttribute("totalthreads", application.TotalThreads.ToString());
                    applicationElement.SetAttribute("unfinishedthreads", application.UnfinishedThreads.ToString());

                    applicationsNode.AppendChild(applicationElement);
                }
            }

            if (m_threads != null)
            {
                IEnumerator threadsEnumerator = m_threads.GetEnumerator();

                while (threadsEnumerator.MoveNext())
                {
                    ThreadStorageView thread = threadsEnumerator.Current as ThreadStorageView;

                    XmlElement threadElement = storageDocument.CreateElement("thread");

                    threadElement.SetAttribute("internalthreadid", thread.InternalThreadId.ToString());
                    threadElement.SetAttribute("applicationid", thread.ApplicationId);
                    threadElement.SetAttribute("executorid", thread.ExecutorId);
                    threadElement.SetAttribute("threadid", thread.ThreadId.ToString());
                    threadElement.SetAttribute("state", thread.State.ToString());
                    threadElement.SetAttribute("timestarted", thread.TimeStarted.ToString());
                    threadElement.SetAttribute("timefinished", thread.TimeFinished.ToString());
                    threadElement.SetAttribute("priority", thread.Priority.ToString());
                    threadElement.SetAttribute("failed", thread.Failed.ToString());

                    threadsNode.AppendChild(threadElement);
                }
            }

            storageDocument.Save(filename);
        }