Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve][admin] Allow creating builtin functions in pulsar-admin CLI #15671

Merged
merged 1 commit into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class CmdFunctionsTest {
private static final String PACKAGE_GO_URL = "function://sample/ns1/godummyexamples@1";
private static final String PACKAGE_PY_URL = "function://sample/ns1/pydummyexamples@1";
private static final String PACKAGE_INVALID_URL = "functionsample.jar";
private static final String BUILTIN_NAR = "builtin://dummyexamples";

private PulsarAdmin admin;
private Functions functions;
Expand Down Expand Up @@ -424,6 +425,27 @@ public void testCreateFunctionWithInvalidPackageUrl() throws Exception {
verify(functions, times(0)).createFunctionWithUrl(any(FunctionConfig.class), anyString());
}

@Test
public void testCreateFunctionWithBuiltinNar() throws Exception {
cmd.run(new String[] {
"create",
"--name", FN_NAME,
"--inputs", INPUT_TOPIC_NAME,
"--output", OUTPUT_TOPIC_NAME,
"--jar", BUILTIN_NAR,
"--tenant", "sample",
"--namespace", "ns1",
"--className", DummyFunction.class.getName(),
});

CreateFunction creater = cmd.getCreater();

assertEquals(FN_NAME, creater.getFunctionName());
assertEquals(INPUT_TOPIC_NAME, creater.getInputs());
assertEquals(OUTPUT_TOPIC_NAME, creater.getOutput());
verify(functions, times(1)).createFunction(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 @@ -671,7 +671,8 @@ && isBlank(functionConfig.getGo())) {
+ " be specified for the function. Please specify one.");
}

if (!isBlank(functionConfig.getJar()) && !Utils.isFunctionPackageUrlSupported(functionConfig.getJar())
if (!isBlank(functionConfig.getJar()) && !functionConfig.getJar().startsWith("builtin://")
&& !Utils.isFunctionPackageUrlSupported(functionConfig.getJar())
&& !new File(functionConfig.getJar()).exists()) {
throw new ParameterException("The specified jar file does not exist");
}
Expand Down