Abstract

This blog post describes a tutorial how to get started with application development and deployment to a local and public Pivotal Cloud Foundry (PCF) environment.

In order to complete the tutorial you need to have the following software installed:

  • Spring Tool Suite 3.8 or higher
  • Java 7 or higher
  • VirtualBox 5 or higher

The overall goal is to set up the local and public cloud configuration and deploy the same sample application to each one.

2016-07-22 13_42_33-Presentation1 - Microsoft PowerPoint

The blog post will guide you through the process of registering for a public PCF account as well as the setup of a local PCF development (PCF Dev) environment. The PCF Dev is a light-weight implementation of the full PCF setup that can be run locally and is very suitable for implementation and testing.

The application to be deployed is taken from the Pivotal Getting Started samples. The import, build and deployment of the application is done using the Spring Tool Suite (STS). If you already have an existing Eclipse installation you can add the STS as extension instead of installing it from scratch. This tutorial will however not describe these steps and is based on a fresh STS installation.

Installing the Cloud Foundry Command Line interface

Prior to using the public or local Cloud Foundry platform it is required to install the Cloud Foundry Command-Line Interface (CF CLI). The download can be found here:  https://console.run.pivotal.io/tools

Download the installer suitable for your Operating System, extract it and run the binary contained in the downloaded file. The installation does not take any parameters.

Registration for a public Pivotal Cloud Foundry account

The base requirement to deploy an application to the public cloud is an account at Pivotal. The registration is free and can be done here.

If you already have an account you can sign in here and proceed to the next step.

On the dialog enter your name, e-mail and password. After the submission of this form an activation link will be sent to your e-mail address.

2016-07-11 11_34_14-Pivotal Account

Confirm the link in your inbox and it will take you to the following web page.

2016-07-11 11_35_35-Pivotal Account

On this page select the Pivotal Web Services. This will take you to a dialog where you need to accept the terms of service. Depending on your preference you can check/uncheck the e-mail notifications and updates from Pivotal.

Select Next: Claim your trial. You need to provide a phone number where you can receive a call or SMS for verification. After this the registration is completed.

If you’re not automatically directed to your Cloud Foundry console, you can always access it via the following link: https://console.run.pivotal.io

2016-07-11 14_29_14-Pivotal Web Services

The first thing you are asked to do is create an Org. You can label it anything you like as long as the name is not already taken.  A so-called space with the name of development is automatically created within this Org.

You will see an overview of your deployments and services. If you just created your space you will have no apps or services running.

2016-07-11 14_29_26-Pivotal Web Services

You can log out for now.

Configuration of the Pivotal Cloud Foundry development (PCF Dev) environment

In order to host a Cloud Foundry platform locally the fastest way is to download and run the PCF Dev environment. You can access the download at: https://network.pivotal.io/products/pcfdev

Pick the download suitable for your Operating System. (This tutorial was written using pcfdev-v0.17.0 on Windows). The download is fairly small in size (~4MB). Extract the content to a certain directory (e.g. pcfdev) and open a command shell in this directory. Execute the executable within this directory.

2016-07-11 13_46_27-MINGW64__c_Users_MHS_Downloads_pcfdev

It will tell you once the plugin is successfully upgraded. After that run “cf dev help” to get the following output screen.

2016-07-11 13_47_31-MINGW64__c_Users_MHS_Downloads_pcfdev

Run “cf dev start -s scs” to kick-off the download and deployment of the VM.

Upon the first start it will ask you to retrieve an API token from your Pivotal profile. Log in to get it here: https://network.pivotal.io/users/dashboard/edit-profile

Copy & paste it into the CLI prompt to continue.

2016-07-11 13_54_42-MINGW64__c_Users_MHS_Downloads_pcfdev

Note: This will download a VM with hard disk size of multiple GBs. It is recommended to do this step using a fast Internet connection.

After completion the VM will automatically be started.

In your VirtualBox Manager you will see a new running VM.

2016-07-11 13_53_39-Oracle VM VirtualBox Manager

Verification of local and public account (Optional step)

Use the CF CLI to login to both public and local Cloud Foundry platform.

For the local platform type:

“cf login -a https://api.local.pcfdev.io –skip-ssl-validation”

Enter username user and password pass to continue.

2016-07-11 13_45_31-MINGW64__c_Users_MHS_Downloads_2

Type cf version to show the implementation version of cf app and to list the installed apps (there won’t be any in a new installation).

2016-07-11 14_20_52-Administrator_ Git CMD

The PCF Dev environment also provides a web console: https://console.local.pcfdev.io/2

As the CF CLI can only be logged in to one Cloud Foundry platform at a time you need to disconnect typing “cf logout“.

Now login to the public platform using:

“cf login -a api.run.pivotal.io”

Enter the email and password you selected when you created the Pivotal account.

The login dialog should look similar to this:

2016-07-11 14_34_13-Administrator_ Git CMD2.png

To verify also run the commands “cf version” and “cf app” and logout again.

Creating the server connections in Spring Tool Suite

Open the Spring Tools Suite

Select File -> New -> Other, Expand Server, select Server and click Next >

2016-07-11 14_53_23-New

Expand Cloud Foundry and select Cloud Foundry

2016-07-14 10_45_26-New Server

Label the Server name: CF public

Select Next >

Edit Email and password and Select Manage Cloud …

Click Add …

Enter a name (e.g. CF public) and the URL: https://api.run.pivotal.io

2016-07-11 14_55_45-Add and validate a Cloud URL

Select Finish

Your dialog should look similar to this one now (showing your own credentials) :

2016-07-14 10_50_41-New Server

Select Validate.

After successful validation the Finish button gets enabled. Press it to complete.

Repeat the previous steps to create the server definition for the CF local server. Use the following specs:

  • Name: CF public
  • Email: user
  • Password: pass
  • Select Trust self-signed certificate

2016-07-11 15_02_13-Add and validate a Cloud URL

After completion your Servers dashboard should contain 3 entries:

2016-07-11 15_03_20-workspace-sts-3.7.3.RELEASE - Spring - Dashboard - Spring Tool Suite

The server connections configuration is now completed.

Import and test run of a sample application

Within the Spring Tool Suite import a sample application.

Select File -> New-> Import Spring Getting Started content.

Select “Messaging Stomp Websocket” (You can basically use any simple type application, but the tutorial was tested with this one).

Uncheck Code Sets initial.

Click Finish.

Right-click on the application in the package explorer, select Refactor and Rename. (or press Alt-Shift-R)

Rename the app to something personal. In my example I used “mhs-messaging”.

Right-click the application again and select Run As -> Spring Boot App

In the console you should be able to see the deployment. Wait until it shows a line with the content

2016-07-11 15_30_47-workspace-sts-3.7.3.RELEASE - Spring - http___spring.io_guides_gs_messaging-stom

Open a web browser and point it to the URL: http://localhost:8080/

The app should be displayed. Click connect, enter a name and press Send.

2016-07-11 15_32_05-Hello WebSocket

If you see the previous screen the app has been compiled and deployed successfully. It is now running on a Tomcat server locally on your Operating System.

Run the sample application on the CloudFoundry instances

Now that you have set up an application in your development environment and configured two cloud instances you can move forward to deploy the same application to them.

Right-click the application within the Spring Tool Suite again.

This time select Run As -> Run on Server.

You will see the local and public instances of Cloud Foundry, which you have configured before:

2016-07-11 15_35_55-Run On Server

Select CF local and click Finish.

On the application details dialog select Next >

On the Launch deployment dialog copy the Deployed URL information to your clipboard.

2016-07-29 10_33_21-

Select Finish.

In the console you can trace the deployment again. The log output will be different this time in a way that the application and the Tomcat server will not be deployed locally to your OS, but to the running VM that hosts the Cloud Foundry runtime.

Once the application is running open a new browser and point it to the link you saved in your clipboard. In case you did not save, it is: http://<name_of_your_app>.local.pcfdev.io. In my case this is http://mhs-messaging.local.pcfdev.io

2016-07-11 16_12_12-Hello WebSocket

The browser should look identical to the local test of the previous example. However the application is hosted within Cloud Foundry (PCF Dev) this time.

As a final step, deploy the application to the public Cloud Foundry platform.

Repeat the steps from above. As this deployment will be publicly available on the Internet, the URL must be unique. If your name is already in use, the deployment will be rejected and you need to use a unique name in the URL.

After completing the dialogs, you will see the deployment steps in the console again. After that your application is running in the public Cloud and accessible via: http://<name_of_your_app>.cfapps.io. In my case this is http://mhs-messaging.cfapps.io

2016-07-11 16_12_22-Hello WebSocket

Summary

With this tutorial you have seen 3 different ways to deploy an application. A “non-Cloud” local deployment and 2 Cloud deployments – to a local development environment and to the public cloud. To the end-user the access is almost transparent, it basically differs by URL only. However, the underlying runtime is significantly different in terms of location and flexibility.

For further validation you can now log in again to the Cloud Foundry Web Services page (public and/or local) where you see your running app:

2016-07-11 16_14_06-Pivotal Web Services

Alternatively you can use the CF CLI to control via command line.

The tutorial completes with this step. Thanks for reading!

Further reading

Cloud Native Platform: Link

Getting Started with Pivotal Cloud Foundry: Link

Spring general: Link

Spring Cloud: Link

NovaTec Blog Post by Johannes Dilli: Service discovery with Eureka in Cloud Foundry

Leave a Comment

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close