I am developing a GWT application on google app engine and I am looking for the best approach to initialize objects (like singleton, list, shared resources etc).
I guess I am looking for something like "Spring application context file"
any ideas?
What you're looking for is here:
http://code.google.com/appengine/docs/java/config/appconfig.html#Using_a_ServletContextListener
Basically, you're going to make a Servlet Context Listener, which is a part of the servlet API designed for exactly what you're referring to. If you're running this locally, it will run when you start your server. In the app engine environment it should run for every warm up request (to avoid, this, you can use "Always ON", which will be set here: http://code.google.com/appengine/docs/adminconsole/instances.html#Always_On)
Besides ServletContextListener you can also use <load-on-startup> to mark your normal servlet to be invoked during a warmup request.
Related
I have an standard appengine app currently running. I am currently developing another flask app which will use flexible runtime. I am wondering is it possible for me to have both apps in same project?
Yes, it is possible, with each of your "applications" being implemented as separate services/modules in the same GAE app. Services/modules offer complete code isolation, see Comparison of service isolation and project isolation.
See also: Custom runtime for non-flexible environment app?
There is an even easier way to do this that doesn't require creating a separate service :)
Since you are only developing your second application, you do not need to set it as the default version to serve traffic to the public. You only need to access it yourself, (or perhaps whoever you give the URL to). The only drawback really is that you will not be able to access your project at the default url, usually .appspot.com
Therefore, you can simply deploy your flexible app engine project, but make sure you don't give it any traffic sharing or promote it to the main version!! You can then access your version simply by clicking on the version in the google cloud console, or by visiting http://-dot-.appspot.com/ (It was not possible to access individual versions like this for flexible for quite some time, but this has now been resolved.)
At a high level: When deployed, I want my Google App Engine app to run through some code and then stop the program automatically once it's finished, so that I don't have to manually stop the versions or instances using the UI.
I tried using the both the stop and delete instances in the Google Compute Engine API here: https://cloud.google.com/compute/docs/reference/latest/instances/delete
When I do that it gives me a successful response with a status equal to 'PENDING.' But when I look at the logs for the app, rather than stopping it looks like it's just repeating the code that I deployed over and over again, which I interpret as, "Oh it must not be stopping the app/instances then."
Am I doing something wrong? Is there another way to tell a Google App Engine app to stop itself?
I'm not sure exactly what you're trying to do, but it seems like you want the App Engine Admin API, rather than the Compute Engine API. I think setting servingStatus via app.services.versions.patch is probably what you want, but I'm not sure.
I want to access an external Google API through a GAS trigger. Is it possible/advisable to use something like the javascript Google API client library, adapted for the GAS context, instead of manually using URL Fetch, as mentioned here ?
PS. I am trying to hit the Google App Engine TaskQueue service via its REST API.
In the Apps Script Code Editor, under the RESOURCES, ADVANCED GOOGLE SERVICES menu, you can enable different API's. I don't see an Advanced Service for anything the resembles a Task Queue. There is a Tasks API, but that's for Task List, which is very different than the Task Queue.
So, I don't think you have any choice but to use the REST API with UrlFetchApp.fetch() in server side gs code in Apps Script.
As far as the trigger is concerned, you might want to look at quota limits, if you're going to be running it a lot, or running code that takes a long time to run.
You can use external APIs with OAUTH2 as outlined here: apps-script-oauth2
It's just not built-in, but you can easily add it as a library as mentioned in the Readme.
I was unable to access my Backend Instance at custom domain.
For example, I have an app and I access the Normal Instance sucessfully at:
http://www.[my_app_id].appspot.com or http://[my_app_id].appspot.com
And I have a backend config name=test and I accessed Backend Instance successfully at:
http://test.[my_app_id].appspot.com
In admin interface, the "Instances" link show the instances of Backend and Normal Instance separately. The content show is the same, but is easy to see when a request go to the Backend Instance and when go to Normal Instance.
Then I configured the wildcard "test" in Google Apps to access my Backend Instance at a custom URL:
I continue access the Normal Instance sucessfully at:
http://www.[my_domain].com or http://[my_domain].com
But request at
http://test.[my_domain].com
redicted to the Normal Instance instead of Backend Instance.
The doc's said it should work but I cann't at this moment and I need uses custom domain because my app is multitenancy.
What I do wrong?
Your backed is really supposed to be accessed by the front end, as I understand it.
So when your application front end makes a request to it's back end (e.g. via a URL), it'll work as it's all done internally.
Have you set your back end to be publicly accessible?
https://developers.google.com/appengine/docs/python/backends/overview#Public_and_Private_Backends
Backends are private by default, since they typically function as a component inside an application, rather than acting as its public face. Private backends can be accessed by application administrators, instances of the application, and by App Engine APIs and services (such as Task Queue tasks and Cron jobs) without any special configuration. Backends are not primarily intended for user-facing traffic, but you can make a backend public for testing or for interacting with an external system.
I don't know why the redirection is not working, but perhaps you should modify your question to show what problem it is you are trying to solve here and get an answer to that instead?
I have a Dynamic Backend setup on GAE which I want to run using cron every 15mins. The problem is cron requires a url that begins with "/". While a backend URL uses the following format: http://backendname.yourapp.appspot.com.
I've read in other forums that you could use fetchurl to call your backend but I don't think that's the ideal way. Because that would require you to make your backend publicly accessible.
According to google's documentation:
http://code.google.com/appengine/docs/java/backends/overview.html#Public_and_Private_Backends
"Private backends can be accessed by application administrators, instances of the application, and by App Engine APIs and services (such as Task Queue tasks and Cron jobs) without any special configuration."
Has anybody got backends called by declaring it in cron.xml?
Use target tag to specify a backend in your cron.xml.
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/long-task</url>
<description></description>
<schedule>every 30 minutes</schedule>
<target>name-of-the-backend</target>
</cron>
</cronentries>
urlfetch can be used to access internal-only URLs such as private backends - if that weren't possible, there'd be no way to communicate within your app! A better idea, though, might be to use the Task Queue, which can be configured to run tasks against a backend.
I haven't try google app engine's Backends functions, because its pricing model.
However, according to the documents:
http://code.google.com/appengine/docs/python/backends/overview.html#Public_and_Private_Backends
Backends are private by default, since they typically function as a component inside an application, rather than acting as its public face.
I think GAE will automatically hide the backend url from public http visiting (even without the needs to configure the app.yaml). You may test its behavior by logout and access the backend url directly.