示例#1
0
 internal VMInstance(VMInstanceData data, TestServer testServer, NetworkCredential networkCredentials)
 {
     mData = data;
     mNetworkCredentials = networkCredentials;
     StartLog();
     StartHeartbeatTimer();
 }
示例#2
0
        private bool Initialize(string snapshot)
        {
            bool result = true;

            if (mTesting == false)
            {
                mBusy = true;

                // Refresh data in case the VM name has changed.....
                mData = VMInstanceData.SelectByIP(mData.IPAddress);

                // Stop the heartbeat timer because rolling it back might cause it to actually miss a heartbeat.
                StopHeartbeatTimer();
                PowerCLI powerCLI = PowerCLI.Instance(mNetworkCredentials);
                result = powerCLI.RollbackVM(mData.VMName, snapshot, mLogFile);
                if (result == false)
                {
                    DatabaseLog.Insert("Rollback failed on VM " + mData.VMName, "There might be an issue with PowerCLI. Please check the logs.", 1);
                }
                StartHeartbeatTimer();
                mBusy = false;
            }

            return(result);
        }
示例#3
0
        private void InactivityTimeout(object state)
        {
            // Error situation
            Log("Error: inactivity timer expired. Reseting VM.", true);

            mData = VMInstanceData.SelectByIP(mData.IPAddress);
            Log("Fetched updated information for VM. VMState: " + mData.State);
            if (mData.State == 1)
            {
                CleanupVM();
            }
        }
示例#4
0
        internal StartClientResponse HandleStartMessage()
        {
            Log("Start message received.");

            // Get latest state
            mData = VMInstanceData.SelectByIP(mData.IPAddress);

            // Reset local flags that represent the state of the VM
            mBusy = false;

            StartClientResponse response = new StartClientResponse()
            {
                Enabled = (mData.State == 1),
                OSType  = mData.OperatingSystemID
            };

            Log("Start response: Enabled=" + response.Enabled + "; OS=" + response.OSType);
            return(response);
        }
示例#5
0
        private static VMInstanceData FromData(IDataReader reader)
        {
            VMInstanceData instance = new VMInstanceData();

            instance.VMInstanceID      = reader.GetInt32(0);
            instance.VMName            = reader.GetString(1);
            instance.HostName          = reader.GetString(2);
            instance.IPAddress         = reader.GetString(3);
            instance.VMConfigurationID = reader.GetInt32(4);
            instance.State             = reader.GetInt32(5);
            // 6: CreateDate
            instance.AlwaysOn          = reader.GetBoolean(7);
            instance.ConfigurationName = reader.GetString(8);
            // 9: TestSuiteID
            // 10: testJobID
            instance.Location          = reader.GetString(14);
            instance.OperatingSystemID = (reader.GetInt32(17) == 1 ? OperatingSystemType.Windows : OperatingSystemType.Mac);
            return(instance);
        }
示例#6
0
        private void HeartbeatTimerTimeout(object state)
        {
            lock (this)
            {
                mHeartbeatsMissed++;
            }

            if (mHeartbeatsMissed > mMaxHeartBeatMissed)
            {
                mHeartbeatsMissed = 0;

                Log(mMaxHeartBeatMissed + " or more heartbeats missed for VM " + mData.VMName, true);
                TestJobData.Cancel(mData.VMInstanceID, "VM missed " + mMaxHeartBeatMissed + " heart beats.");

                try
                {
                    // Refresh data to see if the VM is Disabled
                    mData = VMInstanceData.SelectByIP(mData.IPAddress);
                    Log("Fetched updated information. VMState: " + mData.State);
                }
                catch (Exception ex)
                {
                    Log("ERROR: " + ex.ToString(), true);
                }

                if (mData.State == 1)
                {
                    mBusy = true;
                    //CreateSnapshot("HBFailure_" + DateTime.Now.ToString("yyyy-dd-MM-HH-mm-ss"));
                    mBusy = false;

                    CleanupVM();
                }
            }
            else if (mHeartbeatsMissed > 1)
            {
                Log("Heartbeats missed: " + mHeartbeatsMissed, true);
            }
        }
示例#7
0
        private bool RebootVM()
        {
            bool result = true;

            if (mTesting == false)
            {
                // Refresh data in case the VM name has changed.....
                mData = VMInstanceData.SelectByIP(mData.IPAddress);

                Log("Rebooting VM " + mData.VMName);
                StopHeartbeatTimer();
                PowerCLI powerCLI = PowerCLI.Instance(mNetworkCredentials);
                result = powerCLI.Reboot(mData.VMName, mLogFile);
                if (result == false)
                {
                    DatabaseLog.Insert("Rebooting failed for VM " + mData.VMName, "There might be an issue with PowerCLI. Please check the logs.", 1);
                }
                StartHeartbeatTimer();
            }

            return(result);
        }
示例#8
0
        public static VMInstanceData SelectByIP(string ipAddress)
        {
            string         connectionString = ConfigurationManager.ConnectionStrings["SQLConnectionString"].ConnectionString;
            VMInstanceData result           = null;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand("[Definition].[VMInstance_SelectByIP]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@pIPAddress", ipAddress);

                    var reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                        result = FromData(reader);
                    }
                    reader.Close();
                }
            }

            return(result);
        }