Search in sources :

Example 1 with TransferDirection

use of org.apache.nifi.remote.TransferDirection in project nifi by apache.

the class SiteToSiteCliMain method parseCli.

/**
 * Parses command line options into a CliParse object
 *
 * @param options an empty options object (so callers can print usage if the parse fails
 * @param args    the string array of arguments
 * @return a CliParse object containing the constructed SiteToSiteClient.Builder and a TransferDirection
 * @throws ParseException if there is an error parsing the command line
 */
public static CliParse parseCli(Options options, String[] args) throws ParseException {
    options.addOption("u", URL_OPTION, true, "NiFI URL to connect to (default: " + URL_OPTION_DEFAULT + ")");
    options.addOption("d", DIRECTION_OPTION, true, "Direction (valid directions: " + Arrays.stream(TransferDirection.values()).map(Object::toString).collect(Collectors.joining(", ")) + ") (default: " + DIRECTION_OPTION_DEFAULT + ")");
    options.addOption("n", PORT_NAME_OPTION, true, "Port name");
    options.addOption("i", PORT_IDENTIFIER_OPTION, true, "Port id");
    options.addOption(null, TIMEOUT_OPTION, true, "Timeout");
    options.addOption(null, PENALIZATION_OPTION, true, "Penalization period");
    options.addOption(null, KEYSTORE_OPTION, true, "Keystore");
    options.addOption(null, KEY_STORE_TYPE_OPTION, true, "Keystore type (default: " + KEYSTORE_TYPE_OPTION_DEFAULT + ")");
    options.addOption(null, KEY_STORE_PASSWORD_OPTION, true, "Keystore password");
    options.addOption(null, TRUST_STORE_OPTION, true, "Truststore");
    options.addOption(null, TRUST_STORE_TYPE_OPTION, true, "Truststore type (default: " + KEYSTORE_TYPE_OPTION_DEFAULT + ")");
    options.addOption(null, TRUST_STORE_PASSWORD_OPTION, true, "Truststore password");
    options.addOption(null, NEED_CLIENT_AUTH_OPTION, false, "Need client auth");
    options.addOption("c", COMPRESSION_OPTION, false, "Use compression");
    options.addOption(null, PEER_PERSISTENCE_FILE_OPTION, true, "File to write peer information to so it can be recovered on restart");
    options.addOption("p", TRANSPORT_PROTOCOL_OPTION, true, "Site to site transport protocol (default: " + TRANSPORT_PROTOCOL_OPTION_DEFAULT + ")");
    options.addOption(null, BATCH_COUNT_OPTION, true, "Number of flow files in a batch");
    options.addOption(null, BATCH_SIZE_OPTION, true, "Size of flow files in a batch");
    options.addOption(null, BATCH_DURATION_OPTION, true, "Duration of a batch");
    options.addOption(null, PROXY_HOST_OPTION, true, "Proxy hostname");
    options.addOption(null, PROXY_PORT_OPTION, true, "Proxy port");
    options.addOption(null, PROXY_USERNAME_OPTION, true, "Proxy username");
    options.addOption(null, PROXY_PASSWORD_OPTION, true, "Proxy password");
    options.addOption("h", HELP_OPTION, false, "Show help message and exit");
    CommandLineParser parser = new DefaultParser();
    CommandLine commandLine;
    commandLine = parser.parse(options, args);
    if (commandLine.hasOption(HELP_OPTION)) {
        printUsage(null, options);
        System.exit(1);
    }
    SiteToSiteClient.Builder builder = new SiteToSiteClient.Builder();
    builder.url(commandLine.getOptionValue(URL_OPTION, URL_OPTION_DEFAULT));
    if (commandLine.hasOption(PORT_NAME_OPTION)) {
        builder.portName(commandLine.getOptionValue(PORT_NAME_OPTION));
    }
    if (commandLine.hasOption(PORT_IDENTIFIER_OPTION)) {
        builder.portIdentifier(commandLine.getOptionValue(PORT_IDENTIFIER_OPTION));
    }
    if (commandLine.hasOption(TIMEOUT_OPTION)) {
        builder.timeout(FormatUtils.getTimeDuration(commandLine.getOptionValue(TIMEOUT_OPTION), TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);
    }
    if (commandLine.hasOption(PENALIZATION_OPTION)) {
        builder.nodePenalizationPeriod(FormatUtils.getTimeDuration(commandLine.getOptionValue(PENALIZATION_OPTION), TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);
    }
    if (commandLine.hasOption(KEYSTORE_OPTION)) {
        builder.keystoreFilename(commandLine.getOptionValue(KEYSTORE_OPTION));
        builder.keystoreType(KeystoreType.valueOf(commandLine.getOptionValue(KEY_STORE_TYPE_OPTION, KEYSTORE_TYPE_OPTION_DEFAULT).toUpperCase()));
        if (commandLine.hasOption(KEY_STORE_PASSWORD_OPTION)) {
            builder.keystorePass(commandLine.getOptionValue(KEY_STORE_PASSWORD_OPTION));
        } else {
            throw new ParseException("Must specify keystore password");
        }
    }
    if (commandLine.hasOption(TRUST_STORE_OPTION)) {
        builder.truststoreFilename(commandLine.getOptionValue(TRUST_STORE_OPTION));
        builder.truststoreType(KeystoreType.valueOf(commandLine.getOptionValue(TRUST_STORE_TYPE_OPTION, KEYSTORE_TYPE_OPTION_DEFAULT).toUpperCase()));
        if (commandLine.hasOption(TRUST_STORE_PASSWORD_OPTION)) {
            builder.truststorePass(commandLine.getOptionValue(TRUST_STORE_PASSWORD_OPTION));
        } else {
            throw new ParseException("Must specify truststore password");
        }
    }
    if (commandLine.hasOption(COMPRESSION_OPTION)) {
        builder.useCompression(true);
    } else {
        builder.useCompression(false);
    }
    if (commandLine.hasOption(PEER_PERSISTENCE_FILE_OPTION)) {
        builder.peerPersistenceFile(new File(commandLine.getOptionValue(PEER_PERSISTENCE_FILE_OPTION)));
    }
    if (commandLine.hasOption(BATCH_COUNT_OPTION)) {
        builder.requestBatchCount(Integer.parseInt(commandLine.getOptionValue(BATCH_COUNT_OPTION)));
    }
    if (commandLine.hasOption(BATCH_SIZE_OPTION)) {
        builder.requestBatchSize(Long.parseLong(commandLine.getOptionValue(BATCH_SIZE_OPTION)));
    }
    if (commandLine.hasOption(BATCH_DURATION_OPTION)) {
        builder.requestBatchDuration(FormatUtils.getTimeDuration(commandLine.getOptionValue(BATCH_DURATION_OPTION), TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);
    }
    if (commandLine.hasOption(PROXY_HOST_OPTION)) {
        builder.httpProxy(new HttpProxy(commandLine.getOptionValue(PROXY_HOST_OPTION), Integer.parseInt(commandLine.getOptionValue(PROXY_PORT_OPTION, PROXY_PORT_OPTION_DEFAULT)), commandLine.getOptionValue(PROXY_USERNAME_OPTION), commandLine.getOptionValue(PROXY_PASSWORD_OPTION)));
    }
    builder.transportProtocol(SiteToSiteTransportProtocol.valueOf(commandLine.getOptionValue(TRANSPORT_PROTOCOL_OPTION, TRANSPORT_PROTOCOL_OPTION_DEFAULT).toUpperCase()));
    TransferDirection transferDirection = TransferDirection.valueOf(commandLine.getOptionValue(DIRECTION_OPTION, DIRECTION_OPTION_DEFAULT));
    return new CliParse() {

        @Override
        public SiteToSiteClient.Builder getBuilder() {
            return builder;
        }

        @Override
        public TransferDirection getTransferDirection() {
            return transferDirection;
        }
    };
}
Also used : SiteToSiteClient(org.apache.nifi.remote.client.SiteToSiteClient) HttpProxy(org.apache.nifi.remote.protocol.http.HttpProxy) CommandLine(org.apache.commons.cli.CommandLine) TransferDirection(org.apache.nifi.remote.TransferDirection) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) File(java.io.File) DefaultParser(org.apache.commons.cli.DefaultParser)

Aggregations

File (java.io.File)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 ParseException (org.apache.commons.cli.ParseException)1 TransferDirection (org.apache.nifi.remote.TransferDirection)1 SiteToSiteClient (org.apache.nifi.remote.client.SiteToSiteClient)1 HttpProxy (org.apache.nifi.remote.protocol.http.HttpProxy)1