gpt4 book ai didi

google-app-engine - 如何在本地将 GAE 应用程序和 GCE 应用程序连接到同一数据存储区?

转载 作者:太空宇宙 更新时间:2023-11-03 15:35:11 25 4
gpt4 key购买 nike

我遇到了类似于 this 的问题一。我有一个 GAE 应用程序和一个 GCE 应用程序,它们在云中似乎运行良好,但我无法让我的本地环境正常工作,因此它们都访问同一个数据存储。

我已经按照上面的链接中的描述设置了本地数据存储,除了我的代码看起来像这样(我必须以这种方式构建它才能让它在云中工作):

print("Connecting to datastore - " + datasetId);

// Get credentials form GCE if not local.
Credential computeEngineCredential = DatastoreHelper.getComputeEngineCredential();

if(computeEngineCredential != null)
{
print("Compute Engine Credetianls are not null! Access token: " + computeEngineCredential.getAccessToken());
}

DatastoreOptions options = DatastoreHelper.getOptionsfromEnv().credential(DatastoreHelper.getComputeEngineCredential()).dataset(datasetId).build();

print("Connection Host: " + options.getHost());
print("Connection Dataset: " + options.getDataset());

datastore = DatastoreFactory.get().create(options);

当我在本地运行 GCE 应用程序并尝试连接到正在运行的 GAE 数据存储时,我得到以下信息(我在下面的输出中将实际数据集 ID 替换为“myDatasetId”):

Connecting to datastore - "myDatasetId"

Connection Host: http://localhost:8888

Connection Dataset: "myDatasetId"

com.google.api.services.datastore.client.DatastoreFactory makeClient

WARNING: Not using any credentials

There was a problem running query: Error: runQuery Error 404

Error 404

com.google.api.services.datastore.client.DatastoreException: Error 404

Error 404

at com.google.api.services.datastore.client.RemoteRpc.makeException(RemoteRpc.java:114) at com.google.api.services.datastore.client.RemoteRpc.call(RemoteRpc.java:80) at com.google.api.services.datastore.client.Datastore.runQuery(Datastore.java:109)

我的 GAE 控制台打印出来(我可以在 8888 端口访问管理控制台就好了):

com.google.appengine.tools.development.AbstractModule startup

INFO: The admin console is running at http://localhost:8888/_ah/admin

com.google.appengine.tools.development.LocalResourceFileServlet doGet

WARNING: No file found for:

/datastore/v1beta2/datasets/"myDatasetId"/runQuery

我已验证 GCE 应用程序中的数据集 ID 与 GAE 应用程序匹配。我已经能够成功地在本地单独运行每个应用程序,并且它们都能够正确连接到本地数据存储(这是在为 GCE 应用程序使用 gcd.cmd 工具时)。根据上面链接中的答案,听起来这是可能的,我做错了什么吗?

更新

不确定这是否相关,但在启动 GCD 工具时出现以下错误:

SEVERE: Unable to load the App Engine dev agent. Security restrictions will not be completely emulated. java.lang.RuntimeException: Unexpected exception during cast. at com.google.apphosting.utils.clearcast.ClearCast$CasterImpl.cast(ClearCast.java:385) at com.google.apphosting.utils.clearcast.ClearCast.staticCast(ClearCast.java:252) at com.google.apphosting.utils.clearcast.ClearCast.staticCast(ClearCast.java:263) at com.google.appengine.tools.development.agent.AppEngineDevAgent.premain(AppEngineDevAgent.java:61) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Unknown Source) at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(Unknown Source) Caused by: java.lang.IllegalAccessException: Class com.google.apphosting.utils.clearcast.ClearCast$CasterImpl can not ac cess a member of class com.google.appengine.tools.development.agent.$Proxy0 with modifiers "public" at sun.reflect.Reflection.ensureMemberAccess(Unknown Source) at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(Unknown Source) at java.lang.reflect.AccessibleObject.checkAccess(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.google.apphosting.utils.clearcast.ClearCast$CasterImpl.cast(ClearCast.java:383) ... 9 more

如果初始化正确,我能否以某种方式将我的 GAE 应用程序连接到 GCD 工具数据存储?好迷茫。

最佳答案

没有官方支持的方式在 Java Development Server 之间共享 Datastore 数据( dev_appserver.sh ) 和 local Cloud Datastore tool (gcd.sh)。

但是,如果您的应用是用 Java 编写的,您可以使用描述的解决方法 here并点dev_appserver.sh gcd.sh生成的数据文件通过指定 -Ddatastore.backing_store=<project dir>/WEB-INF/appengine-generated/local_db.bin选项。

关于google-app-engine - 如何在本地将 GAE 应用程序和 GCE 应用程序连接到同一数据存储区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29836399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com