Search in sources :

Example 11 with EntityNotFoundException

use of org.apache.atlas.typesystem.exception.EntityNotFoundException in project incubator-atlas by apache.

the class DataSetLineageResource method outputsGraph.

/**
 * Returns the outputs graph for a given entity.
 *
 * @param tableName table name
 */
@GET
@Path("table/{tableName}/outputs/graph")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response outputsGraph(@Context HttpServletRequest request, @PathParam("tableName") String tableName) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> DataSetLineageResource.outputsGraph({})", tableName);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataSetLineageResource.outputsGraph(tableName=" + tableName + ")");
        }
        final String jsonResult = lineageService.getOutputsGraph(tableName);
        JSONObject response = new JSONObject();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put("tableName", tableName);
        response.put(AtlasClient.RESULTS, new JSONObject(jsonResult));
        return Response.ok(response).build();
    } catch (EntityNotFoundException e) {
        LOG.error("table entity not found for {}", tableName);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
    } catch (DiscoveryException | IllegalArgumentException e) {
        LOG.error("Unable to get lineage outputs graph for table {}", tableName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get lineage outputs graph for table {}", tableName, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get lineage outputs graph for table {}", tableName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) DiscoveryException(org.apache.atlas.discovery.DiscoveryException)

Example 12 with EntityNotFoundException

use of org.apache.atlas.typesystem.exception.EntityNotFoundException in project incubator-atlas by apache.

the class DataSetLineageResource method inputsGraph.

/**
 * Returns the inputs graph for a given entity.
 *
 * @param tableName table name
 */
@GET
@Path("table/{tableName}/inputs/graph")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response inputsGraph(@Context HttpServletRequest request, @PathParam("tableName") String tableName) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> DataSetLineageResource.inputsGraph({})", tableName);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataSetLineageResource.inputsGraph(tableName=" + tableName + ")");
        }
        final String jsonResult = lineageService.getInputsGraph(tableName);
        JSONObject response = new JSONObject();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put("tableName", tableName);
        response.put(AtlasClient.RESULTS, new JSONObject(jsonResult));
        return Response.ok(response).build();
    } catch (EntityNotFoundException e) {
        LOG.error("table entity not found for {}", tableName);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
    } catch (DiscoveryException | IllegalArgumentException e) {
        LOG.error("Unable to get lineage inputs graph for table {}", tableName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get lineage inputs graph for table {}", tableName, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get lineage inputs graph for table {}", tableName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) DiscoveryException(org.apache.atlas.discovery.DiscoveryException)

Example 13 with EntityNotFoundException

use of org.apache.atlas.typesystem.exception.EntityNotFoundException in project incubator-atlas by apache.

the class GraphHelper method findVertex.

/**
     * Args of the format prop1, key1, prop2, key2...
     * Searches for a AtlasVertex with prop1=key1 && prop2=key2
     * @param args
     * @return AtlasVertex with the given property keys
     * @throws EntityNotFoundException
     */
public AtlasVertex findVertex(Object... args) throws EntityNotFoundException {
    AtlasGraphQuery query = graph.query();
    for (int i = 0; i < args.length; i += 2) {
        query = query.has((String) args[i], args[i + 1]);
    }
    Iterator<AtlasVertex> results = query.vertices().iterator();
    // returning one since entityType, qualifiedName should be unique
    AtlasVertex vertex = results.hasNext() ? results.next() : null;
    if (vertex == null) {
        String conditionStr = getConditionString(args);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Could not find a vertex with {}", conditionStr);
        }
        throw new EntityNotFoundException("Could not find an entity in the repository with " + conditionStr);
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Found a vertex {} with {}", string(vertex), getConditionString(args));
        }
    }
    return vertex;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException)

Example 14 with EntityNotFoundException

use of org.apache.atlas.typesystem.exception.EntityNotFoundException in project incubator-atlas by apache.

the class DataSetLineageServiceTest method testLineageWithDelete.

@Test(enabled = false)
public void testLineageWithDelete() throws Exception {
    String tableName = "table" + random();
    createTable(tableName, 3, true);
    String tableId = getEntityId(HIVE_TABLE_TYPE, "name", tableName);
    JSONObject results = getSchema(tableName);
    assertEquals(results.getJSONArray("rows").length(), 3);
    results = getInputsGraph(tableName);
    Struct resultInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
    Map<String, Struct> vertices = (Map) resultInstance.get("vertices");
    assertEquals(vertices.size(), 2);
    Struct vertex = vertices.get(tableId);
    assertEquals(((Struct) vertex.get("vertexId")).get("state"), Id.EntityState.ACTIVE.name());
    results = getOutputsGraph(tableName);
    assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 2);
    results = new JSONObject(lineageService.getSchemaForEntity(tableId));
    assertEquals(results.getJSONArray("rows").length(), 3);
    results = new JSONObject(lineageService.getInputsGraphForEntity(tableId));
    assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 2);
    results = new JSONObject(lineageService.getOutputsGraphForEntity(tableId));
    assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 2);
    // Delete the entity. Lineage for entity returns the same results as before.
    // Lineage for table name throws EntityNotFoundException
    EntityResult deleteResult = repository.deleteEntities(Arrays.asList(tableId));
    assertTrue(deleteResult.getDeletedEntities().contains(tableId));
    results = new JSONObject(lineageService.getSchemaForEntity(tableId));
    assertEquals(results.getJSONArray("rows").length(), 3);
    results = new JSONObject(lineageService.getInputsGraphForEntity(tableId));
    resultInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
    vertices = (Map) resultInstance.get("vertices");
    assertEquals(vertices.size(), 2);
    vertex = vertices.get(tableId);
    assertEquals(((Struct) vertex.get("vertexId")).get("state"), Id.EntityState.DELETED.name());
    assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 2);
    results = new JSONObject(lineageService.getOutputsGraphForEntity(tableId));
    assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 2);
    try {
        getSchema(tableName);
        fail("Expected EntityNotFoundException");
    } catch (EntityNotFoundException e) {
    // expected
    }
    try {
        getInputsGraph(tableName);
        fail("Expected EntityNotFoundException");
    } catch (EntityNotFoundException e) {
    // expected
    }
    try {
        getOutputsGraph(tableName);
        fail("Expected EntityNotFoundException");
    } catch (EntityNotFoundException e) {
    // expected
    }
    // Create table again should show new lineage
    createTable(tableName, 2, false);
    results = getSchema(tableName);
    assertEquals(results.getJSONArray("rows").length(), 2);
    results = getOutputsGraph(tableName);
    assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 0);
    results = getInputsGraph(tableName);
    assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 0);
    tableId = getEntityId(HIVE_TABLE_TYPE, "name", tableName);
    results = new JSONObject(lineageService.getSchemaForEntity(tableId));
    assertEquals(results.getJSONArray("rows").length(), 2);
    results = new JSONObject(lineageService.getInputsGraphForEntity(tableId));
    assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 0);
    results = new JSONObject(lineageService.getOutputsGraphForEntity(tableId));
    assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 0);
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) EntityResult(org.apache.atlas.model.legacy.EntityResult) Map(java.util.Map) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test) BaseRepositoryTest(org.apache.atlas.BaseRepositoryTest)

Example 15 with EntityNotFoundException

use of org.apache.atlas.typesystem.exception.EntityNotFoundException in project incubator-atlas by apache.

the class GraphBackedMetadataRepository method deleteTrait.

/**
 * Deletes a given trait from an existing entity represented by a guid.
 *
 * @param guid      globally unique identifier for the entity
 * @param traitNameToBeDeleted name of the trait
 * @throws RepositoryException
 */
@Override
@GraphTransaction
public void deleteTrait(String guid, String traitNameToBeDeleted) throws TraitNotFoundException, EntityNotFoundException, RepositoryException {
    LOG.debug("Deleting trait={} from entity={}", traitNameToBeDeleted, guid);
    GraphTransactionInterceptor.lockObjectAndReleasePostCommit(guid);
    AtlasVertex instanceVertex = graphHelper.getVertexForGUID(guid);
    List<String> traitNames = GraphHelper.getTraitNames(instanceVertex);
    if (!traitNames.contains(traitNameToBeDeleted)) {
        throw new TraitNotFoundException("Could not find trait=" + traitNameToBeDeleted + " in the repository for entity: " + guid);
    }
    try {
        final String entityTypeName = GraphHelper.getTypeName(instanceVertex);
        String relationshipLabel = GraphHelper.getTraitLabel(entityTypeName, traitNameToBeDeleted);
        AtlasEdge edge = graphHelper.getEdgeForLabel(instanceVertex, relationshipLabel);
        if (edge != null) {
            deleteHandler.deleteEdgeReference(edge, DataTypes.TypeCategory.TRAIT, false, true);
        }
        // update the traits in entity once trait removal is successful
        traitNames.remove(traitNameToBeDeleted);
        updateTraits(instanceVertex, traitNames);
    } catch (Exception e) {
        throw new RepositoryException(e);
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) TraitNotFoundException(org.apache.atlas.typesystem.exception.TraitNotFoundException) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) RepositoryException(org.apache.atlas.repository.RepositoryException) TraitNotFoundException(org.apache.atlas.typesystem.exception.TraitNotFoundException) EntityExistsException(org.apache.atlas.typesystem.exception.EntityExistsException) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) AtlasException(org.apache.atlas.AtlasException) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Aggregations

EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)21 JSONObject (org.codehaus.jettison.json.JSONObject)10 AtlasException (org.apache.atlas.AtlasException)8 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)7 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)6 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)5 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)5 HashMap (java.util.HashMap)4 DiscoveryException (org.apache.atlas.discovery.DiscoveryException)4 Referenceable (org.apache.atlas.typesystem.Referenceable)4 Test (org.testng.annotations.Test)4 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)3 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)3 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)3 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)3 Id (org.apache.atlas.typesystem.persistence.Id)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)2 EntityResult (org.apache.atlas.model.legacy.EntityResult)2