Java Code Examples for org.apache.atlas.AtlasErrorCode#INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND
The following examples show how to use
org.apache.atlas.AtlasErrorCode#INSTANCE_BY_UNIQUE_ATTRIBUTE_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 |
/** * Adds classification to the entity identified by its type and unique attributes. * @param typeName */ @POST @Path("/uniqueAttribute/type/{typeName}/classifications") public void addClassificationsByUniqueAttribute(@PathParam("typeName") String typeName, @Context HttpServletRequest servletRequest, List<AtlasClassification> classifications) throws AtlasBaseException { Servlets.validateQueryParamLength("typeName", typeName); AtlasPerfTracer perf = null; try { if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.addClassificationsByUniqueAttribute(" + typeName + ")"); } AtlasEntityType entityType = ensureEntityType(typeName); Map<String, Object> attributes = getAttributes(servletRequest); String guid = entitiesStore.getGuidByUniqueAttributes(entityType, attributes); if (guid == null) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, typeName, attributes.toString()); } entitiesStore.addClassifications(guid, classifications); } finally { AtlasPerfTracer.log(perf); } }
Example 2
Source File: AtlasRelationshipStoreV1.java From incubator-atlas with Apache License 2.0 | 6 votes |
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 3
Source File: AtlasEntityStoreV1.java From incubator-atlas with Apache License 2.0 | 6 votes |
@Override @GraphTransaction public AtlasEntityWithExtInfo getByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> getByUniqueAttribute({}, {})", entityType.getTypeName(), uniqAttributes); } AtlasVertex entityVertex = AtlasGraphUtilsV1.getVertexByUniqueAttributes(entityType, uniqAttributes); EntityGraphRetriever entityRetriever = new EntityGraphRetriever(typeRegistry); AtlasEntityWithExtInfo ret = entityRetriever.toAtlasEntityWithExtInfo(entityVertex); if (ret == null) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, entityType.getTypeName(), uniqAttributes.toString()); } if (LOG.isDebugEnabled()) { LOG.debug("<== getByUniqueAttribute({}, {}): {}", entityType.getTypeName(), uniqAttributes, ret); } return ret; }
Example 4
Source File: AtlasEntityStoreV2.java From atlas with Apache License 2.0 | 6 votes |
@Override @GraphTransaction public AtlasEntityHeader getEntityHeaderByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> getEntityHeaderByUniqueAttributes({}, {})", entityType.getTypeName(), uniqAttributes); } AtlasVertex entityVertex = AtlasGraphUtilsV2.getVertexByUniqueAttributes(graph, entityType, uniqAttributes); EntityGraphRetriever entityRetriever = new EntityGraphRetriever(graph, typeRegistry); AtlasEntityHeader ret = entityRetriever.toAtlasEntityHeader(entityVertex); if (ret == null) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, entityType.getTypeName(), uniqAttributes.toString()); } AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ, ret), "read entity: typeName=", entityType.getTypeName(), ", uniqueAttributes=", uniqAttributes); if (LOG.isDebugEnabled()) { LOG.debug("<== getEntityHeaderByUniqueAttributes({}, {}): {}", entityType.getTypeName(), uniqAttributes, ret); } return ret; }
Example 5
Source File: AtlasEntityStoreV2.java From atlas with Apache License 2.0 | 6 votes |
@Override @GraphTransaction public AtlasEntityWithExtInfo getByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes, boolean isMinExtInfo, boolean ignoreRelationships) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> getByUniqueAttribute({}, {})", entityType.getTypeName(), uniqAttributes); } AtlasVertex entityVertex = AtlasGraphUtilsV2.getVertexByUniqueAttributes(graph, entityType, uniqAttributes); EntityGraphRetriever entityRetriever = new EntityGraphRetriever(graph, typeRegistry, ignoreRelationships); AtlasEntityWithExtInfo ret = entityRetriever.toAtlasEntityWithExtInfo(entityVertex, isMinExtInfo); if (ret == null) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, entityType.getTypeName(), uniqAttributes.toString()); } AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ, new AtlasEntityHeader(ret.getEntity())), "read entity: typeName=", entityType.getTypeName(), ", uniqueAttributes=", uniqAttributes); if (LOG.isDebugEnabled()) { LOG.debug("<== getByUniqueAttribute({}, {}): {}", entityType.getTypeName(), uniqAttributes, ret); } return ret; }
Example 6
Source File: EntityGraphRetriever.java From atlas with Apache License 2.0 | 6 votes |
public AtlasEntitiesWithExtInfo getEntitiesByUniqueAttributes(String typeName, List<Map<String, Object>> uniqueAttributesList, boolean isMinExtInfo) throws AtlasBaseException { AtlasEntitiesWithExtInfo ret = new AtlasEntitiesWithExtInfo(); AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName); if (entityType != null) { for (Map<String, Object> uniqAttributes : uniqueAttributesList) { try { AtlasVertex vertex = AtlasGraphUtilsV2.getVertexByUniqueAttributes(this.graph, entityType, uniqAttributes); if (vertex != null) { AtlasEntity entity = mapVertexToAtlasEntity(vertex, ret, isMinExtInfo); ret.addEntity(entity); } } catch(AtlasBaseException e) { if (e.getAtlasErrorCode() != AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND) { throw e; } } } } ret.compact(); return ret; }
Example 7
Source File: EntityREST.java From atlas with Apache License 2.0 | 6 votes |
@DELETE @Path("/uniqueAttribute/type/{typeName}/labels") public void removeLabels(@PathParam("typeName") String typeName, Set<String> labels, @Context HttpServletRequest servletRequest) throws AtlasBaseException { Servlets.validateQueryParamLength("typeName", typeName); AtlasPerfTracer perf = null; try { if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.removeLabels(" + typeName + ")"); } AtlasEntityType entityType = ensureEntityType(typeName); Map<String, Object> attributes = getAttributes(servletRequest); String guid = entitiesStore.getGuidByUniqueAttributes(entityType, attributes); if (guid == null) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, typeName, attributes.toString()); } entitiesStore.removeLabels(guid, labels); } finally { AtlasPerfTracer.log(perf); } }
Example 8
Source File: EntityREST.java From atlas with Apache License 2.0 | 6 votes |
@PUT @Path("/uniqueAttribute/type/{typeName}/labels") public void addLabels(@PathParam("typeName") String typeName, Set<String> labels, @Context HttpServletRequest servletRequest) throws AtlasBaseException { Servlets.validateQueryParamLength("typeName", typeName); AtlasPerfTracer perf = null; try { if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.addLabels(" + typeName + ")"); } AtlasEntityType entityType = ensureEntityType(typeName); Map<String, Object> attributes = getAttributes(servletRequest); String guid = entitiesStore.getGuidByUniqueAttributes(entityType, attributes); if (guid == null) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, typeName, attributes.toString()); } entitiesStore.addLabels(guid, labels); } finally { AtlasPerfTracer.log(perf); } }
Example 9
Source File: EntityREST.java From atlas with Apache License 2.0 | 6 votes |
@POST @Path("/uniqueAttribute/type/{typeName}/labels") public void setLabels(@PathParam("typeName") String typeName, Set<String> labels, @Context HttpServletRequest servletRequest) throws AtlasBaseException { Servlets.validateQueryParamLength("typeName", typeName); AtlasPerfTracer perf = null; try { if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.setLabels(" + typeName + ")"); } AtlasEntityType entityType = ensureEntityType(typeName); Map<String, Object> attributes = getAttributes(servletRequest); String guid = entitiesStore.getGuidByUniqueAttributes(entityType, attributes); if (guid == null) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, typeName, attributes.toString()); } entitiesStore.setLabels(guid, labels); } finally { AtlasPerfTracer.log(perf); } }
Example 10
Source File: EntityREST.java From atlas with Apache License 2.0 | 6 votes |
/** * Updates classification on an entity identified by its type and unique attributes. * @param typeName */ @PUT @Path("/uniqueAttribute/type/{typeName}/classifications") public void updateClassificationsByUniqueAttribute(@PathParam("typeName") String typeName, @Context HttpServletRequest servletRequest, List<AtlasClassification> classifications) throws AtlasBaseException { Servlets.validateQueryParamLength("typeName", typeName); AtlasPerfTracer perf = null; try { if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.updateClassificationsByUniqueAttribute(" + typeName + ")"); } AtlasEntityType entityType = ensureEntityType(typeName); Map<String, Object> attributes = getAttributes(servletRequest); String guid = entitiesStore.getGuidByUniqueAttributes(entityType, attributes); if (guid == null) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, typeName, attributes.toString()); } entitiesStore.updateClassifications(guid, classifications); } finally { AtlasPerfTracer.log(perf); } }
Example 11
Source File: AtlasGraphUtilsV2.java From atlas with Apache License 2.0 | 5 votes |
public static AtlasVertex getVertexByUniqueAttributes(AtlasGraph graph, AtlasEntityType entityType, Map<String, Object> attrValues) throws AtlasBaseException { AtlasVertex vertex = findByUniqueAttributes(graph, entityType, attrValues); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, entityType.getTypeName(), attrValues.toString()); } return vertex; }
Example 12
Source File: EntityREST.java From atlas with Apache License 2.0 | 5 votes |
/** * Deletes a given classification from an entity identified by its type and unique attributes. * @param typeName * @param classificationName name of the classification */ @DELETE @Path("/uniqueAttribute/type/{typeName}/classification/{classificationName}") public void deleteClassificationByUniqueAttribute(@PathParam("typeName") String typeName, @Context HttpServletRequest servletRequest,@PathParam("classificationName") String classificationName) throws AtlasBaseException { Servlets.validateQueryParamLength("typeName", typeName); Servlets.validateQueryParamLength("classificationName", classificationName); AtlasPerfTracer perf = null; try { if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.deleteClassificationByUniqueAttribute(" + typeName + ")"); } AtlasEntityType entityType = ensureEntityType(typeName); Map<String, Object> attributes = getAttributes(servletRequest); String guid = entitiesStore.getGuidByUniqueAttributes(entityType, attributes); if (guid == null) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, typeName, attributes.toString()); } entitiesStore.deleteClassification(guid, classificationName); } finally { AtlasPerfTracer.log(perf); } }
Example 13
Source File: AtlasEntityStoreV2.java From atlas with Apache License 2.0 | 5 votes |
@Override @GraphTransaction public EntityMutationResponse deleteByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes) throws AtlasBaseException { if (MapUtils.isEmpty(uniqAttributes)) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, uniqAttributes.toString()); } Collection<AtlasVertex> deletionCandidates = new ArrayList<>(); AtlasVertex vertex = AtlasGraphUtilsV2.findByUniqueAttributes(graph, entityType, uniqAttributes); if (vertex != null) { AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(vertex); AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_DELETE, entityHeader), "delete entity: typeName=", entityType.getTypeName(), ", uniqueAttributes=", uniqAttributes); 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 uniqueAttributes " + uniqAttributes); } } EntityMutationResponse ret = deleteVertices(deletionCandidates); // Notify the change listeners entityChangeNotifier.onEntitiesMutated(ret, false); return ret; }
Example 14
Source File: EntityResource.java From incubator-atlas with Apache License 2.0 | 5 votes |
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 15
Source File: AtlasEntityStoreV1.java From incubator-atlas with Apache License 2.0 | 5 votes |
@Override @GraphTransaction public EntityMutationResponse deleteByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes) throws AtlasBaseException { if (MapUtils.isEmpty(uniqAttributes)) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, uniqAttributes.toString()); } final AtlasVertex vertex = AtlasGraphUtilsV1.findByUniqueAttributes(entityType, uniqAttributes); Collection<AtlasVertex> deletionCandidates = new ArrayList<>(); if (vertex != null) { 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 uniqueAttributes " + uniqAttributes); } } EntityMutationResponse ret = deleteVertices(deletionCandidates); // Notify the change listeners entityChangeNotifier.onEntitiesMutated(ret, false); return ret; }
Example 16
Source File: AtlasGraphUtilsV1.java From incubator-atlas with Apache License 2.0 | 5 votes |
public static AtlasVertex getVertexByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> attrValues) throws AtlasBaseException { AtlasVertex vertex = findByUniqueAttributes(entityType, attrValues); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, entityType.getTypeName(), attrValues.toString()); } return vertex; }
Example 17
Source File: EntityResource.java From atlas with Apache License 2.0 | 5 votes |
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 18
Source File: AtlasRelationshipStoreV2.java From atlas with Apache License 2.0 | 4 votes |
/** * 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); } }