Esempio n. 1
0
        /// <summary>
        /// Shuts down this asset
        /// </summary>
        public override void Shutdown(ShutdownOptions options, ParallelLoopState loopState)
        {
            // If the shutdown option is set to not shutdown the simulator, then
            // set the state to offline and return.
            if (!options.ShutdownDeviceSimulators)
            {
                MapElement.UpdateStatus("Offline", RuntimeState.Offline);
                return;
            }

            _inShutdown = true;

            TraceFactory.Logger.Debug("Shutting down {0}".FormatWith(_machine.Name));
            MapElement.UpdateStatus("Shutdown", RuntimeState.ShuttingDown);

            // Cancel the deployment if it's starting up.
            CancelBootup();

            if (_machine.IsPoweredOn())
            {
                try
                {
                    JediSimulatorManager.ShutdownSimulator(((JediSimulatorDetail)Asset).MachineName);
                }
                catch (Exception ex)
                {
                    TraceFactory.Logger.Debug("Simulator shutdown failed.  Continuing with machine shutdown. {0}".FormatWith(ex.Message));
                }

                _machine.Shutdown();
            }

            MapElement.UpdateStatus("Offline", RuntimeState.Offline);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes this asset
        /// </summary>
        public override void Validate(ParallelLoopState loopState)
        {
            TraceFactory.Logger.Debug("Validating {0}".FormatWith(_machine.Name));
            try
            {
                _inShutdown = false;

                MapElement.UpdateStatus("Validating", RuntimeState.Validating);

                if (_machine.IsPoweredOn())
                {
                    TraceFactory.Logger.Debug("{0} is already powered on...".FormatWith(_machine.Name));

                    if (JediSimulatorManager.IsSimulatorReady(_machine.Name))
                    {
                        MapElement.UpdateStatus("Simulator is already powered on and ready", RuntimeState.Validated);
                    }
                    else
                    {
                        MapElement.UpdateStatus("Simulator is in an unknown state and will be restarted", RuntimeState.Warning);
                    }
                }
                else
                {
                    MapElement.UpdateStatus("Simulator is powered off and will be started", RuntimeState.Validated);
                }
            }
            catch (Exception ex)
            {
                MapElement.UpdateStatus(RuntimeState.Error, "Validation failure: {0}".FormatWith(ex.Message), ex);
            }
        }
        private void Launch(SimReserved simulator)
        {
            Thread.CurrentThread.SetName(simulator.AssetId);

            PowerOn(simulator);

            if (!JediSimulatorManager.IsSimulatorReady(simulator.HostAddress))
            {
                UpdateItemStatus(simulator, "Launching Simulator...");
                JediSimulatorManager.LaunchSimulator(simulator.VirtualMachine, simulator.Product, simulator.HostAddress);
                UpdateItemStatus(simulator, "Launch complete.");
            }
            else
            {
                UpdateItemStatus(simulator, "Simulator is already running.");
            }
        }
        private void PowerOff(SimReserved simulator)
        {
            Thread.CurrentThread.SetName(simulator.AssetId);

            UpdateItemStatus(simulator, "Checking power status...");
            if (VMController.IsPoweredOn(simulator.VirtualMachine))
            {
                if (JediSimulatorManager.IsSimulatorReady(simulator.HostAddress))
                {
                    UpdateItemStatus(simulator, "Shutting down simulator...");
                    JediSimulatorManager.ShutdownSimulator(simulator.VirtualMachine);
                    UpdateItemStatus(simulator, "Simulator Shutdown complete.");
                }

                UpdateItemStatus(simulator, "Powering Off VM...");
                VMController.Shutdown(simulator.VirtualMachine);
                UpdateItemStatus(simulator, "Power Off complete.");
            }
            else
            {
                UpdateItemStatus(simulator, "Already powered off.");
            }
        }
Esempio n. 5
0
        private void StartSimulatorHandler()
        {
            bool alreadyRetried = false;

            TraceFactory.Logger.Debug("Starting simulator {0}".FormatWith(_machine.Name));
            while (true)
            {
                try
                {
                    if (_machine.IsPoweredOn())
                    {
                        // The machine is already powered on, see if the simulator is responsive
                        // and handle accordingly.
                        TraceFactory.Logger.Debug("{0} is already powered on...".FormatWith(_machine.Name));

                        if (JediSimulatorManager.IsSimulatorReady(_machine.Name))
                        {
                            // The simulator is on and ready to go, just return
                            return;
                        }
                        else
                        {
                            // Since the machine is running, but the simulator doesn't respond
                            // attempt to stop the simulator
                            try
                            {
                                // Attempt to shutdown the simulator.  If this fails then log it and continue
                                TraceFactory.Logger.Debug("Attempting to shutdown the simulator");
                                JediSimulatorManager.ShutdownSimulator(_machine.Name);
                            }
                            catch (Exception ex)
                            {
                                TraceFactory.Logger.Debug("Simulator shutdown failed, error: {0}".FormatWith(ex.Message));
                            }
                        }
                    }
                    else
                    {
                        // The machine isn't on, so boot it and then try to start the simulator.
                        try
                        {
                            MachineStart.Run(_machine.Name, () =>
                            {
                                TraceFactory.Logger.Debug("Booting {0}".FormatWith(_machine.Name));
                                MapElement.UpdateStatus("Booting");

                                // Don't track "In Use" for simulator VMs, they are already handled through
                                // asset reservation.
                                _machine.PowerOn(setInUse: false);
                            });
                        }
                        catch (Exception ex)
                        {
                            TraceFactory.Logger.Error("Error booting virtual machine", ex);
                            MapElement.UpdateStatus("Error booting VM", RuntimeState.Error);
                            return;
                        }

                        MapElement.UpdateStatus("ReadyWait");
                        if (!VMController.WaitOnMachineAvailable(_machine.Name, _cancel.Token))
                        {
                            TraceFactory.Logger.Debug("Cancellation request received, returning...");
                            throw new OperationCanceledException("Cancellation received");
                        }
                    }

                    // Now the machine should be booted and ready to start the simulator.
                    MapElement.UpdateStatus("Starting");
                    JediSimulatorManager.LaunchSimulator(_machine.Name, ((JediSimulatorDetail)Asset).Product, _machine.Name, _cancel.Token);
                    return;
                }
                catch (Exception ex)
                {
                    // If an exception is hit trying to start on the first attempt, then try one
                    // more time after first shutting down the machine.
                    TraceFactory.Logger.Debug("Error starting simulator on {0}".FormatWith(_machine.Name));
                    if (alreadyRetried)
                    {
                        MapElement.UpdateStatus("Unable to start this simulator: {0}".FormatWith(ex.Message), RuntimeState.Error);
                        throw new OperationCanceledException("Cancellation received");
                    }
                    else
                    {
                        // Unable to start the simulator, so perform a hard restart and try one more time.
                        _machine.Shutdown();
                        alreadyRetried = true;
                    }
                }
            }
        }