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;
}
});
}
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);
}
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);
}
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();
}
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");
}
Aggregations