Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve workflow definition #118

Merged
merged 2 commits into from
Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build/build-env/defaultBuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ parse() {
}

echo "Building with v$(wfcli --version)..."
if [[ -f $SRC_PKG ]] ; then
if [[ -f ${SRC_PKG} ]] ; then
# Package is a single file
parse ${SRC_PKG} ${DEPLOY_PKG}
elif [[ -d ${SRC_PKG} ]] ; then
Expand All @@ -25,7 +25,7 @@ elif [[ -d ${SRC_PKG} ]] ; then
parse ${wf} > ${DEPLOY_PKG}/dst
done
else
echo "Unknown file type: '${SRC_PKG}'"
echo "Invalid file type: '${SRC_PKG}'"
exit 11
fi
echo "Build succeeded."
46 changes: 32 additions & 14 deletions cmd/wfcli/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,35 @@ import (
"os"
"strings"

"github.com/fission/fission-workflows/pkg/parse/yaml"
"github.com/fission/fission-workflows/pkg/parse"
"github.com/fission/fission-workflows/pkg/types"
"github.com/golang/protobuf/jsonpb"
"github.com/urfave/cli"
)

var cmdParse = cli.Command{
Name: "parse",
Aliases: []string{"p"},
Usage: "parse <path-to-yaml> ",
Name: "parse",
Aliases: []string{"p"},
Usage: "parse <path-to-source> ",
Flags: []cli.Flag{
cli.StringFlag{
Name: "type, t",
Value: "yaml",
Usage: "Indicate which parser plugin to use for the parsing (yaml|pb).",
},
},
Description: "Read YAML definitions to the executable JSON format (deprecated)",
Action: func(c *cli.Context) error {

if c.NArg() == 0 {
panic("Need a path to a yaml workflow definition")
}

parserType := c.String("type")
if parserType != "" && !parse.Supports(parserType) {
fmt.Printf("Unknown parser '%s'; will try all parsers.", parserType)
}

for _, path := range c.Args() {

fnName := strings.TrimSpace(path)
Expand All @@ -30,21 +43,26 @@ var cmdParse = cli.Command{
panic(err)
}

wfSpec, err := yaml.Parse(f)
if err != nil {
panic(err)
}

marshal := jsonpb.Marshaler{
Indent: " ",
}
jsonWf, err := marshal.MarshalToString(wfSpec)
wfSpec, err := parse.ParseWith(f, parserType)
if err != nil {
panic(err)
}

fmt.Println(jsonWf)
println(toFormattedJson(wfSpec))
}
return nil
},
}

func toFormattedJson(spec *types.WorkflowSpec) string {

marshal := jsonpb.Marshaler{
Indent: " ",
}
jsonWf, err := marshal.MarshalToString(spec)
if err != nil {
panic(err)
}

return jsonWf
}
7 changes: 3 additions & 4 deletions pkg/api/dynamic/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ func (ap *Api) AddDynamicTask(invocationId string, parentId string, taskSpec *ty
}

func (ap *Api) AddDynamicWorkflow(invocationId string, parentTaskId string, workflowSpec *types.WorkflowSpec) error {
taskSpec := types.NewTaskSpec()
// TODO add inputs to WorkflowSpec
return ap.addDynamicWorkflow(invocationId, parentTaskId, workflowSpec, taskSpec)
return ap.addDynamicWorkflow(invocationId, parentTaskId, workflowSpec, &types.TaskSpec{})
}

func (ap *Api) addDynamicWorkflow(invocationId string, parentTaskId string, wfSpec *types.WorkflowSpec,
Expand All @@ -63,9 +62,9 @@ func (ap *Api) addDynamicWorkflow(invocationId string, parentTaskId string, wfSp
// Generate Proxy Task
proxyTaskSpec := proto.Clone(stubTask).(*types.TaskSpec)
proxyTaskSpec.FunctionRef = wfId
proxyTaskSpec.AddInput("_parent", typedvalues.ParseString(invocationId))
proxyTaskSpec.Input("_parent", typedvalues.ParseString(invocationId))
proxyTaskId := parentTaskId + "_child"
proxyTask := types.NewTask(proxyTaskId)
proxyTask := types.NewTask(proxyTaskId, proxyTaskSpec.FunctionRef)
proxyTask.Spec = proxyTaskSpec
proxyTask.Status.Status = types.TaskStatus_READY
proxyTask.Status.FnRef = workflows.CreateFnRef(wfId)
Expand Down
116 changes: 75 additions & 41 deletions pkg/apiserver/apiserver.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions pkg/apiserver/apiserver.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/apiserver/apiserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ service WorkflowInvocationAPI {
get: "/invocation/{id}"
};
}

rpc Validate (WorkflowInvocationSpec) returns (google.protobuf.Empty) {
option (google.api.http) = {
post: "/invocation/validate"
body: "*"
};
}
}

message WorkflowInvocationIdentifier {
Expand Down
11 changes: 11 additions & 0 deletions pkg/apiserver/invocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package apiserver

import (
"errors"
"strings"
"time"

"github.com/fission/fission-workflows/pkg/api/invocation"
"github.com/fission/fission-workflows/pkg/fes"
"github.com/fission/fission-workflows/pkg/types"
"github.com/fission/fission-workflows/pkg/types/aggregates"
"github.com/fission/fission-workflows/pkg/types/validate"
"github.com/golang/protobuf/ptypes/empty"
"github.com/sirupsen/logrus"
"golang.org/x/net/context"
Expand All @@ -23,6 +25,15 @@ type grpcInvocationApiServer struct {
wfiCache fes.CacheReader
}

func (gi *grpcInvocationApiServer) Validate(ctx context.Context, spec *types.WorkflowInvocationSpec) (*empty.Empty, error) {
err := validate.WorkflowInvocationSpec(spec)
if err != nil {
logrus.Info(strings.Replace(validate.Format(err), "\n", "; ", -1))
return nil, err
}
return &empty.Empty{}, nil
}

func NewGrpcInvocationApiServer(api *invocation.Api, wfiCache fes.CacheReader) WorkflowInvocationAPIServer {
return &grpcInvocationApiServer{api, wfiCache}
}
Expand Down
Loading