diff --git a/Makefile b/Makefile index eeaa0966..05ae5eda 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: build clean -export BLADE_VERSION=1.1.0 +export BLADE_VERSION=1.2.0 ALLOWGITVERSION=1.8.5 GITVERSION:=$(shell git --version | grep ^git | sed 's/^.* //g') diff --git a/exec/os/executor.go b/exec/os/executor.go index 36e949d1..988eb4bf 100644 --- a/exec/os/executor.go +++ b/exec/os/executor.go @@ -19,43 +19,53 @@ package os import ( "context" "fmt" - "github.com/chaosblade-io/chaosblade-exec-os/exec" - "github.com/chaosblade-io/chaosblade-exec-os/exec/model" "github.com/chaosblade-io/chaosblade-spec-go/channel" "github.com/chaosblade-io/chaosblade-spec-go/spec" "github.com/chaosblade-io/chaosblade-spec-go/util" + "path" ) type Executor struct { - executors map[string]spec.Executor - sshExecutor spec.Executor } func NewExecutor() spec.Executor { - return &Executor{ - executors: model.GetAllOsExecutors(), - sshExecutor: model.GetSHHExecutor(), - } + return &Executor{} } func (*Executor) Name() string { return "os" } +var c = channel.NewLocalChannel() + +const ( + OS_BIN = "chaos_os" + CREATE = "create" + DESTROY = "destroy" +) + func (e *Executor) Exec(uid string, ctx context.Context, model *spec.ExpModel) *spec.Response { - if model.ActionFlags[exec.ChannelFlag.Name] == e.sshExecutor.Name() { - return e.sshExecutor.Exec(uid, ctx, model) + var args string + var flags string + for k, v := range model.ActionFlags { + if v == "" { + continue + } + flags = fmt.Sprintf("%s %s=%s", flags, k, v) + } + + if _, ok := spec.IsDestroy(ctx); ok { + args = fmt.Sprintf("%s %s %s%s uid=%s", DESTROY, model.Target, model.ActionName, flags, uid) + } else { + args = fmt.Sprintf("%s %s %s%s uid=%s", CREATE, model.Target, model.ActionName, flags, uid) } - key := model.Target + model.ActionName - executor := e.executors[key] - if executor == nil { - util.Errorf(uid, util.GetRunFuncName(), fmt.Sprintf(spec.ResponseErr[spec.OsExecutorNotFound].ErrInfo, key)) - return spec.ResponseFailWaitResult(spec.OsExecutorNotFound, fmt.Sprintf(spec.ResponseErr[spec.OsExecutorNotFound].Err, uid), - fmt.Sprintf(spec.ResponseErr[spec.OsExecutorNotFound].ErrInfo, key)) + response := c.Run(ctx, path.Join(util.GetBinPath(), OS_BIN), args) + if response.Success { + return spec.Decode(response.Result.(string), response) + } else { + return response } - executor.SetChannel(channel.NewLocalChannel()) - return executor.Exec(uid, ctx, model) } func (*Executor) SetChannel(channel spec.Channel) { diff --git a/go.mod b/go.mod index d6ea00fd..65f9088e 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,10 @@ module github.com/chaosblade-io/chaosblade go 1.13 require ( - github.com/chaosblade-io/chaosblade-exec-docker v1.0.1-0.20210409014035-355048b67b24 - github.com/chaosblade-io/chaosblade-exec-os v1.0.1-0.20210408072857-7eed94250576 - github.com/chaosblade-io/chaosblade-operator v1.0.1-0.20210409014453-713dbeea24fe - github.com/chaosblade-io/chaosblade-spec-go v1.1.0-dev + github.com/chaosblade-io/chaosblade-exec-docker v1.2.0 + github.com/chaosblade-io/chaosblade-exec-os v1.2.0 + github.com/chaosblade-io/chaosblade-operator v1.2.0 + github.com/chaosblade-io/chaosblade-spec-go v1.2.0 github.com/mattn/go-sqlite3 v1.10.1-0.20190217174029-ad30583d8387 github.com/olekukonko/tablewriter v0.0.5-0.20201029120751-42e21c7531a3 github.com/prometheus/common v0.9.1