Search in sources :

Example 6 with IOption

use of org.apache.hyracks.api.config.IOption 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;
}
Also used : Arrays(java.util.Arrays) URL(java.net.URL) ConfigManagerApplicationConfig(org.apache.hyracks.control.common.application.ConfigManagerApplicationConfig) HashMap(java.util.HashMap) IConfigurator(org.apache.hyracks.api.config.IConfigurator) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) IOption(org.apache.hyracks.api.config.IOption) HashSet(java.util.HashSet) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) CmdLineParser(org.kohsuke.args4j.CmdLineParser) OptionHandlerFilter(org.kohsuke.args4j.OptionHandlerFilter) Section(org.apache.hyracks.api.config.Section) EnumMap(java.util.EnumMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) IApplicationConfig(org.apache.hyracks.api.config.IApplicationConfig) Set(java.util.Set) IOException(java.io.IOException) Option(org.kohsuke.args4j.Option) Logger(java.util.logging.Logger) Ini(org.ini4j.Ini) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) Consumer(java.util.function.Consumer) HyracksException(org.apache.hyracks.api.exceptions.HyracksException) CmdLineException(org.kohsuke.args4j.CmdLineException) List(java.util.List) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) CompositeMap(org.apache.commons.collections4.map.CompositeMap) Profile(org.ini4j.Profile) IConfigManager(org.apache.hyracks.api.config.IConfigManager) Comparator(java.util.Comparator) Collections(java.util.Collections) SortedMap(java.util.SortedMap) CmdLineParser(org.kohsuke.args4j.CmdLineParser) ArrayList(java.util.ArrayList) IOption(org.apache.hyracks.api.config.IOption) Section(org.apache.hyracks.api.config.Section) 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) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 7 with IOption

use of org.apache.hyracks.api.config.IOption in project asterixdb by apache.

the class ConfigManager method toIni.

public Ini toIni(boolean includeDefaults) {
    Ini ini = new Ini();
    for (Map.Entry<IOption, Object> entry : (includeDefaults ? configurationMap : definedMap).entrySet()) {
        if (entry.getValue() != null) {
            final IOption option = entry.getKey();
            ini.add(option.section().sectionName(), option.ini(), option.type().serializeToIni(entry.getValue()));
        }
    }
    for (Map.Entry<String, Map<IOption, Object>> nodeMapEntry : nodeSpecificMap.entrySet()) {
        String section = Section.NC.sectionName() + "/" + nodeMapEntry.getKey();
        for (Map.Entry<IOption, Object> entry : nodeMapEntry.getValue().entrySet()) {
            if (entry.getValue() != null) {
                final IOption option = entry.getKey();
                ini.add(section, option.ini(), option.type().serializeToIni(entry.getValue()));
            }
        }
    }
    return ini;
}
Also used : Ini(org.ini4j.Ini) IOption(org.apache.hyracks.api.config.IOption) 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 8 with IOption

use of org.apache.hyracks.api.config.IOption in project asterixdb by apache.

the class RegisterNodeWork method doRun.

@Override
protected void doRun() throws Exception {
    String id = reg.getNodeId();
    IIPCHandle ncIPCHandle = ccs.getClusterIPC().getHandle(reg.getNodeControllerAddress());
    CCNCFunctions.NodeRegistrationResult result;
    Map<IOption, Object> ncConfiguration = new HashMap<>();
    try {
        INodeController nodeController = new NodeControllerRemoteProxy(ncIPCHandle);
        NodeControllerState state = new NodeControllerState(nodeController, reg);
        INodeManager nodeManager = ccs.getNodeManager();
        nodeManager.addNode(id, state);
        IApplicationConfig cfg = state.getNCConfig().getConfigManager().getNodeEffectiveConfig(id);
        for (IOption option : cfg.getOptions()) {
            ncConfiguration.put(option, cfg.get(option));
        }
        LOGGER.log(Level.INFO, "Registered INodeController: id = " + id);
        NodeParameters params = new NodeParameters();
        params.setClusterControllerInfo(ccs.getClusterControllerInfo());
        params.setDistributedState(ccs.getContext().getDistributedState());
        params.setHeartbeatPeriod(ccs.getCCConfig().getHeartbeatPeriod());
        params.setProfileDumpPeriod(ccs.getCCConfig().getProfileDumpPeriod());
        result = new CCNCFunctions.NodeRegistrationResult(params, null);
    } catch (Exception e) {
        result = new CCNCFunctions.NodeRegistrationResult(null, e);
    }
    ncIPCHandle.send(-1, result, null);
    ccs.getContext().notifyNodeJoin(id, ncConfiguration);
}
Also used : IIPCHandle(org.apache.hyracks.ipc.api.IIPCHandle) INodeManager(org.apache.hyracks.control.cc.cluster.INodeManager) NodeControllerRemoteProxy(org.apache.hyracks.control.common.ipc.NodeControllerRemoteProxy) INodeController(org.apache.hyracks.control.common.base.INodeController) HashMap(java.util.HashMap) CCNCFunctions(org.apache.hyracks.control.common.ipc.CCNCFunctions) NodeParameters(org.apache.hyracks.control.common.controllers.NodeParameters) IOption(org.apache.hyracks.api.config.IOption) IApplicationConfig(org.apache.hyracks.api.config.IApplicationConfig) NodeControllerState(org.apache.hyracks.control.cc.NodeControllerState)

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