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

Deploy decision requirements and decisions via the Go client and zbctl #8979

Merged
merged 5 commits into from
Mar 25, 2022
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
2 changes: 1 addition & 1 deletion clients/go/.gocompat.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ import (

var resourceNamesFlag []string

var deployProcessCmd = &cobra.Command{
Use: "deploy <processPath>...",
Short: "Creates a new process for each BPMN or YAML resource provided",
var deployResourceCmd = &cobra.Command{
Use: "deploy <resourcePath>...",
Short: "Creates a new resource (e.g. process, decision) for each BPMN/DMN resource provided",
Args: cobra.MinimumNArgs(1),
PreRunE: initClient,
RunE: func(cmd *cobra.Command, args []string) error {
if len(resourceNamesFlag) > len(args) {
return fmt.Errorf("there are more resource names (%d) than process paths (%d)", len(resourceNamesFlag), len(args))
return fmt.Errorf("there are more resource names (%d) than resource paths (%d)", len(resourceNamesFlag), len(args))
}

zbCmd := client.NewDeployProcessCommand()
zbCmd := client.NewDeployCommand()
for i := 0; i < len(resourceNamesFlag); i++ {
bytes, err := ioutil.ReadFile(args[i])
if err != nil {
Expand All @@ -59,9 +59,9 @@ var deployProcessCmd = &cobra.Command{
}

func init() {
rootCmd.AddCommand(deployProcessCmd)
rootCmd.AddCommand(deployResourceCmd)

deployProcessCmd.Flags().StringSliceVar(&resourceNamesFlag, "resourceNames", nil, "Resource names"+
" for the processes paths passed as arguments. The resource names are matched to processes by position. If a"+
" process does not have a matching resource name, the process path is used instead")
deployResourceCmd.Flags().StringSliceVar(&resourceNamesFlag, "resourceNames", nil, "Resource names"+
" for the resource paths passed as arguments. The resource names are matched to resources by position. If a"+
" resource does not have a matching resource name, the resource path is used instead")
}
6 changes: 3 additions & 3 deletions clients/go/cmd/zbctl/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ var tests = []testCase{
useHostAndPort: true,
},
{
name: "deploy process",
cmd: strings.Fields("--insecure deploy testdata/model.bpmn testdata/job_model.bpmn --resourceNames=model.bpmn,job.bpmn"),
name: "deploy resources",
cmd: strings.Fields("--insecure deploy testdata/model.bpmn testdata/drg-force-user.dmn --resourceNames=model.bpmn,drg-force-user.dmn"),
goldenFile: "testdata/deploy.golden",
jsonOutput: true,
},
Expand All @@ -116,7 +116,7 @@ var tests = []testCase{
{
name: "create instance with process key",
setupCmds: [][]string{strings.Fields("--insecure deploy testdata/model.bpmn")},
cmd: strings.Fields("--insecure create instance 2251799813685252"),
cmd: strings.Fields("--insecure create instance 2251799813685254"),
goldenFile: "testdata/create_instance.golden",
jsonOutput: true,
},
Expand Down
43 changes: 34 additions & 9 deletions clients/go/cmd/zbctl/testdata/deploy.golden
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
{
"key": "2251799813685250",
"processes": [
"deployments": [
{
"bpmnProcessId": "process",
"version": 1,
"processDefinitionKey": "2251799813685345",
"resourceName": "model.bpmn"
"process": {
"bpmnProcessId": "process",
"version": 1,
"processDefinitionKey": "2251799813685249",
"resourceName": "model.bpmn"
}
},
{
"bpmnProcessId": "jobProcess",
"version": 1,
"processDefinitionKey": "2251799813685346",
"resourceName": "job.bpmn"
"decision": {
"dmnDecisionId": "jedi_or_sith",
"dmnDecisionName": "Jedi or Sith",
"version": 1,
"decisionKey": "2251799813685251",
"dmnDecisionRequirementsId": "force_users",
"decisionRequirementsKey": "2251799813685250"
}
},
{
"decision": {
"dmnDecisionId": "force_user",
"dmnDecisionName": "Which force user?",
"version": 1,
"decisionKey": "2251799813685252",
"dmnDecisionRequirementsId": "force_users",
"decisionRequirementsKey": "2251799813685250"
}
},
{
"decisionRequirements": {
"dmnDecisionRequirementsId": "force_users",
"dmnDecisionRequirementsName": "force_users",
"version": 1,
"decisionRequirementsKey": "2251799813685250",
"resourceName": "drg-force-user.dmn"
}
}
]
}
144 changes: 144 additions & 0 deletions clients/go/cmd/zbctl/testdata/drg-force-user.dmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" xmlns:biodi="http://bpmn.io/schema/dmn/biodi/2.0" xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/" id="force_users" name="force_users" namespace="http://camunda.org/schema/1.0/dmn" exporter="Camunda Modeler" exporterVersion="5.0.0-alpha.1">
<decision id="jedi_or_sith" name="Jedi or Sith">
<decisionTable id="DecisionTable_14n3bxx">
<input id="Input_1" label="Lightsaber color" biodi:width="192">
<inputExpression id="InputExpression_1" typeRef="string">
<text>lightsaberColor</text>
</inputExpression>
</input>
<output id="Output_1" label="Jedi or Sith" name="jedi_or_sith" typeRef="string" biodi:width="192">
<outputValues id="UnaryTests_0hj346a">
<text>"Jedi","Sith"</text>
</outputValues>
</output>
<rule id="DecisionRule_0zumznl">
<inputEntry id="UnaryTests_0leuxqi">
<text>"blue"</text>
</inputEntry>
<outputEntry id="LiteralExpression_0c9vpz8">
<text>"Jedi"</text>
</outputEntry>
</rule>
<rule id="DecisionRule_1utwb1e">
<inputEntry id="UnaryTests_1v3sd4m">
<text>"green"</text>
</inputEntry>
<outputEntry id="LiteralExpression_0tgh8k1">
<text>"Jedi"</text>
</outputEntry>
</rule>
<rule id="DecisionRule_1bwgcym">
<inputEntry id="UnaryTests_0n1ewm3">
<text>"red"</text>
</inputEntry>
<outputEntry id="LiteralExpression_19xnlkw">
<text>"Sith"</text>
</outputEntry>
</rule>
</decisionTable>
</decision>
<decision id="force_user" name="Which force user?">
<informationRequirement id="InformationRequirement_1o8esai">
<requiredDecision href="#jedi_or_sith" />
</informationRequirement>
<decisionTable id="DecisionTable_07g94t1" hitPolicy="FIRST">
<input id="InputClause_0qnqj25" label="Jedi or Sith">
<inputExpression id="LiteralExpression_00lcyt5" typeRef="string">
<text>jedi_or_sith</text>
</inputExpression>
<inputValues id="UnaryTests_1xjidd8">
<text>"Jedi","Sith"</text>
</inputValues>
</input>
<input id="InputClause_0k64hys" label="Body height">
<inputExpression id="LiteralExpression_0ib6fnk" typeRef="number">
<text>height</text>
</inputExpression>
</input>
<output id="OutputClause_0hhe1yo" label="Force user" name="force_user" typeRef="string" />
<rule id="DecisionRule_13zidc5">
<inputEntry id="UnaryTests_056skcq">
<text>"Jedi"</text>
</inputEntry>
<inputEntry id="UnaryTests_0l4xksq">
<text>&gt; 190</text>
</inputEntry>
<outputEntry id="LiteralExpression_0hclhw3">
<text>"Mace Windu"</text>
</outputEntry>
</rule>
<rule id="DecisionRule_0uin2hk">
<description></description>
<inputEntry id="UnaryTests_16maepk">
<text>"Jedi"</text>
</inputEntry>
<inputEntry id="UnaryTests_0rv0nwf">
<text>&gt; 180</text>
</inputEntry>
<outputEntry id="LiteralExpression_0t82c11">
<text>"Obi-Wan Kenobi"</text>
</outputEntry>
</rule>
<rule id="DecisionRule_0mpio0p">
<inputEntry id="UnaryTests_09eicyc">
<text>"Jedi"</text>
</inputEntry>
<inputEntry id="UnaryTests_1bekl8k">
<text>&lt; 70</text>
</inputEntry>
<outputEntry id="LiteralExpression_0brx3vt">
<text>"Yoda"</text>
</outputEntry>
</rule>
<rule id="DecisionRule_06paffx">
<inputEntry id="UnaryTests_1baiid4">
<text>"Sith"</text>
</inputEntry>
<inputEntry id="UnaryTests_0fcdq0i">
<text>&gt; 200</text>
</inputEntry>
<outputEntry id="LiteralExpression_02oibi4">
<text>"Darth Vader"</text>
</outputEntry>
</rule>
<rule id="DecisionRule_1ua4pcl">
<inputEntry id="UnaryTests_1s1h3nm">
<text>"Sith"</text>
</inputEntry>
<inputEntry id="UnaryTests_1pnvw8p">
<text>&gt; 170</text>
</inputEntry>
<outputEntry id="LiteralExpression_1w1n2rc">
<text>"Darth Sidius"</text>
</outputEntry>
</rule>
<rule id="DecisionRule_00ew25e">
<inputEntry id="UnaryTests_07uxyug">
<text></text>
</inputEntry>
<inputEntry id="UnaryTests_1he6fym">
<text></text>
</inputEntry>
<outputEntry id="LiteralExpression_07i3sc8">
<text>"unknown"</text>
</outputEntry>
</rule>
</decisionTable>
</decision>
<dmndi:DMNDI>
<dmndi:DMNDiagram>
<dmndi:DMNShape dmnElementRef="jedi_or_sith">
<dc:Bounds height="80" width="180" x="160" y="280" />
</dmndi:DMNShape>
<dmndi:DMNShape id="DMNShape_1sb3tre" dmnElementRef="force_user">
<dc:Bounds height="80" width="180" x="280" y="80" />
</dmndi:DMNShape>
<dmndi:DMNEdge id="DMNEdge_0gt1p1u" dmnElementRef="InformationRequirement_1o8esai">
<di:waypoint x="250" y="280" />
<di:waypoint x="370" y="180" />
<di:waypoint x="370" y="160" />
</dmndi:DMNEdge>
</dmndi:DMNDiagram>
</dmndi:DMNDI>
</definitions>
2 changes: 1 addition & 1 deletion clients/go/cmd/zbctl/testdata/help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Available Commands:
complete Complete a resource
completion Generate the autocompletion script for the specified shell
create Create resources
deploy Creates a new process for each BPMN or YAML resource provided
deploy Creates a new resource (e.g. process, decision) for each BPMN/DMN resource provided
korthout marked this conversation as resolved.
Show resolved Hide resolved
fail Fail a resource
generate Generate documentation
help Help about any command
Expand Down
72 changes: 71 additions & 1 deletion clients/go/internal/mock_pb/mock_gateway.go

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

8 changes: 4 additions & 4 deletions clients/go/pkg/commands/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

type DeployCommand struct {
Command
request pb.DeployProcessRequest
request pb.DeployResourceRequest
}

func (cmd *DeployCommand) AddResourceFile(path string) *DeployCommand {
Expand All @@ -35,12 +35,12 @@ func (cmd *DeployCommand) AddResourceFile(path string) *DeployCommand {
}

func (cmd *DeployCommand) AddResource(definition []byte, name string) *DeployCommand {
cmd.request.Processes = append(cmd.request.Processes, &pb.ProcessRequestObject{Definition: definition, Name: name})
cmd.request.Resources = append(cmd.request.Resources, &pb.Resource{Content: definition, Name: name})
return cmd
}

func (cmd *DeployCommand) Send(ctx context.Context) (*pb.DeployProcessResponse, error) {
response, err := cmd.gateway.DeployProcess(ctx, &cmd.request)
func (cmd *DeployCommand) Send(ctx context.Context) (*pb.DeployResourceResponse, error) {
response, err := cmd.gateway.DeployResource(ctx, &cmd.request)
if cmd.shouldRetry(ctx, err) {
return cmd.Send(ctx)
}
Expand Down
Loading