Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
Add start cmd for Pulsar Functions (#29)
Browse files Browse the repository at this point in the history
Master Issue: #2 

Add start cmd for Pulsar Functions

```
USED FOR:
    This command is used for starting a stopped function instance.

REQUIRED PERMISSION:
    This command requires super-user permissions.

EXAMPLES:
    #Starts a stopped function instance
    pulsarctl functions start
	--tenant public
	--namespace default
	--name <the name of Pulsar Function>

    #Starts a stopped function instance with instance ID
    pulsarctl functions start
	--tenant public
	--namespace default
	--name <the name of Pulsar Function>
	--instance-id 1

    #Starts a stopped function instance with FQFN
    pulsarctl functions start
	--fqfn tenant/namespace/name [eg: public/default/ExampleFunctions]

OUTPUT:
    #normal output
    Started successfully

    #You must specify a name for the Pulsar Functions or a FQFN, please check the --name args
    [✖]  you must specify a name for the function or a Fully Qualified Function Name (FQFN)

    #The name of Pulsar Functions doesn't exist, please check the --name args
    [✖]  code: 404 reason: Function <your function name> doesn't exist

    #Used an instanceID that does not exist or other impermissible actions
    [✖]  code: 400 reason: Operation not permitted

Usage: pulsarctl functions start [flags]

Aliases: start, start

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
      --instance-id string   The function instanceId (start all instances if instance-id is not provided)
```
  • Loading branch information
wolfstudy authored and maxsxu committed Mar 14, 2023
1 parent ffcacd5 commit 8c60334
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/pulsar/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ type Functions interface {
// Stop function instance
StopFunctionWithID(tenant, namespace, name string, instanceID int) error

// Delete an existing function
DeleteFunction(tenant, namespace, name string) error

// Start all function instances
StartFunction(tenant, namespace, name string) error

// Start function instance
StartFunctionWithID(tenant, namespace, name string, instanceID int) error
}

type functions struct {
Expand Down Expand Up @@ -199,3 +206,16 @@ func (f *functions) DeleteFunction(tenant, namespace, name string) error {
endpoint := f.client.endpoint(f.basePath, tenant, namespace, name)
return f.client.delete(endpoint, nil)
}

func (f *functions) StartFunction(tenant, namespace, name string) error {
endpoint := f.client.endpoint(f.basePath, tenant, namespace, name)
return f.client.post(endpoint+"/start", "", nil)
}

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

return f.client.post(endpoint+"/start", "", nil)
}

0 comments on commit 8c60334

Please sign in to comment.