Esempio n. 1
0
 private void SendStatusMessage(string message)
 {
     using (var proxyClient = SessionProxyBackendConnection.Create(_dispatcherAddress, _sessionId))
     {
         proxyClient.Channel.ChangeMachineStatusMessage(Environment.MachineName, message);
     }
 }
Esempio n. 2
0
        private void AppDomain_ThreadException(object sender, UnhandledExceptionEventArgs e)
        {
            Exception error = (Exception)e.ExceptionObject;

            TraceFactory.Logger.Fatal(error);
            SessionProxyBackendConnection.ChangeResourceState(RuntimeState.Error);
            Environment.Exit(1);
        }
Esempio n. 3
0
 private void Instance_OnExecutionPaused(object sender, EventArgs e)
 {
     // Once the wait count is met, then this event handler will be called.  Set the isPaused
     // to true which will discontinue the loop just above looking for missing threads.  Turn
     // off the event and send a signal out that the resource is now paused.
     _isPaused = true;
     ApplicationFlowControl.Instance.OnExecutionPaused -= Instance_OnExecutionPaused;
     SessionProxyBackendConnection.ChangeResourceState(RuntimeState.Paused);
 }
        /// <summary>
        /// Creates the resources.
        /// </summary>
        public override void Start()
        {
            ChangeResourceState(RuntimeState.Starting);

            OpenManagementServiceEndpoint(_reservation.Name);

            // Register and let the dispatcher know it's available to run.
            SessionProxyBackendConnection.RegisterResource(ServiceEndpoint);
        }
 private void VirtualResourceEventBus_OnReadyToRegister(object sender, EventArgs e)
 {
     // Register and let the dispatcher know it's available to run.
     TraceFactory.Logger.Debug("Registering with proxy: {0}:{1} -> {2}"
                               .FormatWith(GlobalDataStore.Manifest.HostMachine, GlobalDataStore.ResourceInstanceId, _commandService.BaseAddresses[0].AbsoluteUri));
     SessionProxyBackendConnection.RegisterResource(_commandService.BaseAddresses[0]);
     TraceFactory.Logger.Debug("Registering with proxy complete");
     ChangeState(RuntimeState.Registered);
 }
        /// <summary>
        /// Reports a non-functioning asset to the runtime framework.
        /// </summary>
        /// <param name="assetInfo">The <see cref="IAssetInfo" /> representing the asset in error.</param>
        /// <exception cref="ArgumentNullException"><paramref name="assetInfo" /> is null.</exception>
        public void ReportAssetError(IAssetInfo assetInfo)
        {
            if (assetInfo == null)
            {
                throw new ArgumentNullException(nameof(assetInfo));
            }

            RuntimeError assetError = new RuntimeError(assetInfo.AssetId);

            SessionProxyBackendConnection.HandleAssetError(assetError);
        }
        /// <summary>
        /// Collects a memory usage profile from the specified device.
        /// </summary>
        /// <param name="deviceInfo">The <see cref="IDeviceInfo" /> representing the device to profile.</param>
        /// <param name="label">The label to apply (for logging purposes).</param>
        /// <exception cref="ArgumentNullException"><paramref name="deviceInfo" /> is null.</exception>
        public void CollectDeviceMemoryProfile(IDeviceInfo deviceInfo, string label)
        {
            if (deviceInfo == null)
            {
                throw new ArgumentNullException(nameof(deviceInfo));
            }

            //Manually serialize the IDeviceInfo object before going over the wire.
            string serializedDeviceInfo = Serializer.Serialize(deviceInfo).ToString();

            SessionProxyBackendConnection.CollectDeviceMemoryProfile(serializedDeviceInfo, label);
        }
Esempio n. 8
0
        /// <summary>
        /// Event raised by the client factory when the "Shutdown" call has been made.
        /// </summary>
        private void EventBus_OnStop(object sender, EventArgs e)
        {
            TraceFactory.Logger.Info("Stop message received.");

            foreach (PerfMonCounterByInterval counter in _perfMonCountersInterval)
            {
                counter.Stop();
            }

            TraceFactory.Logger.Debug("Logs flushed, sending offline signal");

            SessionProxyBackendConnection.ChangeResourceState(RuntimeState.Offline);
        }
Esempio n. 9
0
        private void EventBus_OnStart(object sender, EventArgs e)
        {
            TraceFactory.Logger.Info("Start message received.");
            Console.WriteLine("Starting counters");

            //start monitoring based on interval
            foreach (PerfMonCounterByInterval counter in _perfMonCountersInterval)
            {
                counter.Start();
            }

            SessionProxyBackendConnection.ChangeResourceState(RuntimeState.Running);
        }
        protected virtual void ChangeState(RuntimeState state, bool copyLogs = false)
        {
            var instanceId = GlobalDataStore.ResourceInstanceId;

            TraceFactory.Logger.Debug("{0} - change state to: {1}".FormatWith(instanceId, state));
            TraceFactory.Logger.Debug("Machine: {0}".FormatWith(GlobalDataStore.Manifest.HostMachine));

            SessionProxyBackendConnection.ChangeResourceState(state);

            if (WorkerStateChanged != null)
            {
                WorkerStateChanged(this, new ResourceEventArgs(instanceId, state, copyLogs));
            }
        }
        /// <summary>
        /// Creates all EventLogCollector virtual resources.
        /// </summary>
        public override void Start()
        {
            ChangeResourceState(RuntimeState.Starting);

            OpenManagementServiceEndpoint(_credential.UserName);

            ChangeMachineStatusMessage("Configuring User");
            CitrixSessionManager.ConfigureLocalUserGroups(_credential, _citrixServer);

            ChangeMachineStatusMessage("Resetting Citrix");
            CitrixSessionManager.ResetCitrixSession(_credential.UserName, _citrixServer);

            // Register and let the dispatcher know it's available to run.
            SessionProxyBackendConnection.RegisterResource(ServiceEndpoint);
        }
Esempio n. 12
0
        private void engineController_WorkerStateChanged(object sender, ResourceEventArgs e)
        {
            if (logTextBox.InvokeRequired)
            {
                logTextBox.Invoke(new MethodInvoker(() => this.engineController_WorkerStateChanged(sender, e)));
            }
            else
            {
                switch (e.State)
                {
                case RuntimeState.Running:
                case RuntimeState.Paused:
                case RuntimeState.Halted:
                case RuntimeState.Completed:
                    string message = "{0}: Activities are {1}.".FormatWith(TimeStamp, e.State);
                    logTextBox.AppendText(message + Environment.NewLine);
                    break;

                case RuntimeState.ShuttingDown:
                    logTextBox.AppendText(TimeStamp + ": Shutting down..." + Environment.NewLine);
                    TraceFactory.Logger.Info("Shutdown message received, exiting in a few seconds");

                    // Dispose the controller which will cascade down and dispose all participating plugins
                    TraceFactory.Logger.Info("Disposing controller, engines and activities");
                    try
                    {
                        _controller.Dispose();
                    }
                    catch (Exception ex)
                    {
                        TraceFactory.Logger.Error(ex.Message);
                    }

                    if (e.CopyLogs)
                    {
                        TraceFactory.Logger.Debug("Pushing log file back to SessionProxy.  Log Location: {0}".FormatWith(_logPath));
                        SessionProxyBackendConnection.SaveLogFiles(_logPath);
                        TraceFactory.Logger.Debug("Log files saved, changing state to offline.");
                    }

                    SessionProxyBackendConnection.ChangeResourceState(RuntimeState.Offline);

                    Thread.Sleep(TimeSpan.FromSeconds(2));
                    Application.Exit();
                    break;
                }
            }
        }
Esempio n. 13
0
        private void ExecuteTasks()
        {
            LoadTesterActivityController.SetThreadName();

            TraceFactory.Logger.Debug("Starting parallel execution of all tasks");

            // Spin up each thread in parallel to get them all started at about the same time.
            foreach (var thread in _threads)
            {
                thread.Task.Start();
            }

            // Wait for all the tasks to complete before proceeding
            Task.WaitAll(_threads.Select(x => x.Task).ToArray());

            TraceFactory.Logger.Debug("ALL TASKS COMPLETE");
            SessionProxyBackendConnection.ChangeResourceState(RuntimeState.Completed);
        }
Esempio n. 14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="resourceId"></param>
        public Program(string resourceId)
        {
            //Set up the local service port
            LoadServiceEndpoint();

            // Sign up for the event that is fired when the client tells us to run.
            VirtualResourceEventBus.OnStartMainRun     += EventBus_OnStart;
            VirtualResourceEventBus.OnShutdownResource += EventBus_OnStop;
            VirtualResourceEventBus.OnPauseResource    += EventBus_OnPause;
            VirtualResourceEventBus.OnResumeResource   += EventBus_OnResume;

            LoadManifest(ref resourceId);

            InitializeCounters();

            SessionProxyBackendConnection.RegisterResource(_serviceEndpoint);

            TraceFactory.Logger.Info("Monitoring {0}".FormatWith(GlobalDataStore.ResourceInstanceId));
            //TraceFactory.Logger.Debug("Counters to monitor: " + components); //TODO: Hook this up
        }
        /// <summary>
        /// Creates all EventLogCollector virtual resources.
        /// </summary>
        public override void Start()
        {
            LoadManifest();

            ChangeResourceState(Runtime.RuntimeState.Starting);

            // Sign up for the event that is fired when the client tells us to run.
            VirtualResourceEventBus.OnStartMainRun     += VirtualResourceEventBus_OnStart;
            VirtualResourceEventBus.OnShutdownResource += VirtualResourceEventBus_OnStop;
            VirtualResourceEventBus.OnPauseResource    += VirtualResourceEventBus_OnPause;
            VirtualResourceEventBus.OnResumeResource   += VirtualResourceEventBus_OnResume;

            OpenManagementServiceEndpoint(_collector.ResourceDefinition.HostName);

            TraceFactory.Logger.Info("Monitoring: {0}{1}{2}".FormatWith(_collector.ResourceDefinition.HostName, Environment.NewLine, DisplayCollection(_collector.ResourceDefinition.Components)));

            SessionProxyBackendConnection.RegisterResource(ServiceEndpoint);

            TraceFactory.Logger.Debug("Dispatcher notified that system is ready to start");
        }
Esempio n. 16
0
        public override void Start()
        {
            // Open the service endpoint so this resource can receive commands from the dispatcher,
            // then start the engine controller and then let the dispatcher know that this
            // resource is ready to run.

            var name = SystemManifest.Resources.OfType <LoadTesterDetail>().First().Name;

            ChangeResourceState(RuntimeState.Starting);

            OpenManagementServiceEndpoint(GlobalDataStore.ResourceInstanceId);

            TraceFactory.Logger.Debug("Service endpoint opened");

            _controller = new LoadTesterActivityController();
            _controller.Start();

            TraceFactory.Logger.Debug("Load tester activity controller started");

            // Register and let the dispatcher know it's available to run.
            SessionProxyBackendConnection.RegisterResource(ServiceEndpoint);

            TraceFactory.Logger.Debug("Dispatcher notified that system is ready to start");
        }
Esempio n. 17
0
        void VirtualResourceEventBus_OnStartMainRun(object sender, VirtualResourceEventBusRunArgs e)
        {
            var resource = _manifest.Resources.First();

            TraceFactory.Logger.Debug("Metadata count: {0}".FormatWith(resource.MetadataDetails.Count));

            SessionProxyBackendConnection.ChangeResourceState(RuntimeState.Starting);

            foreach (var metadataDetail in resource.MetadataDetails.Cast <LoadTesterMetadataDetail>())
            {
                var plan = metadataDetail.Plan as LoadTesterExecutionPlan;

                if (plan.Mode != ExecutionMode.Poisson)
                {
                    TraceFactory.Logger.Debug("Mode: {0}".FormatWith(plan.RampUpMode));

                    switch (plan.RampUpMode)
                    {
                    case RampUpMode.RateBased:
                        StartWithRateBasedRampUp(metadataDetail);
                        break;

                    case RampUpMode.TimeBased:
                        StartWithTimeBasedRampUp(metadataDetail);
                        break;
                    }
                }
                else
                {
                    Task.Factory.StartNew(() => StartPoissonHandler(metadataDetail));
                }
            }

            // Notify clients that this resource is now running
            SessionProxyBackendConnection.ChangeResourceState(RuntimeState.Running);
        }
 /// <summary>
 /// Signals a synchronization event with the specified name.
 /// </summary>
 /// <param name="eventName">The synchronization event name.</param>
 public void SignalSynchronizationEvent(string eventName)
 {
     SessionProxyBackendConnection.SignalSynchronizationEvent(eventName);
 }
 private void EngineEventBus_ActivityStatusMessageChanged(object sender, StatusChangedEventArgs e)
 {
     SessionProxyBackendConnection.ChangeResourceStatusMessage(e.StatusMessage);
 }
Esempio n. 20
0
 private void UnhandledException(Exception e)
 {
     TraceFactory.Logger.Fatal(e);
     SessionProxyBackendConnection.ChangeResourceState(RuntimeState.Error);
     Environment.Exit(1);
 }
Esempio n. 21
0
 private void EventBus_OnPause(object sender, EventArgs e)
 {
     TraceFactory.Logger.Info("Pause message received.");
     SessionProxyBackendConnection.ChangeResourceState(RuntimeState.Paused);
 }
Esempio n. 22
0
        /// <summary>
        /// Starts this instance of the <see cref=" VirtualClientController"/> to work with the Dispatcher,
        /// then creates the virtual resources based on the provided <see cref="SystemManifest"/>.
        /// </summary>
        /// <remarks>
        /// Creates a <see cref="SessionProxyBackendConnection"/> that is used to communicate with the
        /// Dispatcher to provide status updates.  Loads the <see cref="SystemManifest"/>  into
        /// the <see cref="GlobalDataStore"/> and into the <see cref="GlobalSettings"/>.
        /// </remarks>
        public void Start(string sessionId)
        {
            _sessionId = sessionId;

            // Contact the dispatcher and register.
            string manifestData = string.Empty;

            TraceFactory.Logger.Debug("Registering with Dispatcher {0}, SessionId: {1}".FormatWith(_dispatcherAddress, _sessionId));
            using (var proxyClient = SessionProxyBackendConnection.Create(_dispatcherAddress, _sessionId))
            {
                manifestData = proxyClient.Channel.RegisterMachine(Environment.MachineName);
            }

            _manifest = SystemManifest.Deserialize(manifestData);
            string resourceInstanceId = string.Empty;

            switch (_manifest.ResourceType)
            {
            case VirtualResourceType.AdminWorker:
            case VirtualResourceType.OfficeWorker:
            case VirtualResourceType.SolutionTester:
                // These types don't use the resource instance Id as there can be multiple instances
                // of the worker within the client controller process.
                _manifest.PushToGlobalDataStore();

                //The following code monitors the local host VM client event logs.
                if (_manifest.CollectEventLogs)
                {
                    EventLogCollectorDetail detail = new EventLogCollectorDetail();
                    detail.ComponentsData  = Resources.ClientEventLogComponents;
                    detail.EntryTypesData  = Resources.ClientEventLogEntryTypes;
                    detail.Description     = "Client VM Event Collector";
                    detail.Enabled         = true;
                    detail.HostName        = Environment.MachineName;
                    detail.Name            = Environment.MachineName;
                    detail.ResourceType    = VirtualResourceType.EventLogCollector;
                    detail.PollingInterval = 15;
                    _manifest.Resources.Add(detail);
                    resourceInstanceId = _manifest.Resources.OfType <EventLogCollectorDetail>().First().HostName;
                    _manifest.PushToGlobalDataStore(resourceInstanceId);
                }

                break;

            case VirtualResourceType.CitrixWorker:
            case VirtualResourceType.LoadTester:
                // These resources use credentials like the workers above, but run in the
                // client controller process, so the data store needs the resource instance Id set.
                resourceInstanceId = _manifest.Resources.Credentials.First().ResourceInstanceId;
                _manifest.PushToGlobalDataStore(resourceInstanceId);
                break;

            case VirtualResourceType.EventLogCollector:
                // This resource is unique as it uses the hostname as its unique name.  It also
                // runs within the client controller process so it needs its instance Id set.
                // This event log collector monitors target machines rather than the local VM running the client controller
                resourceInstanceId = _manifest.Resources.OfType <EventLogCollectorDetail>().First().HostName;
                _manifest.PushToGlobalDataStore(resourceInstanceId);
                break;

            default:
                // All other resources also run in the client controller process, but they use Name
                // as their unique id.
                var type = GetDetailType(_manifest.ResourceType);
                resourceInstanceId = _manifest.Resources.Where(x => x.GetType().Equals(type)).First().Name;
                TraceFactory.Logger.Debug("Resource Instance Id: {0}".FormatWith(resourceInstanceId));
                _manifest.PushToGlobalDataStore(resourceInstanceId);
                break;
            }

            TraceFactory.Logger.Debug("Resource Instance Id: {0}".FormatWith(resourceInstanceId));

            _manifest.PushToGlobalSettings();

            GlobalSettings.SetDispatcher(_dispatcherAddress);

            TraceFactory.Logger.Debug(_manifest.ToString());

            InstallPrintingCertficates();
            InstallClientSoftware();

            // Creates all the virtual resources specified in the provided manifest.
            _handlers = VirtualResourceHandlerFactory.Create(_manifest);
            foreach (var handler in _handlers)
            {
                handler.Start();
            }
        }
Esempio n. 23
0
 public static void RegisterResource(string resourceInstanceId, Uri endpoint)
 {
     SessionProxyBackendConnection.RegisterResource(endpoint);
 }
Esempio n. 24
0
 /// <summary>
 /// Changes the machine status.
 /// </summary>
 /// <param name="message">The status.</param>
 public static void ChangeMachineStatusMessage(string message)
 {
     SessionProxyBackendConnection.ChangeMachineStatusMessage(message);
 }
Esempio n. 25
0
 private void VirtualResourceEventBus_OnShutdownResource(object sender, VirtualResourceEventBusShutdownArgs e)
 {
     SessionProxyBackendConnection.ChangeResourceState(RuntimeState.ShuttingDown);
 }
Esempio n. 26
0
 /// <summary>
 /// Changes the state.
 /// </summary>
 /// <param name="state">The state.</param>
 public static void ChangeResourceState(RuntimeState state)
 {
     SessionProxyBackendConnection.ChangeResourceState(state);
 }
Esempio n. 27
0
        private void StartPoissonHandler(LoadTesterMetadataDetail metadataDetail)
        {
            var plan = metadataDetail.Plan as LoadTesterExecutionPlan;

            var duration = TimeSpan.FromMinutes(plan.DurationTime);


            var distribution = new PoissonDistribution().GetNormalizedValues(plan.ThreadCount);

            if (distribution.Count() == 0)
            {
                TraceFactory.Logger.Debug("NO TASKS TO RUN");
                SessionProxyBackendConnection.ChangeResourceState(RuntimeState.Completed);
                return;
            }

            // Get the time delta between each sample point.
            var delta = TimeSpan.FromTicks(duration.Ticks / (distribution.Count() - 1));

            TraceFactory.Logger.Debug("Time Delta {0}".FormatWith(delta));

            // Change the plan to support the Poisson settings.  This will create
            // each Task with a shorter execution time and will only create a
            // DurationBased execution engine.
            plan.DurationTime = (int)delta.TotalMinutes;
            plan.Mode         = ExecutionMode.Duration;

            foreach (int threadCount in distribution)
            {
                // Create all the threads that will be used.
                for (int i = 0; i < threadCount; i++)
                {
                    // There is now ramp up delay with a Poisson thread
                    _threads.Add(new LoadTestThread(metadataDetail, TimeSpan.Zero));
                }

                // Start each thread for this segment
                TraceFactory.Logger.Debug("Created {0} Tasks, now starting them...".FormatWith(threadCount));
                foreach (var thread in _threads)
                {
                    thread.Task.Start();
                }

                TraceFactory.Logger.Debug("{0} Tasks started, waiting for them to complete".FormatWith(threadCount));

                // Wait for all the current threads to complete.
                Task.WaitAll(_threads.Select(x => x.Task).ToArray());

                // Clean up the completed threads
                TraceFactory.Logger.Debug("{0} Tasks completed, disposing and clearing list".FormatWith(threadCount));
                foreach (var thread in _threads)
                {
                    thread.Dispose();
                }

                _threads.Clear();
            }

            TraceFactory.Logger.Debug("ALL TASKS COMPLETE");
            SessionProxyBackendConnection.ChangeResourceState(RuntimeState.Completed);
        }
Esempio n. 28
0
 private void VirtualResourceEventBus_ResumeResource(object sender, EventArgs e)
 {
     ApplicationFlowControl.Instance.Resume();
     SessionProxyBackendConnection.ChangeResourceState(RuntimeState.Running);
 }
Esempio n. 29
0
 /// <summary>
 /// Changes the state.
 /// </summary>
 /// <param name="resourceInstanceId">Unique id for this resource.</param>
 /// <param name="state">The state.</param>
 public static void ChangeResourceState(string resourceInstanceId, RuntimeState state)
 {
     SessionProxyBackendConnection.ChangeResourceState(resourceInstanceId, state);
 }