Пример #1
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");
        }
Пример #2
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;
            }
        }
Пример #3
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);
        }
Пример #4
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);
            }
        }