Example usage for org.apache.commons.cli ParseException getClass

List of usage examples for org.apache.commons.cli ParseException getClass

Introduction

In this page you can find the example usage for org.apache.commons.cli ParseException getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.commonvox.hbase_column_manager.UtilityRunner.java

UtilityRunner(String[] args) throws Exception, ParseException, IOException, JAXBException {
    if (args != null && args.length == 1 && (args[0].equals("-" + HELP_OPTION.getOpt())
            || args[0].equals("--" + HELP_OPTION.getLongOpt()))) {
        printHelp();//from  w w  w . ja  v a  2s  .  c o  m
        return;
    }
    CommandLineParser parser = new DefaultParser();
    CommandLine commandLine;
    try {
        commandLine = parser.parse(OPTIONS_SET_1, args);
    } catch (ParseException pe) {
        LOG.error(pe.getClass().getSimpleName() + " encountered: " + pe.getMessage());
        printHelp();
        throw pe;
    }
    if (commandLine.hasOption(HELP_OPTION.getLongOpt())) {
        printHelp();
    }
    String selectedUtility = commandLine.getOptionValue(UTILITY_OPTION.getOpt());
    if (!UTILITY_LIST.contains(selectedUtility)) {
        throw new ParseException("Invalid utility argument submitted: <" + selectedUtility + ">");
    }

    if (selectedUtility.equals(UNINSTALL_REPOSITORY)) {
        logParmInfo(commandLine);
        LOG.info(this.getClass().getSimpleName() + " is invoking the following utility: <" + selectedUtility
                + ">");
        try (Admin standardAdmin = ConnectionFactory.createConnection().getAdmin()) {
            RepositoryAdmin.uninstallRepositoryStructures(standardAdmin);
        }
        return;
    }

    try {
        parser = new DefaultParser();
        commandLine = parser.parse(OPTIONS_SET_2, args);
    } catch (ParseException pe) {
        LOG.error(pe.getClass().getSimpleName() + " encountered: " + pe.getMessage());
        printHelp();
        throw pe;
    }
    logParmInfo(commandLine);

    String selectedTableString = commandLine.getOptionValue(TABLE_OPTION.getOpt());
    String selectedNamespaceString = "";
    if (selectedTableString.endsWith(Repository.ALL_TABLES_WILDCARD_INDICATOR)) {
        selectedNamespaceString = selectedTableString.substring(0, selectedTableString.length() - 2);
        if (selectedNamespaceString.isEmpty()) {
            selectedNamespaceString = Bytes.toString(Repository.HBASE_DEFAULT_NAMESPACE);
        }
    }
    String selectedFileString = commandLine.getOptionValue(FILE_OPTION.getOpt());

    Configuration mConf = MConfiguration.create();
    // invoking UtilityRunner overrides possible inactive state of ColumnManager
    mConf.setBoolean(Repository.HBASE_CONFIG_PARM_KEY_COLMANAGER_ACTIVATED, true);

    try (Connection mConnection = MConnectionFactory.createConnection(mConf)) {
        RepositoryAdmin repositoryAdmin = new RepositoryAdmin(mConnection);
        // Note that selectedUtility will validate selectedTableString and selectedFileString
        File selectedFile = new File(selectedFileString);
        LOG.info(this.getClass().getSimpleName() + " is invoking the following utility: <" + selectedUtility
                + (selectedNamespaceString.isEmpty() ? "> on the following table: <" + selectedTableString
                        : "> on the following namespace: <" + selectedNamespaceString)
                + "> using the following " + "source/target file <" + selectedFileString + ">");
        switch (selectedUtility) {
        case EXPORT_SCHEMA_UTILITY:
            if (selectedNamespaceString.isEmpty()) {
                repositoryAdmin.exportSchema(selectedFile, TableName.valueOf(selectedTableString));
            } else {
                repositoryAdmin.exportSchema(selectedFile, selectedNamespaceString);
            }
            break;
        case IMPORT_SCHEMA_UTILITY:
            if (selectedNamespaceString.isEmpty()) {
                repositoryAdmin.importSchema(selectedFile, TableName.valueOf(selectedTableString), false);
            } else {
                repositoryAdmin.importSchema(selectedFile, selectedNamespaceString, false);
            }
            break;
        case GET_CHANGE_EVENTS_UTILITY:
            StringBuilder headerDetail = new StringBuilder("-- file generated for ")
                    .append(selectedNamespaceString.isEmpty() && selectedTableString.isEmpty()
                            ? "full " + Repository.PRODUCT_NAME + " Repository, "
                            : "")
                    .append(selectedNamespaceString.isEmpty() ? ""
                            : "Namespace:[" + selectedNamespaceString + "], ")
                    .append(selectedTableString.isEmpty() ? "" : "Table:[" + selectedTableString + "], ");
            if (selectedNamespaceString.isEmpty()) {
                ChangeEventMonitor.exportChangeEventListToCsvFile(
                        repositoryAdmin.getChangeEventMonitor()
                                .getChangeEventsForTable(TableName.valueOf(selectedTableString), true),
                        selectedFile, headerDetail.toString());
            } else {
                ChangeEventMonitor.exportChangeEventListToCsvFile(
                        repositoryAdmin.getChangeEventMonitor()
                                .getChangeEventsForNamespace(Bytes.toBytes(selectedNamespaceString), true),
                        selectedFile, headerDetail.toString());
            }
            break;
        case GET_COLUMN_QUALIFIERS_UTILITY_DIRECT_SCAN:
            if (selectedNamespaceString.isEmpty()) {
                repositoryAdmin.discoverColumnMetadata(TableName.valueOf(selectedTableString), true, false);
                repositoryAdmin.outputReportOnColumnQualifiers(selectedFile,
                        TableName.valueOf(selectedTableString));
            } else {
                repositoryAdmin.discoverColumnMetadata(selectedNamespaceString, true, false);
                repositoryAdmin.outputReportOnColumnQualifiers(selectedFile, selectedNamespaceString);
            }
            break;
        case GET_COLUMN_QUALIFIERS_UTILITY_MAP_REDUCE:
            if (selectedNamespaceString.isEmpty()) {
                repositoryAdmin.discoverColumnMetadata(TableName.valueOf(selectedTableString), true, true);
                repositoryAdmin.outputReportOnColumnQualifiers(selectedFile,
                        TableName.valueOf(selectedTableString));
            } else {
                repositoryAdmin.discoverColumnMetadata(selectedNamespaceString, true, true);
                repositoryAdmin.outputReportOnColumnQualifiers(selectedFile, selectedNamespaceString);
            }
            break;
        }
    }
}