Search in sources :

Example 1 with AtlasEntityType

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

the class AtlasEntityStoreV1 method preCreateOrUpdate.

private EntityMutationContext preCreateOrUpdate(EntityStream entityStream, EntityGraphMapper entityGraphMapper, boolean isPartialUpdate) throws AtlasBaseException {
    EntityGraphDiscovery graphDiscoverer = new AtlasEntityGraphDiscoveryV1(typeRegistry, entityStream);
    EntityGraphDiscoveryContext discoveryContext = graphDiscoverer.discoverEntities();
    EntityMutationContext context = new EntityMutationContext(discoveryContext);
    for (String guid : discoveryContext.getReferencedGuids()) {
        AtlasVertex vertex = discoveryContext.getResolvedEntityVertex(guid);
        AtlasEntity entity = entityStream.getByGuid(guid);
        if (entity != null) {
            if (vertex != null) {
                // entity would be null if guid is not in the stream but referenced by an entity in the stream
                if (!isPartialUpdate) {
                    graphDiscoverer.validateAndNormalize(entity);
                } else {
                    graphDiscoverer.validateAndNormalizeForUpdate(entity);
                }
                AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName());
                String guidVertex = AtlasGraphUtilsV1.getIdFromVertex(vertex);
                if (!StringUtils.equals(guidVertex, guid)) {
                    // if entity was found by unique attribute
                    entity.setGuid(guidVertex);
                }
                context.addUpdated(guid, entity, entityType, vertex);
            } else {
                graphDiscoverer.validateAndNormalize(entity);
                AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName());
                //Create vertices which do not exist in the repository
                if ((entityStream instanceof EntityImportStream) && AtlasTypeUtil.isAssignedGuid(entity.getGuid())) {
                    vertex = entityGraphMapper.createVertexWithGuid(entity, entity.getGuid());
                } else {
                    vertex = entityGraphMapper.createVertex(entity);
                }
                discoveryContext.addResolvedGuid(guid, vertex);
                String generatedGuid = AtlasGraphUtilsV1.getIdFromVertex(vertex);
                entity.setGuid(generatedGuid);
                context.addCreated(guid, entity, entityType, vertex);
            }
            // during import, update the system attributes
            if (entityStream instanceof EntityImportStream) {
                entityGraphMapper.updateSystemAttributes(vertex, entity);
            }
        }
    }
    return context;
}
Also used : EntityGraphDiscovery(org.apache.atlas.repository.store.graph.EntityGraphDiscovery) EntityGraphDiscoveryContext(org.apache.atlas.repository.store.graph.EntityGraphDiscoveryContext) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 2 with AtlasEntityType

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

the class AtlasEntityGraphDiscoveryV1 method validateAndNormalizeForUpdate.

@Override
public void validateAndNormalizeForUpdate(AtlasEntity entity) throws AtlasBaseException {
    List<String> messages = new ArrayList<>();
    if (!AtlasTypeUtil.isValidGuid(entity.getGuid())) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, "invalid guid " + entity.getGuid());
    }
    AtlasEntityType type = typeRegistry.getEntityTypeByName(entity.getTypeName());
    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), entity.getTypeName());
    }
    type.validateValueForUpdate(entity, entity.getTypeName(), messages);
    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS, messages);
    }
    type.getNormalizedValueForUpdate(entity);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ArrayList(java.util.ArrayList) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 3 with AtlasEntityType

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

the class RestUtilsTest method convertV2toV1.

private List<HierarchicalTypeDefinition<ClassType>> convertV2toV1(List<AtlasEntityDef> toConvert) throws AtlasBaseException {
    AtlasTypeRegistry reg = createRegistry(toConvert);
    List<HierarchicalTypeDefinition<ClassType>> result = new ArrayList<>(toConvert.size());
    for (int i = 0; i < toConvert.size(); i++) {
        AtlasEntityDef entityDef = toConvert.get(i);
        AtlasEntityType entity = reg.getEntityTypeByName(entityDef.getName());
        HierarchicalTypeDefinition<ClassType> converted = TypeConverterUtil.toTypesDef(entity, reg).classTypesAsJavaList().get(0);
        result.add(converted);
    }
    return result;
}
Also used : HierarchicalTypeDefinition(org.apache.atlas.typesystem.types.HierarchicalTypeDefinition) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) ArrayList(java.util.ArrayList) ClassType(org.apache.atlas.typesystem.types.ClassType) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 4 with AtlasEntityType

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

the class EntityREST method getByUniqueAttributes.

/**
     * Fetch complete definition of an entity given its type and unique attribute.
     * @param typeName
     * @return AtlasEntityWithExtInfo
     * @throws AtlasBaseException
     */
@GET
@Path("/uniqueAttribute/type/{typeName}")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEntityWithExtInfo getByUniqueAttributes(@PathParam("typeName") String typeName, @Context HttpServletRequest servletRequest) throws AtlasBaseException {
    AtlasPerfTracer perf = null;
    try {
        Map<String, Object> attributes = getAttributes(servletRequest);
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.getByUniqueAttributes(" + typeName + "," + attributes + ")");
        }
        AtlasEntityType entityType = ensureEntityType(typeName);
        validateUniqueAttribute(entityType, attributes);
        return entitiesStore.getByUniqueAttributes(entityType, attributes);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with AtlasEntityType

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

the class EntityREST method deleteByUniqueAttribute.

/**
     * Delete an entity identified by its type and unique attributes.
     * @param  typeName - entity type to be deleted
     * @param  servletRequest - request containing unique attributes/values
     * @return EntityMutationResponse
     */
@DELETE
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
@Path("/uniqueAttribute/type/{typeName}")
public EntityMutationResponse deleteByUniqueAttribute(@PathParam("typeName") String typeName, @Context HttpServletRequest servletRequest) throws AtlasBaseException {
    AtlasPerfTracer perf = null;
    try {
        Map<String, Object> attributes = getAttributes(servletRequest);
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.deleteByUniqueAttribute(" + typeName + "," + attributes + ")");
        }
        AtlasEntityType entityType = ensureEntityType(typeName);
        return entitiesStore.deleteByUniqueAttributes(entityType, attributes);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

AtlasEntityType (org.apache.atlas.type.AtlasEntityType)45 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)18 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)16 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)10 Test (org.testng.annotations.Test)10 ArrayList (java.util.ArrayList)8 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)8 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)7 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)6 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)6 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)6 AtlasType (org.apache.atlas.type.AtlasType)6 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)5 AtlasStructType (org.apache.atlas.type.AtlasStructType)5 HashMap (java.util.HashMap)4 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)4 List (java.util.List)3 Map (java.util.Map)3 Consumes (javax.ws.rs.Consumes)3