Search in sources :

Example 66 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class BaseResourceIT method createHiveDBInstanceV1.

protected Referenceable createHiveDBInstanceV1(String dbName) {
    Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
    databaseInstance.set(NAME, dbName);
    databaseInstance.set(DESCRIPTION, "foo database");
    databaseInstance.set(CLUSTER_NAME, "fooCluster");
    return databaseInstance;
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable)

Example 67 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class DataSetLineageJerseyResourceIT method database.

Id database(String name, String description, String owner, String locationUri, String... traitNames) throws Exception {
    Referenceable referenceable = new Referenceable(DATABASE_TYPE, traitNames);
    referenceable.set(NAME, name);
    referenceable.set(QUALIFIED_NAME, name);
    referenceable.set(CLUSTER_NAME, locationUri + name);
    referenceable.set("description", description);
    referenceable.set("owner", owner);
    referenceable.set("locationUri", locationUri);
    referenceable.set("createTime", System.currentTimeMillis());
    return createInstance(referenceable);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable)

Example 68 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class KafkaConsumerTest method testReceive.

@Test
public void testReceive() throws Exception {
    Referenceable entity = getEntity(TRAIT_NAME);
    EntityUpdateRequest message = new EntityUpdateRequest("user1", entity);
    String json = AtlasType.toV1Json(new AtlasNotificationMessage<>(new MessageVersion("1.0.0"), message));
    TopicPartition tp = new TopicPartition("ATLAS_HOOK", 0);
    List<ConsumerRecord<String, String>> klist = Collections.singletonList(new ConsumerRecord<>("ATLAS_HOOK", 0, 0L, "mykey", json));
    Map mp = Collections.singletonMap(tp, klist);
    ConsumerRecords records = new ConsumerRecords(mp);
    when(kafkaConsumer.poll(100)).thenReturn(records);
    kafkaConsumer.assign(Collections.singletonList(tp));
    AtlasKafkaConsumer consumer = new AtlasKafkaConsumer(NotificationType.HOOK, kafkaConsumer, false, 100L);
    List<AtlasKafkaMessage<HookNotification>> messageList = consumer.receive();
    assertTrue(messageList.size() > 0);
    HookNotification consumedMessage = messageList.get(0).getMessage();
    assertMessagesEqual(message, consumedMessage, entity);
}
Also used : MessageVersion(org.apache.atlas.model.notification.MessageVersion) ConsumerRecords(org.apache.kafka.clients.consumer.ConsumerRecords) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) EntityUpdateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest) HookNotification(org.apache.atlas.model.notification.HookNotification) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) TopicPartition(org.apache.kafka.common.TopicPartition) Map(java.util.Map) Test(org.testng.annotations.Test) EntityNotificationTest(org.apache.atlas.notification.entity.EntityNotificationTest)

Example 69 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class KafkaConsumerTest method assertMessagesEqual.

private void assertMessagesEqual(EntityUpdateRequest message, HookNotification consumedMessage, Referenceable entity) {
    assertEquals(consumedMessage.getType(), message.getType());
    assertEquals(consumedMessage.getUser(), message.getUser());
    assertTrue(consumedMessage instanceof EntityUpdateRequest);
    EntityUpdateRequest deserializedEntityUpdateRequest = (EntityUpdateRequest) consumedMessage;
    Referenceable deserializedEntity = deserializedEntityUpdateRequest.getEntities().get(0);
    assertEquals(deserializedEntity.getId(), entity.getId());
    assertEquals(deserializedEntity.getTypeName(), entity.getTypeName());
    assertEquals(deserializedEntity.getTraits(), entity.getTraits());
    assertEquals(deserializedEntity.getTrait(TRAIT_NAME), entity.getTrait(TRAIT_NAME));
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) EntityUpdateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest)

Example 70 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable 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)

Aggregations

Referenceable (org.apache.atlas.v1.model.instance.Referenceable)143 Test (org.testng.annotations.Test)64 Id (org.apache.atlas.v1.model.instance.Id)37 Struct (org.apache.atlas.v1.model.instance.Struct)23 ArrayList (java.util.ArrayList)20 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)15 HashMap (java.util.HashMap)12 List (java.util.List)10 AtlasException (org.apache.atlas.AtlasException)10 HookNotification (org.apache.atlas.model.notification.HookNotification)10 Map (java.util.Map)9 EntityUpdateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest)9 AtlasServiceException (org.apache.atlas.AtlasServiceException)8 EntityAuditEvent (org.apache.atlas.EntityAuditEvent)8 EntityNotificationV1 (org.apache.atlas.v1.model.notification.EntityNotificationV1)7 EntityCreateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest)7 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)6 EntityResult (org.apache.atlas.model.legacy.EntityResult)6 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)6 EntityNotificationTest (org.apache.atlas.notification.entity.EntityNotificationTest)5