Java Code Examples for org.apache.hadoop.hbase.CoprocessorEnvironment#getConfiguration()

The following examples show how to use org.apache.hadoop.hbase.CoprocessorEnvironment#getConfiguration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskRegionObserver.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
    Configuration config = env.getConfiguration();
    timeInterval =
            config.getLong(
                QueryServices.TASK_HANDLING_INTERVAL_MS_ATTRIB,
                QueryServicesOptions.DEFAULT_TASK_HANDLING_INTERVAL_MS);
    timeMaxInterval =
            config.getLong(
                    QueryServices.TASK_HANDLING_MAX_INTERVAL_MS_ATTRIB,
                    QueryServicesOptions.DEFAULT_TASK_HANDLING_MAX_INTERVAL_MS);
    initialDelay =
            config.getLong(
                    QueryServices.TASK_HANDLING_INITIAL_DELAY_MS_ATTRIB,
                    QueryServicesOptions.DEFAULT_TASK_HANDLING_INITIAL_DELAY_MS);
}
 
Example 2
Source File: TestCoprocessorConfiguration.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Rough test that Coprocessor Environment is Read-Only.
 * Just check a random CP and see that it returns a read-only config.
 */
@Test
public void testReadOnlyConfiguration() throws Exception {
  Configuration conf = new Configuration(CONF);
  HRegion region = mock(HRegion.class);
  when(region.getRegionInfo()).thenReturn(REGIONINFO);
  when(region.getTableDescriptor()).thenReturn(TABLEDESC);
  RegionServerServices rsServices = mock(RegionServerServices.class);
  RegionCoprocessorHost rcp = new RegionCoprocessorHost(region, rsServices, conf);
  boolean found = false;
  for (String cpStr: rcp.getCoprocessors()) {
    CoprocessorEnvironment cpenv = rcp.findCoprocessorEnvironment(cpStr);
    if (cpenv != null) {
      found = true;
    }
    Configuration c = cpenv.getConfiguration();
    thrown.expect(UnsupportedOperationException.class);
    c.set("one.two.three", "four.five.six");
  }
  assertTrue("Should be at least one CP found", found);
}
 
Example 3
Source File: MasterQuotasObserver.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void start(CoprocessorEnvironment ctx) throws IOException {
  this.conf = ctx.getConfiguration();
  this.quotasEnabled = QuotaUtil.isQuotaEnabled(conf);

  if (!(ctx instanceof MasterCoprocessorEnvironment)) {
    throw new CoprocessorException("Must be loaded on master.");
  }
  // if running on master
  MasterCoprocessorEnvironment mEnv = (MasterCoprocessorEnvironment) ctx;
  if (mEnv instanceof HasMasterServices) {
    this.masterServices = ((HasMasterServices) mEnv).getMasterServices();
  } else {
    throw new CoprocessorException("Must be loaded on a master having master services.");
  }
}
 
Example 4
Source File: VisibilityController.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
  this.conf = env.getConfiguration();

  authorizationEnabled = AccessChecker.isAuthorizationSupported(conf);
  if (!authorizationEnabled) {
    LOG.warn("The VisibilityController has been loaded with authorization checks disabled.");
  }

  if (HFile.getFormatVersion(conf) < HFile.MIN_FORMAT_VERSION_WITH_TAGS) {
    throw new RuntimeException("A minimum HFile version of " + HFile.MIN_FORMAT_VERSION_WITH_TAGS
      + " is required to persist visibility labels. Consider setting " + HFile.FORMAT_VERSION_KEY
      + " accordingly.");
  }

  // Do not create for master CPs
  if (!(env instanceof MasterCoprocessorEnvironment)) {
    visibilityLabelService = VisibilityLabelServiceManager.getInstance()
        .getVisibilityLabelService(this.conf);
  }
}
 
Example 5
Source File: IndexWriterUtils.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static HTableFactory getDefaultDelegateHTableFactory(CoprocessorEnvironment env) {
  // create a simple delegate factory, setup the way we need
  Configuration conf = env.getConfiguration();
  // set the number of threads allowed per table.
  int htableThreads =
      conf.getInt(IndexWriterUtils.INDEX_WRITER_PER_TABLE_THREADS_CONF_KEY, IndexWriterUtils.DEFAULT_NUM_PER_TABLE_THREADS);
  LOG.trace("Creating HTableFactory with " + htableThreads + " threads for each HTable.");
  IndexManagementUtil.setIfNotSet(conf, HTABLE_THREAD_KEY, htableThreads);
  return new CoprocessorHTableFactory(env);
}
 
Example 6
Source File: BasePermissionsIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
    super.start(env);
    configuration = env.getConfiguration();
    if(env instanceof RegionCoprocessorEnvironment) {
        aclRegion = AccessControlClient.ACL_TABLE_NAME.
                equals(((RegionCoprocessorEnvironment) env).getRegion().
                        getTableDescriptor().getTableName());
    }
}
 
Example 7
Source File: MetaDataRegionObserver.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
    // sleep a little bit to compensate time clock skew when SYSTEM.CATALOG moves
    // among region servers because we relies on server time of RS which is hosting
    // SYSTEM.CATALOG
    Configuration config = env.getConfiguration();
    long sleepTime = config.getLong(QueryServices.CLOCK_SKEW_INTERVAL_ATTRIB,
        QueryServicesOptions.DEFAULT_CLOCK_SKEW_INTERVAL);
    try {
        if(sleepTime > 0) {
            Thread.sleep(sleepTime);
        }
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
    }
    enableRebuildIndex =
            config.getBoolean(
                QueryServices.INDEX_FAILURE_HANDLING_REBUILD_ATTRIB,
                QueryServicesOptions.DEFAULT_INDEX_FAILURE_HANDLING_REBUILD);
    rebuildIndexTimeInterval =
            config.getLong(
                QueryServices.INDEX_FAILURE_HANDLING_REBUILD_INTERVAL_ATTRIB,
                QueryServicesOptions.DEFAULT_INDEX_FAILURE_HANDLING_REBUILD_INTERVAL);
    initialRebuildTaskDelay =
            config.getLong(
                QueryServices.INDEX_REBUILD_TASK_INITIAL_DELAY,
                QueryServicesOptions.DEFAULT_INDEX_REBUILD_TASK_INITIAL_DELAY);
}
 
Example 8
Source File: PhoenixAccessController.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
    Configuration conf = env.getConfiguration();
    this.accessCheckEnabled = conf.getBoolean(QueryServices.PHOENIX_ACLS_ENABLED,
            QueryServicesOptions.DEFAULT_PHOENIX_ACLS_ENABLED);
        if (!this.accessCheckEnabled) {
            LOGGER.warn(
                    "PhoenixAccessController has been loaded with authorization checks disabled.");
        }
    this.execPermissionsCheckEnabled = conf.getBoolean(AccessControlConstants.EXEC_PERMISSION_CHECKS_KEY,
            AccessControlConstants.DEFAULT_EXEC_PERMISSION_CHECKS);
    if (env instanceof PhoenixMetaDataControllerEnvironment) {
        this.env = (PhoenixMetaDataControllerEnvironment)env;
    } else {
        throw new IllegalArgumentException(
                "Not a valid environment, should be loaded by PhoenixMetaDataControllerEnvironment");
    }

    ZKWatcher zk = null;
    RegionCoprocessorEnvironment regionEnv = this.env.getRegionCoprocessorEnvironment();
    if (regionEnv instanceof HasRegionServerServices) {
        zk = ((HasRegionServerServices) regionEnv).getRegionServerServices().getZooKeeper();
    }
    accessChecker = new AccessChecker(env.getConfiguration(), zk);
    // set the user-provider.
    this.userProvider = UserProvider.instantiate(env.getConfiguration());
    // init superusers and add the server principal (if using security)
    // or process owner as default super user.
    Superusers.initialize(env.getConfiguration());
}
 
Example 9
Source File: IndexWriterUtils.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public static HTableFactory getDefaultDelegateHTableFactory(CoprocessorEnvironment env) {
  // create a simple delegate factory, setup the way we need
  Configuration conf = env.getConfiguration();
  // set the number of threads allowed per table.
  int htableThreads =
      conf.getInt(IndexWriterUtils.INDEX_WRITER_PER_TABLE_THREADS_CONF_KEY, IndexWriterUtils.DEFAULT_NUM_PER_TABLE_THREADS);
  LOG.trace("Creating HTableFactory with " + htableThreads + " threads for each HTable.");
  IndexManagementUtil.setIfNotSet(conf, HTABLE_THREAD_KEY, htableThreads);
  return new CoprocessorHTableFactory(env);
}
 
Example 10
Source File: TestClassLoading.java    From hbase with Apache License 2.0 4 votes vote down vote up
void loadingClassFromLibDirInJar(String libPrefix) throws Exception {
  FileSystem fs = cluster.getFileSystem();

  File innerJarFile1 = buildCoprocessorJar(cpName1);
  File innerJarFile2 = buildCoprocessorJar(cpName2);
  File outerJarFile = new File(TEST_UTIL.getDataTestDir().toString(), "outer.jar");

  ClassLoaderTestHelper.addJarFilesToJar(
    outerJarFile, libPrefix, innerJarFile1, innerJarFile2);

  // copy the jars into dfs
  fs.copyFromLocalFile(new Path(outerJarFile.getPath()),
    new Path(fs.getUri().toString() + Path.SEPARATOR));
  String jarFileOnHDFS = fs.getUri().toString() + Path.SEPARATOR +
    outerJarFile.getName();
  assertTrue("Copy jar file to HDFS failed.",
    fs.exists(new Path(jarFileOnHDFS)));
  LOG.info("Copied jar file to HDFS: " + jarFileOnHDFS);

  // create a table that references the coprocessors
  TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder(tableName);
  tdb.setColumnFamily(ColumnFamilyDescriptorBuilder
    .newBuilder(Bytes.toBytes("test")).build());
    // without configuration values
  tdb.setValue("COPROCESSOR$1", jarFileOnHDFS + "|" + cpName1
    + "|" + Coprocessor.PRIORITY_USER);
    // with configuration values
  tdb.setValue("COPROCESSOR$2", jarFileOnHDFS + "|" + cpName2
    + "|" + Coprocessor.PRIORITY_USER + "|k1=v1,k2=v2,k3=v3");
  Admin admin = TEST_UTIL.getAdmin();
  if (admin.tableExists(tableName)) {
    if (admin.isTableEnabled(tableName)) {
      admin.disableTable(tableName);
    }
    admin.deleteTable(tableName);
  }

  TableDescriptor tableDescriptor = tdb.build();
  admin.createTable(tableDescriptor);
  waitForTable(tableDescriptor.getTableName());

  // verify that the coprocessors were loaded
  boolean found1 = false, found2 = false, found2_k1 = false,
      found2_k2 = false, found2_k3 = false;
  MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
  for (HRegion region: hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
    if (region.getRegionInfo().getRegionNameAsString().startsWith(tableName.getNameAsString())) {
      CoprocessorEnvironment env;
      env = region.getCoprocessorHost().findCoprocessorEnvironment(cpName1);
      if (env != null) {
        found1 = true;
      }
      env = region.getCoprocessorHost().findCoprocessorEnvironment(cpName2);
      if (env != null) {
        found2 = true;
        Configuration conf = env.getConfiguration();
        found2_k1 = conf.get("k1") != null;
        found2_k2 = conf.get("k2") != null;
        found2_k3 = conf.get("k3") != null;
      }
    }
  }
  assertTrue("Class " + cpName1 + " was missing on a region", found1);
  assertTrue("Class " + cpName2 + " was missing on a region", found2);
  assertTrue("Configuration key 'k1' was missing on a region", found2_k1);
  assertTrue("Configuration key 'k2' was missing on a region", found2_k2);
  assertTrue("Configuration key 'k3' was missing on a region", found2_k3);
}
 
Example 11
Source File: VisibilityReplication.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
  this.conf = env.getConfiguration();
  visibilityLabelService = VisibilityLabelServiceManager.getInstance()
      .getVisibilityLabelService(this.conf);
}
 
Example 12
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 2 votes vote down vote up
/**
 * Fetch the {@link Configuration} that contains the properties required by the coprocessor. By default,
 * the HBase configuration is returned. This method will never return {@code null} in Tephra but the derived
 * classes might do so if {@link Configuration} is not available temporarily (for example, if it is being fetched
 * from a HBase Table.
 *
 * @param env {@link RegionCoprocessorEnvironment} of the Region to which the coprocessor is associated
 * @return {@link Configuration}, can be null if it is not available
 */
@Nullable
protected Configuration getConfiguration(CoprocessorEnvironment env) {
  return env.getConfiguration();
}
 
Example 13
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 2 votes vote down vote up
/**
 * Fetch the {@link Configuration} that contains the properties required by the coprocessor. By default,
 * the HBase configuration is returned. This method will never return {@code null} in Tephra but the derived
 * classes might do so if {@link Configuration} is not available temporarily (for example, if it is being fetched
 * from a HBase Table.
 *
 * @param env {@link RegionCoprocessorEnvironment} of the Region to which the coprocessor is associated
 * @return {@link Configuration}, can be null if it is not available
 */
@Nullable
protected Configuration getConfiguration(CoprocessorEnvironment env) {
  return env.getConfiguration();
}
 
Example 14
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 2 votes vote down vote up
/**
 * Fetch the {@link Configuration} that contains the properties required by the coprocessor. By default,
 * the HBase configuration is returned. This method will never return {@code null} in Tephra but the derived
 * classes might do so if {@link Configuration} is not available temporarily (for example, if it is being fetched
 * from a HBase Table.
 *
 * @param env {@link RegionCoprocessorEnvironment} of the Region to which the coprocessor is associated
 * @return {@link Configuration}, can be null if it is not available
 */
@Nullable
protected Configuration getConfiguration(CoprocessorEnvironment env) {
  return env.getConfiguration();
}
 
Example 15
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 2 votes vote down vote up
/**
 * Fetch the {@link Configuration} that contains the properties required by the coprocessor. By default,
 * the HBase configuration is returned. This method will never return {@code null} in Tephra but the derived
 * classes might do so if {@link Configuration} is not available temporarily (for example, if it is being fetched
 * from a HBase Table.
 *
 * @param env {@link RegionCoprocessorEnvironment} of the Region to which the coprocessor is associated
 * @return {@link Configuration}, can be null if it is not available
 */
@Nullable
protected Configuration getConfiguration(CoprocessorEnvironment env) {
  return env.getConfiguration();
}
 
Example 16
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 2 votes vote down vote up
/**
 * Fetch the {@link Configuration} that contains the properties required by the coprocessor. By default,
 * the HBase configuration is returned. This method will never return {@code null} in Tephra but the derived
 * classes might do so if {@link Configuration} is not available temporarily (for example, if it is being fetched
 * from a HBase Table.
 *
 * @param env {@link RegionCoprocessorEnvironment} of the Region to which the coprocessor is associated
 * @return {@link Configuration}, can be null if it is not available
 */
@Nullable
protected Configuration getConfiguration(CoprocessorEnvironment env) {
  return env.getConfiguration();
}
 
Example 17
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 2 votes vote down vote up
/**
 * Fetch the {@link Configuration} that contains the properties required by the coprocessor. By
 * default, the HBase configuration is returned. This method will never return {@code null} in
 * Tephra but the derived classes might do so if {@link Configuration} is not available
 * temporarily (for example, if it is being fetched from a HBase Table.
 * @param env {@link RegionCoprocessorEnvironment} of the Region to which the coprocessor is
 *          associated
 * @return {@link Configuration}, can be null if it is not available
 */
@Nullable
protected Configuration getConfiguration(CoprocessorEnvironment env) {
  return env.getConfiguration();
}
 
Example 18
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 2 votes vote down vote up
/**
 * Fetch the {@link Configuration} that contains the properties required by the coprocessor. By default,
 * the HBase configuration is returned. This method will never return {@code null} in Tephra but the derived
 * classes might do so if {@link Configuration} is not available temporarily (for example, if it is being fetched
 * from a HBase Table.
 *
 * @param env {@link RegionCoprocessorEnvironment} of the Region to which the coprocessor is associated
 * @return {@link Configuration}, can be null if it is not available
 */
@Nullable
protected Configuration getConfiguration(CoprocessorEnvironment env) {
  return env.getConfiguration();
}
 
Example 19
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 2 votes vote down vote up
/**
 * Fetch the {@link Configuration} that contains the properties required by the coprocessor. By default,
 * the HBase configuration is returned. This method will never return {@code null} in Tephra but the derived
 * classes might do so if {@link Configuration} is not available temporarily (for example, if it is being fetched
 * from a HBase Table.
 *
 * @param env {@link RegionCoprocessorEnvironment} of the Region to which the coprocessor is associated
 * @return {@link Configuration}, can be null if it is not available
 */
@Nullable
protected Configuration getConfiguration(CoprocessorEnvironment env) {
  return env.getConfiguration();
}