Skip to content

Commit 532ecf3

Browse files
authored
Merge branch 'master' into fix-endpoints-discovery
2 parents 95281c3 + de8f004 commit 532ecf3

File tree

17 files changed

+1005
-0
lines changed

17 files changed

+1005
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.gradle/
2+
api/build/
3+
client/build/
4+
out.pb
5+
server/build/
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2017 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# https://github.com/GoogleCloudPlatform/openjdk-runtime
16+
FROM gcr.io/google_appengine/openjdk8
17+
18+
RUN apt-get update \
19+
&& apt-get -y -q upgrade \
20+
&& rm -rf /var/lib/apt/lists/*
21+
22+
ADD ./server/build/libs/server.jar /hello/server.jar
23+
24+
ENTRYPOINT ["java", "-jar", "/hello/server.jar"]
+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Endpoints Getting Started with gRPC & Java Quickstart
2+
3+
It is assumed that you have a
4+
working
5+
[gRPC](http://www.grpc.io/docs/),
6+
[ProtoBuf](https://github.com/google/protobuf#protocol-compiler-installation) and
7+
Java environment, a Google Cloud account
8+
and [SDK](https://cloud.google.com/sdk/) configured.
9+
10+
1. Build the code:
11+
12+
```bash
13+
./gradlew build
14+
```
15+
16+
1. Test running the code, optional:
17+
18+
```bash
19+
# In the background or another terminal run the server:
20+
java -jar server/build/libs/server.jar
21+
22+
# Check the client parameters:
23+
java -jar client/build/libs/client.jar --help
24+
25+
# Run the client
26+
java -jar client/build/libs/client.jar --greetee 'Endpoints!'
27+
```
28+
29+
1. Generate the `out.pb` from the proto file.
30+
31+
```bash
32+
protoc --include_imports --include_source_info api/src/main/proto/helloworld.proto --descriptor_set_out out.pb
33+
```
34+
35+
1. Edit, `api_config.yaml`. Replace `MY_PROJECT_ID` with your project id.
36+
37+
1. Deploy your service config to Service Management:
38+
39+
```bash
40+
gcloud service-management deploy out.pb api_config.yaml
41+
# The Config ID should be printed out, looks like: 2017-02-01r0, remember this
42+
43+
# set your project to make commands easier
44+
GCLOUD_PROJECT=<Your Project ID>
45+
46+
# Print out your Config ID again, in case you missed it
47+
gcloud service-management configs list --service hellogrpc.endpoints.${GCLOUD_PROJECT}.cloud.goog
48+
```
49+
50+
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)
51+
52+
1. Build a docker image for your gRPC server, store in your Registry
53+
54+
```bash
55+
gcloud container builds submit --tag gcr.io/${GCLOUD_PROJECT}/java-grpc-hello:1.0 .
56+
```
57+
58+
1. Either deploy to GCE (below) or GKE (further down)
59+
60+
### GCE
61+
62+
1. Create your instance and ssh in.
63+
64+
```bash
65+
gcloud compute instances create grpc-host --image-family gci-stable --image-project google-containers --tags=http-server
66+
gcloud compute ssh grpc-host
67+
```
68+
69+
1. Set some variables to make commands easier
70+
71+
```bash
72+
GCLOUD_PROJECT=$(curl -s "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google")
73+
SERVICE_NAME=hellogrpc.endpoints.${GCLOUD_PROJECT}.cloud.goog
74+
SERVICE_CONFIG_ID=<Your Config ID>
75+
```
76+
77+
1. Pull your credentials to access Container Registry, and run your gRPC server container
78+
79+
```bash
80+
/usr/share/google/dockercfg_update.sh
81+
docker run -d --name=grpc-hello gcr.io/${GCLOUD_PROJECT}/java-grpc-hello:1.0
82+
```
83+
84+
1. Run the Endpoints proxy
85+
86+
```bash
87+
docker run --detach --name=esp \
88+
-p 80:9000 \
89+
--link=grpc-hello:grpc-hello \
90+
gcr.io/endpoints-release/endpoints-runtime:1 \
91+
-s ${SERVICE_NAME} \
92+
-v ${SERVICE_CONFIG_ID} \
93+
-P 9000 \
94+
-a grpc://grpc-hello:50051
95+
```
96+
97+
1. Back on your local machine, get the external IP of your GCE instance.
98+
99+
```bash
100+
gcloud compute instances list
101+
```
102+
103+
1. Run the client
104+
105+
```bash
106+
java -jar client/build/libs/client.jar --host <IP of GCE Instance>:80 --api_key <API Key from Console>
107+
```
108+
109+
### GKE
110+
111+
1. Create a cluster
112+
113+
```bash
114+
gcloud container clusters create my-cluster
115+
```
116+
117+
1. Edit `container-engine.yaml`. Replace `SERVICE_NAME`, `SERVICE_CONFIG_ID`, and `GCLOUD_PROJECT` with your values.
118+
119+
1. Deploy to GKE
120+
121+
```bash
122+
kubectl create -f ./container-engine.yaml
123+
```
124+
125+
1. Get IP of load balancer, run until you see an External IP.
126+
127+
```bash
128+
kubectl get svc grpc-hello
129+
```
130+
131+
1. Run the client
132+
133+
```bash
134+
java -jar client/build/libs/client.jar --host <IP of GKE LoadBalancer>:80 --api_key <API Key from Console>
135+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2017 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
////////////////////////////////////////////////////////////////////////////////
16+
17+
apply plugin: 'java'
18+
apply plugin: 'com.google.protobuf'
19+
20+
buildscript {
21+
repositories {
22+
mavenCentral()
23+
}
24+
dependencies {
25+
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0'
26+
27+
}
28+
}
29+
30+
def grpcVersion = '1.0.3'
31+
32+
dependencies {
33+
repositories {
34+
mavenCentral()
35+
}
36+
compile "io.grpc:grpc-netty:${grpcVersion}"
37+
compile "io.grpc:grpc-protobuf:${grpcVersion}"
38+
compile "io.grpc:grpc-stub:${grpcVersion}"
39+
}
40+
41+
protobuf {
42+
protoc {
43+
artifact = 'com.google.protobuf:protoc:3.0.2'
44+
}
45+
46+
plugins {
47+
grpc {
48+
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
49+
}
50+
}
51+
generateProtoTasks {
52+
all()*.plugins {
53+
grpc {}
54+
}
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2015, Google Inc.
2+
//
3+
// Redistribution and use in source and binary forms, with or without
4+
// modification, are permitted provided that the following conditions are
5+
// met:
6+
//
7+
// * Redistributions of source code must retain the above copyright
8+
// notice, this list of conditions and the following disclaimer.
9+
// * Redistributions in binary form must reproduce the above
10+
// copyright notice, this list of conditions and the following disclaimer
11+
// in the documentation and/or other materials provided with the
12+
// distribution.
13+
// * Neither the name of Google Inc. nor the names of its
14+
// contributors may be used to endorse or promote products derived from
15+
// this software without specific prior written permission.
16+
//
17+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
syntax = "proto3";
30+
31+
option java_multiple_files = true;
32+
option java_package = "com.google.endpoints.examples.hello";
33+
option java_outer_classname = "HelloWorldProto";
34+
35+
package helloworld;
36+
37+
// The greeting service definition.
38+
service Greeter {
39+
// Sends a greeting
40+
rpc SayHello (HelloRequest) returns (HelloReply) {}
41+
}
42+
43+
// The request message containing the user's name.
44+
message HelloRequest {
45+
string name = 1;
46+
}
47+
48+
// The response message containing the greetings
49+
message HelloReply {
50+
string message = 1;
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2017 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#
16+
# An example API configuration.
17+
#
18+
# Below, replace MY_PROJECT_ID with your Google Cloud Project ID.
19+
#
20+
21+
# The configuration schema is defined by service.proto file
22+
# https://github.com/googleapis/googleapis/blob/master/google/api/service.proto
23+
type: google.api.Service
24+
config_version: 3
25+
26+
#
27+
# Name of the service configuration.
28+
#
29+
name: hellogrpc.endpoints.jeffs-test-deploy-1.cloud.goog
30+
31+
#
32+
# API title to appear in the user interface (Google Cloud Console).
33+
#
34+
title: Hello gRPC API
35+
apis:
36+
- name: helloworld.Greeter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2017 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
////////////////////////////////////////////////////////////////////////////////
16+
17+
subprojects {
18+
apply plugin: 'java'
19+
20+
repositories {
21+
mavenCentral()
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2017 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
////////////////////////////////////////////////////////////////////////////////
16+
17+
apply plugin: 'application'
18+
19+
mainClassName = "com.google.endpoints.examples.hello.HelloWorldClient"
20+
21+
jar {
22+
manifest {
23+
attributes "Main-Class": "$mainClassName"
24+
}
25+
from {
26+
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
27+
}
28+
}
29+
30+
dependencies {
31+
compile project(':api')
32+
compile 'commons-cli:commons-cli:1.3'
33+
}

0 commit comments

Comments
 (0)