Skip to content

Latest commit

 

History

History
 
 

managed-vm-gae

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Cloud Bigtable for Managed VM's using GAE APIs
(Hello World for Cloud Bigtable)

AppEngine runtime has full access to AppEngine Services and API's, but can only be run in the Cloud.

This app provides:

  1. A web interface that uses Cloud Bigtable to track the number of visits from an opaque version of your Google account.
  2. A simple REST interface that can read and write arbitrary data to a Cloud Bigtable table using GET, POST, and DELETE verbs.

SECURITY WARNING - This app will read / write the two tables you create (gae-hello and from-json) The app provides NO ADDITIONAL SECURITY PROTECTIONS. We suggest that instances should only be available while testing and that test data be used.

Table of Contents

  1. Requirements
  2. Project Setup
  3. Deploying the AppEngine Runtime
  4. AppEngine Debugging Hints
  5. Using Bigtable-Hello
  6. Using-JSON

Requirements

  1. Latest version of gcloud Update with gcloud components update
  2. Java 1.8
  3. Maven

Project Setup

  1. Follow the instructions for Creating a Google Developers Console project and client ID

  2. Use Cloud Console to enable billing.

  3. Select APIs & Auth > APIs

  4. Enable the Cloud Bigtable API and the Cloud Bigtable Admin API
    (You may need to search for the API.)

  5. Select APIs & Auth > Credentials

  6. Select Generate new JSON key

  7. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to point to your json key

Many users find it helpful to add to either their .bash_rc or .profile the line:
export GOOGLE_APPLICATION_CREDENTIALS=~/path_to_key.json

Also copy the client-secret.json to src/main/webapp/WEB-INF/client-secret.json Note - this step isn't technically required, but it will help when we get local debugging working.

  1. Select Storage > Cloud Bigtable > New Cluster

Create a new Cluster -- You will need both the Zone and the Unique ID

  1. Using gcloud, login.

gcloud auth login

  1. Follow the instructions to launch hbase shell

  2. Create the table (tableName, Column Family)

create 'gae-hello', 'visits'
create 'from-json', 'cf1', 'cf2', 'cf3', 'cf4' exit

Deploying the AppEngine Runtime

  1. Edit src/main/webapp/WEB-INF/appengine-web.xml to set BIGTABLE_PROJECT, BIGTABLE_CLUSTER, and BIGTABLE_ZONE (if necessary)

  2. Build the java artifacts and docker image

    mvn clean compile process-resources war:exploded
    Note - you can use mvn pacakge but you'll get an ignorable error on the next step.

  3. Deploy the application

    mvn gcloud:deploy

  4. go to the new default module which will be displayed in results from the deploy. It will look like: https://20150624t111224-dot-default-dot-PROJECTID.appspot.com you can go to that url to test.

  5. Or run locally. First, copy your Service Acccount JSON file into src/main/webapp/WEB-INFO, and uncomment the GOOGLE_APPLICATION_CREDENTIALS file in src/main/webapp/appengine-web.xml, then rerun:

    mvn clean compile process-resources war:exploded

    then

    mvn gcloud:run

  6. After you run locally, you can access the app at http://localhost:8080

AppEngine Debugging Hints

The first thing to do, if you'd like to debug is use the servlet.log() methods, they seem to work when other loggers don't. Then take control of your GAE instance:

  1. Find your instance gcloud preview app modules list

  2. Change the management of the instances

  3. SSH to the instance

  4. Find the Container

  5. Either show the container log docker logs <containerID> or enter the container docker exec -it <containerID> /bin/bash

Using Bigtable-Hello

  1. With your browser, go to docker:8080 (Mac) or localhost:8080 (Linux) in your browser. (Local) Or to https://.appspot.com

  2. Sign-in with Google. Afterwards, your visit should increment the counter.

Using JSON

  1. Entities (rows) can be accessed using //projectID.appspot.com/json/rowkey
  • GET - Will wrap up everything as JSON
  • POST - Will convert the JSON to ColumnFamily : Qualifier and write the data
  • DELETE - Will remove the row.
  1. The URL should be either localhost:8080, docker:8080, or https://.appspot.com

  2. curl -H "Content-Type: application/json" -X POST -d '{"username":"red","id":535}' http://localhost:8080/json/blueword

  3. curl -X GET http://localhost:8080/json/blueword

  4. curl -H "Content-Type: application/json" -X DELETE http://localhost:8080/json/blueword

You will note that none of these examples use Column Family specifiers. It defaults to using cf1, if you wish to use the other column families specify <columnFamily>:<column> where columnFamily is one of cf1, cf2, cf3, or cf4 that you created earlier.