@Override public void deleteTable(HBaseDDLExecutor ddlExecutor, TableId tableId) throws IOException { Preconditions.checkArgument(ddlExecutor != null, "HBaseDDLExecutor should not be null"); Preconditions.checkArgument(tableId != null, "Table Id should not be null."); TableName tableName = HTableNameConverter.toTableName(tablePrefix, tableId); ddlExecutor.deleteTableIfExists(tableName.getNamespaceAsString(), tableName.getQualifierAsString()); }
@Override public void modifyTable(HBaseDDLExecutor ddlExecutor, HTableDescriptor tableDescriptor) throws IOException { Preconditions.checkArgument(ddlExecutor != null, "HBaseDDLExecutor should not be null"); Preconditions.checkArgument(tableDescriptor != null, "Table descriptor should not be null."); TableName tableName = tableDescriptor.getTableName(); TableDescriptor tbd = HBase10TableDescriptorUtil.getTableDescriptor(tableDescriptor); ddlExecutor.modifyTable(tableName.getNamespaceAsString(), tableName.getQualifierAsString(), tbd); }
private void createQueueTable(TableDescriptorBuilder tdBuilder, byte[][] splitKeys) throws IOException { int prefixBytes = (type == QueueConstants.QueueType.SHARDED_QUEUE) ? ShardedHBaseQueueStrategy.PREFIX_BYTES : SaltedHBaseQueueStrategy.SALT_BYTES; String prefix = Integer.toString(prefixBytes); tdBuilder.addProperty(HBaseQueueAdmin.PROPERTY_PREFIX_BYTES, prefix); LOG.info("Create queue table with prefix bytes {}", prefix); try (HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get()) { ddlExecutor.createTableIfNotExists(tdBuilder.build(), splitKeys); } } }
boolean created = executor.createNamespaceIfNotExists(hbaseNamespace); if (namespaceMeta.getConfig().getGroupName() != null) { try { executor.grantPermissions(hbaseNamespace, null, ImmutableMap.of("@" + namespaceMeta.getConfig().getGroupName(), "C")); } catch (IOException | RuntimeException e) { executor.deleteNamespaceIfExists(hbaseNamespace); } catch (Throwable t) { e.addSuppressed(t);
boolean enableTable = false; try { ddlExecutor.disableTableIfEnabled(tableName.getNamespaceAsString(), tableName.getQualifierAsString()); enableTable = true; } catch (TableNotEnabledException e) { if (enableTable) { LOG.debug("Enabling table '{}'...", tableId); ddlExecutor.enableTableIfDisabled(tableName.getNamespaceAsString(), tableName.getQualifierAsString());
private void disableTable(HBaseDDLExecutor ddlExecutor, TableId tableId) throws IOException { try { TableName tableName = HTableNameConverter.toTableName(cConf.get(Constants.Dataset.TABLE_PREFIX), tableId); ddlExecutor.disableTableIfEnabled(tableName.getNamespaceAsString(), tableName.getQualifierAsString()); LOG.debug("TMS Table {} has been disabled.", tableId); } catch (TableNotFoundException ex) { LOG.debug("TMS Table {} was not found. Skipping disable.", tableId, ex); } catch (TableNotEnabledException ex) { LOG.debug("TMS Table {} was already in disabled state.", tableId, ex); } }
private void enableTable(HBaseDDLExecutor ddlExecutor, TableId tableId) throws IOException { try { TableName tableName = HTableNameConverter.toTableName(cConf.get(Constants.Dataset.TABLE_PREFIX), tableId); ddlExecutor.enableTableIfDisabled(tableName.getNamespaceAsString(), tableName.getQualifierAsString()); LOG.debug("TMS Table {} has been enabled.", tableName); } catch (TableNotFoundException ex) { LOG.debug("TMS Table {} was not found. Skipping enable.", tableId, ex); } catch (TableNotDisabledException ex) { LOG.debug("TMS Table {} was already in enabled state.", tableId, ex); } }
/** * Grants permissions on a table. * @param ddlExecutor the {@link HBaseDDLExecutor} to use to communicate with HBase * @param tableId {@link TableId} for the specified table * @param permissions A map from user or group name to the permissions for that user or group, given as a string * containing only characters 'a'(Admin), 'c'(Create), 'r'(Read), 'w'(Write), and 'x'(Execute). * Group names must be prefixed with the character '@'. * @throws IOException */ public void grantPermissions(HBaseDDLExecutor ddlExecutor, TableId tableId, Map<String, String> permissions) throws IOException { TableName tableName = HTableNameConverter.toTableName(getTablePrefix(cConf), tableId); ddlExecutor.grantPermissions(tableName.getNamespaceAsString(), tableName.getQualifierAsString(), permissions); }
/** * Creates HBase namespace for the cdap system namespace. */ private void createSystemHBaseNamespace() { HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get(); try (HBaseDDLExecutor ddlExecutor = new HBaseDDLExecutorFactory(cConf, hConf).get()) { ddlExecutor.createNamespaceIfNotExists(tableUtil.getHBaseNamespace(NamespaceId.SYSTEM)); } catch (IOException e) { throw Throwables.propagate(e); } }
@SuppressWarnings("ConstantConditions") @Override public void delete(NamespaceId namespaceId) throws IOException, ExploreException, SQLException { // delete namespace directory from filesystem super.delete(namespaceId); if (NamespaceId.DEFAULT.equals(namespaceId)) { return; } // delete HBase namespace NamespaceConfig namespaceConfig; try { namespaceConfig = namespaceQueryAdmin.get(namespaceId).getConfig(); } catch (Exception ex) { throw new IOException("Could not fetch custom HBase mapping.", ex); } if (!Strings.isNullOrEmpty(namespaceConfig.getHbaseNamespace())) { // custom namespace mapping is set for HBase, hence don't do anything during delete since the lifecycle of the // namespace will be managed by the user LOG.debug("Custom HBase mapping {} was found while deleting {}. Hence skipping deletion of HBase namespace", namespaceConfig.getHbaseNamespace(), namespaceId); return; } // delete HBase namespace String namespace = tableUtil.getHBaseNamespace(namespaceId); try (HBaseDDLExecutor executor = hBaseDDLExecutorFactory.get()) { executor.deleteNamespaceIfExists(namespace); } } }
boolean created = executor.createNamespaceIfNotExists(hbaseNamespace); if (namespaceMeta.getConfig().getGroupName() != null) { try { executor.grantPermissions(hbaseNamespace, null, ImmutableMap.of("@" + namespaceMeta.getConfig().getGroupName(), "C")); } catch (IOException | RuntimeException e) { executor.deleteNamespaceIfExists(hbaseNamespace); } catch (Throwable t) { e.addSuppressed(t);
boolean enableTable = false; try { ddlExecutor.disableTableIfEnabled(tableName.getNamespaceAsString(), tableName.getQualifierAsString()); enableTable = true; } catch (TableNotEnabledException e) { if (enableTable) { LOG.debug("Enabling table '{}'...", tableId); ddlExecutor.enableTableIfDisabled(tableName.getNamespaceAsString(), tableName.getQualifierAsString());
private void disableTable(HBaseDDLExecutor ddlExecutor, TableId tableId) throws IOException { try { TableName tableName = HTableNameConverter.toTableName(cConf.get(Constants.Dataset.TABLE_PREFIX), tableId); ddlExecutor.disableTableIfEnabled(tableName.getNamespaceAsString(), tableName.getQualifierAsString()); LOG.debug("TMS Table {} has been disabled.", tableId); } catch (TableNotFoundException ex) { LOG.debug("TMS Table {} was not found. Skipping disable.", tableId, ex); } catch (TableNotEnabledException ex) { LOG.debug("TMS Table {} was already in disabled state.", tableId, ex); } }
private void enableTable(HBaseDDLExecutor ddlExecutor, TableId tableId) throws IOException { try { TableName tableName = HTableNameConverter.toTableName(cConf.get(Constants.Dataset.TABLE_PREFIX), tableId); ddlExecutor.enableTableIfDisabled(tableName.getNamespaceAsString(), tableName.getQualifierAsString()); LOG.debug("TMS Table {} has been enabled.", tableName); } catch (TableNotFoundException ex) { LOG.debug("TMS Table {} was not found. Skipping enable.", tableId, ex); } catch (TableNotDisabledException ex) { LOG.debug("TMS Table {} was already in enabled state.", tableId, ex); } }
/** * Grants permissions on a table. * @param ddlExecutor the {@link HBaseDDLExecutor} to use to communicate with HBase * @param tableId {@link TableId} for the specified table * @param permissions A map from user or group name to the permissions for that user or group, given as a string * containing only characters 'a'(Admin), 'c'(Create), 'r'(Read), 'w'(Write), and 'x'(Execute). * Group names must be prefixed with the character '@'. * @throws IOException */ public void grantPermissions(HBaseDDLExecutor ddlExecutor, TableId tableId, Map<String, String> permissions) throws IOException { TableName tableName = HTableNameConverter.toTableName(getTablePrefix(cConf), tableId); ddlExecutor.grantPermissions(tableName.getNamespaceAsString(), tableName.getQualifierAsString(), permissions); }
private void createNamespace(String namespace) throws IOException { String hbaseNamespace = getTableUtil().getHBaseNamespace(new NamespaceId(namespace)); ddlExecutor.createNamespaceIfNotExists(hbaseNamespace); }
@SuppressWarnings("ConstantConditions") @Override public void delete(NamespaceId namespaceId) throws IOException, ExploreException, SQLException { // delete namespace directory from filesystem super.delete(namespaceId); if (NamespaceId.DEFAULT.equals(namespaceId)) { return; } // delete HBase namespace NamespaceConfig namespaceConfig; try { namespaceConfig = namespaceQueryAdmin.get(namespaceId).getConfig(); } catch (Exception ex) { throw new IOException("Could not fetch custom HBase mapping.", ex); } if (!Strings.isNullOrEmpty(namespaceConfig.getHbaseNamespace())) { // custom namespace mapping is set for HBase, hence don't do anything during delete since the lifecycle of the // namespace will be managed by the user LOG.debug("Custom HBase mapping {} was found while deleting {}. Hence skipping deletion of HBase namespace", namespaceConfig.getHbaseNamespace(), namespaceId); return; } // delete HBase namespace String namespace = tableUtil.getHBaseNamespace(namespaceId); try (HBaseDDLExecutor executor = hBaseDDLExecutorFactory.get()) { executor.deleteNamespaceIfExists(namespace); } } }
@Override public void modifyTable(HBaseDDLExecutor ddlExecutor, HTableDescriptor tableDescriptor) throws IOException { Preconditions.checkArgument(ddlExecutor != null, "HBaseDDLExecutor should not be null"); Preconditions.checkArgument(tableDescriptor != null, "Table decsriptor should not be null."); TableName tableName = tableDescriptor.getTableName(); TableDescriptor tbd = HBase96TableDescriptorUtil.getTableDescriptor(tableDescriptor); ddlExecutor.modifyTable(tableName.getNamespaceAsString(), tableName.getQualifierAsString(), tbd); }
@Override public void deleteTable(HBaseDDLExecutor ddlExecutor, TableId tableId) throws IOException { Preconditions.checkArgument(ddlExecutor != null, "HBaseDDLExecutor should not be null"); Preconditions.checkArgument(tableId != null, "Table Id should not be null."); TableName tableName = HTableNameConverter.toTableName(tablePrefix, tableId); ddlExecutor.deleteTableIfExists(tableName.getNamespaceAsString(), tableName.getQualifierAsString()); }
@Override public void create() throws IOException { ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(Bytes.toString(DATA_COLUMN_FAMILY), hConf); TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(tableId, cConf) .addColumnFamily(cfdBuilder.build()); try (HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get()) { ddlExecutor.createTableIfNotExists(tdBuilder.build(), null); } }