FF4J feature toggling issue

934 Views Asked by At

Currently we are FF4J toggle framework for our Spring based application, where we are using SpringJDBSC store. Problem is currently we have multiple applications deployed on an enviroment like DEV,UAT etc., the features that are created on enabled or disabled for all the applications in an environment. Now i want to enable/disable feature per application like the feature "TestFeature" should be ON for App1, and OFF for app2 in DEV enviroment. Any suggestions on how to implement this is really helpful

1

There are 1 best solutions below

0
On BEST ANSWER
  1. Each application you should have a paramter applicationName for you to know if a Feature is toggled or not. This value could be the webContext of your application or a property in your configuration file (application.properties if you use Spring Boot).

  2. Create a FlippingStrategy evaluating on this value, this look like

Sample ApplicationNameStrategy :

public class ApplicationNameStrategy extends AbstractFlipStrategy {

private String currentApplicationName = null;

public ApplicationNameStrategy() {}

public ApplicationNameStrategy() {
    currentApplicationName = //.. init the value here
}

/** {@inheritDoc} */
@Override
public void init(String featureName, Map<String, String> initParams) {
    super.init(featureName, initParams);
}

/** {@inheritDoc} */
@Override
public boolean evaluate(String featureName, FeatureStore store, FlippingExecutionContext executionContext) {
    // special sauce !
    return Arrays.asList(store.read(featureName).getCustomProperty("grantedApplications").split(",")).contains(currentApplicationName);
}
  1. Update your Feature accourdingly

Sample ff4j.xml snippet

<feature uid="myFeature" enable="true" description="description" >
   <custom-properties>
    <property name="grantedApplication"
              type="org.ff4j.property.domain.PropertyString" 
              value="appA,appB"  />
    </custom-properties>
    <flipstrategy class="ApplicationNameStrategy">
    </flipstrategy>
</feature>