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

The following examples show how to use org.apache.hadoop.hbase.coprocessor.CoprocessorException. These examples are extracted from open source projects. 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 Project: hbase   Source File: MasterQuotasObserver.java    License: 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 Project: kylin-on-parquet-v2   Source File: CubeVisitService.java    License: 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 3
Source Project: BigData-In-Practice   Source File: TestRowCountEndPoint.java    License: 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 4
Source Project: Eagle   Source File: AggregateProtocolEndPoint.java    License: 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 5
Source Project: Eagle   Source File: AggregateResultCallbackImpl.java    License: 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 6
Source Project: eagle   Source File: AggregateProtocolEndPoint.java    License: 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 Project: eagle   Source File: AggregateResultCallbackImpl.java    License: 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 8
Source Project: phoenix   Source File: MetaDataEndpointImpl.java    License: 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 9
Source Project: phoenix   Source File: ServerCachingEndpointImpl.java    License: 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 Project: metron   Source File: EnrichmentCoprocessor.java    License: 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 11
Source Project: kylin   Source File: CubeVisitService.java    License: 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 12
Source Project: yuzhouwan   Source File: QueryEndpoint.java    License: 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 13
Source Project: hbase   Source File: TestServerCustomProtocol.java    License: 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 14
Source Project: hbase   Source File: AccessController.java    License: 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 15
Source Project: hbase   Source File: AccessController.java    License: 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 16
Source Project: hbase   Source File: MemStoreCompactorSegmentsIterator.java    License: 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 17
Source Project: hbase   Source File: BulkDeleteEndpoint.java    License: 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 18
Source Project: hbase   Source File: RefreshHFilesEndpoint.java    License: 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 Project: Kylin   Source File: IIEndpoint.java    License: 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 20
Source Project: phoenix   Source File: ChildLinkMetaDataEndpoint.java    License: 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 21
Source Project: phoenix   Source File: ServerCachingEndpointImpl.java    License: 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 Project: geowave   Source File: HBaseBulkDeleteEndpoint.java    License: 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 23
Source Project: geowave   Source File: AggregationEndpoint.java    License: 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 24
@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 25
Source Project: kylin-on-parquet-v2   Source File: CubeVisitServiceTest.java    License: 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 Project: kylin   Source File: CubeVisitServiceTest.java    License: 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 27
Source Project: hbase   Source File: AccessController.java    License: 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 28
Source Project: hbase   Source File: RowCountEndpoint.java    License: 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!");
  }
}