use of org.commonjava.propulsor.config.ConfigurationException in project indy by Commonjava.
the class IndyHttpConfig method sectionComplete.
@Override
public void sectionComplete(String name) throws ConfigurationException {
Map<String, SiteConfigBuilder> builderMap = new HashMap<>();
// key: siteId, value: attributes (map)
Map<String, Map<String, Object>> attributesMap = new HashMap<>();
Map<String, String> parametersMap = getConfiguration();
for (Map.Entry<String, String> et : parametersMap.entrySet()) {
String key = et.getKey();
String value = et.getValue();
switch(key) {
case URI:
case USER:
case PROXY_HOST:
case PROXY_PORT:
case PROXY_USER:
case TRUST_TYPE:
case KEY_CERT_PEM:
case KEY_CERT_PEM_PATH:
case SERVER_CERT_PEM:
case SERVER_CERT_PEM_PATH:
case REQUEST_TIMEOUT_SECONDS:
case MAX_CONNECTIONS:
withEntry(getSiteConfigBuilder(builderMap, DEFAULT_SITE), key, value);
break;
case KEY_PASSWORD:
case PASSWORD:
case PROXY_PASSWORD:
withAttribute(getAttributes(attributesMap, DEFAULT_SITE), getAttributeName(key), value);
break;
default:
// Not match? Never mind. These are non-default config entries, e.g., keycloak.key.cert.pem=xxx
int idx = key.indexOf(".");
String siteId = key.substring(0, idx);
String realKey = key.substring(idx + 1);
if (isAttribute(realKey)) {
withAttribute(getAttributes(attributesMap, siteId), getAttributeName(realKey), value);
} else {
withEntry(getSiteConfigBuilder(builderMap, siteId), realKey, value);
}
break;
}
}
for (Map.Entry<String, Map<String, Object>> et : attributesMap.entrySet()) {
SiteConfigBuilder builder = builderMap.get(et.getKey());
if (builder == null) {
throw new ConfigurationException("[http.conf] No site " + et.getKey() + " defined for attributes");
}
builder.withAttributes(et.getValue());
}
for (Map.Entry<String, SiteConfigBuilder> et : builderMap.entrySet()) {
siteConfigMap.put(et.getKey(), et.getValue().build());
}
logger.debug("Section complete, name={}, siteConfigMap={}", name, siteConfigMap);
}
use of org.commonjava.propulsor.config.ConfigurationException in project indy by Commonjava.
the class IndyKojiConfig method parameter.
@Override
public void parameter(final String name, final String value) throws ConfigurationException {
Logger logger = LoggerFactory.getLogger(getClass());
logger.trace("Got koji config parameter: '{}' with value: '{}'", name, value);
switch(name) {
case "enabled":
{
this.enabled = Boolean.valueOf(value.trim());
break;
}
case "tag.patterns.enabled":
{
this.tagPatternsEnabled = Boolean.valueOf(value.trim());
break;
}
case "query.cache.enabled":
{
this.queryCacheEnabled = Boolean.valueOf(value.trim());
break;
}
case "query.cache.timeout.hours":
{
this.queryCacheTimeoutHours = Integer.valueOf(value);
break;
}
case "proxy.binary.builds":
{
this.proxyBinaryBuilds = Boolean.valueOf(value.trim());
break;
}
case "tag.pattern":
{
if (tagPatterns == null) {
tagPatterns = new ArrayList<>();
}
this.tagPatterns.add(value);
break;
}
case "lock.timeout.seconds":
{
this.lockTimeoutSeconds = Long.parseLong(value);
break;
}
case "metadata.timeout.seconds":
{
this.metadataTimeoutSeconds = Long.parseLong(value);
break;
}
case "storage.root.url":
{
this.storageRootUrl = value;
break;
}
case "proxy.password":
{
this.proxyPassword = value;
break;
}
case "proxy.user":
{
this.proxyUser = value;
break;
}
case "proxy.host":
{
this.proxyHost = value;
break;
}
case "proxy.port":
{
this.proxyPort = Integer.valueOf(value);
break;
}
case "client.pem.password":
{
this.keyPassword = value;
break;
}
case "url":
{
this.url = value;
break;
}
case "ssl.trust.type":
{
this.siteTrustType = value;
break;
}
case "connection.pool.timeout.seconds":
{
this.connectionPoolTimeoutSeconds = Integer.valueOf(value);
break;
}
case "request.timeout.seconds":
{
this.requestTimeoutSeconds = Integer.valueOf(value);
break;
}
case "client.pem.path":
{
this.clientPemPath = value;
break;
}
case "server.pem.path":
{
this.serverPemPath = value;
break;
}
case "server.pem.enabled":
{
this.serverPemEnabled = Boolean.valueOf(value.trim());
break;
}
case "max.connections":
{
this.maxConnections = Integer.valueOf(value);
break;
}
case "artifact.authorityStore":
{
this.artifactAuthorityStore = value;
break;
}
case "naming.format":
{
this.namingFormat = value;
break;
}
case "naming.format.binary":
{
this.binayNamingFormat = value;
break;
}
case "version.filter":
{
this.versionFilter = value;
break;
}
default:
{
if (name.startsWith(TARGET_KEY_PREFIX) && name.length() > TARGET_KEY_PREFIX.length()) {
if (name.startsWith(TARGET_BINARY_KEY_PREFIX) && name.length() > TARGET_BINARY_KEY_PREFIX.length()) {
String source = name.substring(TARGET_BINARY_KEY_PREFIX.length(), name.length());
logger.trace("KOJI: Group {} targets binary group {}", source, value);
targetBinaryGroups.put(source, value);
} else {
String source = name.substring(TARGET_KEY_PREFIX.length(), name.length());
logger.trace("KOJI: Group {} targets group {}", source, value);
targetGroups.put(source, value);
}
} else {
throw new ConfigurationException("Invalid KOJI config parameter: %s=%s", name, value);
}
}
}
}
use of org.commonjava.propulsor.config.ConfigurationException in project indy by Commonjava.
the class DefaultIndyConfigFactory method load.
// private static String configPath = System.getProperty( CONFIG_PATH_PROP, DEFAULT_CONFIG_PATH );
//
// public static void setConfigPath( final String path )
// {
// configPath = path;
// }
//
// @PostConstruct
@Override
public synchronized void load(final String configPath) throws ConfigurationException {
logger.info("\n\n\n\n[CONFIG] Reading Indy configuration in: '{}'\n\nAdding configuration section listeners:", Thread.currentThread().getName());
logger.info("Adding configuration sections...");
if (configSections != null) {
for (final IndyConfigInfo section : configSections) {
String sectionName = ConfigUtils.getSectionName(section.getClass());
logger.info("Adding configuration section: {}", sectionName);
with(sectionName, section);
}
}
final String config = configPath(configPath);
logger.info("\n\n[CONFIG] Reading configuration in: '{}'\n\nfrom {}", Thread.currentThread().getName(), config);
File configFile = new File(config);
if (configFile.isDirectory()) {
configFile = new File(configFile, "main.conf");
}
if (!configFile.exists()) {
File dir = configFile;
if (dir.getName().equals("main.conf")) {
dir = dir.getParentFile();
}
logger.warn("Cannot find configuration in: {}. Writing default configurations there for future modification.", dir);
if (!dir.exists() && !dir.mkdirs()) {
throw new ConfigurationException("Failed to create configuration directory: %s, in order to write defaults.", dir);
}
writeDefaultConfigs(dir);
}
List<ConfigurationListener> listeners = new ArrayList<>();
listeners.add(this);
if (configListeners != null) {
configListeners.forEach((listener) -> listeners.add(listener));
}
InputStream stream = null;
try {
Properties props = getBaseSystemProperties();
configSections.forEach((section) -> {
if (section instanceof SystemPropertyProvider) {
Properties p = ((SystemPropertyProvider) section).getSystemPropertyAdditions();
p.stringPropertyNames().forEach((name) -> props.setProperty(name, p.getProperty(name)));
}
});
stream = ConfigFileUtils.readFileWithIncludes(config);
new DotConfConfigurationReader(listeners).loadConfiguration(stream, props);
System.setProperties(props);
} catch (final IOException e) {
throw new ConfigurationException("Cannot open configuration file: {}. Reason: {}", e, configPath, e.getMessage());
} finally {
closeQuietly(stream);
}
logger.info("[CONFIG] Indy configuration complete for: '{}'.\n\n\n\n", Thread.currentThread().getName());
}
use of org.commonjava.propulsor.config.ConfigurationException in project indy by Commonjava.
the class DefaultIndyConfigFactory method writeDefaultsFor.
private void writeDefaultsFor(final IndyConfigInfo section, final File dir) throws ConfigurationException {
String sectionName = ConfigUtils.getSectionName(section.getClass());
logger.info("Attempting to write default configuration for section: {}", sectionName);
try (InputStream configStream = section.getDefaultConfig()) {
if (configStream != null) {
final String fname = section.getDefaultConfigFileName();
if (fname == null) {
logger.info("NOT writing default configuration for: {}. No defaults available.", sectionName);
return;
}
final File file = new File(dir, fname);
if (!"main.conf".equals(fname) && file.exists()) {
logger.info("NOT writing default configuration to: {}. That file already exists.", file);
return;
}
file.getParentFile().mkdirs();
logger.info("Writing defaults for: {} to: {}", sectionName, file);
FileOutputStream out = null;
try {
// if the filename is 'main.conf', then APPEND the config.
out = new FileOutputStream(file, fname.equals("main.conf"));
IOUtils.copy(configStream, out);
} catch (final IOException e) {
throw new ConfigurationException("Failed to write default configuration to: %s. Reason: %s", e, file, e.getMessage());
} finally {
closeQuietly(out);
}
}
} catch (IOException ioe) {
throw new ConfigurationException("Failed to write default configuration to: %s/%s. Reason: %s", dir.getName(), section.getDefaultConfigFileName(), ioe.getMessage());
}
}
use of org.commonjava.propulsor.config.ConfigurationException in project indy by Commonjava.
the class IndyWeftConfig method parameter.
@Override
public void parameter(final String name, final String value) throws ConfigurationException {
try {
if (DEFAULT_THREADS.equals(name)) {
final int v = Integer.parseInt(value);
weftConfig.configureDefaultThreads(v);
} else if (DEFAULT_PRIORITY.equals(name)) {
final int v = Integer.parseInt(value);
weftConfig.configureDefaultPriority(v);
} else if (DEFAULT_MAX_LOAD_FACTOR.equals(name)) {
final float v = Float.parseFloat(value);
weftConfig.configureDefaultMaxLoadFactor(v);
} else if (ENABLED.equals(name)) {
weftConfig.configureEnabled(Boolean.parseBoolean(value));
} else if (NODE_PREFIX.equals(name)) {
weftConfig.configureNodePrefix(value);
} else {
final int lastIdx = name.lastIndexOf('.');
if (lastIdx > -1 && name.length() > lastIdx) {
final String pool = name.substring(0, lastIdx);
final String suffix = name.substring(lastIdx);
if (THREADS_SUFFIX.equals(suffix)) {
final int v = Integer.parseInt(value);
weftConfig.configureThreads(pool, v);
} else if (PRIORITY_SUFFIX.equals(suffix)) {
final int v = Integer.parseInt(value);
weftConfig.configurePriority(pool, v);
} else if (ENABLED_SUFFIX.equals(suffix)) {
weftConfig.configureEnabled(pool, Boolean.parseBoolean(value));
} else if (MAX_LOAD_FACTOR_SUFFIX.equals(suffix)) {
final float v = Float.parseFloat(value);
weftConfig.configureMaxLoadFactor(pool, v);
}
}
}
} catch (NumberFormatException e) {
throw new ConfigurationException("Non-numeric value for 'threadpools' parameter: '{}' (value was: '{}')", name, value);
}
}
Aggregations