コード例 #1
0
        public void ApplicationStatesToRemoveTestGettingItEmpty()
        {
            StorageMaintenanceParameters maintanenceParameters = new StorageMaintenanceParameters();

            // I want it to return a 0 length array rather than a null
            Assert.AreEqual(0, maintanenceParameters.ApplicationStatesToRemove.Length);
        }
コード例 #2
0
        public void AddApplicationStatesToRemoveTestNull()
        {
            StorageMaintenanceParameters maintanenceParameters = new StorageMaintenanceParameters();

            maintanenceParameters.AddApplicationStatesToRemove(null);

            Assert.AreEqual(0, maintanenceParameters.ApplicationStatesToRemove.Length);
        }
コード例 #3
0
        public void AddApplicationStateToRemoveTestAddOne()
        {
            StorageMaintenanceParameters maintanenceParameters = new StorageMaintenanceParameters();

            maintanenceParameters.AddApplicationStateToRemove(ApplicationState.Ready);

            Assert.AreEqual(1, maintanenceParameters.ApplicationStatesToRemove.Length);
            Assert.AreEqual(ApplicationState.Ready, maintanenceParameters.ApplicationStatesToRemove[0]);
        }
コード例 #4
0
        public void PerformMaintenanceTestNothingToRemove()
        {
            Maintenance maintenance = new Maintenance();
            StorageMaintenanceParameters maintenanceParameters = new StorageMaintenanceParameters();

            PrepareComplexStorageForMaintenanceTests();

            maintenance.PerformMaintenance(m_managerStorage, maintenanceParameters);

            Assert.AreEqual(4, m_managerStorage.GetExecutors().Length);
            Assert.AreEqual(5, m_managerStorage.GetApplications().Length);
        }
コード例 #5
0
        public void AddApplicationStatesToRemoveTestAddingFromArray()
        {
            StorageMaintenanceParameters maintanenceParameters = new StorageMaintenanceParameters();

            ApplicationState[] states = new ApplicationState[2];
            states[0] = ApplicationState.Ready;
            states[1] = ApplicationState.Stopped;

            maintanenceParameters.AddApplicationStatesToRemove(states);

            Assert.AreEqual(2, maintanenceParameters.ApplicationStatesToRemove.Length);
            Assert.AreEqual(ApplicationState.Ready, maintanenceParameters.ApplicationStatesToRemove[0]);
            Assert.AreEqual(ApplicationState.Stopped, maintanenceParameters.ApplicationStatesToRemove[1]);
        }
コード例 #6
0
        public void PerformMaintenanceTestMultipleParameters()
        {
            Maintenance maintenance = new Maintenance();
            StorageMaintenanceParameters maintenanceParameters = new StorageMaintenanceParameters();

            maintenanceParameters.AddApplicationStateToRemove(ApplicationState.AwaitingManifest);
            maintenanceParameters.ExecutorPingTimeCutOff = new TimeSpan(20, 0, 0);

            PrepareComplexStorageForMaintenanceTests();

            maintenance.PerformMaintenance(m_managerStorage, maintenanceParameters);

            Assert.AreEqual(2, m_managerStorage.GetExecutors().Length);
            Assert.AreEqual(3, m_managerStorage.GetApplications().Length);
        }
コード例 #7
0
ファイル: Maintenance.cs プロジェクト: JamesTryand/alchemi
        /// <summary>
        /// Perform various maintenance actions as defined in the maintenance parameters.
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="maintenanceParameters"></param>
        public void PerformMaintenance(IManagerStorage storage, StorageMaintenanceParameters maintenanceParameters)
        {
            RemoveApplications(storage, maintenanceParameters.ApplicationStatesToRemove);

            if (maintenanceParameters.RemoveAllApplications)
            {
                RemoveAllApplications(storage);
            }

            if (maintenanceParameters.RemoveAllExecutors)
            {
                RemoveAllExecutors(storage);
            }

            if (maintenanceParameters.ApplicationTimeCreatedCutOffSet)
            {
                RemoveApplications(storage, maintenanceParameters.ApplicationTimeCreatedCutOff);
            }

            if (maintenanceParameters.ExecutorPingTimeCutOffSet)
            {
                RemoveExecutors(storage, maintenanceParameters.ExecutorPingTimeCutOff);
            }

            if (maintenanceParameters.ApplicationTimeCompletedCutOffSet)
            {
                DateTime timeCompletedCutOff = DateTime.Now.Subtract(maintenanceParameters.ApplicationTimeCompletedCutOff);

                ApplicationStorageView[] applications = storage.GetApplications();
                foreach (ApplicationStorageView application in applications)
                {
                    if (application.TimeCompletedSet && application.TimeCompleted < timeCompletedCutOff)
                    {
                        storage.DeleteApplication(application);
                    }
                }
            }
        }
コード例 #8
0
        public void PerformMaintenanceTestRemoveExecutorsByPingTime()
        {
            Maintenance maintenance = new Maintenance();
            StorageMaintenanceParameters maintenanceParameters = new StorageMaintenanceParameters();

            maintenanceParameters.ExecutorPingTimeCutOff = new TimeSpan(20, 0, 0);

            PrepareComplexStorageForMaintenanceTests();

            maintenance.PerformMaintenance(m_managerStorage, maintenanceParameters);

            Assert.AreEqual(2, m_managerStorage.GetExecutors().Length);
            Assert.AreEqual(5, m_managerStorage.GetApplications().Length);
        }
コード例 #9
0
        public void PerformMaintenanceTestRemoveApplicationsByTimeCompleted()
        {
            Maintenance maintenance = new Maintenance();
            StorageMaintenanceParameters maintenanceParameters = new StorageMaintenanceParameters();

            maintenanceParameters.ApplicationTimeCompletedCutOff = new TimeSpan(20, 0, 0);

            PrepareComplexStorageForMaintenanceTests();

            maintenance.PerformMaintenance(m_managerStorage, maintenanceParameters);

            Assert.AreEqual(4, m_managerStorage.GetExecutors().Length);
            // we should have left the one that didn't have the time completed set
            // and 2 more that were not in the cut-off range
            Assert.AreEqual(3, m_managerStorage.GetApplications().Length);
        }
コード例 #10
0
        public void PerformMaintenanceTestRemoveApplicationByState()
        {
            Maintenance maintenance = new Maintenance();
            StorageMaintenanceParameters maintenanceParameters = new StorageMaintenanceParameters();

            maintenanceParameters.AddApplicationStateToRemove(ApplicationState.AwaitingManifest);
            maintenanceParameters.AddApplicationStateToRemove(ApplicationState.Ready);

            PrepareComplexStorageForMaintenanceTests();

            maintenance.PerformMaintenance(m_managerStorage, maintenanceParameters);

            Assert.AreEqual(4, m_managerStorage.GetExecutors().Length);
            Assert.AreEqual(2, m_managerStorage.GetApplications().Length);
        }
コード例 #11
0
        /// <summary>
        /// convert the controls options into the StorageMaintenanceParameters object
        /// </summary>
        /// <returns></returns>
        private StorageMaintenanceParameters GetStorageMaintenanceParameters()
        {
            StorageMaintenanceParameters result = new StorageMaintenanceParameters();

            // application level options
            result.RemoveAllApplications = chkRemoveAllApplications.Checked;

            if (chkRemoveApplicationsByState.Checked)
            {
                IEnumerator enumerator = lstApplicationStatesToRemove.SelectedItems.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    result.AddApplicationStateToRemove((ApplicationState)enumerator.Current);
                }
            }

            if (chkRemoveApplicationsByTimeCreated.Checked)
            {
                result.ApplicationTimeCreatedCutOff = new TimeSpan(0, Convert.ToInt32(numTimeApplicationCreatedCutOffInMinutes.Value), 0);
            }

            if (chkRemoveApplicationsByTimeCompleted.Checked)
            {
                result.ApplicationTimeCompletedCutOff = new TimeSpan(0, Convert.ToInt32(numTimeApplicationCompletedCutOffInMinutes.Value), 0);
            }

            // executor level options
            result.RemoveAllExecutors = chkRemoveAllExecutors.Checked;

            if (chkRemoveExecutorsByTimePinged.Checked)
            {
                result.ExecutorPingTimeCutOff = new TimeSpan(0, Convert.ToInt32(numTimeExecutorPingedCutOffInMinutes.Value), 0);
            }

            return result;
        }
コード例 #12
0
        private void btnPerformMaintenance_Click(object sender, EventArgs e)
        {
            m_maintenanceParameters = GetStorageMaintenanceParameters();

            m_success = false;

            m_maintenanceThread = new Thread(new ThreadStart(MaintenanceWorkerThread));

            m_maintenanceThread.Start();

            //wait a bit to see if it is done already and if so no longer display the wait dialog.
            m_maintenanceThread.Join(1000);

            if (m_maintenanceThread.ThreadState != System.Threading.ThreadState.Stopped)
            {

                // put up the display dialog
                m_pleaseWait = new PleaseWait();

                if (m_pleaseWait.ShowDialog() != DialogResult.OK)
                {
                    m_maintenanceThread.Join(1000);

                    m_maintenanceThread.Abort();
                }
            }

            m_maintenanceThread = null;

            StringBuilder message = new StringBuilder();

            if (m_success)
            {
                message.Append("Maintenance task completed.");
            }
            else
            {
                message.Append("Maintenance task aborted.");

                if (m_errorMessage != null)
                {
                    message.AppendFormat(" Error message: {0}", m_errorMessage);
                }
            }

            MessageBox.Show(message.ToString());
        }
コード例 #13
0
ファイル: GManagerTester.cs プロジェクト: JamesTryand/alchemi
        public void Admon_PerformStorageMaintenanceTestWithParameters()
        {
            SetupApplicationsGroupsAndUsers(Permission.ManageAllApps);

            SecurityCredentials sc = new SecurityCredentials("username1", HashUtil.GetHash("password1", HashType.MD5));

            _managerStorage.AddApplication(new ApplicationStorageView("username1"));
            _managerStorage.AddExecutor(new ExecutorStorageView(true, true, DateTime.Now, "test", 1, "test", 1, 1, 1, 1));

            StorageMaintenanceParameters maintenanceParameters = new StorageMaintenanceParameters();

            maintenanceParameters.RemoveAllExecutors = true;
            maintenanceParameters.RemoveAllApplications = true;

            // just to keep things honest make sure there is something there
            Assert.AreNotEqual(0, _managerStorage.GetExecutors().Length);
            Assert.AreNotEqual(0, _managerStorage.GetApplications().Length);

            Admon_PerformStorageMaintenance(sc, maintenanceParameters);

            Assert.AreEqual(0, _managerStorage.GetExecutors().Length);
            Assert.AreEqual(0, _managerStorage.GetApplications().Length);
        }
コード例 #14
0
ファイル: GManagerTester.cs プロジェクト: JamesTryand/alchemi
        public void Admon_PerformStorageMaintenanceTestNotEnoughPermissions()
        {
            SetupApplicationsGroupsAndUsers(Permission.ManageOwnApp);

            SecurityCredentials sc = new SecurityCredentials("username1", HashUtil.GetHash("password1", HashType.MD5));

            StorageMaintenanceParameters maintenanceParameters = new StorageMaintenanceParameters();

            try
            {
                Admon_PerformStorageMaintenance(sc, maintenanceParameters);
            }
            catch (AuthorizationException)
            {
                Assert.IsTrue(true);
                return;
            }

            Assert.IsFalse(true, "The authorization should fail");
        }
コード例 #15
0
ファイル: GManagerTester.cs プロジェクト: JamesTryand/alchemi
        public void Admon_PerformStorageMaintenanceTestNoAuthentication()
        {
            SecurityCredentials sc = new SecurityCredentials("username1", HashUtil.GetHash("password1", HashType.MD5));

            StorageMaintenanceParameters maintenanceParameters = new StorageMaintenanceParameters();

            try
            {
                Admon_PerformStorageMaintenance(sc, maintenanceParameters);
            }
            catch (AuthenticationException)
            {
                Assert.IsTrue(true);
                return;
            }

            Assert.IsFalse(true, "The authentication should fail");
        }
コード例 #16
0
        public void ApplicationTimeCreatedCutOffSetTestSettingIt()
        {
            StorageMaintenanceParameters maintanenceParameters = new StorageMaintenanceParameters();

            Assert.IsFalse(maintanenceParameters.ApplicationTimeCreatedCutOffSet);

            maintanenceParameters.ApplicationTimeCreatedCutOff = new TimeSpan(1, 0, 0);

            Assert.IsTrue(maintanenceParameters.ApplicationTimeCreatedCutOffSet);
        }
コード例 #17
0
ファイル: GManager.cs プロジェクト: abhishek-kumar/AIGA
        public void Admon_PerformStorageMaintenance(SecurityCredentials sc, StorageMaintenanceParameters maintenanceParameters)
        {
            AuthenticateUser(sc);
            EnsurePermission(sc, Permission.ManageAllApps);

            logger.Debug(String.Format("Performing maintenance with parameters {0}.", maintenanceParameters));

            Maintenance maintenance = new Maintenance();

            maintenance.PerformMaintenance(ManagerStorageFactory.ManagerStorage(), maintenanceParameters);
        }
コード例 #18
0
        public void ExecutorPingTimeCutOffSetTestSettingIt()
        {
            StorageMaintenanceParameters maintanenceParameters = new StorageMaintenanceParameters();

            Assert.IsFalse(maintanenceParameters.ExecutorPingTimeCutOffSet);

            maintanenceParameters.ExecutorPingTimeCutOff = new TimeSpan(1, 0, 0);

            Assert.IsTrue(maintanenceParameters.ExecutorPingTimeCutOffSet);
        }