forked from GoogleCloudPlatform/microservices-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit for Ads Service. (GoogleCloudPlatform#21)
* Initial commit for Ads Service. * update comments for AdsService and AdsServiceClient * Refactor Ads to Ad Move building AdService to Docker Use default setting for Stackdriver Exporter. Add license text. * Revert the projectId - also remove commented code from frontend/rpc.go * Add adservie to skaffold.yaml * Remove skaffold-adservice.yaml * Replace personal projectId with demo projectId. * Fix the crash in adservice when ran in locally. * Ignore .skaffold*yaml file and .kubernetes-manifests-*/ dir for easy ProjectID switch. * Fixed review comments. 1. Changed Ad redirect urls to products. 2. Removed leftovers from Dockerfile/kub*manifests*yaml 3. Added retry for StackDriver. 4. Added log for Ad request. 5. Added comment for gradle caching. 6. Added README.md to src/adservice. * Added GRPC Health service to Ad Service Also added 1. timeout to getAd RPC call in frontend. 2. Async thread for stackdriver init.
- Loading branch information
Showing
19 changed files
with
1,457 additions
and
272 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 |
---|---|---|
|
@@ -7,3 +7,6 @@ pkg/ | |
.vscode/ | ||
.vs/slnx.sqlite | ||
.vs/microservices-demo/v15/.suo | ||
.idea | ||
.skaffold-*.yaml | ||
.kubernetes-manifests-*/ |
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,63 @@ | ||
# Copyright 2018 Google LLC | ||
# | ||
# 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. | ||
|
||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: adservice | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
app: adservice | ||
spec: | ||
terminationGracePeriodSeconds: 5 | ||
containers: | ||
- name: server | ||
image: gcr.io/microservices-demo-app/adservice | ||
ports: | ||
- containerPort: 9555 | ||
env: | ||
- name: PORT | ||
value: "9555" | ||
resources: | ||
requests: | ||
cpu: 200m | ||
memory: 64Mi | ||
limits: | ||
cpu: 300m | ||
memory: 128Mi | ||
readinessProbe: | ||
tcpSocket: | ||
port: 9555 | ||
initialDelaySeconds: 5 | ||
periodSeconds: 10 | ||
livenessProbe: | ||
tcpSocket: | ||
port: 9555 | ||
initialDelaySeconds: 10 | ||
periodSeconds: 10 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: adservice | ||
spec: | ||
type: ClusterIP | ||
selector: | ||
app: adservice | ||
ports: | ||
- name: grpc | ||
port: 9555 | ||
targetPort: 9555 |
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
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
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,8 @@ | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.gradle/** | ||
.idea/** | ||
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,15 @@ | ||
# adsservice | ||
FROM openjdk:8 | ||
RUN apt-get update && apt-get install net-tools telnet | ||
WORKDIR /app | ||
|
||
# Next three steps are for caching dependency downloads | ||
# to improve subsequent docker build. | ||
COPY ["build.gradle", "gradlew", "./"] | ||
COPY gradle gradle | ||
RUN ./gradlew downloadRepos | ||
|
||
COPY . . | ||
RUN ./gradlew installDist | ||
EXPOSE 9555 | ||
ENTRYPOINT ["/app/build/install/hipstershop/bin/AdService"] |
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,26 @@ | ||
# Ad Service | ||
|
||
The Ad service provides advertisement based on context keys. If no context keys are provided then it returns random ads. | ||
|
||
## Local Build | ||
|
||
The Ad service uses gradlew to compile/install/distribute. Gradle wrapper is already part of the source code. To build Ad Service, run | ||
``` | ||
cd src/adservice; ./gradlew installDist | ||
``` | ||
It will create executable script src/adservice/build/install/hipstershop/bin/AdService | ||
|
||
### Upgrade gradle version | ||
If you need to upgrade the version of gradle then run | ||
``` | ||
cd src/adservice ; ./gradlew wrapper --gradle-version <new-version> | ||
``` | ||
|
||
## Docker Build | ||
|
||
From repository root, run: | ||
|
||
``` | ||
docker build --file src/adservice/Dockerfile . | ||
``` | ||
|
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,122 @@ | ||
description = 'Ad Service' | ||
|
||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
mavenLocal() | ||
maven { | ||
url "https://plugins.gradle.org/m2/" | ||
} | ||
} | ||
dependencies { | ||
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3' | ||
} | ||
} | ||
|
||
apply plugin: 'idea' | ||
apply plugin: 'java' | ||
apply plugin: 'com.google.protobuf' | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenLocal() | ||
} | ||
|
||
group = "adservice" | ||
version = "0.1.0-SNAPSHOT" // CURRENT_OPENCENSUS_VERSION | ||
|
||
def opencensusVersion = "0.15.0" // LATEST_OPENCENSUS_RELEASE_VERSION | ||
def grpcVersion = "1.10.1" // CURRENT_GRPC_VERSION | ||
def prometheusVersion = "0.3.0" | ||
|
||
tasks.withType(JavaCompile) { | ||
sourceCompatibility = '1.8' | ||
targetCompatibility = '1.8' | ||
} | ||
|
||
ext { | ||
speed = project.hasProperty('speed') ? project.getProperty('speed') : false | ||
offlineCompile = new File("$buildDir/output/lib") | ||
} | ||
|
||
dependencies { | ||
if (speed) { | ||
compile fileTree(dir: offlineCompile, include: '*.jar') | ||
} else { | ||
compile "com.google.api.grpc:proto-google-common-protos:1.11.0", | ||
"io.opencensus:opencensus-exporter-stats-prometheus:${opencensusVersion}", | ||
"io.opencensus:opencensus-exporter-stats-stackdriver:${opencensusVersion}", | ||
"io.opencensus:opencensus-exporter-trace-stackdriver:${opencensusVersion}", | ||
"io.opencensus:opencensus-exporter-trace-logging:${opencensusVersion}", | ||
"io.grpc:grpc-protobuf:${grpcVersion}", | ||
"io.grpc:grpc-stub:${grpcVersion}", | ||
"io.grpc:grpc-netty:${grpcVersion}", | ||
"io.grpc:grpc-services:${grpcVersion}", | ||
"io.prometheus:simpleclient_httpserver:${prometheusVersion}" | ||
|
||
runtime "io.opencensus:opencensus-impl:${opencensusVersion}", | ||
"io.netty:netty-tcnative-boringssl-static:2.0.8.Final" | ||
} | ||
} | ||
|
||
protobuf { | ||
protoc { | ||
artifact = 'com.google.protobuf:protoc:3.5.1-1' | ||
} | ||
plugins { | ||
grpc { | ||
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" | ||
} | ||
} | ||
generateProtoTasks { | ||
all()*.plugins { | ||
grpc {} | ||
} | ||
ofSourceSet('main') | ||
} | ||
} | ||
|
||
// Inform IDEs like IntelliJ IDEA, Eclipse or NetBeans about the generated code. | ||
sourceSets { | ||
main { | ||
java { | ||
srcDirs 'hipstershop' | ||
srcDirs 'build/generated/source/proto/main/java/hipstershop' | ||
srcDirs 'build/generated/source/proto/main/grpc/hipstershop' | ||
} | ||
} | ||
} | ||
|
||
// Provide convenience executables for trying out the examples. | ||
apply plugin: 'application' | ||
|
||
startScripts.enabled = false | ||
|
||
// This to cache dependencies during Docker image building. First build will take time. | ||
// Subsequent build will be incremental. | ||
task downloadRepos(type: Copy) { | ||
from configurations.compile | ||
into offlineCompile | ||
from configurations.runtime | ||
into offlineCompile | ||
} | ||
|
||
task adService(type: CreateStartScripts) { | ||
mainClassName = 'hipstershop.AdService' | ||
applicationName = 'AdService' | ||
outputDir = new File(project.buildDir, 'tmp') | ||
classpath = jar.outputs.files + project.configurations.runtime | ||
} | ||
|
||
task adServiceClient(type: CreateStartScripts) { | ||
mainClassName = 'hipstershop.AdServiceClient' | ||
applicationName = 'AdServiceClient' | ||
outputDir = new File(project.buildDir, 'tmp') | ||
classpath = jar.outputs.files + project.configurations.runtime | ||
} | ||
|
||
applicationDistribution.into('bin') { | ||
from(adService) | ||
from(adServiceClient) | ||
fileMode = 0755 | ||
} |
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,22 @@ | ||
#!/bin/bash -eu | ||
# | ||
# Copyright 2018 Google LLC | ||
# | ||
# 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. | ||
|
||
#!/bin/bash -e | ||
|
||
# protos are needed in adservice folder for compiling during Docker build. | ||
|
||
mkdir -p proto && \ | ||
cp ../../pb/demo.proto src/main/proto |
Binary file not shown.
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 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-bin.zip |
Oops, something went wrong.