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());
}
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();
}
Aggregations