microsoft / durabletask-java

Java SDK for Durable Functions and the Durable Task Framework
MIT License
13 stars 7 forks source link

Unable to create instance of interface com.microsoft.durabletask.TaskOrchestrationContext #117

Closed tiurikov closed 1 year ago

tiurikov commented 1 year ago

Hi there!

I'm trying to run a simple Azure Durable Function as described here: https://learn.microsoft.com/en-us/azure/azure-functions/durable/quickstart-java?tabs=bash&pivots=create-option-manual-setup#create-your-functions

I use the following command: mvn clean package azure-functions:run

but got an error after trying to call the HTTP URL http://localhost:7071/api/StartOrchestration for the function:

[2023-02-28T11:59:36.209Z] Worker process started and initialized.
[2023-02-28T11:59:37.851Z] Executing 'Functions.StartOrchestration' (Reason='This function was programmatically called via the host APIs.', Id=09e54993-3475-49e3-852a-38cd2ff08368)
[2023-02-28T11:59:37.977Z] Java HTTP trigger processed a request.
[2023-02-28T11:59:38.516Z] Created new Java orchestration with instance ID = 42d096f5-3b4b-462d-be86-7febcc8fc813
[2023-02-28T11:59:38.528Z] Function "StartOrchestration" (Id: 09e54993-3475-49e3-852a-38cd2ff08368) invoked by Java Worker
[2023-02-28T11:59:38.617Z] Executed 'Functions.StartOrchestration' (Succeeded, Id=09e54993-3475-49e3-852a-38cd2ff08368, Duration=785ms)
[2023-02-28T11:59:40.559Z] Host lock lease acquired by instance ID '000000000000000000000000B20A9825'.
[2023-02-28T11:59:42.457Z] Executing 'Functions.Cities' (Reason='(null)', Id=31ff29e0-9add-4672-880a-1fda6bd961b1)
[2023-02-28T11:59:42.485Z] Executed 'Functions.Cities' (Failed, Id=31ff29e0-9add-4672-880a-1fda6bd961b1, Duration=50ms)
[2023-02-28T11:59:42.485Z] System.Private.CoreLib: Exception while executing function: Functions.Cities. System.Private.CoreLib: Result: Failure
[2023-02-28T11:59:42.485Z] Exception: UnsupportedOperationException: Interface can't be instantiated! Interface name: com.microsoft.durabletask.TaskOrchestrationContext
[2023-02-28T11:59:42.485Z] Stack: java.lang.RuntimeException: Unable to create instance of interface com.microsoft.durabletask.TaskOrchestrationContext. Registering an InstanceCreator or a TypeAdapter for this type, or adding a no-args constructor may fix this problem.
[2023-02-28T11:59:42.485Z]      at com.google.gson.internal.ConstructorConstructor$16.construct(ConstructorConstructor.java:275)
[2023-02-28T11:59:42.485Z]      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:211)
[2023-02-28T11:59:42.485Z]      at com.google.gson.Gson.fromJson(Gson.java:991)
[2023-02-28T11:59:42.485Z]      at com.google.gson.Gson.fromJson(Gson.java:956)
[2023-02-28T11:59:42.485Z]      at com.google.gson.Gson.fromJson(Gson.java:905)
[2023-02-28T11:59:42.485Z]      at com.microsoft.azure.functions.worker.binding.DataOperations.convertFromJson(DataOperations.java:158)
[2023-02-28T11:59:42.485Z]      at com.microsoft.azure.functions.worker.binding.DataOperations.apply(DataOperations.java:114)
[2023-02-28T11:59:42.485Z]      at com.microsoft.azure.functions.worker.binding.DataSource.computeByType(DataSource.java:56)
[2023-02-28T11:59:42.485Z]      at com.microsoft.azure.functions.worker.binding.RpcStringDataSource.computeByType(RpcStringDataSource.java:5)
[2023-02-28T11:59:42.485Z]      at com.microsoft.azure.functions.worker.binding.DataSource.computeByName(DataSource.java:42)
[2023-02-28T11:59:42.486Z]      at com.microsoft.azure.functions.worker.binding.RpcStringDataSource.computeByName(RpcStringDataSource.java:5)
[2023-02-28T11:59:42.486Z]      at com.microsoft.azure.functions.worker.binding.BindingDataStore.getDataByName(BindingDataStore.java:62)
[2023-02-28T11:59:42.486Z]      at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolve(ParameterResolver.java:59)
[2023-02-28T11:59:42.486Z]      at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolve(ParameterResolver.java:42)
[2023-02-28T11:59:42.486Z]      at com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.execute(EnhancedJavaMethodExecutorImpl.java:53)
[2023-02-28T11:59:42.486Z]      at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:61)
[2023-02-28T11:59:42.486Z]      at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:37)
[2023-02-28T11:59:42.486Z]      at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:12)
[2023-02-28T11:59:42.486Z]      at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:44)
[2023-02-28T11:59:42.486Z]      at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:93)
[2023-02-28T11:59:42.486Z]      at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[2023-02-28T11:59:42.486Z]      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[2023-02-28T11:59:42.486Z]      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[2023-02-28T11:59:42.487Z]      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[2023-02-28T11:59:42.487Z]      at java.base/java.lang.Thread.run(Thread.java:829)
[2023-02-28T11:59:42.487Z] Caused by: java.lang.UnsupportedOperationException: Interface can't be instantiated! Interface name: com.microsoft.durabletask.TaskOrchestrationContext
[2023-02-28T11:59:42.487Z]      at com.google.gson.internal.UnsafeAllocator.assertInstantiable(UnsafeAllocator.java:118)
[2023-02-28T11:59:42.487Z]      at com.google.gson.internal.UnsafeAllocator$1.newInstance(UnsafeAllocator.java:49)
[2023-02-28T11:59:42.487Z]      at com.google.gson.internal.ConstructorConstructor$16.construct(ConstructorConstructor.java:272)
[2023-02-28T11:59:42.487Z]      ... 24 more
[2023-02-28T11:59:42.487Z] .
[2023-02-28T11:59:42.491Z] 42d096f5-3b4b-462d-be86-7febcc8fc813: Function 'Cities (Orchestrator)' failed with an error. Reason: Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.Cities
[2023-02-28T11:59:42.491Z]  ---> Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException: Result: Failure
[2023-02-28T11:59:42.491Z] Exception: UnsupportedOperationException: Interface can't be instantiated! Interface name: com.microsoft.durabletask.TaskOrchestrationContext
[2023-02-28T11:59:42.491Z] Stack: java.lang.RuntimeException: Unable to create instance of interface com.microsoft.durabletask.TaskOrchestrationContext. Registering an InstanceCreator or a TypeAdapter for this type, or adding a no-args constructor may fix this problem.
[2023-02-28T11:59:42.491Z]      at com.google.gson.internal.ConstructorConstructor$16.construct(ConstructorConstructor.java:275)
[2023-02-28T11:59:42.492Z]      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:211)
[2023-02-28T11:59:42.492Z]      at com.google.gson.Gson.fromJson(Gson.java:991)
[2023-02-28T11:59:42.492Z]      at com.google.gson.Gson.fromJson(Gson.java:956)
[2023-02-28T11:59:42.492Z]      at com.google.gson.Gson.fromJson(Gson.java:905)
[2023-02-28T11:59:42.492Z]      at com.microsoft.azure.functions.worker.binding.DataOperations.convertFromJson(DataOperations.java:158)
[2023-02-28T11:59:42.492Z]      at com.microsoft.azure.functions.worker.binding.DataOperations.apply(DataOperations.java:114)
[2023-02-28T11:59:42.492Z]      at com.microsoft.azure.functions.worker.binding.DataSource.computeByType(DataSource.java:56)
[2023-02-28T11:59:42.492Z]      at com.microsoft.azure.functions.worker.binding.RpcStringDataSource.computeByType(RpcStringDataSource.java:5)
[2023-02-28T11:59:42.492Z]      at com.microsoft.azure.functions.worker.binding.DataSource.computeByName(DataSource.java:42)
[2023-02-28T11:59:42.492Z]      at com.microsoft.azure.functions.worker.binding.RpcStringDataSource.computeByName(RpcStringDataSource.java:5)
[2023-02-28T11:59:42.492Z]      at com.microsoft.azure.functions.worker.binding.BindingDataStore.getDataByName(BindingDataStore.java:62)
[2023-02-28T11:59:42.492Z]      at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolve(ParameterResolver.java:59)
[2023-02-28T11:59:42.492Z]      at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolve(ParameterResolver.java:42)
[2023-02-28T11:59:42.492Z]      at com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.execute(EnhancedJavaMethodExecutorImpl.java:53)
[2023-02-28T11:59:42.492Z]      at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:61)
[2023-02-28T11:59:42.492Z]      at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:37)
[2023-02-28T11:59:42.492Z]      at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:12)
[2023-02-28T11:59:42.492Z]      at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:44)
[2023-02-28T11:59:42.492Z]      at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:93)
[2023-02-28T11:59:42.493Z]      at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[2023-02-28T11:59:42.493Z]      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[2023-02-28T11:59:42.493Z]      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[2023-02-28T11:59:42.493Z]      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[2023-02-28T11:59:42.493Z]      at java.base/java.lang.Thread.run(Thread.java:829)
[2023-02-28T11:59:42.493Z] Caused by: java.lang.UnsupportedOperationException: Interface can't be instantiated! Interface name: com.microsoft.durabletask.TaskOrchestrationContext
[2023-02-28T11:59:42.493Z]      at com.google.gson.internal.UnsafeAllocator.assertInstantiable(UnsafeAllocator.java:118)
[2023-02-28T11:59:42.493Z]      at com.google.gson.internal.UnsafeAllocator$1.newInstance(UnsafeAllocator.java:49)
[2023-02-28T11:59:42.493Z]      at com.google.gson.internal.ConstructorConstructor$16.construct(ConstructorConstructor.java:272)
[2023-02-28T11:59:42.493Z]      ... 24 more
[2023-02-28T11:59:42.493Z] 
[2023-02-28T11:59:42.493Z]    at Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.InvokeCore(Object[] parameters, FunctionInvocationContext context) in /_/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs:line 96
[2023-02-28T11:59:42.493Z]    at Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) in /_/src/WebJobs.Script/Description/FunctionInvokerBase.cs:line 82
[2023-02-28T11:59:42.493Z]    at Microsoft.Azure.WebJobs.Script.Description.FunctionGenerator.Coerce[T](Task`1 src) in /_/src/WebJobs.Script/Description/FunctionGenerator.cs:line 225
[2023-02-28T11:59:42.493Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 52
[2023-02-28T11:59:42.493Z]    at Microsoft.Azure.WebJobs.Extensions.DurableTask.OutOfProcMiddleware.<>c__DisplayClass10_0.<<CallOrchestratorAsync>b__0>d.MoveNext() in D:\a\_work\1\s\src\WebJobs.Extensions.DurableTask\OutOfProcMiddleware.cs:line 124
[2023-02-28T11:59:42.493Z] --- End of stack trace from previous location ---
[2023-02-28T11:59:42.493Z]    at Microsoft.Azure.WebJobs.Host.Executors.TriggeredFunctionExecutor`1.<>c__DisplayClass7_0.<<TryExecuteAsync>b__0>d.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\TriggeredFunctionExecutor.cs:line 50
[2023-02-28T11:59:42.493Z] --- End of stack trace from previous location ---
[2023-02-28T11:59:42.493Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeWithTimeoutAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Boolean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 581
[2023-02-28T11:59:42.494Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 527
[2023-02-28T11:59:42.494Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 306
[2023-02-28T11:59:42.494Z]    --- End of inner exception stack trace ---
[2023-02-28T11:59:42.494Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 352
[2023-02-28T11:59:42.494Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 108. IsReplay: False. State: Failed. HubName: JavaTestHub. AppName: . SlotName: . ExtensionVersion: 2.8.1. SequenceNumber: 4. TaskEventId: -1

Looks like a TaskOrchestrationContext instance is needed but the Gson doesn't know how to instantiate it and asking for InstanceCreator or a TypeAdapter. Any idea how to fix it?

I'm using Java 11, com.microsoft.azure.functions:azure-functions-java-library:3.0.0, com.microsoft:durabletask-azure-functions:1.0.1

Best regards, Stan

kbeaugrand commented 1 year ago

I have the same issue. @tiurikov did you have found a work around ?

kbeaugrand commented 1 year ago

@tiurikov found something:

Durable Functions for Java requires Azure Functions Core Tools v4.0.4915 or newer. You can see which version is installed by running the func --version command from the terminal.

I had an older version of the core tools. After upgrading, I had some other errors, but it seems that it's in my hands...

cgillum commented 1 year ago

@tiurikov did you get a chance to try updating your Core Tools version? I expect that's the root of the problem.

ChrisRomp commented 1 year ago

Working in Ubuntu (Bullseye), installing from apt the most current version is 4.0.4895.

~ $ func --version
4.0.4895

~ $ sudo apt install azure-functions-core-tools-4
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
azure-functions-core-tools-4 is already the newest version (4.0.4895-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Edit: Same for Focal (20.04).

ChrisRomp commented 1 year ago

Installing via NPM installs the most current release. I don't encounter the interface creation error anymore (though I need to fix my VS Code build/debug tasks).

ChrisRomp commented 1 year ago

Looks like the package release issue is resolved and I'm seeing 4.0.5095 from apt now. 🎉

cgillum commented 1 year ago

Glad to hear this was resolved! I'll go ahead and close this issue now.