public void Reserve(UserCredential credential, RequestedVMDictionary requestedVMs, VMQuantityDictionary requiredVMQuantity)
        {
            var virtualMachines = VMInventoryManager.RequestVMs(_sessionId, credential, requestedVMs, requiredVMQuantity);

            try
            {
                foreach (VirtualMachine machine in virtualMachines)
                {
                    TraceFactory.Logger.Debug("{0} : {1}".FormatWith(machine.Name, machine.MachineType));

                    var machineType     = EnumUtil.GetByDescription <ManagedMachineType>(machine.MachineType);
                    var machineInstance = new ManagedMachine(machine.Name, machineType);
                    GetMachineQueueForPlatform(machine.PlatformUsage).Enqueue(machineInstance);
                }
            }
            catch (Exception ex)
            {
                TraceFactory.Logger.Error(ex);

                // Something bad happened.  Release everything.
                foreach (var machine in virtualMachines)
                {
                    using (var machineInstance = new ManagedMachine(machine.Name, EnumUtil.GetByDescription <ManagedMachineType>(machine.MachineType)))
                    {
                        machineInstance.ReleaseReservation();
                    }
                }

                Dispose();
                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));
        }
        public override void Replace()
        {
            TraceFactory.Logger.Info("Replacing {0}.".FormatWith(_machine.Name));
            var replacement = VMInventoryManager.GetReplacement(_machine.Name);

            VMInventoryManager.SetInUseClearSession(_machine.Name);
            _machine = new ManagedMachine(replacement.Name, ManagedMachineType.WindowsVirtual);
            TraceFactory.Logger.Info("New replacement machine {0} selected.".FormatWith(_machine.Name));
        }
Example #4
0
        private void _addTarget()
        {
            if (!_targets.Any(t => t.MachineName == _selectedMachineName))
            {
                var machine = _machine.Graph.Buzz.Song.Machines.SingleOrDefault(m => m.Name == _selectedMachineName);
                if (machine != null)
                {
                    var targetModel = new Target(machine);
                    ManagedMachine.AddTarget(targetModel);


                    var targetView = new TargetVm(targetModel);
                    targetView.PropertyChanged += Target_PropertyChanged;
                    _targets.Add(targetView);

                    PropertyChanged.Raise(this, "Targets");
                }
            }
        }
 private void CleanupAssetHostsHandler(DeviceSimulator simulatorMachine)
 {
     using (var machine = new ManagedMachine(simulatorMachine.VirtualMachine, ManagedMachineType.WindowsVirtual))
     {
         try
         {
             MachineStop.Run(machine.Name, () =>
             {
                 if (machine.IsPoweredOn())
                 {
                     machine.Shutdown(wait: true);
                 }
             });
         }
         catch (Exception ex)
         {
             TraceFactory.Logger.Error(ex.Message);
         }
     }
 }
        private void CleanupResourceHostsHandler(VirtualMachine machine)
        {
            using (var managedMachine = new ManagedMachine(machine.Name, EnumUtil.GetByDescription <ManagedMachineType>(machine.MachineType)))
            {
                TraceFactory.Logger.Debug("Resetting resource host {0}".FormatWith(managedMachine));

                try
                {
                    MachineStop.Run(managedMachine.Name, () =>
                    {
                        managedMachine.Revert(wait: true);
                        managedMachine.ReleaseReservation();
                    });
                }
                catch (Exception ex)
                {
                    TraceFactory.Logger.Error(ex);
                }
            }
        }
 /// <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="WindowsMachineDesktop" /> class.
 /// </summary>
 /// <param name="manifest">The system manifest used for this host.</param>
 public WindowsMachineDesktop(ManagedMachine machine, SystemManifest manifest)
     : base(manifest)
 {
 }
Example #9
0
 private bool _canAddTarget()
 {
     return(!string.IsNullOrEmpty(_selectedMachineName) && !ManagedMachine.HasTarget(_selectedMachineName));
 }
Example #10
0
 private void RemoveTarget(string machineName)
 {
     ManagedMachine.RemoveTarget(machineName);
     _targets = _targets.Where(t => t.MachineName != machineName).ToList();
     PropertyChanged.Raise(this, "Targets");
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JediSimulatorHost"/> class.
 /// </summary>
 /// <param name="asset">The asset details from the manifest.</param>
 public JediSimulatorHost(AssetDetail asset)
     : base(asset, ((JediSimulatorDetail)asset).MachineName, ElementType.Device, "JediSimulator")
 {
     _simulatorDetail = (JediSimulatorDetail)asset;
     _machine         = new ManagedMachine(_simulatorDetail.MachineName, ManagedMachineType.WindowsVirtual);
 }