Developers Club geek daily blog

1 year, 5 months ago
previous parts:
Google Cloud Endpoints on Java: Manual. p.1
Google Cloud Endpoints on Java: Manual. p. 2 (Frontend)

Work with versions


Google App Engine gives an opportunity to load up to 10 different application versions.
One of them (by default — first loaded) is main (default) and is available to the key address of the application, and respectively to the address of own domain(s).

The others are available to the address of a type {version} - dot-{ID project} .appspot.com
The version can call somehow, it shall not be 1-dot-{ID project} of .appspot.com, it is possible to apply more difficult designations that in particular does the address of the crude version hardly accessible for wide audience
But, naturally, as the name of the version to become part of the web address, there should not be a point or invalid characters in web addresses.

For testing A/B, it is possible to include traffic splitting and to redirect a certain percent of visitors on the version other than the version by default.

Version control is available in the menu of the developer: Compute-> App Engine-> Versions:
image

We specify versions in two places in the appendix in /src/main/webapp/WEB-INF/appengine-web.xml:
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
    <application>{проект ID}</application>
    <version>{наименование версии}</version>

— it is actually the application version in GAE,

and in pom.xml:
    <modelVersion>4.0.0</modelVersion>
    <packaging>war</packaging>
    <version>{версия}</version>

— it will be part of the name of the .war-file: target/{ID project} - {version} of .war

Actually designations of the version in appengine-web.xml and pom.xml are technically not connected and can be absolutely different, but from the point of view of maintenance of an order logically that they matched.

The mvn appengine:update command places updates in the version with the name '1' irrespective of the .war version of the file and value of the version specified in /src/main/webapp/WEB-INF/appengine-web.xml

Therefore for work with different application versions we will need Google App Engine SDK. At the time of writing of this article the latest version 1.9.28. We download on: We will also extract cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_Java in a directory for choice, and, for convenience, we register in PATH, for example:
mkdir ~/GAE-SDK # any path you like
cd $_
wget https://storage.googleapis.com/appengine-sdks/featured/appengine-java-sdk-1.9.28.zip
unzip appengine-java-sdk-1.9.28.zip
cd appengine-java-sdk-1.9.28/bin
echo 'export PATH=$PATH:'$(pwd) >> ~/.bashrc # adds current dir to PATH
source ~/.bashrc
cd


For deploya the utility of appcfg.sh is used, in a directory of the project we start command:
appcfg.sh update ./src/main/webapp/ --noisy

The utility makes user authentication via the browser, and saves tokens in ~ / .appcfg_oauth2_tokens_java
We specify a way to a directory as parameters in which WEB INF is located where in turn to be appengine-web.xml, and the project will be loaded into the version the name of which is specified the server in appengine-web.xml

Well and when changing versions it is necessary not to forget to designate change of versions in comments of kommit of git.

Downloading of files of the project from the server


By means of the utility it is also possible to download files of the project from the server. It becomes command of a type:
appcfg.sh - A {ID project} - V { a version name } download_app { a directory for downloading }
for example:
appcfg.sh -A hello-habrahabr-api -V '1' download_app temp_hello-habrahabr-api.1

The downloaded project will look approximately so:
image

or so:
image

I.e. it is result of expansion of .war on the server but not .war and not the source code.

Downloading of logs from the server


Log can be downloaded from the server on the local machine by means of the same utility in a format of the simple text file by command of a type:

appcfg.sh - A { the ID project, it is possible to miss — it is used from appengine-web.xml } - V { a version name } - num_days= { the number of days, by default: 1, it is available to 90 } - severity= { level 0 (DEBUG) to 4 (CRITICAL) if this parameter is passed, are downloaded only a log of requests } request_logs src/main/webapp/{ the file for saving of information)

It is possible to specify options also:
- append (to add to the existing file)
- include_all (to include all contents of log messages)
- noisy (to output more information on work of the utility)

For example:
appcfg.sh -A 'hello-habrahabr-api' -V '1' --num_days=90 --noisy request_logs src/main/webapp/ ../$(date '+%Y-%m-%d').LOGS.txt


Google Cloud Shell


One more interesting function of the console of the developer is Google Cloud Shell.

By clicking on the icon representing the terminal in a top panel in the lower part of the page the console is started, and we get access to the Debian-based Linux virtual computer with the preset tools necessary for work with cloud services of Google, in particular: standard utilities of Debian-based Linux, including apt-get, wget, etc.; Java 7; Maven 3.2; Git; Python 2.7 and pip; Node.js and npm; Google Cloud SDK; Google App Engine SDK; Vim, Nano, Emacs.

To the user 5GB of the permanent place on a disk is selected, but only the house directory of the user remains between restarts. That is programs, files, and settings in a house directory will be available at each new input. It is possible to install programs with the help but apt-get — but only on one session.
Also the Web preview function is available: it is possible to start a web the server (for example python - m SimpleHTTPServer) with port in the range from 8080 to 8084 and to open it in a separate window / tab of the browser the "web preview" button (it is available only to this user)

image
So Cloud Shell looks. Shooters designated buttons of start of the console and Web preview.

This article is a translation of the original post at habrahabr.ru/post/271385/
If you have any questions regarding the material covered in the article above, please, contact the original author of the post.
If you have any complaints about this article or you want this article to be deleted, please, drop an email here: sysmagazine.com@gmail.com.

We believe that the knowledge, which is available at the most popular Russian IT blog habrahabr.ru, should be accessed by everyone, even though it is poorly translated.
Shared knowledge makes the world better.
Best wishes.

comments powered by Disqus