Skip to content

Commit

Permalink
Fix the 400 error when create function (streamnative/pulsarctl#405)
Browse files Browse the repository at this point in the history
* Fix the 400 error when create function
---

*Motivation*

When using pulsarctl create functions, pulsarctl always get 400 bac request
error. That cause by we pass the unneeded field in the request. This PR ignore
the function configurations in the request if the field is empty.

*Modifications*

- Ignore the empty field in the function configuration data when transform to json

*Verify this change*

Update the function test image to running the created test
  • Loading branch information
zymap authored and tisonkun committed Aug 16, 2023
1 parent 1d7be34 commit bbb7854
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
1 change: 1 addition & 0 deletions pulsaradmin/pkg/cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ func responseError(resp *http.Response) error {
return e
}

e.Reason = string(body)
err = json.Unmarshal(body, &e)
if err != nil {
e.Reason = string(body)
Expand Down
64 changes: 32 additions & 32 deletions pulsaradmin/pkg/pulsar/utils/function_confg.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,54 +24,54 @@ const (
)

type FunctionConfig struct {
TimeoutMs *int64 `json:"timeoutMs" yaml:"timeoutMs"`
TopicsPattern *string `json:"topicsPattern" yaml:"topicsPattern"`
TimeoutMs *int64 `json:"timeoutMs,omitempty" yaml:"timeoutMs"`
TopicsPattern *string `json:"topicsPattern,omitempty" yaml:"topicsPattern"`
// Whether the subscriptions the functions created/used should be deleted when the functions is deleted
CleanupSubscription bool `json:"cleanupSubscription" yaml:"cleanupSubscription"`
RetainOrdering bool `json:"retainOrdering" yaml:"retainOrdering"`
AutoAck bool `json:"autoAck" yaml:"autoAck"`
Parallelism int `json:"parallelism" yaml:"parallelism"`
MaxMessageRetries *int `json:"maxMessageRetries" yaml:"maxMessageRetries"`
CleanupSubscription bool `json:"cleanupSubscription,omitempty" yaml:"cleanupSubscription"`
RetainOrdering bool `json:"retainOrdering,omitempty" yaml:"retainOrdering"`
AutoAck bool `json:"autoAck,omitempty" yaml:"autoAck"`
Parallelism int `json:"parallelism,omitempty" yaml:"parallelism"`
MaxMessageRetries *int `json:"maxMessageRetries,omitempty" yaml:"maxMessageRetries"`

Output string `json:"output" yaml:"output"`
Output string `json:"output,omitempty" yaml:"output"`

OutputSerdeClassName string `json:"outputSerdeClassName" yaml:"outputSerdeClassName"`
LogTopic string `json:"logTopic" yaml:"logTopic"`
ProcessingGuarantees string `json:"processingGuarantees" yaml:"processingGuarantees"`
OutputSerdeClassName string `json:"outputSerdeClassName,omitempty" yaml:"outputSerdeClassName"`
LogTopic string `json:"logTopic,omitempty" yaml:"logTopic"`
ProcessingGuarantees string `json:"processingGuarantees,omitempty" yaml:"processingGuarantees"`

// Represents either a builtin schema type (eg: 'avro', 'json', etc) or the class name for a Schema implementation
OutputSchemaType string `json:"outputSchemaType" yaml:"outputSchemaType"`
OutputSchemaType string `json:"outputSchemaType,omitempty" yaml:"outputSchemaType"`

Runtime string `json:"runtime" yaml:"runtime"`
DeadLetterTopic string `json:"deadLetterTopic" yaml:"deadLetterTopic"`
SubName string `json:"subName" yaml:"subName"`
FQFN string `json:"fqfn" yaml:"fqfn"`
Jar *string `json:"jar" yaml:"jar"`
Py *string `json:"py" yaml:"py"`
Go *string `json:"go" yaml:"go"`
Runtime string `json:"runtime,omitempty" yaml:"runtime"`
DeadLetterTopic string `json:"deadLetterTopic,omitempty" yaml:"deadLetterTopic"`
SubName string `json:"subName,omitempty" yaml:"subName"`
FQFN string `json:"fqfn,omitempty" yaml:"fqfn"`
Jar *string `json:"jar,omitempty" yaml:"jar"`
Py *string `json:"py,omitempty" yaml:"py"`
Go *string `json:"go,omitempty" yaml:"go"`
// Any flags that you want to pass to the runtime.
// note that in thread mode, these flags will have no impact
RuntimeFlags string `json:"runtimeFlags" yaml:"runtimeFlags"`
RuntimeFlags string `json:"runtimeFlags,omitempty" yaml:"runtimeFlags"`

Tenant string `json:"tenant" yaml:"tenant"`
Namespace string `json:"namespace" yaml:"namespace"`
Name string `json:"name" yaml:"name"`
ClassName string `json:"className" yaml:"className"`
Tenant string `json:"tenant,omitempty" yaml:"tenant"`
Namespace string `json:"namespace,omitempty" yaml:"namespace"`
Name string `json:"name,omitempty" yaml:"name"`
ClassName string `json:"className,omitempty" yaml:"className"`

Resources *Resources `json:"resources" yaml:"resources"`
WindowConfig *WindowConfig `json:"windowConfig" yaml:"windowConfig"`
Inputs []string `json:"inputs" yaml:"inputs"`
UserConfig map[string]interface{} `json:"userConfig" yaml:"userConfig"`
CustomSerdeInputs map[string]string `json:"customSerdeInputs" yaml:"customSerdeInputs"`
CustomSchemaInputs map[string]string `json:"customSchemaInputs" yaml:"customSchemaInputs"`
Resources *Resources `json:"resources,omitempty" yaml:"resources"`
WindowConfig *WindowConfig `json:"windowConfig,omitempty" yaml:"windowConfig"`
Inputs []string `json:"inputs,omitempty" yaml:"inputs"`
UserConfig map[string]interface{} `json:"userConfig,omitempty" yaml:"userConfig"`
CustomSerdeInputs map[string]string `json:"customSerdeInputs,omitempty" yaml:"customSerdeInputs"`
CustomSchemaInputs map[string]string `json:"customSchemaInputs,omitempty" yaml:"customSchemaInputs"`

// A generalized way of specifying inputs
InputSpecs map[string]ConsumerConfig `json:"inputSpecs" yaml:"inputSpecs"`
InputSpecs map[string]ConsumerConfig `json:"inputSpecs,omitempty" yaml:"inputSpecs"`

// This is a map of secretName(aka how the secret is going to be
// accessed in the function via context) to an object that
// encapsulates how the secret is fetched by the underlying
// secrets provider. The type of an value here can be found by the
// SecretProviderConfigurator.getSecretObjectType() method.
Secrets map[string]interface{} `json:"secrets" yaml:"secrets"`
Secrets map[string]interface{} `json:"secrets,omitempty" yaml:"secrets"`
}

0 comments on commit bbb7854

Please sign in to comment.