Esempio n. 1
0
        /// <summary>
        /// Builds all components in this map.
        /// </summary>
        public override void Stage(ParallelLoopState loopState)
        {
            Thread.CurrentThread.SetName("Stage-{0}".FormatWith(Thread.CurrentThread.ManagedThreadId));

            TraceFactory.Logger.Debug("Entering...");

            // Use the index to create an initial unique hostname that will be
            // replaced during the validation stage with an actual hostname.
            foreach (var manifest in Configuration.ManifestSet)
            {
                ResourceHost host = new ResourceHost(manifest);
                host.OnResourcesComplete += new EventHandler(ResourceHostsCompleted);
                Hosts.Add(host);
            }

            try
            {
                Parallel.ForEach <ResourceHost>(Hosts, (h, l) => h.Stage(l));
                if (!SessionMapElement.AllElementsSetTo <ResourceHost>(Hosts, RuntimeState.Available))
                {
                    loopState.Break();
                    return;
                }
            }
            catch (AggregateException ex)
            {
                // Log the exception at this element level, then throw again to catch it higher
                MapElement.UpdateStatus(RuntimeState.Error, "Staging error", ex);
                throw;
            }
        }
        public void AssignMachine(ResourceHost host)
        {
            ManagedMachine machine = null;

            if (GlobalSettings.IsDistributedSystem)
            {
                machine = _reservationManager.GetNext(host.Manifest.Platform);
            }
            else
            {
                if (_localMachineCount == 1)
                {
                    _localMachineCount--;
                    machine = new ManagedMachine(Environment.MachineName, ManagedMachineType.WindowsDesktop);
                }
                else
                {
                    // The only way to get here is if the maximum worker count has been exceeded for the entire scenario,
                    // which would cause more than one machine to get assigned.
                    throw new InvalidOperationException("The maximum solution tester count has been exceeded.");
                }
            }

            host.Machine              = ObjectFactory.Create <HostMachine>(machine.MachineType, machine, host.Manifest);
            host.MapElement.Name      = machine.Name;
            host.Manifest.HostMachine = machine.Name;
            host.MapElement.Enabled   = true;
            host.Machine.Configured   = true;
            TraceFactory.Logger.Debug("{0} : {1}".FormatWith(machine.Name, machine.MachineType));
        }