Search in sources :

Example 36 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class AtlasEntityGraphDiscoveryV1 method discover.

protected void discover() throws AtlasBaseException {
    EntityStream entityStream = discoveryContext.getEntityStream();
    Set<String> walkedEntities = new HashSet<>();
    // walk through top-level entities and find entity references
    while (entityStream.hasNext()) {
        AtlasEntity entity = entityStream.next();
        if (entity == null) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "found null entity");
        }
        walkEntityGraph(entity);
        walkedEntities.add(entity.getGuid());
    }
    // walk through entities referenced by other entities
    // referencedGuids will be updated within this for() loop; avoid use of iterators
    List<String> referencedGuids = discoveryContext.getReferencedGuids();
    for (int i = 0; i < referencedGuids.size(); i++) {
        String guid = referencedGuids.get(i);
        if (walkedEntities.contains(guid)) {
            continue;
        }
        AtlasEntity entity = entityStream.getByGuid(guid);
        if (entity != null) {
            walkEntityGraph(entity);
            walkedEntities.add(entity.getGuid());
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) HashSet(java.util.HashSet)

Example 37 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project 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 38 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class AtlasEnumDefStoreV1 method updateByGuid.

@Override
public AtlasEnumDef updateByGuid(String guid, AtlasEnumDef enumDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasEnumDefStoreV1.updateByGuid({})", guid);
    }
    AtlasEnumDef existingDef = typeRegistry.getEnumDefByGuid(guid);
    AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update enum-def ", (existingDef != null ? existingDef.getName() : guid));
    validateType(enumDef);
    AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.ENUM);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
    }
    typeDefStore.updateTypeVertex(enumDef, vertex);
    toVertex(enumDef, vertex);
    AtlasEnumDef ret = toEnumDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasEnumDefStoreV1.updateByGuid({}): {}", guid, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasTypeAccessRequest(org.apache.atlas.authorize.AtlasTypeAccessRequest) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Example 39 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class AtlasEnumDefStoreV1 method preDeleteByName.

@Override
public AtlasVertex preDeleteByName(String name) throws AtlasBaseException {
    AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.ENUM);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
    }
    AtlasEnumDef existingDef = typeRegistry.getEnumDefByName(name);
    AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_DELETE, existingDef), "delete enum-def ", (existingDef != null ? existingDef.getName() : name));
    return vertex;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasTypeAccessRequest(org.apache.atlas.authorize.AtlasTypeAccessRequest) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Example 40 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class AtlasRelationshipDefStoreV1 method updateByName.

@Override
public AtlasRelationshipDef updateByName(String name, AtlasRelationshipDef relationshipDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasRelationshipDefStoreV1.updateByName({}, {})", name, relationshipDef);
    }
    AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByName(name);
    AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update relationship-def ", name);
    validateType(relationshipDef);
    AtlasType type = typeRegistry.getType(relationshipDef.getName());
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name());
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.RELATIONSHIP);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
    }
    preUpdateCheck(relationshipDef, (AtlasRelationshipType) type, vertex);
    AtlasRelationshipDef ret = toRelationshipDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasRelationshipDefStoreV1.updateByName({}, {}): {}", name, relationshipDef, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasTypeAccessRequest(org.apache.atlas.authorize.AtlasTypeAccessRequest) AtlasType(org.apache.atlas.type.AtlasType)

Aggregations

AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)437 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)129 Test (org.testng.annotations.Test)60 ArrayList (java.util.ArrayList)59 AtlasType (org.apache.atlas.type.AtlasType)51 AtlasException (org.apache.atlas.AtlasException)50 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)48 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)45 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)43 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)36 HashMap (java.util.HashMap)34 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)33 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)31 Produces (javax.ws.rs.Produces)29 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)29 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)29 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)26 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)26 Path (javax.ws.rs.Path)25 Map (java.util.Map)24