Skip to content

Commit

Permalink
Add delete cmd for Pulsar Functions (streamnative/pulsar-admin-go#26)
Browse files Browse the repository at this point in the history
Signed-off-by: xiaolong.ran <[email protected]>

Master Issue: streamnative/pulsar-admin-go#2 

Add delete cmd for Pulsar Functions, the output as follows:

```
USED FOR:
    This command is used for delete a Pulsar Function that is running on a Pulsar cluster.

REQUIRED PERMISSION:
    This command requires super-user permissions.

EXAMPLES:
    #Delete a Pulsar Function that is running on a Pulsar cluster
    pulsarctl functions create
	--tenant public
	--namespace default
	--name <the name of Pulsar Functions>

    #Delete a Pulsar Function that is running on a Pulsar cluster with instance ID
    pulsarctl functions create
	--tenant public
	--namespace default
	--name <the name of Pulsar Functions>
	--instance-id 1

    #Delete a Pulsar Function that is running on a Pulsar cluster with FQFN
    pulsarctl functions delete
	--fqfn tenant/namespace/name [eg: public/default/ExampleFunctions]

OUTPUT:
    #normal output
    Deleted successfully

Usage: pulsarctl functions delete [flags]

Aliases: delete, delete

FunctionsConfig flags:
      --fqfn string        The Fully Qualified Function Name (FQFN) for the function
      --tenant string      The tenant of a Pulsar Function
      --namespace string   The namespace of a Pulsar Function
      --name string        The name of a Pulsar Function
```
  • Loading branch information
wolfstudy authored and tisonkun committed Aug 15, 2023
1 parent 698ead4 commit a9d69f8
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions pulsaradmin/pkg/pulsar/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type Functions interface {

// Stop function instance
StopFunctionWithID(tenant, namespace, name string, instanceID int) error

DeleteFunction(tenant, namespace, name string) error
}

type functions struct {
Expand Down Expand Up @@ -183,21 +185,17 @@ func (f *functions) CreateFuncWithUrl(funcConf *FunctionConfig, pkgUrl string) e

func (f *functions) StopFunction(tenant, namespace, name string) error {
endpoint := f.client.endpoint(f.basePath, tenant, namespace, name)
err := f.client.post(endpoint+"/stop", "", nil)
if err != nil {
return err
}
return nil
return f.client.post(endpoint+"/stop", "", nil)
}

func (f *functions) StopFunctionWithID(tenant, namespace, name string, instanceID int) error {
id := fmt.Sprintf("%d", instanceID)
endpoint := f.client.endpoint(f.basePath, tenant, namespace, name, id)

err := f.client.post(endpoint+"/stop", "", nil)
if err != nil {
return err
}
return f.client.post(endpoint+"/stop", "", nil)
}

return nil
func (f *functions) DeleteFunction(tenant, namespace, name string) error {
endpoint := f.client.endpoint(f.basePath, tenant, namespace, name)
return f.client.delete(endpoint, nil)
}

0 comments on commit a9d69f8

Please sign in to comment.