Java 类org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse 实例源码

项目:ditb    文件:TestVisibilityLabelsWithDefaultVisLabelService.java   
@Test
public void testListLabelsWithRegEx() throws Throwable {
  PrivilegedExceptionAction<ListLabelsResponse> action =
      new PrivilegedExceptionAction<ListLabelsResponse>() {
    public ListLabelsResponse run() throws Exception {
      ListLabelsResponse response = null;
      try (Connection conn = ConnectionFactory.createConnection(conf)) {
        response = VisibilityClient.listLabels(conn, ".*secret");
      } catch (Throwable e) {
        fail("Should not have thrown exception");
      }
      // Only return the labels that end with 'secret'
      List<ByteString> labels = response.getLabelList();
      assertEquals(2, labels.size());
      assertTrue(labels.contains(ByteString.copyFrom(SECRET.getBytes())));
      assertTrue(labels.contains(ByteString.copyFrom(TOPSECRET.getBytes())));
      return null;
    }
  };
  SUPERUSER.runAs(action);
}
项目:pbase    文件:TestVisibilityLabelsWithDefaultVisLabelService.java   
@Test
public void testListLabelsWithRegEx() throws Throwable {
  PrivilegedExceptionAction<ListLabelsResponse> action =
      new PrivilegedExceptionAction<ListLabelsResponse>() {
    public ListLabelsResponse run() throws Exception {
      ListLabelsResponse response = null;
      try {
        response = VisibilityClient.listLabels(conf, ".*secret");
      } catch (Throwable e) {
        fail("Should not have thrown exception");
      }
      // Only return the labels that end with 'secret'
      List<ByteString> labels = response.getLabelList();
      assertEquals(2, labels.size());
      assertTrue(labels.contains(ByteString.copyFrom(SECRET.getBytes())));
      assertTrue(labels.contains(ByteString.copyFrom(TOPSECRET.getBytes())));
      return null;
    }
  };
  SUPERUSER.runAs(action);
}
项目:hbase    文件:TestVisibilityLabelsWithDefaultVisLabelService.java   
@Test
public void testListLabelsWithRegEx() throws Throwable {
  PrivilegedExceptionAction<ListLabelsResponse> action =
      new PrivilegedExceptionAction<ListLabelsResponse>() {
    @Override
    public ListLabelsResponse run() throws Exception {
      ListLabelsResponse response = null;
      try (Connection conn = ConnectionFactory.createConnection(conf)) {
        response = VisibilityClient.listLabels(conn, ".*secret");
      } catch (Throwable e) {
        fail("Should not have thrown exception");
      }
      // Only return the labels that end with 'secret'
      List<ByteString> labels = response.getLabelList();
      assertEquals(2, labels.size());
      assertTrue(labels.contains(ByteString.copyFrom(SECRET.getBytes())));
      assertTrue(labels.contains(ByteString.copyFrom(TOPSECRET.getBytes())));
      return null;
    }
  };
  SUPERUSER.runAs(action);
}
项目:ditb    文件:TestVisibilityLabelsWithDefaultVisLabelService.java   
@Test
public void testListLabels() throws Throwable {
  PrivilegedExceptionAction<ListLabelsResponse> action =
      new PrivilegedExceptionAction<ListLabelsResponse>() {
    public ListLabelsResponse run() throws Exception {
      ListLabelsResponse response = null;
      try (Connection conn = ConnectionFactory.createConnection(conf)) {
        response = VisibilityClient.listLabels(conn, null);
      } catch (Throwable e) {
        fail("Should not have thrown exception");
      }
      // The addLabels() in setup added:
      // { SECRET, TOPSECRET, CONFIDENTIAL, PUBLIC, PRIVATE, COPYRIGHT, ACCENT,
      //  UNICODE_VIS_TAG, UC1, UC2 };
      // The previous tests added 2 more labels: ABC, XYZ
      // The 'system' label is excluded.
      List<ByteString> labels = response.getLabelList();
      assertEquals(12, labels.size());
      assertTrue(labels.contains(ByteString.copyFrom(SECRET.getBytes())));
      assertTrue(labels.contains(ByteString.copyFrom(TOPSECRET.getBytes())));
      assertTrue(labels.contains(ByteString.copyFrom(CONFIDENTIAL.getBytes())));
      assertTrue(labels.contains(ByteString.copyFrom("ABC".getBytes())));
      assertTrue(labels.contains(ByteString.copyFrom("XYZ".getBytes())));
      assertFalse(labels.contains(ByteString.copyFrom(SYSTEM_LABEL.getBytes())));
      return null;
    }
  };
  SUPERUSER.runAs(action);
}
项目:pbase    文件:TestVisibilityLabelsWithDefaultVisLabelService.java   
@Test
public void testListLabels() throws Throwable {
  PrivilegedExceptionAction<ListLabelsResponse> action =
      new PrivilegedExceptionAction<ListLabelsResponse>() {
    public ListLabelsResponse run() throws Exception {
      ListLabelsResponse response = null;
      try {
        response = VisibilityClient.listLabels(conf, null);
      } catch (Throwable e) {
        fail("Should not have thrown exception");
      }
      // The addLabels() in setup added:
      // { SECRET, TOPSECRET, CONFIDENTIAL, PUBLIC, PRIVATE, COPYRIGHT, ACCENT,
      //  UNICODE_VIS_TAG, UC1, UC2 };
      // The previous tests added 2 more labels: ABC, XYZ
      // The 'system' label is excluded.
      List<ByteString> labels = response.getLabelList();
      assertEquals(12, labels.size());
      assertTrue(labels.contains(ByteString.copyFrom(SECRET.getBytes())));
      assertTrue(labels.contains(ByteString.copyFrom(TOPSECRET.getBytes())));
      assertTrue(labels.contains(ByteString.copyFrom(CONFIDENTIAL.getBytes())));
      assertTrue(labels.contains(ByteString.copyFrom("ABC".getBytes())));
      assertTrue(labels.contains(ByteString.copyFrom("XYZ".getBytes())));
      assertFalse(labels.contains(ByteString.copyFrom(SYSTEM_LABEL.getBytes())));
      return null;
    }
  };
  SUPERUSER.runAs(action);
}
项目:hbase    文件:TestVisibilityLabelsWithDefaultVisLabelService.java   
@Test
public void testListLabels() throws Throwable {
  PrivilegedExceptionAction<ListLabelsResponse> action =
      new PrivilegedExceptionAction<ListLabelsResponse>() {
    @Override
    public ListLabelsResponse run() throws Exception {
      ListLabelsResponse response = null;
      try (Connection conn = ConnectionFactory.createConnection(conf)) {
        response = VisibilityClient.listLabels(conn, null);
      } catch (Throwable e) {
        fail("Should not have thrown exception");
      }
      // The addLabels() in setup added:
      // { SECRET, TOPSECRET, CONFIDENTIAL, PUBLIC, PRIVATE, COPYRIGHT, ACCENT,
      //  UNICODE_VIS_TAG, UC1, UC2 };
      // The previous tests added 2 more labels: ABC, XYZ
      // The 'system' label is excluded.
      List<ByteString> labels = response.getLabelList();
      assertEquals(12, labels.size());
      assertTrue(labels.contains(ByteString.copyFrom(SECRET.getBytes())));
      assertTrue(labels.contains(ByteString.copyFrom(TOPSECRET.getBytes())));
      assertTrue(labels.contains(ByteString.copyFrom(CONFIDENTIAL.getBytes())));
      assertTrue(labels.contains(ByteString.copyFrom("ABC".getBytes())));
      assertTrue(labels.contains(ByteString.copyFrom("XYZ".getBytes())));
      assertFalse(labels.contains(ByteString.copyFrom(SYSTEM_LABEL.getBytes())));
      return null;
    }
  };
  SUPERUSER.runAs(action);
}
项目:hbase    文件:VisibilityClient.java   
/**
 * Retrieve the list of visibility labels defined in the system.
 * @param connection The Connection instance to use.
 * @param regex  The regular expression to filter which labels are returned.
 * @return labels The list of visibility labels defined in the system.
 * @throws Throwable
 */
public static ListLabelsResponse listLabels(Connection connection, final String regex)
    throws Throwable {
  try (Table table = connection.getTable(LABELS_TABLE_NAME)) {
    Batch.Call<VisibilityLabelsService, ListLabelsResponse> callable =
        new Batch.Call<VisibilityLabelsService, ListLabelsResponse>() {
      ServerRpcController controller = new ServerRpcController();
      CoprocessorRpcUtils.BlockingRpcCallback<ListLabelsResponse> rpcCallback =
          new CoprocessorRpcUtils.BlockingRpcCallback<>();

      @Override
      public ListLabelsResponse call(VisibilityLabelsService service) throws IOException {
        ListLabelsRequest.Builder listAuthLabelsReqBuilder = ListLabelsRequest.newBuilder();
        if (regex != null) {
          // Compile the regex here to catch any regex exception earlier.
          Pattern pattern = Pattern.compile(regex);
          listAuthLabelsReqBuilder.setRegex(pattern.toString());
        }
        service.listLabels(controller, listAuthLabelsReqBuilder.build(), rpcCallback);
        ListLabelsResponse response = rpcCallback.get();
        if (controller.failedOnException()) {
          throw controller.getFailedOn();
        }
        return response;
      }
    };
    Map<byte[], ListLabelsResponse> result =
        table.coprocessorService(VisibilityLabelsService.class, HConstants.EMPTY_BYTE_ARRAY,
            HConstants.EMPTY_BYTE_ARRAY, callable);
    return result.values().iterator().next(); // There will be exactly one region for labels
    // table and so one entry in result Map.
  }
}
项目:ditb    文件:VisibilityClient.java   
/**
 * Retrieve the list of visibility labels defined in the system.
 * @param connection The Connection instance to use.
 * @param regex  The regular expression to filter which labels are returned.
 * @return labels The list of visibility labels defined in the system.
 * @throws Throwable
 */
public static ListLabelsResponse listLabels(Connection connection, final String regex)
    throws Throwable {
  Table table = null;
  try {
    table = connection.getTable(LABELS_TABLE_NAME);
    Batch.Call<VisibilityLabelsService, ListLabelsResponse> callable =
        new Batch.Call<VisibilityLabelsService, ListLabelsResponse>() {
          ServerRpcController controller = new ServerRpcController();
          BlockingRpcCallback<ListLabelsResponse> rpcCallback =
              new BlockingRpcCallback<ListLabelsResponse>();

          public ListLabelsResponse call(VisibilityLabelsService service) throws IOException {
            ListLabelsRequest.Builder listAuthLabelsReqBuilder = ListLabelsRequest.newBuilder();
            if (regex != null) {
              // Compile the regex here to catch any regex exception earlier.
              Pattern pattern = Pattern.compile(regex);
              listAuthLabelsReqBuilder.setRegex(pattern.toString());
            }
            service.listLabels(controller, listAuthLabelsReqBuilder.build(), rpcCallback);
            ListLabelsResponse response = rpcCallback.get();
            if (controller.failedOnException()) {
              throw controller.getFailedOn();
            }
            return response;
          }
        };
    Map<byte[], ListLabelsResponse> result =
        table.coprocessorService(VisibilityLabelsService.class, HConstants.EMPTY_BYTE_ARRAY,
          HConstants.EMPTY_BYTE_ARRAY, callable);
    return result.values().iterator().next(); // There will be exactly one region for labels
    // table and so one entry in result Map.
  }
  finally {
    if (table != null) {
      table.close();
    }
    if (connection != null) {
      connection.close();
    }
  }
}
项目:pbase    文件:VisibilityClient.java   
/**
 * Retrieve the list of visibility labels defined in the system.
 * @param conf
 * @param regex  The regular expression to filter which labels are returned.
 * @return labels The list of visibility labels defined in the system.
 * @throws Throwable
 */
public static ListLabelsResponse listLabels(Configuration conf, final String regex)
    throws Throwable {
  Connection connection = null;
  Table table = null;
  try {
    connection = ConnectionFactory.createConnection(conf);
    table = connection.getTable(LABELS_TABLE_NAME);
    Batch.Call<VisibilityLabelsService, ListLabelsResponse> callable =
        new Batch.Call<VisibilityLabelsService, ListLabelsResponse>() {
      ServerRpcController controller = new ServerRpcController();
      BlockingRpcCallback<ListLabelsResponse> rpcCallback =
          new BlockingRpcCallback<ListLabelsResponse>();

      public ListLabelsResponse call(VisibilityLabelsService service) throws IOException {
        ListLabelsRequest.Builder listAuthLabelsReqBuilder = ListLabelsRequest.newBuilder();
        if (regex != null) {
          // Compile the regex here to catch any regex exception earlier.
          Pattern pattern = Pattern.compile(regex);
          listAuthLabelsReqBuilder.setRegex(pattern.toString());
        }
        service.listLabels(controller, listAuthLabelsReqBuilder.build(), rpcCallback);
        ListLabelsResponse response = rpcCallback.get();
        if (controller.failedOnException()) {
          throw controller.getFailedOn();
        }
        return response;
      }
    };
    Map<byte[], ListLabelsResponse> result =
        table.coprocessorService(VisibilityLabelsService.class, HConstants.EMPTY_BYTE_ARRAY,
          HConstants.EMPTY_BYTE_ARRAY, callable);
    return result.values().iterator().next(); // There will be exactly one region for labels
    // table and so one entry in result Map.
  }
  finally {
    if (table != null) {
      table.close();
    }
    if (connection != null) {
      connection.close();
    }
  }
}
项目:hbase    文件:TestMasterCoprocessorServices.java   
@Override
public void listLabels(RpcController controller, ListLabelsRequest request,
    RpcCallback<ListLabelsResponse> done) {
}
项目:ditb    文件:VisibilityClient.java   
/**
 * Retrieve the list of visibility labels defined in the system.
 * @param conf
 * @param regex  The regular expression to filter which labels are returned.
 * @return labels The list of visibility labels defined in the system.
 * @throws Throwable
 * @deprecated Use {@link #listLabels(Connection,String)} instead.
 */
@Deprecated
public static ListLabelsResponse listLabels(Configuration conf, final String regex)
    throws Throwable {
  try(Connection connection = ConnectionFactory.createConnection(conf)){
    return listLabels(connection, regex);
  }
}
项目:hbase    文件:VisibilityClient.java   
/**
 * Retrieve the list of visibility labels defined in the system.
 * @param conf
 * @param regex  The regular expression to filter which labels are returned.
 * @return labels The list of visibility labels defined in the system.
 * @throws Throwable
 * @deprecated Use {@link #listLabels(Connection,String)} instead.
 */
@Deprecated
public static ListLabelsResponse listLabels(Configuration conf, final String regex)
    throws Throwable {
  try(Connection connection = ConnectionFactory.createConnection(conf)){
    return listLabels(connection, regex);
  }
}