Local Development Setup

To use this development environment on OSX, you need to have Docker and Boot2docker installed.

Cloudbreak Deployer

Simplest way to prepare the working environment is to start the Cloudbreak on your local machine is to use the Cloudbreak Deployer.

First you need to create a sandbox directory which will store the necessary configuration files and dependencies of Cloudbreak Deployer. This directory must be created outside of the cloned Cloudbreak git repository:

mkdir cbd-local

To start the complete Cloudbreak ecosystem on your machine just execute the following sequence of commands:

cd cbd-local
curl https://raw.githubusercontent.com/sequenceiq/cloudbreak-deployer/master/install | sh && cbd --version
cbd update master
cbd init
cbd start

If everything went well then the Cloudbreak will be available on http://192.168.59.103:3000. For more details and config parameters please check the documentation of Cloudbreak Deployer.

The deployer has generated a certs directory under cbd-local directory which will be needed later on to set up the IDEA properly.

The next step is to edit the cbd-local/Profile file with any editor and add the CB_SCHEMA_SCRIPTS_LOCATION environment variable which configures the location of SQL scripts that are in the 'core/src/main/resources/schema' directory in the cloned Cloudbreak git repository. Please note that the full path needs to be configured and env variables like $USER cannot be used.

export CB_SCHEMA_SCRIPTS_LOCATION=/Users/myusername/prj/cloudbreak/core/src/main/resources/schema

In order to kill Cloudbreak container running inside the boot2docker and redirect the Cloudbreak related traffic to the Cloudbreak running in IDEA use the followig command:

cbd util local-dev

IDEA

Cloudbreak can be imported into IDEA as gradle project. Once it is done, you need to import the proper code formatter by using the File -> Import Settings... menu and selecting the idea_settings.jar located in the config directory in Cloudbreak git repository.

To launch the Cloudbreak application execute the com.sequenceiq.cloudbreak.CloudbreakApplication class with VM options:

-XX:MaxPermSize=1024m
-Dcb.cert.dir=FULL_PATH_OF_THE_CERTS_DIR_GENERATED_BY_CBD
-Dcb.client.id=cloudbreak
-Dcb.client.secret=cbsecret2015
-Dcb.db.port.5432.tcp.addr=192.168.59.103
-Dcb.db.port.5432.tcp.port=5432
-Dcb.identity.server.url=http://192.168.59.103:8089
-Dserver.port=9091
-Dcb.schema.migration.auto=true

The -Dcb.cert.dir=FULL_PATH_OF_THE_CERTS_DIR_GENERATED_BY_CBD value above needs to be replaced with the full path of certs directory generated by Cloudbreak Deployer e.g. -Dcb.cert.dir=/Users/myusername/prj/cbd-local/certs. The databse migration is ran automatically by Cloudbreak, this automated migration could be turn off through the -Dcb.schema.migration.auto=false VM option.

Command line

To run Cloudbreak from command line you have to create a property file, for example application.properties, with the content below, and execute ./gradlew bootRun -Dspring.config.location=file:/path/of/property/application.properties command at project root.

-Dcb.cert.dir=FULL_PATH_OF_THE_CERTS_DIR_GENERATED_BY_CBD
-Dcb.client.id=cloudbreak
-Dcb.client.secret=cbsecret2015
-Dcb.db.port.5432.tcp.addr=192.168.59.103
-Dcb.db.port.5432.tcp.port=5432
-Dcb.identity.server.url=http://192.168.59.103:8089
-Dserver.port=9091

Database development

If schema change is required in Cloudbreak database (cbdb), then the developer needs to write SQL scripts to migrate the database accordingly. In Cloudbreak the schema migration is managed by MYBATIS Migrations and the cbd tool provides an easy-to-use wrapper for it. The syntax for using the migration commands is cbd migrate <database name> <command> [parameters] e.g. cbd migrate migrate status.

Create a SQL template for schema changes:

cbd migrate cbdb new "CLOUD-123 schema change for new feature"

As as result of the above command an SQL file template is generated under the path specified in CB_SCHEMA_SCRIPTS_LOCATION environment variable, which is defined in Profile. The structure of the generated SQL template looks like the following:

-- // CLOUD-123 schema change for new feature
-- Migration SQL that makes the change goes here.



-- //@UNDO
-- SQL to undo the change goes here.

Once you have implemented your SQLs then you can execute them with:

cbd migrate cbdb up

If you would like to rollback the last SQL file, then just use the down command:

cbd migrate cbdb down

On order to check the status of database

cbd migrate cbdb status

#Every script that has not been executed will be marked as ...pending... in the output of status command:

------------------------------------------------------------------------
-- MyBatis Migrations - status
------------------------------------------------------------------------
ID             Applied At          Description
================================================================================
20150421140021 2015-07-08 10:04:28 create changelog
20150421150000 2015-07-08 10:04:28 CLOUD-607 create baseline schema
20150507121756 2015-07-08 10:04:28 CLOUD-576 change instancegrouptype hostgroup to core
20151008090632    ...pending...    CLOUD-123 schema change for new feature

------------------------------------------------------------------------

Building

Gradle is used for build and dependency management. Gradle wrapper is added to Cloudbreak git repository, therefore building can be done with:

./gradlew clean build