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:

    @Override
    public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) {
        // Enable variable substitution with environment variables
        bootstrap.setConfigurationSourceProvider(
            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:

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

c02-apply_edits.JPG

The application quickly restarts (Factor IX. Disposability):
c03-deploying_release

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

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

https://helloworld-gse00001975.apaas.em2.oraclecloud.com/hello-world

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

 

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s