Search in sources :

Example 1 with IOption

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);
}
Also used : IOption(org.apache.hyracks.api.config.IOption) ArrayList(java.util.ArrayList) Section(org.apache.hyracks.api.config.Section) ConfigManager(org.apache.hyracks.control.common.config.ConfigManager)

Example 2 with IOption

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));
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) IOption(org.apache.hyracks.api.config.IOption)

Example 3 with IOption

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);
        }
    }
}
Also used : Ini(org.ini4j.Ini) IOption(org.apache.hyracks.api.config.IOption) HyracksException(org.apache.hyracks.api.exceptions.HyracksException) Section(org.apache.hyracks.api.config.Section) URL(java.net.URL) Profile(org.ini4j.Profile) HashMap(java.util.HashMap) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) Map(java.util.Map) EnumMap(java.util.EnumMap) TreeMap(java.util.TreeMap) CompositeMap(org.apache.commons.collections4.map.CompositeMap) SortedMap(java.util.SortedMap)

Example 4 with IOption

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;
}
Also used : IOption(org.apache.hyracks.api.config.IOption) Section(org.apache.hyracks.api.config.Section) HashSet(java.util.HashSet)

Example 5 with IOption

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));
            }
        }
    }
}
Also used : IOption(org.apache.hyracks.api.config.IOption)

Aggregations

IOption (org.apache.hyracks.api.config.IOption)8 HashMap (java.util.HashMap)5 ArrayListValuedHashMap (org.apache.commons.collections4.multimap.ArrayListValuedHashMap)4 Section (org.apache.hyracks.api.config.Section)4 EnumMap (java.util.EnumMap)3 Map (java.util.Map)3 SortedMap (java.util.SortedMap)3 TreeMap (java.util.TreeMap)3 CompositeMap (org.apache.commons.collections4.map.CompositeMap)3 Ini (org.ini4j.Ini)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 IApplicationConfig (org.apache.hyracks.api.config.IApplicationConfig)2 HyracksException (org.apache.hyracks.api.exceptions.HyracksException)2 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1