Search in sources :

Example 1 with EntityNotFoundException

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

the class DefaultTypeSystem method deleteEntity.

@Override
public void deleteEntity(ResourceDefinition definition, Request request) throws ResourceNotFoundException {
    String typeName = definition.getTypeName();
    String cleanIdPropName = definition.getIdPropertyName();
    String idValue = request.getProperty(cleanIdPropName);
    try {
        // transaction handled by atlas repository
        metadataService.deleteEntityByUniqueAttribute(typeName, cleanIdPropName, idValue);
    } catch (EntityNotFoundException e) {
        throw new ResourceNotFoundException(String.format("The specified entity doesn't exist: type=%s, %s=%s", typeName, cleanIdPropName, idValue));
    } catch (AtlasException e) {
        throw new CatalogRuntimeException(String.format("An unexpected error occurred while attempting to delete entity: type=%s, %s=%s : %s", typeName, cleanIdPropName, idValue, e), e);
    }
}
Also used : CatalogRuntimeException(org.apache.atlas.catalog.exception.CatalogRuntimeException) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) ResourceNotFoundException(org.apache.atlas.catalog.exception.ResourceNotFoundException) AtlasException(org.apache.atlas.AtlasException)

Example 2 with EntityNotFoundException

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

the class DefaultMetadataServiceTest method testGetEntityByUniqueAttribute.

@Test
public void testGetEntityByUniqueAttribute() throws Exception {
    Referenceable entity = createDBEntity();
    TestUtils.createInstance(metadataService, entity);
    // get entity by valid qualified name
    String entityJson = metadataService.getEntityDefinition(TestUtils.DATABASE_TYPE, NAME, (String) entity.get(NAME));
    Assert.assertNotNull(entityJson);
    Referenceable referenceable = InstanceSerialization.fromJsonReferenceable(entityJson, true);
    assertEquals(referenceable.get(NAME), entity.get(NAME));
    // get entity by invalid qualified name
    try {
        metadataService.getEntityDefinition(TestUtils.DATABASE_TYPE, NAME, "random");
        Assert.fail("Expected EntityNotFoundException");
    } catch (EntityNotFoundException e) {
    // expected
    }
    // get entity by non-unique attribute
    try {
        metadataService.getEntityDefinition(TestUtils.DATABASE_TYPE, "description", (String) entity.get("description"));
        Assert.fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 3 with EntityNotFoundException

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

the class AtlasRelationshipStoreV1 method getById.

@Override
@GraphTransaction
public AtlasRelationship getById(String guid) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> getById({})", guid);
    }
    AtlasRelationship ret;
    try {
        AtlasEdge edge = graphHelper.getEdgeForGUID(guid);
        ret = mapEdgeToAtlasRelationship(edge);
    } catch (EntityNotFoundException ex) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_GUID_NOT_FOUND, guid);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== getById({}): {}", guid, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) AtlasRelationship(org.apache.atlas.model.instance.AtlasRelationship) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 4 with EntityNotFoundException

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

the class GraphBackedMetadataRepository method getEntityDefinitions.

@Override
@GraphTransaction
public List<ITypedReferenceableInstance> getEntityDefinitions(String... guids) throws RepositoryException, EntityNotFoundException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Retrieving entities with guids={}", Arrays.toString(guids));
    }
    RequestContext context = RequestContext.get();
    ITypedReferenceableInstance[] result = new ITypedReferenceableInstance[guids.length];
    // Map of the guids of instances not in the cache to their index(es) in the result.
    // This is used to put the loaded instances into the location(s) corresponding
    // to their guid in the result.  Note that a set is needed since guids can
    // appear more than once in the list.
    Map<String, Set<Integer>> uncachedGuids = new HashMap<>();
    for (int i = 0; i < guids.length; i++) {
        String guid = guids[i];
        // First, check the cache.
        ITypedReferenceableInstance cached = context.getInstanceV1(guid);
        if (cached != null) {
            result[i] = cached;
        } else {
            Set<Integer> indices = uncachedGuids.get(guid);
            if (indices == null) {
                indices = new HashSet<>(1);
                uncachedGuids.put(guid, indices);
            }
            indices.add(i);
        }
    }
    List<String> guidsToFetch = new ArrayList<>(uncachedGuids.keySet());
    Map<String, AtlasVertex> instanceVertices = graphHelper.getVerticesForGUIDs(guidsToFetch);
    // search for missing entities
    if (instanceVertices.size() != guidsToFetch.size()) {
        Set<String> missingGuids = new HashSet<String>(guidsToFetch);
        missingGuids.removeAll(instanceVertices.keySet());
        if (!missingGuids.isEmpty()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Failed to find guids={}", missingGuids);
            }
            throw new EntityNotFoundException("Could not find entities in the repository with guids: " + missingGuids.toString());
        }
    }
    for (String guid : guidsToFetch) {
        try {
            ITypedReferenceableInstance entity = graphToInstanceMapper.mapGraphToTypedInstance(guid, instanceVertices.get(guid));
            for (int index : uncachedGuids.get(guid)) {
                result[index] = entity;
            }
        } catch (AtlasException e) {
            throw new RepositoryException(e);
        }
    }
    return Arrays.asList(result);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ArrayList(java.util.ArrayList) RepositoryException(org.apache.atlas.repository.RepositoryException) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) AtlasException(org.apache.atlas.AtlasException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) RequestContext(org.apache.atlas.RequestContext) HashSet(java.util.HashSet) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 5 with EntityNotFoundException

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

the class GraphHelper method findElement.

private AtlasElement findElement(boolean isVertexSearch, 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<AtlasElement> results = isVertexSearch ? query.vertices().iterator() : query.edges().iterator();
    AtlasElement element = (results != null && results.hasNext()) ? results.next() : null;
    if (element == null) {
        throw new EntityNotFoundException("Could not find " + (isVertexSearch ? "vertex" : "edge") + " with condition: " + getConditionString(args));
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Found {} with condition {}", string(element), getConditionString(args));
    }
    return element;
}
Also used : AtlasElement(org.apache.atlas.repository.graphdb.AtlasElement) AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException)

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