예제 #1
0
파일: parser.go 프로젝트: hotchemi/walter
func (parser *Parser) mapStage(stageMap map[interface{}]interface{},
	requiredStages map[string]map[interface{}]interface{}) (stages.Stage, error) {
	mergedStageMap, err := parser.extractStage(stageMap, requiredStages)
	if err != nil {
		return nil, err
	}
	stage, err := parser.initStage(mergedStageMap)
	if err != nil {
		return nil, err
	}

	if stageName := mergedStageMap["name"]; stageName != nil {
		stage.SetStageName(mergedStageMap["name"].(string))
	} else if stageName := mergedStageMap["stage_name"]; stageName != nil {
		log.Warn("found property \"stage_name\"")
		log.Warn("property \"stage_name\" is deprecated. please use \"stage\" instead.")
		stage.SetStageName(mergedStageMap["stage_name"].(string))
	}

	stageOpts := stages.NewStageOpts()
	if reportingFullOutput := mergedStageMap["report_full_output"]; reportingFullOutput != nil {
		stageOpts.ReportingFullOutput = true
	}
	stage.SetStageOpts(*stageOpts)

	newStageValue := reflect.ValueOf(stage).Elem()
	newStageType := reflect.TypeOf(stage).Elem()
	for i := 0; i < newStageType.NumField(); i++ {
		tagName := newStageType.Field(i).Tag.Get("config")
		isReplace := newStageType.Field(i).Tag.Get("is_replace")
		for stageOptKey, stageOptVal := range mergedStageMap {
			if tagName == stageOptKey {
				if stageOptVal == nil {
					log.Warnf("stage option \"%s\" is not specified", stageOptKey)
				} else {
					parser.setFieldVal(newStageValue.Field(i), stageOptVal, isReplace)
				}
			}
		}
	}

	parallelStages := mergedStageMap["parallel"]
	if parallelStages == nil {
		if parallelStages = mergedStageMap["run_after"]; parallelStages != nil {
			log.Warn("`run_after' will be obsoleted in near future. Use `parallel' instead.")
		}
	}

	if parallelStages != nil {
		for _, parallelStage := range parallelStages.([]interface{}) {
			childStage, err := parser.mapStage(parallelStage.(map[interface{}]interface{}), requiredStages)
			if err != nil {
				return nil, err
			}
			stage.AddChildStage(childStage)
		}
	}
	return stage, nil
}
예제 #2
0
파일: envvar.go 프로젝트: hotchemi/walter
func (envVariables *EnvVariables) regexReplace(input string) string {
	matched := (*envVariables.re).FindStringSubmatch(input)
	if len(matched) == 2 {
		if replaced := (*envVariables.variables)[matched[1]]; replaced != "" {
			return replaced
		}
		log.Warnf("NO environment variable: %s", matched[0])
		return ""

	}
	return input
}
예제 #3
0
파일: service.go 프로젝트: jacec/walter
func LoadLastUpdate(fname string) (Update, error) {
	file, err := ioutil.ReadFile(fname)
	log.Infof("opening file: \"%s\"...", fname)
	if err != nil {
		log.Warnf("error occured opening file: \"%s\" ...", fname)
		log.Warnf(err.Error())
		log.Warnf("continue the process with the new settings")
		update := Update{
			Time:      time.Date(1970, time.November, 10, 15, 0, 0, 0, time.Local),
			Succeeded: true,
			Status:    "inprogress"}
		return update, nil
	}

	log.Infof("loading last update form \"%s\"\n", string(file))
	var update Update
	if err := json.Unmarshal(file, &update); err != nil {
		log.Warnf("failed to load \"%s\" ...", fname)
		log.Warnf(err.Error())
		log.Warnf("continue the process with the new settings")
		update := Update{
			Time:      time.Now(),
			Succeeded: true,
			Status:    "inprogress"}
		return update, nil
	}

	if update.Status == "inprogress" {
		return Update{}, errors.New("update is currently run in another process")
	}

	log.Info("setting update status into \"inprogress\"...")
	return update, nil
}
예제 #4
0
func execCommand(cmd *exec.Cmd, prefix string, name string) (bool, *string, *string) {
	out, err := cmd.StdoutPipe()
	outE, errE := cmd.StderrPipe()

	if err != nil {
		log.Warnf("[command] %s err: %s", prefix, out)
		log.Warnf("[command] %s err: %s", prefix, err)
		return false, nil, nil
	}

	if errE != nil {
		log.Warnf("[command] %s err: %s", prefix, outE)
		log.Warnf("[command] %s err: %s", prefix, errE)
		return false, nil, nil
	}

	err = cmd.Start()
	if err != nil {
		log.Warnf("[command] %s err: %s", prefix, err)
		return false, nil, nil
	}
	outResult := copyStream(out, prefix, name)
	errResult := copyStream(outE, prefix, name)

	err = cmd.Wait()
	if err != nil {
		log.Warnf("[command] %s err: %s", prefix, err)
		return false, &outResult, &errResult
	}
	return true, &outResult, &errResult
}
예제 #5
0
// Run registered commands.
func (commandStage *CommandStage) Run() bool {
	// Check OnlyIf
	if commandStage.runOnlyIf() == false {
		log.Warnf("[command] exec: skipped this stage \"%s\", since only_if condition failed", commandStage.BaseStage.StageName)
		return true
	}

	// Run command
	result := commandStage.runCommand()
	if result == false {
		log.Errorf("[command] exec: failed stage \"%s\"", commandStage.BaseStage.StageName)
	}
	return result
}
예제 #6
0
파일: engine.go 프로젝트: hotchemi/walter
// 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)
}