/// <summary> /// Adds Asset info to the specified <see cref="SystemManifest"/>. /// </summary> /// <param name="manifest">The <see cref="SystemManifest"/>.</param> public void AssignManifestInfo(SystemManifest manifest) { manifest.AllAssets.Clear(); manifest.ActivityAssets.Clear(); List <AssetInfo> assetInfoList = new List <AssetInfo>(); var assetIds = _activityAssets.Values.SelectMany(n => n).Distinct().ToList(); using (AssetInventoryContext context = DbConnect.AssetInventoryContext()) { assetInfoList.AddRange(context.Assets.Where(n => assetIds.Contains(n.AssetId)).ToAssetInfoCollection()); assetInfoList.AddRange(context.BadgeBoxes.Where(n => assetIds.Contains(n.PrinterId)).ToBadgeBoxInfoCollection()); } foreach (AssetInfo asset in assetInfoList) { manifest.AllAssets.Add(asset); TraceFactory.Logger.Debug("asset: " + asset.AssetId + " Desc: " + asset.Description); } foreach (var activityAsset in _activityAssets) { manifest.ActivityAssets.Add(activityAsset.Key, activityAsset.Value); } }
/// <summary> /// Creates resource detail and inserts it into the manifest. /// </summary> /// <param name="resources">The resources.</param> /// <param name="manifest">The manifest.</param> internal override void AddToManifest(Collection <VirtualResource> resources, SystemManifest manifest) { // There is one Load Tester per VM, so there should only be one // resource embedded in this manifest. var resource = resources.First(); // First determine if the resource already exists in the Resource collection. If not, then // have VirtualResource create it, then update it with other data and add it to the list. var detail = manifest.Resources.GetResource <LoadTesterDetail>(resource.VirtualResourceId); if (detail == null) { detail = CreateDetail(resource); detail.CommandPortOffset = 40000; manifest.Resources.Add(detail); } // Use the system settings Administrator credentials for the AdminWorker var userCredential = new OfficeWorkerCredential(); userCredential.UserName = GlobalSettings.Items[Setting.DomainAdminUserName]; userCredential.Password = GlobalSettings.Items[Setting.DomainAdminPassword]; userCredential.Domain = GlobalSettings.Items[Setting.Domain]; userCredential.Port = detail.CommandPortOffset; userCredential.ResourceInstanceId = SystemManifestAgent.CreateUniqueId(userCredential.UserName); detail.UserCredentials.Add(userCredential); }
/// <summary> /// Creates the specified resources. /// </summary> /// <param name="resources">The resources.</param> /// <param name="manifest">The manifest.</param> internal override void AddToManifest(Collection <VirtualResource> resources, SystemManifest manifest) { // Iterate through each resource and create the office worker process foreach (VirtualResource resource in resources) { // First determine if the resource already exists in the Resource collection. If not, then // have VirtualResource create it, then update it with other data and add it to the list. var detail = manifest.Resources.GetResource <AdminWorkerDetail>(resource.VirtualResourceId); if (detail == null) { detail = (AdminWorkerDetail)CreateDetail(resource); detail.CommandPortOffset = 40000; manifest.Resources.Add(detail); } // Use the system settings Administrator credentials for the AdminWorker var userCredential = new OfficeWorkerCredential(); userCredential.UserName = GlobalSettings.Items[Setting.DomainAdminUserName]; userCredential.Password = GlobalSettings.Items[Setting.DomainAdminPassword]; userCredential.Domain = GlobalSettings.Items[Setting.Domain]; userCredential.Port = detail.CommandPortOffset; // This only works with just the username because there is only one // allowed per VM. If this ever changes then there will need to be a // unique suffix added. //userCredential.InstanceId = SystemManifestAgent.CreateUniqueId(userCredential.UserName); userCredential.ResourceInstanceId = userCredential.UserName; detail.UserCredentials.Add(userCredential); } }
protected void LoadResources <T>(Collection <VirtualResource> resources, SystemManifest manifest) where T : OfficeWorkerDetail { // Iterate through each resource and create the office worker process foreach (var resource in resources) { // First determine if the resource already exists in the Resource collection. If not, then // have VirtualResource create it, then update it with other data and add it to the list. var detail = manifest.Resources.GetResource <T>(resource.VirtualResourceId); if (detail == null) { detail = (T)CreateDetail(resource); detail.OfficeWorkerCount = ResourcePacker.TotalResourceCount(ResourceType); detail.StartIndex = ManifestAgent.UserAccounts.StartIndex(((OfficeWorker)resource).UserPool); detail.UserNameFormat = ManifestAgent.UserAccounts.UserFormat(((OfficeWorker)resource).UserPool); detail.CommandPortOffset = 40000; manifest.Resources.Add(detail); } // Get the next credential and add it to the OW definition OfficeWorkerCredential credential = AddCredential(resource, detail); detail.UserCredentials.Add(credential); // Add any external credentials associated with the OW credential AddExternalCredentials(credential, detail); } }
/// <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)); }
/// <summary> /// Creates resource detail and inserts it into the manifest. /// </summary> /// <param name="resources">The resources.</param> /// <param name="manifest">The manifest.</param> internal override void AddToManifest(Collection <VirtualResource> resources, SystemManifest manifest) { var resource = resources.First(); MachineReservationDetail detail = manifest.Resources.GetResource <MachineReservationDetail>(resource.VirtualResourceId); if (detail == null) { detail = CreateDetail(resource); manifest.Resources.Add(detail); } // Add installers to the manifest that are specific to this instance of the Machine Reservation MachineReservationMetadata metadata = LegacySerializer.DeserializeXml <MachineReservationMetadata>(resource.VirtualResourceMetadataSet.First().Metadata); if (metadata.PackageId != Guid.Empty) { using (EnterpriseTestContext context = new EnterpriseTestContext()) { int i = 1; foreach (var installer in SelectSoftwareInstallers(context, metadata.PackageId)) { TraceFactory.Logger.Debug("Adding {0}".FormatWith(installer.Description)); manifest.SoftwareInstallers.Add(CreateSoftwareInstallerDetail(installer, i++)); } } } }
public override void Validate(ParallelLoopState loopState, SystemManifest manifest, string machineName) { TraceFactory.Logger.Debug("Validating activities for {0} on Machine {1}".FormatWith(Id, machineName)); Parallel.ForEach <ResourceMetadata>(Metadata, (m, l) => m.Validate(l, Id, manifest, machineName)); if (SessionMapElement.AnyElementsSetTo <ResourceMetadata>(Metadata, RuntimeState.Error)) { var elements = SessionMapElement.GetElements <ResourceMetadata>(RuntimeState.Error, Metadata).Select(x => x.Detail.Name); TraceFactory.Logger.Debug("Metadata in ERROR: {0}".FormatWith(string.Join(", ", elements.ToArray()))); TraceFactory.Logger.Debug("Activity validation failed for {0}".FormatWith(Id)); MapElement.UpdateStatus("Activity validation failed", RuntimeState.Error); loopState.Break(); return; } else if (SessionMapElement.AnyElementsSetTo <ResourceMetadata>(Metadata, RuntimeState.Warning)) { var elements = SessionMapElement.GetElements <ResourceMetadata>(RuntimeState.Warning, Metadata).Select(x => x.Detail.Name); TraceFactory.Logger.Debug("Metadata in WARNING: {0}".FormatWith(string.Join(", ", elements.ToArray()))); TraceFactory.Logger.Debug("Activity validation caused a warning for {0}".FormatWith(Id)); MapElement.UpdateStatus("Activity validation caused a warning", RuntimeState.Warning); return; } MapElement.UpdateStatus("Validated", RuntimeState.Validated); }
public void AssignManifestInfo(SystemManifest manifest) { manifest.PluginDefinitions.Clear(); foreach (PluginDefinition definition in SettingsLoader.LoadPluginDefinitions()) { manifest.PluginDefinitions.Add(definition); } }
public void AssignManifestInfo(SystemManifest manifest) { manifest.ActivityRetrySettings.Clear(); foreach (var retrySetting in _activityRetrySettings) { manifest.ActivityRetrySettings.Add(retrySetting.Key, retrySetting.Value); } }
public void AssignManifestInfo(SystemManifest manifest) { manifest.ActivityPrintQueues.Clear(); foreach (var item in _printQueues) { manifest.ActivityPrintQueues.Add(item.Key, item.Value); } }
/// <summary> /// Initializes a new instance of the <see cref="MachineReservationHandler"/> class. /// </summary> /// <param name="manifest">The manifest.</param> public MachineReservationHandler(SystemManifest manifest) : base(manifest) { _reservation = GlobalDataStore.Manifest.Resources.OfType <MachineReservationDetail>().First(); VirtualResourceEventBus.OnStartMainRun += VirtualResourceEventBus_OnStartMainRun; VirtualResourceEventBus.OnShutdownResource += VirtualResourceEventBus_OnShutdownResource; VirtualResourceEventBus.OnPauseResource += VirtualResourceEventBus_OnPauseResource; VirtualResourceEventBus.OnResumeResource += VirtualResourceEventBus_OnResumeResource; }
/// <summary> /// Creates resource detail and inserts it into the manifest. /// </summary> /// <param name="resources">The resources.</param> /// <param name="manifest">The manifest.</param> internal override void AddToManifest(Collection <VirtualResource> resources, SystemManifest manifest) { foreach (VirtualResource resource in resources) { EventLogCollectorDetail detail = manifest.Resources.GetResource <EventLogCollectorDetail>(resource.VirtualResourceId); if (detail == null) { detail = CreateDetail(resource); manifest.Resources.Add(detail); } } }
/// <summary> /// Creates resource detail and inserts it into the manifest. /// </summary> /// <param name="resources">The resources.</param> /// <param name="manifest">The manifest.</param> internal override void AddToManifest(Collection <VirtualResource> resources, SystemManifest manifest) { // Iterate through each resource and create the manifest for the PerfMon Collector process. foreach (VirtualResource resource in resources) { PerfMonCollectorDetail detail = manifest.Resources.GetResource <PerfMonCollectorDetail>(resource.VirtualResourceId); if (detail == null) { detail = CreateDetail(resource); manifest.Resources.Add(detail); } } }
/// <summary> /// Initializes a new instance of the <see cref="MachineReservationHandler"/> class. /// </summary> /// <param name="manifest">The manifest.</param> public CitrixPublishedApplicationHandler(SystemManifest manifest) : base(manifest) { _worker = SystemManifest.Resources.OfType <CitrixWorkerDetail>().First(); _citrixServer = _worker.ServerHostname; _credential = SystemManifest.Resources.Credentials.First(); VirtualResourceEventBus.OnStartMainRun += VirtualResourceEventBus_OnStartMainRun; VirtualResourceEventBus.OnShutdownResource += VirtualResourceEventBus_OnShutdownResource; VirtualResourceEventBus.OnPauseResource += VirtualResourceEventBus_OnPauseResource; VirtualResourceEventBus.OnResumeResource += VirtualResourceEventBus_OnResumeResource; }
/// <summary> /// Initializes a new instance of the <see cref="LocalPrintQueueInstaller"/> class. /// </summary> /// <param name="manifest">The manifest.</param> public LocalPrintQueueInstaller(SystemManifest manifest) { // The manifest includes all queues required for the entire session. // Only install queues for activities that are part of this manifest. var activityIds = manifest.Resources.SelectMany(n => n.MetadataDetails).Select(n => n.Id); var printingActivityIds = activityIds.Where(n => manifest.ActivityPrintQueues.ContainsKey(n)); List <DynamicLocalPrintQueueInfo> printQueues = printingActivityIds.Select(n => manifest.ActivityPrintQueues[n]).SelectMany(n => n.OfType <DynamicLocalPrintQueueInfo>()).ToList(); foreach (DynamicLocalPrintQueueInfo printQueueInfo in printQueues) { _localPrintDeviceInstallers.Add(new LocalPrintDeviceInstaller(printQueueInfo)); } }
public void AssignManifestInfo(SystemManifest manifest) { manifest.Servers.Clear(); manifest.ActivityServers.Clear(); foreach (ServerInfo server in _servers) { manifest.Servers.Add(server); } foreach (var activityServer in _activityServers) { manifest.ActivityServers.Add(activityServer.Key, activityServer.Value); } }
public void AssignManifestInfo(SystemManifest manifest) { manifest.Documents.Clear(); manifest.ActivityDocuments.Clear(); foreach (Document document in _documents) { manifest.Documents.Add(document); } foreach (var activityDocument in _activityDocuments) { manifest.ActivityDocuments.Add(activityDocument.Key, activityDocument.Value); } }
/// <summary> /// Initializes a new instance of the <see cref="CitrixWorkerHandler" /> class. /// </summary> /// <param name="manifest">The manifest.</param> public CitrixWorkerHandler(SystemManifest manifest) : base(manifest) { if (manifest == null) { throw new ArgumentNullException("manifest"); } _userProfile = Environment.GetEnvironmentVariable("USERPROFILE"); _credential = SystemManifest.Resources.Credentials.First(); _credential.WorkingDirectory = Directory.GetCurrentDirectory(); _worker = SystemManifest.Resources.OfType <CitrixWorkerDetail>().First(); _citrixServer = _worker.ServerHostname; _randomizeStartupDelay = _worker.RandomizeStartupDelay; _minStartupDelay = TimeSpan.FromSeconds(_worker.MinStartupDelay); _maxStartupDelay = TimeSpan.FromSeconds(_worker.MaxStartupDelay); }
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()); }
/// <summary> /// Creates contract data for the specified scenario. /// </summary> /// <param name="scenario"></param> /// <returns></returns> public static EnterpriseScenarioContract Create(EnterpriseScenario scenario) { EnterpriseScenarioContract contract = new EnterpriseScenarioContract(scenario, "1.0"); Guid scenarioId = scenario.EnterpriseScenarioId; SystemManifest manifest = CreateReferenceManifest(scenarioId); AddTestDocumentInfoToContract(scenario.EnterpriseScenarioId, contract, manifest); AddAssetInfoToContract(scenario.EnterpriseScenarioId, contract, manifest); AddActivityUsageDataToContract(contract, scenarioId); AddFolderDataToContract(contract, scenario); foreach (var resource in scenario.VirtualResources) { var resourceDetail = VirtualResourceDetailBuilder.CreateBaseDetail(resource); contract.ResourceDetails.Add(resourceDetail); UpdateStatus("Exporting {0}".FormatWith(resourceDetail.Name)); } return(contract); }
private static SystemManifest CreateReferenceManifest(Guid scenarioId) { var manifest = new SystemManifest(); manifest.PullFromGlobalSettings(); var _agents = new List <IManifestComponentAgent>() { new ManifestAssetAgent(scenarioId), new ManifestDocumentAgent(scenarioId), new ManifestServerAgent(scenarioId), new ManifestPrintQueueAgent(scenarioId), new ManifestSettingsAgent() }; // Have all agents populate their respective portions of the manifest foreach (IManifestComponentAgent agent in _agents) { agent.AssignManifestInfo(manifest); } return(manifest); }
/// <summary> /// Initializes a new instance of the <see cref="VirtualResourceHandler" /> class. /// </summary> /// <param name="manifest">The manifest.</param> /// <exception cref="System.ArgumentNullException">manifest</exception> protected VirtualResourceHandler(SystemManifest manifest) { if (manifest == null) { throw new ArgumentNullException("manifest"); } SystemManifest = manifest; if (_clientService == null) { try { _clientService = ClientControllerServiceConnection.CreateServiceHost(this); _clientService.Open(); TraceFactory.Logger.Debug("Started Service Host: {0}".FormatWith(_clientService.BaseAddresses[0].AbsoluteUri)); } catch (Exception) { } } }
/// <summary> /// Initializes a new instance of the <see cref="ResourceHost" /> class. /// </summary> /// <param name="manifest">The manifest.</param> public ResourceHost(SystemManifest manifest) { Manifest = manifest; // Set the logging thread context if (manifest != null) { TraceFactory.SetThreadContextProperty("SessionId", manifest.SessionId, false); TraceFactory.SetThreadContextProperty("Dispatcher", manifest.Dispatcher, false); } Resources = new Collection <ResourceInstance>(); // Define an empty machine class as simply a placeholder. It will be replaced with an // actual machine class in the validate step. Machine = new HostMachine(manifest); Machine.OnStatusChanged += Machine_OnStatusChanged; // Create a temporary Id for the map element as it won't be set until the machines are created MapElement = new SessionMapElement(Guid.NewGuid().ToString(), ElementType.Machine); MapElement.Enabled = false; }
protected OfficeWorkerDetail GetFilteredWorkerDetail(ResourceExecutionPhase phase) { TraceFactory.Logger.Debug("Phase: {0}".FormatWith(phase)); // Create a copy of the manifest and trim out activities that are not part of this phase var manifest = SystemManifest.Deserialize(GlobalDataStore.Manifest.Serialize()); var workerDetail = manifest.Resources.GetWorker <OfficeWorkerDetail>(GlobalDataStore.ResourceInstanceId); int count = workerDetail.MetadataDetails.Count(); TraceFactory.Logger.Debug("Initial activity count {0}".FormatWith(count)); var toRemove = workerDetail.MetadataDetails.Where(n => n.Plan.Phase != phase).ToList(); foreach (var detail in toRemove) { workerDetail.MetadataDetails.Remove(detail); } count = workerDetail.MetadataDetails.Count(); TraceFactory.Logger.Debug("Final activity count {0}".FormatWith(count)); return(workerDetail); }
/// <summary> /// Initializes a new instance of the <see cref="WindowsMachineVirtual" /> class. /// </summary> public WindowsMachineVirtual(ManagedMachine machine, SystemManifest manifest) : base(manifest) { _machine = machine; }
/// <summary> /// Initializes a new instance of the <see cref="HostMachine"/> class. /// </summary> public HostMachine(SystemManifest manifest) { Manifest = manifest; Configured = false; }
internal override void AddToManifest(Collection <VirtualResource> resources, SystemManifest manifest) { LoadResources <SolutionTesterDetail>(resources, manifest); }
private static void AddAssetInfoToContract(Guid scenarioId, EnterpriseScenarioContract contract, SystemManifest manifest) { contract.AllAssets.Clear(); foreach (var asset in manifest.AllAssets) { contract.AllAssets.Add(asset); UpdateStatus("Exporting {0}".FormatWith(asset.AssetId)); } }
private static void AddTestDocumentInfoToContract(Guid scenarioId, EnterpriseScenarioContract contract, SystemManifest manifest) { // Add any test documents referenced in the resource metadata to a collection that will // be resolved against the target system during import. contract.TestDocuments.Clear(); foreach (Document doc in manifest.Documents) { string relativeFilePath = doc.Group + @"\" + doc.FileName; contract.TestDocuments.Add(new TestDocumentContract(relativeFilePath)); UpdateStatus("Exporting {0}".FormatWith(relativeFilePath)); } }
private void LoadSystemSettings(string manifestFilePath) { SystemManifest systemManifest = LegacySerializer.DeserializeDataContract <SystemManifest>(GetFileContents(manifestFilePath)); GlobalDataStore.Load(systemManifest); }