public static boolean getInputIsWide(Configuration conf) {
   return Boolean.parseBoolean(conf.get(INPUT_WIDEROWS_CONFIG));
 }
Ejemplo n.º 2
0
  /**
   * Initialize any state for this DB. Called once per DB instance; there is one DB instance per
   * client thread.
   */
  public void init() throws DBException {
    String hosts = getProperties().getProperty("hosts");
    if (hosts == null) {
      throw new DBException("Required property \"hosts\" missing for CassandraClient");
    }

    column_family =
        getProperties().getProperty(COLUMN_FAMILY_PROPERTY, COLUMN_FAMILY_PROPERTY_DEFAULT);
    parent = new ColumnParent(column_family);

    ConnectionRetries =
        Integer.parseInt(
            getProperties()
                .getProperty(CONNECTION_RETRY_PROPERTY, CONNECTION_RETRY_PROPERTY_DEFAULT));
    OperationRetries =
        Integer.parseInt(
            getProperties()
                .getProperty(OPERATION_RETRY_PROPERTY, OPERATION_RETRY_PROPERTY_DEFAULT));

    String username = getProperties().getProperty(USERNAME_PROPERTY);
    String password = getProperties().getProperty(PASSWORD_PROPERTY);

    _debug = Boolean.parseBoolean(getProperties().getProperty("debug", "false"));

    String[] allhosts = hosts.split(",");
    String myhost = allhosts[random.nextInt(allhosts.length)];

    Exception connectexception = null;

    for (int retry = 0; retry < ConnectionRetries; retry++) {
      tr = new TFramedTransport(new TSocket(myhost, 9160));
      TProtocol proto = new TBinaryProtocol(tr);
      client = new Cassandra.Client(proto);
      try {
        tr.open();
        connectexception = null;
        break;
      } catch (Exception e) {
        connectexception = e;
      }
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
      }
    }
    if (connectexception != null) {
      System.err.println(
          "Unable to connect to " + myhost + " after " + ConnectionRetries + " tries");
      System.out.println(
          "Unable to connect to " + myhost + " after " + ConnectionRetries + " tries");
      throw new DBException(connectexception);
    }

    if (username != null && password != null) {
      Map<String, String> cred = new HashMap<String, String>();
      cred.put("username", username);
      cred.put("password", password);
      AuthenticationRequest req = new AuthenticationRequest(cred);
      try {
        client.login(req);
      } catch (Exception e) {
        throw new DBException(e);
      }
    }
  }