Java Code Examples for org.apache.hadoop.hive.metastore.HiveMetaStoreClient#createDatabase()

The following examples show how to use org.apache.hadoop.hive.metastore.HiveMetaStoreClient#createDatabase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WaggleDanceIntegrationTest.java    From waggle-dance with Apache License 2.0 6 votes vote down vote up
@Test
public void createDatabaseUsingManualAndWhitelistingUpdatesConfig() throws Exception {
  runner = WaggleDanceRunner
      .builder(configLocation)
      .primary("primary", localServer.getThriftConnectionUri(),
          AccessControlType.READ_AND_WRITE_AND_CREATE_ON_DATABASE_WHITELIST)
      .build();

  runWaggleDance(runner);

  HiveMetaStoreClient proxy = getWaggleDanceClient();
  proxy.createDatabase(new Database("newDB", "", new File(localWarehouseUri, "newDB").toURI().toString(), null));
  Database newDB = proxy.getDatabase("newDB");
  assertNotNull(newDB);

  // Should be allowed due to newly loaded write privileges
  proxy.alterDatabase("newDB", new Database(newDB));

  Federations federations = stopServerAndGetConfiguration();
  PrimaryMetaStore metaStore = federations.getPrimaryMetaStore();
  assertThat(metaStore.getWritableDatabaseWhiteList().size(), is(1));
  assertThat(metaStore.getWritableDatabaseWhiteList().get(0), is("newdb"));
  // Mapped databases should still map everything
  assertThat(metaStore.getMappedDatabases(), is(nullValue()));
}
 
Example 2
Source File: WaggleDanceIntegrationTest.java    From waggle-dance with Apache License 2.0 6 votes vote down vote up
@Test
public void createDatabaseDatabaseUsingPrefixAndWhitelistingUpdates() throws Exception {
  runner = WaggleDanceRunner
      .builder(configLocation)
      .databaseResolution(DatabaseResolution.PREFIXED)
      .primary("primary", localServer.getThriftConnectionUri(),
          AccessControlType.READ_AND_WRITE_AND_CREATE_ON_DATABASE_WHITELIST)
      .build();

  runWaggleDance(runner);

  HiveMetaStoreClient proxy = getWaggleDanceClient();
  proxy.createDatabase(new Database("newDB", "", new File(localWarehouseUri, "newDB").toURI().toString(), null));
  Database newDB = proxy.getDatabase("newDB");
  assertNotNull(newDB);

  // Should be allowed due to newly loaded write privileges
  proxy.alterDatabase("newDB", new Database(newDB));

  Federations federations = stopServerAndGetConfiguration();
  PrimaryMetaStore metaStore = federations.getPrimaryMetaStore();
  assertThat(metaStore.getWritableDatabaseWhiteList().size(), is(1));
  assertThat(metaStore.getWritableDatabaseWhiteList().get(0), is("newdb"));
  // Mapped databases should still map everything
  assertThat(metaStore.getMappedDatabases(), is(nullValue()));
}
 
Example 3
Source File: BeejuCore.java    From beeju with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new database with the specified name.
 *
 * @param databaseName Database name.
 * @throws TException If an error occurs creating the database.
 */
public void createDatabase(String databaseName) throws TException {
  File tempFile = tempDir.toFile();
  HiveMetaStoreClient client = new HiveMetaStoreClient(new HiveConf(conf));
  String databaseFolder = new File(tempFile, databaseName).toURI().toString();
  try {
    client.createDatabase(new Database(databaseName, null, databaseFolder, null));
  } finally {
    client.close();
  }
}
 
Example 4
Source File: WaggleDanceIntegrationTest.java    From waggle-dance with Apache License 2.0 5 votes vote down vote up
@Test
public void readWriteCreateAllowed() throws Exception {
  String writableDatabase = "writable_db";

  localServer.createDatabase(writableDatabase);

  runner = WaggleDanceRunner
      .builder(configLocation)
      .primary("primary", localServer.getThriftConnectionUri(), AccessControlType.READ_AND_WRITE_AND_CREATE)
      .build();

  runWaggleDance(runner);

  HiveMetaStoreClient proxy = getWaggleDanceClient();
  // create rights
  proxy.createDatabase(new Database("newDB", "", new File(localWarehouseUri, "newDB").toURI().toString(), null));
  Database newDB = proxy.getDatabase("newDB");
  assertNotNull(newDB);

  // read rights
  Table localTable = localServer.client().getTable(LOCAL_DATABASE, LOCAL_TABLE);
  Table waggledLocalTable = proxy.getTable(LOCAL_DATABASE, LOCAL_TABLE);
  assertThat(waggledLocalTable, is(localTable));

  // write rights
  proxy.dropTable(LOCAL_DATABASE, LOCAL_TABLE);
  try {
    proxy.getTable(LOCAL_DATABASE, LOCAL_TABLE);
    fail("Should get NoSuchObjectException");
  } catch (NoSuchObjectException e) {
    // Local table should be allowed to drop, so it now no longer exists and we get an appropriate exception
  }
}
 
Example 5
Source File: WaggleDanceIntegrationTest.java    From waggle-dance with Apache License 2.0 5 votes vote down vote up
@Test
public void readWriteCreateAllowedPrefixed() throws Exception {
  String writableDatabase = "writable_db";

  localServer.createDatabase(writableDatabase);

  runner = WaggleDanceRunner
      .builder(configLocation)
      .databaseResolution(DatabaseResolution.PREFIXED)
      .primary("primary", localServer.getThriftConnectionUri(), AccessControlType.READ_AND_WRITE_AND_CREATE)
      .build();

  runWaggleDance(runner);

  HiveMetaStoreClient proxy = getWaggleDanceClient();
  // create rights
  proxy.createDatabase(new Database("newDB", "", new File(localWarehouseUri, "newDB").toURI().toString(), null));
  Database newDB = proxy.getDatabase("newDB");
  assertNotNull(newDB);

  // read rights
  Table localTable = localServer.client().getTable(LOCAL_DATABASE, LOCAL_TABLE);
  Table waggledLocalTable = proxy.getTable(LOCAL_DATABASE, LOCAL_TABLE);
  assertThat(waggledLocalTable, is(localTable));

  // write rights
  proxy.dropTable(LOCAL_DATABASE, LOCAL_TABLE);
  try {
    proxy.getTable(LOCAL_DATABASE, LOCAL_TABLE);
    fail("Should get NoSuchObjectException");
  } catch (NoSuchObjectException e) {
    // Local table should be allowed to drop, so it now no longer exists and we get an appropriate exception
  }
}
 
Example 6
Source File: WaggleDanceIntegrationTest.java    From waggle-dance with Apache License 2.0 5 votes vote down vote up
@Test
public void doesNotOverwriteConfigOnShutdownManualMode() throws Exception {
  // Note a similar test for PREFIX is not required
  runner = WaggleDanceRunner
      .builder(configLocation)
      .databaseResolution(DatabaseResolution.MANUAL)
      .overwriteConfigOnShutdown(false)
      .primary("primary", localServer.getThriftConnectionUri(),
          AccessControlType.READ_AND_WRITE_AND_CREATE_ON_DATABASE_WHITELIST)
      .federate(SECONDARY_METASTORE_NAME, remoteServer.getThriftConnectionUri(), REMOTE_DATABASE)
      .build();

  runWaggleDance(runner);

  HiveMetaStoreClient proxy = getWaggleDanceClient();
  proxy.createDatabase(new Database("newDB", "", new File(localWarehouseUri, "newDB").toURI().toString(), null));
  Database newDB = proxy.getDatabase("newDB");
  assertNotNull(newDB);

  Federations federations = stopServerAndGetConfiguration();

  PrimaryMetaStore primaryMetastore = federations.getPrimaryMetaStore();
  List<String> writableDatabases = primaryMetastore.getWritableDatabaseWhiteList();
  assertThat(writableDatabases.size(), is(0));

  // Double check federated metastores
  List<FederatedMetaStore> federatedMetastores = federations.getFederatedMetaStores();
  assertThat(federatedMetastores.size(), is(1));

  List<String> mappedDatabases = federatedMetastores.get(0).getMappedDatabases();
  assertThat(mappedDatabases.size(), is(1));
  assertThat(mappedDatabases.get(0), is(REMOTE_DATABASE));
}
 
Example 7
Source File: WaggleDanceIntegrationTest.java    From waggle-dance with Apache License 2.0 5 votes vote down vote up
@Test
public void primaryMappedDatabasesManual() throws Exception {
  localServer.createDatabase("random_primary");
  remoteServer.createDatabase("random_federated");

  runner = WaggleDanceRunner
      .builder(configLocation)
      .databaseResolution(DatabaseResolution.MANUAL)
      .primary("primary", localServer.getThriftConnectionUri(),
          AccessControlType.READ_AND_WRITE_AND_CREATE_ON_DATABASE_WHITELIST)
      .withPrimaryMappedDatabases(new String[] { LOCAL_DATABASE })
      .federate(SECONDARY_METASTORE_NAME, remoteServer.getThriftConnectionUri(), REMOTE_DATABASE)
      .build();

  runWaggleDance(runner);
  HiveMetaStoreClient proxy = getWaggleDanceClient();

  List<String> allDatabases = proxy.getAllDatabases();
  assertThat(allDatabases.size(), is(2));
  assertThat(allDatabases.get(0), is(LOCAL_DATABASE));
  assertThat(allDatabases.get(1), is(REMOTE_DATABASE));

  // Ensure that the database is added to mapped-databases
  proxy.createDatabase(new Database("newDB", "", new File(localWarehouseUri, "newDB").toURI().toString(), null));
  Federations federations = stopServerAndGetConfiguration();
  PrimaryMetaStore primaryMetaStore = federations.getPrimaryMetaStore();
  assertThat(primaryMetaStore.getMappedDatabases().contains("newDB"), is(true));
}
 
Example 8
Source File: WaggleDanceIntegrationTest.java    From waggle-dance with Apache License 2.0 5 votes vote down vote up
@Test
public void primaryMappedDatabasesPrefixed() throws Exception {
  localServer.createDatabase("random_primary");
  remoteServer.createDatabase("random_federated");

  runner = WaggleDanceRunner
      .builder(configLocation)
      .databaseResolution(DatabaseResolution.PREFIXED)
      .primary("primary", localServer.getThriftConnectionUri(),
          AccessControlType.READ_AND_WRITE_AND_CREATE_ON_DATABASE_WHITELIST)
      .withPrimaryMappedDatabases(new String[] { LOCAL_DATABASE })
      .federate(SECONDARY_METASTORE_NAME, remoteServer.getThriftConnectionUri(), REMOTE_DATABASE)
      .build();

  runWaggleDance(runner);
  HiveMetaStoreClient proxy = getWaggleDanceClient();

  List<String> allDatabases = proxy.getAllDatabases();
  assertThat(allDatabases.size(), is(2));
  assertThat(allDatabases.get(0), is(LOCAL_DATABASE));
  assertThat(allDatabases.get(1), is(PREFIXED_REMOTE_DATABASE));

  // Ensure that the database is added to mapped-databases
  proxy.createDatabase(new Database("newDB", "", new File(localWarehouseUri, "newDB").toURI().toString(), null));
  Federations federations = stopServerAndGetConfiguration();
  PrimaryMetaStore primaryMetaStore = federations.getPrimaryMetaStore();
  assertThat(primaryMetaStore.getMappedDatabases().contains("newDB"), is(true));
}
 
Example 9
Source File: AbstractMetastoreTestWithStaticConfiguration.java    From incubator-sentry with Apache License 2.0 4 votes vote down vote up
public void createMetastoreDB(HiveMetaStoreClient client, String dbName)
    throws Exception {
  Database db = new Database();
  db.setName(dbName);
  client.createDatabase(db);
}