SlideShare a Scribd company logo
GAE Developer - Day4
Simon @ MiCloud
2014Q1
Last Class
● Memcache basic
● Task Queue concept
● Push Queue
● Pull Queue
● Create a Bucket
● Create a CloudSQL
Before Today
Create a Bucket
$ gcloud auth login
$ gcloud config set project [my-project-id]
$ gsutil mb gs://[my-bucket]
$ gsutil ls gs://[my-bucket]
Sample Database
http://www.mysqltutorial.org/mysql-sample-database.aspx
Create a CloudSQL
$ gcloud sql -h
$ gcloud sql instances create [inst-name]
$ gcloud sql instances list
$ gcloud sql instances import instance-name --uri 
gs://your-bucket/sql-dump-file.gz
$ gcloud sql instances patch --assign-ip [inst-name]
$ gcloud sql instances get [inst-name]
Create a CloudSQL
$ gcloud sql instances set-root-password test-sql 
-p [password]
$ gcloud sql instances patch test-sql 
--authorized-networks=[your-ip-address]
Connect Cloud SQL - MySQL Workbench
http://www.mysql.com/products/workbench/
Today
● Use CloudStorage - BlobStore
● Connect CloudSQL
Using Cloud Storage
Use CloudStorage - BlobStore
Create Upload Url
BlobstoreService blobstoreService =
BlobstoreServiceFactory.getBlobstoreService();
UploadOptions uploadOptions =
UploadOptions.Builder.withGoogleStorageBucketName(
"BUCKET-NAME"); //Name without “gs://”
String uploadUrl = blobstoreService.createUploadUrl(
"/callback-url", uploadOptions);
resp.getWriter().println("<form action=" + uploadUrl
+ " method="post" enctype="multipart/form-data">");
resp.getWriter().println("<input type="file" name="field-name"");
public void doPost(HttpServletRequest req,
HttpServletResponse resp) throws IOException {
BlobstoreService blobstoreService =
BlobstoreServiceFactory.getBlobstoreService();
Map<String, List<FileInfo>> blobs = blobstoreService.getFileInfos(req);
List<FileInfo> keys = blobs.get("field-name"); //input file name on
form
if (keys != null && keys.size() > 0) {
FileInfo fileKey = keys.get(0);
String objectUploaded = fileKey.getGsObjectName();
…. (Save the objectUploaded mapping to datastore or database)
Create Callback Handler
Serving Data
public void doGet(HttpServletRequest req, HttpServletResponse resp){
BlobstoreService blobstoreService =
BlobstoreServiceFactory.getBlobstoreService();
BlobKey blobKey =
blobstoreService.createGsBlobKey("/gs/<bucket>/<object>");
try {
blobstoreService.serve(blobKey, resp);
} catch (IOException e){
e.printStackTrace();
}
….
Other Storage API
● Image API
● Cloud Storage Client Library
Connect Cloud SQL
Before Connect
● CloudSQL instance ready
● Authorized
○ root password
○ instance ip address
○ access ip address
Configure Connectors
● Hostname is Cloud SQL instance IP address
● Connection URL includes instance IP and
database name
● Java connection is:
jdbc:mysql://<instance-ip>:3306/
Local Test Configure
appengine-web.xml
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>mitac-cp300</application>
<version>eord</version>
….
<use-google-connector-j>true</use-google-connector-j>
….
</appengine-web-app>
Connect from App Engine
● JDBC
● Java Persistence API (JPA)
● Java Data Objects (JDO)
● Other JPAs custom additions: Hibernate, EclipseLink
jdbc:google:mysql://...
(instead of jdbc:mysql://...)
Detect running environment
Connection conn = null;
if (SystemProperty.environment.value() ==
SystemProperty.Environment.Value.Production) {
// app is running in production
Class.forName("com.mysql.jdbc.GoogleDriver");
String url= "jdbc:google:mysql://instance-name/";
conn = DriverManager.getConnection(url);
...
} else {
// app is running on localhost
Class.forName("com.mysql.jdbc.Driver");
String url= "jdbc:mysql://db-ip-address/";
conn = DriverManager.getConnection(url);
...
}
conn.~
DriverManager.registerDriver(new AppEngineDriver());
conn = DriverManager.getConnection(connUrl);
String sql = "SELECT count(*) as total FROM " + tableName + "";
PreparedStatement stmt = conn.prepareStatement(sql);
ResultSet results = stmt.executeQuery();
while (results.next()) {
int total = results.getInt("total");
…
}
Query Example - Standard JDBC
Other Frameworks
Popular frameworks for programming MySQL
● Hibernate (Java)
● JOOQ (Java)
● JPA ( Java )
● Django (Python)
Google App Engine Developer - Day4

More Related Content

PPT
SharePoint Administration with PowerShell
PDF
Docker in Action
PPTX
Scalable network applications, event-driven - Node JS
PPTX
Event-driven IO server-side JavaScript environment based on V8 Engine
PDF
Node.js 與 google cloud storage
PDF
GCPUG meetup 201610 - Dataflow Introduction
PDF
David Fetter, Disqus
PDF
Nodejs - A-quick-tour-v3
SharePoint Administration with PowerShell
Docker in Action
Scalable network applications, event-driven - Node JS
Event-driven IO server-side JavaScript environment based on V8 Engine
Node.js 與 google cloud storage
GCPUG meetup 201610 - Dataflow Introduction
David Fetter, Disqus
Nodejs - A-quick-tour-v3

What's hot (20)

PDF
高性能かつスケールアウト可能なHPCクラウド AIST Super Green Cloud
PDF
1027 predictive models in 10 seconds, by David Pardo Villaverde, Corunet
PDF
Device Synchronization with Javascript and PouchDB
PDF
Dirty - How simple is your database?
KEY
Node.js - As a networking tool
PPT
Intergalactic data speak_highload++_20131028
PDF
Philipp Krenn "Elasticsearch (R)Evolution — You Know, for Search…"
PDF
Nodejs - A quick tour (v4)
PDF
ClickHouse Monitoring 101: What to monitor and how
PPT
jclouds overview
KEY
Node.js - A practical introduction (v2)
PDF
AWS user group Serverless in September - Chris Johnson Bidler "Go Serverless ...
PDF
Presto in Treasure Data (presented at db tech showcase Sapporo 2015)
PDF
CouchDB Mobile - From Couch to 5K in 1 Hour
PDF
FleetDB: A Schema-Free Database in Clojure
PDF
Nodejs - Should Ruby Developers Care?
PDF
XWiki: The best wiki for developers
PDF
ClickHouse on Kubernetes! By Robert Hodges, Altinity CEO
PDF
MongoDB .local Paris 2020: Adéo @MongoDB : MongoDB Atlas & Leroy Merlin : et ...
PDF
Nodejs a-practical-introduction-oredev
高性能かつスケールアウト可能なHPCクラウド AIST Super Green Cloud
1027 predictive models in 10 seconds, by David Pardo Villaverde, Corunet
Device Synchronization with Javascript and PouchDB
Dirty - How simple is your database?
Node.js - As a networking tool
Intergalactic data speak_highload++_20131028
Philipp Krenn "Elasticsearch (R)Evolution — You Know, for Search…"
Nodejs - A quick tour (v4)
ClickHouse Monitoring 101: What to monitor and how
jclouds overview
Node.js - A practical introduction (v2)
AWS user group Serverless in September - Chris Johnson Bidler "Go Serverless ...
Presto in Treasure Data (presented at db tech showcase Sapporo 2015)
CouchDB Mobile - From Couch to 5K in 1 Hour
FleetDB: A Schema-Free Database in Clojure
Nodejs - Should Ruby Developers Care?
XWiki: The best wiki for developers
ClickHouse on Kubernetes! By Robert Hodges, Altinity CEO
MongoDB .local Paris 2020: Adéo @MongoDB : MongoDB Atlas & Leroy Merlin : et ...
Nodejs a-practical-introduction-oredev
Ad

Similar to Google App Engine Developer - Day4 (20)

PDF
GAE for PHP - Google Cloud SQL and Cloud Storage
PDF
Google Cloud Platform 2014Q1 - Starter Guide
PPTX
Google developers consoles
PDF
GCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic Training
PDF
Magellan on Google Cloud Platform
PDF
Java Web Programming on Google Cloud Platform [2/3] : Datastore
PDF
Google App Engine Developer - Day2
PDF
Introduction to Datastore
PDF
Cannibalising The Google App Engine
PPTX
File Repository on GAE
PDF
Google Cloud Platform - Building a scalable mobile application
PDF
Google Cloud Platform - Building a scalable Mobile Application
PDF
Google cloud platform Introduction - 2014
PPTX
Intro to the Google Cloud for Developers
PDF
Cloud platform overview for camping
PPTX
Google app engine by example
PDF
Google App Engine
PDF
Google Developer Days Brazil 2009 - Java Appengine
PDF
Easy integration of Bluemix services with your applications
PDF
Introduction to Google's Cloud Technologies
GAE for PHP - Google Cloud SQL and Cloud Storage
Google Cloud Platform 2014Q1 - Starter Guide
Google developers consoles
GCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic Training
Magellan on Google Cloud Platform
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Google App Engine Developer - Day2
Introduction to Datastore
Cannibalising The Google App Engine
File Repository on GAE
Google Cloud Platform - Building a scalable mobile application
Google Cloud Platform - Building a scalable Mobile Application
Google cloud platform Introduction - 2014
Intro to the Google Cloud for Developers
Cloud platform overview for camping
Google app engine by example
Google App Engine
Google Developer Days Brazil 2009 - Java Appengine
Easy integration of Bluemix services with your applications
Introduction to Google's Cloud Technologies
Ad

More from Simon Su (20)

PDF
Kubernetes Basic Operation
PDF
Google IoT Core 初體驗
PDF
JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
PDF
GCPUG.TW meetup #28 - GKE上運作您的k8s服務
PDF
Google Cloud Platform Special Training
PDF
GCE Windows Serial Console Usage Guide
PDF
GCPNext17' Extend 開始GCP了嗎?
PDF
Try Cloud Spanner
PDF
Google Cloud Monitoring
PDF
Google Cloud Computing compares GCE, GAE and GKE
PDF
JCConf 2016 - Google Dataflow 小試
PDF
JCConf 2016 - Dataflow Workshop Labs
PDF
JCConf2016 - Dataflow Workshop Setup
PDF
Brocade - Stingray Application Firewall
PDF
使用 Raspberry pi + fluentd + gcp cloud logging, big query 做iot 資料搜集與分析
PDF
Google I/O 2016 Recap - Google Cloud Platform News Update
PDF
IThome DevOps Summit - IoT、docker與DevOps
PDF
Google Cloud Platform Introduction - 2016Q3
PDF
Google I/O Extended 2016 - 台北場活動回顧
PPTX
GCS - Access Control Lists (中文)
Kubernetes Basic Operation
Google IoT Core 初體驗
JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
GCPUG.TW meetup #28 - GKE上運作您的k8s服務
Google Cloud Platform Special Training
GCE Windows Serial Console Usage Guide
GCPNext17' Extend 開始GCP了嗎?
Try Cloud Spanner
Google Cloud Monitoring
Google Cloud Computing compares GCE, GAE and GKE
JCConf 2016 - Google Dataflow 小試
JCConf 2016 - Dataflow Workshop Labs
JCConf2016 - Dataflow Workshop Setup
Brocade - Stingray Application Firewall
使用 Raspberry pi + fluentd + gcp cloud logging, big query 做iot 資料搜集與分析
Google I/O 2016 Recap - Google Cloud Platform News Update
IThome DevOps Summit - IoT、docker與DevOps
Google Cloud Platform Introduction - 2016Q3
Google I/O Extended 2016 - 台北場活動回顧
GCS - Access Control Lists (中文)

Recently uploaded (20)

PDF
NewMind AI Monthly Chronicles - July 2025
PPT
Teaching material agriculture food technology
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Encapsulation theory and applications.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
NewMind AI Monthly Chronicles - July 2025
Teaching material agriculture food technology
Understanding_Digital_Forensics_Presentation.pptx
Empathic Computing: Creating Shared Understanding
Diabetes mellitus diagnosis method based random forest with bat algorithm
The AUB Centre for AI in Media Proposal.docx
Encapsulation theory and applications.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Modernizing your data center with Dell and AMD
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Big Data Technologies - Introduction.pptx
A Presentation on Artificial Intelligence
Mobile App Security Testing_ A Comprehensive Guide.pdf
Review of recent advances in non-invasive hemoglobin estimation
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation_ Review paper, used for researhc scholars

Google App Engine Developer - Day4

  • 1. GAE Developer - Day4 Simon @ MiCloud 2014Q1
  • 2. Last Class ● Memcache basic ● Task Queue concept ● Push Queue ● Pull Queue
  • 3. ● Create a Bucket ● Create a CloudSQL Before Today
  • 4. Create a Bucket $ gcloud auth login $ gcloud config set project [my-project-id] $ gsutil mb gs://[my-bucket] $ gsutil ls gs://[my-bucket]
  • 6. Create a CloudSQL $ gcloud sql -h $ gcloud sql instances create [inst-name] $ gcloud sql instances list $ gcloud sql instances import instance-name --uri gs://your-bucket/sql-dump-file.gz $ gcloud sql instances patch --assign-ip [inst-name] $ gcloud sql instances get [inst-name]
  • 7. Create a CloudSQL $ gcloud sql instances set-root-password test-sql -p [password] $ gcloud sql instances patch test-sql --authorized-networks=[your-ip-address]
  • 8. Connect Cloud SQL - MySQL Workbench http://www.mysql.com/products/workbench/
  • 9. Today ● Use CloudStorage - BlobStore ● Connect CloudSQL
  • 11. Use CloudStorage - BlobStore
  • 12. Create Upload Url BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService(); UploadOptions uploadOptions = UploadOptions.Builder.withGoogleStorageBucketName( "BUCKET-NAME"); //Name without “gs://” String uploadUrl = blobstoreService.createUploadUrl( "/callback-url", uploadOptions); resp.getWriter().println("<form action=" + uploadUrl + " method="post" enctype="multipart/form-data">"); resp.getWriter().println("<input type="file" name="field-name"");
  • 13. public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService(); Map<String, List<FileInfo>> blobs = blobstoreService.getFileInfos(req); List<FileInfo> keys = blobs.get("field-name"); //input file name on form if (keys != null && keys.size() > 0) { FileInfo fileKey = keys.get(0); String objectUploaded = fileKey.getGsObjectName(); …. (Save the objectUploaded mapping to datastore or database) Create Callback Handler
  • 14. Serving Data public void doGet(HttpServletRequest req, HttpServletResponse resp){ BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService(); BlobKey blobKey = blobstoreService.createGsBlobKey("/gs/<bucket>/<object>"); try { blobstoreService.serve(blobKey, resp); } catch (IOException e){ e.printStackTrace(); } ….
  • 15. Other Storage API ● Image API ● Cloud Storage Client Library
  • 17. Before Connect ● CloudSQL instance ready ● Authorized ○ root password ○ instance ip address ○ access ip address
  • 18. Configure Connectors ● Hostname is Cloud SQL instance IP address ● Connection URL includes instance IP and database name ● Java connection is: jdbc:mysql://<instance-ip>:3306/
  • 19. Local Test Configure appengine-web.xml <?xml version="1.0" encoding="utf-8"?> <appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> <application>mitac-cp300</application> <version>eord</version> …. <use-google-connector-j>true</use-google-connector-j> …. </appengine-web-app>
  • 20. Connect from App Engine ● JDBC ● Java Persistence API (JPA) ● Java Data Objects (JDO) ● Other JPAs custom additions: Hibernate, EclipseLink jdbc:google:mysql://... (instead of jdbc:mysql://...)
  • 21. Detect running environment Connection conn = null; if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) { // app is running in production Class.forName("com.mysql.jdbc.GoogleDriver"); String url= "jdbc:google:mysql://instance-name/"; conn = DriverManager.getConnection(url); ... } else { // app is running on localhost Class.forName("com.mysql.jdbc.Driver"); String url= "jdbc:mysql://db-ip-address/"; conn = DriverManager.getConnection(url); ... } conn.~
  • 22. DriverManager.registerDriver(new AppEngineDriver()); conn = DriverManager.getConnection(connUrl); String sql = "SELECT count(*) as total FROM " + tableName + ""; PreparedStatement stmt = conn.prepareStatement(sql); ResultSet results = stmt.executeQuery(); while (results.next()) { int total = results.getInt("total"); … } Query Example - Standard JDBC
  • 23. Other Frameworks Popular frameworks for programming MySQL ● Hibernate (Java) ● JOOQ (Java) ● JPA ( Java ) ● Django (Python)