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

The following examples show how to use org.apache.hadoop.hbase.coprocessor.MasterCoprocessor. 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: TestMasterCoprocessorServices.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testAccessControlServices() {
  MasterCoprocessor defaultImpl = new AccessController();
  MasterCoprocessor customImpl = new MockAccessController();
  MasterCoprocessor unrelatedImpl = new JMXListener();
  assertTrue(masterServices.checkCoprocessorWithService(
      Collections.singletonList(defaultImpl), AccessControlService.Interface.class));
  assertTrue(masterServices.checkCoprocessorWithService(
      Collections.singletonList(customImpl), AccessControlService.Interface.class));
  assertFalse(masterServices.checkCoprocessorWithService(
      Collections.emptyList(), AccessControlService.Interface.class));
  assertFalse(masterServices.checkCoprocessorWithService(
      null, AccessControlService.Interface.class));
  assertFalse(masterServices.checkCoprocessorWithService(
      Collections.singletonList(unrelatedImpl), AccessControlService.Interface.class));
  assertTrue(masterServices.checkCoprocessorWithService(
      Arrays.asList(unrelatedImpl, customImpl), AccessControlService.Interface.class));
  assertTrue(masterServices.checkCoprocessorWithService(
      Arrays.asList(unrelatedImpl, defaultImpl), AccessControlService.Interface.class));
}
 
Example #2
Source File: TestMasterCoprocessorServices.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testVisibilityLabelServices() {
  MasterCoprocessor defaultImpl = new VisibilityController();
  MasterCoprocessor customImpl = new MockVisibilityController();
  MasterCoprocessor unrelatedImpl = new JMXListener();
  assertTrue(masterServices.checkCoprocessorWithService(
      Collections.singletonList(defaultImpl), VisibilityLabelsService.Interface.class));
  assertTrue(masterServices.checkCoprocessorWithService(
      Collections.singletonList(customImpl), VisibilityLabelsService.Interface.class));
  assertFalse(masterServices.checkCoprocessorWithService(
      Collections.emptyList(), VisibilityLabelsService.Interface.class));
  assertFalse(masterServices.checkCoprocessorWithService(
      null, VisibilityLabelsService.Interface.class));
  assertFalse(masterServices.checkCoprocessorWithService(
      Collections.singletonList(unrelatedImpl), VisibilityLabelsService.Interface.class));
  assertTrue(masterServices.checkCoprocessorWithService(
      Arrays.asList(unrelatedImpl, customImpl), VisibilityLabelsService.Interface.class));
  assertTrue(masterServices.checkCoprocessorWithService(
      Arrays.asList(unrelatedImpl, defaultImpl), VisibilityLabelsService.Interface.class));
}
 
Example #3
Source File: HBaseAtlasCoprocessor.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void init(){
    if(LOG.isDebugEnabled()) {
        LOG.debug("==> HBaseAtlasCoprocessor.init()");
    }

    try {
        atlasPluginClassLoader = AtlasPluginClassLoader.getInstance(ATLAS_PLUGIN_TYPE, this.getClass());

        @SuppressWarnings("unchecked")
        Class<?> cls = Class.forName(ATLAS_HBASE_HOOK_IMPL_CLASSNAME, true, atlasPluginClassLoader);

        activatePluginClassLoader();

        impl                     = cls.newInstance();
        implMasterObserver       = (MasterObserver)impl;
        implRegionObserver       = (RegionObserver)impl;
        implRegionServerObserver = (RegionServerObserver)impl;
        implMasterCoprocessor 	 = (MasterCoprocessor)impl;

    } catch (Exception e) {
        // check what need to be done
        LOG.error("Error Enabling RangerHbasePlugin", e);
    } finally {
        deactivatePluginClassLoader();
    }

    if(LOG.isDebugEnabled()) {
        LOG.debug("<== HBaseAtlasCoprocessor.init()");
    }
}
 
Example #4
Source File: MasterCoprocessorHost.java    From hbase with Apache License 2.0 5 votes vote down vote up
public MasterEnvironment(final MasterCoprocessor impl, final int priority, final int seq,
    final Configuration conf, final MasterServices services) {
  super(impl, priority, seq, conf);
  this.services = services;
  this.metricRegistry =
      MetricsCoprocessor.createRegistryForMasterCoprocessor(impl.getClass().getName());
}
 
Example #5
Source File: MasterCoprocessorHost.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public MasterEnvironment createEnvironment(final MasterCoprocessor instance, final int priority,
    final int seq, final Configuration conf) {
  // If coprocessor exposes any services, register them.
  for (Service service : instance.getServices()) {
    masterServices.registerService(service);
  }
  // If a CoreCoprocessor, return a 'richer' environment, one laden with MasterServices.
  return instance.getClass().isAnnotationPresent(CoreCoprocessor.class)?
      new MasterEnvironmentForCoreCoprocessors(instance, priority, seq, conf, masterServices):
      new MasterEnvironment(instance, priority, seq, conf, masterServices);
}
 
Example #6
Source File: MasterCoprocessorHost.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public MasterCoprocessor checkAndGetInstance(Class<?> implClass)
    throws InstantiationException, IllegalAccessException {
  try {
    if (MasterCoprocessor.class.isAssignableFrom(implClass)) {
      return implClass.asSubclass(MasterCoprocessor.class).getDeclaredConstructor().newInstance();
    } else {
      LOG.error("{} is not of type MasterCoprocessor. Check the configuration of {}",
          implClass.getName(), CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY);
      return null;
    }
  } catch (NoSuchMethodException | InvocationTargetException e) {
    throw (InstantiationException) new InstantiationException(implClass.getName()).initCause(e);
  }
}
 
Example #7
Source File: MasterRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Determines if there is a coprocessor implementation in the provided argument which extends
 * or implements the provided {@code service}.
 */
boolean checkCoprocessorWithService(
    List<MasterCoprocessor> coprocessorsToCheck, Class<?> service) {
  if (coprocessorsToCheck == null || coprocessorsToCheck.isEmpty()) {
    return false;
  }
  for (MasterCoprocessor cp : coprocessorsToCheck) {
    if (service.isAssignableFrom(cp.getClass())) {
      return true;
    }
  }
  return false;
}
 
Example #8
Source File: MasterCoprocessorHost.java    From hbase with Apache License 2.0 4 votes vote down vote up
public MasterEnvironmentForCoreCoprocessors(final MasterCoprocessor impl, final int priority,
    final int seq, final Configuration conf, final MasterServices services) {
  super(impl, priority, seq, conf, services);
  this.masterServices = services;
}
 
Example #9
Source File: MasterRpcServices.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Determines if there is a MasterCoprocessor deployed which implements
 * {@link AccessControlService.Interface}.
 */
boolean hasAccessControlServiceCoprocessor(MasterCoprocessorHost cpHost) {
  return checkCoprocessorWithService(cpHost.findCoprocessors(MasterCoprocessor.class),
    AccessControlService.Interface.class);
}
 
Example #10
Source File: MasterRpcServices.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Determines if there is a MasterCoprocessor deployed which implements
 * {@link VisibilityLabelsService.Interface}.
 */
boolean hasVisibilityLabelsServiceCoprocessor(MasterCoprocessorHost cpHost) {
  return checkCoprocessorWithService(cpHost.findCoprocessors(MasterCoprocessor.class),
    VisibilityLabelsService.Interface.class);
}