Skip to content

Commit

Permalink
merge: #8945 #8995
Browse files Browse the repository at this point in the history
8945: Introduce new immutable protocol r=npepinpe a=npepinpe

## Description

Introduces a new immutable protocol directly under `protocol`, which annotates the types directly. This has several advantages:

- We can now easily recursively copy the types (except for `Record`, which is a special case due to its generic typing)
- It's less error prone thanks to an ArchUnit test guaranteeing we don't forget to annotate the types
- It's less overhead for developers when adding new types
- It allows us to easily collect metadata about the types via reflection using annotations

This is the first step for #8837 - the next step will remove the immutable variants in `protocol-jackson` and replace them with this.

## Related issues

related to #8837 



8995: Introduce new commands to deploy resources in the Go client r=npepinpe a=npepinpe

## Description

This PR reverts the previous breaking changes and instead introduces new commands to deploy decisions and decision requirements. The client must now use `client.NewDeployResourceCommand()`, and the old `client.NewDeployProcessCommand()` has been restored. Similarly, `zbctl` now supports its old `zbctl deploy <path> <path>` behavior, but also supports `zbctl deploy resource mySuper.dmn` as well, which behaves the same as the old deploy command but can deploy DMN files.

## Related issues

<!-- Which issues are closed by this PR or are related -->

related to #8979 



Co-authored-by: Nicolas Pepin-Perreault <nicolas.pepin-perreault@camunda.com>
  • Loading branch information
zeebe-bors-camunda[bot] and npepinpe committed Mar 25, 2022
3 parents 4f04f2e + b1bfc42 + 69512da commit d325919
Show file tree
Hide file tree
Showing 55 changed files with 788 additions and 99 deletions.
2 changes: 1 addition & 1 deletion clients/go/.gocompat.json

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions clients/go/cmd/zbctl/internal/commands/deploy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright © 2018 Camunda Services GmbH (info@camunda.com)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package commands

import (
"context"
"fmt"
"github.com/spf13/cobra"
"io/ioutil"
)

// Remove the nolint directive once deploy resource is the only command left
//nolint
var deployCmd = &cobra.Command{
Use: "deploy <processPath>...",
Short: "Deploys new resources for each file 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))
}

zbCmd := client.NewDeployProcessCommand()
for i := 0; i < len(resourceNamesFlag); i++ {
bytes, err := ioutil.ReadFile(args[i])
if err != nil {
return err
}

zbCmd.AddResource(bytes, resourceNamesFlag[i])
}

for i := len(resourceNamesFlag); i < len(args); i++ {
zbCmd = zbCmd.AddResourceFile(args[i])
}

ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
defer cancel()

response, err := zbCmd.Send(ctx)
if err != nil {
return err
}

return printJSON(response)
},
}

func init() {
rootCmd.AddCommand(deployCmd)

deployCmd.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")
}
10 changes: 6 additions & 4 deletions clients/go/cmd/zbctl/internal/commands/deployResource.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ import (

var resourceNamesFlag []string

// Remove the nolint directive when this command is the only remaining one for deploy
//nolint
var deployResourceCmd = &cobra.Command{
Use: "deploy <resourcePath>...",
Short: "Creates a new resource (e.g. process, decision) for each BPMN/DMN resource provided",
Use: "resource <resourcePath>...",
Short: "Deploys 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 resource paths (%d)", len(resourceNamesFlag), len(args))
}

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

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

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"+
Expand Down
12 changes: 9 additions & 3 deletions clients/go/cmd/zbctl/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,17 @@ var tests = []testCase{
useHostAndPort: true,
},
{
name: "deploy resources",
cmd: strings.Fields("--insecure deploy testdata/model.bpmn testdata/drg-force-user.dmn --resourceNames=model.bpmn,drg-force-user.dmn"),
name: "deploy processes",
cmd: strings.Fields("--insecure deploy testdata/model.bpmn testdata/job_model.bpmn --resourceNames=model.bpmn,job.bpmn"),
goldenFile: "testdata/deploy.golden",
jsonOutput: true,
},
{
name: "deploy resources",
cmd: strings.Fields("--insecure deploy resource testdata/model.bpmn testdata/drg-force-user.dmn --resourceNames=model.bpmn,drg-force-user.dmn"),
goldenFile: "testdata/deploy_resources.golden",
jsonOutput: true,
},
{
name: "create instance with process id",
setupCmds: [][]string{strings.Fields("--insecure deploy testdata/model.bpmn")},
Expand All @@ -116,7 +122,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 2251799813685254"),
cmd: strings.Fields("--insecure create instance 2251799813685256"),
goldenFile: "testdata/create_instance.golden",
jsonOutput: true,
},
Expand Down
43 changes: 9 additions & 34 deletions clients/go/cmd/zbctl/testdata/deploy.golden
Original file line number Diff line number Diff line change
@@ -1,42 +1,17 @@
{
"key": "2251799813685250",
"deployments": [
"processes": [
{
"process": {
"bpmnProcessId": "process",
"version": 1,
"processDefinitionKey": "2251799813685249",
"resourceName": "model.bpmn"
}
"bpmnProcessId": "process",
"version": 1,
"processDefinitionKey": "2251799813685345",
"resourceName": "model.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"
}
"bpmnProcessId": "jobProcess",
"version": 1,
"processDefinitionKey": "2251799813685346",
"resourceName": "job.bpmn"
}
]
}
42 changes: 42 additions & 0 deletions clients/go/cmd/zbctl/testdata/deploy_resources.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"key": "2251799813685250",
"deployments": [
{
"process": {
"bpmnProcessId": "process",
"version": 1,
"processDefinitionKey": "2251799813685249",
"resourceName": "model.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"
}
}
]
}
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 resource (e.g. process, decision) for each BPMN/DMN resource provided
deploy Deploys new resources for each file provided
fail Fail a resource
generate Generate documentation
help Help about any command
Expand Down
9 changes: 5 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.DeployResourceRequest
request pb.DeployProcessRequest //nolint
}

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

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

func (cmd *DeployCommand) Send(ctx context.Context) (*pb.DeployResourceResponse, error) {
response, err := cmd.gateway.DeployResource(ctx, &cmd.request)
func (cmd *DeployCommand) Send(ctx context.Context) (*pb.DeployProcessResponse, error) { //nolint
response, err := cmd.gateway.DeployProcess(ctx, &cmd.request) //nolint
if cmd.shouldRetry(ctx, err) {
return cmd.Send(ctx)
}
Expand Down
58 changes: 58 additions & 0 deletions clients/go/pkg/commands/deploy_resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright © 2018 Camunda Services GmbH (info@camunda.com)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package commands

import (
"context"
"github.com/camunda/zeebe/clients/go/pkg/pb"
"io/ioutil"
"log"
)

type DeployResourceCommand struct {
Command
request pb.DeployResourceRequest
}

func (cmd *DeployResourceCommand) AddResourceFile(path string) *DeployResourceCommand {
b, err := ioutil.ReadFile(path)
if err != nil {
log.Fatal(err)
}
return cmd.AddResource(b, path)
}

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

func (cmd *DeployResourceCommand) Send(ctx context.Context) (*pb.DeployResourceResponse, error) {
response, err := cmd.gateway.DeployResource(ctx, &cmd.request)
if cmd.shouldRetry(ctx, err) {
return cmd.Send(ctx)
}

return response, err
}

func NewDeployResourceCommand(gateway pb.GatewayClient, pred retryPredicate) *DeployResourceCommand {
return &DeployResourceCommand{
Command: Command{
gateway: gateway,
shouldRetry: pred,
},
}
}
Loading

0 comments on commit d325919

Please sign in to comment.