下面列出了怎么用org.apache.hadoop.hbase.coprocessor.MasterObserver的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void preAlterTable(ObserverContext<PhoenixMetaDataControllerEnvironment> ctx, String tenantId,
String tableName, TableName physicalTableName, TableName parentPhysicalTableName, PTableType tableType) throws IOException {
if (!accessCheckEnabled) { return; }
for (MasterObserver observer : getAccessControllers()) {
if (tableType != PTableType.VIEW) {
observer.preModifyTable(getMasterObsevrverContext(), physicalTableName,
TableDescriptorBuilder.newBuilder(physicalTableName).build());
}
}
if (tableType == PTableType.VIEW) {
if(execPermissionsCheckEnabled) {
requireAccess("Alter "+tableType, parentPhysicalTableName, Action.READ, Action.EXEC);
} else {
requireAccess("Alter "+tableType, parentPhysicalTableName, Action.READ);
}
}
}
public void preStopMaster() throws IOException {
// While stopping master all coprocessors method should be executed first then the coprocessor
// environment should be cleaned up.
if (coprocEnvironments.isEmpty()) {
return;
}
execShutdown(new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.preStopMaster(this);
}
@Override
public void postEnvCall() {
// invoke coprocessor stop method
shutdown(this.getEnvironment());
}
});
}
private List<MasterObserver> getAccessControllers() throws IOException {
ArrayList<MasterObserver> oldAccessControllers = accessControllers.get();
if (oldAccessControllers == null) {
oldAccessControllers = new ArrayList<>();
RegionCoprocessorHost cpHost = this.env.getCoprocessorHost();
for (RegionCoprocessor cp : cpHost.findCoprocessors(RegionCoprocessor.class)) {
if (cp instanceof AccessControlService.Interface && cp instanceof MasterObserver) {
oldAccessControllers.add((MasterObserver)cp);
if(cp.getClass().getName().equals(org.apache.hadoop.hbase.security.access.AccessController.class.getName())) {
hbaseAccessControllerEnabled = true;
}
}
}
accessControllers.set(oldAccessControllers);
}
return accessControllers.get();
}
@Override
public void preIndexUpdate(ObserverContext<PhoenixMetaDataControllerEnvironment> ctx, String tenantId,
String indexName, TableName physicalTableName, TableName parentPhysicalTableName, PIndexState newState)
throws IOException {
if (!accessCheckEnabled) { return; }
for (MasterObserver observer : getAccessControllers()) {
observer.preModifyTable(getMasterObsevrverContext(), physicalTableName,
TableDescriptorBuilder.newBuilder(physicalTableName).build());
}
// Check for read access in case of rebuild
if (newState == PIndexState.BUILDING) {
if(execPermissionsCheckEnabled) {
requireAccess("Rebuild:", parentPhysicalTableName, Action.READ, Action.EXEC);
} else {
requireAccess("Rebuild:", parentPhysicalTableName, Action.READ);
}
}
}
public void preGetClusterMetrics() throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.preGetClusterMetrics(this);
}
});
}
public void postSwitchRpcThrottle(final boolean oldValue, final boolean newValue)
throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postSwitchRpcThrottle(this, oldValue, newValue);
}
});
}
public void preGrant(UserPermission userPermission, boolean mergeExistingPermissions)
throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.preGrant(this, userPermission, mergeExistingPermissions);
}
});
}
public void preGetTableNames(final List<TableDescriptor> descriptors,
final String regex) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.preGetTableNames(this, descriptors, regex);
}
});
}
public void preTransitReplicationPeerSyncReplicationState(String peerId,
SyncReplicationState state) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.preTransitReplicationPeerSyncReplicationState(this, peerId, state);
}
});
}
public void postGetConfiguredNamespacesAndTablesInRSGroup(final String groupName)
throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
protected void call(MasterObserver observer) throws IOException {
observer.postGetConfiguredNamespacesAndTablesInRSGroup(this, groupName);
}
});
}
public void postCreateNamespace(final NamespaceDescriptor ns) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postCreateNamespace(this, ns);
}
});
}
public void preDeleteNamespace(final String namespaceName) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.preDeleteNamespace(this, namespaceName);
}
});
}
public void postDeleteNamespace(final String namespaceName) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postDeleteNamespace(this, namespaceName);
}
});
}
public void postMoveTables(final Set<TableName> tables, final String targetGroup)
throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postMoveTables(this, tables, targetGroup);
}
});
}
public void postRequestLock(String namespace, TableName tableName, RegionInfo[] regionInfos,
LockType type, String description) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postRequestLock(this, namespace, tableName, regionInfos, description);
}
});
}
public void postGetNamespaceDescriptor(final NamespaceDescriptor ns)
throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postGetNamespaceDescriptor(this, ns);
}
});
}
public void preListNamespaces(final List<String> namespaces) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver oserver) throws IOException {
oserver.preListNamespaces(this, namespaces);
}
});
}
public void preUpdateRSGroupConfig(final String groupName,
final Map<String, String> configuration) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
protected void call(MasterObserver observer) throws IOException {
observer.preUpdateRSGroupConfig(this, groupName, configuration);
}
});
}
public void postUpdateRSGroupConfig(final String groupName,
final Map<String, String> configuration) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
protected void call(MasterObserver observer) throws IOException {
observer.postUpdateRSGroupConfig(this, groupName, configuration);
}
});
}
public void preSwitchExceedThrottleQuota(boolean enable) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.preSwitchExceedThrottleQuota(this, enable);
}
});
}
public void postCloneSnapshot(final SnapshotDescription snapshot,
final TableDescriptor hTableDescriptor) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postCloneSnapshot(this, snapshot, hTableDescriptor);
}
});
}
public void postRevoke(UserPermission userPermission) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postRevoke(this, userPermission);
}
});
}
public void postCompletedCreateTableAction(
final TableDescriptor htd, final RegionInfo[] regions, final User user) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postCompletedCreateTableAction(this, htd, regions);
}
});
}
public void postLockHeartbeat(LockProcedure proc, boolean keepAlive) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postLockHeartbeat(this);
}
});
}
@Override
public void preCreateSchema(ObserverContext<PhoenixMetaDataControllerEnvironment> ctx, String schemaName)
throws IOException {
if (!accessCheckEnabled) { return; }
for (MasterObserver observer : getAccessControllers()) {
observer.preCreateNamespace(getMasterObsevrverContext(),
NamespaceDescriptor.create(schemaName).build());
}
}
public void postRemoveReplicationPeer(final String peerId) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postRemoveReplicationPeer(this, peerId);
}
});
}
public void postSetUserQuota(
final String user, final TableName table, final GlobalQuotaSettings quotas)
throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postSetUserQuota(this, user, table, quotas);
}
});
}
public void postTruncateTable(final TableName tableName) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postTruncateTable(this, tableName);
}
});
}
public void preListReplicationPeers(final String regex) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.preListReplicationPeers(this, regex);
}
});
}
public void postCompletedTruncateTableAction(final TableName tableName, final User user)
throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postCompletedTruncateTableAction(this, tableName);
}
});
}