Search in sources :

Example 1 with AdminConsoleServiceMBean

use of org.codice.ddf.admin.core.api.jmx.AdminConsoleServiceMBean in project ddf by codice.

the class ServiceOperation method readState.

private static Map<String, Object> readState(String pid, AdminConsoleServiceMBean adminConsoleServiceMBean) throws ConfiguratorException {
    try {
        Map<String, Object> configResults = adminConsoleServiceMBean.getProperties(pid);
        if (configResults.isEmpty()) {
            Optional<Service> defaultMetatypeValues = adminConsoleServiceMBean.listServices().stream().filter(service -> service.getId() != null && service.getId().equals(pid)).findFirst();
            List<MetatypeAttribute> metatypes = new ArrayList<>();
            if (defaultMetatypeValues.isPresent()) {
                metatypes = defaultMetatypeValues.get().getAttributeDefinitions();
            }
            return metatypes.stream().collect(Collectors.toMap(MetatypeAttribute::getId, MetatypeAttribute::getDefaultValue));
        } else {
            return configResults;
        }
    } catch (IOException e) {
        throw new ConfiguratorException(String.format("Unable to find configuration for pid, %s", pid), e);
    }
}
Also used : ConfigValidator.validateString(org.codice.ddf.admin.configurator.impl.ConfigValidator.validateString) ConfiguratorException(org.codice.ddf.admin.configurator.ConfiguratorException) Logger(org.slf4j.Logger) Service(org.codice.ddf.admin.core.api.Service) ServiceActions(org.codice.ddf.internal.admin.configurator.actions.ServiceActions) LoggerFactory(org.slf4j.LoggerFactory) Result(org.codice.ddf.admin.configurator.Result) IOException(java.io.IOException) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) MalformedObjectNameException(javax.management.MalformedObjectNameException) List(java.util.List) Operation(org.codice.ddf.admin.configurator.Operation) AdminConsoleServiceMBean(org.codice.ddf.admin.core.api.jmx.AdminConsoleServiceMBean) ConfigValidator.validateMap(org.codice.ddf.admin.configurator.impl.ConfigValidator.validateMap) MetatypeAttribute(org.codice.ddf.admin.core.api.MetatypeAttribute) Map(java.util.Map) OsgiUtils.getConfigAdminMBean(org.codice.ddf.admin.configurator.impl.OsgiUtils.getConfigAdminMBean) Optional(java.util.Optional) Collections(java.util.Collections) ArrayList(java.util.ArrayList) Service(org.codice.ddf.admin.core.api.Service) ConfigValidator.validateString(org.codice.ddf.admin.configurator.impl.ConfigValidator.validateString) IOException(java.io.IOException) MetatypeAttribute(org.codice.ddf.admin.core.api.MetatypeAttribute) ConfiguratorException(org.codice.ddf.admin.configurator.ConfiguratorException)

Example 2 with AdminConsoleServiceMBean

use of org.codice.ddf.admin.core.api.jmx.AdminConsoleServiceMBean in project ddf by codice.

the class ManagedServiceOperation method readState.

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

Aggregations

IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConfiguratorException (org.codice.ddf.admin.configurator.ConfiguratorException)2 ConfigValidator.validateMap (org.codice.ddf.admin.configurator.impl.ConfigValidator.validateMap)2 ConfigValidator.validateString (org.codice.ddf.admin.configurator.impl.ConfigValidator.validateString)2 AdminConsoleServiceMBean (org.codice.ddf.admin.core.api.jmx.AdminConsoleServiceMBean)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 Operation (org.codice.ddf.admin.configurator.Operation)1 Result (org.codice.ddf.admin.configurator.Result)1 OsgiUtils.getConfigAdminMBean (org.codice.ddf.admin.configurator.impl.OsgiUtils.getConfigAdminMBean)1 MetatypeAttribute (org.codice.ddf.admin.core.api.MetatypeAttribute)1 Service (org.codice.ddf.admin.core.api.Service)1 ServiceActions (org.codice.ddf.internal.admin.configurator.actions.ServiceActions)1 Logger (org.slf4j.Logger)1