Search in sources :

Example 26 with GraphTransaction

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

the class AtlasEntityStoreV1 method updateEntityAttributeByGuid.

@Override
@GraphTransaction
public EntityMutationResponse updateEntityAttributeByGuid(String guid, String attrName, Object attrValue) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> updateEntityAttributeByGuid({}, {}, {})", guid, attrName, attrValue);
    }
    AtlasEntityWithExtInfo entityInfo = getById(guid);
    if (entityInfo == null || entityInfo.getEntity() == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    }
    AtlasEntity entity = entityInfo.getEntity();
    AtlasEntityType entityType = (AtlasEntityType) typeRegistry.getType(entity.getTypeName());
    AtlasAttribute attr = entityType.getAttribute(attrName);
    if (attr == null) {
        throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_ATTRIBUTE, attrName, entity.getTypeName());
    }
    AtlasType attrType = attr.getAttributeType();
    AtlasEntity updateEntity = new AtlasEntity();
    updateEntity.setGuid(guid);
    updateEntity.setTypeName(entity.getTypeName());
    switch(attrType.getTypeCategory()) {
        case PRIMITIVE:
            updateEntity.setAttribute(attrName, attrValue);
            break;
        case OBJECT_ID_TYPE:
            AtlasObjectId objId;
            if (attrValue instanceof String) {
                objId = new AtlasObjectId((String) attrValue, attr.getAttributeDef().getTypeName());
            } else {
                objId = (AtlasObjectId) attrType.getNormalizedValue(attrValue);
            }
            updateEntity.setAttribute(attrName, objId);
            break;
        default:
            throw new AtlasBaseException(AtlasErrorCode.ATTRIBUTE_UPDATE_NOT_SUPPORTED, attrName, attrType.getTypeName());
    }
    return createOrUpdate(new AtlasEntityStream(updateEntity), true);
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasType(org.apache.atlas.type.AtlasType) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 27 with GraphTransaction

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

the class GraphBackedMetadataRepositoryTest method getTableEntityVertex.

@GraphTransaction
AtlasVertex getTableEntityVertex() {
    AtlasGraph graph = TestUtils.getGraph();
    AtlasGraphQuery query = graph.query().has(Constants.ENTITY_TYPE_PROPERTY_KEY, ComparisionOperator.EQUAL, TestUtils.TABLE_TYPE);
    Iterator<AtlasVertex> results = query.vertices().iterator();
    // returning one since guid should be unique
    AtlasVertex tableVertex = results.hasNext() ? results.next() : null;
    if (tableVertex == null) {
        Assert.fail();
    }
    return tableVertex;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 28 with GraphTransaction

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

the class GraphBackedMetadataRepositoryTest method getGUID.

@GraphTransaction
String getGUID() {
    AtlasVertex tableVertex = getTableEntityVertex();
    String guid = GraphHelper.getSingleValuedProperty(tableVertex, Constants.GUID_PROPERTY_KEY, String.class);
    if (guid == null) {
        Assert.fail();
    }
    return guid;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 29 with GraphTransaction

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

the class AtlasTypeDefGraphStore method deleteTypesDef.

@Override
@GraphTransaction
public void deleteTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasTypeDefGraphStore.deleteTypesDef(enums={}, structs={}, classfications={}, entities={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), CollectionUtils.size(typesDef.getEntityDefs()));
    }
    AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
    AtlasEnumDefStore enumDefStore = getEnumDefStore(ttr);
    AtlasStructDefStore structDefStore = getStructDefStore(ttr);
    AtlasClassificationDefStore classifiDefStore = getClassificationDefStore(ttr);
    AtlasEntityDefStore entityDefStore = getEntityDefStore(ttr);
    List<Object> preDeleteStructDefs = new ArrayList<>();
    List<Object> preDeleteClassifiDefs = new ArrayList<>();
    List<Object> preDeleteEntityDefs = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) {
        for (AtlasStructDef structDef : typesDef.getStructDefs()) {
            if (StringUtils.isNotBlank(structDef.getGuid())) {
                preDeleteStructDefs.add(structDefStore.preDeleteByGuid(structDef.getGuid()));
            } else {
                preDeleteStructDefs.add(structDefStore.preDeleteByName(structDef.getName()));
            }
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
        for (AtlasClassificationDef classifiDef : typesDef.getClassificationDefs()) {
            if (StringUtils.isNotBlank(classifiDef.getGuid())) {
                preDeleteClassifiDefs.add(classifiDefStore.preDeleteByGuid(classifiDef.getGuid()));
            } else {
                preDeleteClassifiDefs.add(classifiDefStore.preDeleteByName(classifiDef.getName()));
            }
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
        for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
            if (StringUtils.isNotBlank(entityDef.getGuid())) {
                preDeleteEntityDefs.add(entityDefStore.preDeleteByGuid(entityDef.getGuid()));
            } else {
                preDeleteEntityDefs.add(entityDefStore.preDeleteByName(entityDef.getName()));
            }
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) {
        int i = 0;
        for (AtlasStructDef structDef : typesDef.getStructDefs()) {
            if (StringUtils.isNotBlank(structDef.getGuid())) {
                structDefStore.deleteByGuid(structDef.getGuid(), preDeleteStructDefs.get(i));
            } else {
                structDefStore.deleteByName(structDef.getName(), preDeleteStructDefs.get(i));
            }
            i++;
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
        int i = 0;
        for (AtlasClassificationDef classifiDef : typesDef.getClassificationDefs()) {
            if (StringUtils.isNotBlank(classifiDef.getGuid())) {
                classifiDefStore.deleteByGuid(classifiDef.getGuid(), preDeleteClassifiDefs.get(i));
            } else {
                classifiDefStore.deleteByName(classifiDef.getName(), preDeleteClassifiDefs.get(i));
            }
            i++;
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
        int i = 0;
        for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
            if (StringUtils.isNotBlank(entityDef.getGuid())) {
                entityDefStore.deleteByGuid(entityDef.getGuid(), preDeleteEntityDefs.get(i));
            } else {
                entityDefStore.deleteByName(entityDef.getName(), preDeleteEntityDefs.get(i));
            }
            i++;
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
        for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
            if (StringUtils.isNotBlank(enumDef.getGuid())) {
                enumDefStore.deleteByGuid(enumDef.getGuid());
            } else {
                enumDefStore.deleteByName(enumDef.getName());
            }
        }
    }
    // Remove all from
    ttr.removeTypesDef(typesDef);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasTypeDefGraphStore.deleteTypesDef(enums={}, structs={}, classfications={}, entities={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), CollectionUtils.size(typesDef.getEntityDefs()));
    }
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) ArrayList(java.util.ArrayList) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 30 with GraphTransaction

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

the class AtlasTypeDefGraphStore method updateEnumDefByGuid.

@Override
@GraphTransaction
public AtlasEnumDef updateEnumDefByGuid(String guid, AtlasEnumDef enumDef) throws AtlasBaseException {
    AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
    tryUpdateByGUID(guid, enumDef, ttr);
    return getEnumDefStore(ttr).updateByGuid(guid, enumDef);
}
Also used : AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) 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