Java Code Examples for org.apache.atlas.AtlasErrorCode#INSTANCE_GUID_NOT_FOUND

The following examples show how to use org.apache.atlas.AtlasErrorCode#INSTANCE_GUID_NOT_FOUND . 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: EntityREST.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Bulk API to retrieve list of entities identified by its GUIDs.
 */
@GET
@Path("/bulk")
public AtlasEntitiesWithExtInfo getByGuids(@QueryParam("guid") List<String> guids, @QueryParam("minExtInfo") @DefaultValue("false") boolean minExtInfo, @QueryParam("ignoreRelationships") @DefaultValue("false") boolean ignoreRelationships) throws AtlasBaseException {
    if (CollectionUtils.isNotEmpty(guids)) {
        for (String guid : guids) {
            Servlets.validateQueryParamLength("guid", guid);
        }
    }

    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.getByGuids(" + guids + ")");
        }

        if (CollectionUtils.isEmpty(guids)) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guids);
        }

        return entitiesStore.getByIds(guids, minExtInfo, ignoreRelationships);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example 2
Source File: AtlasEntityStoreV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
@GraphTransaction
public AtlasEntityHeader getHeaderById(final String guid) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> getHeaderById({})", guid);
    }

    EntityGraphRetriever entityRetriever = new EntityGraphRetriever(graph, typeRegistry);

    AtlasEntityHeader ret = entityRetriever.toAtlasEntityHeader(guid);

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

    AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ, ret), "read entity: guid=", guid);

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== getHeaderById({}): {}", guid, ret);
    }

    return ret;
}
 
Example 3
Source File: AtlasEntityStoreV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
@GraphTransaction
public AtlasEntityWithExtInfo getById(final String guid, final boolean isMinExtInfo, boolean ignoreRelationships) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> getById({}, {})", guid, isMinExtInfo);
    }

    EntityGraphRetriever entityRetriever = new EntityGraphRetriever(graph, typeRegistry, ignoreRelationships);

    AtlasEntityWithExtInfo ret = entityRetriever.toAtlasEntityWithExtInfo(guid, isMinExtInfo);

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

    AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ, new AtlasEntityHeader(ret.getEntity())), "read entity: guid=", guid);

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== getById({}, {}): {}", guid, isMinExtInfo, ret);
    }

    return ret;
}
 
Example 4
Source File: EntityREST.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the list of classifications for a given entity represented by a guid.
 * @param guid globally unique identifier for the entity
 * @return a list of classifications for the given entity guid
 */
@GET
@Path("/guid/{guid}/classifications")
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasClassification.AtlasClassifications getClassifications(@PathParam("guid") String guid) throws AtlasBaseException {
    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.getClassifications(" + guid + ")");
        }

        if (StringUtils.isEmpty(guid)) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }

        return new AtlasClassification.AtlasClassifications(entitiesStore.getClassifications(guid));
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example 5
Source File: EntityREST.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Bulk API to retrieve list of entities identified by its GUIDs.
 */
@GET
@Path("/bulk")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEntitiesWithExtInfo getByGuids(@QueryParam("guid") List<String> guids) throws AtlasBaseException {
    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.getByGuids(" + guids + ")");
        }

        if (CollectionUtils.isEmpty(guids)) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guids);
        }

        return entitiesStore.getByIds(guids);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example 6
Source File: EntityLineageService.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Override
@GraphTransaction
public AtlasLineageInfo getAtlasLineageInfo(String guid, LineageDirection direction, int depth) throws AtlasBaseException {
    AtlasLineageInfo lineageInfo;

    if (!entityExists(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    }

    if (direction != null) {
        if (direction.equals(LineageDirection.INPUT)) {
            lineageInfo = getLineageInfo(guid, LineageDirection.INPUT, depth);
        } else if (direction.equals(LineageDirection.OUTPUT)) {
            lineageInfo = getLineageInfo(guid, LineageDirection.OUTPUT, depth);
        } else if (direction.equals(LineageDirection.BOTH)) {
            lineageInfo = getBothLineageInfo(guid, depth);
        } else {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_LINEAGE_INVALID_PARAMS, "direction", direction.toString());
        }
    } else {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_LINEAGE_INVALID_PARAMS, "direction", null);
    }

    return lineageInfo;
}
 
Example 7
Source File: EntityREST.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes a given classification from an existing entity represented by a guid.
 * @param guid      globally unique identifier for the entity
 * @param classificationName name of the classifcation
 */
@DELETE
@Path("/guid/{guid}/classification/{classificationName}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public void deleteClassification(@PathParam("guid") String guid,
                                 @PathParam("classificationName") final String classificationName) throws AtlasBaseException {
    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.deleteClassification(" + guid + "," + classificationName + ")");
        }

        if (StringUtils.isEmpty(guid)) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }

        ensureClassificationType(classificationName);

        entitiesStore.deleteClassifications(guid, new ArrayList<String>() {{ add(classificationName);}} );
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example 8
Source File: GlossaryREST.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Get specific glossary term
 * @param termGuid unique identifier for glossary term
 * @return Glossary term
 * @throws AtlasBaseException
 * @HTTP 200 If glossary term exists for given GUID
 * @HTTP 404 If glossary term GUID is invalid
 */
@GET
@Path("/term/{termGuid}")
public AtlasGlossaryTerm getGlossaryTerm(@PathParam("termGuid") String termGuid) throws AtlasBaseException {
    Servlets.validateQueryParamLength("termGuid", termGuid);

    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.getGlossaryTerm(" + termGuid + ")");
        }
        AtlasGlossaryTerm ret = glossaryService.getTerm(termGuid);
        if (ret == null) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
        }

        return ret;
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example 9
Source File: EntityREST.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the list of classifications for a given entity represented by a guid.
 * @param guid globally unique identifier for the entity
 * @return classification for the given entity guid
 */
@GET
@Path("/guid/{guid}/classification/{classificationName}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasClassification getClassification(@PathParam("guid") String guid, @PathParam("classificationName") final String classificationName) throws AtlasBaseException {
    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.getClassification(" + guid + "," + classificationName + ")");
        }

        if (StringUtils.isEmpty(guid)) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }

        ensureClassificationType(classificationName);
        return entitiesStore.getClassification(guid, classificationName);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example 10
Source File: GlossaryREST.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Get a specific Glossary
 * @param glossaryGuid unique glossary identifier
 * @return Glossary
 * @throws AtlasBaseException
 * @HTTP 200 If glossary with given guid exists
 * @HTTP 404 If glossary GUID is invalid
 */
@GET
@Path("/{glossaryGuid}")
public AtlasGlossary getGlossary(@PathParam("glossaryGuid") String glossaryGuid) throws AtlasBaseException {
    Servlets.validateQueryParamLength("glossaryGuid", glossaryGuid);

    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.getGlossary(" + glossaryGuid + ")");
        }
        AtlasGlossary ret = glossaryService.getGlossary(glossaryGuid);

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

        return ret;
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example 11
Source File: EntityGraphMapper.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public void deleteClassifications(String guid, List<String> classificationNames) throws AtlasBaseException {

        AtlasVertex instanceVertex = AtlasGraphUtilsV1.findByGuid(guid);
        if (instanceVertex == null) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }

        List<String> traitNames = GraphHelper.getTraitNames(instanceVertex);

        validateClassificationExists(traitNames, classificationNames);

        for (String classificationName : classificationNames) {
            try {
                final String entityTypeName = getTypeName(instanceVertex);
                String relationshipLabel = GraphHelper.getTraitLabel(entityTypeName, classificationName);
                AtlasEdge edge = graphHelper.getEdgeForLabel(instanceVertex, relationshipLabel);
                if (edge != null) {
                    deleteHandler.deleteEdgeReference(edge, TypeCategory.CLASSIFICATION, false, true);

                    // update the traits in entity once trait removal is successful
                    traitNames.remove(classificationName);

                }
            } catch (Exception e) {
                throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
            }
        }

        // remove the key
        instanceVertex.removeProperty(Constants.TRAIT_NAMES_PROPERTY_KEY);

        // add it back again
        for (String traitName : traitNames) {
            GraphHelper.addProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, traitName);
        }
        updateModificationMetadata(instanceVertex);
    }
 
Example 12
Source File: AtlasEntityStoreV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
@GraphTransaction
public EntityMutationResponse deleteById(final String guid) throws AtlasBaseException {
    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    }

    Collection<AtlasVertex> deletionCandidates = new ArrayList<>();
    AtlasVertex             vertex             = AtlasGraphUtilsV2.findByGuid(graph, guid);

    if (vertex != null) {
        AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(vertex);

        AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_DELETE, entityHeader), "delete entity: guid=", guid);

        deletionCandidates.add(vertex);
    } else {
        if (LOG.isDebugEnabled()) {
            // Entity does not exist - treat as non-error, since the caller
            // wanted to delete the entity and it's already gone.
            LOG.debug("Deletion request ignored for non-existent entity with guid " + guid);
        }
    }

    EntityMutationResponse ret = deleteVertices(deletionCandidates);

    // Notify the change listeners
    entityChangeNotifier.onEntitiesMutated(ret, false);

    return ret;
}
 
Example 13
Source File: EntityLineageServiceTest.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@DataProvider(name = "invalidQueryParamsProvider")
private Object[][] params() throws Exception {
    String entityGuid = getEntityId(HIVE_TABLE_TYPE, "name", "sales_fact_monthly_mv");

    // String guid, LineageDirection direction, int depth, AtlasErrorCode errorCode

    return new Object[][]{
            {"", null, 0, AtlasErrorCode.INSTANCE_GUID_NOT_FOUND},
            {" ", null, 0, AtlasErrorCode.INSTANCE_GUID_NOT_FOUND},
            {null, null, 0, AtlasErrorCode.INSTANCE_GUID_NOT_FOUND},
            {"invalidGuid", LineageDirection.OUTPUT, 6, AtlasErrorCode.INSTANCE_GUID_NOT_FOUND},
            {entityGuid, null, -10, AtlasErrorCode.INSTANCE_LINEAGE_INVALID_PARAMS},
            {entityGuid, null, 5, AtlasErrorCode.INSTANCE_LINEAGE_INVALID_PARAMS}
    };
}
 
Example 14
Source File: EntityGraphRetriever.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private AtlasVertex getEntityVertex(String guid) throws AtlasBaseException {
    AtlasVertex ret = AtlasGraphUtilsV1.findByGuid(guid);

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

    return ret;
}
 
Example 15
Source File: EntityResource.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public static WebApplicationException toWebApplicationException(AtlasBaseException e) {
    if (e.getAtlasErrorCode() == AtlasErrorCode.CLASSIFICATION_NOT_FOUND
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_GUID_NOT_FOUND
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND) {
        return new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
    }

    if (e.getAtlasErrorCode() == AtlasErrorCode.INVALID_PARAMETERS
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS) {
        return new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    }

    return new WebApplicationException(Servlets.getErrorResponse(e, e.getAtlasErrorCode().getHttpCode()));
}
 
Example 16
Source File: EntityGraphRetriever.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public List<AtlasClassification> getClassifications(String guid) throws AtlasBaseException {

        AtlasVertex instanceVertex = AtlasGraphUtilsV1.findByGuid(guid);
        if (instanceVertex == null) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }

        return getClassifications(instanceVertex, null);
    }
 
Example 17
Source File: AtlasObjectIdConverter.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public Object fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext converterContext) throws AtlasBaseException {
    Id ret = null;

    if (v2Obj != null) {

        if (v2Obj instanceof Map) {
            Map    v2Map    = (Map) v2Obj;
            String idStr    = (String)v2Map.get(AtlasObjectId.KEY_GUID);
            String typeName = type.getTypeName();

            if (StringUtils.isEmpty(idStr)) {
                throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
            }

            ret = new Id(idStr, 0, typeName);
        } else if (v2Obj instanceof AtlasObjectId) { // transient-id
            ret = new Id(((AtlasObjectId) v2Obj).getGuid(), 0, type.getTypeName());
        } else if (v2Obj instanceof AtlasEntity) {
            AtlasEntity entity = (AtlasEntity) v2Obj;
            ret = new Id(((AtlasObjectId) v2Obj).getGuid(), 0, type.getTypeName());
        } else {
            throw new AtlasBaseException(AtlasErrorCode.TYPE_CATEGORY_INVALID, type.getTypeCategory().name());
        }
    }
    return ret;
}
 
Example 18
Source File: EntityGraphMapper.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public void updateClassification(final EntityMutationContext context, String guid, AtlasClassification classification)
                                 throws AtlasBaseException {

    AtlasVertex instanceVertex = AtlasGraphUtilsV1.findByGuid(guid);

    if (instanceVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    }

    String entityTypeName = AtlasGraphUtilsV1.getTypeName(instanceVertex);

    final AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName);

    if (LOG.isDebugEnabled()) {
        LOG.debug("Updating classification {} for entity {}", classification, guid);
    }

    // get the classification vertex from entity
    String      relationshipLabel    = GraphHelper.getTraitLabel(entityTypeName, classification.getTypeName());
    AtlasEdge   classificationEdge   = graphHelper.getEdgeForLabel(instanceVertex, relationshipLabel);

    if (classificationEdge == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "classificationEdge is null for label: " + relationshipLabel);
    }

    AtlasVertex classificationVertex = classificationEdge.getInVertex();

    if (LOG.isDebugEnabled()) {
        LOG.debug("updating vertex {} for trait {}", string(classificationVertex), classification.getTypeName());
    }

    mapClassification(EntityOperation.UPDATE, context, classification, entityType, instanceVertex, classificationVertex);
}
 
Example 19
Source File: EntityGraphMapper.java    From atlas with Apache License 2.0 5 votes vote down vote up
public void deleteClassifications(String guid) throws AtlasBaseException {
    AtlasVertex instanceVertex = AtlasGraphUtilsV2.findByGuid(this.graph, guid);

    if (instanceVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    }

    List<String> traitNames = getTraitNames(instanceVertex);

    if (CollectionUtils.isNotEmpty(traitNames)) {
        for (String traitName : traitNames) {
            deleteClassification(guid, traitName);
        }
    }
}
 
Example 20
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);
    }
}