Application Container Cloud and Factor III. Config

Dropwizard applications deployed to Oracle’s Application Container Cloud Service (ACCS) check off most of the best practices recommend by the twelve-factor methodology. In this article I’m going to address Factor III. Config – Store config in the environment.

Dropwizard has extensive support for Configuration (See Creating a Configuration Class). The configuration parameters are externalized in a YAML configuration file. This was demonstrated in the HelloWorld getting started application where the following was defined:

template: Hello, %s!
defaultName: Stranger

Dropwizard also supports substituting these configuration settings with the value of environment variables.

As a test, I augmented the HelloWorldApplication class’ initialize method with the following boilerplate code:

    public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) {
        // Enable variable substitution with environment variables
            new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false)

I then updated the hello-world.yml as follows:

template: ${template:-Hello, %s!}
defaultName: ${defaultName:-Stranger Danger}

Now, on initialization, the application will first look for environment variables named “template” and “defaultName”. If the variables are not defined, the application will use the strings as defined in the YAML file.

On deployment to the Application Container Cloud Service (ACCS), the application shows the following when run:

{"id":1,"content":"Hello, Stranger Danger!"}

Now if I log into the ACCS Service Console and select the Deployments tab, I can create user-defined environment variables. For example:

I then have to apply the edits, which will restart the application:


The application quickly restarts (Factor IX. Disposability):

And a refresh of my browser now pulls the default name from my environment:

{"id":1,"content":"Hello, Application Container Cloud Service!"}

Thus, I now have the ability to configure the application without needing to redeploy.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s