Search in sources :

Example 16 with GraphTransaction

use of org.apache.atlas.annotation.GraphTransaction in project incubator-atlas by apache.

the class AtlasTypeDefGraphStore method updateClassificationDefByGuid.

@Override
@GraphTransaction
public AtlasClassificationDef updateClassificationDefByGuid(String guid, AtlasClassificationDef classificationDef) throws AtlasBaseException {
    AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
    tryUpdateByGUID(guid, classificationDef, ttr);
    return getClassificationDefStore(ttr).updateByGuid(guid, classificationDef);
}
Also used : AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 17 with GraphTransaction

use of org.apache.atlas.annotation.GraphTransaction in project incubator-atlas by apache.

the class AtlasTypeDefGraphStore method createTypesDef.

@Override
@GraphTransaction
public AtlasTypesDef createTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classifications={}, entities={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), CollectionUtils.size(typesDef.getEntityDefs()));
    }
    AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
    tryTypeCreation(typesDef, ttr);
    AtlasTypesDef ret = addToGraphStore(typesDef, ttr);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classfications={}, entities={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), CollectionUtils.size(typesDef.getEntityDefs()));
    }
    return ret;
}
Also used : AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 18 with GraphTransaction

use of org.apache.atlas.annotation.GraphTransaction in project incubator-atlas by apache.

the class GraphBackedMetadataRepository method deleteEntities.

@Override
@GraphTransaction
public EntityResult deleteEntities(List<String> guids) throws RepositoryException {
    if (guids == null || guids.size() == 0) {
        throw new IllegalArgumentException("guids must be non-null and non-empty");
    }
    // Retrieve vertices for requested guids.
    Map<String, AtlasVertex> vertices = graphHelper.getVerticesForGUIDs(guids);
    Collection<AtlasVertex> deletionCandidates = vertices.values();
    if (LOG.isDebugEnabled()) {
        for (String guid : guids) {
            if (!vertices.containsKey(guid)) {
                // 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);
            }
        }
    }
    if (deletionCandidates.isEmpty()) {
        LOG.info("No deletion candidate entities were found for guids %s", guids);
        return new EntityResult(Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList());
    }
    try {
        deleteHandler.deleteEntities(deletionCandidates);
    } catch (AtlasException e) {
        throw new RepositoryException(e);
    }
    RequestContext requestContext = RequestContext.get();
    return createEntityResultFromContext(requestContext);
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) RepositoryException(org.apache.atlas.repository.RepositoryException) RequestContext(org.apache.atlas.RequestContext) EntityResult(org.apache.atlas.model.legacy.EntityResult) AtlasException(org.apache.atlas.AtlasException) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 19 with GraphTransaction

use of org.apache.atlas.annotation.GraphTransaction in project incubator-atlas by apache.

the class GraphBackedMetadataRepository method getEntityDefinition.

@Override
@GraphTransaction
public ITypedReferenceableInstance getEntityDefinition(String entityType, String attribute, Object value) throws AtlasException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Retrieving entity with type={} and {}={}", entityType, attribute, value);
    }
    IDataType type = typeSystem.getDataType(IDataType.class, entityType);
    String propertyKey = getFieldNameInVertex(type, attribute);
    AtlasVertex instanceVertex = graphHelper.findVertex(propertyKey, value, Constants.ENTITY_TYPE_PROPERTY_KEY, entityType, Constants.STATE_PROPERTY_KEY, Id.EntityState.ACTIVE.name());
    String guid = GraphHelper.getGuid(instanceVertex);
    ITypedReferenceableInstance cached = RequestContext.get().getInstanceV1(guid);
    if (cached != null) {
        return cached;
    }
    return graphToInstanceMapper.mapGraphToTypedInstance(guid, instanceVertex);
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) IDataType(org.apache.atlas.typesystem.types.IDataType) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 20 with GraphTransaction

use of org.apache.atlas.annotation.GraphTransaction in project incubator-atlas by apache.

the class GraphBackedMetadataRepository method createEntities.

@Override
@GraphTransaction
public CreateUpdateEntitiesResult createEntities(ITypedReferenceableInstance... entities) throws RepositoryException, EntityExistsException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("adding entities={}", entities);
    }
    try {
        TypedInstanceToGraphMapper instanceToGraphMapper = new TypedInstanceToGraphMapper(graphToInstanceMapper, deleteHandler);
        instanceToGraphMapper.mapTypedInstanceToGraph(TypedInstanceToGraphMapper.Operation.CREATE, entities);
        List<String> createdGuids = RequestContext.get().getCreatedEntityIds();
        CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
        EntityResult entityResult = new EntityResult(createdGuids, null, null);
        GuidMapping mapping = instanceToGraphMapper.createGuidMapping();
        result.setEntityResult(entityResult);
        result.setGuidMapping(mapping);
        return result;
    } catch (EntityExistsException e) {
        throw e;
    } catch (AtlasException e) {
        throw new RepositoryException(e);
    }
}
Also used : CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) RepositoryException(org.apache.atlas.repository.RepositoryException) EntityResult(org.apache.atlas.model.legacy.EntityResult) AtlasException(org.apache.atlas.AtlasException) EntityExistsException(org.apache.atlas.typesystem.exception.EntityExistsException) GuidMapping(org.apache.atlas.model.instance.GuidMapping) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Aggregations

GraphTransaction (org.apache.atlas.annotation.GraphTransaction)34 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)12 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)11 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)11 AtlasException (org.apache.atlas.AtlasException)6 RepositoryException (org.apache.atlas.repository.RepositoryException)6 ArrayList (java.util.ArrayList)5 RequestContext (org.apache.atlas.RequestContext)4 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)4 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)4 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)3 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)3 GuidMapping (org.apache.atlas.model.instance.GuidMapping)3 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)3 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)2 EntityResult (org.apache.atlas.model.legacy.EntityResult)2 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)2 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)2 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)2 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)2