Skip to content

Latest commit

 

History

History
108 lines (85 loc) · 4.58 KB

lab.adoc

File metadata and controls

108 lines (85 loc) · 4.58 KB

Lab 2 - Binding to Cloudfoundry Services

The Workshop application was designed to illustrate the ease with which data services can be bound to and utilized by applications running on Cloud Foundry. In this lab, we’ll be binding the application to a MySQL databases.

Cloud Foundry services are managed through two primary types of operations:

Create/Delete

These operations create or delete instances of a service. For a database this could mean creating/deleting a schema in an existing multitenant cluster or creating/deleting a dedicated database cluster.

Bind/Unbind

These operations create or delete unique credential sets for an existing service instance that can then be injected into the environment of an application instance.

A Bit of Review

Your instance of the sample Workshop should not be running after the steps completed in lab 1. Make sure to change to the cf-spring-mvc-boot sample application directory. For this lab we will be using the Java application. Deploy the application:

$ cf push <some-unique-appname>

After the application deploys and starts, visit the application in your browser by hitting the route that was generated by the CLI. Currently, this data is being retrieved from an in-memory HSQL database running within the JVM. Let’s change that.

lab

The Services Marketplace

There are two ways to discover what services are available on Pivotal Cloudfoundry. The first is available on any instance of Cloud Foundry: the CLI. Just type:

$ cf marketplace

and you’ll get a list of services, their available plans, and descriptions. On Pivotal Cloudfoundry, the "free" tier of plans is normally the first one listed.

The second way is specific to Pivotal Cloudfoundry’s Apps Manager UI. If you haven’t already, login to it by visiting Apps Mgr

Click on the "Marketplace" link:

lab1

and you’ll see the same (or a similar if on PWS) service/plan/description listing in the browser:

lab2

Creating and Binding to a Service Instance

  1. Let’s begin by creating a MySQL service instance. From the Apps Manager UI service marketplace, select MySQL for Pivotal Cloudfoundry, select the free plan, and provide an instance name. In the drop-down list next to Bind to App select your workshop application.

    lab3
  2. Notice the admonition to Use 'cf restage' to ensure your env variable changes take effect. Let’s take a look at the environment variables for our application. We can do this by viewing to the homepage of the application. Here we will see a printout of the environment information. Take note of what is contained in the section Bound Services. It’s an empty JSON document!

  3. Now let’s restage the application, which cycles our application back through the staging/buildpack process before redeploying the application. In this case, we could accomplish the same goal by only restarting the application via cf restart cf-spring-mvc-boot. A restage is generally recommended because Cloud Foundry buildpacks also have access to injected environment variables and can install or configure things differently based on their values.]

    $ cf restage cf-spring-mvc-boot

    Once the application is running again, revisit or refresh the browser tab where you have the Wokshop application loaded. You’ll notice now we have information that could be used to connect to a DB. In fact, our data is now being retrieved from that MySQL database!

    Bound Services:
    {
       "p-mysql":[
          {
             "name":"adam-db",
             "label":"p-mysql",
             "tags":[
                "mysql",
                "relational"
             ],
             "plan":"100mb-dev",
             "credentials":{
                "hostname":"10.68.105.55",
                "port":3306,
                "name":"cf_226845a3_1982_44ac_92b9_4b149af56bbc",
                "username":"n67hpBOnKlsPUjKn",
                "password":"hUa4WSrq2hPtBsuk",
                "uri":"mysql://n67hpBOnKlsPUjKn:[email protected]:3306/cf_226845a3_1982_44ac_92b9_4b149af56bbc?reconnect=true",
                "jdbcUrl":"jdbc:mysql://10.68.105.55:3306/cf_226845a3_1982_44ac_92b9_4b149af56bbc?user=n67hpBOnKlsPUjKn&password=hUa4WSrq2hPtBsuk"
             }
          }
       ]
    }
  4. You may also verify your service was provisioned in the Apps Manager UI by clicking on your application and selecting the Services tab.

    lab4

    You should now see the service created in step 1 listed.

  5. You may also verify your service was provisioned using the CLI:

    $ cf services

    You should now see the service created in step 1 listed and your application listed as a bound app.