public void LoadCommand(MOG_Command command) { tbComputer.Text = command.GetComputerName(); tbDate.Text = MogUtils_StringVersion.VersionToString(command.GetCommandTimeStamp()); tbIp.Text = command.GetComputerIP(); tbID.Text = command.GetCommandID().ToString(); tbProject.Text = command.GetProject(); tbType.Text = command.GetCommandType().ToString(); tbUser.Text = command.GetUserName(); tbBranch.Text = command.GetBranch(); tbJobId.Text = command.GetJobLabel(); tbBlocking.Text = command.IsBlocking().ToString(); tbSlaveID.Text = command.mAssignedSlaveID.ToString(); tbCompleted.Text = command.IsCompleted().ToString(); tbValidSlaves.Text = command.GetValidSlaves(); if (command.GetAssetFilename() != null) { tbAssetName.Text = command.GetAssetFilename().GetAssetFullName(); } }
bool IsDuplicateCommand(MOG_Command pCommand1, MOG_Command pCommand2) { // Check if the CommandType matches? // Check if the AssetFilename matches? // Check if the Platforms matches? // Check if the Branch matches? // Check if the JobLabel matches? // Check if the ValidSlaves matches? if (pCommand1.GetCommandType() == pCommand2.GetCommandType() && String.Compare(pCommand1.GetAssetFilename().GetOriginalFilename(), pCommand2.GetAssetFilename().GetOriginalFilename(), true) == 0 && String.Compare(pCommand1.GetPlatform(), pCommand2.GetPlatform(), true) == 0 && String.Compare(pCommand1.GetBranch(), pCommand2.GetBranch(), true) == 0 && String.Compare(pCommand1.GetJobLabel(), pCommand2.GetJobLabel(), true) == 0 && String.Compare(pCommand1.GetValidSlaves(), pCommand2.GetValidSlaves(), true) == 0) { return(true); } return(false); }
internal bool AssignToSlave(MOG_Command pCommand) { MOG_Command pSlave = null; // Always make sure that the AssignedSlaveID is cleared just in case we fail pCommand.SetAssignedSlaveID(0); // Check if this is an exclusive command? if (pCommand.IsExclusiveCommand()) { // Check if this exclusive command is already actively getting processed? if (CheckExclusiveCommands(pCommand)) { // Don't assign this exclusive command because there is already another one being processed return(false); } } // Identify a valid slave based on the mValidSlaves? if (pCommand.GetValidSlaves().Length > 0) { // Look for a valid slave by scanning mAvailableSlaves for (int s = 0; s < mAvailableSlaves.Count; s++) { // Is this slave's name specified in mValidSlaves? pSlave = (MOG_Command)mAvailableSlaves[s]; if (pSlave != null) { if (IsSlaveListed(pSlave.GetComputerName(), pCommand.GetValidSlaves())) { break; } } // Indicate that this slave wasn't listed in mValidSlaves pSlave = null; } // No available valid slave found? if (pSlave == null) { // Request a new slave respecting this command's valid slaves RequestNewSlave(pCommand); // Bail out since we need to wait for a slave to become available return(false); } } else { // Check if we have run out of available slaves? if (mAvailableSlaves.Count == 0) { // Request a new slave? RequestNewSlave(pCommand); // Bail out here because there were no slaves and it can take some time before any requested slaves will be launched return(false); } // Since mValidSlaves was blank, get the first slave in the list pSlave = (MOG_Command)mAvailableSlaves[0]; } // Did we actually locate a valid available slave? if (pSlave != null) { // Send the command to the available slave if (mServerCommandManager.SendToConnection(pSlave.GetNetworkID(), pCommand)) { // Assign the Slave's NetworkID within the command so we will know who is working on this command pCommand.SetAssignedSlaveID(pSlave.GetNetworkID()); // Stick this command into the RegisteredSlave's command pSlave.SetCommand(pCommand); // Add the slave to mActiveSlaves mActiveSlaves.Add(pSlave); // Remove the top slave from mAvailableSlaves mAvailableSlaves.Remove(pSlave); // Send out needed Notify command MOG_Command pNotify = MOG_CommandFactory.Setup_NotifyActiveConnection(pSlave); mServerCommandManager.SendToActiveTab("Connections", pNotify); pNotify = MOG_CommandFactory.Setup_NotifyActiveCommand(pCommand); mServerCommandManager.SendToActiveTab("Connections", pNotify); return(true); } } return(false); }
bool RequestNewSlave(MOG_Command pCommand) { MOG_Command pClient = null; bool bAutoLaunchedSlave = false; bool bThisSpecificSlaveBeingRequested = false; // Check if we should wait a bit longer before we request a slave? if (DateTime.Now < mNextSlaveRequstTime) { // Ignore this request return(false); } // Check for a 'SlaveMachine' section in the System's config file? MOG_Ini pConfigFile = MOG_ControllerSystem.GetSystem().GetConfigFile(); string[] validSlaveMachines = null; if (pConfigFile.SectionExist("SlaveMachines")) { validSlaveMachines = pConfigFile.GetSectionKeys("SlaveMachines"); } // Check if we obtained a list of validSlaveMachines? if (validSlaveMachines != null && validSlaveMachines.Length > 0) { // Scan all the slaves specifically listed in our config file first // Walk list of specified SlaveMachines? foreach (string machineName in validSlaveMachines) { // Get the SlaveMachine info string machinePriority = pConfigFile.GetString("SlaveMachines", machineName); bThisSpecificSlaveBeingRequested = false; // Check if we have already requested this slave? if (IsAlreadyRequestedSlave(machineName)) { // We can skip this machine because we have already issued a request for a slave continue; } // Check if we had a specific list of validSlaves specified? if (pCommand.GetValidSlaves().Length != 0) { // Check if this machineName isn't listed in the command's validSlaves? if (IsSlaveListed(machineName, pCommand.GetValidSlaves())) { bThisSpecificSlaveBeingRequested = true; } else { // We can skip this machine because it isn't listed as a validSlave continue; } } // Check if there is already a slave running on this machine? if (mServerCommandManager.LocateRegisteredSlaveByComputerName(machineName) != null) { continue; } // Make sure there is a client running on this machine? pClient = mServerCommandManager.LocateClientByComputerName(machineName); if (pClient != null) { // Check if this Slave should be considered an AutoLaunchedSlave? if (String.Compare(machinePriority, "Always", true) != 0 && String.Compare(machinePriority, "Yes", true) != 0 && String.Compare(machinePriority, "True", true) != 0) { // Indicate this slave should be terminated when it is no longer needed bAutoLaunchedSlave = true; } break; } } } // Check if we are still missing a client to launch a slave on? if (pClient == null) { // Scan all the registered clients looking for one that we can send this request to? ArrayList registeredClients = this.mServerCommandManager.GetRegisteredClients(); for (int c = 0; c < registeredClients.Count; c++) { MOG_Command pRegisteredClient = (MOG_Command)registeredClients[c]; string machineName = pRegisteredClient.GetComputerName(); bThisSpecificSlaveBeingRequested = false; // Check if we have already requested this slave? if (IsAlreadyRequestedSlave(machineName)) { // We can skip this machine because we have already issued a request for a slave continue; } // Check if there is already a slave running on this machine? if (mServerCommandManager.LocateRegisteredSlaveByComputerName(machineName) != null) { continue; } // Check if we had a specific list of validSlaves specified? if (pCommand.GetValidSlaves().Length != 0) { // Check if this machineName isn't listed in the specified validSlaves? if (IsSlaveListed(machineName, pCommand.GetValidSlaves())) { bThisSpecificSlaveBeingRequested = true; } else { // We can skip this machine because it isn't listed as a validSlave continue; } } else { // Check if there was a list of validSlaveMachines specified? if (validSlaveMachines != null) { // Check if this computer was listed? if (pConfigFile.KeyExist("SlaveMachines", machineName)) { // Make sure this isn't listed as an exclusion? string machinePriority = pConfigFile.GetString("SlaveMachines", machineName); if (String.Compare(machinePriority, "Never", true) != 0 || String.Compare(machinePriority, "No", true) != 0 || String.Compare(machinePriority, "Exempt", true) != 0 || String.Compare(machinePriority, "Ignore", true) != 0 || String.Compare(machinePriority, "Skip", true) != 0) { continue; } } } } // Looks like we can use this client pClient = pRegisteredClient; // Indicate this slave should be terminated when it is no longer needed bAutoLaunchedSlave = true; break; } } // Check if this is just a generic slave request? if (!bThisSpecificSlaveBeingRequested) { // Check if we have a maximum number of slaves to auto launch? and // Check if we are over our maximum number of slaves? if (mManagedSlavesMax != 0 && mManagedSlavesMax < mAutoLaunchedSlaveNames.Count) { // No need to launch this slave because we have exceeded our max return(false); } } // Check if we found a client that we can request a new slave from? if (pClient != null) { // Instruct this client to launch a slave MOG_ControllerSystem.LaunchSlave(pClient.GetNetworkID()); // Track when this last request was made mNextSlaveRequstTime = DateTime.Now.AddSeconds(5); // Add this slave to our list of requested slave names AddRequestedSlave(pClient.GetComputerName()); // Check if we should add this slave as an AutoLaunchedSlave? if (bAutoLaunchedSlave) { AddAutoLaunchedSlaveName(pClient.GetComputerName()); } // Indicate we launched a new slave return(true); } // Check if it is time to report a missing slave error? if (DateTime.Now > mNextNoSlaveReportTime) { // Check if there was a specific validslaves listed? if (pCommand.GetValidSlaves().Length > 0) { bool bWarnUser = true; // Split up the specified ValidSlaves String delimStr = ",;"; Char[] delimiter = delimStr.ToCharArray(); String[] SlaveNames = pCommand.GetValidSlaves().Trim().Split(delimiter); // Check the registered slaves to see if a valid slave is running for (int n = 0; n < SlaveNames.Length; n++) { // Check if we found our matching slave name? if (mServerCommandManager.LocateRegisteredSlaveByComputerName(SlaveNames[n]) != null) { // We found a match...this command will eventually get processed bWarnUser = false; break; } } // Check if we decided to warn the user? if (bWarnUser) { // Setup the Broadcast message indicating that there are no valid slaves running string message = String.Concat("MOG Server is trying to process a command containing a 'ValidSlaves' property and has been unable to launch the needed Slave.\n", "VALIDSLAVES=", pCommand.GetValidSlaves(), "\n\n", "Please check this machine to ensure it is connected to the MOG Server."); MOG_ControllerSystem.NetworkBroadcast(pCommand.GetUserName(), message); // Record the time when this report was sent mNextNoSlaveReportTime = DateTime.Now.AddMinutes(5); } } } // Indicate that we failed to find a qualified slave return(false); }