From 8c60334218edb28681d1ea93989d74beb6ad1fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=89=E5=B0=8F=E9=BE=99?= Date: Wed, 4 Sep 2019 14:13:07 +0800 Subject: [PATCH] Add start cmd for Pulsar Functions (#29) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 #Starts a stopped function instance with instance ID pulsarctl functions start --tenant public --namespace default --name --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 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) ``` --- pkg/pulsar/functions.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/pulsar/functions.go b/pkg/pulsar/functions.go index a2d5555..71815ca 100644 --- a/pkg/pulsar/functions.go +++ b/pkg/pulsar/functions.go @@ -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 { @@ -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) +} +