Search in sources :

Example 6 with EntityCreateRequest

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");
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) ArrayList(java.util.ArrayList) NotificationException(org.apache.atlas.notification.NotificationException) EntityCreateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest) NotificationException(org.apache.atlas.notification.NotificationException) Test(org.testng.annotations.Test)

Example 7 with EntityCreateRequest

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());
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) TopicPartition(org.apache.kafka.common.TopicPartition) AtlasKafkaMessage(org.apache.atlas.kafka.AtlasKafkaMessage) EntityCreateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest) Test(org.testng.annotations.Test)

Example 8 with EntityCreateRequest

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);
}
Also used : EntityStream(org.apache.atlas.repository.store.graph.v1.EntityStream) AtlasKafkaMessage(org.apache.atlas.kafka.AtlasKafkaMessage) EntityCreateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest) Test(org.testng.annotations.Test)

Example 9 with EntityCreateRequest

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);
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) ArrayList(java.util.ArrayList) EntityCreateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest)

Example 10 with EntityCreateRequest

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);
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) EntityCreateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest) Test(org.testng.annotations.Test)

Aggregations

EntityCreateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest)12 Test (org.testng.annotations.Test)10 HookNotification (org.apache.atlas.model.notification.HookNotification)8 Referenceable (org.apache.atlas.v1.model.instance.Referenceable)6 ArrayList (java.util.ArrayList)5 NotificationException (org.apache.atlas.notification.NotificationException)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 AtlasKafkaMessage (org.apache.atlas.kafka.AtlasKafkaMessage)2 EntityAuditEvent (org.apache.atlas.EntityAuditEvent)1 EntityStream (org.apache.atlas.repository.store.graph.v1.EntityStream)1 EntityPartialUpdateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityPartialUpdateRequest)1 TopicPartition (org.apache.kafka.common.TopicPartition)1