Skip to content

Commit

Permalink
Fix: Bug when function package jar/py/go and runtime is not set (apac…
Browse files Browse the repository at this point in the history
…he#4814)

### Modifications

When submitting a function via REST interface, if user doesn't provide the function package or function runtime as part of function config, the function will get submitted and deployed to run but the typeClassName for the source will not be set causing a weird error in the function instance code
  • Loading branch information
jerrypeng authored and sijie committed Jul 26, 2019
1 parent 19b883b commit e1547e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,11 @@ public static ClassLoader validate(FunctionConfig functionConfig, File functionP
} else if (functionConfig.getRuntime() == FunctionConfig.Runtime.GO) {
doGolangChecks(functionConfig);
return null;
} else {
} else if (functionConfig.getRuntime() == FunctionConfig.Runtime.PYTHON){
doPythonChecks(functionConfig);
return null;
} else {
throw new IllegalArgumentException("Function language runtime is either not set or cannot be determined");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,31 @@ public void testRegisterFunctionWithConflictingFields() {
resource.registerFunction(actualTenant, actualNamespace, actualName, null, null, filePackageUrl, functionConfig, null, null);
}

@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Function language runtime is either not set or cannot be determined")
public void testCreateFunctionWithoutSettingRuntime() {
Configurator.setRootLevel(Level.DEBUG);

String fileLocation = FutureUtil.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String filePackageUrl = "file://" + fileLocation;
when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(false);

RequestResult rr = new RequestResult().setSuccess(true).setMessage("function registered");
CompletableFuture<RequestResult> requestResult = CompletableFuture.completedFuture(rr);
when(mockedManager.updateFunction(any(FunctionMetaData.class))).thenReturn(requestResult);

FunctionConfig functionConfig = new FunctionConfig();
functionConfig.setTenant(tenant);
functionConfig.setNamespace(namespace);
functionConfig.setName(function);
functionConfig.setClassName(className);
functionConfig.setParallelism(parallelism);
functionConfig.setCustomSerdeInputs(topicsToSerDeClassName);
functionConfig.setOutput(outputTopic);
functionConfig.setOutputSerdeClassName(outputSerdeClassName);
resource.registerFunction(tenant, namespace, function, null, null, filePackageUrl, functionConfig, null, null);

}

public static FunctionConfig createDefaultFunctionConfig() {
FunctionConfig functionConfig = new FunctionConfig();
functionConfig.setTenant(tenant);
Expand Down

0 comments on commit e1547e1

Please sign in to comment.