Search in sources :

Example 1 with ConfiguratorException

use of org.codice.ddf.admin.configurator.ConfiguratorException in project admin-console-beta by connexta.

the class AdminOperation method readState.

@Override
public Map<String, Object> readState() throws ConfiguratorException {
    try {
        Map<String, Object> configResults = getConfigAdminMBean().getProperties(pid);
        if (configResults.isEmpty()) {
            Optional<Map<String, Object>> defaultMetatypeValues = getConfigAdminMBean().listServices().stream().filter(service -> service.get("id") != null && service.get("id").equals(pid)).findFirst();
            List<Map<String, Object>> metatypes = new ArrayList<>();
            if (defaultMetatypeValues.isPresent()) {
                metatypes = (List) defaultMetatypeValues.get().get("metatype");
            }
            return metatypes.stream().collect(Collectors.toMap(field -> (String) field.get("id"), field -> field.get("defaultValue")));
        } else {
            return configResults;
        }
    // return getConfigAdminMBean().getProperties(pid);
    } catch (IOException | MalformedObjectNameException e) {
        throw new ConfiguratorException(String.format("Unable to find configuration for pid, %s", pid), e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) List(java.util.List) ConfiguratorException(org.codice.ddf.admin.configurator.ConfiguratorException) Logger(org.slf4j.Logger) ConfigurationAdminMBean(org.codice.ddf.ui.admin.api.ConfigurationAdminMBean) Map(java.util.Map) LoggerFactory(org.slf4j.LoggerFactory) Optional(java.util.Optional) IOException(java.io.IOException) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) MalformedObjectNameException(javax.management.MalformedObjectNameException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ConfiguratorException(org.codice.ddf.admin.configurator.ConfiguratorException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with ConfiguratorException

use of org.codice.ddf.admin.configurator.ConfiguratorException in project admin-console-beta by connexta.

the class AdminOperation method commit.

@Override
public Void commit() throws ConfiguratorException {
    Map<String, Object> properties;
    if (keepIgnored) {
        properties = new HashMap<>(currentProperties);
    } else {
        properties = new HashMap<>();
    }
    properties.putAll(configs);
    try {
        saveConfigs(properties);
    } catch (IOException | MalformedObjectNameException e) {
        throw new ConfiguratorException(String.format("Error writing configuration for %s", pid));
    }
    return null;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) IOException(java.io.IOException) ConfiguratorException(org.codice.ddf.admin.configurator.ConfiguratorException)

Example 3 with ConfiguratorException

use of org.codice.ddf.admin.configurator.ConfiguratorException in project admin-console-beta by connexta.

the class ManagedServiceOperation method readState.

@Override
public Map<String, Map<String, Object>> readState() throws ConfiguratorException {
    try {
        String[][] configurations = getConfigAdmin().getConfigurations(String.format("(service.factoryPid=%s)", factoryPid));
        if (configurations == null || configurations.length == 0) {
            return Collections.emptyMap();
        }
        HashMap<String, Map<String, Object>> retVal = new HashMap<>();
        ConfigurationAdminMBean configAdminMBean = getConfigAdminMBean();
        for (String[] configuration : configurations) {
            String configPid = configuration[0];
            retVal.put(configPid, configAdminMBean.getProperties(configPid));
        }
        return retVal;
    } catch (IOException | MalformedObjectNameException e) {
        LOGGER.debug("Error retrieving configurations for factoryPid, {}", factoryPid, e);
        throw new ConfiguratorException("Error retrieving configurations");
    }
}
Also used : ConfigurationAdminMBean(org.codice.ddf.ui.admin.api.ConfigurationAdminMBean) MalformedObjectNameException(javax.management.MalformedObjectNameException) HashMap(java.util.HashMap) IOException(java.io.IOException) ConfiguratorException(org.codice.ddf.admin.configurator.ConfiguratorException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with ConfiguratorException

use of org.codice.ddf.admin.configurator.ConfiguratorException in project admin-console-beta by connexta.

the class PropertyOperation method saveProperties.

void saveProperties(Map<String, String> propertyMap) throws ConfiguratorException {
    Properties properties = new Properties();
    properties.putAll(propertyMap);
    try (FileOutputStream out = new FileOutputStream(configFile)) {
        properties.store(out, null);
    } catch (IOException e) {
        LOGGER.debug("Error writing properties to file {}", configFile, e);
        throw new ConfiguratorException("Error writing properties to file");
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Properties(java.util.Properties) ConfiguratorException(org.codice.ddf.admin.configurator.ConfiguratorException)

Example 5 with ConfiguratorException

use of org.codice.ddf.admin.configurator.ConfiguratorException in project admin-console-beta by connexta.

the class ManagedServiceOperation method createManagedService.

String createManagedService(Map<String, Object> properties) {
    try {
        String configPid = configAdmin.createFactoryConfiguration(factoryPid);
        cfgAdmMbean.update(configPid, properties);
        return configPid;
    } catch (IOException e) {
        LOGGER.debug("Error creating managed service for factoryPid {}", factoryPid, e);
        throw new ConfiguratorException("Internal error");
    }
}
Also used : IOException(java.io.IOException) ConfiguratorException(org.codice.ddf.admin.configurator.ConfiguratorException)

Aggregations

IOException (java.io.IOException)5 ConfiguratorException (org.codice.ddf.admin.configurator.ConfiguratorException)5 MalformedObjectNameException (javax.management.MalformedObjectNameException)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConfigurationAdminMBean (org.codice.ddf.ui.admin.api.ConfigurationAdminMBean)2 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1