org.apache.hadoop.hbase.coprocessor.CoprocessorException Java Examples

The following examples show how to use org.apache.hadoop.hbase.coprocessor.CoprocessorException. 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: 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 #2
Source File: AccessController.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated since 2.2.0 and will be removed in 4.0.0. Use
 *   {@link Admin#grant(UserPermission, boolean)} instead.
 * @see Admin#grant(UserPermission, boolean)
 * @see <a href="https://issues.apache.org/jira/browse/HBASE-21739">HBASE-21739</a>
 */
@Deprecated
@Override
public void grant(RpcController controller,
    AccessControlProtos.GrantRequest request,
    RpcCallback<AccessControlProtos.GrantResponse> done) {
  final UserPermission perm = AccessControlUtil.toUserPermission(request.getUserPermission());
  AccessControlProtos.GrantResponse response = null;
  try {
    // verify it's only running at .acl.
    if (aclRegion) {
      if (!initialized) {
        throw new CoprocessorException("AccessController not yet initialized");
      }
      User caller = RpcServer.getRequestUser().orElse(null);
      if (LOG.isDebugEnabled()) {
        LOG.debug("Received request from {} to grant access permission {}",
          caller.getName(), perm.toString());
      }
      preGrantOrRevoke(caller, "grant", perm);

      // regionEnv is set at #start. Hopefully not null at this point.
      regionEnv.getConnection().getAdmin().grant(
        new UserPermission(perm.getUser(), perm.getPermission()),
        request.getMergeExistingPermissions());
      if (AUDITLOG.isTraceEnabled()) {
        // audit log should store permission changes in addition to auth results
        AUDITLOG.trace("Granted permission " + perm.toString());
      }
    } else {
      throw new CoprocessorException(AccessController.class, "This method "
          + "can only execute at " + PermissionStorage.ACL_TABLE_NAME + " table.");
    }
    response = AccessControlProtos.GrantResponse.getDefaultInstance();
  } catch (IOException ioe) {
    // pass exception back up
    CoprocessorRpcUtils.setControllerException(controller, ioe);
  }
  done.run(response);
}
 
Example #3
Source File: SpliceRSRpcServices.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
    if (env instanceof RegionServerCoprocessorEnvironment) {
        this.regionServerServices = (RegionServerServices) ((RegionServerCoprocessorEnvironment) env).getOnlineRegions();
        SpliceLogUtils.info(LOG,"Started SpliceRSRpcServices");
    } else {
        throw new CoprocessorException("Must be loaded on a RegionServer!");
    }
}
 
Example #4
Source File: AggregationEndpoint.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public void start(final CoprocessorEnvironment env) throws IOException {
  if (env instanceof RegionCoprocessorEnvironment) {
    this.env = (RegionCoprocessorEnvironment) env;
  } else {
    throw new CoprocessorException("Must be loaded on a table region!");
  }
}
 
Example #5
Source File: HBaseBulkDeleteEndpoint.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public void start(final CoprocessorEnvironment env) throws IOException {
  if (env instanceof RegionCoprocessorEnvironment) {
    this.env = (RegionCoprocessorEnvironment) env;
  } else {
    throw new CoprocessorException("Must be loaded on a table region!");
  }
}
 
Example #6
Source File: ServerCachingEndpointImpl.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
  if (env instanceof RegionCoprocessorEnvironment) {
    this.env = (RegionCoprocessorEnvironment) env;
  } else {
    throw new CoprocessorException("Must be loaded on a table region!");
  }
}
 
Example #7
Source File: ChildLinkMetaDataEndpoint.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
    if (env instanceof RegionCoprocessorEnvironment) {
        this.env = (RegionCoprocessorEnvironment) env;
    } else {
        throw new CoprocessorException("Must be loaded on a table region!");
    }
    this.phoenixAccessCoprocessorHost = new PhoenixMetaDataCoprocessorHost(this.env);
    this.accessCheckEnabled = env.getConfiguration().getBoolean(QueryServices.PHOENIX_ACLS_ENABLED,
        QueryServicesOptions.DEFAULT_PHOENIX_ACLS_ENABLED);
}
 
Example #8
Source File: IIEndpoint.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
    if (env instanceof RegionCoprocessorEnvironment) {
        this.env = (RegionCoprocessorEnvironment) env;
    } else {
        throw new CoprocessorException("Must be loaded on a table region!");
    }
}
 
Example #9
Source File: RefreshHFilesEndpoint.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
  if (env instanceof RegionCoprocessorEnvironment) {
    this.env = (RegionCoprocessorEnvironment) env;
  } else {
    throw new CoprocessorException("Must be loaded on a table region!");
  }
}
 
Example #10
Source File: BulkDeleteEndpoint.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
  if (env instanceof RegionCoprocessorEnvironment) {
    this.env = (RegionCoprocessorEnvironment) env;
  } else {
    throw new CoprocessorException("Must be loaded on a table region!");
  }
}
 
Example #11
Source File: MemStoreCompactorSegmentsIterator.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the scanner for compacting the pipeline.
 * @return the scanner
 */
private InternalScanner createScanner(HStore store, List<KeyValueScanner> scanners)
    throws IOException {
  InternalScanner scanner = null;
  boolean success = false;
  try {
    RegionCoprocessorHost cpHost = store.getCoprocessorHost();
    ScanInfo scanInfo;
    if (cpHost != null) {
      scanInfo = cpHost.preMemStoreCompactionCompactScannerOpen(store);
    } else {
      scanInfo = store.getScanInfo();
    }
    scanner = new StoreScanner(store, scanInfo, scanners, ScanType.COMPACT_RETAIN_DELETES,
        store.getSmallestReadPoint(), HConstants.OLDEST_TIMESTAMP);
    if (cpHost != null) {
      InternalScanner scannerFromCp = cpHost.preMemStoreCompactionCompact(store, scanner);
      if (scannerFromCp == null) {
        throw new CoprocessorException("Got a null InternalScanner when calling" +
            " preMemStoreCompactionCompact which is not acceptable");
      }
      success = true;
      return scannerFromCp;
    } else {
      success = true;
      return scanner;
    }
  } finally {
    if (!success) {
      Closeables.close(scanner, true);
      scanners.forEach(KeyValueScanner::close);
    }
  }
}
 
Example #12
Source File: AccessController.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated since 2.2.0 and will be removed in 4.0.0. Use {@link Admin#revoke(UserPermission)}
 *   instead.
 * @see Admin#revoke(UserPermission)
 * @see <a href="https://issues.apache.org/jira/browse/HBASE-21739">HBASE-21739</a>
 */
@Deprecated
@Override
public void revoke(RpcController controller, AccessControlProtos.RevokeRequest request,
    RpcCallback<AccessControlProtos.RevokeResponse> done) {
  final UserPermission perm = AccessControlUtil.toUserPermission(request.getUserPermission());
  AccessControlProtos.RevokeResponse response = null;
  try {
    // only allowed to be called on _acl_ region
    if (aclRegion) {
      if (!initialized) {
        throw new CoprocessorException("AccessController not yet initialized");
      }
      User caller = RpcServer.getRequestUser().orElse(null);
      if (LOG.isDebugEnabled()) {
        LOG.debug("Received request from {} to revoke access permission {}",
          caller.getShortName(), perm.toString());
      }
      preGrantOrRevoke(caller, "revoke", perm);
      // regionEnv is set at #start. Hopefully not null here.
      regionEnv.getConnection().getAdmin()
          .revoke(new UserPermission(perm.getUser(), perm.getPermission()));
      if (AUDITLOG.isTraceEnabled()) {
        // audit log should record all permission changes
        AUDITLOG.trace("Revoked permission " + perm.toString());
      }
    } else {
      throw new CoprocessorException(AccessController.class, "This method "
          + "can only execute at " + PermissionStorage.ACL_TABLE_NAME + " table.");
    }
    response = AccessControlProtos.RevokeResponse.getDefaultInstance();
  } catch (IOException ioe) {
    // pass exception back up
    CoprocessorRpcUtils.setControllerException(controller, ioe);
  }
  done.run(response);
}
 
Example #13
Source File: CubeVisitService.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
    if (env instanceof RegionCoprocessorEnvironment) {
        this.env = (RegionCoprocessorEnvironment) env;
    } else {
        throw new CoprocessorException("Must be loaded on a table region!");
    }
}
 
Example #14
Source File: TestServerCustomProtocol.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
  if (env instanceof RegionCoprocessorEnvironment) {
    return;
  }
  throw new CoprocessorException("Must be loaded on a table region!");
}
 
Example #15
Source File: QueryEndpoint.java    From yuzhouwan with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
    if (env instanceof RegionCoprocessorEnvironment) {
        this.env = (RegionCoprocessorEnvironment) env;
    } else {
        throw new CoprocessorException("Must be loaded on a table region!");
    }
}
 
Example #16
Source File: CubeVisitService.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
    if (env instanceof RegionCoprocessorEnvironment) {
        this.env = (RegionCoprocessorEnvironment) env;
    } else {
        throw new CoprocessorException("Must be loaded on a table region!");
    }
}
 
Example #17
Source File: EnrichmentCoprocessor.java    From metron with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment ce) throws IOException {
  LOG.info("Starting enrichment coprocessor");
  if (ce instanceof RegionCoprocessorEnvironment) {
    this.coprocessorEnv = (RegionCoprocessorEnvironment) ce;
  } else {
    throw new CoprocessorException("Enrichment coprocessor must be loaded on a table region.");
  }
  LOG.info("Checking if internal cache initialized");
  if (null == this.cache) {
    LOG.info("Cache null, initializing");
    LOG.info("Getting global config from Zookeeper");
    String zkUrl = getZookeeperUrl(this.coprocessorEnv.getConfiguration());
    if (null == globalConfigService) {
      globalConfigService = getGlobalConfigService(zkUrl);
    }
    globalConfig = globalConfigService.get();
    Configuration config = this.coprocessorEnv.getConfiguration();
    CacheWriter<String, String> cacheWriter = null;
    try {
      String hbaseTableProviderName = (String) globalConfig
          .get(EnrichmentConfigurations.TABLE_PROVIDER);
      String tableName = (String) globalConfig.get(EnrichmentConfigurations.TABLE_NAME);
      String columnFamily = (String) globalConfig.get(EnrichmentConfigurations.COLUMN_FAMILY);
      cacheWriter = new HBaseCacheWriter(config, TableProvider
          .create(hbaseTableProviderName, HTableProvider::new), tableName, columnFamily,
          COLUMN_QUALIFIER);
    } catch (ClassNotFoundException | InstantiationException | InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
      throw new IOException("Unable to instantiate cache writer", e);
    }
    this.cache = Caffeine.newBuilder().writer(cacheWriter).build();
    LOG.info("Finished initializing cache");
  }
  LOG.info("Finished starting enrichment coprocessor");
}
 
Example #18
Source File: ServerCachingEndpointImpl.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
  if (env instanceof RegionCoprocessorEnvironment) {
    this.env = (RegionCoprocessorEnvironment) env;
  } else {
    throw new CoprocessorException("Must be loaded on a table region!");
  }
}
 
Example #19
Source File: MetaDataEndpointImpl.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * Stores a reference to the coprocessor environment provided by the
 * {@link org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost} from the region where this
 * coprocessor is loaded. Since this is a coprocessor endpoint, it always expects to be loaded
 * on a table region, so always expects this to be an instance of
 * {@link RegionCoprocessorEnvironment}.
 * @param env the environment provided by the coprocessor host
 * @throws IOException if the provided environment is not an instance of
 *             {@code RegionCoprocessorEnvironment}
 */
@Override
public void start(CoprocessorEnvironment env) throws IOException {
    if (env instanceof RegionCoprocessorEnvironment) {
        this.env = (RegionCoprocessorEnvironment) env;
    } else {
        throw new CoprocessorException("Must be loaded on a table region!");
    }
    logger.info("Starting Tracing-Metrics Systems");
    // Start the phoenix trace collection
    Tracing.addTraceMetricsSource();
    Metrics.ensureConfigured();
}
 
Example #20
Source File: AggregateResultCallbackImpl.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Override
public void update(byte[] region, byte[] row, AggregateProtos.AggregateResult result) {
    try {
        if (result == null) {
            throw new IllegalStateException(new CoprocessorException("result is null"));
        }
        this.update(region, row, ProtoBufConverter.fromPBResult(result));
    } catch (IOException e) {
        LOG.error("Failed to convert PB-Based message", e);
    }
}
 
Example #21
Source File: AggregateProtocolEndPoint.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
    if (env instanceof RegionCoprocessorEnvironment) {
        this.env = (RegionCoprocessorEnvironment) env;
    } else {
        throw new CoprocessorException("Must be loaded on a table region!");
    }
}
 
Example #22
Source File: AggregateResultCallbackImpl.java    From Eagle with Apache License 2.0 5 votes vote down vote up
@Override
public void update(byte[] region, byte[] row, AggregateProtos.AggregateResult result) {
    try {
        if(result == null) throw new IllegalStateException(new CoprocessorException("result is null"));
        this.update(region,row, ProtoBufConverter.fromPBResult(result));
    } catch (IOException e) {
        LOG.error("Failed to convert PB-Based message",e);
    }
}
 
Example #23
Source File: AggregateProtocolEndPoint.java    From Eagle with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
    if (env instanceof RegionCoprocessorEnvironment) {
        this.env = (RegionCoprocessorEnvironment)env;
    } else {
        throw new CoprocessorException("Must be loaded on a table region!");
    }
}
 
Example #24
Source File: TestRowCountEndPoint.java    From BigData-In-Practice with Apache License 2.0 5 votes vote down vote up
@Override
public void start(CoprocessorEnvironment env) throws IOException {
    // 需要检查当前环境是否在region上
    if (env instanceof RegionCoprocessorEnvironment) {
        this.envi = (RegionCoprocessorEnvironment) env;

    } else {
        throw new CoprocessorException("Must be loaded on a table region!");
    }

}
 
Example #25
Source File: CubeVisitServiceTest.java    From kylin with Apache License 2.0 4 votes vote down vote up
@Test(expected = CoprocessorException.class)
public void testStart() throws IOException {
    CoprocessorEnvironment env = PowerMockito.mock(RegionServerCoprocessorEnvironment.class);
    CubeVisitService service = new CubeVisitService();
    service.start(env);
}
 
Example #26
Source File: AccessController.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * @deprecated since 2.2.0 and will be removed in 4.0.0. Use
 *   {@link Admin#getUserPermissions(GetUserPermissionsRequest)} instead.
 * @see Admin#getUserPermissions(GetUserPermissionsRequest)
 * @see <a href="https://issues.apache.org/jira/browse/HBASE-21911">HBASE-21911</a>
 */
@Deprecated
@Override
public void getUserPermissions(RpcController controller,
    AccessControlProtos.GetUserPermissionsRequest request,
    RpcCallback<AccessControlProtos.GetUserPermissionsResponse> done) {
  AccessControlProtos.GetUserPermissionsResponse response = null;
  try {
    // only allowed to be called on _acl_ region
    if (aclRegion) {
      if (!initialized) {
        throw new CoprocessorException("AccessController not yet initialized");
      }
      User caller = RpcServer.getRequestUser().orElse(null);
      final String userName = request.hasUserName() ? request.getUserName().toStringUtf8() : null;
      final String namespace =
          request.hasNamespaceName() ? request.getNamespaceName().toStringUtf8() : null;
      final TableName table =
          request.hasTableName() ? ProtobufUtil.toTableName(request.getTableName()) : null;
      final byte[] cf =
          request.hasColumnFamily() ? request.getColumnFamily().toByteArray() : null;
      final byte[] cq =
          request.hasColumnQualifier() ? request.getColumnQualifier().toByteArray() : null;
      preGetUserPermissions(caller, userName, namespace, table, cf, cq);
      GetUserPermissionsRequest getUserPermissionsRequest = null;
      if (request.getType() == AccessControlProtos.Permission.Type.Table) {
        getUserPermissionsRequest = GetUserPermissionsRequest.newBuilder(table).withFamily(cf)
            .withQualifier(cq).withUserName(userName).build();
      } else if (request.getType() == AccessControlProtos.Permission.Type.Namespace) {
        getUserPermissionsRequest =
            GetUserPermissionsRequest.newBuilder(namespace).withUserName(userName).build();
      } else {
        getUserPermissionsRequest =
            GetUserPermissionsRequest.newBuilder().withUserName(userName).build();
      }
      List<UserPermission> perms =
          regionEnv.getConnection().getAdmin().getUserPermissions(getUserPermissionsRequest);
      response = AccessControlUtil.buildGetUserPermissionsResponse(perms);
    } else {
      throw new CoprocessorException(AccessController.class, "This method "
          + "can only execute at " + PermissionStorage.ACL_TABLE_NAME + " table.");
    }
  } catch (IOException ioe) {
    // pass exception back up
    CoprocessorRpcUtils.setControllerException(controller, ioe);
  }
  done.run(response);
}
 
Example #27
Source File: CubeVisitServiceTest.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Test(expected = CoprocessorException.class)
public void testStart() throws IOException {
    CoprocessorEnvironment env = PowerMockito.mock(RegionServerCoprocessorEnvironment.class);
    CubeVisitService service = new CubeVisitService();
    service.start(env);
}
 
Example #28
Source File: RowCountEndpoint.java    From hbase with Apache License 2.0 3 votes vote down vote up
/**
 * Stores a reference to the coprocessor environment provided by the
 * {@link org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost} from the region where this
 * coprocessor is loaded.  Since this is a coprocessor endpoint, it always expects to be loaded
 * on a table region, so always expects this to be an instance of
 * {@link RegionCoprocessorEnvironment}.
 * @param env the environment provided by the coprocessor host
 * @throws IOException if the provided environment is not an instance of
 * {@code RegionCoprocessorEnvironment}
 */
@Override
public void start(CoprocessorEnvironment env) throws IOException {
  if (env instanceof RegionCoprocessorEnvironment) {
    this.env = (RegionCoprocessorEnvironment)env;
  } else {
    throw new CoprocessorException("Must be loaded on a table region!");
  }
}