Esempio n. 1
0
        private void ExecuteSTB(string scenarioName)
        {
            string[] args = new string[8];

            args[0] = "-dispatcher";
            args[1] = Environment.MachineName;
            args[2] = "-database";
            args[3] = _currentDatabase;
            args[4] = "-scenario";
            args[5] = scenarioName;
            args[6] = "-owner";
            args[7] = UserManager.CurrentUser;

            WriteLine("Starting session...");
            using (CommandLineExec commandLine = new CommandLineExec(args))
            {
                try
                {
                    _ticket = commandLine.Ticket;
                    commandLine.HandleSessionClientEvents = false;
                    commandLine.StatusChanged            += CommandLine_StatusChanged;
                    FrameworkServicesInitializer.InitializeExecution();
                    commandLine.StartSession();
                }
                catch (Exception ex)
                {
                    UpdateStatus($"Error: {ex.Message}");
                    WriteLine(ex.ToString());
                }
            }
        }
        /// <summary>
        /// start the execution of the scenario
        /// </summary>
        /// <param name="scenarioId">the scenario ID</param>
        public void StartSession(Guid scenarioId)
        {
            using (SessionConfigurationWizard wizard = new SessionConfigurationWizard(scenarioId))
            {
                if (wizard.ShowDialog(this) == DialogResult.OK)
                {
                    SessionTicket ticket = wizard.Ticket;
                    SessionId = ticket.SessionId;

                    // Set the display details from the ticket
                    sessionId_Label.Text    = ticket.SessionId;
                    sessionName_Label.Text  = ticket.SessionName;
                    sessionOwner_Label.Text = ticket.SessionOwner.UserName;

                    // Start the session
                    start_ToolStripButton.Enabled = false;
                    SessionClient.Instance.PowerUp(SessionId);
                }
                else
                {
                    if (_transition != SessionStartupTransition.ReadyToStart && _transition != SessionStartupTransition.None)
                    {
                        ShutdownOptions options = new ShutdownOptions();
                        options.ShutdownDeviceSimulators = false;
                        SessionClient.Instance.Shutdown(wizard.Ticket.SessionId, options);
                    }
                }
            }
        }
Esempio n. 3
0
 public void UpdateFromTicket(SessionTicket ticket)
 {
     Name = ticket.SessionName;
     if (ticket.SessionOwner != null)
     {
         Owner = ticket.SessionOwner.UserName;
     }
 }
        /// <summary>
        /// Initializes the wizard page with the specified <see cref="WizardConfiguration"/>.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public virtual bool Initialize(WizardConfiguration configuration)
        {
            Ticket = configuration.Ticket;
            Guid scenarioId = Ticket.ScenarioIds.FirstOrDefault();

            if (STFDispatcherManager.Dispatcher == null && STFDispatcherManager.ConnectToDispatcher() == false)
            {
                //The user canceled the connect dialog
                return(false);
            }

            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                // Load the specified scenario (if there is one)
                if (scenarioId != Guid.Empty)
                {
                    LoadScenario(scenarioId, context);
                    LoadComboBoxes(context);
                }
            }

            // If this is not the first time we have entered this step, the user
            // must have come back from some point later in the wizard.
            // Make sure the dispatcher doesn't hang onto configuration from the previous try.
            if (!_initial)
            {
                SessionClient.Instance.Close(Ticket.SessionId);
            }

            if (_scenario != null && Ticket.SessionId != null && Ticket.AssociatedProductList.Count != 0)
            {
                foreach (var item in Ticket.AssociatedProductList)
                {
                    _scenarioProducts.Where(n => n.ProductId == item.AssociatedProductId && n.Vendor == item.Vendor && n.Version == item.Version).FirstOrDefault().Active = item.Active;
                }
                scenarioProductBindingSource.Clear();
                scenarioProductBindingSource.DataSource = _scenarioProducts;
                scenarioProductBindingSource.ResetBindings(true);
            }
            deviceOffline_CheckBox.Checked = Ticket.RemoveUnresponsiveDevices;

            environment_Label.Text = "{0} {1} Environment".FormatWith(GlobalSettings.Items[Setting.Organization], GlobalSettings.Items[Setting.Environment]);

            if (string.IsNullOrEmpty(logLocation_TextBox.Text))
            {
                logLocation_TextBox.Text = GlobalSettings.WcfHosts[WcfService.DataLog];
            }
            _initial = false;

            dispatcher_Label.Text = STFDispatcherManager.Dispatcher.HostName;

            if (!GlobalSettings.IsDistributedSystem)
            {
                this.settings_TabControl.TabPages.Remove(this.virtualMachineSelection_TabPage);
            }

            return(true);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="WizardConfiguration"/> class.
        /// </summary>
        public WizardConfiguration()
        {
            Ticket = new SessionTicket()
            {
                SessionOwner = UserManager.CurrentUser
            };

            SessionAssets = new AssetDetailCollection();
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes the wizard page with the specified <see cref="WizardConfiguration"/>.
        /// </summary>
        /// <param name="configuration">The <see cref="WizardConfiguration"/>.</param>
        public bool Initialize(WizardConfiguration configuration)
        {
            Ticket     = configuration.Ticket;
            _scenarios = new BindingList <ScenarioSelectionItem>();
            scenarios_DataGridView.DataSource = null;

            if (STFDispatcherManager.Dispatcher == null && STFDispatcherManager.ConnectToDispatcher() == false)
            {
                //The user canceled the connect dialog
                return(false);
            }

            using (new BusyCursor())
            {
                using (EnterpriseTestContext context = new EnterpriseTestContext())
                {
                    foreach (EnterpriseScenario scenario in EnterpriseScenario.Select(context, Ticket.ScenarioIds))
                    {
                        _scenarios.Add(new ScenarioSelectionItem(scenario));
                    }

                    LoadComboBoxes(context);
                }

                _bindingSource = new BindingSource(_scenarios, string.Empty);
                scenarios_DataGridView.DataSource = _bindingSource;
            }

            //Set data from Ticket
            if (Ticket.SessionId != null)
            {
                SetEstimatedRunTime();
                sessionName_ComboBox.Text = string.IsNullOrEmpty(Ticket.SessionName) ? "Multiple Scenarios" : Ticket.SessionName;
            }

            if (!_initial)
            {
                SessionClient.Instance.Close(Ticket.SessionId);

                sessionType_ComboBox.SelectedText = Ticket.SessionType;

                if (!string.IsNullOrEmpty(Ticket.EmailAddresses))
                {
                    runtime_NumericUpDown.Value = Math.Min(Ticket.DurationHours, runtime_NumericUpDown.Maximum);
                }
            }

            environment_Label.Text = "{0} {1} Environment".FormatWith(GlobalSettings.Items[Setting.Organization], GlobalSettings.Items[Setting.Environment]);
            dispatcher_Label.Text  = STFDispatcherManager.Dispatcher.HostName;
            _initial = false;

            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// Starts the session.
        /// </summary>
        /// <param name="wizard">The wizard form.</param>
        /// <param name="ticket">The ticket.</param>
        /// <returns><c>true</c> if start operation successful, <c>false</c> otherwise.</returns>
        public bool StartSession(Form wizard, SessionTicket ticket)
        {
            bool result = false;

            var activeSessions = GetActiveSessions().Count();

            if (AbleToStartNewSession == false || activeSessions >= MAX_ACTIVE_SESSIONS)
            {
                MessageBox.Show(_treeView, "{0} active sessions out of {1} allowed".FormatWith(activeSessions, MAX_ACTIVE_SESSIONS), "Unable To Start Session");
                return(result);
            }

            if (EnsureDispatcherConnected())
            {
                try
                {
                    AbleToStartNewSession = false;
                    using (wizard)
                    {
                        var newSession = GetNewExecutingSessionInfo(ticket);
                        if (wizard.ShowDialog(_sessionControl) == DialogResult.OK)
                        {
                            //SessionClient.Instance.PowerUp(newSession.SessionId);
                            newSession.UpdateFromTicket(ticket);
                            result = true;
                            UpdateSessionInfoFromDatabaseAsynch(newSession, false);
                        }
                        else
                        {
                            var transition = newSession.StartupTransition;
                            if (transition != SessionStartupTransition.ReadyToStart && transition != SessionStartupTransition.None)
                            {
                                ShutdownOptions options = new ShutdownOptions();
                                options.ShutdownDeviceSimulators = false;
                                SessionClient.Instance.Shutdown(newSession.SessionId, options);
                                newSession.State = SessionState.ShutdownComplete;
                            }
                            else
                            {
                                newSession.State = SessionState.Canceled;
                                RemoveManagedSession(newSession);
                            }
                        }
                    }
                }
                finally
                {
                    AbleToStartNewSession = true;
                }
            }
            return(result);
        }
Esempio n. 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WizardConfiguration"/> class.
        /// </summary>
        public WizardConfiguration()
        {
            // Add the user credentials to the ticket which will be used to interact with VCenter
            // for VM operations.  The assumption is that the user has a VCenter login with the same
            // username as their HP LR0 domain username.
            var credential = new UserCredential(UserManager.LoggedInUser.UserName, UserManager.LoggedInUser.Domain)
            {
                Role     = UserManager.LoggedInUser.Role,
                Password = UserManager.LoggedInUser.Password
            };

            Ticket = new SessionTicket()
            {
                SessionOwner = credential
            };

            SessionAssets = new AssetDetailCollection();
        }
Esempio n. 9
0
        private void ExecuteSTF(string scenario, string holdId)
        {
            WriteLine("Starting session...");

            _ticket = SessionTicket.Create(scenario);
            _ticket.SessionOwner = new UserCredential(UserManager.CurrentUser, UserManager.CurrentUserCredential.Password,
                                                      UserManager.CurrentUserCredential.Domain)
            {
                Role = UserManager.CurrentUserRole
            };
            if (!string.IsNullOrEmpty(holdId))
            {
                _ticket.RequestedVMs.Add("BY_HOLDID", (from vm in SelectMachinesByHoldId(holdId) select vm.Name).ToList());
            }

            _ticket.ExpirationDate = _sessionRetention.GetExpirationDate(DateTime.Now);
            WriteLine("Created ticket {0}".FormatWith(_ticket.SessionId));
            _scenarioList.ElementAt(_currentScenarioIndex).SessionId = _ticket.SessionId;
            _startTime = DateTime.Now;
            LogSessionExecution();
            WriteLine("Initializing");
            SessionClient.Instance.Initialize(_currentDispatcher);
            SessionClient.Instance.InitiateSession(_ticket);

            UpdateStatus("Initialized");
            var assetDetails = SessionClient.Instance.Reserve(_ticket.SessionId);

            WriteLine("Reserved...{0}".FormatWith(_ticket.SessionId));
            UpdateStatus("Reserved");
            foreach (var asset in assetDetails.Where(x => x.Availability == AssetAvailability.NotAvailable))
            {
                WriteLine("Unavailable: {0}".FormatWith(asset.AssetId));
            }

            // This call to Stage() will kick off the process and as each event arrives to indicate
            // a step in the process has completed, the next step will automatically continue.
            SessionClient.Instance.Stage(_ticket.SessionId, assetDetails);
            WriteLine("Staged...{0}".FormatWith(_ticket.SessionId));
            UpdateStatus("Staged");
        }
Esempio n. 10
0
        private ExecutingSessionInfo GetNewExecutingSessionInfo(SessionTicket ticket)
        {
            if (IsManagedSession(ticket.SessionId))
            {
                throw new Exception("Session {0} already exists".FormatWith(ticket.SessionId));
            }

            var result = new ExecutingSessionInfo()
            {
                SessionId         = ticket.SessionId,
                Name              = ticket.SessionName,
                Owner             = ticket.SessionOwner.UserName,
                MapElement        = null,
                State             = SessionState.Available,
                StartupTransition = SessionStartupTransition.None,
                Dispatcher        = Dispatcher,
            };

            AddManagedSession(result);
            SetCurrentSession(result.SessionId);
            return(result);
        }
Esempio n. 11
0
        public void StartSession(StfSessionTicket sessionTicket)
        {
            _isSessionExecuting = true;
            try
            {
                var ticket = SessionTicket.Create(new[] { Guid.Parse(sessionTicket.ScenarioId) }, sessionTicket.SessionName, sessionTicket.Duration);
                ticket.ExpirationDate = DateTime.Now + TimeSpan.FromDays(180.0);
                if (GlobalSettings.IsDistributedSystem)
                {
                    ticket.SessionOwner = new UserCredential(GlobalSettings.Items.DomainAdminCredential.UserName, GlobalSettings.Items.DomainAdminCredential.Password, GlobalSettings.Items.DomainAdminCredential.Domain);
                }
                SessionClient.Instance.InitiateSession(ticket);
                var assetDetails = SessionClient.Instance.Reserve(ticket.SessionId);

                if (assetDetails.Any(x => x.Availability != AssetAvailability.Available))
                {
                    SessionClient.Instance.Close(ticket.SessionId);
                    TraceFactory.Logger.Error($"One or more assets are unavailable for session {ticket.SessionId}");
                    _isSessionExecuting = false;
                    return;
                }
                foreach (var printDeviceDetail in assetDetails.OfType <PrintDeviceDetail>())
                {
                    printDeviceDetail.UseCrc = false;
                }
                SessionClient.Instance.Stage(ticket.SessionId, assetDetails);
                lock (ticket.SessionId)
                {
                    SessionExecutionDictionary.TryAdd(ticket.SessionId, sessionTicket);
                }
            }
            catch (Exception e)
            {
                TraceFactory.Logger.Error(e.JoinAllErrorMessages());
                _isSessionExecuting = false;
            }
        }
Esempio n. 12
0
 public ExecutingSessionInfo(SessionTicket ticket)
     : this()
 {
     SessionId = ticket.SessionId;
     UpdateFromTicket(ticket);
 }
Esempio n. 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandLineExec"/> class.
        /// Validates the App Config key-value entries.
        /// </summary>
        /// <param name="appConfig">The App Config arguments.</param>
        public CommandLineExec(NameValueCollection appConfig)
        {
            AllocConsole();
            TraceFactory.SetThreadContextProperty("PID", Process.GetCurrentProcess().Id.ToString(), false);
            _arguments = appConfig;

            _state = SessionState.Available;
            string dispatcher              = string.Empty;
            string database                = string.Empty;
            string sessionName             = string.Empty;
            int    durationHours           = 2;
            IEnumerable <string> scenarios = null;

            if (_arguments != null)
            {
                scenarios     = _arguments["scenarios"].ToString().Split(';');
                dispatcher    = string.IsNullOrEmpty(_arguments["dispatcher"]) ? Environment.MachineName : _arguments["dispatcher"].ToString();
                database      = _arguments["database"].ToString();
                sessionName   = _arguments["sessionName"].ToString();
                durationHours = string.IsNullOrEmpty(_arguments["durationHours"]) ? 2 : Convert.ToInt32(_arguments["durationHours"]);
            }

            if (string.IsNullOrEmpty(dispatcher))
            {
                _state = SessionState.Error;
                throw new ArgumentException("Dispatcher is required.", "dispatcher");
            }
            TraceFactory.SetThreadContextProperty("Dispatcher", dispatcher, false);

            if (string.IsNullOrEmpty(sessionName))
            {
                _state = SessionState.Error;
                throw new ArgumentException("Session Name is required.", "sessionName");
            }
            if (string.IsNullOrEmpty(database))
            {
                _state = SessionState.Error;
                throw new ArgumentException("Database Host is required.", "database");
            }

            if (string.IsNullOrEmpty(_arguments["owner"].ToString()))
            {
                _state = SessionState.Error;
                throw new ArgumentException("Session Owner User name is required.", "owner");
            }

            if (GlobalSettings.IsDistributedSystem)
            {
                //We only care about password and domain if it's STF
                if (string.IsNullOrEmpty(_arguments["password"]))
                {
                    _state = SessionState.Error;
                    throw new ArgumentException("Session owner Password is required.", "password");
                }

                if (string.IsNullOrEmpty(_arguments["domain"]))
                {
                    _state = SessionState.Error;
                    throw new ArgumentException("User Domain is required.", "domain");
                }
            }

            // No need to check optional args.  They will be handled later.

            //Initialize the environment and create a ticket.
            GlobalSettings.SetDispatcher(dispatcher);
            GlobalSettings.Load(database);

            _ticket = SessionTicket.Create(scenarios, sessionName, durationHours);
            _ticket.SessionOwner   = GetSessionOwner(_arguments["owner"], _arguments["password"], _arguments["domain"] ?? Environment.UserDomainName);
            _ticket.ExpirationDate = SessionLogRetention.Month.GetExpirationDate(DateTime.Now);
        }
Esempio n. 14
0
        public static bool Start(string dispatcher, string database, string scenario, out string clientVM, out string sessionId, out string result)
        {
            _clientVM           = string.Empty;
            _errorDetails       = string.Empty;
            _isSessionCompleted = false;
            _sessionError       = false;

            Console.WriteLine("Starting session...");

            GlobalSettings.SetDispatcher(dispatcher);
            GlobalSettings.Load(database);

            _ticket = SessionTicket.Create(scenario);
            _ticket.SessionOwner = new UserCredential("youngmak", "AMERICAS.CPQCORP.NET");
            Console.WriteLine("Created ticket {0}".FormatWith(_ticket.SessionId));

            SessionClient.Instance.DispatcherExceptionReceived      += DispatcherErrorReceived;
            SessionClient.Instance.SessionStateReceived             += SessionStateChanged;
            SessionClient.Instance.SessionStartupTransitionReceived += SessionStartupTransitionReceived;
            SessionClient.Instance.SessionMapElementReceived        += Instance_SessionMapElementReceived;

            TraceFactory.Logger.Debug("Initializing");
            SessionClient.Instance.Initialize(dispatcher);

            SessionClient.Instance.InitiateSession(_ticket);

            var assetDetails = SessionClient.Instance.Reserve(_ticket.SessionId);

            Console.WriteLine("Reserved...{0}".FormatWith(_ticket.SessionId));

            foreach (var asset in assetDetails.Where(x => x.Availability == AssetAvailability.NotAvailable))
            {
                Console.WriteLine("Unavailable: {0}".FormatWith(asset.AssetId));
            }

            // This call to Stage() will kick off the process and as each event arrives to indicate
            // a step in the process has completed, the next step will automatically continue.
            SessionClient.Instance.Stage(_ticket.SessionId, assetDetails);
            Console.WriteLine("Staged...{0}".FormatWith(_ticket.SessionId));

            _isSessionCompleted = false;

            while (!_isSessionCompleted)
            {
                // block till the session completed or throws error
            }

            sessionId = _ticket.SessionId;
            clientVM  = _clientVM;

            if (_sessionError)
            {
                result = _errorDetails;
                return(false);
            }
            else
            {
                result = "Executed Successful";
                return(true);
            }
        }