Datastore Location with Google App Engine / Java - google-app-engine

How can I customize the location of the datastore file while working with GAE/J.
The option --datastore_path doesn't seem to work with GAE/J.
And if it is possible, what option do I use in the maven-gae-plugin.

I assume you mean while running the dev app server locally. Try the --generated_dir option with <sdk>/bin/dev_appserver.sh:
--generated_dir=dir Set the directory where generated files are created.
The generated files include the local datastore file.

Related

Bucket files still saved locally when using dev_appserver and --support_datastore_emulator=false

I'm running a local instance of a PHP app-engine project, I have got some buckets setup in GCP specifically for the local dev version, however instead of the data that I write to the bucket appearing online, they are being saved locally into the dev_appserver Datastore. I can see the files in the local admin interface (localhost:8000) under Datastore.
This is an issue as the application I'm developing has a companion app which needs to also access the bucket files.
The
--support_datastore_emulator=[true|false]
flag is documented under
dev_appserver.py -h
But it doesn't seem to have any effect when using =false.
So my question is: How do I stop the dev_appserver from using the local Datastore and make it use the 'real' buckets on the web?
Try setting the --default_gcs_bucket_name flag documented here to establish the default GCS bucket to use:
dev_appserver.py app.yaml --default_gcs_bucket_name gs://BUCKET-NAME

Writing to a file in App Engine: How to view that file afterwards?

I managed to get the "Quickstart for Python 3 in the App Engine Standard Environment" example up and running, and I thought I'd try and further my knowledge a little, perhaps by attempting to get a cron job running.
So I updated the python code, adding another endpoint, counter, like this:
#app.route('/counter')
def counter():
with open('counter.txt', 'a') as the_file:
the_file.write('Hello\n')
return 'Counter incremented'
I intend to have the cron job periodically hit /counter. When this endpoint is hit it will open the file and add a line to it. The /counter endpoint works on my local machine. After I deploy this updated code to the Google cloud, if I go to my blahblah.appspot.com/counter url it should update this 'counter.txt' file.
My question is: How do I see that file to know if it is being updated or not? How do I view that file in the cloud? Thanks.
It not possible to write files in the Google App Engine Standard Python3 environment except in the /tmp directory. As stated in the Python3 GAE official documentation:
The runtime includes a full filesystem. The filesystem is read-only except for the location /tmp, which is a virtual disk storing data in your App Engine instance's RAM.
I agree with #Josh J answer, you should use Google Cloud Storage instead.
You shouldn't write to the local file system in Google App Engine. It may or may not be visible to your app when it scales.
Google Cloud Storage is the preferred method of file storage.
https://cloud.google.com/appengine/docs/standard/python3/using-cloud-storage
For python 2.7 you can import a module from string instead of file, you can see in this answer:
https://stackoverflow.com/a/7548190/8244338

Clean datastore for GoogleAppEngine

How to clear datastore in GoogleAppEngine.
I want to clear my development data to do a test again, but I can found a way to do that
If you are running from the commandline, use the --clear_datastore flag, e.g.,
dev_appserver.py --clear_datastore=yes app
Otherwise, if you're running it off the included GAE launcher, go into the settings of your app (double click it), and there should be a little checkbox that says "clear datastore on launch" under Launch Settings.
reference:
https://cloud.google.com/appengine/docs/python/tools/devserver#Python_Using_the_Datastore
dev_appserver.py --clear_datastore myapp
assuming by "development data", you mean the data in the dev server.
Simply use Administering Your Datastore (Experimental)
Some Other ways
App Engine: How to "reset" the datastore?
Delete all data for a kind in Google App Engine
Interactive console is also a great way.
For Java, the following information can be seen in Using the Datastore - Clearing the Datastore at the end of the page (as of 2013/05/10):
The development web server uses a local version of the Datastore for testing your application, using local files. The data persists as long as the temporary files exist, and the web server does not reset these files unless you ask it to do so.
The file is named local_db.bin, and it is created in your application's WAR directory, in the WEB-INF/appengine-generated/ directory. To clear the Datastore, delete this file.
So, stop your server, delete the file, and restart it up.
On your local machine you can go to : http://localhost:8080/_ah/admin/datastore

Google app engine:Where is the datastore file stored on the local development server?

I am working on a google app engine project using python. I want to know where does google app engine stores the datastore for the projects. I have tried but could not find it.
Can anyone please help me? I am using windows.
Thanks in advance.
On my Windows machine the datastore file is stored in:
C:\Documents and Settings\(yourusername)\Local Settings\Temp
It'll have a .datastore extension.
If you want to manage datastore file in your own directory, you can set the datastore path with command line arguments. See this document.
--datastore_path=...
The path to use for the local datastore data file. The server creates this file if it does not exist.

Deployment of static directory contents to google app engine

I've deployed my first GAE application and I am getting "TemplateDoesNotExist" exception at my main page. It feels like my static directory content is not uploaded to GAE.
Isn't it possible that I update (appcfg.py update myapp/) all my files including the static ones and run it standalone on myappid.appspot.com ?
by the way here you can see the problem:
http://pollbook.appspot.com
PS: my app works perfect locally
Your templates should not be stored in a directory that you refer to as "static" in app.yaml. Static directories are for literally static files that will be served to end users by the CDN without changing. These files cannot be read by the templating engine. It works locally because the dev_appserver does not precisely emulate the production server.
Put your templates in a different directory like /templates or something. You do not need to refer to this directory in your app.yaml.

Resources