Skip to content

Commit

Permalink
Completecli (apache#43)
Browse files Browse the repository at this point in the history
* Create pulsar-functions module (#1)

* Create pulsar-functions module

* rename `sdk` package to `api`

* Added the first cut of the Java interface for Pulsar functions (#2)

* Adhere to rest semantics

* Complete the list of functions supported by cli
  • Loading branch information
srkukarni authored and sijie committed Mar 4, 2018
1 parent 27f4c0b commit 5077d71
Showing 1 changed file with 76 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
@Parameters(commandDescription = "Operations about functions")
public class CmdFunctions extends CmdBase {
private LocalRunner localRunner;
private SubmitFunction submitter;
private CreateFunction creater;
private DeleteFunction deleter;
private UpdateFunction updater;
private GetFunction getter;
private ListFunctions lister;
@Getter
abstract class FunctionsCommand extends CliCommand {
@Parameter(names = "--name", description = "Function Name\n")
Expand Down Expand Up @@ -115,21 +119,65 @@ void run_functions_cmd() throws Exception {
}
}

@Parameters(commandDescription = "Submit function")
class SubmitFunction extends FunctionsCommand {
@Parameters(commandDescription = "Create function")
class CreateFunction extends FunctionsCommand {
@Override
void run_functions_cmd() throws Exception {
PulsarFunctionsAdmin a = (PulsarFunctionsAdmin)admin;
a.functions().createFunction(functionConfig, Files.readAllBytes(Paths.get(jarFile)));
}
}

@Parameters(commandDescription = "Get function")
class GetFunction extends FunctionsCommand {
@Override
void run_functions_cmd() throws Exception {
PulsarFunctionsAdmin a = (PulsarFunctionsAdmin)admin;
a.functions().getFunction(functionConfig.getTenant(), functionConfig.getNameSpace(), functionConfig.getName());
}
}

@Parameters(commandDescription = "Delete function")
class DeleteFunction extends FunctionsCommand {
@Override
void run_functions_cmd() throws Exception {
PulsarFunctionsAdmin a = (PulsarFunctionsAdmin)admin;
a.functions().deleteFunction(functionConfig.getTenant(), functionConfig.getNameSpace(), functionConfig.getName());
}
}

@Parameters(commandDescription = "Update function")
class UpdateFunction extends FunctionsCommand {
@Override
void run_functions_cmd() throws Exception {
PulsarFunctionsAdmin a = (PulsarFunctionsAdmin)admin;
a.functions().updateFunction(functionConfig, Files.readAllBytes(Paths.get(jarFile)));
}
}

@Parameters(commandDescription = "List function")
class ListFunctions extends FunctionsCommand {
@Override
void run_functions_cmd() throws Exception {
PulsarFunctionsAdmin a = (PulsarFunctionsAdmin)admin;
a.functions().getFunctions(functionConfig.getTenant(), functionConfig.getNameSpace());
}
}

public CmdFunctions(PulsarAdmin admin) {
super("functions", admin);
localRunner = new LocalRunner();
submitter = new SubmitFunction();
jcommander.addCommand("localrun", localRunner);
jcommander.addCommand("submit", submitter);
creater = new CreateFunction();
deleter = new DeleteFunction();
updater = new UpdateFunction();
getter = new GetFunction();
lister = new ListFunctions();
jcommander.addCommand("localrun", getLocalRunner());
jcommander.addCommand("create", getCreater());
jcommander.addCommand("delete", getDeleter());
jcommander.addCommand("update", getUpdater());
jcommander.addCommand("get", getGetter());
jcommander.addCommand("list", getLister());
}

@VisibleForTesting
Expand All @@ -138,7 +186,27 @@ LocalRunner getLocalRunner() {
}

@VisibleForTesting
SubmitFunction getSubmitter() {
return submitter;
CreateFunction getCreater() {
return creater;
}

@VisibleForTesting
DeleteFunction getDeleter() {
return deleter;
}

@VisibleForTesting
UpdateFunction getUpdater() {
return updater;
}

@VisibleForTesting
GetFunction getGetter() {
return getter;
}

@VisibleForTesting
ListFunctions getLister() {
return lister;
}
}

0 comments on commit 5077d71

Please sign in to comment.