我有一个应用程序分为 5 个模块(参见我美丽的 ascii 艺术)每个模块都有自己的目录,就像这个结构一样
AppEngine App <--Here's the dispatch.yaml
---------------------
| | | | |
| | | | |
Mod1 Mod2 Mod3 Mod4 Mod5
^ ^
\__Here's the models |__ Here i wanna read the models
.py file
with the __init__.py
Run Code Online (Sandbox Code Playgroud)
NDB 模型在一个模块中定义(例如 mod1),我想读取 Mod5 中的一些数据,官方文档说这是可能的,但我做不到。我以这种方式导入模型
#this is in mod5 py file
import Mod1.models # No module named Mod1.models
from Path.Mod1 import models #No module named Path.Mod1
from Mod1 import models #No module named Mod1
from …Run Code Online (Sandbox Code Playgroud) python google-app-engine app-engine-ndb google-cloud-datastore gae-module
我的应用设置为允许将备份保存到Google云端硬盘应用数据文件夹.它在同一台设备上运行良好.当我进行备份时,删除应用程序的数据,然后恢复所有工作.
但是,当我尝试在一台设备上进行备份,然后安装在另一台设备上并尝试恢复时,找不到任何文件.当我在原始设备上卸载应用程序,在同一设备上重新安装并尝试还原时,也是如此.这两种情况都导致没有找到文件,尽管我在登录Google云端硬盘时看到appdata文件夹中有文件.
我在某处读过你必须使用RESOURCE_ID而不是文件的DRIVE_ID才能在设备之间工作,因为DRIVE_ID会因设备而异.但是,我看到如何获取RESOURCE_ID的唯一方法是使用driveId.getResourceId(),我无法从其他设备获取正确的DRIVE_ID.
tl; dr:我该如何从另一台设备/安装创建的appdata文件夹中检索正确的文件?
我正在测量Google云计算引擎和Google数据存储之间的延迟。
我正在使用python客户端库执行简单的lookup()。
谷歌性能仪表板说,我的请求耗时约18毫秒。我假设这是服务器端指标,而不是往返指标。
我在github上的研究中添加了一些细节。
到目前为止,我找不到关于stackoverflow的这个特定问题的答案:
https://github.com/GoogleCloudPlatform/google-cloud-datastore/issues/5#issuecomment-72590494
我有一个名为 Account 的实体类型。其中一个字段是名为 的字符串selfie,它基本上是用户上传的自拍照的 URL。我想为有自拍的用户获取(因此,如果用户没有自拍,则不应将其包含在结果集中)。我有以下查询。但它不起作用,因为我有"NULL"一个字符串。这样做的正确方法是什么?同样,我只想要有自拍的用户。
Filter selfie = new FilterPredicate("selfie", FilterOperator.GREATER_THAN, "NULL");
Query query = new Query(Account.class.getSimpleName()).setFilter(selfie);
FetchOptions options = FetchOptions.Builder.withLimit(30);
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
QueryResultList<Entity> entities = datastore.prepare(query).asQueryResultList(options);
Run Code Online (Sandbox Code Playgroud)
此外,我对在 App-Engine 上执行此操作的 JDO/JPA 方式持开放态度(但它必须适用于 App-Engine)。
我希望有人可以帮助我.
我想将一个url作为字符串发送到客户端端点函数,然后我希望端点函数下载图像并通过HTTP Post请求发送到我的servlet(也在GAE上运行).
问题是 - 根本没有张贴图片.
这很奇怪,因为如果我在Android客户端上使用完全相同的代码(HttpPost类),它工作正常 - 图像被发布到servlet,servlet将图像存储到数据存储区/ blobstore中.
是否有可能从客户端端点函数向servlet发送HTTP Post请求?
解决了,请看下面的答案!
安卓:
BackendApi.anyMethod("url-to-any-image").execute();
Run Code Online (Sandbox Code Playgroud)
客户端端点功能:
@ApiMethod(path = "anyMethod")
public void anyMethod(@Named("url") String url) {
// --------------------------------------------------
// No input validation here - just a proof of concept
// --------------------------------------------------
try {
// Download image
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
Resources.asByteSource(new URL(url)).copyTo(buffer);
// Upload image
HttpPost httpPost = new HttpPost();
httpPost.setTarget(new URL(BlobstoreServiceFactory.getBlobstoreService().createUploadUrl("/upload")));
httpPost.add("image", buffer.toByteArray());
httpPost.send();
} catch (IOException e) {
LOG.log(Level.WARNING, e.getMessage(), e);
}
}
Run Code Online (Sandbox Code Playgroud)
HttpPost类:
public class HttpPost { …Run Code Online (Sandbox Code Playgroud) java google-app-engine android servlets google-cloud-datastore
我正在开发基于谷歌应用引擎的网络应用程序.该应用程序使用谷歌身份验证api.基本上每个处理程序都从这个BaseHandler扩展,并且作为任何get/post的第一个操作,checkAuth被执行.
class BaseHandler(webapp2.RequestHandler):
googleUser = None
userId = None
def checkAuth(self):
user = users.get_current_user()
self.googleUser = user;
if user:
self.userId = user.user_id()
userKey=ndb.Key(PROJECTNAME, 'rootParent', 'Utente', self.userId)
dbuser = MyUser.query(MyUser.key==userKey).get(keys_only=True)
if dbuser:
pass
else:
self.redirect('/')
else:
self.redirect('/')
Run Code Online (Sandbox Code Playgroud)
这个想法是它重定向到/如果没有用户通过谷歌登录或者如果我的用户数据库中没有用户具有该谷歌ID.
问题是我可以成功登录我的网络应用程序并进行操作.然后,从gmail,o从任何谷歌帐户注销,但如果我尝试继续使用它的工作的网络应用程序.这意味着users.get_current_user()仍然返回有效用户(有效但实际上是OLD).那可能吗?
重要更新 我了解Alex Martelli评论中解释的内容:有一个cookie可以保持前GAE认证有效.问题是,同一个网络应用程序还利用Google Api Client Library for Python https://developers.google.com/api-client-library/python/在Drive和Calendar上执行操作.在GAE应用程序中,可以通过实现整个OAuth2 Flow的装饰器轻松使用此类库(https://developers.google.com/api-client-library/python/guide/google_app_engine).
因此,我的处理程序get/post方法用oauth_required这样装饰
class SomeHandler(BaseHandler):
@DECORATOR.oauth_required
def get(self):
super(SomeHandler,self).checkAuth()
uid = self.googleUser.user_id()
http = DECORATOR.http()
service = build('calendar', 'v3')
calendar_list = service.calendarList().list(pageToken=page_token).execute(http=http)
Run Code Online (Sandbox Code Playgroud)
装饰者在哪里
from oauth2client.appengine import OAuth2Decorator
DECORATOR = OAuth2Decorator(
client_id='XXXXXX.apps.googleusercontent.com', …Run Code Online (Sandbox Code Playgroud) 有没有办法ids []int64在数据存储区上进行查询?我试过以下但没有用.
错误
q := datastore.NewQuery("Category").Filter("Id IN", ids)
Run Code Online (Sandbox Code Playgroud)只需获取数据存储区中的所有类别即可
for _, id := range ids {
q.Filter("Id =", id)
}
Run Code Online (Sandbox Code Playgroud)在icza的回答之后
var keys []*datastore.Key
for _, id := range ids {
keys = append(keys, datastore.NewKey(c, "Category", "", id, nil))
}
categories := make([]Category, len(keys))
err := datastore.GetMulti(c, keys, categories)
if err != nil {
return nil, err
}
Run Code Online (Sandbox Code Playgroud) 我的任务非常简单.迁移并向现有NDB实体(~100K实体)添加新字段(重复和复合属性)后,我需要为其设置默认值.
我先尝试了这个代码:
q = dm.E.query(ancestor=dm.E.root_key)
for user in q.iter(batch_size=500):
user.field1 = [dm.E2()]
user.put()
Run Code Online (Sandbox Code Playgroud)
但它失败了这样的错误:
2015-04-25 20:41:44.792 /**** 500 599830ms 0kb AppEngine-Google; (+http://code.google.com/appengine) module=default version=1-17-0
W 2015-04-25 20:32:46.675 suspended generator run_to_queue(query.py:938) raised Timeout(The datastore operation timed out, or the data was temporarily unavailable.)
W 2015-04-25 20:32:46.676 suspended generator helper(context.py:876) raised Timeout(The datastore operation timed out, or the data was temporarily unavailable.)
E 2015-04-25 20:41:44.475 Traceback (most recent call last): File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 267, in
Run Code Online (Sandbox Code Playgroud)
任务在单独的任务队列上运行,因此它至少需要10分钟才能执行,但似乎还不够.奇怪的是:来自NDB的警告.可能存在死锁,因为来自其他实例的相同实体的更新(由用户发起)但不确定.
无论如何,我想知道这种任务的最佳实践(和最简单).我知道MapReduce,但目前我认为这样的任务过于复杂.
更新:
此外,我尝试put_multi通过抓取数组中的所有实体来使用,但GAE会在超过~600 MB内存(限制为500 …
python google-app-engine bigdata app-engine-ndb google-cloud-datastore
我有以下 Objectify 关系:
@Entity(“Author”)
public class Author{
@Id
private long authorId;
…
}
@Entity(“Book”)
public class Book{
@Id
private long id;
private Key<Author> authorKey;
…
}
Run Code Online (Sandbox Code Playgroud)
现在是有趣的部分:我有authorId(id,不是实体),我需要为该作者查询 Book。我的查询在下面,但它返回一个空列表,而我知道该作者在数据存储区中有书籍。那么我该如何解决这个查询呢?
public static List<Book> getBooksForAuthor(Long authorId) {
Key<Author> authorKey = Key.create(Author.class, authorId);
return OfyService.ofy().load().type(Book.class).filter("authorKey", authorKey).order(“-date").list();
}
Run Code Online (Sandbox Code Playgroud) google-app-engine filter objectify google-cloud-endpoints google-cloud-datastore
是否可以创建从Pub/Sub读取数据并写入数据存储区的管道?在我的代码中,我将PubsubIO指定为输入,并应用窗口来获取有界PCollection,但似乎无法使用带有options.setStreaming的DatastoreIO.writeTo为true,而这是必需的以便使用PubsubIO作为输入.有没有解决的办法?或者是不可能从pubsub读取并写入数据存储区?
这是我的代码:
DataflowPipelineOptions options = PipelineOptionsFactory.create()
.as(DataflowPipelineOptions.class);
options.setRunner(DataflowPipelineRunner.class);
options.setProject(projectName);
options.setStagingLocation("gs://my-staging-bucket/staging");
options.setStreaming(true);
Pipeline p = Pipeline.create(options);
PCollection<String> input = p.apply(PubsubIO.Read.topic("projects/"+projectName+"/topics/event-streaming"));
PCollection<String> inputWindow = input.apply(Window.<String>into(FixedWindows.of(Duration.standardSeconds(5))).triggering(AfterPane.elementCountAtLeast(1)).discardingFiredPanes().withAllowedLateness(Duration.standardHours(1)));
PCollection<String> inputDecode = inputWindow.apply(ParDo.of(new DoFn<String, String>() {
private static final long serialVersionUID = 1L;
public void processElement(ProcessContext c) {
String msg = c.element();
byte[] decoded = Base64.decodeBase64(msg.getBytes());
String outmsg = new String(decoded);
c.output(outmsg);
}
}));
PCollection<DatastoreV1.Entity> inputEntity = inputDecode.apply(ParDo.of(new CreateEntityFn("stream", "events")));
inputEntity.apply(DatastoreIO.writeTo(datasetid));
p.run();
Run Code Online (Sandbox Code Playgroud)
这是我得到的例外:
Exception in thread "main" java.lang.UnsupportedOperationException: The Write transform is not supported by the …Run Code Online (Sandbox Code Playgroud) google-cloud-datastore google-cloud-pubsub google-cloud-dataflow