baigan-config

The baigan-config distributed configuration service.

License

License

Categories

Categories

config Application Layer Libs Configuration
GroupId

GroupId

org.zalando
ArtifactId

ArtifactId

baigan-config
Last Version

Last Version

0.17.0
Release Date

Release Date

Type

Type

jar
Description

Description

baigan-config
The baigan-config distributed configuration service.
Project URL

Project URL

https://github.com/zalando/baigan-config
Source Code Management

Source Code Management

https://github.com/zalando/baigan-config.git

Download baigan-config

How to add to project

<!-- https://jarcasting.com/artifacts/org.zalando/baigan-config/ -->
<dependency>
    <groupId>org.zalando</groupId>
    <artifactId>baigan-config</artifactId>
    <version>0.17.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.zalando/baigan-config/
implementation 'org.zalando:baigan-config:0.17.0'
// https://jarcasting.com/artifacts/org.zalando/baigan-config/
implementation ("org.zalando:baigan-config:0.17.0")
'org.zalando:baigan-config:jar:0.17.0'
<dependency org="org.zalando" name="baigan-config" rev="0.17.0">
  <artifact name="baigan-config" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.zalando', module='baigan-config', version='0.17.0')
)
libraryDependencies += "org.zalando" % "baigan-config" % "0.17.0"
[org.zalando/baigan-config "0.17.0"]

Dependencies

compile (13)

Group / Artifact Type Version
org.eclipse.mylyn.github : org.eclipse.egit.github.core jar 2.1.5
com.google.code.findbugs : jsr305 jar 3.0.0
com.fasterxml.jackson.core : jackson-databind jar 2.6.1
com.fasterxml.jackson.datatype : jackson-datatype-guava jar 2.6.1
com.fasterxml.jackson.datatype : jackson-datatype-jdk8 jar 2.6.1
org.springframework : spring-core jar 4.2.1.RELEASE
org.springframework : spring-context jar 4.2.1.RELEASE
com.amazonaws : aws-java-sdk-core jar 1.11.25
com.amazonaws : aws-java-sdk-s3 jar 1.11.25
com.google.guava : guava jar 18.0
net.jodah : failsafe jar 2.2.0
org.slf4j : slf4j-api jar 1.7.12
org.reflections : reflections jar 0.9.10

test (4)

Group / Artifact Type Version
junit : junit jar 4.11
org.hamcrest : hamcrest-library jar 1.3
org.mockito : mockito-all jar 1.10.19
org.springframework : spring-test jar 4.2.1.RELEASE

Project Modules

There are no modules declared in this project.

Baigan configuration

Maven CentralCircleCI

Baigan configuration is an easy to use configuration framework for Spring based applications.

What makes Baigan a rockstar configuration framework ?

  • Simple: Using Baigan configurations is as simple as annotating a Java interface.
  • Extensible: Extend configurations, create rules, define types that suit you.
  • Flexible: Baigan is a client library that can read configurations from multiple repositories:
    • Filesystem
    • Github
    • AWS S3
    • Etcd

Prerequisites

  • Java 1.8
  • Spring framework
  • AWS SDK

Getting started

To build the project run:

    mvn clean install -Pintegration-test

Integrating Baigan config

Baigan config is a spring project. The larger part of integration involves configuring beans to facilitate the spring beans.

Configuring components and Configuration interface scanning.

import org.zalando.baigan.BaiganSpringContext;

@ComponentScan(basePackageClasses = {BaiganSpringContext.class })
@ConfigurationServiceScan(basePackages = {"com.foo.configurations" })
public class Application {
}

The BaiganSpringContext class includes the Baigan-Config beans required to be loaded into the spring application context. And the @ConfigurationServiceScan annotation hints the Baigan registrar to look into the packages where the @BaiganConfig annotated interfaces could be found.

Annotate your configuration interfaces with @BaiganConfig

	@BaiganConfig
	public interface ExpressFeature {

	    public Boolean enabled();

	    public String serviceUrl();

	}

The above example code enables the application to inject ExpressFeature spring bean into any other Spring bean:

	@Component
	public class ExpressServiceImpl implements ExpressService{

		@Inject
		private ExpressFeature expressFeature;

		@Override
		public void sendShipment(final Shipment shipment){
			if (expressFeature.enabled()){
				final String serviceUrl = expressFeature.serviceUrl();
				// Use the configuration
			}
		}
	}

Creating configurations

Baigan configurations follow a specific schema and can be stored on any of the supported repositories.

Configuration schema

Configurations are stored in its simplest form as key values. A configuration is a pair of a dot(.) separated key and a value objects in JSON format.

A configuration object should conform to the following JSON Schema:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Configuration",
    "description": "A baigan configuration object value.",
    "type": "object",
    "properties": {
        "alias": {
            "description": "The identifier for the configuration, same as its key.",
            "type": "string"
        },
         "description": {
            "description": "Summary of the configuration.",
            "type": "string"
        },
         "defaultValue": {
            "description": "Default configuration if none of the condition is satisfied.",
            "type": {}
        },
         "conditions": {
            "description": "List of conditions to check",
            "type": "array",
            "items": {
            	"type": "object",
            	"properties": {
                    "value": {
                        "description": "Configuration value if this condition evaluates to true.",
                        "type": {}
                    },
            		"conditionType": {
                        "description": "Type of condition to evaluate. This can be custom defined, with custom defined properties.",
                        "type": "object",
                    }
                }
            }
        }
    },
    "required": ["defaultValue"]
}

Example configurations

This sample JSON defines a configuration for the key express.feature.enabled with the value true when the country_code is 3, and a default value of false.

{
  "alias": "express.feature.enabled",
  "description": "Feature toggle",
  "defaultValue": false,
  "conditions": [
    {
      "value": true,
      "conditionType": {
        "onValue": "3",
        "type": "Equals"
      },
      "paramName": "country_code"
    }
  ]
}

Pushing configuration to repositories

This step depends on the chosen repository.

Filesystem

Save a file named express-feature.json with the content above anywhere on the filesystem and bundle it as part of your application. To use it just specify the classpath in the constructor.

Github

Save a file named express-feature.json with the content above and push it to any Github repository. To use it just provide the required Github settings to the provider. Github Enterprise is also supported.

AWS S3

Save a file named express-feature.json with the content above and upload it to any S3 bucket. To use it just provide the bucket name and the object key.

Etcd

To create a key in etcd, you can either use etcdctl or the good old curl in the following way. Save a file named express-feature.json with the content above and push it to your etcd cluster:

With etcdctl v2:

etcdctl set express.feature.enabled < express-feature.json 

With curl:

curl -v -XPUT http://127.0.0.1:2379/v2/keys/express.feature.enabled -d value="$(cat express-feature.json)"

License

Copyright 2016 Zalando SE

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

org.zalando

Zalando SE

The org page for Zalando, Europe's leading online fashion platform. Visit opensource.zalando.com for project stats.

Versions

Version
0.17.0
0.16.0
0.15.0
0.14.1
0.14.0
0.13.0
0.12.1
0.12.0
0.11.0
0.9.6
0.9.5
0.9.4
0.9.3
0.9.1
0.9.0