This repository contains the code for the Cloud Controller. The NG signifies that this is a "next generation" component and this is not backward-compatible with the original cloud_controller. This version adds significant new functionality including the additional mandatory "organization" and "space" hierarchy that all users, applications and services must use.
The Cloud Controller itself is written in Ruby and provides REST API endpoints for clients to access the system. The Cloud Controller maintains a database with tables for orgs, spaces, apps, services, service instances, user roles, and more.
The Cloud Controller database has been tested with Postgres, Mysql, and Oracle.
The Cloud Controller manages a blob store for:
-
resources - files that are uploaded to the Cloud Controller with a unique SHA such that they can be reused without re-uploading the file
-
app packages - unstaged files that represent an application
-
droplets - the result of taking an app package and staging it (processesing a buildpack) and getting it ready to run
The blob store uses FOG such that it can use abstractions like Amazon S3 or an NFS-mounted file system for storage.
The Cloud Controller interacts with other core components of the Cloud Foundry platform using the NATS message bus. For example, it performs the following using NATS:
- Instructs a DEA to stage an application (processes a buildpack for the app) to prepare it to run
- Instructs a DEA to start or stop an application
- Receives information from the Health Manager about applications
- Subscribes to Service Gateways that advertise available services
- Instructs Service Gateways to handle provisioning, unprovision, bind and unbind operations for services
By default rspec
will run test suite with sqlite3 in-memory database;
however, you can specify connection string via DB_CONNECTION
environment
variable to test against postgres, mysql, and oracle. Examples:
DB_CONNECTION="postgres://postgres@localhost:5432/ccng" rspec
DB_CONNECTION="mysql2://root:password@localhost:3306/ccng" rspec
DB_CONNECTION="oracle://root:password@localhost:1521/xe" rspec
Travis currently runs 3 build jobs against sqlite, postgres, and mysql.
To run an interactive console with the cloud controller code loaded:
bin/console
Cloud Controller uses Steno to manage its logs. Each log entry includes a "source" field to designate which module in the code the entry originates from. Some of the possible sources are 'cc.app', 'cc.app_stager', 'cc.dea.client' and 'cc.healthmanager.client'.
Here are some use cases for the different log levels:
error
- the CC received a malformed HTTP request, or a request for a non-existent dropletwarn
- the CC failed to delete a droplet, CC received a request with an invalid auth tokeninfo
- CC received a token from UAA, CC received a NATS requestdebug2
- CC created a service, updated a servicedebug
- CC syncs resource pool, CC uploaded a file
The logs for database migrations are written to standard out.
The Cloud Controller uses a YAML configuration file.
For an example, see config/cloud_controller.yml
.
Some of the keys that are read from this configuration file are:
logging
- a steno configuration hashbulk_api
- basic auth credentials for the application state bulk API. In Cloud Foundry, this endpoint is used by the health manager to retrieve the expected state of every user application.uaa
- URL and credentials for connecting to the UAA, Cloud Foundry's OAuth 2.0 server.
Several key differences exist in Oracle compared to other databases that need to be taken into account when developing a feature:
- Oracle has a 30 character identifier limit. This effects column names, index names, foreign key names, etc. Make sure to keep all identifiers short.
- In Oracle
timestamp
is a reserved word. Choose a different name for timestamp columns then alias it usingdef_column_alias
if needed. - Oracle has no boolean. Instead Sequel will use a single char (Y,N) for boolean. Because
of this
char(1)
has been hijacked by Oracle for all databases. - Oracle has no
case insensitive
column support. Use the framework provided to simplify adding support for queries and indexes that use thelower()
function. - Oracle doesn't support 'empty'. When you attempt to insert
empty
it gets converted tonull
. However, if querying forempty
Oracle will not matchnull
. - Oracle doesn't provide an auto increment PK type. To compensate for this Sequel will automatically create a sequence and a trigger to update the PK with the latest sequence value. This works great. However, when renaming a table you will need to rename the sequence and re-make the trigger for that table.
- Count query limitation. For some reason Oracle-Sequel doesn't support filter parameters in count(). So, queries
like
Models::Organization.count(:id => org.id)
need to change toModels::Organization.filter(:id => org.id).count