public void Build(PipelineBuildOrder pipelineBuildOrder) { string machineName = Environment.MachineName; PipelineType = pipelineBuildOrder.PipelineType; PipelineId = pipelineBuildOrder.PipelineId.ToString(CultureInfo.InvariantCulture); ReportPipeName = new ReportPipeName(machineName, PipelineType, PipelineId); using (ReportPipe = new Pipe(ReportPipeName)) { ReportPipe.Create(); } uint orderNumber = 0; foreach (var rolePlan in pipelineBuildOrder.RolePlans) { PipelineSection pipelineSection = new PipelineSection(machineName, orderNumber, PipelineType, PipelineId, rolePlan); PipelineSections.Add(pipelineSection); if (rolePlan.Name == "Log") { LogDataPipeName = new DataPipeName(machineName, PipelineType, PipelineId, "Log" /* section name*/); } orderNumber++; } PipelineStatus.PipelineState = PipelineState.Built; }
protected override void PeriodicPipelineServicingHook() { base.PeriodicPipelineServicingHook(); if (CurrentContinuation > NumberOfContinuations) { return; } if (PipelineStatus.PipelineState < PipelineState.FirstWorkerCompleted) { Tracer.Warning("FIRST WORKER HAS NOT COMPLETED YET!"); return; } PipelineSection triggerSection = PipelineSections.Find(pipelineSection => pipelineSection.OrderNumber == 1); if (triggerSection == null) { return; } if (triggerSection.DataPipeName != null && triggerSection.DataPipeName.Count > 0) { Tracer.Warning("SECOND SECTION IS STILL BUSY!"); return; } Tracer.Warning("ACTION GOES HERE!"); CurrentContinuation++; }
protected void ProcessWorkerStateChangeReports(WorkerStateChangedMessage message) { PipelineSection pipelineSection = FindPipelineSection(message.WorkerBadge.SectionName); if (pipelineSection == null) { return; } WorkerStatus workerStatus; bool found = pipelineSection.WorkerStatuses.TryGetValue(message.WorkerBadge.WorkerId, out workerStatus); if (found) { workerStatus.WorkerState = message.WorkerState; } else { workerStatus = new WorkerStatus() { WorkerBadge = message.WorkerBadge, WorkerState = message.WorkerState }; pipelineSection.WorkerStatuses.Add(message.WorkerBadge.WorkerId, workerStatus); Tracer.Trace("Pipeline {0}, section {1} added new worker {2} with state {3}", PipelineId, pipelineSection.Name, message.WorkerBadge.WorkerId, workerStatus.WorkerState); } // Debug //Tracer.Warning("Worker " + message.WorkerBadge.WorkerId + " reported state " + message.WorkerState); if (pipelineSection.OrderNumber == 0 && message.WorkerState == WorkerState.Started) { Tracer.Info("Pipeline initialization completed in {0:0.##} seconds. First worker started filling up the pipe.", _runTime.Elapsed.TotalSeconds); } // Handling first worker completion if (pipelineSection.OrderNumber == 0 && message.WorkerState == WorkerState.Completed) { // First worker reported that it generated at least one message to the pipe. PipelineStatus.PipelineState = PipelineState.FirstWorkerCompleted; CheckPipelineForCompletion(); } // Handling worker quit if (message.WorkerState == WorkerState.Quit) { if (pipelineSection.WorkersNotQuit == 0) { long remainingWorkers = PipelineSections.Aggregate <PipelineSection, long>(0, (current, curPipelineSection) => current + curPipelineSection.WorkersNotQuit); if (remainingWorkers == 0) { PipelineStatus.PipelineState = PipelineState.AllWorkersQuit; } } } }
protected PipelineSection FindPipelineSection(string sectionName) { if (PipelineSections != null) { foreach (PipelineSection pipelineSection in PipelineSections.Where(pipelineSection => pipelineSection.Name == sectionName)) { return(pipelineSection); } } Debug.Assert(false, "Pipeline received message from worker with unexpected section name"); return(null); }
protected bool CheckPipelineForCompletion() { if (PipelineStatus.GetMostRecentState() != PipelineState.FirstWorkerCompleted) { return(false); } // Debugging //foreach (var pipelineSection in PipelineSections) //{ // if (pipelineSection.DataPipeName != null /*&& pipelineSection.DataPipeName.Count > 0*/) // { // Tracer.Debug("Pipeline section {0} contains {1} messages.", pipelineSection.Name, pipelineSection.DataPipeName.Count); // } //} // When in the Running state we can check all data pipes sequentially and if they all are empty this means we are done if (PipelineSections.Any(pipelineSection => pipelineSection.DataPipeName != null && pipelineSection.DataPipeName.Count > 0)) { return(false); } Tracer.Info("Pipeline detected that there are no more messages in the pipes."); try { if (!Completed()) { Tracer.Info("Custom Pipeline completion handler requested continuation of pipeline operation."); return(false); } } catch (Exception ex) { ex.Trace(); ProblemReport problemReport = new ProblemReport("Pipeline completion", WorkerStage.EndWork, ex); PipelineStatus.ProblemReports.Add(problemReport); } if (PipelineStatus.ProblemReports.Any()) { Tracer.Warning("Pipeline detected job completion WITH ERRORS in {0:0.##} seconds.", _runTime.Elapsed.TotalSeconds); PipelineStatus.PipelineState = PipelineState.ProblemReported; return(true); } Tracer.Warning("Pipeline detected job completion without errors in {0:0.##} seconds.", _runTime.Elapsed.TotalSeconds); PipelineStatus.PipelineState = PipelineState.Completed; return(true); }
public void Delete() { if (ReportPipe != null) { ReportPipe.Delete(); } foreach (PipelineSection pipelineSection in PipelineSections) { pipelineSection.DeletePipes(); } // Just in case PipelineSections.Clear(); }
public List <WorkRequest> GenerateWorkRequests() { try { List <WorkRequest> workRequests = new List <WorkRequest>(); foreach (PipelineSection pipelineSection in PipelineSections) { WorkRequest workRequest = new WorkRequest ( pipelineSection.Name, pipelineSection.DataPipeName, pipelineSection.HiringPipeName, LogDataPipeName, ReportPipe.Name as ReportPipeName, pipelineSection.RoleType, PipelineType, PipelineId, null ) { OutputSections = new List <WorkRequest.OutputSection>() }; foreach (string outputSectionName in pipelineSection.OutputSectionNames) { PipelineSection outputPipelineSection = PipelineSections.Find(item => item.Name == outputSectionName); workRequest.OutputSections.Add(new WorkRequest.OutputSection(outputSectionName, outputPipelineSection.DataPipeName)); } workRequests.Add(workRequest); } return(workRequests); } catch (Exception ex) { ex.AddDbgMsg("Work request generation failed.").Trace().Swallow(); return(null); // Calling method handles this gracefully. } }