Exemplo n.º 1
0
        private void ShutdownScenarioHandler(string sessionId, ShutdownOptions options)
        {
            try
            {
                // If a session exists, proceed with the shutdown, otherwise, just return.
                SessionProxyController controller = null;
                if (_proxyControllers.TryGetValue(sessionId, out controller))
                {
                    _proxyControllers.Remove(controller);
                    TraceFactory.Logger.Debug("Found & removed controller: Cnt: {0} : {1}".FormatWith(_proxyControllers.Count, controller.Endpoint.AbsoluteUri));

                    if (!controller.SessionClosing) //Make sure the session isn't already closing
                    {
                        lock (controller)
                        {
                            controller.SessionClosing = true;
                            ThreadPool.QueueUserWorkItem(t => ShutdownScenario(controller, sessionId, options));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TraceFactory.Logger.Error(ex);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds the specified entry.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">Adding this entry will exceed the maximum allowable of {0}.FormatWith(Maximum)</exception>
        public void Add(SessionProxyController entry)
        {
            if (_controllers.Count() + 1 > Maximum)
            {
                throw new ArgumentOutOfRangeException("Adding this entry will exceed the maximum allowable of {0}".FormatWith(Maximum));
            }

            _controllers.Add(entry.SessionId, entry);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Removes an entry based on the specified session unique identifier.
        /// </summary>
        /// <param name="controller">The controller.</param>
        public void Remove(SessionProxyController controller)
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }

            if (_controllers.ContainsKey(controller.SessionId))
            {
                _controllers.Remove(controller.SessionId);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Starts the Session Proxy process if not already running.
        /// </summary>
        public void StartProxyProcess(string sessionId)
        {
            try
            {
                SessionProxyController controller = null;
                if (!_controllers.TryGetValue(sessionId, out controller))
                {
                    controller = new SessionProxyController(sessionId);
                    _controllers.Add(sessionId, controller);
                }

                TraceFactory.Logger.Debug(">>>> {0} - Starting Proxy Process...".FormatWith(sessionId));
                controller.StartProxyProcess();
                TraceFactory.Logger.Debug(">>>> {0} - Starting Proxy Process...Done".FormatWith(sessionId));
            }
            catch (Exception ex)
            {
                TraceFactory.Logger.Error(ex);
                throw;
            }
        }
Exemplo n.º 5
0
 private void ShutdownScenario(SessionProxyController controller, string sessionId, ShutdownOptions options)
 {
     try
     {
         SetTraceSessionContext(sessionId);
         TraceFactory.Logger.Debug("{0}: {1}".FormatWith(sessionId, controller.Endpoint.AbsoluteUri));
         if (controller.ProxyProcessStarted)
         {
             controller.Channel.Shutdown(options);
         }
         else
         {
             TraceFactory.Logger.Debug("Proxy process not started");
         }
     }
     catch (Exception ex)
     {
         TraceFactory.Logger.Warn("Error sending shutdown call, ignoring", ex);
     }
     finally
     {
         controller.Dispose();
     }
 }
Exemplo n.º 6
0
 public bool TryGetValue(string sessionId, out SessionProxyController controller)
 {
     return(_controllers.TryGetValue(sessionId, out controller));
 }
Exemplo n.º 7
0
        private void CloseSessionHandler(string sessionId, ShutdownOptions options)
        {
            SetTraceSessionContext(sessionId);
            SessionProxyController controller = null;

            if (_proxyControllers.TryGetValue(sessionId, out controller))  //If a session exists, proceed with normal shutdown.  Otherwise reset manually.
            {
                _proxyControllers.Remove(controller);
                TraceFactory.Logger.Debug("Found & removed controller: Count: {0} : {1}".FormatWith(_proxyControllers.Count, controller.Endpoint.AbsoluteUri));

                if (!controller.SessionClosing) //Make sure the session isn't already closing
                {
                    lock (controller)
                    {
                        controller.SessionClosing = true;
                        try
                        {
                            ThreadPool.QueueUserWorkItem(t => ShutdownScenario(controller, sessionId, options));
                        }
                        catch (Exception ex)
                        {
                            TraceFactory.Logger.Error(ex);
                        }
                    }
                }
            }
            else
            {
                TraceFactory.Logger.Debug(string.Format("Closing session {0}", sessionId));

                // Manually reset DomainAccountReservation for all inactive SessionIds
                using (AssetInventoryContext context = DbConnect.AssetInventoryContext())
                {
                    List <string> activeSessionIds = context.FrameworkClients.Select(n => n.SessionId).Distinct().Where(n => n != null).ToList();

                    foreach (var reservation in context.DomainAccountReservations)
                    {
                        if (!activeSessionIds.Contains(reservation.SessionId))
                        {
                            context.DomainAccountReservations.Remove(reservation);
                        }
                    }
                    context.SaveChanges();
                }

                try
                {
                    // Parallel process the two actions required to clean up this session, first define
                    // the collection of actions, then spawn them each off in the background and then
                    // wait for them to return.
                    var actions = new Collection <Action>()
                    {
                        () => CleanupAssetHosts(sessionId),
                        () => CleanupResourceHosts(sessionId)
                    };
                    Parallel.ForEach <Action>(actions, a => a());

                    using (DataLogContext context = DbConnect.DataLogContext())
                    {
                        SessionSummary summary = context.DbSessions.First(n => n.SessionId == sessionId);
                        summary.Status      = SessionStatus.Aborted.ToString();
                        summary.EndDateTime = DateTime.UtcNow;
                        context.SaveChanges();
                    }

                    UpdateSessionShutdownState(MachineShutdownState.ManualReset, sessionId, ignoreMissing: true);
                    TraceFactory.Logger.Info("Done closing {0}".FormatWith(sessionId));
                }
                catch (Exception ex)
                {
                    TraceFactory.Logger.Error(ex);
                }

                // Tell all clients to clean up any session info
                EventPublisher.ReleaseSession(sessionId);
                //Checks for any Virtual worker process which may have not been terminated correctly from the previous runs
                if (GlobalSettings.IsDistributedSystem == false)
                {
                    using (DataLogContext context = DbConnect.DataLogContext())
                    {
                        SessionSummary summary = context.DbSessions.First(n => n.SessionId == sessionId);
                        if (summary.Dispatcher == Environment.MachineName)
                        {
                            KillOrphanedWorkerProcesses(sessionId);
                        }
                    }
                }
            }
        }