Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
/**
 * Executes HBase DDL operations.
 */
public interface HBaseDDLExecutor {

  /**
   * Create the specified namespace if it does not exist.
   *
   * @param name the namespace to create
   * @throws IOException if a remote or network exception occurs
   */
  void createNamespaceIfNotExists(String name) throws IOException;

  /**
   * Delete the specified namespace if it exists.
   *
   * @param name the namespace to delete
   * @throws IOException if a remote or network exception occurs
   * @throws IllegalStateException if there are tables in the namespace
   */
  void deleteNamespaceIfExists(String name) throws IOException;

  /**
   * Create the specified table if it does not exist.
   *
   * @param descriptor the descriptor for the table to create
   * @param splitKeys the initial split keys for the table
   * @throws IOException if a remote or network exception occurs
   * @throws NotFoundException if the namespace for the specified table does not exist
   */
  void createTableIfNotExists(TableDescriptor descriptor, @Nullable byte[][] splitKeys) throws IOException;

  /**
   * Enable the specified table.
   *
   * @param namespace the namespace of the table to enable
   * @param name the name of the table to enable
   * @throws IOException if a remote or network exception occurs
   * @throws NotFoundException if the specified table does not exist
   */
  void enableTable(String namespace, String name) throws IOException;

  /**
   * Disable the specified table.
   *
   * @param namespace the namespace of the table to disable
   * @param name the name of the table to disable
   * @throws IOException if a remote or network exception occurs
   * @throws NotFoundException if the specified table does not exist
   */
  void disableTable(String namespace, String name) throws IOException;

  /**
   * Modify the specified table. The table must be disabled.
   *
   * @param namespace the namespace of the table to modify
   * @param name the name of the table to modify
   * @param descriptor the descriptor for the table
   * @throws IOException if a remote or network exception occurs
   * @throws NotFoundException if the specified table does not exist
   * @throws IllegalStateException if the specified table is not disabled
   */
  void modifyTable(String namespace, String name, TableDescriptor descriptor) throws IOException;
 
  /**
   * Truncate the specified table. The table must be disabled.
   *   
   * @param namespace the namespace of the table to truncate
   * @param name the name of the table to truncate
   * @throws IOException if a remote or network exception occurs
   * @throws NotFoundException if the specified table does not exist
   * @throws IllegalStateException if the specified table is not disabled
   */
  void truncateTable(String namespace, String name) throws IOException;

  /**
   * Delete the table if it exists. The table must be disabled.
   *
   * @param namespace the namespace of the table to delete
   * @param name the table to delete
   * @throws IOException if a remote or network exception occurs
   * @throws NotFoundException if the namespace for the specified table does not exist
   * @throws IllegalStateException if the specified table is not disabled
   */
  void deleteTableIfExists(String namespace, String name) throws IOException;
}
 
/**
 * Describes an HBase Table.
 */
public class TableDescriptor {
  private final String namespace;
  private final String name;
  private final Map<String, ColumnFamilyDescriptor> families;
  private final Collection<CoprocessorDescriptor> coprocessors;
  private final Map<String, String> properties;
}
 
/**
 * Describes an HBase table CoProcessor.
 */
public class CoprocessorDescriptor {
  private final String classname;
  private final String path;
  private final int priority;
  private final Map<String, String> properties;
}

/**
 * Describes an HBase table column family.
 */
public class ColumnFamilyDescriptor {
  private final int maxVersions;
  private final CompressionType compressionType;
  private final BloomType bloomType;
  private final Map<String, String> properties;
}

/**
 * Types of column family compression.
 */
public enum CompressionType {
  LZO, SNAPPY, GZIP, NONE
}
 
/**
 * Types of column family bloom filters.
 */
public enum BloomType {
  ROW, ROWCOL, NONE
}

The default implementation will simply use the existing HBaseTableUtil. There can be another implementation that makes REST calls for each method, leaving actual HBase operations and auth up to an external service. For example, an analagous RESTful API could be:

...

MethodPathRequest BodyDescription
PUT/namespaces/<namespace> create namespace if it doesn't exist. No-op if it already exists.
PUT/namespaces/<namespace>/tables/<table>HTableDescriptor contentsTableDescriptor, split keyscreate table if it doesn't exist. No-op if it already exists.
PUT/namespaces/<namespace>/tables/<table>/propertiesHTableDescriptor contentsTableDescriptormodify an existing table.
POST/namespaces/<namespace>/tables/<table>/enable enable an existing table.
POST/namespaces/<namespace>/tables/<table>/disable disable an existing table.
POST/namespaces/<namespace>/tables/<table>/truncate truncate an existing table.
DELETE/namespaces/<namespace> delete a namespace.
DELETE/namespaces/<namespace>/tables/<table> delete a table.

...