From 085792eadb5f9d72e81aff0b3a588d8c49957bb7 Mon Sep 17 00:00:00 2001 From: Jisha Abubaker Date: Tue, 8 May 2018 12:46:53 -0700 Subject: [PATCH 1/3] adding code sample for Google Cloud Memorystore --- memorystore/redis/README.md | 17 ++++ memorystore/redis/flex_deployment/app.yaml | 17 ++++ memorystore/redis/gce_deployment/deploy.sh | 60 ++++++++++++++ .../redis/gce_deployment/startup-script.sh | 78 +++++++++++++++++++ memorystore/redis/gce_deployment/teardown.sh | 20 +++++ memorystore/redis/gke_deployment/Dockerfile | 17 ++++ .../redis/gke_deployment/visit-counter.yaml | 39 ++++++++++ memorystore/redis/pom.xml | 78 +++++++++++++++++++ .../redis/AppServletContextListener.java | 73 +++++++++++++++++ .../example/redis/VisitCounterServlet.java | 53 +++++++++++++ .../src/main/resources/application.properties | 16 ++++ pom.xml | 2 + 12 files changed, 470 insertions(+) create mode 100644 memorystore/redis/README.md create mode 100644 memorystore/redis/flex_deployment/app.yaml create mode 100755 memorystore/redis/gce_deployment/deploy.sh create mode 100644 memorystore/redis/gce_deployment/startup-script.sh create mode 100755 memorystore/redis/gce_deployment/teardown.sh create mode 100644 memorystore/redis/gke_deployment/Dockerfile create mode 100644 memorystore/redis/gke_deployment/visit-counter.yaml create mode 100644 memorystore/redis/pom.xml create mode 100644 memorystore/redis/src/main/java/com/example/redis/AppServletContextListener.java create mode 100644 memorystore/redis/src/main/java/com/example/redis/VisitCounterServlet.java create mode 100644 memorystore/redis/src/main/resources/application.properties diff --git a/memorystore/redis/README.md b/memorystore/redis/README.md new file mode 100644 index 00000000000..fbef96ad1d7 --- /dev/null +++ b/memorystore/redis/README.md @@ -0,0 +1,17 @@ +# Getting started with Googe Cloud Memorystore +Simple HTTP server example to demonstrate connecting to Google Cloud Memorystore. +This sample uses the [Jedis client](https://mvnrepository.com/artifact/redis.clients/jedis). +Please see other client library options [here](https://redis.io/clients#java). + +## Running on GCE + +Follow the instructions in [this guide](TODO-UPDATE-LINK) to deploy the sample application on a GCE VM. + +## Running on GKE + +Follow the instructions in [this guide](TODO-UPDATE-LINK) to deploy the sample application on GKE. + +## Running on Google App Engine Flex + +Follow the instructions in [this guide](TODO-UPDATE-LINK) to deploy the sample application on GKE. + diff --git a/memorystore/redis/flex_deployment/app.yaml b/memorystore/redis/flex_deployment/app.yaml new file mode 100644 index 00000000000..05cc5023e4f --- /dev/null +++ b/memorystore/redis/flex_deployment/app.yaml @@ -0,0 +1,17 @@ +# Copyright 2018 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. +# [START app_yaml] +runtime: java +env: flex +# [END app_yaml] diff --git a/memorystore/redis/gce_deployment/deploy.sh b/memorystore/redis/gce_deployment/deploy.sh new file mode 100755 index 00000000000..8e2a1cb0887 --- /dev/null +++ b/memorystore/redis/gce_deployment/deploy.sh @@ -0,0 +1,60 @@ +#!/bin/bash +# +# Copyright 2018 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. +# [START deploy_sh] +if [ -z "$GCS_APP_LOCATION" ]; then + if [ -z "$BUCKET"]; then + echo "Must set \$BUCKET. For example: BUCKET=my-bucket-name" + exit 1 + fi + GCS_APP_LOCATION="gs://$BUCKET/gce/" + echo $GCS_APP_LOCATION +fi + +if [ -z "$ZONE" ]; then + ZONE=$(gcloud config get-value compute/zone -q) + echo $ZONE +fi + +if [ -z "$WAR" ]; then + WAR=visitcounter-1.0-SNAPSHOT.war +fi + +#Build the WAR package +cd .. +mvn clean package + +#Copy the WAR artifact to the GCS bucket location +gsutil cp -r target/${WAR} ${GCS_APP_LOCATION} + +cd gce_deployment + +# Create an instance +gcloud compute instances create my-instance \ + --image-family=debian-8 \ + --image-project=debian-cloud \ + --machine-type=g1-small \ + --scopes cloud-platform \ + --metadata-from-file startup-script=startup-script.sh \ + --metadata app-location=${GCS_APP_LOCATION},app-war=$WAR \ + --zone $ZONE \ + --tags http-server + +gcloud compute firewall-rules create allow-http-server-8080 \ + --allow tcp:8080 \ + --source-ranges 0.0.0.0/0 \ + --target-tags http-server \ + --description "Allow port 8080 access to http-server" +# [END deploy_sh] diff --git a/memorystore/redis/gce_deployment/startup-script.sh b/memorystore/redis/gce_deployment/startup-script.sh new file mode 100644 index 00000000000..d688acedfad --- /dev/null +++ b/memorystore/redis/gce_deployment/startup-script.sh @@ -0,0 +1,78 @@ +#! /bin/bash + +# Copyright 2018 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. +# [START startup_script_sh] +set -ex + +# Talk to the metadata server to get the project id and location of application binary. +PROJECTID=$(curl -s "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google") +GCS_APP_LOCATION=$(curl -s "http://metadata.google.internal/computeMetadata/v1/instance/attributes/app-location" -H "Metadata-Flavor: Google") +WAR=$(curl -s "http://metadata.google.internal/computeMetadata/v1/instance/attributes/app-war" -H "Metadata-Flavor: Google") + +gsutil cp "$GCS_APP_LOCATION"** . + +# Install dependencies from apt +apt-get update +apt install -t jessie-backports -yq openjdk-8-jre-headless ca-certificates-java +apt install -t jessie-backports -yq openjdk-8-jdk + +# Make Java8 the default +update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java + +# Jetty Setup +mkdir -p /opt/jetty/temp +mkdir -p /var/log/jetty + +# Get Jetty +curl -L https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-distribution/9.4.4.v20170414/jetty-distribution-9.4.4.v20170414.tar.gz -o jetty9.tgz +tar xf jetty9.tgz --strip-components=1 -C /opt/jetty + +# Add a Jetty User +useradd --user-group --shell /bin/false --home-dir /opt/jetty/temp jetty + +cd /opt/jetty +# Add running as "jetty" +java -jar /opt/jetty/start.jar --add-to-startd=setuid +cd / + +# very important - by renaming the war to root.war, it will run as the root servlet. +mv $WAR /opt/jetty/webapps/root.war + +# Make sure "jetty" owns everything. +chown --recursive jetty /opt/jetty + +# Configure the default paths for the Jetty service +cp /opt/jetty/bin/jetty.sh /etc/init.d/jetty +echo "JETTY_HOME=/opt/jetty" > /etc/default/jetty +{ + echo "JETTY_BASE=/opt/jetty" + echo "TMPDIR=/opt/jetty/temp" + echo "JAVA_OPTIONS=-Djetty.http.port=8080" + echo "JETTY_LOGS=/var/log/jetty" +} >> /etc/default/jetty + + +# Reload daemon to pick up new service +systemctl daemon-reload + +# Install logging monitor. The monitor will automatically pickup logs sent to syslog. +curl -s "https://storage.googleapis.com/signals-agents/logging/google-fluentd-install.sh" | bash +service google-fluentd restart & + +service jetty start +service jetty check + +echo "Startup Complete" +# [END startup_script_sh] diff --git a/memorystore/redis/gce_deployment/teardown.sh b/memorystore/redis/gce_deployment/teardown.sh new file mode 100755 index 00000000000..fe048c53cce --- /dev/null +++ b/memorystore/redis/gce_deployment/teardown.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Copyright 2018 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. +# [START teardown_sh] +gcloud compute instances delete my-instance + +gcloud compute firewall-rules delete allow-http-server-8080 +# [END teardown_sh] diff --git a/memorystore/redis/gke_deployment/Dockerfile b/memorystore/redis/gke_deployment/Dockerfile new file mode 100644 index 00000000000..be5f7e3c0f1 --- /dev/null +++ b/memorystore/redis/gke_deployment/Dockerfile @@ -0,0 +1,17 @@ +# Copyright 2018 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. + +FROM launcher.gcr.io/google/jetty + +ADD target/visitcounter-1.0-SNAPSHOT.war $JETTY_BASE/webapps/root.war diff --git a/memorystore/redis/gke_deployment/visit-counter.yaml b/memorystore/redis/gke_deployment/visit-counter.yaml new file mode 100644 index 00000000000..d10e98475e7 --- /dev/null +++ b/memorystore/redis/gke_deployment/visit-counter.yaml @@ -0,0 +1,39 @@ + +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: visit-counter + labels: + app: visit-counter +spec: + replicas: 1 + template: + metadata: + labels: + app: visit-counter + spec: + containers: + - name: visit-counter + image: "gcr.io//visit-counter:v1" + env: + - name: REDISHOST + valueFrom: + configMapKeyRef: + name: redishost + key: REDISHOST + ports: + - name: http + containerPort: 8080 +--- +apiVersion: v1 +kind: Service +metadata: + name: visit-counter +spec: + type: LoadBalancer + selector: + app: visit-counter + ports: + - port: 80 + targetPort: 8080 + protocol: TCP diff --git a/memorystore/redis/pom.xml b/memorystore/redis/pom.xml new file mode 100644 index 00000000000..52cb8dfc6db --- /dev/null +++ b/memorystore/redis/pom.xml @@ -0,0 +1,78 @@ + + + 4.0.0 + war + 1.0-SNAPSHOT + com.example.redis + visitcounter + + + + com.google.cloud.samples + shared-configuration + 1.0.8 + + + + 1.8 + 1.8 + 9.4.4.v20170414 + false + + + + + + + javax.servlet + javax.servlet-api + 3.1.0 + jar + provided + + + redis.clients + jedis + 2.9.0 + + + + + + + servlet/target/visitcounter-1.0-SNAPSHOT/WEB-INF/classes + + + + org.eclipse.jetty + jetty-maven-plugin + ${jetty} + + + + + com.google.cloud.tools + appengine-maven-plugin + 1.3.2 + + + + + diff --git a/memorystore/redis/src/main/java/com/example/redis/AppServletContextListener.java b/memorystore/redis/src/main/java/com/example/redis/AppServletContextListener.java new file mode 100644 index 00000000000..8d4c88fabe5 --- /dev/null +++ b/memorystore/redis/src/main/java/com/example/redis/AppServletContextListener.java @@ -0,0 +1,73 @@ +/* + * Copyright 2018 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. + */ +// [START web_listener] + +package com.example.redis; + +import java.io.IOException; +import java.util.Properties; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.annotation.WebListener; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolConfig; + +@WebListener +public class AppServletContextListener implements ServletContextListener { + + private Properties config = new Properties(); + + private JedisPool createJedisPool() throws IOException { + String host; + Integer port; + config.load( + Thread.currentThread() + .getContextClassLoader() + .getResourceAsStream("application.properties")); + host = config.getProperty("redis.host", "127.0.0.1"); + port = Integer.valueOf(config.getProperty("redis.port", "6379")); + + JedisPoolConfig poolConfig = new JedisPoolConfig(); + // Default : 8, consider how many concurrent connections into Redis you will need under load + poolConfig.setMaxTotal(128); + + return new JedisPool(poolConfig, host, port); + } + + @Override + public void contextDestroyed(ServletContextEvent event) { + JedisPool jedisPool = (JedisPool) event.getServletContext().getAttribute("jedisPool"); + if (jedisPool != null) { + jedisPool.destroy(); + event.getServletContext().setAttribute("jedisPool", null); + } + } + + // Run this before web application is started + @Override + public void contextInitialized(ServletContextEvent event) { + JedisPool jedisPool = (JedisPool) event.getServletContext().getAttribute("jedisPool"); + if (jedisPool == null) { + try { + jedisPool = createJedisPool(); + event.getServletContext().setAttribute("jedisPool", jedisPool); + } catch (IOException e) { + // handle exception + } + } + } +} +// [END web_listener] diff --git a/memorystore/redis/src/main/java/com/example/redis/VisitCounterServlet.java b/memorystore/redis/src/main/java/com/example/redis/VisitCounterServlet.java new file mode 100644 index 00000000000..4b5dd7cdc21 --- /dev/null +++ b/memorystore/redis/src/main/java/com/example/redis/VisitCounterServlet.java @@ -0,0 +1,53 @@ +/* + * Copyright 2018 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. + */ +// [START visit_servlet] + +package com.example.redis; + +import java.io.IOException; +import java.net.SocketException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +@WebServlet(name = "Track visits", value = "") +public class VisitCounterServlet extends HttpServlet { + + @Override + public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + try { + JedisPool jedisPool = (JedisPool) req.getServletContext().getAttribute("jedisPool"); + + if (jedisPool == null) { + throw new SocketException("Error connecting to Jedis pool"); + } + Long visits; + + try (Jedis jedis = jedisPool.getResource()) { + visits = jedis.incr("visits"); + } + + resp.setStatus(HttpServletResponse.SC_OK); + resp.getWriter().println("Visitor counter: " + String.valueOf(visits)); + } catch (Exception e) { + resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); + } + } +} +// [END visit_servlet] diff --git a/memorystore/redis/src/main/resources/application.properties b/memorystore/redis/src/main/resources/application.properties new file mode 100644 index 00000000000..89d1eca84c2 --- /dev/null +++ b/memorystore/redis/src/main/resources/application.properties @@ -0,0 +1,16 @@ +# Copyright 2018 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. + +redis.host=127.0.0.1 +redis.port=6379 \ No newline at end of file diff --git a/pom.xml b/pom.xml index deee7c101ea..b9d971b1e89 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,8 @@ monitoring/cloud-client monitoring/v3 + memorystore/redis + pubsub/cloud-client spanner/cloud-client From 937764ab178822c84d32ad113105e19784731809 Mon Sep 17 00:00:00 2001 From: Jisha Abubaker Date: Tue, 8 May 2018 21:26:51 -0700 Subject: [PATCH 2/3] Addressing review comments memorystore_ region tags --- memorystore/redis/flex_deployment/app.yaml | 6 +++--- memorystore/redis/gce_deployment/deploy.sh | 8 ++++---- .../redis/gce_deployment/startup-script.sh | 11 +++++------ memorystore/redis/gce_deployment/teardown.sh | 6 +++--- memorystore/redis/gke_deployment/Dockerfile | 2 +- .../redis/gke_deployment/visit-counter.yaml | 13 +++++++++++++ memorystore/redis/pom.xml | 15 +++++++-------- .../example/redis/AppServletContextListener.java | 4 ++-- .../com/example/redis/VisitCounterServlet.java | 2 +- .../src/main/resources/application.properties | 6 +++--- 10 files changed, 42 insertions(+), 31 deletions(-) diff --git a/memorystore/redis/flex_deployment/app.yaml b/memorystore/redis/flex_deployment/app.yaml index 05cc5023e4f..c49b943bf36 100644 --- a/memorystore/redis/flex_deployment/app.yaml +++ b/memorystore/redis/flex_deployment/app.yaml @@ -1,4 +1,4 @@ -# Copyright 2018 Google Inc. +# 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. @@ -11,7 +11,7 @@ # 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. -# [START app_yaml] +# [START memorystore_app_yaml] runtime: java env: flex -# [END app_yaml] +# [END memorystore_app_yaml] diff --git a/memorystore/redis/gce_deployment/deploy.sh b/memorystore/redis/gce_deployment/deploy.sh index 8e2a1cb0887..06f8e5ec21b 100755 --- a/memorystore/redis/gce_deployment/deploy.sh +++ b/memorystore/redis/gce_deployment/deploy.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright 2018 Google Inc. +# 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. @@ -13,7 +13,7 @@ # 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. -# [START deploy_sh] +# [START memorystore_deploy_sh] if [ -z "$GCS_APP_LOCATION" ]; then if [ -z "$BUCKET"]; then echo "Must set \$BUCKET. For example: BUCKET=my-bucket-name" @@ -43,7 +43,7 @@ cd gce_deployment # Create an instance gcloud compute instances create my-instance \ - --image-family=debian-8 \ + --image-family=debian-9 \ --image-project=debian-cloud \ --machine-type=g1-small \ --scopes cloud-platform \ @@ -57,4 +57,4 @@ gcloud compute firewall-rules create allow-http-server-8080 \ --source-ranges 0.0.0.0/0 \ --target-tags http-server \ --description "Allow port 8080 access to http-server" -# [END deploy_sh] +# [END memorystore_deploy_sh] diff --git a/memorystore/redis/gce_deployment/startup-script.sh b/memorystore/redis/gce_deployment/startup-script.sh index d688acedfad..5bd5ab72bbe 100644 --- a/memorystore/redis/gce_deployment/startup-script.sh +++ b/memorystore/redis/gce_deployment/startup-script.sh @@ -1,6 +1,6 @@ #! /bin/bash -# Copyright 2018 Google Inc. +# 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. @@ -13,7 +13,7 @@ # 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. -# [START startup_script_sh] +# [START memorystore_startup_script_sh] set -ex # Talk to the metadata server to get the project id and location of application binary. @@ -25,8 +25,7 @@ gsutil cp "$GCS_APP_LOCATION"** . # Install dependencies from apt apt-get update -apt install -t jessie-backports -yq openjdk-8-jre-headless ca-certificates-java -apt install -t jessie-backports -yq openjdk-8-jdk +apt-get install -qq openjdk-8-jdk-headless # Make Java8 the default update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java @@ -36,7 +35,7 @@ mkdir -p /opt/jetty/temp mkdir -p /var/log/jetty # Get Jetty -curl -L https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-distribution/9.4.4.v20170414/jetty-distribution-9.4.4.v20170414.tar.gz -o jetty9.tgz +curl -L https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-distribution/9.4.10.v20180503/jetty-distribution-9.4.10.v20180503.tar.gz -o jetty9.tgz tar xf jetty9.tgz --strip-components=1 -C /opt/jetty # Add a Jetty User @@ -75,4 +74,4 @@ service jetty start service jetty check echo "Startup Complete" -# [END startup_script_sh] +# [END memorystore_startup_script_sh] diff --git a/memorystore/redis/gce_deployment/teardown.sh b/memorystore/redis/gce_deployment/teardown.sh index fe048c53cce..8277a5ce712 100755 --- a/memorystore/redis/gce_deployment/teardown.sh +++ b/memorystore/redis/gce_deployment/teardown.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright 2018 Google Inc. +# 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. @@ -13,8 +13,8 @@ # 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. -# [START teardown_sh] +# [START memorystore_teardown_sh] gcloud compute instances delete my-instance gcloud compute firewall-rules delete allow-http-server-8080 -# [END teardown_sh] +# [END memorystore_teardown_sh] diff --git a/memorystore/redis/gke_deployment/Dockerfile b/memorystore/redis/gke_deployment/Dockerfile index be5f7e3c0f1..2026f71135e 100644 --- a/memorystore/redis/gke_deployment/Dockerfile +++ b/memorystore/redis/gke_deployment/Dockerfile @@ -1,4 +1,4 @@ -# Copyright 2018 Google Inc. +# 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. diff --git a/memorystore/redis/gke_deployment/visit-counter.yaml b/memorystore/redis/gke_deployment/visit-counter.yaml index d10e98475e7..a1fa7516158 100644 --- a/memorystore/redis/gke_deployment/visit-counter.yaml +++ b/memorystore/redis/gke_deployment/visit-counter.yaml @@ -1,3 +1,16 @@ +# 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 diff --git a/memorystore/redis/pom.xml b/memorystore/redis/pom.xml index 52cb8dfc6db..dc94e11472b 100644 --- a/memorystore/redis/pom.xml +++ b/memorystore/redis/pom.xml @@ -1,5 +1,5 @@ + - javax.servlet javax.servlet-api @@ -53,7 +52,7 @@ 2.9.0 - + @@ -65,14 +64,14 @@ jetty-maven-plugin ${jetty} - + com.google.cloud.tools appengine-maven-plugin 1.3.2 - + diff --git a/memorystore/redis/src/main/java/com/example/redis/AppServletContextListener.java b/memorystore/redis/src/main/java/com/example/redis/AppServletContextListener.java index 8d4c88fabe5..513ff8c331f 100644 --- a/memorystore/redis/src/main/java/com/example/redis/AppServletContextListener.java +++ b/memorystore/redis/src/main/java/com/example/redis/AppServletContextListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Google Inc. + * 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. @@ -37,7 +37,7 @@ private JedisPool createJedisPool() throws IOException { Thread.currentThread() .getContextClassLoader() .getResourceAsStream("application.properties")); - host = config.getProperty("redis.host", "127.0.0.1"); + host = config.getProperty("redis.host"); port = Integer.valueOf(config.getProperty("redis.port", "6379")); JedisPoolConfig poolConfig = new JedisPoolConfig(); diff --git a/memorystore/redis/src/main/java/com/example/redis/VisitCounterServlet.java b/memorystore/redis/src/main/java/com/example/redis/VisitCounterServlet.java index 4b5dd7cdc21..5f66e69ad3b 100644 --- a/memorystore/redis/src/main/java/com/example/redis/VisitCounterServlet.java +++ b/memorystore/redis/src/main/java/com/example/redis/VisitCounterServlet.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Google Inc. + * 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. diff --git a/memorystore/redis/src/main/resources/application.properties b/memorystore/redis/src/main/resources/application.properties index 89d1eca84c2..fc1a1a3ef54 100644 --- a/memorystore/redis/src/main/resources/application.properties +++ b/memorystore/redis/src/main/resources/application.properties @@ -1,4 +1,4 @@ -# Copyright 2018 Google Inc. +# 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. @@ -12,5 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. -redis.host=127.0.0.1 -redis.port=6379 \ No newline at end of file +redis.host=REDIS_HOST_IP +redis.port=6379 From 076722ef9b5af9aa83b10296dd611232e285dfee Mon Sep 17 00:00:00 2001 From: Jisha Abubaker Date: Tue, 8 May 2018 21:41:28 -0700 Subject: [PATCH 3/3] Adding README links --- memorystore/redis/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/memorystore/redis/README.md b/memorystore/redis/README.md index fbef96ad1d7..e2de0f60232 100644 --- a/memorystore/redis/README.md +++ b/memorystore/redis/README.md @@ -1,17 +1,17 @@ # Getting started with Googe Cloud Memorystore -Simple HTTP server example to demonstrate connecting to Google Cloud Memorystore. +Simple HTTP server example to demonstrate connecting to [Google Cloud Memorystore](https://cloud.google.com/memorystore/docs/redis) This sample uses the [Jedis client](https://mvnrepository.com/artifact/redis.clients/jedis). Please see other client library options [here](https://redis.io/clients#java). ## Running on GCE -Follow the instructions in [this guide](TODO-UPDATE-LINK) to deploy the sample application on a GCE VM. +Follow the instructions in [this guide](https://cloud.google.com/memorystore/docs/redis/connect-redis-instance-gce) to deploy the sample application on a GCE VM. ## Running on GKE -Follow the instructions in [this guide](TODO-UPDATE-LINK) to deploy the sample application on GKE. +Follow the instructions in [this guide](https://cloud.google.com/memorystore/docs/redis/connect-redis-instance-gke) to deploy the sample application on GKE. ## Running on Google App Engine Flex -Follow the instructions in [this guide](TODO-UPDATE-LINK) to deploy the sample application on GKE. +Follow the instructions in [this guide](https://cloud.google.com/memorystore/docs/redis/connect-redis-instance-flex) to deploy the sample application on GAE Flex.