use of org.apache.hyracks.api.config.Section 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.Section 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.Section 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.Section in project asterixdb by apache.
the class ConfigManager method processCommandLine.
// use of System.err, System.exit()
@SuppressWarnings({ "squid:S106", "squid:S1147" })
private List<String> processCommandLine(Collection<Section> sections, OptionHandlerFilter usageFilter, BiConsumer<IOption, Object> setAction) throws CmdLineException {
final Args4jBean bean = new Args4jBean();
CmdLineParser cmdLineParser = new CmdLineParser(bean);
final List<String> appArgs = new ArrayList<>();
List<IOption> commandLineOptions = new ArrayList<>();
for (Map.Entry<Section, Map<String, IOption>> sectionMapEntry : sectionMap.entrySet()) {
if (!sections.contains(sectionMapEntry.getKey())) {
continue;
}
for (IOption option : sectionMapEntry.getValue().values()) {
if (option.section() != Section.VIRTUAL) {
commandLineOptions.add(option);
}
}
}
commandLineOptions.sort(Comparator.comparing(IOption::cmdline));
commandLineOptions.forEach(option -> cmdLineParser.addOption(new Args4jSetter(option, setAction, false), new Args4jOption(option, this, option.type().targetType())));
if (!argListeners.isEmpty()) {
cmdLineParser.addArgument(new Args4jSetter(o -> appArgs.add(String.valueOf(o)), true, String.class), new Args4jArgument());
}
LOGGER.fine("parsing cmdline: " + Arrays.toString(args));
if (args == null || args.length == 0) {
LOGGER.info("no command line args supplied");
return appArgs;
}
try {
cmdLineParser.parseArgument(args);
} catch (CmdLineException e) {
if (!bean.help) {
ConfigUtils.printUsage(e, usageFilter, System.err);
throw e;
} else {
LOGGER.log(Level.FINE, "Ignoring parse exception due to -help", e);
}
}
if (bean.help) {
ConfigUtils.printUsage(cmdLineParser, usageFilter, System.err);
System.exit(0);
} else if (bean.version) {
System.err.println(versionString);
System.exit(0);
}
return appArgs;
}
Aggregations