use of org.apache.hadoop.hive.metastore.messaging.CreateFunctionMessage in project hive by apache.
the class CreateFunctionHandler method handle.
@Override
public void handle(Context withinContext) throws Exception {
CreateFunctionMessage createFunctionMessage = deserializer.getCreateFunctionMessage(event.getMessage());
LOG.info("Processing#{} CREATE_MESSAGE message : {}", fromEventId(), event.getMessage());
Path metadataPath = new Path(withinContext.eventRoot, EximUtil.METADATA_NAME);
FileSystem fileSystem = metadataPath.getFileSystem(withinContext.hiveConf);
try (JsonWriter jsonWriter = new JsonWriter(fileSystem, metadataPath)) {
new FunctionSerializer(createFunctionMessage.getFunctionObj(), withinContext.hiveConf).writeTo(jsonWriter, withinContext.replicationSpec);
}
withinContext.createDmd(this).write();
}
use of org.apache.hadoop.hive.metastore.messaging.CreateFunctionMessage in project hive by apache.
the class TestDbNotificationListener method createFunction.
@Test
public void createFunction() throws Exception {
String defaultDbName = "default";
String funcName = "createfunction";
String funcName2 = "createfunction2";
String ownerName = "me";
String funcClass = "o.a.h.h.createfunc";
String funcClass2 = "o.a.h.h.createfunc2";
String funcResource = "file:/tmp/somewhere";
String funcResource2 = "file:/tmp/somewhere2";
Function func = new Function(funcName, defaultDbName, funcClass, ownerName, PrincipalType.USER, startTime, FunctionType.JAVA, Arrays.asList(new ResourceUri(ResourceType.JAR, funcResource)));
// Event 1
msClient.createFunction(func);
// Get notifications from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(1, rsp.getEventsSize());
NotificationEvent event = rsp.getEvents().get(0);
assertEquals(firstEventId + 1, event.getEventId());
assertTrue(event.getEventTime() >= startTime);
assertEquals(EventType.CREATE_FUNCTION.toString(), event.getEventType());
assertEquals(defaultDbName, event.getDbName());
// Parse the message field
CreateFunctionMessage createFuncMsg = md.getCreateFunctionMessage(event.getMessage());
assertEquals(defaultDbName, createFuncMsg.getDB());
Function funcObj = createFuncMsg.getFunctionObj();
assertEquals(defaultDbName, funcObj.getDbName());
assertEquals(funcName, funcObj.getFunctionName());
assertEquals(funcClass, funcObj.getClassName());
assertEquals(ownerName, funcObj.getOwnerName());
assertEquals(FunctionType.JAVA, funcObj.getFunctionType());
assertEquals(1, funcObj.getResourceUrisSize());
assertEquals(ResourceType.JAR, funcObj.getResourceUris().get(0).getResourceType());
assertEquals(funcResource, funcObj.getResourceUris().get(0).getUri());
// Verify the eventID was passed to the non-transactional listener
MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.CREATE_FUNCTION, firstEventId + 1);
// When hive.metastore.transactional.event.listeners is set,
// a failed event should not create a new notification
DummyRawStoreFailEvent.setEventSucceed(false);
func = new Function(funcName2, defaultDbName, funcClass2, ownerName, PrincipalType.USER, startTime, FunctionType.JAVA, Arrays.asList(new ResourceUri(ResourceType.JAR, funcResource2)));
try {
msClient.createFunction(func);
fail("Error: create function should've failed");
} catch (Exception ex) {
// expected
}
rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(1, rsp.getEventsSize());
}
Aggregations