Skip to content

Commit c05d208

Browse files
sbourkeostkStephen Bourkelhotarinodece
committed
[fix][fn] Fix functions update issue where artifact is provided as a http url (#25840)
Co-authored-by: Stephen Bourke <sbourke@beyond.com> Co-authored-by: Lari Hotari <lhotari@users.noreply.github.com> Co-authored-by: Zixuan Liu <nodeces@gmail.com> (cherry picked from commit 235a7a8)
1 parent 3726698 commit c05d208

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,7 @@ protected File getPackageFile(FunctionDetails.ComponentType componentType, Strin
17761776
if (isNotBlank(functionPkgUrl)) {
17771777
componentPackageFile = getPackageFile(componentType, functionPkgUrl);
17781778
} else if (existingPackagePath.startsWith(Utils.FILE) || existingPackagePath.startsWith(Utils.HTTP)) {
1779-
if (!worker().getPackageUrlValidator().isValidPackageUrl(componentType, functionPkgUrl)) {
1779+
if (!worker().getPackageUrlValidator().isValidPackageUrl(componentType, existingPackagePath)) {
17801780
throw new IllegalArgumentException("Function Package url is not valid."
17811781
+ "supported url (http/https/file)");
17821782
}
@@ -1785,7 +1785,7 @@ protected File getPackageFile(FunctionDetails.ComponentType componentType, Strin
17851785
} catch (Exception e) {
17861786
throw new IllegalArgumentException(String.format("Encountered error \"%s\" "
17871787
+ "when getting %s package from %s", e.getMessage(),
1788-
ComponentTypeUtils.toString(componentType), functionPkgUrl));
1788+
ComponentTypeUtils.toString(componentType), existingPackagePath));
17891789
}
17901790
} else if (Utils.hasPackageTypePrefix(existingPackagePath)) {
17911791
componentPackageFile = getPackageFile(componentType, existingPackagePath);

pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/AbstractFunctionApiResourceTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,45 @@ public void testUpdateFunctionWithUrl() throws IOException {
10281028

10291029
}
10301030

1031+
@Test
1032+
public void testUpdateFunctionWithExistingFileUrl() throws IOException {
1033+
1034+
String fileLocation = FutureUtil.class.getProtectionDomain().getCodeSource().getLocation().getPath();
1035+
String filePackageUrl = "file://" + fileLocation;
1036+
1037+
FunctionConfig functionConfig = new FunctionConfig();
1038+
functionConfig.setOutput(OUTPUT_TOPIC);
1039+
functionConfig.setOutputSerdeClassName(OUTPUT_SERDE_CLASS_NAME);
1040+
functionConfig.setTenant(TENANT);
1041+
functionConfig.setNamespace(NAMESPACE);
1042+
functionConfig.setName(FUNCTION);
1043+
functionConfig.setClassName(CLASS_NAME);
1044+
// increment parallelism to avoid 'Update contains no change' exception
1045+
functionConfig.setParallelism(PARALLELISM + 1);
1046+
functionConfig.setRuntime(FunctionConfig.Runtime.JAVA);
1047+
functionConfig.setCustomSerdeInputs(TOPICS_TO_SER_DE_CLASS_NAME);
1048+
1049+
FunctionMetaData existingMetaData = FunctionMetaData.newBuilder()
1050+
.setFunctionDetails(createDefaultFunctionDetails())
1051+
.setPackageLocation(org.apache.pulsar.functions.proto.Function.PackageLocationMetaData.newBuilder()
1052+
.setPackagePath(filePackageUrl)
1053+
.build())
1054+
.build();
1055+
1056+
when(mockedManager.containsFunction(eq(TENANT), eq(NAMESPACE), eq(FUNCTION))).thenReturn(true);
1057+
when(mockedManager.getFunctionMetaData(any(), any(), any())).thenReturn(existingMetaData);
1058+
1059+
updateFunction(
1060+
TENANT,
1061+
NAMESPACE,
1062+
FUNCTION,
1063+
null,
1064+
null,
1065+
null,
1066+
functionConfig,
1067+
null, null);
1068+
}
1069+
10311070
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "function failed to register")
10321071
public void testUpdateFunctionFailure() throws Exception {
10331072
try {

0 commit comments

Comments
 (0)