internal bool AddCommand(MOG_Command pCommand) { bool bSuccess = false; // Check if this is the StartJob command? if (pCommand.GetCommandType() == MOG.COMMAND.MOG_COMMAND_TYPE.MOG_COMMAND_StartJob) { mStartJobCommand = pCommand; bSuccess = true; } else { // Check if this command has requested to have duplicate commands removed? if (pCommand.IsRemoveDuplicateCommands()) { // Scan the Server's command queue looking for any other instance of this same command? if (RemoveDuplicateCommands(pCommand)) { } } // Check if this is a completed command? if (pCommand.GetCommandType() == MOG.COMMAND.MOG_COMMAND_TYPE.MOG_COMMAND_Complete) { // Immediately process 'Complete' commands if (ProcessCommand(pCommand)) { // Remove the original command that is encapsulated within this 'Complete' command RemoveCommand(pCommand.GetCommand()); bSuccess = true; } } else { // Get the appropriate command list for this command HybridDictionary commandList = GetJobCommandList(pCommand); if (commandList != null) { // Make sure we always clear the command's assigned slave or else it will never get processed pCommand.SetAssignedSlaveID(0); // Add this command to the appropriate list for later processing commandList[pCommand.GetCommandID().ToString()] = pCommand; bSuccess = true; } } } return(bSuccess); }
internal bool ReleaseSlave(MOG_Command pCommand) { // Scan mActiveSlaves looking for one that matches this command // This way is safer just in case NetworkIDs get reset from a reconnect event for (int s = 0; s < mActiveSlaves.Count; s++) { MOG_Command pSlave = (MOG_Command)mActiveSlaves[s]; // Check if this slave is working on something? if (pSlave.GetCommand() != null) { // Check if the CommandID matches? if (pSlave.GetCommand().GetCommandID() == pCommand.GetCommandID()) { // Clear this slave's command pSlave.SetCommand(null); // Refresh the command's SetAssignedSlaveID pCommand.SetAssignedSlaveID(pSlave.GetNetworkID()); // 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); // Insert the slave at the top of mAvailableSlaves so it will be immeadiately reused mAvailableSlaves.Insert(0, pSlave); // Erase the slave from mActiveSlaves mActiveSlaves.RemoveAt(s); // Return the command that the slave was processing for reference return(true); } } } string message = String.Concat("Server could not release slave because it failed to locate the slave in mActiveSlaves\n", "Command:", pCommand.ToString(), " NetworkID:", pCommand.GetNetworkID(), " Asset:", pCommand.GetAssetFilename().GetOriginalFilename()); MOG_Report.ReportMessage("Server", message, Environment.StackTrace, MOG_ALERT_LEVEL.ERROR); return(false); }
internal bool RecoverCommand(MOG_Command pCommand) { bool bRecovered = false; // Get the appropriate command list for this command HybridDictionary commandList = GetJobCommandList(pCommand); if (commandList != null) { if (commandList.Contains(pCommand.GetCommandID().ToString())) { // Clear the assigned slave pCommand.SetAssignedSlaveID(0); commandList[pCommand.GetCommandID().ToString()] = pCommand; bRecovered = true; } } return(bRecovered); }
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); }