Firebase Java Admin SDK 5.6.0 FirestoreClient不断抛出io.grpc.StatusRuntimeException:UNKNOWN

时间:2017-12-10 03:44:34

标签: java scala firebase google-cloud-firestore firebase-admin

使用Firebase Admin SDK 5.6.0 for Java(在Scala Play!应用程序中)时,无论何时使用<获取或设置数据,我们都会不断获得 io.grpc.StatusRuntimeException:UNKNOWN 强> FirestoreClient 即可。但是,Firebase的auth功能似乎没有任何问题。

以下是我们获得的例外情况:

ERROR application - method=GET uri=/v1/users/synchAllUsers remote-address=0:0:0:0:0:0:0:1 status=500 error=class java.util.concurrent.ExecutionException: io.grpc.StatusRuntimeException: UNKNOWN
com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:503)
com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:482)
com.google.api.core.AbstractApiFuture.get(AbstractApiFuture.java:56)
services.FirebaseAdminService.createToken(FirebaseAdminService.scala:98)
services.UsersService.$anonfun$synchAllUsers$2(UsersService.scala:37)
scala.collection.Iterator.foreach(Iterator.scala:929)
scala.collection.Iterator.foreach$(Iterator.scala:929)
scala.collection.AbstractIterator.foreach(Iterator.scala:1417)
scala.collection.IterableLike.foreach(IterableLike.scala:71)
scala.collection.IterableLike.foreach$(IterableLike.scala:70)
scala.collection.AbstractIterable.foreach(Iterable.scala:54)
services.UsersService.$anonfun$synchAllUsers$1(UsersService.scala:34)
services.UsersService.$anonfun$synchAllUsers$1$adapted(UsersService.scala:34)
scala.util.Success.$anonfun$map$1(Try.scala:251)
scala.util.Success.map(Try.scala:209)
scala.concurrent.Future.$anonfun$map$1(Future.scala:287)
scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:29)
scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:29)
scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)
scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:81)
akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:91)
akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:38)
akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:43)
akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

以下是我们正在运行的代码:

  private lazy val app = {
    FirebaseApp.getApps().stream().filter(a => a.getName == FirebaseApp.DEFAULT_APP_NAME).findFirst().orElseGet(
      () => {
        //val serviceAccount = new ByteArrayInputStream(Firebase.serviceAccountKey.getBytes(StandardCharsets.UTF_8.name()))
        val serviceAccount = new FileInputStream("conf/gcp_service_account.json")

        val options = new FirebaseOptions.Builder()
          .setCredentials(GoogleCredentials.fromStream(serviceAccount))
          //.setDatabaseUrl("https://festive-bazaar-146119.firebaseio.com")
          .build()

        serviceAccount.close()

        FirebaseApp.initializeApp(options, FirebaseApp.DEFAULT_APP_NAME)
      }
    )
  }

  def createToken(user: User, claims: Map[String, Object] = Map()) = {

    val auth = FirebaseAuth.getInstance(app)
    val db = FirestoreClient.getFirestore(app)

    val firebaseUser = getUserById(auth, user.id.toString)
    if (firebaseUser == null) {
      auth.createUserAsync(new CreateRequest()
        .setUid(user.id.toString)
        .setDisplayName(user.firstName + ' ' + user.lastName)
        .setEmail(user.email)
        .setEmailVerified(true)
        .setDisabled(false)).get()
   }
    else {
      auth.updateUserAsync(new UpdateRequest(user.id.toString)
        .setDisplayName(user.firstName + ' ' + user.lastName)
        .setEmail(user.email)
        .setEmailVerified(true)
        .setDisabled(false)).get()
    }
    // Set the user's info in our user metadata area
    val userInfoRec = new ImmutableMap.Builder[String, String]()
      .put("id", user.id.toString)
      .put("name", user.email)
      .put("email", user.email)
      .put("firstName", user.firstName)
      .put("lastName", user.lastName)
      .build()
db.collection("tenants").document(user.companyId.toString).collection("users").document(user.id.toString).get()
        val users = db.collection("tenants").get.get

        val result = db.collection("tenants").document(user.companyId.toString).collection("users").document(user.id.toString).set(userInfoRec)
    result.get() // **** This triggers the exception shown above, everytime ****

    auth.createCustomTokenAsync(user.id.toString, (claims + ("companyId" -> user.companyId.asInstanceOf[Object])).asJava).get()
  }

上面的注释与****注释是触发异常的行。有没有其他人遇到这个问题或对此有所了解?在当前状态下,它使FirestoreClient对我们完全无用,因为我们无法获取或设置数据到Firestore。我已经检查了文档,API参考,并且通常用Google搜索,但似乎找不到任何有用的东西。

0 个答案:

没有答案