-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix-endpoints-discovery
- Loading branch information
Showing
17 changed files
with
1,005 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.gradle/ | ||
api/build/ | ||
client/build/ | ||
out.pb | ||
server/build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# 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. | ||
|
||
# https://github.com/GoogleCloudPlatform/openjdk-runtime | ||
FROM gcr.io/google_appengine/openjdk8 | ||
|
||
RUN apt-get update \ | ||
&& apt-get -y -q upgrade \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
ADD ./server/build/libs/server.jar /hello/server.jar | ||
|
||
ENTRYPOINT ["java", "-jar", "/hello/server.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# Endpoints Getting Started with gRPC & Java Quickstart | ||
|
||
It is assumed that you have a | ||
working | ||
[gRPC](http://www.grpc.io/docs/), | ||
[ProtoBuf](https://github.com/google/protobuf#protocol-compiler-installation) and | ||
Java environment, a Google Cloud account | ||
and [SDK](https://cloud.google.com/sdk/) configured. | ||
|
||
1. Build the code: | ||
|
||
```bash | ||
./gradlew build | ||
``` | ||
|
||
1. Test running the code, optional: | ||
|
||
```bash | ||
# In the background or another terminal run the server: | ||
java -jar server/build/libs/server.jar | ||
# Check the client parameters: | ||
java -jar client/build/libs/client.jar --help | ||
# Run the client | ||
java -jar client/build/libs/client.jar --greetee 'Endpoints!' | ||
``` | ||
|
||
1. Generate the `out.pb` from the proto file. | ||
|
||
```bash | ||
protoc --include_imports --include_source_info api/src/main/proto/helloworld.proto --descriptor_set_out out.pb | ||
``` | ||
|
||
1. Edit, `api_config.yaml`. Replace `MY_PROJECT_ID` with your project id. | ||
|
||
1. Deploy your service config to Service Management: | ||
|
||
```bash | ||
gcloud service-management deploy out.pb api_config.yaml | ||
# The Config ID should be printed out, looks like: 2017-02-01r0, remember this | ||
# set your project to make commands easier | ||
GCLOUD_PROJECT=<Your Project ID> | ||
# Print out your Config ID again, in case you missed it | ||
gcloud service-management configs list --service hellogrpc.endpoints.${GCLOUD_PROJECT}.cloud.goog | ||
``` | ||
|
||
1. Also get an API key from the Console's API Manager for use in the client later. (https://console.cloud.google.com/apis/credentials) | ||
1. Build a docker image for your gRPC server, store in your Registry | ||
```bash | ||
gcloud container builds submit --tag gcr.io/${GCLOUD_PROJECT}/java-grpc-hello:1.0 . | ||
``` | ||
1. Either deploy to GCE (below) or GKE (further down) | ||
### GCE | ||
1. Create your instance and ssh in. | ||
```bash | ||
gcloud compute instances create grpc-host --image-family gci-stable --image-project google-containers --tags=http-server | ||
gcloud compute ssh grpc-host | ||
``` | ||
1. Set some variables to make commands easier | ||
```bash | ||
GCLOUD_PROJECT=$(curl -s "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google") | ||
SERVICE_NAME=hellogrpc.endpoints.${GCLOUD_PROJECT}.cloud.goog | ||
SERVICE_CONFIG_ID=<Your Config ID> | ||
``` | ||
1. Pull your credentials to access Container Registry, and run your gRPC server container | ||
```bash | ||
/usr/share/google/dockercfg_update.sh | ||
docker run -d --name=grpc-hello gcr.io/${GCLOUD_PROJECT}/java-grpc-hello:1.0 | ||
``` | ||
1. Run the Endpoints proxy | ||
```bash | ||
docker run --detach --name=esp \ | ||
-p 80:9000 \ | ||
--link=grpc-hello:grpc-hello \ | ||
gcr.io/endpoints-release/endpoints-runtime:1 \ | ||
-s ${SERVICE_NAME} \ | ||
-v ${SERVICE_CONFIG_ID} \ | ||
-P 9000 \ | ||
-a grpc://grpc-hello:50051 | ||
``` | ||
1. Back on your local machine, get the external IP of your GCE instance. | ||
```bash | ||
gcloud compute instances list | ||
``` | ||
1. Run the client | ||
```bash | ||
java -jar client/build/libs/client.jar --host <IP of GCE Instance>:80 --api_key <API Key from Console> | ||
``` | ||
### GKE | ||
1. Create a cluster | ||
```bash | ||
gcloud container clusters create my-cluster | ||
``` | ||
1. Edit `container-engine.yaml`. Replace `SERVICE_NAME`, `SERVICE_CONFIG_ID`, and `GCLOUD_PROJECT` with your values. | ||
1. Deploy to GKE | ||
```bash | ||
kubectl create -f ./container-engine.yaml | ||
``` | ||
1. Get IP of load balancer, run until you see an External IP. | ||
```bash | ||
kubectl get svc grpc-hello | ||
``` | ||
1. Run the client | ||
```bash | ||
java -jar client/build/libs/client.jar --host <IP of GKE LoadBalancer>:80 --api_key <API Key from Console> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// 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. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
apply plugin: 'java' | ||
apply plugin: 'com.google.protobuf' | ||
|
||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0' | ||
|
||
} | ||
} | ||
|
||
def grpcVersion = '1.0.3' | ||
|
||
dependencies { | ||
repositories { | ||
mavenCentral() | ||
} | ||
compile "io.grpc:grpc-netty:${grpcVersion}" | ||
compile "io.grpc:grpc-protobuf:${grpcVersion}" | ||
compile "io.grpc:grpc-stub:${grpcVersion}" | ||
} | ||
|
||
protobuf { | ||
protoc { | ||
artifact = 'com.google.protobuf:protoc:3.0.2' | ||
} | ||
|
||
plugins { | ||
grpc { | ||
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" | ||
} | ||
} | ||
generateProtoTasks { | ||
all()*.plugins { | ||
grpc {} | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
endpoints/getting-started-grpc/api/src/main/proto/helloworld.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2015, Google Inc. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are | ||
// met: | ||
// | ||
// * Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// * Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following disclaimer | ||
// in the documentation and/or other materials provided with the | ||
// distribution. | ||
// * Neither the name of Google Inc. nor the names of its | ||
// contributors may be used to endorse or promote products derived from | ||
// this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
syntax = "proto3"; | ||
|
||
option java_multiple_files = true; | ||
option java_package = "com.google.endpoints.examples.hello"; | ||
option java_outer_classname = "HelloWorldProto"; | ||
|
||
package helloworld; | ||
|
||
// The greeting service definition. | ||
service Greeter { | ||
// Sends a greeting | ||
rpc SayHello (HelloRequest) returns (HelloReply) {} | ||
} | ||
|
||
// The request message containing the user's name. | ||
message HelloRequest { | ||
string name = 1; | ||
} | ||
|
||
// The response message containing the greetings | ||
message HelloReply { | ||
string message = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# 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. | ||
|
||
# | ||
# An example API configuration. | ||
# | ||
# Below, replace MY_PROJECT_ID with your Google Cloud Project ID. | ||
# | ||
|
||
# The configuration schema is defined by service.proto file | ||
# https://github.com/googleapis/googleapis/blob/master/google/api/service.proto | ||
type: google.api.Service | ||
config_version: 3 | ||
|
||
# | ||
# Name of the service configuration. | ||
# | ||
name: hellogrpc.endpoints.jeffs-test-deploy-1.cloud.goog | ||
|
||
# | ||
# API title to appear in the user interface (Google Cloud Console). | ||
# | ||
title: Hello gRPC API | ||
apis: | ||
- name: helloworld.Greeter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
subprojects { | ||
apply plugin: 'java' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// 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. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
apply plugin: 'application' | ||
|
||
mainClassName = "com.google.endpoints.examples.hello.HelloWorldClient" | ||
|
||
jar { | ||
manifest { | ||
attributes "Main-Class": "$mainClassName" | ||
} | ||
from { | ||
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } | ||
} | ||
} | ||
|
||
dependencies { | ||
compile project(':api') | ||
compile 'commons-cli:commons-cli:1.3' | ||
} |
Oops, something went wrong.