Search in sources :

Example 1 with EntityCreateRequest

use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest in project atlas by apache.

the class NotificationHookConsumerIT method testMessageHandleFailureConsumerContinues.

@Test
public void testMessageHandleFailureConsumerContinues() throws Exception {
    // send invalid message - update with invalid type
    sendHookMessage(new EntityPartialUpdateRequest(TEST_USER, randomString(), null, null, new Referenceable(randomString())));
    // send valid message
    final Referenceable entity = new Referenceable(DATABASE_TYPE_BUILTIN);
    final String dbName = "db" + randomString();
    entity.set(NAME, dbName);
    entity.set(DESCRIPTION, randomString());
    entity.set(QUALIFIED_NAME, dbName);
    entity.set(CLUSTER_NAME, randomString());
    sendHookMessage(new EntityCreateRequest(TEST_USER, entity));
    waitFor(MAX_WAIT_TIME, new Predicate() {

        @Override
        public boolean evaluate() throws Exception {
            ArrayNode results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_BUILTIN, entity.get(NAME)));
            return results.size() == 1;
        }
    });
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) EntityPartialUpdateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityPartialUpdateRequest) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) EntityCreateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest) Test(org.testng.annotations.Test)

Example 2 with EntityCreateRequest

use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest in project atlas by apache.

the class NotificationHookConsumerIT method testCreateEntity.

@Test
public void testCreateEntity() throws Exception {
    final Referenceable entity = new Referenceable(DATABASE_TYPE_BUILTIN);
    final String dbName = "db" + randomString();
    entity.set(NAME, dbName);
    entity.set(DESCRIPTION, randomString());
    entity.set(QUALIFIED_NAME, dbName);
    entity.set(CLUSTER_NAME, randomString());
    sendHookMessage(new EntityCreateRequest(TEST_USER, entity));
    waitFor(MAX_WAIT_TIME, new Predicate() {

        @Override
        public boolean evaluate() throws Exception {
            ArrayNode results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, entity.get(QUALIFIED_NAME)));
            return results.size() == 1;
        }
    });
    // Assert that user passed in hook message is used in audit
    Referenceable instance = atlasClientV1.getEntity(DATABASE_TYPE_BUILTIN, QUALIFIED_NAME, (String) entity.get(QUALIFIED_NAME));
    List<EntityAuditEvent> events = atlasClientV1.getEntityAuditEvents(instance.getId()._getId(), (short) 1);
    assertEquals(events.size(), 1);
    assertEquals(events.get(0).getUser(), TEST_USER);
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) EntityCreateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest) Test(org.testng.annotations.Test)

Example 3 with EntityCreateRequest

use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest in project atlas by apache.

the class AtlasHook method notifyEntities.

protected void notifyEntities(String user, List<Referenceable> entities) {
    List<HookNotification> hookNotifications = new ArrayList<>();
    hookNotifications.add(new EntityCreateRequest(user, entities));
    notifyEntities(hookNotifications);
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) ArrayList(java.util.ArrayList) EntityCreateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest)

Example 4 with EntityCreateRequest

use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest in project atlas by apache.

the class KafkaNotificationTest method testReceiveKafkaMessages.

@Test
public void testReceiveKafkaMessages() throws Exception {
    kafkaNotification.send(NotificationInterface.NotificationType.HOOK, new EntityCreateRequest("u1", new Referenceable("type")));
    kafkaNotification.send(NotificationInterface.NotificationType.HOOK, new EntityCreateRequest("u2", new Referenceable("type")));
    kafkaNotification.send(NotificationInterface.NotificationType.HOOK, new EntityCreateRequest("u3", new Referenceable("type")));
    kafkaNotification.send(NotificationInterface.NotificationType.HOOK, new EntityCreateRequest("u4", new Referenceable("type")));
    NotificationConsumer<Object> consumer = kafkaNotification.createConsumers(NotificationInterface.NotificationType.HOOK, 1).get(0);
    List<AtlasKafkaMessage<Object>> messages = null;
    // fetch starting time
    long startTime = System.currentTimeMillis();
    while ((System.currentTimeMillis() - startTime) < 10000) {
        messages = consumer.receive();
        if (messages.size() > 0) {
            break;
        }
    }
    int i = 1;
    for (AtlasKafkaMessage<Object> msg : messages) {
        HookNotification message = (HookNotification) msg.getMessage();
        assertEquals(message.getUser(), "u" + i++);
    }
    consumer.close();
}
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 5 with EntityCreateRequest

use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest in project atlas by apache.

the class HookNotificationTest method testNewMessageSerDe.

@Test
public void testNewMessageSerDe() throws Exception {
    Referenceable entity1 = new Referenceable("sometype");
    Referenceable entity2 = new Referenceable("newtype");
    entity1.set("attr", "value");
    entity1.set("complex", new Referenceable("othertype"));
    String user = "user";
    EntityCreateRequest request = new EntityCreateRequest(user, entity1, entity2);
    String notificationJson = AtlasType.toV1Json(request);
    HookNotification actualNotification = deserializer.deserialize(notificationJson);
    assertEquals(actualNotification.getType(), HookNotificationType.ENTITY_CREATE);
    assertEquals(actualNotification.getUser(), user);
    assertTrue(actualNotification instanceof EntityCreateRequest);
    EntityCreateRequest createRequest = (EntityCreateRequest) actualNotification;
    assertEquals(createRequest.getEntities().size(), 2);
    Referenceable actualEntity1 = createRequest.getEntities().get(0);
    assertEquals(actualEntity1.getTypeName(), "sometype");
    assertEquals(((Referenceable) actualEntity1.get("complex")).getTypeName(), "othertype");
    assertEquals(createRequest.getEntities().get(1).getTypeName(), "newtype");
}
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