func (es *executionService) CreateDefinitionRunByDefinitionID(definitionID string, req *state.DefinitionExecutionRequest) (state.Run, error) {
	definition, err := es.stateManager.GetDefinition(definitionID)
	if err != nil {
		return state.Run{}, err
	}
	return es.createFromDefinition(definition, req)
}
Create constructs and queues a new Run on the cluster specified.
package services
import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/aws/aws-sdk-go/aws"
	"math/rand"
	"regexp"
	"strconv"
	"time"
	"github.com/stitchfix/flotilla-os/clients/cluster"
	"github.com/stitchfix/flotilla-os/config"
	"github.com/stitchfix/flotilla-os/exceptions"
	"github.com/stitchfix/flotilla-os/execution/engine"
	"github.com/stitchfix/flotilla-os/state"
)
type ExecutionService interface {
	CreateDefinitionRunByDefinitionID(definitionID string, req *state.DefinitionExecutionRequest) (state.Run, error)
	CreateDefinitionRunByAlias(alias string, req *state.DefinitionExecutionRequest) (state.Run, error)
	List(
		limit int,
		offset int,
		sortOrder string,
		sortField string,
		filters map[string][]string,
		envFilters map[string]string) (state.RunList, error)
	Get(runID string) (state.Run, error)
	UpdateStatus(runID string, status string, exitCode *int64, runExceptions *state.RunExceptions, exitReason *string) error
	Terminate(runID string, userInfo state.UserInfo) error
	ReservedVariables() []string
	ListClusters() ([]string, error)
	GetEvents(run state.Run) (state.PodEventList, error)
	CreateTemplateRunByTemplateID(templateID string, req *state.TemplateExecutionRequest) (state.Run, error)
	CreateTemplateRunByTemplateName(templateName string, templateVersion string, req *state.TemplateExecutionRequest) (state.Run, error)
}
type executionService struct {
	stateManager             state.Manager
	eksClusterClient         cluster.Client
	eksExecutionEngine       engine.Engine
	emrExecutionEngine       engine.Engine
	reservedEnv              map[string]func(run state.Run) string
	eksClusterOverride       []string
	eksOverridePercent       int
	clusterOndemandWhitelist []string
	checkImageValidity       bool
	baseUri                  string
	spotReAttemptOverride    float32
	eksSpotOverride          bool
	spotThresholdMinutes     float64
	terminateJobChannel      chan state.TerminateJob
}
func (es *executionService) GetEvents(run state.Run) (state.PodEventList, error) {
	return es.eksExecutionEngine.GetEvents(run)
}
func NewExecutionService(conf config.Config, eksExecutionEngine engine.Engine, sm state.Manager, eksClusterClient cluster.Client, emrExecutionEngine engine.Engine) (ExecutionService, error) {
	es := executionService{
		stateManager:       sm,
		eksClusterClient:   eksClusterClient,
		eksExecutionEngine: eksExecutionEngine,
		emrExecutionEngine: emrExecutionEngine,
	}
	ownerKey := conf.GetString("owner_id_var")
	if len(ownerKey) == 0 {
		ownerKey = "FLOTILLA_RUN_OWNER_ID"
	}
	es.eksClusterOverride = conf.GetStringSlice("eks.cluster_override")
	es.eksOverridePercent = conf.GetInt("eks.cluster_override_percent")
	es.clusterOndemandWhitelist = conf.GetStringSlice("eks.cluster_ondemand_whitelist")
	if conf.IsSet("check_image_validity") {
		es.checkImageValidity = conf.GetBool("check_image_validity")
	} else {
		es.checkImageValidity = true
	}
	if conf.IsSet("base_uri") {
		es.baseUri = conf.GetString("base_uri")
	}
	if conf.IsSet("eks.spot_reattempt_override") {
		es.spotReAttemptOverride = float32(conf.GetFloat64("eks.spot_reattempt_override"))
	} else {
		es.spotReAttemptOverride = float32(0.05)
	}
	if conf.IsSet("eks.spot_override") {
		es.eksSpotOverride = conf.GetBool("eks.spot_override")
	} else {
		es.eksSpotOverride = false
	}
	if conf.IsSet("eks.spot_threshold_minutes") {
		es.spotThresholdMinutes = conf.GetFloat64("eks.spot_threshold_minutes")
	} else {
		es.spotThresholdMinutes = 30.0
	}
	es.reservedEnv = map[string]func(run state.Run) string{
		"FLOTILLA_SERVER_MODE": func(run state.Run) string {
			return conf.GetString("flotilla_mode")
		},
		"FLOTILLA_RUN_ID": func(run state.Run) string {
			return run.RunID
		},
		"AWS_ROLE_SESSION_NAME": func(run state.Run) string {
			return run.RunID
		},
		ownerKey: func(run state.Run) string {
			return run.User
		},
	}
	es.terminateJobChannel = make(chan state.TerminateJob, 100)
	return &es, nil
}
func (es *executionService) ReservedVariables() []string {
	var keys []string
	for k := range es.reservedEnv {
		keys = append(keys, k)
	}
	return keys
}