Search in sources :

Example 1 with TracingConfigurationCommandArg

use of org.apache.ignite.internal.commandline.tracing.configuration.TracingConfigurationCommandArg in project ignite by apache.

the class TracingConfigurationCommand method parseArguments.

/**
 * {@inheritDoc}
 */
@Override
public void parseArguments(CommandArgIterator argIter) {
    // If there is no arguments, use list command.
    if (!argIter.hasNextSubArg()) {
        args = new TracingConfigurationArguments.Builder(TracingConfigurationSubcommand.GET_ALL).build();
        return;
    }
    TracingConfigurationSubcommand cmd = of(argIter.nextArg("Expected tracing configuration action."));
    if (cmd == null)
        throw new IllegalArgumentException("Expected correct tracing configuration action.");
    TracingConfigurationArguments.Builder tracingConfigurationArgs = new TracingConfigurationArguments.Builder(cmd);
    Scope scope = null;
    String lb = null;
    double samplingRate = SAMPLING_RATE_NEVER;
    Set<Scope> includedScopes = new HashSet<>();
    while (argIter.hasNextSubArg()) {
        TracingConfigurationCommandArg arg = CommandArgUtils.of(argIter.nextArg(""), TracingConfigurationCommandArg.class);
        String strVal;
        assert arg != null;
        switch(arg) {
            case SCOPE:
                {
                    String peekedNextArg = argIter.peekNextArg();
                    if (!TracingConfigurationCommandArg.args().contains(peekedNextArg)) {
                        strVal = argIter.nextArg("The scope should be specified. The following " + "values can be used: " + Arrays.toString(Scope.values()) + '.');
                        try {
                            scope = Scope.valueOf(strVal);
                        } catch (IllegalArgumentException e) {
                            throw new IllegalArgumentException("Invalid scope '" + strVal + "'. The following " + "values can be used: " + Arrays.toString(Scope.values()) + '.');
                        }
                    }
                    break;
                }
            case LABEL:
                {
                    lb = argIter.nextArg("The label should be specified.");
                    break;
                }
            case SAMPLING_RATE:
                {
                    strVal = argIter.nextArg("The sampling rate should be specified. Decimal value between 0 and 1 should be used.");
                    try {
                        samplingRate = Double.parseDouble(strVal);
                    } catch (IllegalArgumentException e) {
                        throw new IllegalArgumentException("Invalid sampling-rate '" + strVal + "'. Decimal value between 0 and 1 should be used.");
                    }
                    if (samplingRate < SAMPLING_RATE_NEVER || samplingRate > SAMPLING_RATE_ALWAYS)
                        throw new IllegalArgumentException("Invalid sampling-rate '" + strVal + "'. Decimal value between 0 and 1 should be used.");
                    break;
                }
            case INCLUDED_SCOPES:
                {
                    Set<String> setStrVals = argIter.nextStringSet("At least one supported scope should be specified.");
                    for (String scopeStrVal : setStrVals) {
                        try {
                            includedScopes.add(Scope.valueOf(scopeStrVal));
                        } catch (IllegalArgumentException e) {
                            throw new IllegalArgumentException("Invalid supported scope '" + scopeStrVal + "'. The following " + "values can be used: " + Arrays.toString(Scope.values()) + '.');
                        }
                    }
                    break;
                }
        }
    }
    // Scope is a mandatory attribute for all sub-commands except get_all and reset_all.
    if ((cmd != GET_ALL && cmd != RESET_ALL) && scope == null) {
        throw new IllegalArgumentException("Scope attribute is missing. Following values can be used: " + Arrays.toString(Scope.values()) + '.');
    }
    switch(cmd) {
        case GET_ALL:
        case RESET_ALL:
            {
                tracingConfigurationArgs.withScope(scope);
                break;
            }
        case RESET:
        case GET:
            {
                tracingConfigurationArgs.withScope(scope).withLabel(lb);
                break;
            }
        case SET:
            {
                tracingConfigurationArgs.withScope(scope).withLabel(lb).withSamplingRate(samplingRate).withIncludedScopes(includedScopes);
                break;
            }
        default:
            {
                // We should never get here.
                assert false : "Unexpected tracing configuration argument [arg= " + cmd + ']';
            }
    }
    args = tracingConfigurationArgs.build();
}
Also used : TracingConfigurationCommandArg(org.apache.ignite.internal.commandline.tracing.configuration.TracingConfigurationCommandArg) HashSet(java.util.HashSet) Set(java.util.Set) Scope(org.apache.ignite.spi.tracing.Scope) TracingConfigurationArguments(org.apache.ignite.internal.commandline.tracing.configuration.TracingConfigurationArguments) TracingConfigurationSubcommand(org.apache.ignite.internal.commandline.tracing.configuration.TracingConfigurationSubcommand) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 Set (java.util.Set)1 TracingConfigurationArguments (org.apache.ignite.internal.commandline.tracing.configuration.TracingConfigurationArguments)1 TracingConfigurationCommandArg (org.apache.ignite.internal.commandline.tracing.configuration.TracingConfigurationCommandArg)1 TracingConfigurationSubcommand (org.apache.ignite.internal.commandline.tracing.configuration.TracingConfigurationSubcommand)1 Scope (org.apache.ignite.spi.tracing.Scope)1