Search in sources :

Example 1 with ConfigFileInfo

use of org.apache.karaf.features.ConfigFileInfo in project karaf by apache.

the class FeatureConfigInstaller method installFeatureConfigs.

public void installFeatureConfigs(Feature feature) throws IOException, InvalidSyntaxException {
    for (ConfigInfo config : feature.getConfigurations()) {
        TypedProperties props = new TypedProperties();
        // trim lines
        String val = config.getValue();
        if (config.isExternal()) {
            props.load(new URL(val));
        } else {
            props.load(new StringReader(val));
        }
        String[] pid = parsePid(config.getName());
        Configuration cfg = findExistingConfiguration(configAdmin, pid[0], pid[1]);
        if (cfg == null) {
            Dictionary<String, Object> cfgProps = convertToDict(props);
            cfg = createConfiguration(configAdmin, pid[0], pid[1]);
            String key = createConfigurationKey(pid[0], pid[1]);
            cfgProps.put(CONFIG_KEY, key);
            cfg.update(cfgProps);
            try {
                updateStorage(pid[0], pid[1], props, false);
            } catch (Exception e) {
                LOGGER.warn("Can't update cfg file", e);
            }
        } else if (config.isAppend()) {
            boolean update = false;
            Dictionary<String, Object> properties = cfg.getProperties();
            for (String key : props.keySet()) {
                if (properties.get(key) == null) {
                    properties.put(key, props.get(key));
                    update = true;
                }
            }
            if (update) {
                cfg.update(properties);
                try {
                    updateStorage(pid[0], pid[1], props, true);
                } catch (Exception e) {
                    LOGGER.warn("Can't update cfg file", e);
                }
            }
        }
    }
    for (ConfigFileInfo configFile : feature.getConfigurationFiles()) {
        installConfigurationFile(configFile.getLocation(), configFile.getFinalname(), configFile.isOverride());
    }
}
Also used : Configuration(org.osgi.service.cm.Configuration) StringReader(java.io.StringReader) ConfigFileInfo(org.apache.karaf.features.ConfigFileInfo) ConfigInfo(org.apache.karaf.features.ConfigInfo) TypedProperties(org.apache.felix.utils.properties.TypedProperties) URL(java.net.URL) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 2 with ConfigFileInfo

use of org.apache.karaf.features.ConfigFileInfo in project karaf by apache.

the class KarServiceImpl method copyFeatureToJar.

private void copyFeatureToJar(JarOutputStream jos, Feature feature, Map<URI, Integer> locationMap) throws URISyntaxException {
    for (BundleInfo bundleInfo : feature.getBundles()) {
        URI location = new URI(bundleInfo.getLocation());
        copyResourceToJar(jos, location, locationMap);
    }
    for (ConfigFileInfo configFileInfo : feature.getConfigurationFiles()) {
        URI location = new URI(configFileInfo.getLocation());
        copyResourceToJar(jos, location, locationMap);
    }
}
Also used : BundleInfo(org.apache.karaf.features.BundleInfo) ConfigFileInfo(org.apache.karaf.features.ConfigFileInfo) URI(java.net.URI)

Example 3 with ConfigFileInfo

use of org.apache.karaf.features.ConfigFileInfo in project karaf by apache.

the class JmxFeature method getConfigFileList.

static TabularData getConfigFileList(List<ConfigFileInfo> configFiles) throws OpenDataException {
    TabularDataSupport table = new TabularDataSupport(FEATURE_CONFIG_FILES_TABLE);
    for (ConfigFileInfo configFile : configFiles) {
        String[] itemNames = FeaturesServiceMBean.FEATURE_CONFIG_FILES;
        Object[] itemValues = { configFile.getFinalname() };
        CompositeData config = new CompositeDataSupport(FEATURE_CONFIG_FILES, itemNames, itemValues);
        table.put(config);
    }
    return table;
}
Also used : TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) ConfigFileInfo(org.apache.karaf.features.ConfigFileInfo)

Aggregations

ConfigFileInfo (org.apache.karaf.features.ConfigFileInfo)3 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URL (java.net.URL)1 CompositeData (javax.management.openmbean.CompositeData)1 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)1 TabularDataSupport (javax.management.openmbean.TabularDataSupport)1 TypedProperties (org.apache.felix.utils.properties.TypedProperties)1 BundleInfo (org.apache.karaf.features.BundleInfo)1 ConfigInfo (org.apache.karaf.features.ConfigInfo)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 Configuration (org.osgi.service.cm.Configuration)1