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

[Pages:7]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.

To turn off your database instance go to Cloud SQL. Open your database instance. Click Stop located in the Instance details bar.

If you deleted your project from the previous lab, you will need to do the following using the gcloud CLI:

1. gcloud projects list to get the project-id of the new project 2. gcloud config set project to switch gcloud from the deleted project to the new project.

Alternatively, you can open up a terminal window, move to the directory that has the code, & type "gcloud init" (assumes you installed the gcloud SDK)

Troubleshooting: If at any point you are having trouble or are getting a 500 error message try the following:

1. Make sure you have authorized the application to run on GCP by running: gcloud auth application-default login

2. Check the database information in the pom.xml file to make sure that you are connecting to the database on GCP correctly.

3. Check the logs found in the logging utility on GCP. In the navigation menu (upper-left three stacked vertical bars) scroll down to Operations. Select Logging and then Log Viewer.

From the drop-down menu options going from left to right select the following: 1. GAE Application (first drop-down) 2. appengine.request_log (second drop-down) 3. Error or Critical (third drop-down) 4. No limit (fourth drop-down)

You will then be able to see all the critical errors that have occurred, and you can expand them to see the error messages and stack traces.

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

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

Google Online Preview   Download