3

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)

Seraf
  • 850
  • 1
  • 17
  • 34

1 Answers1

4

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

Community
  • 1
  • 1
Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • I do not need to modify the app.yaml and appengine-web.xml right? I just need to "fuse" both cron files and put a cron.yaml file into the root directory? – Seraf Jan 16 '17 at 17:53
  • 1
    Correct, `app.yaml` and `appengine-web.xml` are service-level config files, relevant only to the respective services. You'll probably need to add a `dispatch.yaml` file and adjust the request path namespace... I'll update the answer for this. – Dan Cornilescu Jan 16 '17 at 18:47
  • Do I deploy both services separately or how does it work? when I put the two folders one beside the other and do gcloud app deploy --project project-name it says app.yaml is missing. With the dispatch.yaml and cron will it work even if there's no app.yaml in the main folder of the project? – Seraf Jan 17 '17 at 14:07
  • Services can be deployed together or independently, as you desire. Explicitly pass the list of service `.yaml` files as deployables, I suspect `gcloud` auto-detection is very basic and only works for single-service apps (it's just looking for an `app.yaml` file in the current/app dir). Personally I only used the GAE SDK so far, so deploying with `appcfg.py` (which has the same problem). – Dan Cornilescu Jan 17 '17 at 14:19
  • I have issues with the java app, I only can deploy it with mvn appengine:update but I can't access it from the my_app.appspot.com, can I make it a service so I can access it with java-dot-myapp.appspot.com? And how? it says that only gcloud app deploy supports the service deployment and mvn appengine:update only can deploy a default one? – Seraf Jan 17 '17 at 15:03
  • Since I added the java it is giving me 409 conflict when doing mvn appengine:update – Seraf Jan 17 '17 at 15:09
  • Sorry, not a java user, no clue about mvn. – Dan Cornilescu Jan 17 '17 at 15:12
  • maybe try `mvn appengine:deploy` instead? https://cloud.google.com/appengine/docs/java/tools/maven-reference#appenginedeploy (I'm just guessworking here...) – Dan Cornilescu Jan 17 '17 at 15:16
  • `mvn appengine:update` is the same as `mv appengine:deploy`. This is another problem, the main question is closed thanks again Dan! – Seraf Jan 17 '17 at 15:18