/**
  * Check whether a configuration is fully configured to be used with an Accumulo {@link
  * InputFormat}.
  *
  * @param job the Hadoop context for the configured job
  * @throws java.io.IOException if the context is improperly configured
  * @since 1.5.0
  */
 protected static void validateOptions(JobConf job) throws IOException {
   final Instance inst = InputConfigurator.validateInstance(CLASS, job);
   String principal = InputConfigurator.getPrincipal(CLASS, job);
   AuthenticationToken token = InputConfigurator.getAuthenticationToken(CLASS, job);
   // In secure mode, we need to convert the DelegationTokenStub into a real DelegationToken
   token = ConfiguratorBase.unwrapAuthenticationToken(job, token);
   Connector conn;
   try {
     conn = inst.getConnector(principal, token);
   } catch (Exception e) {
     throw new IOException(e);
   }
   InputConfigurator.validatePermissions(CLASS, job, conn);
 }
  /**
   * Set all the initial parameters needed in this class for connectivity out to Accumulo.
   *
   * @param context
   */
  private void initialize(JobContext context) { // Configuration conf){

    Configuration conf = context.getConfiguration();
    try {
      // output zoom level
      log.info("Working from zoom level = " + zoomLevel);
      if (zoomLevel == -1) {
        zoomLevel = Integer.parseInt(conf.get(MrGeoAccumuloConstants.MRGEO_ACC_KEY_ZOOMLEVEL));
      }

      table = conf.get(MrGeoAccumuloConstants.MRGEO_ACC_KEY_OUTPUT_TABLE);
      username = conf.get(MrGeoAccumuloConstants.MRGEO_ACC_KEY_USER);
      instanceName = conf.get(MrGeoAccumuloConstants.MRGEO_ACC_KEY_INSTANCE);
      zooKeepers = conf.get(MrGeoAccumuloConstants.MRGEO_ACC_KEY_ZOOKEEPERS);

      String pl = conf.get(MrGeoConstants.MRGEO_PROTECTION_LEVEL);
      if (pl != null) {
        colViz = new ColumnVisibility(pl);
      } else if (colViz == null) {
        vizStr = conf.get(MrGeoAccumuloConstants.MRGEO_ACC_KEY_VIZ);

        if (vizStr == null) {
          colViz = new ColumnVisibility();
        } else {
          colViz = new ColumnVisibility(vizStr);
        }
      }

      password = conf.get(MrGeoAccumuloConstants.MRGEO_ACC_KEY_PASSWORD);
      String isEnc = conf.get(MrGeoAccumuloConstants.MRGEO_ACC_KEY_PWENCODED64, "false");
      if (isEnc.equalsIgnoreCase("true")) {
        password = Base64Utils.decodeToString(password);
      }

      if (_innerFormat != null) {
        return;
      }

      _innerFormat = AccumuloOutputFormat.class.newInstance();
      AuthenticationToken token = new PasswordToken(password.getBytes());
      //      log.info("Setting output with: u = " + username);
      //      log.info("Setting output with: p = " + password);
      //      log.info("Setting output with: i = " + instanceName);
      //      log.info("Setting output with: z = " + zooKeepers);

      boolean connSet = ConfiguratorBase.isConnectorInfoSet(AccumuloOutputFormat.class, conf);
      if (!connSet) {
        // job not always available - do it how Accumulo does it
        OutputConfigurator.setConnectorInfo(AccumuloOutputFormat.class, conf, username, token);
        ClientConfiguration cc = ClientConfiguration.loadDefault().withInstance(instanceName);
        cc.setProperty(ClientProperty.INSTANCE_ZK_HOST, zooKeepers);

        OutputConfigurator.setZooKeeperInstance(AccumuloOutputFormat.class, conf, cc);
        OutputConfigurator.setDefaultTableName(AccumuloOutputFormat.class, conf, table);
        OutputConfigurator.setCreateTables(AccumuloOutputFormat.class, conf, true);

        outputInfoSet = true;
      }
    } catch (InstantiationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (AccumuloSecurityException ase) {
      ase.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  } // end initialize
 /**
  * Gets the authenticated token from either the specified token file or directly from the
  * configuration, whichever was used when the job was configured.
  *
  * @param job the Hadoop context for the configured job
  * @return the principal's authentication token
  * @since 1.6.0
  * @see #setConnectorInfo(JobConf, String, AuthenticationToken)
  * @see #setConnectorInfo(JobConf, String, String)
  */
 protected static AuthenticationToken getAuthenticationToken(JobConf job) {
   AuthenticationToken token = InputConfigurator.getAuthenticationToken(CLASS, job);
   return ConfiguratorBase.unwrapAuthenticationToken(job, token);
 }
 /**
  * Gets the authenticated token from either the specified token file or directly from the
  * configuration, whichever was used when the job was configured.
  *
  * @param context the Hadoop context for the configured job
  * @return the principal's authentication token
  * @since 1.6.0
  * @see #setConnectorInfo(Job, String, AuthenticationToken)
  * @see #setConnectorInfo(Job, String, String)
  */
 protected static AuthenticationToken getAuthenticationToken(JobContext context) {
   AuthenticationToken token =
       InputConfigurator.getAuthenticationToken(CLASS, context.getConfiguration());
   return ConfiguratorBase.unwrapAuthenticationToken(context, token);
 }