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);
}
}
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;
}
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");
}
}
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");
}
}
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");
}
}
Aggregations