Read worker directory from WorkerInitRequest (#608)

This commit is contained in:
Shreyas Gopalakrishna 2022-08-10 11:59:30 -05:00 коммит произвёл GitHub
Родитель a7fd08bca1
Коммит 210d5d5476
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 13 добавлений и 20 удалений

Просмотреть файл

@ -6,7 +6,6 @@ package com.microsoft.azure.functions.worker;
public final class Constants {
private Constants(){}
public final static String TRIGGER_METADATA_DOLLAR_REQUEST_KEY = "$request";
public final static String FUNCTIONS_WORKER_DIRECTORY = "FUNCTIONS_WORKER_DIRECTORY";
public final static String JAVA_LIBRARY_DIRECTORY = "/annotationLib";
public final static String JAVA_LIBRARY_ARTIFACT_ID = "azure-functions-java-library";
public final static String HAS_IMPLICIT_OUTPUT_QUALIFIED_NAME = "com.microsoft.azure.functions.annotation.HasImplicitOutput";

Просмотреть файл

@ -37,7 +37,7 @@ public class JavaWorkerClient implements AutoCloseable {
private void addHandlers() {
JavaFunctionBroker broker = new JavaFunctionBroker(classPathProvider);
this.handlerSuppliers.put(StreamingMessage.ContentCase.WORKER_INIT_REQUEST, WorkerInitRequestHandler::new);
this.handlerSuppliers.put(StreamingMessage.ContentCase.WORKER_INIT_REQUEST, () -> new WorkerInitRequestHandler(broker));
this.handlerSuppliers.put(StreamingMessage.ContentCase.FUNCTION_ENVIRONMENT_RELOAD_REQUEST, () -> new FunctionEnvironmentReloadRequestHandler(broker));
this.handlerSuppliers.put(StreamingMessage.ContentCase.FUNCTION_LOAD_REQUEST, () -> new FunctionLoadRequestHandler(broker));
this.handlerSuppliers.put(StreamingMessage.ContentCase.INVOCATION_REQUEST, () -> new InvocationRequestHandler(broker));

Просмотреть файл

@ -130,7 +130,7 @@ public class JavaFunctionBroker {
}
public void addJavaAnnotationLibrary() throws IOException {
String javaLibPath = System.getenv(Constants.FUNCTIONS_WORKER_DIRECTORY) + Constants.JAVA_LIBRARY_DIRECTORY;
String javaLibPath = workerDirectory + Constants.JAVA_LIBRARY_DIRECTORY;
File javaLib = new File(javaLibPath);
if (!javaLib.exists()) throw new FileNotFoundException("Error loading java annotation library jar, location doesn't exist: " + javaLibPath);
File[] files = javaLib.listFiles(file -> file.getName().contains(Constants.JAVA_LIBRARY_ARTIFACT_ID) && file.getName().endsWith(".jar"));
@ -164,6 +164,11 @@ public class JavaFunctionBroker {
}
}
public void setWorkerDirectory(String workerDirectory) {
this.workerDirectory = workerDirectory;
}
private final Map<String, ImmutablePair<String, JavaMethodExecutor>> methods;
private final ClassLoaderProvider classLoaderProvider;
private String workerDirectory;
}

Просмотреть файл

@ -81,6 +81,4 @@ public class FunctionEnvironmentReloadRequestHandler
}
private final JavaFunctionBroker broker;
public final String WebsitePlaceholderMode = "WEBSITE_PLACEHOLDER_MODE";
public final String AzureWebsiteInstanceId = "WEBSITE_INSTANCE_ID";
}

Просмотреть файл

@ -1,14 +0,0 @@
package com.microsoft.azure.functions.worker.handler;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.Native;
import com.sun.jna.win32.W32APIOptions;
// kernel32.dll uses the __stdcall calling convention (check the function
// declaration for "WINAPI" or "PASCAL"), so extend StdCallLibrary
// Most C libraries will just extend com.sun.jna.Library,
public interface PicoHelper extends StdCallLibrary {
PicoHelper INSTANCE = (PicoHelper)Native.load("picohelper", PicoHelper.class, W32APIOptions.DEFAULT_OPTIONS);
void ReinitializeDetours();
}

Просмотреть файл

@ -2,17 +2,20 @@ package com.microsoft.azure.functions.worker.handler;
import com.microsoft.azure.functions.worker.*;
import com.microsoft.azure.functions.rpc.messages.*;
import com.microsoft.azure.functions.worker.broker.JavaFunctionBroker;
public class WorkerInitRequestHandler extends MessageHandler<WorkerInitRequest, WorkerInitResponse.Builder> {
public WorkerInitRequestHandler() {
public WorkerInitRequestHandler(JavaFunctionBroker broker) {
super(StreamingMessage::getWorkerInitRequest,
WorkerInitResponse::newBuilder,
WorkerInitResponse.Builder::setResult,
StreamingMessage.Builder::setWorkerInitResponse);
this.broker = broker;
}
@Override
String execute(WorkerInitRequest request, WorkerInitResponse.Builder response) {
broker.setWorkerDirectory(request.getWorkerDirectory());
response.setWorkerVersion(Application.version());
response.putCapabilities("TypedDataCollection", "TypedDataCollection");
response.putCapabilities("WorkerStatus", "WorkerStatus");
@ -30,4 +33,6 @@ public class WorkerInitRequestHandler extends MessageHandler<WorkerInitRequest,
workerMetadataBuilder.setWorkerBitness(System.getProperty("os.arch"));
return workerMetadataBuilder;
}
private final JavaFunctionBroker broker;
}