Exemplo n.º 1
0
        private void CreateRunningJob(JobInfo jobInfo)
        {
            if (jobInfo == null)
            {
                return;
            }

            Tracer.Info("Starting workers for a new job. PipelineId = {0}, JobId = {1}, JobTypeId = {2}",
                        jobInfo.PipelineId, jobInfo.JobId, jobInfo.JobTypeId);

            RunningJob runningJob = new RunningJob(jobInfo);

            foreach (WorkRequest workRequest in jobInfo.WorkRequests)
            {
                workRequest.BootParameters = jobInfo.BootParameters;
                workRequest.JobParameters  = jobInfo.JobParameters;
                WorkerCard workerCard = WorkersInventory.Instance.FindWorkerForRole(workRequest.RoleType);
                if (null == workerCard)
                {
                    Tracer.Info("This worker manager does not have workers suitable for the role {0}", workRequest.RoleType);
                    continue;
                }
                JobSection jobSection = new JobSection(workRequest, workerCard);
                runningJob.Sections.Add(jobSection);
            }
            RunningJobs.Add(runningJob);

            if (jobInfo.Command == Command.Run)
            {
                EmployWorkersForJob(runningJob);
            }
        }
Exemplo n.º 2
0
 internal WorkerRunner(WorkerCard workerCard, WorkAssignment workAssignment, CommittableTransaction committableTransaction)
 {
     WorkerCard             = workerCard;
     WorkAssignment         = workAssignment;
     CommittableTransaction = committableTransaction;
     Command        = Command.Run;
     quitGracefully = false;
 }
Exemplo n.º 3
0
 internal WorkerRunner(WorkerCard workerCard, WorkAssignment workAssignment, CommittableTransaction committableTransaction)
 {
     WorkerCard = workerCard;
     WorkAssignment = workAssignment;
     CommittableTransaction = committableTransaction;
     Command = Command.Run;
     quitGracefully = false;
 }
Exemplo n.º 4
0
        public JobSection(WorkRequest workRequest, WorkerCard workerCard)
        {
            WorkRequest = workRequest;
            WorkerCard = workerCard;

            WorkerIDs = new List<string>();

            HiringPipe = new Pipe(workRequest.HiringPipeName);
            HiringPipe.Open();
        }
Exemplo n.º 5
0
        public JobSection(WorkRequest workRequest, WorkerCard workerCard)
        {
            WorkRequest = workRequest;
            WorkerCard  = workerCard;

            WorkerIDs = new List <string>();

            HiringPipe = new Pipe(workRequest.HiringPipeName);
            HiringPipe.Open();
        }
Exemplo n.º 6
0
        //[DebuggerNonUserCode] // Suppressing expected first chance exceptions from polluting debugger output window
        protected WorkersInventory()
        {
            WorkerCards = new List <WorkerCard>();

            string workerManagerDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);

            Debug.Assert(workerManagerDirectory != null, "workerManagerDirectory != null");
            string workersDirectory          = Path.Combine(workerManagerDirectory, @"."); // Intentionally do nothing
            Uri    workersDirectoryUri       = new Uri(workersDirectory);
            string workersDirectoryLocalPath = workersDirectoryUri.LocalPath;

            List <FileInfo> workersFiles = Utils.TraverseTree(workersDirectoryLocalPath, "*Worker*.dll");

            // Load for reflection the type which is the base for all other worker types
            Assembly overdriveCoreAssembly = Assembly.ReflectionOnlyLoad("OverdriveCore");
            Type     baseWorkerType        = overdriveCoreAssembly.GetType("LexisNexis.Evolution.Overdrive.WorkerBase");

            // Enumerate all DLLs which may contain workers
            foreach (FileInfo fileInfo in workersFiles)
            {
                Assembly assembly = null;
                try
                {
                    // Reflection only context is required to be able to introspect assemblies with different bitness
                    assembly = Assembly.ReflectionOnlyLoadFrom(fileInfo.FullName);
                    //Tracer.Trace("Introspecting file {0} looking for workers",  fileInfo.FullName);
                }
                catch (Exception)
                {
                    continue; // Ignore those DLLs we can't load. They are probably not a valid .NET assemblies.
                }

                List <Type> workerTypes = LoadAllTypesForReflection(assembly).Where(t => t != baseWorkerType && t.IsSubclassOf(baseWorkerType)).ToList();

                foreach (var workerType in workerTypes)
                {
                    WorkerCard workerCard = BuildWorkerCard(fileInfo.FullName, workerType.FullName);

                    // Make sure we don't get duplicate worker for the same role
                    if (WorkerCards.Any(wc => wc.RoleType == workerCard.RoleType))
                    {
                        Tracer.Warning("WorkerManager found assembly {0}, but there already is a worker for the role {1}. Ignoring that worker.",
                                       workerCard.AssemblyPath, workerCard.RoleType);
                        continue;
                    }

                    //Tracer.Info("Worker {0} found in {1}", workerCard.RoleType, workerCard.AssemblyPath);
                    WorkerCards.Add(workerCard);
                }
            }
        }
Exemplo n.º 7
0
        internal void EmployWorker(WorkerCard workerCard, WorkAssignment workAssignment, CommittableTransaction committableTransaction)
        {
            WorkerRunner workerRunner = null;

            switch (workAssignment.WorkRequest.WorkerIsolationLevel)
            {
            case WorkerIsolationLevel.SeparateAppDomain:
                workerRunner = new WorkerRunnerAppDomain(workerCard, workAssignment, committableTransaction);
                break;

            case WorkerIsolationLevel.SeparateProcess:
                workerRunner = new WorkerRunnerProcess(workerCard, workAssignment, committableTransaction);

                // Debug
                //workerRunner = new WorkerRunnerThread(workerCard, WorkAssignment, committableTransaction);
                break;

            case WorkerIsolationLevel.SeparateThread:
            case WorkerIsolationLevel.Default:
            default:
                workerRunner = new WorkerRunnerThread(workerCard, workAssignment, committableTransaction);
                break;
            }

            try
            {
                AllWorkerRunners.Add(workAssignment.WorkerId, workerRunner);
            }
            catch (Exception ex)
            {
                Tracer.Error("AllWorkerRunners.Add({0}) caused exception: {1}", workAssignment.WorkerId, ex);
                foreach (string workerId in AllWorkerRunners.Keys)
                {
                    Tracer.Error("AllWorkerRunners contains worker {0}", workerId);
                }
                throw;
            }
            workerRunner.Run();
        }
Exemplo n.º 8
0
        private WorkerCard BuildWorkerCard(string assemblyPath, string typeName)
        {
            WorkerCard workerCard = new WorkerCard();

            workerCard.AssemblyPath = assemblyPath;

            int    start   = typeName.LastIndexOf('.');
            string strRole = typeName.Substring(start + 1);

            strRole             = Utils.RemoveSuffix(strRole, "Worker");
            workerCard.RoleType = new RoleType(strRole);

            workerCard.TypeName = typeName;

            #region Set max worker instances
            var    configKey       = workerCard.RoleType + "MaxInstances";
            string strMaxInstances = ConfigurationManager.AppSettings[configKey];
            if (null == strMaxInstances)
            {
                workerCard.MaxNumOfInstances = 1000; // Effectively if maximum number of worker instances per machine is not set we consider it infinite
            }
            else
            {
                uint uintMaxInstances;
                if (uint.TryParse(strMaxInstances, out uintMaxInstances))
                {
                    workerCard.MaxNumOfInstances = uintMaxInstances;
                }
                else
                {
                    Tracer.Error("Maximum number of instances for the worker {0} is configured as {1} which is not a number", strRole, strMaxInstances);
                    workerCard.MaxNumOfInstances = 1000; // Effectively if maximum number of worker instances per machine is not set we consider it infinite
                }
            }
            #endregion

            return(workerCard);
        }
Exemplo n.º 9
0
 internal WorkerRunnerThread(WorkerCard workerCard, WorkAssignment workAssignment, CommittableTransaction committableTransaction)
     : base(workerCard, workAssignment, committableTransaction)
 {
 }
Exemplo n.º 10
0
        internal void EmployWorker(WorkerCard workerCard, WorkAssignment workAssignment, CommittableTransaction committableTransaction)
        {
            WorkerRunner workerRunner = null;

            switch (workAssignment.WorkRequest.WorkerIsolationLevel)
            {
                case WorkerIsolationLevel.SeparateAppDomain:
                    workerRunner = new WorkerRunnerAppDomain(workerCard, workAssignment, committableTransaction);
                    break;
                case WorkerIsolationLevel.SeparateProcess:
                    workerRunner = new WorkerRunnerProcess(workerCard, workAssignment, committableTransaction);

                    // Debug
                    //workerRunner = new WorkerRunnerThread(workerCard, WorkAssignment, committableTransaction);
                    break;
                case WorkerIsolationLevel.SeparateThread:
                case WorkerIsolationLevel.Default:
                default:
                    workerRunner = new WorkerRunnerThread(workerCard, workAssignment, committableTransaction);
                    break;
            }

            try
            {
                AllWorkerRunners.Add(workAssignment.WorkerId, workerRunner);
            }
            catch (Exception ex)
            {
                Tracer.Error("AllWorkerRunners.Add({0}) caused exception: {1}", workAssignment.WorkerId, ex);
                foreach (string workerId in AllWorkerRunners.Keys)
                {
                    Tracer.Error("AllWorkerRunners contains worker {0}", workerId);                    
                }
                throw;
            }
            workerRunner.Run();
        }
Exemplo n.º 11
0
 internal WorkerRunnerThread(WorkerCard workerCard, WorkAssignment workAssignment, CommittableTransaction committableTransaction)
     : base(workerCard, workAssignment, committableTransaction)
 {
 }
        private WorkerCard BuildWorkerCard(string assemblyPath, string typeName)
        {
            WorkerCard workerCard = new WorkerCard();
            workerCard.AssemblyPath = assemblyPath;

            int start = typeName.LastIndexOf('.');
            string strRole = typeName.Substring(start + 1);
            strRole = Utils.RemoveSuffix(strRole, "Worker");
            workerCard.RoleType = new RoleType(strRole);

            workerCard.TypeName = typeName;

            #region Set max worker instances
            var configKey = workerCard.RoleType + "MaxInstances";
            string strMaxInstances = ConfigurationManager.AppSettings[configKey];
            if (null == strMaxInstances)
            {
                workerCard.MaxNumOfInstances = 1000; // Effectively if maximum number of worker instances per machine is not set we consider it infinite
            }
            else
            {
                uint uintMaxInstances;
                if (uint.TryParse(strMaxInstances, out uintMaxInstances))
                {
                    workerCard.MaxNumOfInstances = uintMaxInstances;
                }
                else
                {
                    Tracer.Error("Maximum number of instances for the worker {0} is configured as {1} which is not a number", strRole, strMaxInstances);
                    workerCard.MaxNumOfInstances = 1000; // Effectively if maximum number of worker instances per machine is not set we consider it infinite
                }
            }
            #endregion

            return workerCard;
        }