下面列出了org.apache.hadoop.hbase.CoprocessorEnvironment#getConfiguration ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
}
@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.");
}
}
/**
* 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);
}
@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);
}
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);
}
@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());
}
@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);
}
@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());
}
}
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);
}
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);
}
@Override
public void start(CoprocessorEnvironment env) throws IOException {
this.conf = env.getConfiguration();
visibilityLabelService = VisibilityLabelServiceManager.getInstance()
.getVisibilityLabelService(this.conf);
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}