/** * Remove all {@link Constraint Constraints} that have been added to the table * and turn off the constraint processing. * <p> * All {@link Configuration Configurations} and their associated * {@link Constraint} are removed. * * @param desc * {@link HTableDescriptor} to remove {@link Constraint Constraints} * from. */ public static void remove(HTableDescriptor desc) { // disable constraints disable(desc); // remove all the constraint settings List<Bytes> keys = new ArrayList<>(); // loop through all the key, values looking for constraints for (Map.Entry<Bytes, Bytes> e : desc .getValues().entrySet()) { String key = Bytes.toString((e.getKey().get())); String[] className = CONSTRAINT_HTD_ATTR_KEY_PATTERN.split(key); if (className.length == 2) { keys.add(e.getKey()); } } // now remove all the keys we found for (Bytes key : keys) { desc.remove(key); } }
private static Set<String> getCoprocessorJarPaths(Admin hbaseAdmin, List<String> tableNames) throws IOException { HashSet<String> result = new HashSet<String>(); for (String tableName : tableNames) { HTableDescriptor tableDescriptor = null; try { tableDescriptor = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName)); } catch (TableNotFoundException e) { logger.warn("Table not found " + tableName, e); continue; } Matcher keyMatcher; Matcher valueMatcher; for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e : tableDescriptor.getValues().entrySet()) { keyMatcher = HConstants.CP_HTD_ATTR_KEY_PATTERN.matcher(Bytes.toString(e.getKey().get())); if (!keyMatcher.matches()) { continue; } valueMatcher = HConstants.CP_HTD_ATTR_VALUE_PATTERN.matcher(Bytes.toString(e.getValue().get())); if (!valueMatcher.matches()) { continue; } String jarPath = valueMatcher.group(1).trim(); if (StringUtils.isNotEmpty(jarPath)) { result.add(jarPath); } } } return result; }
/** * Constructor * @param htd the table descriptor */ public TableSchemaModel(HTableDescriptor htd) { setName(htd.getTableName().getNameAsString()); for (Map.Entry<Bytes, Bytes> e: htd.getValues().entrySet()) { addAttribute(Bytes.toString(e.getKey().get()), Bytes.toString(e.getValue().get())); } for (HColumnDescriptor hcd: htd.getFamilies()) { ColumnSchemaModel columnModel = new ColumnSchemaModel(); columnModel.setName(hcd.getNameAsString()); for (Map.Entry<Bytes, Bytes> e: hcd.getValues().entrySet()) { columnModel.addAttribute(Bytes.toString(e.getKey().get()), Bytes.toString(e.getValue().get())); } addColumnFamily(columnModel); } }
assertEquals(originalTableDescriptor.getValues().size(), cloneHtd.getValues().size()); assertEquals(originalTableDescriptor.getConfiguration().size(), cloneHtd.getConfiguration().size()); assertEquals(TEST_CUSTOM_VALUE, cloneHtd.getValue(TEST_CUSTOM_VALUE)); assertEquals(TEST_CONF_CUSTOM_VALUE, cloneHtd.getConfigurationValue(TEST_CONF_CUSTOM_VALUE)); assertEquals(originalTableDescriptor.getValues(), cloneHtd.getValues()); assertEquals(originalTableDescriptor.getConfiguration(), cloneHtd.getConfiguration());
private static Set<String> getCoprocessorJarPaths(HBaseAdmin hbaseAdmin, List<String> tableNames) throws IOException { HashSet<String> result = new HashSet<String>(); for (String tableName : tableNames) { HTableDescriptor tableDescriptor = null; try { tableDescriptor = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName)); } catch (TableNotFoundException e) { logger.warn("Table not found " + tableName, e); continue; } Matcher keyMatcher; Matcher valueMatcher; for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e : tableDescriptor.getValues().entrySet()) { keyMatcher = HConstants.CP_HTD_ATTR_KEY_PATTERN.matcher(Bytes.toString(e.getKey().get())); if (!keyMatcher.matches()) { continue; } valueMatcher = HConstants.CP_HTD_ATTR_VALUE_PATTERN.matcher(Bytes.toString(e.getValue().get())); if (!valueMatcher.matches()) { continue; } String jarPath = valueMatcher.group(1).trim(); String clsName = valueMatcher.group(2).trim(); if (OBSERVER_CLS_NAME.equals(clsName)) { result.add(jarPath); } } } return result; }
/** * @return map of all table attributes formatted into string. */ public String toStringTableAttributes() { return getValues(true).toString(); }
/** * @return Name of this table and then a map of all of the column family * descriptors. * @see #getNameAsString() */ @Override public String toString() { StringBuilder s = new StringBuilder(); s.append('\'').append(Bytes.toString(name.getName())).append('\''); s.append(getValues(true)); for (HColumnDescriptor f : families.values()) { s.append(", ").append(f); } return s.toString(); }
/** * @return Name of this table and then a map of all of the column family * descriptors (with only the non-default column family attributes) */ public String toStringCustomizedValues() { StringBuilder s = new StringBuilder(); s.append('\'').append(Bytes.toString(name.getName())).append('\''); s.append(getValues(false)); for(HColumnDescriptor hcd : families.values()) { s.append(", ").append(hcd.toStringCustomizedValues()); } return s.toString(); }
/** * @return all non-coprocessor properties. */ public static Map<String, String> getNonCoprocessorProperties(HTableDescriptor tableDescriptor) { Map<String, String> properties = new HashMap<>(); for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> entry : tableDescriptor.getValues().entrySet()) { String key = Bytes.toString(entry.getKey().get()).trim(); String val = Bytes.toString(entry.getValue().get()).trim(); if (HConstants.CP_HTD_ATTR_KEY_PATTERN.matcher(key).matches()) { continue; } properties.put(key, val); } return properties; }
/** * @return all non-coprocessor properties. */ public static Map<String, String> getNonCoprocessorProperties(HTableDescriptor tableDescriptor) { Map<String, String> properties = new HashMap<>(); for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> entry : tableDescriptor.getValues().entrySet()) { String key = Bytes.toString(entry.getKey().get()).trim(); String val = Bytes.toString(entry.getValue().get()).trim(); if (HConstants.CP_HTD_ATTR_KEY_PATTERN.matcher(key).matches()) { continue; } properties.put(key, val); } return properties; }
UnmodifyableHTableDescriptor(final HTableDescriptor desc) { super(desc.getName(), getUnmodifyableFamilies(desc), desc.getValues()); }
UnmodifyableHTableDescriptor(final HTableDescriptor desc) { super(desc.getTableName(), getUnmodifyableFamilies(desc), desc.getValues()); }
private static Set<String> getCoprocessorJarPaths(HBaseAdmin hbaseAdmin, List<String> tableNames) throws IOException { HashSet<String> result = new HashSet<String>(); for (String tableName : tableNames) { HTableDescriptor tableDescriptor = null; try { tableDescriptor = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName)); } catch (TableNotFoundException e) { logger.warn("Table not found " + tableName, e); continue; } Matcher keyMatcher; Matcher valueMatcher; for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e : tableDescriptor.getValues().entrySet()) { keyMatcher = HConstants.CP_HTD_ATTR_KEY_PATTERN.matcher(Bytes.toString(e.getKey().get())); if (!keyMatcher.matches()) { continue; } valueMatcher = HConstants.CP_HTD_ATTR_VALUE_PATTERN.matcher(Bytes.toString(e.getValue().get())); if (!valueMatcher.matches()) { continue; } String jarPath = valueMatcher.group(1).trim(); String clsName = valueMatcher.group(2).trim(); if (OBSERVER_CLS_NAME.equals(clsName)) { result.add(jarPath); } } } return result; }
/** * Remove all {@link Constraint Constraints} that have been added to the table * and turn off the constraint processing. * <p> * All {@link Configuration Configurations} and their associated * {@link Constraint} are removed. * * @param desc * {@link HTableDescriptor} to remove {@link Constraint Constraints} * from. */ public static void remove(HTableDescriptor desc) { // disable constraints disable(desc); // remove all the constraint settings List<ImmutableBytesWritable> keys = new ArrayList<ImmutableBytesWritable>(); // loop through all the key, values looking for constraints for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e : desc .getValues().entrySet()) { String key = Bytes.toString((e.getKey().get())); String[] className = CONSTRAINT_HTD_ATTR_KEY_PATTERN.split(key); if (className.length == 2) { keys.add(e.getKey()); } } // now remove all the keys we found for (ImmutableBytesWritable key : keys) { desc.remove(key); } }
private static Set<String> getCoprocessorJarPaths(Admin hbaseAdmin, List<String> tableNames) throws IOException { HashSet<String> result = new HashSet<String>(); for (String tableName : tableNames) { HTableDescriptor tableDescriptor = null; try { tableDescriptor = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName)); } catch (TableNotFoundException e) { logger.warn("Table not found " + tableName, e); continue; } Matcher keyMatcher; Matcher valueMatcher; for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e : tableDescriptor.getValues().entrySet()) { keyMatcher = HConstants.CP_HTD_ATTR_KEY_PATTERN.matcher(Bytes.toString(e.getKey().get())); if (!keyMatcher.matches()) { continue; } valueMatcher = HConstants.CP_HTD_ATTR_VALUE_PATTERN.matcher(Bytes.toString(e.getValue().get())); if (!valueMatcher.matches()) { continue; } String jarPath = valueMatcher.group(1).trim(); if (StringUtils.isNotEmpty(jarPath)) { result.add(jarPath); } } } return result; }
/** * Remove all {@link Constraint Constraints} that have been added to the table * and turn off the constraint processing. * <p> * All {@link Configuration Configurations} and their associated * {@link Constraint} are removed. * * @param desc * {@link HTableDescriptor} to remove {@link Constraint Constraints} * from. */ public static void remove(HTableDescriptor desc) { // disable constraints disable(desc); // remove all the constraint settings List<ImmutableBytesWritable> keys = new ArrayList<ImmutableBytesWritable>(); // loop through all the key, values looking for constraints for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e : desc .getValues().entrySet()) { String key = Bytes.toString((e.getKey().get())); String[] className = CONSTRAINT_HTD_ATTR_KEY_PATTERN.split(key); if (className.length == 2) { keys.add(e.getKey()); } } // now remove all the keys we found for (ImmutableBytesWritable key : keys) { desc.remove(key.get()); } }
/** * Constructor * @param htd the table descriptor */ public TableSchemaModel(HTableDescriptor htd) { setName(htd.getTableName().getNameAsString()); for (Map.Entry<Bytes, Bytes> e: htd.getValues().entrySet()) { addAttribute(Bytes.toString(e.getKey().get()), Bytes.toString(e.getValue().get())); } for (HColumnDescriptor hcd: htd.getFamilies()) { ColumnSchemaModel columnModel = new ColumnSchemaModel(); columnModel.setName(hcd.getNameAsString()); for (Map.Entry<Bytes, Bytes> e: hcd.getValues().entrySet()) { columnModel.addAttribute(Bytes.toString(e.getKey().get()), Bytes.toString(e.getValue().get())); } addColumnFamily(columnModel); } }
/** * Constructor * @param htd the table descriptor */ public TableSchemaModel(HTableDescriptor htd) { setName(htd.getNameAsString()); for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e: htd.getValues().entrySet()) { addAttribute(Bytes.toString(e.getKey().get()), Bytes.toString(e.getValue().get())); } for (HColumnDescriptor hcd: htd.getFamilies()) { ColumnSchemaModel columnModel = new ColumnSchemaModel(); columnModel.setName(hcd.getNameAsString()); for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e: hcd.getValues().entrySet()) { columnModel.addAttribute(Bytes.toString(e.getKey().get()), Bytes.toString(e.getValue().get())); } addColumnFamily(columnModel); } }
/** * Constructor * @param htd the table descriptor */ public TableSchemaModel(HTableDescriptor htd) { setName(htd.getTableName().getNameAsString()); for (Map.Entry<Bytes, Bytes> e: htd.getValues().entrySet()) { addAttribute(Bytes.toString(e.getKey().get()), Bytes.toString(e.getValue().get())); } for (HColumnDescriptor hcd: htd.getFamilies()) { ColumnSchemaModel columnModel = new ColumnSchemaModel(); columnModel.setName(hcd.getNameAsString()); for (Map.Entry<Bytes, Bytes> e: hcd.getValues().entrySet()) { columnModel.addAttribute(Bytes.toString(e.getKey().get()), Bytes.toString(e.getValue().get())); } addColumnFamily(columnModel); } }
assertEquals(originalTableDescriptor.getValues().size(), cloneHtd.getValues().size()); assertEquals(originalTableDescriptor.getConfiguration().size(), cloneHtd.getConfiguration().size()); assertEquals(TEST_CUSTOM_VALUE, cloneHtd.getValue(TEST_CUSTOM_VALUE)); assertEquals(TEST_CONF_CUSTOM_VALUE, cloneHtd.getConfigurationValue(TEST_CONF_CUSTOM_VALUE)); assertEquals(originalTableDescriptor.getValues(), cloneHtd.getValues()); assertEquals(originalTableDescriptor.getConfiguration(), cloneHtd.getConfiguration());