Search in sources :

Example 6 with PropertyStore

use of org.ff4j.property.store.PropertyStore in project ff4j by ff4j.

the class FF4jCliDisplay method displayEnvironments.

/**
 * Display a table of available environments.
 *
 * @param envs
 * 		environnements in config file
 */
public static void displayEnvironments(Map<String, FF4j> envs) {
    yellow("+--------------------+----------+------------+-------+----------+\n");
    System.out.print("|");
    cyan(" Environments       ");
    yellow("|");
    cyan(" Features ");
    yellow("|");
    cyan(" Properties ");
    yellow("|");
    cyan(" Audit ");
    yellow("|");
    cyan(" Security ");
    yellow("|\n");
    System.out.println("+--------------------+----------+------------+-------+----------+");
    for (Map.Entry<String, FF4j> entries : envs.entrySet()) {
        FeatureStore fs = entries.getValue().getFeatureStore();
        PropertyStore ps = entries.getValue().getPropertiesStore();
        yellow("|  ");
        green(StringUtils.rightPad(entries.getKey(), 18));
        yellow("|  ");
        String featureStore = "---";
        if (fs != null) {
            featureStore = String.valueOf(fs.readAll().size());
        }
        white(StringUtils.rightPad(featureStore, 8));
        yellow("|  ");
        String propertyStore = "---";
        if (fs != null) {
            propertyStore = String.valueOf(ps.listPropertyNames().size());
        }
        white(StringUtils.rightPad(propertyStore, 10));
        yellow("|");
        AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
        if (entries.getValue().isEnableAudit()) {
            green("  ON   ");
        } else {
            red("  OFF  ");
        }
        AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
        yellow("|");
        AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
        if (entries.getValue().getAuthorizationsManager() != null) {
            green("  ON      ");
        } else {
            red("  OFF     ");
        }
        AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
        yellow("|\n");
    }
    System.out.println("+--------------------+----------+------------+-------+----------+");
    System.out.println("");
}
Also used : FF4j(org.ff4j.FF4j) PropertyString(org.ff4j.property.PropertyString) HashMap(java.util.HashMap) Map(java.util.Map) FeatureStore(org.ff4j.core.FeatureStore) PropertyStore(org.ff4j.property.store.PropertyStore)

Example 7 with PropertyStore

use of org.ff4j.property.store.PropertyStore in project ff4j by ff4j.

the class PropertyStoreArchaiusPolledSourceTest method initArchauis.

@BeforeClass
public static void initArchauis() throws InterruptedException {
    // Sample FF4J Store
    PropertyStore ff4jStore = new InMemoryPropertyStore("ff4j-properties.xml");
    // FF4Store as polling Source for Archiaus
    PolledConfigurationSource ff4jSource = new FF4jPolledConfigurationSource(ff4jStore);
    // Working Thread (polling from ff4j => Archaius)
    AbstractPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 1000, true);
    // Define configuration with polling and source
    configuration = new DynamicConfiguration(ff4jSource, scheduler);
}
Also used : InMemoryPropertyStore(org.ff4j.property.store.InMemoryPropertyStore) DynamicConfiguration(com.netflix.config.DynamicConfiguration) AbstractPollingScheduler(com.netflix.config.AbstractPollingScheduler) FixedDelayPollingScheduler(com.netflix.config.FixedDelayPollingScheduler) PolledConfigurationSource(com.netflix.config.PolledConfigurationSource) InMemoryPropertyStore(org.ff4j.property.store.InMemoryPropertyStore) PropertyStore(org.ff4j.property.store.PropertyStore) BeforeClass(org.junit.BeforeClass)

Example 8 with PropertyStore

use of org.ff4j.property.store.PropertyStore in project ff4j by ff4j.

the class ConsoleOperations method importFile.

/**
 * User action to import Features from a properties files.
 *
 * @param in
 *            inpustream from configuration file
 * @throws IOException
 *             Error raised if the configuration cannot be read
 */
public static void importFile(FF4j ff4j, InputStream in) throws IOException {
    FeatureStore store = ff4j.getFeatureStore();
    XmlConfig xmlConfig = new XmlParser().parseConfigurationFile(in);
    Map<String, Feature> mapsOfFeat = xmlConfig.getFeatures();
    for (Entry<String, Feature> feature : mapsOfFeat.entrySet()) {
        if (store.exist(feature.getKey())) {
            store.update(feature.getValue());
        } else {
            store.create(feature.getValue());
        }
    }
    LOGGER.info(mapsOfFeat.size() + " features have been imported.");
    PropertyStore pstore = ff4j.getPropertiesStore();
    Map<String, Property<?>> mapsOfProperties = xmlConfig.getProperties();
    for (Entry<String, Property<?>> p : mapsOfProperties.entrySet()) {
        if (pstore.existProperty(p.getKey())) {
            pstore.updateProperty(p.getValue());
        } else {
            pstore.createProperty(p.getValue());
        }
    }
    LOGGER.info(mapsOfProperties.size() + " features have been imported.");
}
Also used : XmlParser(org.ff4j.conf.XmlParser) XmlConfig(org.ff4j.conf.XmlConfig) Feature(org.ff4j.core.Feature) Property(org.ff4j.property.Property) FeatureStore(org.ff4j.core.FeatureStore) PropertyStore(org.ff4j.property.store.PropertyStore)

Aggregations

PropertyStore (org.ff4j.property.store.PropertyStore)8 InMemoryPropertyStore (org.ff4j.property.store.InMemoryPropertyStore)6 FeatureStore (org.ff4j.core.FeatureStore)3 AbstractPollingScheduler (com.netflix.config.AbstractPollingScheduler)2 DynamicConfiguration (com.netflix.config.DynamicConfiguration)2 FixedDelayPollingScheduler (com.netflix.config.FixedDelayPollingScheduler)2 PolledConfigurationSource (com.netflix.config.PolledConfigurationSource)2 Map (java.util.Map)2 FF4j (org.ff4j.FF4j)2 Property (org.ff4j.property.Property)2 BeforeClass (org.junit.BeforeClass)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 PropertyStoreAuditProxy (org.ff4j.audit.proxy.PropertyStoreAuditProxy)1 FF4JCacheManager (org.ff4j.cache.FF4JCacheManager)1 FF4jCacheProxy (org.ff4j.cache.FF4jCacheProxy)1 InMemoryCacheManager (org.ff4j.cache.InMemoryCacheManager)1 Store2CachePollingScheduler (org.ff4j.cache.Store2CachePollingScheduler)1 XmlConfig (org.ff4j.conf.XmlConfig)1 XmlParser (org.ff4j.conf.XmlParser)1