Search in sources :

Example 71 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class AlterTableRename method processTables.

private void processTables(Table oldTable, Table newTable, List<HookNotification> ret) throws Exception {
    AtlasEntityWithExtInfo oldTableEntity = toTableEntity(oldTable);
    AtlasEntityWithExtInfo renamedTableEntity = toTableEntity(newTable);
    if (oldTableEntity == null || renamedTableEntity == null) {
        return;
    }
    // update qualifiedName for all columns, partitionKeys, storageDesc
    String renamedTableQualifiedName = (String) renamedTableEntity.getEntity().getAttribute(ATTRIBUTE_QUALIFIED_NAME);
    renameColumns((List<AtlasObjectId>) oldTableEntity.getEntity().getRelationshipAttribute(ATTRIBUTE_COLUMNS), oldTableEntity, renamedTableQualifiedName, ret);
    renameColumns((List<AtlasObjectId>) oldTableEntity.getEntity().getRelationshipAttribute(ATTRIBUTE_PARTITION_KEYS), oldTableEntity, renamedTableQualifiedName, ret);
    renameStorageDesc(oldTableEntity, renamedTableEntity, ret);
    // set previous name as the alias
    renamedTableEntity.getEntity().setAttribute(ATTRIBUTE_ALIASES, Collections.singletonList(oldTable.getTableName()));
    // make a copy of renamedTableEntity to send as partial-update with no relationship attributes
    AtlasEntity renamedTableEntityForPartialUpdate = new AtlasEntity(renamedTableEntity.getEntity());
    renamedTableEntityForPartialUpdate.setRelationshipAttributes(null);
    String oldTableQualifiedName = (String) oldTableEntity.getEntity().getAttribute(ATTRIBUTE_QUALIFIED_NAME);
    AtlasObjectId oldTableId = new AtlasObjectId(oldTableEntity.getEntity().getTypeName(), ATTRIBUTE_QUALIFIED_NAME, oldTableQualifiedName);
    // update qualifiedName and other attributes (like params - which include lastModifiedTime, lastModifiedBy) of the table
    ret.add(new EntityPartialUpdateRequestV2(getUserName(), oldTableId, new AtlasEntityWithExtInfo(renamedTableEntityForPartialUpdate)));
    // to handle cases where Atlas didn't have the oldTable, send a full update
    ret.add(new EntityUpdateRequestV2(getUserName(), new AtlasEntitiesWithExtInfo(renamedTableEntity)));
    // partial update relationship attribute ddl
    if (!context.isMetastoreHook()) {
        AtlasEntity ddlEntity = createHiveDDLEntity(renamedTableEntity.getEntity(), true);
        if (ddlEntity != null) {
            ret.add(new HookNotification.EntityCreateRequestV2(getUserName(), new AtlasEntitiesWithExtInfo(ddlEntity)));
        }
    }
    context.removeFromKnownTable(oldTableQualifiedName);
}
Also used : EntityPartialUpdateRequestV2(org.apache.atlas.model.notification.HookNotification.EntityPartialUpdateRequestV2) HookNotification(org.apache.atlas.model.notification.HookNotification) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) 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)

Example 72 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class AlterTableRename method renameStorageDesc.

private void renameStorageDesc(AtlasEntityWithExtInfo oldEntityExtInfo, AtlasEntityWithExtInfo newEntityExtInfo, List<HookNotification> notifications) {
    AtlasEntity oldSd = getStorageDescEntity(oldEntityExtInfo);
    // make a copy of newSd, since we will be setting relationshipAttributes to 'null' below
    AtlasEntity newSd = new AtlasEntity(getStorageDescEntity(newEntityExtInfo));
    if (oldSd != null && newSd != null) {
        AtlasObjectId oldSdId = new AtlasObjectId(oldSd.getTypeName(), ATTRIBUTE_QUALIFIED_NAME, oldSd.getAttribute(ATTRIBUTE_QUALIFIED_NAME));
        newSd.removeAttribute(ATTRIBUTE_TABLE);
        newSd.setRelationshipAttributes(null);
        notifications.add(new EntityPartialUpdateRequestV2(getUserName(), oldSdId, new AtlasEntityWithExtInfo(newSd)));
    }
}
Also used : EntityPartialUpdateRequestV2(org.apache.atlas.model.notification.HookNotification.EntityPartialUpdateRequestV2) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId)

Example 73 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class BaseHiveEvent method toTableEntity.

protected AtlasEntity toTableEntity(AtlasObjectId dbId, Table table, AtlasEntityExtInfo entityExtInfo) throws Exception {
    String tblQualifiedName = getQualifiedName(table);
    boolean isKnownTable = context.isKnownTable(tblQualifiedName);
    AtlasEntity ret = context.getEntity(tblQualifiedName);
    if (ret == null) {
        PreprocessAction action = context.getPreprocessActionForHiveTable(tblQualifiedName);
        if (action == PreprocessAction.IGNORE) {
            LOG.info("ignoring table {}", tblQualifiedName);
        } else {
            ret = new AtlasEntity(HIVE_TYPE_TABLE);
            // - cause Atlas server to resolve the entity by its qualifiedName
            if (isKnownTable && !isAlterTableOperation()) {
                ret.setGuid(null);
            }
            long createTime = getTableCreateTime(table);
            long lastAccessTime = table.getLastAccessTime() > 0 ? (table.getLastAccessTime() * MILLIS_CONVERT_FACTOR) : createTime;
            AtlasRelatedObjectId dbRelatedObject = new AtlasRelatedObjectId(dbId, RELATIONSHIP_HIVE_TABLE_DB);
            ret.setRelationshipAttribute(ATTRIBUTE_DB, dbRelatedObject);
            ret.setAttribute(ATTRIBUTE_QUALIFIED_NAME, tblQualifiedName);
            ret.setAttribute(ATTRIBUTE_NAME, table.getTableName().toLowerCase());
            ret.setAttribute(ATTRIBUTE_OWNER, table.getOwner());
            ret.setAttribute(ATTRIBUTE_CREATE_TIME, createTime);
            ret.setAttribute(ATTRIBUTE_LAST_ACCESS_TIME, lastAccessTime);
            ret.setAttribute(ATTRIBUTE_RETENTION, table.getRetention());
            ret.setAttribute(ATTRIBUTE_PARAMETERS, table.getParameters());
            ret.setAttribute(ATTRIBUTE_COMMENT, table.getParameters().get(ATTRIBUTE_COMMENT));
            ret.setAttribute(ATTRIBUTE_TABLE_TYPE, table.getTableType().name());
            ret.setAttribute(ATTRIBUTE_TEMPORARY, table.isTemporary());
            if (table.getViewOriginalText() != null) {
                ret.setAttribute(ATTRIBUTE_VIEW_ORIGINAL_TEXT, table.getViewOriginalText());
            }
            if (table.getViewExpandedText() != null) {
                ret.setAttribute(ATTRIBUTE_VIEW_EXPANDED_TEXT, table.getViewExpandedText());
            }
            boolean pruneTable = table.isTemporary() || action == PreprocessAction.PRUNE;
            if (pruneTable) {
                LOG.info("ignoring details of table {}", tblQualifiedName);
            } else {
                AtlasObjectId tableId = AtlasTypeUtil.getObjectId(ret);
                AtlasEntity sd = getStorageDescEntity(tableId, table);
                List<AtlasEntity> partitionKeys = getColumnEntities(tableId, table, table.getPartitionKeys(), RELATIONSHIP_HIVE_TABLE_PART_KEYS);
                List<AtlasEntity> columns = getColumnEntities(tableId, table, table.getCols(), RELATIONSHIP_HIVE_TABLE_COLUMNS);
                if (entityExtInfo != null) {
                    entityExtInfo.addReferredEntity(sd);
                    if (partitionKeys != null) {
                        for (AtlasEntity partitionKey : partitionKeys) {
                            entityExtInfo.addReferredEntity(partitionKey);
                        }
                    }
                    if (columns != null) {
                        for (AtlasEntity column : columns) {
                            entityExtInfo.addReferredEntity(column);
                        }
                    }
                }
                ret.setRelationshipAttribute(ATTRIBUTE_STORAGEDESC, AtlasTypeUtil.getAtlasRelatedObjectId(sd, RELATIONSHIP_HIVE_TABLE_STORAGE_DESC));
                ret.setRelationshipAttribute(ATTRIBUTE_PARTITION_KEYS, AtlasTypeUtil.getAtlasRelatedObjectIds(partitionKeys, RELATIONSHIP_HIVE_TABLE_PART_KEYS));
                ret.setRelationshipAttribute(ATTRIBUTE_COLUMNS, AtlasTypeUtil.getAtlasRelatedObjectIds(columns, RELATIONSHIP_HIVE_TABLE_COLUMNS));
            }
            context.putEntity(tblQualifiedName, ret);
        }
    }
    return ret;
}
Also used : PreprocessAction(org.apache.atlas.hive.hook.HiveHook.PreprocessAction) AtlasRelatedObjectId(org.apache.atlas.model.instance.AtlasRelatedObjectId) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId)

Example 74 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class DropDatabase method getNotificationMessages.

@Override
public List<HookNotification> getNotificationMessages() {
    List<HookNotification> ret = null;
    List<AtlasObjectId> entities = context.isMetastoreHook() ? getHiveMetastoreEntities() : getHiveEntities();
    if (CollectionUtils.isNotEmpty(entities)) {
        ret = new ArrayList<>(entities.size());
        for (AtlasObjectId entity : entities) {
            ret.add(new EntityDeleteRequestV2(getUserName(), Collections.singletonList(entity)));
        }
    }
    return ret;
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) EntityDeleteRequestV2(org.apache.atlas.model.notification.HookNotification.EntityDeleteRequestV2)

Example 75 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class DropDatabase method getHiveMetastoreEntities.

private List<AtlasObjectId> getHiveMetastoreEntities() {
    List<AtlasObjectId> ret = new ArrayList<>();
    DropDatabaseEvent dbEvent = (DropDatabaseEvent) context.getMetastoreEvent();
    String dbQName = getQualifiedName(dbEvent.getDatabase());
    AtlasObjectId dbId = new AtlasObjectId(HIVE_TYPE_DB, ATTRIBUTE_QUALIFIED_NAME, dbQName);
    context.removeFromKnownDatabase(dbQName);
    ret.add(dbId);
    return ret;
}
Also used : ArrayList(java.util.ArrayList) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) DropDatabaseEvent(org.apache.hadoop.hive.metastore.events.DropDatabaseEvent)

Aggregations

AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)255 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)124 Test (org.testng.annotations.Test)70 ArrayList (java.util.ArrayList)69 Map (java.util.Map)47 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)44 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)41 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)41 HashMap (java.util.HashMap)40 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)38 List (java.util.List)36 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)33 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)32 BeforeTest (org.testng.annotations.BeforeTest)32 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)29 AtlasTypeUtil.getAtlasObjectId (org.apache.atlas.type.AtlasTypeUtil.getAtlasObjectId)24 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)22 AtlasExportRequest (org.apache.atlas.model.impexp.AtlasExportRequest)14 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)13 AtlasType (org.apache.atlas.type.AtlasType)11