Search in sources :

Example 11 with AtlasVertex

use of org.apache.atlas.repository.graphdb.AtlasVertex in project incubator-atlas by apache.

the class AtlasEnumDefStoreV1 method updateByGuid.

@Override
public AtlasEnumDef updateByGuid(String guid, AtlasEnumDef enumDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasEnumDefStoreV1.updateByGuid({})", guid);
    }
    validateType(enumDef);
    AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.ENUM);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
    }
    typeDefStore.updateTypeVertex(enumDef, vertex);
    toVertex(enumDef, vertex);
    AtlasEnumDef ret = toEnumDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasEnumDefStoreV1.updateByGuid({}): {}", guid, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Example 12 with AtlasVertex

use of org.apache.atlas.repository.graphdb.AtlasVertex in project incubator-atlas by apache.

the class AtlasEnumDefStoreV1 method updateByName.

@Override
public AtlasEnumDef updateByName(String name, AtlasEnumDef enumDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasEnumDefStoreV1.updateByName({}, {})", name, enumDef);
    }
    validateType(enumDef);
    AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.ENUM);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
    }
    typeDefStore.updateTypeVertex(enumDef, vertex);
    toVertex(enumDef, vertex);
    AtlasEnumDef ret = toEnumDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasEnumDefStoreV1.updateByName({}, {}): {}", name, enumDef, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Example 13 with AtlasVertex

use of org.apache.atlas.repository.graphdb.AtlasVertex in project incubator-atlas by apache.

the class AtlasEntityStoreV1 method getByUniqueAttributes.

@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;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 14 with AtlasVertex

use of org.apache.atlas.repository.graphdb.AtlasVertex in project incubator-atlas by apache.

the class AtlasEntityStoreV1 method deleteByUniqueAttributes.

@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;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) ArrayList(java.util.ArrayList) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 15 with AtlasVertex

use of org.apache.atlas.repository.graphdb.AtlasVertex in project incubator-atlas by apache.

the class GraphHelperTest method testGetInstancesByUniqueAttributes.

@Test
public void testGetInstancesByUniqueAttributes() throws Exception {
    GraphHelper helper = GraphHelper.getInstance();
    List<ITypedReferenceableInstance> instances = new ArrayList<>();
    List<String> guids = new ArrayList<>();
    TypeSystem ts = TypeSystem.getInstance();
    ClassType dbType = ts.getDataType(ClassType.class, TestUtils.DATABASE_TYPE);
    for (int i = 0; i < 10; i++) {
        Referenceable db = TestUtils.createDBEntity();
        String guid = createInstance(db);
        ITypedReferenceableInstance instance = convert(db, dbType);
        instances.add(instance);
        guids.add(guid);
    }
    //lookup vertices via getVertexForInstanceByUniqueAttributes
    List<AtlasVertex> vertices = helper.getVerticesForInstancesByUniqueAttribute(dbType, instances);
    assertEquals(instances.size(), vertices.size());
    //assert vertex matches the vertex we get through getVertexForGUID
    for (int i = 0; i < instances.size(); i++) {
        String guid = guids.get(i);
        AtlasVertex foundVertex = vertices.get(i);
        AtlasVertex expectedVertex = helper.getVertexForGUID(guid);
        assertEquals(foundVertex, expectedVertex);
    }
}
Also used : TypeSystem(org.apache.atlas.typesystem.types.TypeSystem) Referenceable(org.apache.atlas.typesystem.Referenceable) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ArrayList(java.util.ArrayList) ClassType(org.apache.atlas.typesystem.types.ClassType) Test(org.testng.annotations.Test)

Aggregations

AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)164 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)53 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)26 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)21 ArrayList (java.util.ArrayList)20 Test (org.testng.annotations.Test)19 HashMap (java.util.HashMap)16 Id (org.apache.atlas.typesystem.persistence.Id)14 Map (java.util.Map)13 List (java.util.List)12 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)12 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)12 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)12 AtlasException (org.apache.atlas.AtlasException)11 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)11 RepositoryException (org.apache.atlas.repository.RepositoryException)11 AtlasGraphQuery (org.apache.atlas.repository.graphdb.AtlasGraphQuery)11 AtlasType (org.apache.atlas.type.AtlasType)11 HashSet (java.util.HashSet)8 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)8