Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

googlearchive/cloud-debugger-gce-java-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

status: inactive

This project is no longer actively developed or maintained.

Cloud Debug for Compute Engine sample

cloud-debugger-gce-java-sample

This sample shows how to add the ability to debug your Java application running on Google Compute Engine. It is based on the Spark Java - a tiny Sinatra inspired framework for creating web applications in Java 8.

This application just listens on port 8080 for requests and says "hello world" with a counter. You can ask that a Cloud Debugger snapshot be generated on any line.

Preperation

  1. Download & install the Cloud SDK

  2. Create a project (if you don't have one already) using the Developers Console.

  3. If you haven't already, use:

    $ gcloud init

  4. Create a bucket (Storage > Cloud Storage > Browser > Create bucket) or using the command line:

    $ gsutil mb <bucketName>

  5. Connect with your Cloud Source Repository using:

    $ gcloud beta source repos clone default <directoryName>

  6. Copy this project, skiping any .git files by using:

    rsync -av --exclude=".*" <src> <directoryName>

  7. go into your directory:

    $ cd <directoryName>

Deploying

  1. Commit and push the project to the Source Repository:

    $ git add *
    $ git commit -m 'Initial Commit'
    $ git push origin master

  2. Build the project

    $ mvn package -Dbucket=<bucketName>

In addition to the normal compiling of classes and building of jars, we add to the process-resources phase the following:

gcloud app gen-repo-info-file -\-output-file=target/project-1.0-SNAPSHOT/WEB-INF/classes/source-context.json

Which helps tell the Cloud Debugger which version of your source code to associate with this execution as you can have many.

  1. Deploy your application using:

    $ mvn deploy -Dbucket=<bucketName>

Deploy will first copy the startup script and the jar to the bucket using gsutil. Then it will create a new instance using:

gcloud compute instances create cdb --image debian-8 --metadata startup-script-url=gs://bucket/start.sh,my-bucket=gs://bucket --scopes cloud-platform

For this application, it is important that we use debian-8 (Jessie) as it will allow us to use Java 8 easily.

The startup script installs the Java 8 open jdk, uses update-alternatives to tell the system to default to Java 8 and gets a copy of the jar from the bucket.

The next steps are to setup the Cloud Debugger. The first two lines get the latest version of the debugger bootstrap script and make it executable.

wget -q https://storage.googleapis.com/cloud-debugger/compute-java/format_env_gce.sh chmod +x format_env_gce.sh

This next line executes that script passing a copy of the jar, and the return Java command line arguments

CDBG_ARGS="$( sudo ./format_env_gce.sh --app_class_path=hellosparky-1.0-SNAPSHOT-jar-with-dependencies.jar )"

Finally we startup the code using, it will listen on port 8080:

java ${CDBG_ARGS} -cp sparky/hellosparky-1.0-SNAPSHOT-jar-with-dependencies.jar com.example.hellosparky.App

Run Locally

java -cp target/hellosparky-1.0-SNAPSHOT-jar-with-dependencies.jar com.example.hellosparky.App
  1. Visit the application at http://localhost:8080.

Contributing changes

Licensing

About

SparkJava based sample that shows how to use the Google Cloud Debugger

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •