Search in sources :

Example 26 with HookNotification

use of org.apache.atlas.model.notification.HookNotification in project atlas by apache.

the class HookNotificationTest method testEntityCreateV2SerDe.

@Test
public void testEntityCreateV2SerDe() throws Exception {
    AtlasEntity entity1 = new AtlasEntity("sometype");
    AtlasEntity entity2 = new AtlasEntity("newtype");
    AtlasEntity entity3 = new AtlasEntity("othertype");
    setAttributes(entity1);
    entity1.setAttribute("complex", new AtlasObjectId(entity3.getGuid(), entity3.getTypeName()));
    AtlasEntitiesWithExtInfo entities = new AtlasEntitiesWithExtInfo();
    entities.addEntity(entity1);
    entities.addEntity(entity2);
    entities.addReferredEntity(entity3);
    String user = "user";
    EntityCreateRequestV2 request = new EntityCreateRequestV2(user, entities);
    String notificationJson = AtlasJson.toJson(request);
    HookNotification actualNotification = deserializer.deserialize(notificationJson);
    assertEquals(actualNotification.getType(), HookNotificationType.ENTITY_CREATE_V2);
    assertEquals(actualNotification.getUser(), user);
    EntityCreateRequestV2 createRequest = (EntityCreateRequestV2) actualNotification;
    assertEquals(createRequest.getEntities().getEntities().size(), 2);
    AtlasEntity actualEntity1 = createRequest.getEntities().getEntities().get(0);
    AtlasEntity actualEntity2 = createRequest.getEntities().getEntities().get(1);
    AtlasEntity actualEntity3 = createRequest.getEntities().getReferredEntity(entity3.getGuid());
    Map actualComplexAttr = (Map) actualEntity1.getAttribute("complex");
    assertEquals(actualEntity1.getGuid(), entity1.getGuid());
    assertEquals(actualEntity1.getTypeName(), entity1.getTypeName());
    assertAttributes(actualEntity1);
    assertEquals(actualComplexAttr.get(AtlasObjectId.KEY_GUID), entity3.getGuid());
    assertEquals(actualComplexAttr.get(AtlasObjectId.KEY_TYPENAME), entity3.getTypeName());
    assertEquals(actualEntity2.getGuid(), entity2.getGuid());
    assertEquals(actualEntity2.getTypeName(), entity2.getTypeName());
    assertEquals(actualEntity3.getGuid(), entity3.getGuid());
    assertEquals(actualEntity3.getTypeName(), entity3.getTypeName());
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Map(java.util.Map) EntityCreateRequestV2(org.apache.atlas.model.notification.HookNotification.EntityCreateRequestV2) Test(org.testng.annotations.Test)

Example 27 with HookNotification

use of org.apache.atlas.model.notification.HookNotification in project atlas by apache.

the class HookNotificationTest method testEntityUpdateV2SerDe.

@Test
public void testEntityUpdateV2SerDe() throws Exception {
    AtlasEntity entity1 = new AtlasEntity("sometype");
    AtlasEntity entity2 = new AtlasEntity("newtype");
    AtlasEntity entity3 = new AtlasEntity("othertype");
    setAttributes(entity1);
    entity1.setAttribute("complex", new AtlasObjectId(entity3.getGuid(), entity3.getTypeName()));
    AtlasEntitiesWithExtInfo entities = new AtlasEntitiesWithExtInfo();
    entities.addEntity(entity1);
    entities.addEntity(entity2);
    entities.addReferredEntity(entity3);
    String user = "user";
    EntityUpdateRequestV2 request = new EntityUpdateRequestV2(user, entities);
    String notificationJson = AtlasJson.toJson(request);
    HookNotification actualNotification = deserializer.deserialize(notificationJson);
    assertEquals(actualNotification.getType(), HookNotificationType.ENTITY_FULL_UPDATE_V2);
    assertEquals(actualNotification.getUser(), user);
    EntityUpdateRequestV2 updateRequest = (EntityUpdateRequestV2) actualNotification;
    assertEquals(updateRequest.getEntities().getEntities().size(), 2);
    AtlasEntity actualEntity1 = updateRequest.getEntities().getEntities().get(0);
    AtlasEntity actualEntity2 = updateRequest.getEntities().getEntities().get(1);
    AtlasEntity actualEntity3 = updateRequest.getEntities().getReferredEntity(entity3.getGuid());
    Map actualComplexAttr = (Map) actualEntity1.getAttribute("complex");
    assertEquals(actualEntity1.getGuid(), entity1.getGuid());
    assertEquals(actualEntity1.getTypeName(), entity1.getTypeName());
    assertAttributes(actualEntity1);
    assertEquals(actualComplexAttr.get(AtlasObjectId.KEY_GUID), entity3.getGuid());
    assertEquals(actualComplexAttr.get(AtlasObjectId.KEY_TYPENAME), entity3.getTypeName());
    assertEquals(actualEntity2.getGuid(), entity2.getGuid());
    assertEquals(actualEntity2.getTypeName(), entity2.getTypeName());
    assertEquals(actualEntity3.getGuid(), entity3.getGuid());
    assertEquals(actualEntity3.getTypeName(), entity3.getTypeName());
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) EntityUpdateRequestV2(org.apache.atlas.model.notification.HookNotification.EntityUpdateRequestV2) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 28 with HookNotification

use of org.apache.atlas.model.notification.HookNotification 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)

Example 29 with HookNotification

use of org.apache.atlas.model.notification.HookNotification in project atlas by apache.

the class AtlasHookTest method testAllFailedMessagesAreLogged.

@Test
public void testAllFailedMessagesAreLogged() throws NotificationException {
    List<HookNotification> hookNotifications = new ArrayList<HookNotification>() {

        {
            add(new EntityCreateRequest("user"));
        }
    };
    doThrow(new NotificationException(new Exception(), Arrays.asList("test message1", "test message2"))).when(notificationInterface).send(NotificationInterface.NotificationType.HOOK, hookNotifications);
    AtlasHook.notifyEntitiesInternal(hookNotifications, 2, notificationInterface, true, failedMessagesLogger);
    verify(failedMessagesLogger, times(1)).log("test message1");
    verify(failedMessagesLogger, times(1)).log("test message2");
}
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 30 with HookNotification

use of org.apache.atlas.model.notification.HookNotification in project atlas by apache.

the class AtlasHookTest method testFailedMessageIsNotLoggedIfNotRequired.

@Test
public void testFailedMessageIsNotLoggedIfNotRequired() throws NotificationException {
    List<HookNotification> hookNotifications = new ArrayList<>();
    doThrow(new NotificationException(new Exception(), Arrays.asList("test message"))).when(notificationInterface).send(NotificationInterface.NotificationType.HOOK, hookNotifications);
    AtlasHook.notifyEntitiesInternal(hookNotifications, 2, notificationInterface, false, failedMessagesLogger);
    verifyZeroInteractions(failedMessagesLogger);
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) ArrayList(java.util.ArrayList) NotificationException(org.apache.atlas.notification.NotificationException) NotificationException(org.apache.atlas.notification.NotificationException) Test(org.testng.annotations.Test)

Aggregations

HookNotification (org.apache.atlas.model.notification.HookNotification)31 Test (org.testng.annotations.Test)18 ArrayList (java.util.ArrayList)13 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)9 Referenceable (org.apache.atlas.v1.model.instance.Referenceable)9 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)8 EntityCreateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest)8 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)6 EntityNotificationTest (org.apache.atlas.notification.entity.EntityNotificationTest)6 EntityUpdateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest)6 Map (java.util.Map)5 EntityCreateRequestV2 (org.apache.atlas.model.notification.HookNotification.EntityCreateRequestV2)5 NotificationException (org.apache.atlas.notification.NotificationException)5 EntityUpdateRequestV2 (org.apache.atlas.model.notification.HookNotification.EntityUpdateRequestV2)4 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)3 EntityDeleteRequestV2 (org.apache.atlas.model.notification.HookNotification.EntityDeleteRequestV2)3 EntityPartialUpdateRequestV2 (org.apache.atlas.model.notification.HookNotification.EntityPartialUpdateRequestV2)3 MessageVersion (org.apache.atlas.model.notification.MessageVersion)2 Table (org.apache.hadoop.hive.ql.metadata.Table)2 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)2