-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Move and update appengine-endpoints-helloendpoints-java-maven sample #488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
27fc125
c997b45
bf45639
9ed4fe1
4837310
49dd01f
3771154
6be18e5
0161bd1
447cd7a
42298a8
9d6fe59
5600031
ff0bb3b
ed02821
ec6b6ba
129988e
278313b
5771eab
e8ceb34
79ec9e1
ef7ab95
67f2946
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Google Cloud Endpoints Frameworks for App Engine Standard | ||
|
||
This directory contains Google Cloud Endpoints Frameworks for App Engine for | ||
App Engine Standard samples. The [`backend/`](backend/) directory contains the | ||
sample code for the [quickstart][4] for Cloud Endpoints Frameworks on App Engine | ||
using an OpenAPI development process. The [`discovery/`](discovery/) directory | ||
contains the sample code for [migrated][2] prior version of [Cloud Endpoints | ||
Frameworks][1] project to the new [Cloud Endpoints Frameworks for App Engine][8] | ||
using a discovery document development process. | ||
|
||
The new Google Cloud Endpoints Frameworks for App Engine provides | ||
[additional functionality][3] using OpenAPI which is a paid service. It's | ||
recommended that you migrate projects using the prior version of [Cloud Endpoints Frameworks][1]. | ||
|
||
|
||
[1]: https://cloud.google.com/appengine/docs/java/endpoints/ | ||
[2]: https://cloud.google.com/appengine/docs/java/endpoints/migrating | ||
[3]: https://cloud.google.com/endpoints/docs/frameworks/java/about-cloud-endpoints-frameworks | ||
[4]: https://cloud.google.com/endpoints/docs/frameworks/java/quickstart-frameworks-java |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2017 Google Inc. | ||
# | ||
# 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. | ||
|
||
# Fail on non-zero return and print command to stdout | ||
set -xe | ||
|
||
# Jenkins Test Script | ||
function TestEndpoints () { | ||
# Test getGreeting Endpoint (hello world!) | ||
curl -X GET \ | ||
"https://${1}.appspot.com/_ah/api/helloworld/v1/hellogreeting/0" | \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
grep "hello version-${2}" | ||
|
||
# Test getGreeting Endpoint (goodbye world!) | ||
curl -X GET \ | ||
"https://${1}.appspot.com/_ah/api/helloworld/v1/hellogreeting/1" | \ | ||
grep "goodbye world!" | ||
|
||
# Test listGreeting Endpoint (hello world! and goodbye world!) | ||
curl -X GET \ | ||
"https://${1}.appspot.com/_ah/api/helloworld/v1/hellogreeting" | \ | ||
grep "hello world!\|goodbye world!" | ||
|
||
# Test multiply Endpoint (This is a greeting.) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't look like the right format to look at a specific instance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This didn't come to mind. Thanks for pointing that out! |
||
curl -X POST \ | ||
-H "Content-Type: application/json" \ | ||
--data "{'message':'This is a greeting from instance ${2}'}." \ | ||
"https://${1}.appspot.com/_ah/api/helloworld/v1/hellogreeting/1" | \ | ||
grep "This is a greeting from instance ${2}." | ||
} | ||
|
||
# Jenkins provides values for GOOGLE_PROJECT_ID and GOOGLE_VERSION_ID | ||
# Update Greetings.java | ||
sed -i'.bak' -e "s/hello world!/hello version-${GOOGLE_VERSION_ID}!/g" src/main/java/com/example/helloendpoints/Greetings.java | ||
|
||
# Test with Maven | ||
# Attempt to clean and deploy generated archetype | ||
mvn clean appengine:deploy \ | ||
-Dapp.deploy.version="${GOOGLE_VERSION_ID}" \ | ||
-DskipTests=true | ||
|
||
# End-2-End tests | ||
TestEndpoints $GOOGLE_PROJECT_ID $GOOGLE_VERSION_ID | ||
|
||
# Clean and redploy using Gradle | ||
mvn clean | ||
|
||
# Test with Gradle | ||
# Delete Version $GOOGLE_VERSION_ID to test Gradle | ||
gcloud -q app services set-traffic default --splits 1=1 | ||
gcloud -q app versions delete ${GOOGLE_VERSION_ID} | ||
|
||
# Update build.gradle | ||
sed -i'.bak' -e "s/deploy {/deploy {\n version='${GOOGLE_VERSION_ID}'/g" build.gradle | ||
|
||
# Modify Greetings.java for Gradle | ||
sed -i'.bak' -e "s/hello version-${GOOGLE_VERSION_ID}!/hello version-gradle-${GOOGLE_VERSION_ID}!/g" src/main/java/com/example/helloendpoints/Greetings.java | ||
|
||
# Deploy Gradle | ||
gradle appengineDeploy | ||
|
||
# End-2-End tests | ||
TestEndpoints $GOOGLE_PROJECT_ID "gradle-${GOOGLE_VERSION_ID}" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are going to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jenkins uses the GOOGLE_VERSION_ID as the test version and it expects to delete that version when tests are complete. Do you want this step to be contained within the Jenkins.sh? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes - it hasn't been deleting things. We ran out of versions last week. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you run this past the google bash linter? And made sure you are with the style guide? https://google.github.io/styleguide/shell.xml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Hello World Google Cloud Endpoints for App Engine with a discovery document | ||
|
||
This sample provides an example of a [migration][7] from the prior version of | ||
[Google Cloud Endpoints Frameworks][3] to new [Google Cloud Endpoints Frameworks for App Engine][8] | ||
while still using a discovery document. This sample contains comments of how to | ||
use the prior Endpoints Frameworks as well. For clarity, the prior Endpoints | ||
Frameworks and the new Endpoints Frameworks are denoted as Endpoints Frameworks v1.0 | ||
and Endpoints Frameworks v2.0 respectively. | ||
|
||
Google Cloud Endpoints Frameworks v2.0 provides new functionality at a | ||
cost and uses an OpenAPI specification instead of the discovery document. The | ||
OpenAPI development process is explained [here][8] and a quickstart is provided | ||
[here][9]. | ||
|
||
## Products | ||
- [Google App Engine Standard][1] | ||
|
||
## Language | ||
- [Java][2] | ||
|
||
## APIs | ||
- [Google Cloud Endpoints Frameworks v2.0][8] | ||
- [Google Cloud Endpoints Frameworks v1.0][3] | ||
|
||
## Build and Deployment Plugins | ||
- [Google Cloud Endpoints Frameworks Maven Plugin][10] | ||
- [Google Cloud Endpoints Frameworks Gradle Plugin][11] | ||
|
||
## Setup | ||
1. [Optional]: These sub steps are not required but will enable the "Authenticated | ||
Greeting" functionality. | ||
|
||
1. Update the values in [Constants.java](src/main/java/com/example/helloendpoints/Constants.java) | ||
to reflect the web client ID you have registered in the [Credentials on Developers Console for OAuth 2.0 client IDs][6]. | ||
|
||
1. Update the value of `google.devrel.samples.helloendpoints.CLIENT_ID` in [base.js](src/main/webapp/js/base.js) | ||
to reflect the web client ID you have registered in the [Credentials on Developers Console for OAuth 2.0 client IDs][6]. | ||
|
||
1. [Optional]: Use Cloud Endpoints Frameworks v2.0 Maven and Gradle discovery and | ||
client library generation plugins with Cloud Endpoints Frameworks v1.0. | ||
|
||
- Uncomment `Endpoints Frameworks v1.0` sections and comment | ||
`Endpoints Frameworks v2.0` sections in the following files. | ||
|
||
``` | ||
pom.xml | ||
build.gradle | ||
src/main/webapp/WEB-INF/web.xml | ||
``` | ||
|
||
## Build and Deployment | ||
|
||
### Maven | ||
|
||
1. Build a fresh binary with | ||
|
||
`mvn clean compile` | ||
|
||
1. Run the application locally at [localhost:8080][5] with | ||
|
||
`mvn appengine:run` | ||
|
||
1. Generate the client library in a zip file named `helloworld-v1-java.zip` with | ||
|
||
`mvn endpoints-framework:clientLibs` | ||
|
||
1. Deploy your application to Google App Engine with | ||
|
||
`mvn appengine:deploy` | ||
|
||
### Gradle | ||
|
||
1. Build a fresh binary with | ||
|
||
`gradle clean compileJava` | ||
|
||
1. Run the application locally at [localhost:8080][5] with | ||
|
||
`gradle appengineRun` | ||
|
||
1. Generate the client library in a zip file named `helloworld-v1-java.zip` with | ||
|
||
`gradle endpointsClientLibs` | ||
|
||
1. Deploy your application to Google App Engine with | ||
|
||
`gradle appengineDeploy` | ||
|
||
[1]: https://cloud.google.com/appengine/docs/java/ | ||
[2]: http://java.com/en/ | ||
[3]: https://cloud.google.com/appengine/docs/java/endpoints/ | ||
[4]: https://cloud.google.com/appengine/docs/java/tools/maven | ||
[5]: https://localhost:8080/ | ||
[6]: https://console.developers.google.com/project/_/apiui/credential | ||
[7]: https://cloud.google.com/appengine/docs/java/endpoints/migrating | ||
[8]: https://cloud.google.com/endpoints/docs/frameworks/java/about-cloud-endpoints-frameworks | ||
[9]: https://cloud.google.com/endpoints/docs/frameworks/java/quickstart-frameworks-java | ||
[10]: https://github.com/GoogleCloudPlatform/endpoints-framework-maven-plugin | ||
[11]: https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2017 Google Inc. | ||
// | ||
// 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. | ||
|
||
buildscript { // Configuration for building | ||
repositories { | ||
mavenCentral() | ||
jcenter() // Bintray's repository - a fast Maven Central mirror & more | ||
} | ||
dependencies { | ||
classpath 'com.google.cloud.tools:appengine-gradle-plugin:+' // latest App Engine Gradle tasks | ||
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:+' | ||
} | ||
} | ||
|
||
repositories { // repositories for Jar's you access in your code | ||
maven { | ||
url 'https://oss.sonatype.org/content/repositories/snapshots' // SNAPSHOT Repository (if needed) | ||
} | ||
mavenCentral() | ||
jcenter() | ||
} | ||
|
||
apply plugin: 'java' // standard Java tasks | ||
apply plugin: 'war' // standard Web Archive plugin | ||
apply plugin: 'com.google.cloud.tools.appengine' // App Engine tasks | ||
apply plugin: 'com.google.cloud.tools.endpoints-framework-server' | ||
|
||
dependencies { | ||
providedCompile group: 'javax.servlet', name: 'servlet-api', version:'2.5' | ||
compile 'jstl:jstl:1.2' | ||
compile group: 'javax.inject', name: 'javax.inject', version: '1' | ||
|
||
// Uncomment to use Endpoints Frameworks v1.0 | ||
// compile group: 'com.google.appengine', name: 'appengine-endpoints', version: '1.9.48' | ||
// End of Endpoints Frameworks v1.0 | ||
|
||
// Endpoints Frameworks v2.0 | ||
compile "com.google.endpoints:endpoints-framework:+" | ||
// End of Endpoints Frameworks v2.0 | ||
} | ||
|
||
appengine { // App Engine tasks configuration | ||
run { // local (dev_appserver) configuration (standard environments only) | ||
|
||
} | ||
|
||
deploy { // deploy configuration | ||
|
||
} | ||
} | ||
|
||
group = "com.example.helloendpoints" // Generated output GroupId | ||
version = "1" // Version in generated output | ||
|
||
sourceCompatibility = 1.7 // App Engine Standard uses Java 7 | ||
targetCompatibility = 1.7 // App Engine Standard uses Java 7 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#Mon Jan 16 22:18:59 PST 2017 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which may require payment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acknowledged.