@Override public void start( @SuppressWarnings("rawtypes") CoprocessorEnvironment env) throws IOException { RegionCoprocessorEnvironment renv = (RegionCoprocessorEnvironment) env; FAMILY_TO_ADD = Bytes.toBytes(renv.getConfiguration().get(FAMILY_TO_ADD_KEY)); QUALIFIER_TO_ADD = Bytes.toBytes(renv.getConfiguration().get(QUALIFIER_TO_ADD_KEY)); }
@Override public List<UserPermission> run() throws Exception { if (cf != null || userName != null) { // retrieve permission based on the requested parameters return AccessControlLists.getUserTablePermissions(regionEnv.getConfiguration(), table, cf, cq, userName, true); } else { return AccessControlLists.getUserTablePermissions(regionEnv.getConfiguration(), table, null, null, null, false); } } });
@Override public List<UserPermission> run() throws Exception { if (userName != null) { // retrieve permission based on the requested parameters return AccessControlLists.getUserNamespacePermissions(regionEnv.getConfiguration(), namespace, userName, true); } else { return AccessControlLists.getUserNamespacePermissions(regionEnv.getConfiguration(), namespace, null, false); } } });
@Override public List<UserPermission> run() throws Exception { if (userName != null) { // retrieve permission based on the requested parameters return AccessControlLists.getUserPermissions(regionEnv.getConfiguration(), null, null, null, userName, true); } else { return AccessControlLists.getUserPermissions(regionEnv.getConfiguration(), null, null, null, null, false); } } });
@Override public void start( @SuppressWarnings("rawtypes") CoprocessorEnvironment env) throws IOException { RegionCoprocessorEnvironment renv = (RegionCoprocessorEnvironment) env; sourceValue = Bytes.toBytes(renv.getConfiguration().get(ORIGINAL_VALUE_KEY)); replacedValue = Bytes.toBytes(renv.getConfiguration().get(REPLACED_VALUE_KEY)); comparator = new Bytes.ByteArrayComparator(); cellBuilder = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY); }
@Override public void start(CoprocessorEnvironment env) throws IOException { RegionCoprocessorEnvironment renv = (RegionCoprocessorEnvironment) env; try { this.cache = ((ZKDataHolder) renv.getSharedData().computeIfAbsent(ZKKEY, k -> { String ensemble = renv.getConfiguration().get(ZK_ENSEMBLE_KEY); int sessionTimeout = renv.getConfiguration().getInt(ZK_SESSION_TIMEOUT_KEY, ZK_SESSION_TIMEOUT_DEFAULT); return new ZKDataHolder(ensemble, sessionTimeout); })).acquire(); } catch (Exception e) { throw new IOException(e); } }
@Override public void start(CoprocessorEnvironment environment) throws IOException { if (environment instanceof RegionCoprocessorEnvironment) { env = (RegionCoprocessorEnvironment) environment; userProvider = UserProvider.instantiate(env.getConfiguration()); } else { throw new CoprocessorException("Must be loaded on a table region!"); } }
@Override public void postOpen(ObserverContext<RegionCoprocessorEnvironment> c) { RegionCoprocessorEnvironment env = c.getEnvironment(); Configuration conf = env.getConfiguration(); sleepTime.set(conf.getLong(SLEEP_TIME_CONF_KEY, DEFAULT_SLEEP_TIME)); }
@Override public void postOpen(ObserverContext<RegionCoprocessorEnvironment> c) { RegionCoprocessorEnvironment env = c.getEnvironment(); Configuration conf = env.getConfiguration(); sleepTime.set(conf.getLong(SLEEP_TIME_CONF_KEY, DEFAULT_SLEEP_TIME)); }
private void initialize(RegionCoprocessorEnvironment e) throws IOException { final Region region = e.getRegion(); Configuration conf = e.getConfiguration(); Map<byte[], ListMultimap<String, UserPermission>> tables = AccessControlLists.loadAll(region); // For each table, write out the table's permissions to the respective // znode for that table. for (Map.Entry<byte[], ListMultimap<String, UserPermission>> t: tables.entrySet()) { byte[] entry = t.getKey(); ListMultimap<String, UserPermission> perms = t.getValue(); byte[] serialized = AccessControlLists.writePermissionsAsBytes(perms, conf); getAuthManager().getZKPermissionWatcher().writeToZookeeper(entry, serialized); } initialized = true; }
@Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="NP_NULL_ON_SOME_PATH", justification="NPE should never happen; if it does it is a bigger issue") public void preCommitStoreFile(final ObserverContext<RegionCoprocessorEnvironment> ctx, final byte[] family, final List<Pair<Path, Path>> pairs) throws IOException { RegionCoprocessorEnvironment env = ctx.getEnvironment(); Configuration c = env.getConfiguration(); if (pairs == null || pairs.isEmpty() || !c.getBoolean(HConstants.REPLICATION_BULKLOAD_ENABLE_KEY, HConstants.REPLICATION_BULKLOAD_ENABLE_DEFAULT)) { LOG.debug("Skipping recording bulk load entries in preCommitStoreFile for bulkloaded " + "data replication."); return; } // This is completely cheating AND getting a HRegionServer from a RegionServerEnvironment is // just going to break. This is all private. Not allowed. Regions shouldn't assume they are // hosted in a RegionServer. TODO: fix. RegionServerServices rss = ((HasRegionServerServices)env).getRegionServerServices(); Replication rep = (Replication)((HRegionServer)rss).getReplicationSourceService(); rep.addHFileRefsToQueue(env.getRegionInfo().getTable(), family, pairs); } }
@Override public void preCommitStoreFile(final ObserverContext<RegionCoprocessorEnvironment> ctx, final byte[] family, final List<Pair<Path, Path>> pairs) throws IOException { Configuration cfg = ctx.getEnvironment().getConfiguration(); if (pairs == null || pairs.isEmpty() || !BackupManager.isBackupEnabled(cfg)) { LOG.debug("skipping recording bulk load in preCommitStoreFile since backup is disabled"); return; } try (Connection connection = ConnectionFactory.createConnection(cfg); BackupSystemTable tbl = new BackupSystemTable(connection)) { List<TableName> fullyBackedUpTables = tbl.getTablesForBackupType(BackupType.FULL); RegionInfo info = ctx.getEnvironment().getRegionInfo(); TableName tableName = info.getTable(); if (!fullyBackedUpTables.contains(tableName)) { if (LOG.isTraceEnabled()) { LOG.trace(tableName + " has not gone thru full backup"); } return; } tbl.writeFilesForBulkLoadPreCommit(tableName, info.getEncodedNameAsBytes(), family, pairs); return; } } }
@Override public void export(RpcController controller, ExportProtos.ExportRequest request, RpcCallback<ExportProtos.ExportResponse> done) { Region region = env.getRegion(); Configuration conf = HBaseConfiguration.create(env.getConfiguration()); conf.setStrings("io.serializations", conf.get("io.serializations"), ResultSerialization.class.getName()); try { Scan scan = validateKey(region.getRegionInfo(), request); Token userToken = null; if (userProvider.isHadoopSecurityEnabled() && !request.hasFsToken()) { LOG.warn("Hadoop security is enable, but no found of user token"); } else if (userProvider.isHadoopSecurityEnabled()) { userToken = new Token(request.getFsToken().getIdentifier().toByteArray(), request.getFsToken().getPassword().toByteArray(), new Text(request.getFsToken().getKind()), new Text(request.getFsToken().getService())); } ExportProtos.ExportResponse response = processData(region, conf, userProvider, scan, userToken, getWriterOptions(conf, region.getRegionInfo(), request)); done.run(response); } catch (IOException e) { CoprocessorRpcUtils.setControllerException(controller, e); LOG.error(e.toString(), e); } }
Configuration conf = regionEnv.getConfiguration(); byte [] currentEntry = null;
@Override public void postBulkLoadHFile(ObserverContext<RegionCoprocessorEnvironment> ctx, List<Pair<byte[], String>> stagingFamilyPaths, Map<byte[], List<Path>> finalPaths) throws IOException { Configuration cfg = ctx.getEnvironment().getConfiguration(); if (finalPaths == null) { // there is no need to record state return; } if (!BackupManager.isBackupEnabled(cfg)) { LOG.debug("skipping recording bulk load in postBulkLoadHFile since backup is disabled"); return; } try (Connection connection = ConnectionFactory.createConnection(cfg); BackupSystemTable tbl = new BackupSystemTable(connection)) { List<TableName> fullyBackedUpTables = tbl.getTablesForBackupType(BackupType.FULL); RegionInfo info = ctx.getEnvironment().getRegionInfo(); TableName tableName = info.getTable(); if (!fullyBackedUpTables.contains(tableName)) { if (LOG.isTraceEnabled()) { LOG.trace(tableName + " has not gone thru full backup"); } return; } tbl.writePathsPostBulkLoad(tableName, info.getEncodedNameAsBytes(), finalPaths); } catch (IOException ioe) { LOG.error("Failed to get tables which have been fully backed up", ioe); } } @Override
private void initialize() throws IOException { // ZK configuration must _not_ have hbase.security.authentication or it will require SASL auth Configuration zkConf = new Configuration(conf); zkConf.set(User.HBASE_SECURITY_CONF_KEY, "simple"); this.zookeeper = new ZKWatcher(zkConf, TokenServer.class.getSimpleName(), this, true); this.rpcServer.start(); // Mock up region coprocessor environment RegionCoprocessorEnvironment mockRegionCpEnv = mock(RegionCoprocessorEnvironment.class, Mockito.withSettings().extraInterfaces(HasRegionServerServices.class)); when(mockRegionCpEnv.getConfiguration()).thenReturn(conf); when(mockRegionCpEnv.getClassLoader()).then( (var1) -> Thread.currentThread().getContextClassLoader()); RegionServerServices mockRss = mock(RegionServerServices.class); when(mockRss.getRpcServer()).thenReturn(rpcServer); when(((HasRegionServerServices) mockRegionCpEnv).getRegionServerServices()) .thenReturn(mockRss); super.start(mockRegionCpEnv); started = true; }
/****************************** Region related hooks ******************************/ @Override public void postOpen(ObserverContext<RegionCoprocessorEnvironment> e) { // Read the entire labels table and populate the zk if (e.getEnvironment().getRegion().getRegionInfo().getTable().equals(LABELS_TABLE_NAME)) { this.labelsRegion = true; synchronized (this) { this.accessControllerAvailable = CoprocessorHost.getLoadedCoprocessors() .contains(AccessController.class.getName()); } initVisibilityLabelService(e.getEnvironment()); } else { checkAuths = e.getEnvironment().getConfiguration() .getBoolean(VisibilityConstants.CHECK_AUTHS_FOR_MUTATION, false); initVisibilityLabelService(e.getEnvironment()); } }
public DropChildViewsTask(RegionCoprocessorEnvironment env, long timeMaxInterval) { this.env = env; this.accessCheckEnabled = env.getConfiguration().getBoolean(QueryServices.PHOENIX_ACLS_ENABLED, QueryServicesOptions.DEFAULT_PHOENIX_ACLS_ENABLED); this.timeMaxInterval = timeMaxInterval; }
/** * Determines if statistics are enabled (which is the default). This is done on the * RegionCoprocessorEnvironment for now to allow setting this on a per-table basis, although * it could be moved to the general table metadata in the future if there is a realistic * use case for that. */ private static boolean statisticsEnabled(RegionCoprocessorEnvironment env) { return (env.getConfiguration().getBoolean(STATS_COLLECTION_ENABLED, DEFAULT_STATS_COLLECTION_ENABLED)) && StatisticsUtil.isStatsEnabled(env.getRegionInfo().getTable()); }
@Test public void getDefaultFailurePolicy() throws Exception { Configuration conf = new Configuration(false); RegionCoprocessorEnvironment env = Mockito.mock(RegionCoprocessorEnvironment.class); Region region = Mockito.mock(Region.class); Mockito.when(env.getRegion()).thenReturn(region); Mockito.when(env.getConfiguration()).thenReturn(conf); Mockito.when(region.getTableDescriptor()).thenReturn( TableDescriptorBuilder.newBuilder(TableName.valueOf("dummy")).build()); assertNotNull(IndexWriter.getFailurePolicy(env)); }