Skip to content

amitjoy/feature-flags-for-osgi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo

Why? start with what and why

This is an implementation of the Feature Toggles pattern (also known as Feature Flags) for OSGi Service Platform. Feature Flags (also known as Feature Toggles and Feature Controls) is the software development practice that facilitates the easy enablement and disablement of deployed functionalities. Besides, feature flags ease the management of the feature's entire lifecycle. These allow you to manage components and compartmentalise risk. We can also roll out the features to a specific group of users or exclude the group from accessing it, perform A/B test and much more. It’s also the way to test how your features function in the real world and not just in an artificial test environment. Therefore, feature toggle is a widespread agile development practice in the context of continuous deployment and delivery.


Build Status Codacy Badge BCH compliance codecov Coverage Status javadoc


Requirements

  1. Java 8+
  2. OSGi R4.3+

Dependencies

This project comprises three bundles -

  1. com.amitinside.featureflags.api - The core feature flags API
  2. com.amitinside.featureflags.provider - The core feature flags implementation
  3. com.amitinside.featureflags.example - Example project showing how to use core feature flags in codebase

As test dependencies, the following test libraries are used:

  1. JUnit 4.12
  2. Mockito Core 2.10

Installation

To use feature flags in OSGi environment, you only need to install com.amitinside.featureflags.provider.


Contribution contributions welcome

Want to contribute? Great! Check out Contribution Guide


Project Import

Import as Eclipse Projects

  1. Install Bndtools
  2. Import all the projects (File -> Import -> General -> Existing Projects into Workspace)

Building from Source

Run ./gradlew clean build in the project root directory

License

This project is licensed under Apache License License


Usage

  1. In your DS Component, add an attribute definition to the existing or new object class definition.
@ObjectClassDefinition
@interface MyConfig {
      @AttributeDefinition(name = "My First Feature", description = "My Feature Description")
      boolean osgi_feature_myfeature() default true;
}

or provide a metatype XML with the required configuration in your bundle's OSGI-INF/metatype directory

<?xml version="1.0" encoding="UTF-8"?>
<MetaData xmlns="http://www.osgi.org/xmlns/metatype/v1.2.0" localization="en_us">
    <OCD id="ExampleFeatureFlagOCD" 
         name="My Feature Configuration">

        <AD id="osgi.feature.myfeature"
            name="My First Feature"
            description="My Feature Description"
            type="Boolean"
            cardinality="0"
            required="true"
            default="true">
        </AD>

    </OCD>
    
    <Designate pid="ExampleFeatureFlagOSGiR4WithXML">
        <Object ocdref="ExampleFeatureFlagOCD"/>
    </Designate>
</MetaData>
  1. The primary contract of using feature flags in your codebase is to introduce boolean attribute definitions to existing or new object class definitions in metatype. The IDs of the attribute definitions must be osgi.feature.X where X is the name of your feature. And don't forget to add the aforementioned requirement capability to your manifest.
The primary benefit of this approach is that developers can use feature flags without having any dependency to any external API.

For more information, have a look at the example project.