use of org.codice.ddf.configuration.status.ConfigurationFileException in project ddf by codice.
the class ConfigurationAdminMigration method getConfigurationFiles.
private Collection<ConfigurationFile> getConfigurationFiles() throws IOException {
Collection<Path> files = listFiles();
Collection<ConfigurationFile> configurationFiles = new ArrayList<>(files.size());
for (Path file : files) {
ConfigurationFile configFile;
try {
configFile = configurationFileFactory.createConfigurationFile(file);
configurationFiles.add(configFile);
} catch (ConfigurationFileException e) {
LOGGER.info(e.getMessage(), e);
moveConfigurationFile(file, failedDirectory);
}
}
return configurationFiles;
}
use of org.codice.ddf.configuration.status.ConfigurationFileException in project ddf by codice.
the class ConfigurationAdminMigration method notify.
@Override
public void notify(Path file) {
Path fileInFailedDirectory = failedDirectory.resolve(file.getFileName());
boolean result = deleteFileFromFailedDirectory(fileInFailedDirectory);
LOGGER.debug("Deleted file [{}]: {}", fileInFailedDirectory.toString(), result);
try {
ConfigurationFile configFile = configurationFileFactory.createConfigurationFile(file);
configFile.createConfig();
moveConfigurationFile(file, processedDirectory);
} catch (ConfigurationFileException | RuntimeException e) {
moveConfigurationFile(file, failedDirectory);
}
}
use of org.codice.ddf.configuration.status.ConfigurationFileException in project ddf by codice.
the class ConfigurationAdminMigration method export.
public void export(@NotNull Path exportDirectory) throws MigrationException, IOException {
notNull(exportDirectory, "exportDirectory cannot be null");
Path etcDirectory = createEtcDirectory(exportDirectory);
try {
Configuration[] configurations = configurationAdmin.listConfigurations(FILTER);
if (configurations != null) {
for (Configuration configuration : configurations) {
Path exportedFilePath = etcDirectory.resolve(configuration.getPid() + configurationFileExtension);
try {
configurationFileFactory.createConfigurationFile(configuration.getProperties()).exportConfig(exportedFilePath.toString());
} catch (ConfigurationFileException e) {
LOGGER.info("Could not create configuration file {} for configuration {}.", exportedFilePath, configuration.getPid());
throw new ExportMigrationException(e);
} catch (IOException e) {
LOGGER.info("Could not export configuration {} to {}.", configuration.getPid(), exportedFilePath);
throw new ExportMigrationException(e);
}
}
}
} catch (InvalidSyntaxException e) {
LOGGER.info("Invalid filter string {}", FILTER, e);
throw new UnexpectedMigrationException("Export failed", e);
} catch (IOException e) {
LOGGER.info("There was an issue retrieving configurations from ConfigurationAdmin: {}", e.getMessage());
throw new UnexpectedMigrationException("Export failed", e);
}
}
use of org.codice.ddf.configuration.status.ConfigurationFileException in project ddf by codice.
the class FelixPersistenceStrategy method read.
@Override
@SuppressWarnings("unchecked")
public Dictionary<String, Object> read(InputStream inputStream) throws ConfigurationFileException, IOException {
notNull(inputStream, "InputStream cannot be null");
final StringBuilder filteredOutput = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
PropertyConverter propertyConverter = createPropertyConverter(filteredOutput);
reader.lines().forEach(propertyConverter);
LOGGER.debug("Calling ConfigurationHandler with {}", filteredOutput.toString());
Dictionary properties;
try {
properties = ConfigurationHandler.read(new ByteArrayInputStream(filteredOutput.toString().getBytes(StandardCharsets.UTF_8)));
} catch (RuntimeException e) {
LOGGER.info("ConfigurationHandler failed to read configuration from file", e);
throw new ConfigurationFileException("Failed to read configuration from file", e);
}
checkForInvalidProperties(propertyConverter.getPropertyNames(), properties);
return properties;
}
use of org.codice.ddf.configuration.status.ConfigurationFileException in project ddf by codice.
the class ManagedServiceConfigurationFile method createConfig.
@Override
public void createConfig() throws ConfigurationFileException {
String servicePid = getServicePid();
try {
Configuration configuration = configAdmin.getConfiguration(servicePid, null);
configuration.update(properties);
} catch (IOException e) {
String message = String.format("Unable to get or update Configuration for pid [%s].", servicePid);
LOGGER.info(message, e);
throw new ConfigurationFileException(message, e);
}
}
Aggregations