Cloud Foundry
From Zero To Hero

07 Where does my app store state?

This content is copyright of CloudCredo. © CloudCredo 2015. All rights reserved.

Feature

As a CF hero
I want a new version of my app to show the same data
So that I can iterate on feedback from my users

Where does my app store state?

In a service deployed alongside Cloud Foundry

Registered with CF through a Service Broker

What is a Service Broker?

A service for provisioning resources of a specific type

An API advertising a catalog of service offerings and plans

How do I see all available
service offerings?

$ cf marketplace
service          plans               description
____________________________________________________________________

cleardb          spark, boost*, ...  Highly available MySQL for y...
cloudamqp        lemur, tiger*, ...  Managed HA RabbitMQ servers ...
elephantsql      turtle, panda*, ..  PostgreSQL as a Service     ...
ironworker       large*,        ...  Scalable Background and Asyn...
loadimpact       lifree, li100*, ..  Automated and on-demand perf...
memcachedcloud   100mb*, 250mb*, ..  Enterprise-Class Memcached f...
mongolab         sandbox        ...  Fully-managed MongoDB-as-a-S...
newrelic         standard       ...  Manage and monitor your apps...
rediscloud       100mb*, 250mb*, ..  Enterprise-Class Redis for D...
searchly         small*, micro*, ..  Search Made Simple. Powered-...
sendgrid         free, bronze*,  ..  Email Delivery. Simplified.
....................................................................

I want a Redis service instance

$ cf create-service rediscloud 30mb redis
$ cf services

name    service      plan   bound apps   last operation
redis   rediscloud   30mb                create succeeded

I want my app to store state
in this Redis service instance

# From the training home directory:
$ cd 07-shared-state/stateful-app
$ cf push --no-start
$ cf bind-service stateful-app redis

App stateful-app is already bound to redis.
# Services can be defined in the app manifest
$ cf start stateful-app

Are all app instances
using the same Redis?

$ cf scale stateful-app -i 2

How are service details exposed to apps?

$ cf env stateful-app
...
 "VCAP_SERVICES": {
  "rediscloud": [
   {
    "credentials": {
     "hostname": "pub-redis-15708.us-east-1-4.6.ec2.redislabs.com",
     "password": "PASSWORD",
     "port": "15708"
    },
...
$ redis-cli -h pub-redis-15708...redislabs.com -p 15708 -a PASSWORD
pub-redis-15708.us-east-1-4.6.ec2.redislabs.com:15708> keys *
1) "9f397b68...total_instance_10.10.81.59:61500_responses"
2) "9f397b68...total_instance_10.10.17.49:61509_responses"
3) "9f397b68...total_app_responses"
pub-redis-15708.us-east-1-4.6.ec2.redislabs.com:15708> exit

Let’s iterate on user feedback

$ cf set-env stateful-app SHOW_APP_SUPPORTERS true
$ cf restart stateful-app

App gets deleted by mistake

What actually happened: the CEO clicked some links.

$ cf delete -f -r stateful-app

We restore the app, much to our users’ delight.

# From the training home directory:
$ cd 07-shared-state/stateful-app
$ cf push --no-start
$ cf set-env stateful-app SHOW_APP_SUPPORTERS true
$ cf start stateful-app

DELIVERED

As a CF hero
I want a new version of my app to show the same data
So that I can iterate on feedback from my users

Any questions?

Questions cannot be stupid. Answers can.

CF SUPERHERO

This content is copyright of CloudCredo. © CloudCredo 2015. All rights reserved.