예제 #1
0
파일: dataMover.go 프로젝트: kkellerlbl/AWE
func prepareAppTask(parsed *mediumwork, work *core.Workunit) (err error) {

	// get app definition
	//app_cmd_mode_object, err := core.MyAppRegistry.Get_cmd_mode_object(app_array[0], app_array[1], app_array[2])

	if work.App.AppDef == nil {
		return errors.New("error reading app defintion AppDef from workunit, workid=" + work.Id)
	}
	app_cmd_mode_object := work.App.AppDef
	//if err != nil {
	//	return errors.New("error reading app registry, workid=" + work.Id + " error=" + err.Error())
	//}

	parsed.workunit.Cmd.Dockerimage = app_cmd_mode_object.Dockerimage

	var cmd_interpreter = app_cmd_mode_object.Cmd_interpreter

	logger.Debug(1, fmt.Sprintf("cmd_interpreter: %s", cmd_interpreter))
	var cmd_script = parsed.workunit.Cmd.Cmd_script

	//if len(app_cmd_mode_object.Cmd_script) > 0 {
	//	parsed.workunit.Cmd.Cmd_script = app_cmd_mode_object.Cmd_script
	//	logger.Debug(2, fmt.Sprintf("cmd_script: %s", strings.Join(cmd_script, ", ")))
	//}

	// expand variables on client-side

	numcpu := runtime.NumCPU() //TODO document reserved variable NumCPU // TODO read NumCPU from client profile info
	numcpu_str := strconv.Itoa(numcpu)
	logger.Debug(2, fmt.Sprintf("NumCPU: %s", numcpu_str))

	app_variables := make(core.AppVariables) // this does not reuse exiting app variables, this more like a constant
	//app_variables := work.AppVariables // workunit does not need it yet

	app_variables["NumCPU"] = core.AppVariable{Key: "NumCPU", Var_type: core.Ait_string, Value: numcpu_str}

	for _, io_obj := range work.Inputs {
		name := io_obj.Name
		if io_obj.Host != "" {
			app_variables[name+".host"] = core.AppVariable{Key: name + ".host", Var_type: core.Ait_string, Value: io_obj.Host}
		}
		if io_obj.Node != "" {
			app_variables[name+".node"] = core.AppVariable{Key: name + ".node", Var_type: core.Ait_string, Value: io_obj.Node}
		}
		if io_obj.Url != "" {
			app_variables[name+".url"] = core.AppVariable{Key: name + ".url", Var_type: core.Ait_string, Value: io_obj.Url}
		}

	}

	sigil := "--" // TODO use config from app definition
	arguments_string := ""
	for _, app_arg := range work.App.App_args {
		name := app_arg.Key
		value, ok := app_variables[name]
		if ok {

			if app_arg.Resource == "string" {
				arguments_string += " " + sigil + name + "=" + value.Value
			} else if app_arg.Resource == "bool" {
				if value.Value == "true" {
					arguments_string += " " + sigil + name
				}
			}
		}
	}

	app_variables["arguments"] = core.AppVariable{
		Key:      "arguments",
		Value:    arguments_string,
		Var_type: core.Ait_string,
	}

	app_variables["datatoken"] = core.AppVariable{Key: "datatoken", Var_type: core.Ait_string, Value: work.Info.DataToken}

	err = core.Expand_app_variables(app_variables, cmd_script)
	if err != nil {
		return errors.New(fmt.Sprintf("error: core.Expand_app_variables, %s", err.Error()))
	}

	//for i, _ := range cmd_script {
	//	cmd_script[i] = strings.Replace(cmd_script[i], "${NumCPU}", numcpu_str, -1)
	//}

	// get arguments
	//args_array := strings.Split(args_string_space_removed, ",")
	//args_array := parsed.workunit.Cmd.App_args

	logger.Debug(1, "+++ replace_filepath_with_full_filepath")
	// expand filenames
	err = replace_filepath_with_full_filepath(parsed.workunit.Inputs, conf.DOCKER_WORK_DIR, cmd_script)
	if err != nil {
		return errors.New(fmt.Sprintf("error: replace_filepath_with_full_filepath, %s", err.Error()))
	}
	logger.Debug(1, fmt.Sprintf("cmd_script (expanded): %s", strings.Join(cmd_script, ", ")))
	return
}
예제 #2
0
파일: dataMover.go 프로젝트: wtangiit/AWE
func prepareAppTask(parsed *mediumwork, work *core.Workunit) (err error) {

	app_string := strings.TrimPrefix(parsed.workunit.Cmd.Name, "app:")

	app_array := strings.Split(app_string, ".")

	if len(app_array) != 3 {
		return errors.New("app could not be parsed, workid=" + work.Id + " app=" + app_string)
	}

	if core.MyAppRegistry == nil {
		core.MyAppRegistry, err = core.MakeAppRegistry()
		if err != nil {
			return errors.New("error creating app registry, workid=" + work.Id + " error=" + err.Error())
		}
	}

	// get app definition
	app_cmd_mode_object, err := core.MyAppRegistry.Get_cmd_mode_object(app_array[0], app_array[1], app_array[2])

	if err != nil {
		return errors.New("error reading app registry, workid=" + work.Id + " error=" + err.Error())
	}

	parsed.workunit.Cmd.Dockerimage = app_cmd_mode_object.Dockerimage

	var cmd_interpreter = app_cmd_mode_object.Cmd_interpreter

	logger.Debug(1, fmt.Sprintf("cmd_interpreter: %s", cmd_interpreter))
	var cmd_script = parsed.workunit.Cmd.Cmd_script

	if len(app_cmd_mode_object.Cmd_script) > 0 {
		parsed.workunit.Cmd.ParsedArgs = app_cmd_mode_object.Cmd_script
		logger.Debug(2, fmt.Sprintf("cmd_script: %s", strings.Join(cmd_script, ", ")))
	}

	// expand variables on client-side

	numcpu := runtime.NumCPU() //TODO document reserved variable NumCPU // TODO read NumCPU from client profile info
	numcpu_str := strconv.Itoa(numcpu)
	logger.Debug(2, fmt.Sprintf("NumCPU: %s", numcpu_str))

	app_variables := make(core.AppVariables)

	app_variables["NumCPU"] = core.AppVariable{Var_type: core.Ait_string, Value: numcpu_str}

	err = core.Expand_app_variables(app_variables, cmd_script)
	if err != nil {
		return errors.New(fmt.Sprintf("error: core.Expand_app_variables, %s", err.Error()))
	}

	//for i, _ := range cmd_script {
	//	cmd_script[i] = strings.Replace(cmd_script[i], "${NumCPU}", numcpu_str, -1)
	//}

	// get arguments
	//args_array := strings.Split(args_string_space_removed, ",")
	//args_array := parsed.workunit.Cmd.App_args

	logger.Debug(1, "+++ replace_filepath_with_full_filepath")
	// expand filenames
	err = replace_filepath_with_full_filepath(&parsed.workunit.Inputs, cmd_script)
	if err != nil {
		return errors.New(fmt.Sprintf("error: replace_filepath_with_full_filepath, %s", err.Error()))
	}
	logger.Debug(1, fmt.Sprintf("cmd_script (expanded): %s", strings.Join(cmd_script, ", ")))
	return
}