From cb2f4ee3960fc841ad42bc6e6b1209a92b88d5d9 Mon Sep 17 00:00:00 2001 From: Rajan Dhabalia Date: Mon, 13 Aug 2018 14:40:18 -0700 Subject: [PATCH] add function package-url into function-get api response (#2354) ### Motivation Right now, we mostly use function by submitting function with url and many times, we want to verify function package-url to confirm the package-version. So, function-admin api should return packageurl along with function metadata. ### Modifications return function pacakge-url along with function-metadata on get-function api call. --- .../proto/src/main/proto/Function.proto | 1 + .../functions/worker/rest/api/FunctionsImpl.java | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pulsar-functions/proto/src/main/proto/Function.proto b/pulsar-functions/proto/src/main/proto/Function.proto index 92f14f6f197e2..77a9c2c0b6047 100644 --- a/pulsar-functions/proto/src/main/proto/Function.proto +++ b/pulsar-functions/proto/src/main/proto/Function.proto @@ -58,6 +58,7 @@ message FunctionDetails { SourceSpec source = 11; SinkSpec sink = 12; Resources resources = 13; + string packageUrl = 14; //present only if function submitted with package-url } message SourceSpec { diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java index b71e6cd3270a5..4bb6e49cc499b 100644 --- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java +++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java @@ -733,9 +733,8 @@ private FunctionDetails validateUpdateRequestParamsWithPkgUrl(String tenant, Str throw new IllegalArgumentException("Function Package url is not valid. supported url (http/https/file)"); } Utils.validateFileUrl(functionPkgUrl, workerServiceSupplier.get().getWorkerConfig().getDownloadDirectory()); - File jarWithFileUrl = functionPkgUrl.startsWith(FILE) ? (new File((new URL(functionPkgUrl)).toURI())) : null; FunctionDetails functionDetails = validateUpdateRequestParams(tenant, namespace, functionName, - functionDetailsJson, jarWithFileUrl); + functionDetailsJson, functionPkgUrl); return functionDetails; } @@ -789,7 +788,7 @@ private String getFunctionCodeBuiltin(FunctionDetails functionDetails) { } private FunctionDetails validateUpdateRequestParams(String tenant, String namespace, String functionName, - String functionDetailsJson, File jarWithFileUrl) throws IllegalArgumentException { + String functionDetailsJson, String functionPkgUrl) throws IllegalArgumentException { if (tenant == null) { throw new IllegalArgumentException("Tenant is not provided"); } @@ -806,7 +805,14 @@ private FunctionDetails validateUpdateRequestParams(String tenant, String namesp try { FunctionDetails.Builder functionDetailsBuilder = FunctionDetails.newBuilder(); org.apache.pulsar.functions.utils.Utils.mergeJson(functionDetailsJson, functionDetailsBuilder); - validateFunctionClassTypes(jarWithFileUrl, functionDetailsBuilder); + if (isNotBlank(functionPkgUrl)) { + // validate function details by loading function-jar from local file-system + File jarWithFileUrl = functionPkgUrl.startsWith(FILE) ? (new File((new URL(functionPkgUrl)).toURI())) + : null; + validateFunctionClassTypes(jarWithFileUrl, functionDetailsBuilder); + // set package-url if present + functionDetailsBuilder.setPackageUrl(functionPkgUrl); + } FunctionDetails functionDetails = functionDetailsBuilder.build(); List missingFields = new LinkedList<>();