/** * 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); } }
@Override public ListLabelsResponse run() throws Exception { ListLabelsResponse response = null; try (Connection conn = ConnectionFactory.createConnection(conf)) { response = VisibilityClient.listLabels(conn, ".*secret"); } catch (Throwable e) { throw new IOException(e); } // Only return the labels that end with 'secret' List<ByteString> labels = response.getLabelList(); assertEquals(2, labels.size()); assertTrue(labels.contains(ByteString.copyFrom(Bytes.toBytes(SECRET)))); assertTrue(labels.contains(ByteString.copyFrom(Bytes.toBytes(TOPSECRET)))); return null; } };
@Override public ListLabelsResponse run() throws Exception { ListLabelsResponse response = null; try (Connection conn = ConnectionFactory.createConnection(conf)) { response = VisibilityClient.listLabels(conn, null); } catch (Throwable e) { throw new IOException(e); } // 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(Bytes.toBytes(SECRET)))); assertTrue(labels.contains(ByteString.copyFrom(Bytes.toBytes(TOPSECRET)))); assertTrue(labels.contains(ByteString.copyFrom(Bytes.toBytes(CONFIDENTIAL)))); assertTrue(labels.contains(ByteString.copyFrom(Bytes.toBytes("ABC")))); assertTrue(labels.contains(ByteString.copyFrom(Bytes.toBytes("XYZ")))); assertFalse(labels.contains(ByteString.copyFrom(Bytes.toBytes(SYSTEM_LABEL)))); return null; } };
/** * 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); } }
@Override public Void run() { VisibilityLabelsProtos.ListLabelsResponse response = null; try { response = VisibilityClient.listLabels(user.getConnection(), labelRegex); user.openConnection(); // See HBASE-18472 System.out.println("Labels:"); int count = 0; for (ByteString label : response.getLabelList()) { System.out.println(" " + label.toStringUtf8()); count++; } System.out.println("Found " + count + " labels."); } catch (Throwable throwable) { System.out.println("printLabels() failed with: " + throwable.getMessage().split("\n")[0]); } return null; } });
/** * 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); } }
/** * 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); } }
@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; } };
@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; } };