コード例 #1
0
ファイル: walter.go プロジェクト: bluele/walter
// New creates a Walter instance.
func New(opts *config.Opts) (*Walter, error) {
	log.Infof("Pipeline file path: \"%s\"", opts.PipelineFilePath)
	configData, err := config.ReadConfig(opts.PipelineFilePath)
	if err != nil {
		log.Warn("failed to read the configuration file")
		return nil, err
	}

	envs := config.NewEnvVariables()
	parser := &config.Parser{ConfigData: configData, EnvVariables: envs}
	resources, err := parser.Parse()
	if err != nil {
		log.Warn("failed to parse the configuration")
		return nil, err
	}
	monitorCh := make(chan stages.Mediator)
	engine := &engine.Engine{
		Resources:    resources,
		Opts:         opts,
		MonitorCh:    &monitorCh,
		EnvVariables: envs,
	}
	return &Walter{
		Opts:   opts,
		Engine: engine,
	}, nil
}
コード例 #2
0
ファイル: parser.go プロジェクト: bluele/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 {
				continue
			} else if stageOptVal == nil {
				log.Warnf("stage option \"%s\" is not specified", stageOptKey)
				continue
			}
			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
}
コード例 #3
0
ファイル: parser.go プロジェクト: bluele/walter
func (parser *Parser) initStage(stageMap map[interface{}]interface{}) (stages.Stage, error) {
	var stageType = "command"
	if stageMap["type"] != nil {
		stageType = stageMap["type"].(string)
	} else if stageMap["stage_type"] != nil {
		log.Warn("found property \"stage_type\"")
		log.Warn("property \"stage_type\" is deprecated. please use \"type\" instead.")
		stageType = stageMap["stage_type"].(string)
	}
	return stages.InitStage(stageType)
}