CREATE TABLE IF NOT EXISTS patients ( id SERIAL PRIMARY KEY,

Cloud Computing: Running Applications on App Engine Initial Setup:

Read the following link about setting up a Java environment for building apps. Follow the steps to install the Eclipse Plugin.

Once setup switch to Google Cloud. Open the patient-app project created in Lab #1. In the navigation menu (upper-left three stacked vertical bars) open App Engine. You will be brought to this page:

Click on Create Application Under region select us-east1 and then click Next. You will be brought to a Get started page.

Under Language select Java. Under Environment select Standard. Click Next. You will be brought to a page with additional options. Select I'll Do This Later or explore the additional steps such as viewing the documentation.

Step 1: Deploying a Simple Web Application Read the following link on how to run static content in the App Engine With the app engine setup, we can now run an application in the cloud. Open Eclipse and import the following repo: . This repo contains two projects that we will run and deploy. When imported open the first project patient-app-1. This project runs a simple web application. Look through the project to see how things are structured and should run. This application was created using Eclipse : File, New, Google App Engine Standard (try it). Open the pom.xml file and edit the field under properties. This is the name of your project on GCP. This can be found on the homepage of your GCP project.

Do not change app.deploy.version. GCLOUD_CONFIG allows GCP to determine the version number of your application when deploying. Each deploy will have a version number.

Open a terminal and cd to the directory containing patient-app-1. We can run apps both locally and on the app engine server. Run the app locally by running mvn package appengine:run. This will build the application and then run it. You can access the application by going to .

Once the application successfully runs deploy it on the app engine. To deploy run the following command: mvn package appengine:deploy. Once deployed you can view your app by typing gcloud app browse or visit url http://[YOUR_PROJECT_ID].

The application when running both deployed and locally should look like this:

Step 2: Deploying a Java Web Application Open the patient-app-2 project. This project contains a working example of a web application that works with the patient database created in Lab #1. If you have deleted the DB, then create a new Google Cloud Postgres DB instance and create the ghs database. You do not need to create the patient table. If you already have a ghs DB with a patients table, then it must be set up so the id is automatically created by the DB. Specifically, this command: CREATE TABLE IF NOT EXISTS patients ( id SERIAL PRIMARY KEY, firstName VARCHAR(255), lastName VARCHAR(255), gender VARCHAR(255), address VARCHAR(255), birthDate DATE); If your patients table does not have an id sequence, then drop the table (the application will automatically create the table if it does not exist).

Before the application can be run we will need to configure the application to connect to Cloud SQL. Open the pom.xml file. Under the tag locate these fields:

Replace them with the information for the ghs database created in Lab #1. Steps to locate the projectId can be found in Step 1. Do not change app.deploy.version. The instance name for your Cloud SQL DB can be found under connection information for your DB:

Fill-in sql.username/sql.password with the un/pw for your Cloud SQL DB. The sql.dbName is already set to ghs, assuming you have a DB named ghs. If not, see the previous lab for steps on how to create it. Explore the structure of the application:

In src/main/webapp you will find the jsp files that are used in the application for viewing, listing, adding, editing, and deleting patients.

In src/main/java/ you will find the Java code. The model package contains the Patient class. Inside the dao package is the CloudSqlDao that creates connections to the database and performs all of the SQL operations. In the servlet package you will find the code for the servlets that read, list, create, delete, update patients and redirect to the corresponding JSP page.

Open a terminal and cd to the directory containing patient-app-2. Run the app locally by running mvn package appengine:run. You can access the application by going to . If you get an error when running the application check your database information in the pom.xml file and make sure that you have run the following command to authorize your application so it can access Cloud SQL: gcloud auth application-default login

When the app is successfully running locally deploy it to the app engine using mvn package appengine:deploy. Once deployed you can view your app by typing gcloud app browse or

go to the URL http://[YOUR_PROJECT_ID].. Test the application by adding, viewing, listing, and updating patients. Note: If your application is using Java 8, you may need to set up Cloud Build to be able to deploy your application. Cloud Build can be found under Tools in the navigation menu. If needed, enable Cloud Build, and select Settings. Set the Status for App Engine to Enabled. More details can be found here: ing_additional_access

Hand-in: Hand in a screenshot of patient listing with a few patients when your application is running on the app engine. When done with the App Engine and Cloud SQL remember to shut down your database and the app to avoid charges for leaving them running. To shutdown your app, open the App Engine and go to settings. Under Disable Application you will find a button to disable it.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download