Skip to content

Commit

Permalink
[Pulsar Functions] Support URL fetching for Go && Python functions (a…
Browse files Browse the repository at this point in the history
…pache#8808)

Signed-off-by: xiaolong.ran <[email protected]>

Master Issue: apache#8795 

### Motivation

Support URL fetching for Go and Python functions.

### Modifications

- Support URL fetching for Go and Python functions 
- Add test case for creating go function with URL
- Add test case for creating python function with URL
  • Loading branch information
wolfstudy authored Dec 7, 2020
1 parent 05c9156 commit 81d9c2d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ public IObjectFactory getObjectFactory() {

private static final String TEST_NAME = "test_name";
private static final String JAR_NAME = CmdFunctionsTest.class.getClassLoader().getResource("dummyexamples.jar").getFile();
private static final String GO_EXEC_FILE_NAME = "test-go-function-with-url";
private static final String PYTHON_FILE_NAME = "test-go-function-with-url";
private static final String URL ="file:" + JAR_NAME;
private static final String URL_WITH_GO ="file:" + GO_EXEC_FILE_NAME;
private static final String URL_WITH_PY ="file:" + PYTHON_FILE_NAME;
private static final String FN_NAME = TEST_NAME + "-function";
private static final String INPUT_TOPIC_NAME = TEST_NAME + "-input-topic";
private static final String OUTPUT_TOPIC_NAME = TEST_NAME + "-output-topic";
Expand Down Expand Up @@ -318,6 +322,47 @@ public void testCreateFunctionWithFileUrl() throws Exception {
verify(functions, times(1)).createFunctionWithUrl(any(FunctionConfig.class), anyString());
}

@Test
public void testCreateGoFunctionWithFileUrl() throws Exception {
cmd.run(new String[] {
"create",
"--name", "test-go-function",
"--inputs", INPUT_TOPIC_NAME,
"--output", OUTPUT_TOPIC_NAME,
"--go", URL_WITH_GO,
"--tenant", "sample",
"--namespace", "ns1",
});

CreateFunction creater = cmd.getCreater();

assertEquals("test-go-function", creater.getFunctionName());
assertEquals(INPUT_TOPIC_NAME, creater.getInputs());
assertEquals(OUTPUT_TOPIC_NAME, creater.getOutput());
verify(functions, times(1)).createFunctionWithUrl(any(FunctionConfig.class), anyString());
}

@Test
public void testCreatePyFunctionWithFileUrl() throws Exception {
cmd.run(new String[] {
"create",
"--name", "test-py-function",
"--inputs", INPUT_TOPIC_NAME,
"--output", OUTPUT_TOPIC_NAME,
"--py", URL_WITH_PY,
"--tenant", "sample",
"--namespace", "ns1",
"--className", "process_python_function",
});

CreateFunction creater = cmd.getCreater();

assertEquals("test-py-function", creater.getFunctionName());
assertEquals(INPUT_TOPIC_NAME, creater.getInputs());
assertEquals(OUTPUT_TOPIC_NAME, creater.getOutput());
verify(functions, times(1)).createFunctionWithUrl(any(FunctionConfig.class), anyString());
}

@Test
public void testCreateFunctionWithoutBasicArguments() throws Exception {
cmd.run(new String[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,10 @@ class CreateFunction extends FunctionDetailsCommand {
void runCmd() throws Exception {
if (Utils.isFunctionPackageUrlSupported(functionConfig.getJar())) {
admin.functions().createFunctionWithUrl(functionConfig, functionConfig.getJar());
} else if (Utils.isFunctionPackageUrlSupported(functionConfig.getPy())) {
admin.functions().createFunctionWithUrl(functionConfig, functionConfig.getPy());
} else if (Utils.isFunctionPackageUrlSupported(functionConfig.getGo())) {
admin.functions().createFunctionWithUrl(functionConfig, functionConfig.getGo());
} else {
admin.functions().createFunction(functionConfig, userCodeFile);
}
Expand Down

0 comments on commit 81d9c2d

Please sign in to comment.