Example usage for org.apache.cassandra.tools NodeProbe close

List of usage examples for org.apache.cassandra.tools NodeProbe close

Introduction

In this page you can find the example usage for org.apache.cassandra.tools NodeProbe close.

Prototype

public void close() throws IOException 

Source Link

Usage

From source file:com.perpetumobile.bit.orm.cassandra.CliMain.java

License:Apache License

private void describeKeySpace(String keySpaceName, KsDef metadata) throws TException {
    NodeProbe probe = sessionState.getNodeProbe();

    // getting compaction manager MBean to displaying index building information
    CompactionManagerMBean compactionManagerMBean = (probe == null) ? null : probe.getCompactionManagerProxy();

    // Describe and display
    sessionState.out.println("Keyspace: " + keySpaceName + ":");
    try {/*  w  ww  .  ja v a2 s .  c o m*/
        KsDef ks_def;
        ks_def = metadata == null ? thriftClient.describe_keyspace(keySpaceName) : metadata;
        sessionState.out.println("  Replication Strategy: " + ks_def.strategy_class);

        sessionState.out.println("  Durable Writes: " + ks_def.durable_writes);

        Map<String, String> options = ks_def.strategy_options;
        sessionState.out
                .println("    Options: [" + ((options == null) ? "" : FBUtilities.toString(options)) + "]");

        sessionState.out.println("  Column Families:");

        Collections.sort(ks_def.cf_defs, new CfDefNamesComparator());

        for (CfDef cf_def : ks_def.cf_defs)
            describeColumnFamily(ks_def, cf_def, probe);

        // compaction manager information
        if (compactionManagerMBean != null) {
            for (Map<String, String> info : compactionManagerMBean.getCompactions()) {
                // if ongoing compaction type is index build
                if (info.get("taskType").equals(OperationType.INDEX_BUILD.toString()))
                    continue;
                sessionState.out.printf("%nCurrently building index %s, completed %d of %d bytes.%n",
                        info.get("columnfamily"), info.get("bytesComplete"), info.get("totalBytes"));
            }
        }

        // closing JMX connection
        if (probe != null)
            probe.close();
    } catch (InvalidRequestException e) {
        sessionState.out.println("Invalid request: " + e);
    } catch (NotFoundException e) {
        sessionState.out.println("Keyspace " + keySpaceName + " could not be found.");
    } catch (IOException e) {
        sessionState.out.println("Error while closing JMX connection: " + e.getMessage());
    }
}

From source file:com.perpetumobile.bit.orm.cassandra.CliMain.java

License:Apache License

private void executeDescribe(Tree statement) throws TException, InvalidRequestException, NotFoundException {
    if (!CliMain.isConnected())
        return;/*from  w  w w  .  j av a  2  s . c o m*/

    printCQL3TablesWarning("describe");

    int argCount = statement.getChildCount();

    if (keySpace == null && argCount == 0) {
        sessionState.out
                .println("Authenticate to a Keyspace, before using `describe` or `describe <column_family>`");
        return;
    }

    KsDef currentKeySpace = null;
    if (keySpace != null) {
        keyspacesMap.remove(keySpace);
        currentKeySpace = getKSMetaData(keySpace);
    }

    if (argCount > 1) // in case somebody changes Cli grammar
        throw new RuntimeException("`describe` command take maximum one argument. See `help describe;`");

    if (argCount == 0) {
        if (currentKeySpace != null) {
            describeKeySpace(currentKeySpace.name, null);
            return;
        }

        sessionState.out
                .println("Authenticate to a Keyspace, before using `describe` or `describe <column_family>`");
    } else if (argCount == 1) {
        // name of the keyspace or ColumnFamily
        String entityName = statement.getChild(0).getText();

        KsDef inputKsDef = CliUtils.getKeySpaceDef(entityName, thriftClient.describe_keyspaces());

        if (inputKsDef == null && currentKeySpace == null)
            throw new RuntimeException(String.format("Keyspace with name '%s' wasn't found, "
                    + "to lookup ColumnFamily with that name, please, authorize to one "
                    + "of the keyspaces first.", entityName));

        CfDef inputCfDef = (inputKsDef == null) ? getCfDef(currentKeySpace, entityName) : null; // no need to lookup CfDef if we know that it was keyspace

        if (inputKsDef != null) {
            describeKeySpace(inputKsDef.name, inputKsDef);
        } else if (inputCfDef != null) {
            NodeProbe probe = sessionState.getNodeProbe();

            try {
                describeColumnFamily(currentKeySpace, inputCfDef, probe);

                if (probe != null)
                    probe.close();
            } catch (IOException e) {
                sessionState.out.println("Error while closing JMX connection: " + e.getMessage());
            }
        } else {
            sessionState.out.println("Sorry, no Keyspace nor ColumnFamily was found with name: " + entityName);
        }
    }
}