Search in sources :

Example 1 with CreateDatabaseMessage

use of org.apache.hadoop.hive.metastore.messaging.CreateDatabaseMessage in project hive by apache.

the class TestDbNotificationListener method createDatabase.

@Test
public void createDatabase() throws Exception {
    String dbName = "createdb";
    String dbName2 = "createdb2";
    String dbLocationUri = "file:/tmp";
    String dbDescription = "no description";
    Database db = new Database(dbName, dbDescription, dbLocationUri, emptyParameters);
    msClient.createDatabase(db);
    // Read notification from metastore
    NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
    assertEquals(1, rsp.getEventsSize());
    // Read event from notification
    NotificationEvent event = rsp.getEvents().get(0);
    assertEquals(firstEventId + 1, event.getEventId());
    assertTrue(event.getEventTime() >= startTime);
    assertEquals(EventType.CREATE_DATABASE.toString(), event.getEventType());
    assertEquals(dbName, event.getDbName());
    assertNull(event.getTableName());
    // Parse the message field
    CreateDatabaseMessage createDbMsg = md.getCreateDatabaseMessage(event.getMessage());
    assertEquals(dbName, createDbMsg.getDB());
    // Verify the eventID was passed to the non-transactional listener
    MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.CREATE_DATABASE, firstEventId + 1);
    // When hive.metastore.transactional.event.listeners is set,
    // a failed event should not create a new notification
    DummyRawStoreFailEvent.setEventSucceed(false);
    db = new Database(dbName2, dbDescription, dbLocationUri, emptyParameters);
    try {
        msClient.createDatabase(db);
        fail("Error: create database should've failed");
    } catch (Exception ex) {
    // expected
    }
    rsp = msClient.getNextNotification(firstEventId, 0, null);
    assertEquals(1, rsp.getEventsSize());
}
Also used : NotificationEventResponse(org.apache.hadoop.hive.metastore.api.NotificationEventResponse) CreateDatabaseMessage(org.apache.hadoop.hive.metastore.messaging.CreateDatabaseMessage) Database(org.apache.hadoop.hive.metastore.api.Database) NotificationEvent(org.apache.hadoop.hive.metastore.api.NotificationEvent) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) Test(org.junit.Test)

Example 2 with CreateDatabaseMessage

use of org.apache.hadoop.hive.metastore.messaging.CreateDatabaseMessage in project hive by apache.

the class CreateDatabaseHandler method handle.

@Override
public void handle(Context withinContext) throws Exception {
    LOG.info("Processing#{} CREATE_DATABASE message : {}", fromEventId(), event.getMessage());
    CreateDatabaseMessage createDatabaseMsg = deserializer.getCreateDatabaseMessage(event.getMessage());
    Path metaDataPath = new Path(withinContext.eventRoot, EximUtil.METADATA_NAME);
    FileSystem fileSystem = metaDataPath.getFileSystem(withinContext.hiveConf);
    EximUtil.createDbExportDump(fileSystem, metaDataPath, createDatabaseMsg.getDatabaseObject(), withinContext.replicationSpec);
    withinContext.createDmd(this).write();
}
Also used : Path(org.apache.hadoop.fs.Path) CreateDatabaseMessage(org.apache.hadoop.hive.metastore.messaging.CreateDatabaseMessage) FileSystem(org.apache.hadoop.fs.FileSystem)

Aggregations

CreateDatabaseMessage (org.apache.hadoop.hive.metastore.messaging.CreateDatabaseMessage)2 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 Database (org.apache.hadoop.hive.metastore.api.Database)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 NotificationEvent (org.apache.hadoop.hive.metastore.api.NotificationEvent)1 NotificationEventResponse (org.apache.hadoop.hive.metastore.api.NotificationEventResponse)1 Test (org.junit.Test)1