Exemple #1
0
func (e *Engine) finalizeMonitorChAfterExecute(mediators []stages.Mediator) {
	if mediators[0].Type == "start" {
		log.Debug("Finalize monitor channel..")
		mediatorEnd := stages.Mediator{States: make(map[string]string), Type: "end"}
		*e.MonitorCh <- mediatorEnd
	} else {
		log.Debugf("Skipped finalizing")
	}
}
Exemple #2
0
func (e *Engine) waitAllChildStages(childStages *list.List, stage *stages.Stage) {
	for childStage := childStages.Front(); childStage != nil; childStage = childStage.Next() {
		s := childStage.Value.(stages.Stage)
		for {
			log.Debugf("Receiving child: %v", s.GetStageName())
			childReceived, ok := <-*s.GetOutputCh()
			if !ok {
				log.Debug("Closing child output")
				break
			}
			log.Debugf("Sending child: %v", childReceived)
			*(*stage).GetOutputCh() <- childReceived
			log.Debugf("Send child: %v", childReceived)
		}
		log.Debugf("Finished executing child: %v", s.GetStageName())
	}
}
Exemple #3
0
// ExecuteStage executes the supplied stage
func (e *Engine) ExecuteStage(stage stages.Stage) {
	log.Debug("Receiving input")

	mediatorsReceived := e.receiveInputs(stage.GetInputCh())

	log.Debugf("Received input size: %v", len(mediatorsReceived))
	log.Debugf("Mediator received: %+v", mediatorsReceived)
	log.Debugf("Execute as parent: %+v", stage)
	log.Debugf("Execute as parent name %+v", stage.GetStageName())

	var result string
	if !e.isUpstreamAnyFailure(mediatorsReceived) || e.Opts.StopOnAnyFailure {
		result = strconv.FormatBool(stage.(stages.Runner).Run())
	} else {
		log.Warnf("Execution is skipped: %v", stage.GetStageName())
		result = "skipped"
	}
	log.Debugf("Stage execution results: %+v, %+v", stage.GetStageName(), result)
	e.Resources.ReportStageResult(stage, result)

	mediator := stages.Mediator{States: make(map[string]string)}
	mediator.States[stage.GetStageName()] = result

	if childStages := stage.GetChildStages(); childStages.Len() > 0 {
		log.Debugf("Execute childstage: %v", childStages)
		e.executeAllChildStages(&childStages, mediator)
		e.waitAllChildStages(&childStages, &stage)
	}

	log.Debugf("Sending output of stage: %+v %v", stage.GetStageName(), mediator)
	*stage.GetOutputCh() <- mediator
	log.Debugf("Closing output of stage: %+v", stage.GetStageName())
	close(*stage.GetOutputCh())

	for _, m := range mediatorsReceived {
		*e.MonitorCh <- m
	}
	*e.MonitorCh <- mediator

	e.finalizeMonitorChAfterExecute(mediatorsReceived)
}