/// <summary>
        /// Sets up this instance using the specified client controller host name.
        /// </summary>
        /// <param name="clientControllerHostName">Name of the client controller host.</param>
        public static OfficeWorkerActivityController Create(string clientControllerHostName, string instanceId)
        {
            // The office worker is a separate process, so it must make a call up to the client controller to obtain
            // the manifest that will be used for the test.
            SystemManifest manifest = null;

            using (var serviceConnection = ClientControllerServiceConnection.Create(clientControllerHostName))
            {
                var data = serviceConnection.Channel.GetManifest(instanceId);
                manifest = SystemManifest.Deserialize(data);
                manifest.PushToGlobalDataStore(instanceId);
                manifest.PushToGlobalSettings();
                _sessionId    = manifest.SessionId;
                _statusLogger = new VirtualResourceInstanceStatusLogger(_sessionId, Environment.UserName, 0, Enum.GetName(typeof(RuntimeState), 6), false, GlobalDataStore.ResourceInstanceId);
            }


            TraceFactory.Logger.Debug("Resource type: {0}".FormatWith(manifest.ResourceType));
            TraceFactory.Logger.Debug("InstanceId: {0}".FormatWith(GlobalDataStore.ResourceInstanceId));
            TraceFactory.Logger.Debug("UserName: {0}".FormatWith(GlobalDataStore.Credential.UserName));

            FrameworkServicesInitializer.InitializeExecution();

            return(ObjectFactory.Create <OfficeWorkerActivityController>(manifest.ResourceType, clientControllerHostName));
        }
Exemplo n.º 2
0
        private void LoadManifest(ref string instanceId)
        {
            // Get the manifest from the factory
            TraceFactory.Logger.Debug("Attempting to get the manifest from the Factory Service");
            SystemManifest manifest = null;

            using (var clientController = ClientControllerServiceConnection.Create(Environment.MachineName))
            {
                var data = clientController.Channel.GetManifest(instanceId);
                manifest = SystemManifest.Deserialize(data);
            }

            // Cache the definition that corresponds to the resourceId
            var definition = manifest.Resources.GetByType(VirtualResourceType.PerfMonCollector).FirstOrDefault();

            if (definition == null)
            {
                throw new InvalidOperationException("Resource Definition is null.");
            }

            manifest.PushToGlobalSettings();
            manifest.PushToGlobalDataStore(definition.Name);

            _sessionId = manifest.SessionId;

            // get all the resources which are of type perfmoncollector
            var perfMonResources = manifest.Resources.Where(c => c.ResourceType == VirtualResourceType.PerfMonCollector);

            // if we have permoncounter collectors then we read manifest
            if (perfMonResources.Count() > 0)
            {
                ReadManifest(perfMonResources);
            }
            else
            {
                throw new InvalidOperationException("No performance counters to monitor");
            }


            TraceFactory.Logger.Info(Environment.NewLine + manifest.ToString());
        }
Exemplo n.º 3
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();
            }
        }