use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest in project atlas by apache.
the class AtlasHookTest method testFailedMessageIsLoggedIfRequired.
@Test
public void testFailedMessageIsLoggedIfRequired() throws NotificationException {
List<HookNotification> hookNotifications = new ArrayList<HookNotification>() {
{
add(new EntityCreateRequest("user"));
}
};
doThrow(new NotificationException(new Exception(), Arrays.asList("test message"))).when(notificationInterface).send(NotificationInterface.NotificationType.HOOK, hookNotifications);
AtlasHook.notifyEntitiesInternal(hookNotifications, 2, notificationInterface, true, failedMessagesLogger);
verify(failedMessagesLogger, times(1)).log("test message");
}
use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest in project atlas by apache.
the class NotificationHookConsumerTest method testCommitIsCalledWhenMessageIsProcessed.
@Test
public void testCommitIsCalledWhenMessageIsProcessed() throws AtlasServiceException, AtlasException {
NotificationHookConsumer notificationHookConsumer = new NotificationHookConsumer(notificationInterface, atlasEntityStore, serviceState, instanceConverter, typeRegistry);
NotificationConsumer consumer = mock(NotificationConsumer.class);
NotificationHookConsumer.HookConsumer hookConsumer = notificationHookConsumer.new HookConsumer(consumer);
EntityCreateRequest message = mock(EntityCreateRequest.class);
Referenceable mock = mock(Referenceable.class);
when(message.getUser()).thenReturn("user");
when(message.getType()).thenReturn(HookNotificationType.ENTITY_CREATE);
when(message.getEntities()).thenReturn(Arrays.asList(mock));
hookConsumer.handleMessage(new AtlasKafkaMessage(message, -1, -1));
verify(consumer).commit(any(TopicPartition.class), anyInt());
}
use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest in project atlas by apache.
the class NotificationHookConsumerTest method testCommitIsNotCalledEvenWhenMessageProcessingFails.
@Test
public void testCommitIsNotCalledEvenWhenMessageProcessingFails() throws AtlasServiceException, AtlasException, AtlasBaseException {
NotificationHookConsumer notificationHookConsumer = new NotificationHookConsumer(notificationInterface, atlasEntityStore, serviceState, instanceConverter, typeRegistry);
NotificationConsumer consumer = mock(NotificationConsumer.class);
NotificationHookConsumer.HookConsumer hookConsumer = notificationHookConsumer.new HookConsumer(consumer);
EntityCreateRequest message = new EntityCreateRequest("user", Collections.singletonList(mock(Referenceable.class)));
when(atlasEntityStore.createOrUpdate(any(EntityStream.class), anyBoolean())).thenThrow(new RuntimeException("Simulating exception in processing message"));
hookConsumer.handleMessage(new AtlasKafkaMessage(message, -1, -1));
verifyZeroInteractions(consumer);
}
use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest in project atlas by apache.
the class FalconHook method fireAndForget.
private void fireAndForget(FalconEvent event) throws FalconException, URISyntaxException {
LOG.info("Entered Atlas hook for Falcon hook operation {}", event.getOperation());
List<HookNotification> messages = new ArrayList<>();
Operation op = getOperation(event.getOperation());
String user = getUser(event.getUser());
LOG.info("fireAndForget user:{}", user);
switch(op) {
case ADD:
messages.add(new EntityCreateRequest(user, createEntities(event, user)));
break;
}
notifyEntities(messages);
}
use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest in project atlas by apache.
the class HookNotificationTest method testBackwardCompatibility.
@Test
public void testBackwardCompatibility() throws Exception {
// Code to generate the json, use it for hard-coded json used later in this test
Referenceable entity = new Referenceable("sometype");
entity.set("attr", "value");
EntityCreateRequest request = new EntityCreateRequest(null, entity);
String notificationJsonFromCode = AtlasType.toV1Json(request);
System.out.println(notificationJsonFromCode);
// Json without user and assert that the string can be deserialised
String notificationJson = "{\n" + " \"entities\": [\n" + " {\n" + " \"jsonClass\": \"org.apache.atlas.typesystem.json.InstanceSerialization$_Reference\",\n" + " \"id\": {\n" + " \"jsonClass\": \"org.apache.atlas.typesystem.json.InstanceSerialization$_Id\",\n" + " \"id\": \"-1459493350903186000\",\n" + " \"version\": 0,\n" + " \"typeName\": \"sometype\",\n" + " \"state\": \"ACTIVE\"\n" + " },\n" + " \"typeName\": \"sometype\",\n" + " \"values\": {\n" + " \"attr\": \"value\"\n" + " },\n" + " \"traitNames\": [],\n" + " \"traits\": {}\n" + " }\n" + " ],\n" + " \"type\": \"ENTITY_CREATE\"\n" + "}";
HookNotification actualNotification = deserializer.deserialize(notificationJson);
assertEquals(actualNotification.getType(), HookNotificationType.ENTITY_CREATE);
assertEquals(actualNotification.getUser(), HookNotification.UNKNOW_USER);
}
Aggregations