use of org.apache.hyracks.api.config.IOption in project asterixdb by apache.
the class ConfigUsageTest method generateUsage.
public void generateUsage(String startDelim, String midDelim, String endDelim, EnumMap<Column, Boolean> align, PrintStream output) {
ConfigManager configManager = getConfigManager();
StringBuilder buf = new StringBuilder();
final Column[] columns = Column.values();
for (Section section : getSections(configManager)) {
for (IOption option : getSectionOptions(configManager, section)) {
for (Column column : columns) {
if (align.computeIfAbsent(column, c -> false)) {
calculateMaxWidth(option, column);
}
}
}
}
// output header
for (Column column : columns) {
buf.append(column.ordinal() == 0 ? startDelim : midDelim);
pad(buf, StringUtils.capitalize(column.name().toLowerCase()), align.computeIfAbsent(column, c -> false) ? calculateMaxWidth(column, column.name()) : 0);
}
buf.append(endDelim).append('\n');
StringBuilder sepLine = new StringBuilder();
for (Column column : columns) {
sepLine.append(column.ordinal() == 0 ? startDelim : midDelim);
pad(sepLine, "", maxWidths.getOrDefault(column, 0), '-');
}
sepLine.append(endDelim).append('\n');
buf.append(sepLine.toString().replace(' ', '-'));
for (Section section : getSections(configManager)) {
List<IOption> options = new ArrayList<>(getSectionOptions(configManager, section));
options.sort(Comparator.comparing(IOption::ini));
for (IOption option : options) {
for (Column column : columns) {
buf.append(column.ordinal() == 0 ? startDelim : midDelim);
if (column == Column.SECTION) {
center(buf, extractValue(column, option), maxWidths.getOrDefault(column, 0));
} else {
pad(buf, extractValue(column, option), maxWidths.getOrDefault(column, 0));
}
}
buf.append(endDelim).append('\n');
}
}
output.println(buf);
}
use of org.apache.hyracks.api.config.IOption in project asterixdb by apache.
the class ConfigManager method extractIniPointersFromCommandLine.
private void extractIniPointersFromCommandLine() throws CmdLineException {
Map<IOption, Object> cmdLineOptions = new HashMap<>();
processCommandLine(cmdLineSections, usageFilter, cmdLineOptions::put);
for (IOption option : iniPointerOptions) {
if (cmdLineOptions.containsKey(option)) {
set(option, cmdLineOptions.get(option));
}
}
}
use of org.apache.hyracks.api.config.IOption in project asterixdb by apache.
the class ConfigManager method parseIni.
private void parseIni() throws IOException {
Ini ini = null;
for (IOption option : iniPointerOptions) {
Object pointer = get(option);
if (pointer instanceof String) {
ini = ConfigUtils.loadINIFile((String) pointer);
} else if (pointer instanceof URL) {
ini = ConfigUtils.loadINIFile((URL) pointer);
} else if (pointer != null) {
throw new IllegalArgumentException("config file pointer options must be of type String (for file) or " + "URL, instead of " + option.type().targetType());
}
}
if (ini == null) {
LOGGER.info("no INI file specified; skipping parsing");
return;
}
LOGGER.info("parsing INI file: " + ini);
for (Profile.Section section : ini.values()) {
allSections.add(section.getName());
final Section rootSection = Section.parseSectionName(section.getParent() == null ? section.getName() : section.getParent().getName());
String node;
if (rootSection == Section.EXTENSION) {
parseExtensionIniSection(section);
continue;
} else if (rootSection == Section.NC) {
node = section.getName().equals(section.getSimpleName()) ? null : section.getSimpleName();
} else if (Section.parseSectionName(section.getName()) != null) {
node = null;
} else {
throw new HyracksException("Unknown section in ini: " + section.getName());
}
Map<String, IOption> optionMap = getSectionOptionMap(rootSection);
for (Map.Entry<String, String> iniOption : section.entrySet()) {
String name = iniOption.getKey();
final IOption option = optionMap == null ? null : optionMap.get(name);
if (option == null) {
handleUnknownOption(section, name);
return;
}
final String value = iniOption.getValue();
LOGGER.fine("setting " + option.toIniString() + " to " + value);
final Object parsed = option.type().parse(value);
invokeSetters(option, parsed, node);
}
}
}
use of org.apache.hyracks.api.config.IOption in project asterixdb by apache.
the class ConfigManager method getOptionNames.
public Set<String> getOptionNames(String sectionName) {
Set<String> optionNames = new HashSet<>();
Section section = Section.parseSectionName(sectionName);
for (IOption option : getSectionOptionMap(section).values()) {
optionNames.add(option.ini());
}
return optionNames;
}
use of org.apache.hyracks.api.config.IOption in project asterixdb by apache.
the class ConfigManager method register.
@Override
public void register(IOption... options) {
for (IOption option : options) {
if (option.section() == Section.VIRTUAL || registeredOptions.contains(option)) {
continue;
}
if (configured) {
throw new IllegalStateException("configuration already processed");
}
LOGGER.fine("registering option: " + option.toIniString());
Map<String, IOption> optionMap = sectionMap.computeIfAbsent(option.section(), section -> new HashMap<>());
IOption prev = optionMap.put(option.ini(), option);
if (prev != null) {
if (prev != option) {
throw new IllegalStateException("An option cannot be defined multiple times: " + option.toIniString() + ": " + Arrays.asList(option.getClass(), prev.getClass()));
}
} else {
registeredOptions.add(option);
optionSetters.put(option, (node, value, isDefault) -> correctedMap(option.section() == Section.NC ? node : null, isDefault).put(option, value));
if (LOGGER.isLoggable(Level.FINE)) {
optionSetters.put(option, (node, value, isDefault) -> LOGGER.fine((isDefault ? "defaulting" : "setting ") + option.toIniString() + " to " + value));
}
}
}
}
Aggregations