Java Code Examples for org.apache.atlas.model.instance.AtlasObjectId#getUniqueAttributes()

The following examples show how to use org.apache.atlas.model.instance.AtlasObjectId#getUniqueAttributes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityGraphRetriever.java    From atlas with Apache License 2.0 6 votes vote down vote up
private AtlasVertex getEntityVertex(AtlasObjectId objId) throws AtlasBaseException {
    AtlasVertex ret = null;

    if (! AtlasTypeUtil.isValid(objId)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, objId.toString());
    }

    if (AtlasTypeUtil.isAssignedGuid(objId)) {
        ret = AtlasGraphUtilsV2.findByGuid(this.graph, objId.getGuid());
    } else {
        AtlasEntityType     entityType     = typeRegistry.getEntityTypeByName(objId.getTypeName());
        Map<String, Object> uniqAttributes = objId.getUniqueAttributes();

        ret = AtlasGraphUtilsV2.getVertexByUniqueAttributes(this.graph, entityType, uniqAttributes);
    }

    if (ret == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, objId.toString());
    }

    return ret;
}
 
Example 2
Source File: EntityGraphRetriever.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private AtlasVertex getEntityVertex(AtlasObjectId objId) throws AtlasBaseException {
    AtlasVertex ret = null;

    if (! AtlasTypeUtil.isValid(objId)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, objId.toString());
    }

    if (AtlasTypeUtil.isAssignedGuid(objId)) {
        ret = AtlasGraphUtilsV1.findByGuid(objId.getGuid());
    } else {
        AtlasEntityType     entityType     = typeRegistry.getEntityTypeByName(objId.getTypeName());
        Map<String, Object> uniqAttributes = objId.getUniqueAttributes();

        ret = AtlasGraphUtilsV1.getVertexByUniqueAttributes(entityType, uniqAttributes);
    }

    if (ret == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, objId.toString());
    }

    return ret;
}
 
Example 3
Source File: AtlasRelationshipStoreV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private void validateEnd(AtlasObjectId end) throws AtlasBaseException {
    String              guid             = end.getGuid();
    String              typeName         = end.getTypeName();
    Map<String, Object> uniqueAttributes = end.getUniqueAttributes();
    AtlasVertex         endVertex        = AtlasGraphUtilsV1.findByGuid(guid);

    if (!AtlasTypeUtil.isValidGuid(guid) || endVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    } else if (MapUtils.isNotEmpty(uniqueAttributes))  {
        AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);

        if (AtlasGraphUtilsV1.findByUniqueAttributes(entityType, uniqueAttributes) == null) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, typeName, uniqueAttributes.toString());
        }
    }
}
 
Example 4
Source File: EntityGraphDiscoveryContext.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public AtlasVertex getResolvedEntityVertex(AtlasObjectId objId) {
    AtlasVertex vertex = resolvedIdsByUniqAttribs.get(objId);

    // check also for sub-types; ref={typeName=Asset; guid=abcd} should match {typeName=hive_table; guid=abcd}
    if (vertex == null) {
        final AtlasEntityType entityType  = typeRegistry.getEntityTypeByName(objId.getTypeName());
        final Set<String>     allSubTypes = entityType.getAllSubTypes();

        for (String subType : allSubTypes) {
            AtlasObjectId subTypeObjId = new AtlasObjectId(objId.getGuid(), subType, objId.getUniqueAttributes());

            vertex = resolvedIdsByUniqAttribs.get(subTypeObjId);

            if (vertex != null) {
                resolvedIdsByUniqAttribs.put(objId, vertex);
                break;
            }
        }
    }

    return vertex;
}
 
Example 5
Source File: EntityGraphMapper.java    From atlas with Apache License 2.0 5 votes vote down vote up
public AtlasVertex createShellEntityVertex(AtlasObjectId objectId, EntityGraphDiscoveryContext context) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> createShellEntityVertex({})", objectId.getTypeName());
    }

    final String    guid       = UUID.randomUUID().toString();
    AtlasEntityType entityType = typeRegistry.getEntityTypeByName(objectId.getTypeName());
    AtlasVertex     ret        = createStructVertex(objectId);

    for (String superTypeName : entityType.getAllSuperTypes()) {
        AtlasGraphUtilsV2.addEncodedProperty(ret, SUPER_TYPES_PROPERTY_KEY, superTypeName);
    }

    AtlasGraphUtilsV2.setEncodedProperty(ret, GUID_PROPERTY_KEY, guid);
    AtlasGraphUtilsV2.setEncodedProperty(ret, VERSION_PROPERTY_KEY, getEntityVersion(null));
    AtlasGraphUtilsV2.setEncodedProperty(ret, IS_INCOMPLETE_PROPERTY_KEY, INCOMPLETE_ENTITY_VALUE);

    // map unique attributes
    Map<String, Object>   uniqueAttributes = objectId.getUniqueAttributes();
    EntityMutationContext mutationContext  = new EntityMutationContext(context);

    for (AtlasAttribute attribute : entityType.getUniqAttributes().values()) {
        String attrName  = attribute.getName();

        if (uniqueAttributes.containsKey(attrName)) {
            Object attrValue = attribute.getAttributeType().getNormalizedValue(uniqueAttributes.get(attrName));

            mapAttribute(attribute, attrValue, ret, CREATE, mutationContext);
        }
    }

    GraphTransactionInterceptor.addToVertexCache(guid, ret);

    return ret;
}
 
Example 6
Source File: AtlasRelationshipStoreV2.java    From atlas with Apache License 2.0 4 votes vote down vote up
/**
 * Validate the ends of the passed relationship
 * @param relationship
 * @throws AtlasBaseException
 */
private void validateEnds(AtlasRelationship relationship) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("validateEnds entry relationship:" + relationship);
    }
    List<AtlasObjectId>           ends                 = new ArrayList<>();
    List<AtlasRelationshipEndDef> endDefs              = new ArrayList<>();
    String                        relationshipTypeName = relationship.getTypeName();
    AtlasRelationshipDef          relationshipDef      = typeRegistry.getRelationshipDefByName(relationshipTypeName);

    ends.add(relationship.getEnd1());
    ends.add(relationship.getEnd2());
    endDefs.add(relationshipDef.getEndDef1());
    endDefs.add(relationshipDef.getEndDef2());

    for (int i = 0; i < ends.size(); i++) {
        AtlasObjectId       end              = ends.get(i);
        String              guid             = end.getGuid();
        String              typeName         = end.getTypeName();
        Map<String, Object> uniqueAttributes = end.getUniqueAttributes();
        AtlasVertex         endVertex        = AtlasGraphUtilsV2.findByGuid(this.graph, guid);

        if (!AtlasTypeUtil.isValidGuid(guid) || endVertex == null) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);

        } else if (MapUtils.isNotEmpty(uniqueAttributes)) {
            AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);

            if (AtlasGraphUtilsV2.findByUniqueAttributes(this.graph, entityType, uniqueAttributes) == null) {
                throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, typeName, uniqueAttributes.toString());
            }
        } else {
            // check whether the guid is the correct type
            String vertexTypeName = endVertex.getProperty(Constants.TYPE_NAME_PROPERTY_KEY, String.class);

            if (!Objects.equals(vertexTypeName, typeName)) {
                String attrName = endDefs.get(i).getName();

                throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_INVALID_ENDTYPE, attrName, guid, vertexTypeName, typeName);
            }
        }
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("validateEnds exit successfully validated relationship:" + relationship);
    }
}
 
Example 7
Source File: EntityGraphMapper.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
public static AtlasEntityHeader constructHeader(AtlasObjectId id) {
    return new AtlasEntityHeader(id.getTypeName(), id.getGuid(), id.getUniqueAttributes());
}
 
Example 8
Source File: AbstractLineageStrategy.java    From nifi with Apache License 2.0 4 votes vote down vote up
private Referenceable toReferenceable(AtlasObjectId id) {
    return StringUtils.isEmpty(id.getGuid())
            ? new Referenceable(id.getTypeName(), id.getUniqueAttributes())
            : new Referenceable(id.getGuid(), id.getTypeName(), id.getUniqueAttributes());
}