Search in sources :

Example 31 with AtlasType

use of org.apache.atlas.type.AtlasType in project atlas by apache.

the class NotificationHookConsumerTest method setup.

@BeforeMethod
public void setup() throws AtlasBaseException {
    MockitoAnnotations.initMocks(this);
    AtlasType mockType = mock(AtlasType.class);
    AtlasEntitiesWithExtInfo mockEntity = mock(AtlasEntitiesWithExtInfo.class);
    when(typeRegistry.getType(anyString())).thenReturn(mockType);
    when(instanceConverter.toAtlasEntities(anyList())).thenReturn(mockEntity);
    EntityMutationResponse mutationResponse = mock(EntityMutationResponse.class);
    when(atlasEntityStore.createOrUpdate(any(EntityStream.class), anyBoolean())).thenReturn(mutationResponse);
}
Also used : EntityStream(org.apache.atlas.repository.store.graph.v1.EntityStream) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasType(org.apache.atlas.type.AtlasType) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 32 with AtlasType

use of org.apache.atlas.type.AtlasType in project atlas by apache.

the class NotificationHookConsumerKafkaTest method setup.

@BeforeTest
public void setup() throws AtlasException, InterruptedException, AtlasBaseException {
    MockitoAnnotations.initMocks(this);
    AtlasType mockType = mock(AtlasType.class);
    AtlasEntitiesWithExtInfo mockEntity = mock(AtlasEntitiesWithExtInfo.class);
    when(typeRegistry.getType(anyString())).thenReturn(mockType);
    when(instanceConverter.toAtlasEntities(anyList())).thenReturn(mockEntity);
    initNotificationService();
}
Also used : AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) AtlasType(org.apache.atlas.type.AtlasType) BeforeTest(org.testng.annotations.BeforeTest)

Example 33 with AtlasType

use of org.apache.atlas.type.AtlasType in project incubator-atlas by apache.

the class EntityGraphMapper method mapObjectIdValueUsingRelationship.

private AtlasEdge mapObjectIdValueUsingRelationship(AttributeMutationContext ctx, EntityMutationContext context) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> mapObjectIdValueUsingRelationship({})", ctx);
    }
    AtlasVertex attributeVertex = context.getDiscoveryContext().getResolvedEntityVertex(getGuid(ctx.getValue()));
    AtlasVertex entityVertex = ctx.getReferringVertex();
    AtlasEdge ret;
    if (attributeVertex == null) {
        AtlasObjectId objectId = getObjectId(ctx.getValue());
        attributeVertex = (objectId != null) ? context.getDiscoveryContext().getResolvedEntityVertex(objectId) : null;
    }
    if (attributeVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, (ctx.getValue() == null ? null : ctx.getValue().toString()));
    }
    String attributeName = ctx.getAttribute().getName();
    AtlasType type = typeRegistry.getType(AtlasGraphUtilsV1.getTypeName(entityVertex));
    AtlasRelationshipEdgeDirection edgeDirection = ctx.getAttribute().getRelationshipEdgeDirection();
    String edgeLabel = ctx.getAttribute().getRelationshipEdgeLabel();
    if (type instanceof AtlasEntityType) {
        AtlasEntityType entityType = (AtlasEntityType) type;
        // use relationship to create/update edges
        if (entityType.hasRelationshipAttribute(attributeName)) {
            if (ctx.getCurrentEdge() != null) {
                ret = updateRelationship(ctx.getCurrentEdge(), attributeVertex, edgeDirection, ctx.getAttribute());
                recordEntityUpdate(attributeVertex);
            } else {
                String relationshipName = graphHelper.getRelationshipDefName(entityVertex, entityType, attributeName);
                AtlasVertex fromVertex;
                AtlasVertex toVertex;
                if (edgeDirection == IN) {
                    fromVertex = attributeVertex;
                    toVertex = entityVertex;
                } else {
                    fromVertex = entityVertex;
                    toVertex = attributeVertex;
                }
                boolean relationshipExists = isRelationshipExists(fromVertex, toVertex, edgeLabel);
                ret = getOrCreateRelationship(fromVertex, toVertex, relationshipName, ctx.getAttribute());
                // record entity update on both relationship vertices
                if (!relationshipExists) {
                    recordEntityUpdate(attributeVertex);
                }
            }
        } else {
            // use legacy way to create/update edges
            if (LOG.isDebugEnabled()) {
                LOG.debug("No RelationshipDef defined between {} and {} on attribute: {}", getTypeName(entityVertex), getTypeName(attributeVertex), attributeName);
            }
            ret = mapObjectIdValue(ctx, context);
        }
    } else {
        // if type is StructType having objectid as attribute
        ret = mapObjectIdValue(ctx, context);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== mapObjectIdValueUsingRelationship({})", ctx);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasRelationshipEdgeDirection(org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasType(org.apache.atlas.type.AtlasType) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 34 with AtlasType

use of org.apache.atlas.type.AtlasType in project incubator-atlas by apache.

the class AtlasStructDefStoreV1 method updateByGuid.

@Override
public AtlasStructDef updateByGuid(String guid, AtlasStructDef structDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasStructDefStoreV1.updateByGuid({})", guid);
    }
    validateType(structDef);
    AtlasType type = typeRegistry.getTypeByGuid(guid);
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.STRUCT) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, structDef.getName(), TypeCategory.STRUCT.name());
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.STRUCT);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
    }
    AtlasStructDefStoreV1.updateVertexPreUpdate(structDef, (AtlasStructType) type, vertex, typeDefStore);
    AtlasStructDefStoreV1.updateVertexAddReferences(structDef, vertex, typeDefStore);
    AtlasStructDef ret = toStructDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasStructDefStoreV1.updateByGuid({}): {}", guid, ret);
    }
    return ret;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasType(org.apache.atlas.type.AtlasType)

Example 35 with AtlasType

use of org.apache.atlas.type.AtlasType in project incubator-atlas by apache.

the class EntityGraphMapper method mapAttribute.

private void mapAttribute(AtlasAttribute attribute, Object attrValue, AtlasVertex vertex, EntityOperation op, EntityMutationContext context) throws AtlasBaseException {
    if (attrValue == null) {
        AtlasAttributeDef attributeDef = attribute.getAttributeDef();
        AtlasType attrType = attribute.getAttributeType();
        if (attrType.getTypeCategory() == TypeCategory.PRIMITIVE) {
            if (attributeDef.getDefaultValue() != null) {
                attrValue = attrType.createDefaultValue(attributeDef.getDefaultValue());
            } else {
                if (attribute.getAttributeDef().getIsOptional()) {
                    attrValue = attrType.createOptionalDefaultValue();
                } else {
                    attrValue = attrType.createDefaultValue();
                }
            }
        }
    }
    AttributeMutationContext ctx = new AttributeMutationContext(op, vertex, attribute, attrValue);
    mapToVertexByTypeCategory(ctx, context);
}
Also used : AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasType(org.apache.atlas.type.AtlasType)

Aggregations

AtlasType (org.apache.atlas.type.AtlasType)95 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)51 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)33 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)23 AtlasArrayType (org.apache.atlas.type.AtlasArrayType)17 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)17 AtlasStructType (org.apache.atlas.type.AtlasStructType)16 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)15 AtlasMapType (org.apache.atlas.type.AtlasMapType)13 ArrayList (java.util.ArrayList)11 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)9 HashMap (java.util.HashMap)8 AtlasTypeAccessRequest (org.apache.atlas.authorize.AtlasTypeAccessRequest)8 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)8 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)8 Map (java.util.Map)7 List (java.util.List)6 Collection (java.util.Collection)5 LinkedHashSet (java.util.LinkedHashSet)5 Set (java.util.Set)4