简体   繁体   English

通过 Java API 创建 Google Cloud Function:“io.grpc.StatusRuntimeException: INVALID_ARGUMENT”

[英]Creating Google Cloud Function via Java API: “io.grpc.StatusRuntimeException: INVALID_ARGUMENT”

I am trying to create a Google Cloud Function using the Java Client API with this client:我正在尝试使用 Java 客户端 API 与此客户端创建 Google Cloud Function:

Credentials myCredentials = ServiceAccountCredentials.fromStream(new FileInputStream(keyFile));
CloudFunctionsServiceSettings settings = CloudFunctionsServiceSettings.newBuilder()
        .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)).build();
client = CloudFunctionsServiceClient.create(settings);


String project = "my-project-name";
String location = "us-central1";

LocationName locationName = LocationName.of( project, location );
CloudFunction function = CloudFunction.newBuilder().build();
CloudFunction response = client.createFunctionAsync(locationName, function).get();

I tried different invocations but I'am getting always the following stack trace:我尝试了不同的调用,但我总是得到以下堆栈跟踪:

java.util.concurrent.ExecutionException: com.google.api.gax.rpc.InvalidArgumentException: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: The request has errors
        at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:566)
        at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:547)
        at com.google.common.util.concurrent.FluentFuture$TrustedFuture.get(FluentFuture.java:86)
        at com.google.common.util.concurrent.ForwardingFuture.get(ForwardingFuture.java:62)
        at com.google.api.gax.longrunning.OperationFutureImpl.get(OperationFutureImpl.java:127)
        at it.myapp.test.App.main(App.java:59)
Caused by: com.google.api.gax.rpc.InvalidArgumentException: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: The request has errors
        at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:49)
        at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:72)
        at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:60)
        at com.google.api.gax.grpc.GrpcExceptionCallable$ExceptionTransformingFuture.onFailure(GrpcExceptionCallable.java:97)
        at com.google.api.core.ApiFutures$1.onFailure(ApiFutures.java:68)
        at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:1041)
        at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:30)
        at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:1215)
        at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:983)
        at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:771)
        at io.grpc.stub.ClientCalls$GrpcFuture.setException(ClientCalls.java:563)
        at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:533)
        at io.grpc.internal.DelayedClientCall$DelayedListener$3.run(DelayedClientCall.java:464)
        at io.grpc.internal.DelayedClientCall$DelayedListener.delayOrExecute(DelayedClientCall.java:428)
        at io.grpc.internal.DelayedClientCall$DelayedListener.onClose(DelayedClientCall.java:461)
        at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:553)
        at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:68)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:739)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:718)
        at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
        at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: The request has errors
        at io.grpc.Status.asRuntimeException(Status.java:535)
        ... 16 more

My pom.xml have the following setup:我的 pom.xml 有以下设置:

<dependencyManagement>
<dependencies>
  <dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-functions-bom</artifactId>
    <version>1.0.8</version>
    <type>pom</type>
    <scope>import</scope>
  </dependency>
</dependencies>
</dependencyManagement>
<dependencies>
 <dependency>
   <groupId>com.google.cloud</groupId>
   <artifactId>google-cloud-functions</artifactId>
 </dependency>
</dependencies>

Does anyone know what do i wrong?有谁知道我做错了什么?

Thank you谢谢

The error means that your Function Builder is missing the required parameters in order to create the function.该错误意味着您的 Function Builder 缺少创建 function 所需的参数。 If you try to create a function via Cloud Console, you're required to enter details such as function name, entrypoint, runtime, trigger type, and source code.如果您尝试通过 Cloud Console 创建 function,则需要输入 function 名称、入口点、运行时、触发器类型和源代码等详细信息。

I've already reached out to the engineers and they are now informed with regards to the lack of details in the log output.我已经联系了工程师,他们现在被告知日志 output 中缺少详细信息。

As a solution, here's a sample code that will create a Cloud Function running on Java 11. Of course you can always choose any type of runtime you want:作为解决方案,这里有一个示例代码,它将创建一个在 Java 11 上运行的云 Function。当然,您始终可以选择所需的任何类型的运行时:

package function;

import com.google.cloud.functions.v1.CloudFunctionsServiceClient;
import com.google.cloud.functions.v1.HttpsTrigger;
import com.google.cloud.functions.v1.CloudFunction;
import com.google.cloud.functions.v1.LocationName;

public class App {
  public static void main( String[] args ){
    try {

      // TODO: Add your credentials here

      CloudFunctionsServiceClient cloudFunctionsServiceClient = CloudFunctionsServiceClient.create();
      String location = LocationName.of("[PROJECT_ID]", "us-central1").toString();
      CloudFunction function = CloudFunction.newBuilder()
        .setName(location + "/functions/[FUNCTION_NAME]")
        .setEntryPoint("functions.HelloHttp") // fully qualified class name (FQN)
        .setRuntime("java11")
        .setHttpsTrigger(HttpsTrigger.getDefaultInstance())
        .setSourceArchiveUrl("gs://[BUCKET_NAME]/source_code.zip")
        .build(); 
  
      CloudFunction response = cloudFunctionsServiceClient.createFunctionAsync(location, function).get();
    }catch (Exception e){
      e.printStackTrace();
    }
  }
}

Note: If your zipped source code is from a storage bucket, make sure your source files are at the root of the ZIP file , rather than a folder containing the files.注意:如果您的压缩源代码来自存储桶,请确保您的源文件位于 ZIP 文件的根目录,而不是包含文件的文件夹。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google DocumentAI Java 示例因 io.grpc.StatusRuntimeException 失败:INVALID_ARGUMENT:请求包含无效参数 - Google DocumentAI Java example fails with io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Request contains an invalid argument io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED 同时从谷歌云 PubSub 获取主题(发布者)名称 - io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED while getting the topic(publisher) name from Google cloud PubSub 数据流中的错误:io.grpc.StatusRuntimeException:不可用 - Error in Dataflow: io.grpc.StatusRuntimeException: UNAVAILABLE io.grpc.StatusRuntimeException:UNIMPLEMENTED:找不到方法 - io.grpc.StatusRuntimeException: UNIMPLEMENTED: Method not found grpc 客户端-流式 Java 客户端获取 io.grpc.StatusRuntimeException: UNAVAILABLE: HTTP 状态代码 503 - grpc Client-Streaming Java Client gets io.grpc.StatusRuntimeException: UNAVAILABLE: HTTP status code 503 引起:io.grpc.StatusRuntimeException:NOT_FOUND:找不到资源 - Caused by: io.grpc.StatusRuntimeException: NOT_FOUND: Resource not found gRpc,客户端获取 io.grpc.StatusRuntimeException: UNIMPLEMENTED: 即使消息被服务器接收并反序列化的方法 - gRpc, client getting io.grpc.StatusRuntimeException: UNIMPLEMENTED: Method even when the message is received and deserialized by the server io.grpc.StatusRuntimeException:未实现:未知服务 manipula.core2.core.proto.Centrifugo - io.grpc.StatusRuntimeException: UNIMPLEMENTED: unknown service manipula.core2.core.proto.Centrifugo 通过 Java API 创建 Google Cloud Function:前提条件检查失败 - Creating Google Cloud Function via Java API: Precondition check failed 尝试使用Google Cloud Vision时出现INVALID_ARGUMENT - I get INVALID_ARGUMENT when I try to use Google Cloud Vision
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM