From 476afecc6f08de0a03c2827c211db9edf694a7ea Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 14 Sep 2016 16:51:59 +1000 Subject: [PATCH 1/2] Updated async-rest demo to latest Flex Also used as demo for https://github.com/GoogleCloudPlatform/jetty-runtime/issues/4 --- managed_vms/async-rest/README.md | 21 ++----- managed_vms/async-rest/pom.xml | 62 +++---------------- .../async-rest/src/main/appengine/app.yaml | 27 ++++++++ .../async-rest/src/main/docker/Dockerfile | 8 +++ .../src/main/docker/jetty-logging.properties | 19 ++++++ .../google/appengine/demos/DumpServlet.java | 4 ++ .../async-rest/src/main/webapp/Dockerfile | 2 - .../src/main/webapp/WEB-INF/appengine-web.xml | 10 --- 8 files changed, 73 insertions(+), 80 deletions(-) create mode 100644 managed_vms/async-rest/src/main/appengine/app.yaml create mode 100644 managed_vms/async-rest/src/main/docker/Dockerfile create mode 100644 managed_vms/async-rest/src/main/docker/jetty-logging.properties delete mode 100644 managed_vms/async-rest/src/main/webapp/Dockerfile delete mode 100644 managed_vms/async-rest/src/main/webapp/WEB-INF/appengine-web.xml diff --git a/managed_vms/async-rest/README.md b/managed_vms/async-rest/README.md index c4162700843..8ab37ebf087 100644 --- a/managed_vms/async-rest/README.md +++ b/managed_vms/async-rest/README.md @@ -16,17 +16,19 @@ First, complete the following steps: - Install the Cloud SDK `app-engine-java` component. - Authenticate wth the gcloud SDK: gcloud auth login. - Install [Maven](http://maven.apache.org/download.cgi) if you haven't already. - ## Providing your Google Places API key ## -You will need to edit the pom.xml file and replace YOUR_PLACES_APP_KEY with the value of your key: +To run locally, you need to edit the pom.xml file and replace YOUR_PLACES_APP_KEY with the value of your key: YOUR_PLACES_APP_KEY -You then have several options of how to run it: +To deploy to gcloud, you need to edit the src/main/appengine/app.yaml file and replace YOUR_PLACES_APP_KEY with the value of your key: + + PLACES_APPKEY: 'YOUR_PLACES_APP_KEY' + ## Running locally without the AppEngine environment ## The application does not use any AppEngine specific services, so you can run it simply on your local machine by doing: @@ -36,22 +38,11 @@ The application does not use any AppEngine specific services, so you can run it Go to http://localhost:8080 to see the webapp. -## Running locally using Docker ## - -The project also can build a docker image based on the jetty9 image for [Google Container Engine](https://cloud.google.com/container-engine/). -First uncomment the maven plugin section for docker-maven-plugin in the pom.xml. -The WAR file is installed in the webapps directory and the resulting image can be run locally with: - - docker run --rm -it -p 8080:8080 jetty9-async-rest --exec -Dcom.google.appengine.demos.asyncrest.appKey=YOUR_PLACES_APP_KEY - -Where you replace YOUR_PLACES_APP_KEY with the key you obtained in the initial setup. - - ## Deploying to the cloud as an AppEngine ManagedVM ## To automatically stage and deploy the webapp to your project in the cloud do: - mvn gcloud:deploy + mvn appengine:deploy See here for more information on the [GCloud Maven Plugin](https://github.com/GoogleCloudPlatform/gcloud-maven-plugin). diff --git a/managed_vms/async-rest/pom.xml b/managed_vms/async-rest/pom.xml index fbb6073c274..8014ffb94b2 100644 --- a/managed_vms/async-rest/pom.xml +++ b/managed_vms/async-rest/pom.xml @@ -29,8 +29,8 @@ - async- - 9.3.7.v20160115 + 0.1.2 + 9.3.8.v20160314 1.8 1.8 YOUR_PLACES_APP_KEY @@ -50,15 +50,13 @@ - - com.google.appengine - gcloud-maven-plugin - 2.0.9.106.v20160420 - - debug - debug - false - remote + + com.google.cloud.tools + appengine-maven-plugin + ${appengine.maven.plugin} + + true + true @@ -77,48 +75,6 @@ - diff --git a/managed_vms/async-rest/src/main/appengine/app.yaml b/managed_vms/async-rest/src/main/appengine/app.yaml new file mode 100644 index 00000000000..e439d2821ad --- /dev/null +++ b/managed_vms/async-rest/src/main/appengine/app.yaml @@ -0,0 +1,27 @@ +# Copyright 2016 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# [START appyaml] +runtime: custom +vm: true + +handlers: +- url: /.* + script: this field is required, but ignored + secure: always + + +env_variables: + PLACES_APPKEY: 'YOUR_PLACES_APP_KEY' + +# [END appyaml] diff --git a/managed_vms/async-rest/src/main/docker/Dockerfile b/managed_vms/async-rest/src/main/docker/Dockerfile new file mode 100644 index 00000000000..7796e353862 --- /dev/null +++ b/managed_vms/async-rest/src/main/docker/Dockerfile @@ -0,0 +1,8 @@ +FROM gcr.io/google_appengine/jetty9 +#FROM gcr.io/YOUR_PROJECT/jetty9 +ADD managed-vms-async-rest-1.0.0-SNAPSHOT.war $JETTY_BASE/webapps/root.war +ADD jetty-logging.properties $JETTY_BASE/resources/jetty-logging.properties +RUN chown jetty:jetty $JETTY_BASE/webapps/root.war $JETTY_BASE/resources/jetty-logging.properties +WORKDIR $JETTY_BASE +#RUN java -jar $JETTY_HOME/start.jar --approve-all-licenses --add-to-startd=jmx,stats,hawtio + diff --git a/managed_vms/async-rest/src/main/docker/jetty-logging.properties b/managed_vms/async-rest/src/main/docker/jetty-logging.properties new file mode 100644 index 00000000000..fd14a1d4c87 --- /dev/null +++ b/managed_vms/async-rest/src/main/docker/jetty-logging.properties @@ -0,0 +1,19 @@ +## Copied to $JETTY_BASE/resources in Dockerfile + +## Direct Jetty logging to JavaUtilLog +# org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.JavaUtilLog + +### Configure jetty root logger level for the default StdErrLog class. +## Levels are OFF, DEBUG, INFO, WARN, ALL +org.eclipse.jetty.LEVEL=INFO +#org.eclipse.jetty.server.LEVEL=DEBUG + +## If SOURCE is true, the filename and line number of the logging event origin are logged +org.eclipse.jetty.SOURCE=false + +## If STACKS is true, full stack traces for exceptions are logged +org.eclipse.jetty.STACKS=true + +## If LONG is true, fully qualified package names are used rather than abbreviations +org.eclipse.jetty.LONG=false + diff --git a/managed_vms/async-rest/src/main/java/com/google/appengine/demos/DumpServlet.java b/managed_vms/async-rest/src/main/java/com/google/appengine/demos/DumpServlet.java index 6d0541adceb..682d79480c7 100644 --- a/managed_vms/async-rest/src/main/java/com/google/appengine/demos/DumpServlet.java +++ b/managed_vms/async-rest/src/main/java/com/google/appengine/demos/DumpServlet.java @@ -31,6 +31,10 @@ public class DumpServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + if (Boolean.parseBoolean(request.getParameter("throw"))) + throw new ServletException("Test Exception"); + response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_OK); diff --git a/managed_vms/async-rest/src/main/webapp/Dockerfile b/managed_vms/async-rest/src/main/webapp/Dockerfile deleted file mode 100644 index d1d08b4bb8e..00000000000 --- a/managed_vms/async-rest/src/main/webapp/Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -FROM gcr.io/google_appengine/jetty9-compat:githubheadasync -ADD . /app diff --git a/managed_vms/async-rest/src/main/webapp/WEB-INF/appengine-web.xml b/managed_vms/async-rest/src/main/webapp/WEB-INF/appengine-web.xml deleted file mode 100644 index 85197614067..00000000000 --- a/managed_vms/async-rest/src/main/webapp/WEB-INF/appengine-web.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - true - false - true - false - - - - From e6cd9348f9474a03e05d6021cb265dab0a9d46b7 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 15 Sep 2016 12:12:36 +1000 Subject: [PATCH 2/2] fixed formatting --- .../src/main/java/com/google/appengine/demos/DumpServlet.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/managed_vms/async-rest/src/main/java/com/google/appengine/demos/DumpServlet.java b/managed_vms/async-rest/src/main/java/com/google/appengine/demos/DumpServlet.java index 682d79480c7..8f99971f8b3 100644 --- a/managed_vms/async-rest/src/main/java/com/google/appengine/demos/DumpServlet.java +++ b/managed_vms/async-rest/src/main/java/com/google/appengine/demos/DumpServlet.java @@ -32,8 +32,9 @@ public class DumpServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (Boolean.parseBoolean(request.getParameter("throw"))) + if (Boolean.parseBoolean(request.getParameter("throw"))) { throw new ServletException("Test Exception"); + } response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_OK);