Skip to content

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

Merged
merged 23 commits into from
Feb 1, 2017
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
27fc125
Adding endpoints v1 using endpoints frameworks v2 samples
Jan 19, 2017
c997b45
Removing CONTRIB and LICENSE from within a sample
Jan 19, 2017
bf45639
Moved endpoints-v1-using-endpoints-frameworks-v2
Jan 27, 2017
9ed4fe1
Removed nbactions.xml and eclipse-launch-profiles.
Jan 27, 2017
4837310
Removed 'All Rights Reserved'
Jan 27, 2017
49dd01f
Added project id to expected test output in Jenkins.sh
Jan 27, 2017
3771154
Removed unnecessary plugins
Jan 30, 2017
6be18e5
Added README to explain the endpoints directories for Standard
Jan 30, 2017
0161bd1
Updated discovery doc sample for EP standard
Jan 30, 2017
447cd7a
Updating PROJECT_ID to VERSION_ID in Jenkins.sh test
Jan 31, 2017
42298a8
Making Endpoints E2E tests version specific.
Jan 31, 2017
9d6fe59
Typo... in which argument being used.
Jan 31, 2017
5600031
Adding Gradle tests to Jenkins.sh
Jan 31, 2017
ff0bb3b
Merge branch 'master' into add_endpoints_hello_sample
lesv Jan 31, 2017
ed02821
Changed README text for endpoints-frameworks-v2/
Jan 31, 2017
ec6b6ba
Updating endpoints-frameworks-v2/discovery/Jenkins.sh to be version s…
Jan 31, 2017
129988e
Merge branch 'add_endpoints_hello_sample' of github.com:GoogleCloudPl…
Jan 31, 2017
278313b
Added parent pom to pom.xml and updated sample based on stylecheck.
Jan 31, 2017
5771eab
fix typo. setting java compiler source and target
Jan 31, 2017
e8ceb34
Adding space between region tags
Jan 31, 2017
79ec9e1
Modified verbage for cost related to endpoints in README
Jan 31, 2017
ef7ab95
Updated endpionts README to give more information about user authenti…
Jan 31, 2017
67f2946
Double quotes for environment variables Jenkins.sh
Jan 31, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions appengine/endpoints-frameworks-v2/README.md
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which may require payment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acknowledged.

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
77 changes: 77 additions & 0 deletions appengine/endpoints-frameworks-v2/discovery/Jenkins.sh
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" | \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be {$1}

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.)
Copy link
Contributor

Choose a reason for hiding this comment

The 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. name-dot-instance.appspot.com ??

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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}"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are going to use ${GOOGLE_VERSION_ID} from Jenkins, you should delete your instances after you are done deploying.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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

100 changes: 100 additions & 0 deletions appengine/endpoints-frameworks-v2/discovery/README.md
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

67 changes: 67 additions & 0 deletions appengine/endpoints-frameworks-v2/discovery/build.gradle
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
Loading