Search in sources :

Example 21 with NotificationEvent

use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.

the class DbNotificationListener method onDropDatabase.

/**
 * @param dbEvent database event
 * @throws MetaException
 */
@Override
public void onDropDatabase(DropDatabaseEvent dbEvent) throws MetaException {
    Database db = dbEvent.getDatabase();
    NotificationEvent event = new NotificationEvent(0, now(), EventType.DROP_DATABASE.toString(), msgFactory.buildDropDatabaseMessage(db).toString());
    event.setDbName(db.getName());
    process(event, dbEvent);
}
Also used : Database(org.apache.hadoop.hive.metastore.api.Database) NotificationEvent(org.apache.hadoop.hive.metastore.api.NotificationEvent)

Example 22 with NotificationEvent

use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.

the class DbNotificationListener method onDropConstraint.

/**
 * @param dropConstraintEvent drop constraint event
 * @throws MetaException
 */
@Override
public void onDropConstraint(DropConstraintEvent dropConstraintEvent) throws MetaException {
    String dbName = dropConstraintEvent.getDbName();
    String tableName = dropConstraintEvent.getTableName();
    String constraintName = dropConstraintEvent.getConstraintName();
    NotificationEvent event = new NotificationEvent(0, now(), EventType.DROP_CONSTRAINT.toString(), msgFactory.buildDropConstraintMessage(dbName, tableName, constraintName).toString());
    event.setDbName(dbName);
    event.setTableName(tableName);
    process(event, dropConstraintEvent);
}
Also used : NotificationEvent(org.apache.hadoop.hive.metastore.api.NotificationEvent)

Example 23 with NotificationEvent

use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.

the class DbNotificationListener method onAddUniqueConstraint.

/**
 * @param addUniqueConstraintEvent add unique constraint event
 * @throws MetaException
 */
@Override
public void onAddUniqueConstraint(AddUniqueConstraintEvent addUniqueConstraintEvent) throws MetaException {
    List<SQLUniqueConstraint> cols = addUniqueConstraintEvent.getUniqueConstraintCols();
    if (cols.size() > 0) {
        NotificationEvent event = new NotificationEvent(0, now(), EventType.ADD_UNIQUECONSTRAINT.toString(), msgFactory.buildAddUniqueConstraintMessage(addUniqueConstraintEvent.getUniqueConstraintCols()).toString());
        event.setDbName(cols.get(0).getTable_db());
        event.setTableName(cols.get(0).getTable_name());
        process(event, addUniqueConstraintEvent);
    }
}
Also used : SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) NotificationEvent(org.apache.hadoop.hive.metastore.api.NotificationEvent)

Example 24 with NotificationEvent

use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.

the class DbNotificationListener method onAddPartition.

/**
 * @param partitionEvent partition event
 * @throws MetaException
 */
@Override
public void onAddPartition(AddPartitionEvent partitionEvent) throws MetaException {
    Table t = partitionEvent.getTable();
    String msg = msgFactory.buildAddPartitionMessage(t, partitionEvent.getPartitionIterator(), new PartitionFilesIterator(partitionEvent.getPartitionIterator(), t)).toString();
    NotificationEvent event = new NotificationEvent(0, now(), EventType.ADD_PARTITION.toString(), msg);
    event.setDbName(t.getDbName());
    event.setTableName(t.getTableName());
    process(event, partitionEvent);
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) NotificationEvent(org.apache.hadoop.hive.metastore.api.NotificationEvent)

Example 25 with NotificationEvent

use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.

the class TestObjectStore method testNotificationOps.

/**
 * Test notification operations
 */
// TODO MS-SPLIT uncomment once we move EventMessage over
@Test
public void testNotificationOps() throws InterruptedException {
    final int NO_EVENT_ID = 0;
    final int FIRST_EVENT_ID = 1;
    final int SECOND_EVENT_ID = 2;
    NotificationEvent event = new NotificationEvent(0, 0, EventMessage.EventType.CREATE_DATABASE.toString(), "");
    NotificationEventResponse eventResponse;
    CurrentNotificationEventId eventId;
    // Verify that there is no notifications available yet
    eventId = objectStore.getCurrentNotificationEventId();
    Assert.assertEquals(NO_EVENT_ID, eventId.getEventId());
    // Verify that addNotificationEvent() updates the NotificationEvent with the new event ID
    objectStore.addNotificationEvent(event);
    Assert.assertEquals(FIRST_EVENT_ID, event.getEventId());
    objectStore.addNotificationEvent(event);
    Assert.assertEquals(SECOND_EVENT_ID, event.getEventId());
    // Verify that objectStore fetches the latest notification event ID
    eventId = objectStore.getCurrentNotificationEventId();
    Assert.assertEquals(SECOND_EVENT_ID, eventId.getEventId());
    // Verify that getNextNotification() returns all events
    eventResponse = objectStore.getNextNotification(new NotificationEventRequest());
    Assert.assertEquals(2, eventResponse.getEventsSize());
    Assert.assertEquals(FIRST_EVENT_ID, eventResponse.getEvents().get(0).getEventId());
    Assert.assertEquals(SECOND_EVENT_ID, eventResponse.getEvents().get(1).getEventId());
    // Verify that getNextNotification(last) returns events after a specified event
    eventResponse = objectStore.getNextNotification(new NotificationEventRequest(FIRST_EVENT_ID));
    Assert.assertEquals(1, eventResponse.getEventsSize());
    Assert.assertEquals(SECOND_EVENT_ID, eventResponse.getEvents().get(0).getEventId());
    // Verify that getNextNotification(last) returns zero events if there are no more notifications available
    eventResponse = objectStore.getNextNotification(new NotificationEventRequest(SECOND_EVENT_ID));
    Assert.assertEquals(0, eventResponse.getEventsSize());
    // Verify that cleanNotificationEvents() cleans up all old notifications
    Thread.sleep(1);
    objectStore.cleanNotificationEvents(1);
    eventResponse = objectStore.getNextNotification(new NotificationEventRequest());
    Assert.assertEquals(0, eventResponse.getEventsSize());
}
Also used : NotificationEventResponse(org.apache.hadoop.hive.metastore.api.NotificationEventResponse) NotificationEventRequest(org.apache.hadoop.hive.metastore.api.NotificationEventRequest) NotificationEvent(org.apache.hadoop.hive.metastore.api.NotificationEvent) CurrentNotificationEventId(org.apache.hadoop.hive.metastore.api.CurrentNotificationEventId) MetastoreUnitTest(org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest) Test(org.junit.Test)

Aggregations

NotificationEvent (org.apache.hadoop.hive.metastore.api.NotificationEvent)67 Test (org.junit.Test)41 Table (org.apache.hadoop.hive.metastore.api.Table)28 NotificationEventResponse (org.apache.hadoop.hive.metastore.api.NotificationEventResponse)27 ArrayList (java.util.ArrayList)16 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)16 SerDeInfo (org.apache.hadoop.hive.metastore.api.SerDeInfo)12 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)12 HCatNotificationEvent (org.apache.hive.hcatalog.api.HCatNotificationEvent)11 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)10 Partition (org.apache.hadoop.hive.metastore.api.Partition)10 ReplicationTask (org.apache.hive.hcatalog.api.repl.ReplicationTask)10 Database (org.apache.hadoop.hive.metastore.api.Database)9 NoopReplicationTask (org.apache.hive.hcatalog.api.repl.NoopReplicationTask)9 IMetaStoreClient (org.apache.hadoop.hive.metastore.IMetaStoreClient)8 Index (org.apache.hadoop.hive.metastore.api.Index)6 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)4 Nullable (javax.annotation.Nullable)4 Function (org.apache.hadoop.hive.metastore.api.Function)4