示例#1
0
文件: Jobs.cs 项目: xiangyuan/Unreal4
		public Int32 BeginJobSpecification( AgentJobSpecification NewJobSpecification32, Hashtable NewJobDescription32, AgentJobSpecification NewJobSpecification64, Hashtable NewJobDescription64 )
		{
			Int32 ErrorCode = Constants.INVALID;

			bool bAllow64bitJobs = Allow64bitJobs();
			bool bUse64bitJob = (bAllow64bitJobs && NewJobSpecification64 != null) ? true : false;

			// Using the provided specifications, request all necessary Job files. For local
			// Agents, the executable and dependencies must already exist in the cache. For
			// remote Agents, we'll need request the necessary files from the Instigator.
			bool bReceivedJobFiles = false;

			// Am I the instigator?
			if ( Owner is LocalConnection )
			{
				// Request the files for both job specifications (so we can hand out either version to remote agents).
				if ( NewJobSpecification32 != null )
				{
					bReceivedJobFiles = RequestJobFiles( Owner, NewJobSpecification32 );
				}
				if ( NewJobSpecification64 != null && (NewJobSpecification32 == null || bReceivedJobFiles) )
				{
					bReceivedJobFiles = RequestJobFiles( Owner, NewJobSpecification64 );
				}
			}
			else
			{
				// Request the files for my job specification only.
				bReceivedJobFiles = RequestJobFiles( Owner, bUse64bitJob ? NewJobSpecification64 : NewJobSpecification32 );
			}

			if ( bReceivedJobFiles )
			{
				// If this succeeds, set the new specification and update the job state
				Specification32 = NewJobSpecification32;
				Specification64 = NewJobSpecification64;
				Description32 = NewJobDescription32;
				Description64 = NewJobDescription64;

				Specification = bUse64bitJob ? NewJobSpecification64 : NewJobSpecification32;
				Description = bUse64bitJob ? NewJobDescription64 : NewJobDescription32;

				CurrentState = JobState.AGENT_JOB_PENDING;

				ErrorCode = Constants.SUCCESS;
			}
			else
			{
				Manager.Log( EVerbosityLevel.Critical, ELogColour.Red, "[Job] BeginJobSpecification: Failed to cache necessary job files" );
				ErrorCode = Constants.ERROR_CHANNEL_NOT_FOUND;
			}

			return ( ErrorCode );
		}
示例#2
0
文件: Jobs.cs 项目: xiangyuan/Unreal4
		private bool RequestJobFiles( Connection RequestingConnection, AgentJobSpecification JobSpecification )
		{
			// Check for and possibly request the executable
			if( !RequestDependency( RequestingConnection, JobSpecification.ExecutableName, true ) )
			{
				return false;
			}
			// Check for and possibly request each dependency
			if( JobSpecification.RequiredDependencies != null )
			{
				foreach( string Dependency in JobSpecification.RequiredDependencies )
				{
					if( !RequestDependency( RequestingConnection, Dependency, true ) )
					{
						return false;
					}
				}
			}
			if( JobSpecification.OptionalDependencies != null )
			{
				foreach( string Dependency in JobSpecification.OptionalDependencies )
				{
					if( !RequestDependency( RequestingConnection, Dependency, false ) )
					{
						return false;
					}
				}
			}
			return true;
		}
		/*
		 * CacheAllFiles
		 *
		 * Ensures all executables and dependencies are correctly placed in the cache
		 */
		Int32 CacheAllFiles(AgentJobSpecification JobSpecification)
		{
			Int32 ReturnValue = Constants.INVALID;
			try
			{
				// Allocate the dictionary we'll use for the name mapping
				Dictionary<String, String> DependenciesOriginalNames = new Dictionary<String, String>();

				bool bUse64bitNamingConvention = (JobSpecification.JobFlags & EJobTaskFlags.FLAG_64BIT) != 0;

				// Check for and possibly cache the executable
				String OriginalExecutableFullPath = Path.GetFullPath(JobSpecification.ExecutableName);
				String CachedExecutableName;
				ReturnValue = CacheFileAndConvertName(OriginalExecutableFullPath, out CachedExecutableName, bUse64bitNamingConvention);
				if (ReturnValue < 0)
				{
					// Failed to cache the executable, return failure
					Log(EVerbosityLevel.Critical, ELogColour.Red, "[Interface:CacheAllFiles] Failed to cache the executable: " + OriginalExecutableFullPath);
					return ReturnValue;
				}

				JobSpecification.ExecutableName = CachedExecutableName;

				String OriginalExecutableName = Path.GetFileName(OriginalExecutableFullPath);
				DependenciesOriginalNames.Add(CachedExecutableName, OriginalExecutableName);

				// Check and cache all the required dependencies
				if ((JobSpecification.RequiredDependencies != null) &&
					(JobSpecification.RequiredDependencies.Count > 0))
				{
					for (Int32 i = 0; i < JobSpecification.RequiredDependencies.Count; i++)
					{
						String OriginalDependencyFullPath = Path.GetFullPath(JobSpecification.RequiredDependencies[i]);
						String CachedDependencyName;
						ReturnValue = CacheFileAndConvertName(OriginalDependencyFullPath, out CachedDependencyName, bUse64bitNamingConvention);
						if (ReturnValue < 0)
						{
							// Failed to cache the dependency, return failure
							Log(EVerbosityLevel.Critical, ELogColour.Red, "[Interface:CacheAllFiles] Failed to cache the required dependency: " + OriginalDependencyFullPath);
							return ReturnValue;
						}

						JobSpecification.RequiredDependencies[i] = CachedDependencyName;

						String OriginalDependencyName = Path.GetFileName(OriginalDependencyFullPath);
						DependenciesOriginalNames.Add(CachedDependencyName, OriginalDependencyName);
					}
				}
				// Check and cache any optional dependencies
				if ((JobSpecification.OptionalDependencies != null) &&
					(JobSpecification.OptionalDependencies.Count > 0))
				{
					for (Int32 i = 0; i < JobSpecification.OptionalDependencies.Count; i++)
					{
						String OriginalDependencyFullPath = JobSpecification.OptionalDependencies[i];
						String CachedDependencyName;
						ReturnValue = CacheFileAndConvertName(OriginalDependencyFullPath, out CachedDependencyName, bUse64bitNamingConvention);
						if (ReturnValue < 0)
						{
							// Failed to cache the dependency, log a warning
							Log(EVerbosityLevel.Verbose, ELogColour.Orange, "[Interface:CacheAllFiles] Failed to cache an optional dependency: " + OriginalDependencyFullPath);
						}
						else
						{
							JobSpecification.OptionalDependencies[i] = CachedDependencyName;

							String OriginalDependencyName = Path.GetFileName(OriginalDependencyFullPath);
							DependenciesOriginalNames.Add(CachedDependencyName, OriginalDependencyName);
						}
					}
				}

				// Set the newly created name mapping dictionary
				JobSpecification.DependenciesOriginalNames = DependenciesOriginalNames;

				ReturnValue = Constants.SUCCESS;
			}
			catch (Exception Ex)
			{
				Log(EVerbosityLevel.Critical, ELogColour.Red, "[Interface:CacheAllFiles] Error: " + Ex.Message);
				ReturnValue = Constants.ERROR_CONNECTION_DISCONNECTED;
				CleanupClosedConnection();
			}
			return ReturnValue;
		}
		///////////////////////////////////////////////////////////////////////////
		
		public Int32 BeginJobSpecification(Int32 ConnectionHandle, AgentJobSpecification Specification32, Hashtable Description32, AgentJobSpecification Specification64, Hashtable Description64)
		{
			BeginJobSpecificationDelegate DBeginJobSpecification = Connection.BeginJobSpecification;
			
			// Set up the versioned hashtable input parameters
			Hashtable InParameters = new Hashtable();
			InParameters["Version"] = ESwarmVersionValue.VER_1_0;
			InParameters["Specification32"] = Specification32;
			InParameters["Specification64"] = Specification64;
			InParameters["Description32"] = Description32;
			InParameters["Description64"] = Description64;
			
			// Invoke the method, then wait for it to finish or to be notified that the connection dropped
			Hashtable OutParameters = null;
			IAsyncResult Result = DBeginJobSpecification.BeginInvoke(ConnectionHandle, InParameters, ref OutParameters, null, null);
			WaitHandle.WaitAny(new WaitHandle[]{ Result.AsyncWaitHandle, ConnectionDroppedEvent });
			
			// If the method completed normally, return the result
			if (Result.IsCompleted)
			{
				// If the invocation completed, success
				return DBeginJobSpecification.EndInvoke(ref OutParameters, Result);
			}
			// Otherwise, error
			return Constants.ERROR_CONNECTION_DISCONNECTED;
		}
示例#5
0
 public AgentJobRecord()
 {
     Specification = null;
     WorkerAgentNames = new List<string>();
     WorkerAgentIPAddresses = new List<string>();
     AllTasks = new ReaderWriterDictionary<AgentGuid, AgentTask>();
     AgentToGoldenTaskQueueMapping = new ReaderWriterDictionary<string, Queue<AgentTask>>();
     AgentToTaskQueueMapping = new ReaderWriterDictionary<string, Queue<AgentTask>>();
 }