From a9732d8851467f4d11a5fb22fa2451b1c4b9742b Mon Sep 17 00:00:00 2001 From: Shun Fan Date: Tue, 1 Mar 2016 11:35:11 -0800 Subject: [PATCH] Remove cloudsql for now --- managed_vms/cloudsql/README.md | 16 ---- managed_vms/cloudsql/pom.xml | 66 -------------- .../cloudsql/src/main/appengine/app.yaml | 12 --- .../managedvms/cloudsql/CloudSqlServlet.java | 87 ------------------- 4 files changed, 181 deletions(-) delete mode 100644 managed_vms/cloudsql/README.md delete mode 100644 managed_vms/cloudsql/pom.xml delete mode 100644 managed_vms/cloudsql/src/main/appengine/app.yaml delete mode 100644 managed_vms/cloudsql/src/main/java/com/example/managedvms/cloudsql/CloudSqlServlet.java diff --git a/managed_vms/cloudsql/README.md b/managed_vms/cloudsql/README.md deleted file mode 100644 index fbbbd58dd81..00000000000 --- a/managed_vms/cloudsql/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# Cloud SQL sample for Google Managed VMs -This sample demonstrates how to use [Cloud SQL](https://cloud.google.com/sql/) on Google Managed VMs -## Setup -Before you can run or deploy the sample, you will need to do the following: -1. Create a Cloud SQL instance. You can do this from the [Google Developers Console](https://console.developers.google.com) or via the [Cloud SDK](https://cloud.google.com/sdk). To create it via the SDK use the following command: - $ gcloud sql instances create [your-instance-name] \ - --assign-ip \ - --authorized-networks 0.0.0.0/0 \ - --tier D0 -1. Create a new user and database for the application. The easiest way to do this is via the [Google Developers Console](https://console.developers.google.com/project/_/sql/instances/example-instance2/access-control/users). Alternatively, you can use MySQL tools such as the command line client or workbench. -## Running locally -1. Update the connection string in ``appengine-web.xml`` with your local MySQL instance values. - $ mvn clean jetty:run -## Deploying -1. Update the connection string in ``appengine-web.xml`` with your Cloud SQL instance values. - $ mvn clean gcloud:deploy diff --git a/managed_vms/cloudsql/pom.xml b/managed_vms/cloudsql/pom.xml deleted file mode 100644 index 2fe8c74d4aa..00000000000 --- a/managed_vms/cloudsql/pom.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - 4.0.0 - war - 1.0-SNAPSHOT - com.example.managedvms - managed-vms-cloudsql - - - doc-samples - com.google.cloud - 1.0.0 - ../.. - - - - - javax.servlet - javax.servlet-api - 3.1.0 - jar - provided - - - - mysql - mysql-connector-java - 5.1.38 - - - - - - ${project.build.directory}/${project.build.finalName}/WEB-INF/classes - - - com.google.appengine - gcloud-maven-plugin - 2.0.9.95.v20160203 - - - org.apache.maven.plugins - maven-war-plugin - 2.6 - - false - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.3 - - 1.8 - 1.8 - - - - org.eclipse.jetty - jetty-maven-plugin - 9.3.7.v20160115 - - - - diff --git a/managed_vms/cloudsql/src/main/appengine/app.yaml b/managed_vms/cloudsql/src/main/appengine/app.yaml deleted file mode 100644 index dfcc0f70120..00000000000 --- a/managed_vms/cloudsql/src/main/appengine/app.yaml +++ /dev/null @@ -1,12 +0,0 @@ -runtime: java -vm: true - -handlers: -- url: /.* - script: this field is required, but ignored - secure: always - -# [START env_variables] -env_variables: - SQL_DATABASE_URL: jdbc:mysql://HOST-IP:3306/YOUR-DB-NAME?user=USERNAME&password=PASSWORD -# [END env_variables] diff --git a/managed_vms/cloudsql/src/main/java/com/example/managedvms/cloudsql/CloudSqlServlet.java b/managed_vms/cloudsql/src/main/java/com/example/managedvms/cloudsql/CloudSqlServlet.java deleted file mode 100644 index 04cb9aebbd5..00000000000 --- a/managed_vms/cloudsql/src/main/java/com/example/managedvms/cloudsql/CloudSqlServlet.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright 2015 Google Inc. All Rights Reserved. - * - * 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. - */ - -package com.example.managedvms.cloudsql; - -import java.io.IOException; -import java.io.PrintWriter; -import java.net.Inet4Address; -import java.net.Inet6Address; -import java.net.InetAddress; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.Date; - -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -// [START example] -@SuppressWarnings("serial") -@WebServlet(name = "cloudsql", value = "") -public class CloudSqlServlet extends HttpServlet { - - @Override - public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, - ServletException { - // store only the first two octets of a users ip address - String userIp = req.getRemoteAddr(); - InetAddress address = InetAddress.getByName(userIp); - if (address instanceof Inet6Address) { - // nest indexOf calls to find the second occurrence of a character in a string - // an alternative is to use Apache Commons Lang: StringUtils.ordinalIndexOf() - userIp = userIp.substring(0, userIp.indexOf(":", userIp.indexOf(":") + 1)) + ":*:*:*:*:*:*"; - } else if (address instanceof Inet4Address) { - userIp = userIp.substring(0, userIp.indexOf(".", userIp.indexOf(".") + 1)) + ".*.*"; - } - - final String createTableSql = "CREATE TABLE IF NOT EXISTS visits ( visit_id INT NOT NULL " - + "AUTO_INCREMENT, user_ip VARCHAR(46) NOT NULL, timestamp DATETIME NOT NULL, " - + "PRIMARY KEY (visit_id) )"; - final String createVisitSql = "INSERT INTO visits (user_ip, timestamp) VALUES (?, ?)"; - final String selectSql = "SELECT user_ip, timestamp FROM visits ORDER BY timestamp DESC " - + "LIMIT 10"; - PrintWriter out = resp.getWriter(); - resp.setContentType("text/plain"); - String url = System.getenv("SQL_DATABASE_URL"); - - try (Connection conn = DriverManager.getConnection(url); - PreparedStatement statementCreateVisit = conn.prepareStatement(createVisitSql)) { - conn.createStatement().executeUpdate(createTableSql); - statementCreateVisit.setString(1, userIp); - statementCreateVisit.setTimestamp(2, new Timestamp(new Date().getTime())); - statementCreateVisit.executeUpdate(); - - try (ResultSet rs = conn.prepareStatement(selectSql).executeQuery()) { - out.print("Last 10 visits:\n"); - while (rs.next()) { - String savedIp = rs.getString("user_ip"); - String timeStamp = rs.getString("timestamp"); - out.print("Time: " + timeStamp + " Addr: " + savedIp + "\n"); - } - } - } catch (SQLException e) { - throw new ServletException("SQL error", e); - } - } -} -// [END example]