Seraf
Seraf

Reputation: 950

Deploying different languages services to the same Application [Google App Engine]

I have two applications, one in Python and the other one in Java.

In Python, my application is under a Service which is set in the app.yaml, also the cron.yaml calls the service.

In my (Maven) Java app, it is not under a Service so it is the default service (which I will change if needed). The app is also called with the ../WEB-INF/cron.xml file and the informations about the app in the ../WEB-INF/appengine-web.xml

For now they have no connection with each other, I deployed both apps to different projects.

I would like to fuse them and put them in the same project as:

python-app.project.appspot.com

and

java-app.project.appspot.com

instead of the current

python-app.project1.appspot.com

and

project2.appspot.com

I didn't try to play around with the app.yaml and appengine-web.xml files because I do not know if those are to be modified or not.

How do I make different services (modules) with differents languages (Python and Java)

Upvotes: 3

Views: 2163

Answers (1)

Dan Cornilescu
Dan Cornilescu

Reputation: 39824

The naming of the resulting app on appspot.com will be a bit different than what you mentioned, because of the url routing rules. From Routing via URL:

Sends a request to an available instance of the default version of the named service:

https://service-dot-app-id.appspot.com
http://service.my-custom-domain.com

So, assuming your services are named python and java and you app is named app then your appspot.com URLs woulds be:

python-dot-app.appspot.com
java-dot-app.appspot.com

But you can map them them however you want with custom domains.

As for building such app:

  • keep in mind that one of the services needs to me named default (or remain unnamed)

  • create app sub-directories for each service (following what used to be recommended multi-service app structure picture no longer found in the docs, but captured in Can a default service/module in a Google App Engine app be a sibling of a non-default one in terms of folder structure?)

  • copy the entire content of each service code into the respective subdir

  • identify the app-level configuration files (cron.yaml, dispatch.yaml, queue.yaml and index.yaml or their java equivalents) you have and move them one level up, at the app level directory (you may need to merge them if such config files are present in both services). You may need to choose one language for these files, I'd choose python. Cron jobs would need to have targets configured (see target row in Cron job definitions).

    Remember that deploying one/all modules might not necessarily update these files as you may be used to, instead they might need to be explicitly deployed - check the respective service configuration docs. You should keep an eye out for potentially overwriting these configs when deploying the services, you may need to come up with a certain deployment sequence.

  • it's probably a good idea (potentially mandatory) to add a dispatch.yaml file and re-visit/adjust the request path namespaces of the services, to ensure that each request is properly directed to the respective service. Special attention for cron jobs, from the target row in Cron job definitions:

If you use a dispatch file, your job might be re-routed. For example, given the following cron.yaml and dispatch.yaml files, the job will run in module2, even though its target is module1:

# cron.yaml
cron:
- description: "test dispatch vs target"
  url: /tasks/hello_module2
  schedule: every 1 mins
  target: module1

# dispatch.yaml:
dispatch:
- url: '*/tasks/hello_module2'
  module: module2

https://cloud.google.com/appengine/docs/python/config/cronref#cron_job_definitions

Upvotes: 4

Related Questions