Search in sources :

Example 6 with EntityCreateRequestV2

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

the class HBaseAtlasHook method createOrUpdateNamespaceInstance.

private void createOrUpdateNamespaceInstance(HBaseOperationContext hbaseOperationContext) {
    AtlasEntity nameSpace = buildNameSpace(hbaseOperationContext);
    switch(hbaseOperationContext.getOperation()) {
        case CREATE_NAMESPACE:
            LOG.info("Create NameSpace {}", nameSpace.getAttribute(REFERENCEABLE_ATTRIBUTE_NAME));
            hbaseOperationContext.addMessage(new EntityCreateRequestV2(hbaseOperationContext.getUser(), new AtlasEntitiesWithExtInfo(nameSpace)));
            break;
        case ALTER_NAMESPACE:
            LOG.info("Modify NameSpace {}", nameSpace.getAttribute(REFERENCEABLE_ATTRIBUTE_NAME));
            hbaseOperationContext.addMessage(new EntityUpdateRequestV2(hbaseOperationContext.getUser(), new AtlasEntitiesWithExtInfo(nameSpace)));
            break;
    }
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) EntityUpdateRequestV2(org.apache.atlas.model.notification.HookNotification.EntityUpdateRequestV2) EntityCreateRequestV2(org.apache.atlas.model.notification.HookNotification.EntityCreateRequestV2)

Example 7 with EntityCreateRequestV2

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

the class HBaseAtlasHook method createOrUpdateTableInstance.

private void createOrUpdateTableInstance(HBaseOperationContext hbaseOperationContext) {
    AtlasEntity nameSpace = buildNameSpace(hbaseOperationContext);
    AtlasEntity table = buildTable(hbaseOperationContext, nameSpace);
    List<AtlasEntity> columnFamilies = buildColumnFamilies(hbaseOperationContext, nameSpace, table);
    table.setAttribute(ATTR_COLUMNFAMILIES, AtlasTypeUtil.getAtlasObjectIds(columnFamilies));
    AtlasEntitiesWithExtInfo entities = new AtlasEntitiesWithExtInfo(table);
    entities.addReferredEntity(nameSpace);
    if (CollectionUtils.isNotEmpty(columnFamilies)) {
        for (AtlasEntity columnFamily : columnFamilies) {
            entities.addReferredEntity(columnFamily);
        }
    }
    switch(hbaseOperationContext.getOperation()) {
        case CREATE_TABLE:
            LOG.info("Create Table {}", table.getAttribute(REFERENCEABLE_ATTRIBUTE_NAME));
            hbaseOperationContext.addMessage(new EntityCreateRequestV2(hbaseOperationContext.getUser(), entities));
            break;
        case ALTER_TABLE:
            LOG.info("Modify Table {}", table.getAttribute(REFERENCEABLE_ATTRIBUTE_NAME));
            hbaseOperationContext.addMessage(new EntityUpdateRequestV2(hbaseOperationContext.getUser(), entities));
            break;
    }
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) EntityUpdateRequestV2(org.apache.atlas.model.notification.HookNotification.EntityUpdateRequestV2) EntityCreateRequestV2(org.apache.atlas.model.notification.HookNotification.EntityCreateRequestV2)

Example 8 with EntityCreateRequestV2

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

Aggregations

AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)8 EntityCreateRequestV2 (org.apache.atlas.model.notification.HookNotification.EntityCreateRequestV2)8 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)5 HookNotification (org.apache.atlas.model.notification.HookNotification)5 EntityUpdateRequestV2 (org.apache.atlas.model.notification.HookNotification.EntityUpdateRequestV2)3 Map (java.util.Map)1 AtlasHookException (org.apache.atlas.hook.AtlasHookException)1 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)1 Configuration (org.apache.commons.configuration.Configuration)1 ImportException (org.apache.sqoop.util.ImportException)1 Test (org.testng.annotations.Test)1