Search in sources :

Example 61 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)

Example 62 with AtlasVertex

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

the class GraphHelperTest method testGetOutgoingEdgesByLabel.

@Test
public void testGetOutgoingEdgesByLabel() throws Exception {
    AtlasGraph graph = TestUtils.getGraph();
    AtlasVertex v1 = graph.addVertex();
    AtlasVertex v2 = graph.addVertex();
    graph.addEdge(v1, v2, "l1");
    graph.addEdge(v1, v2, "l2");
    Iterator<AtlasEdge> iterator = GraphHelper.getInstance().getOutGoingEdgesByLabel(v1, "l1");
    assertTrue(iterator.hasNext());
    assertTrue(iterator.hasNext());
    assertNotNull(iterator.next());
    assertNull(iterator.next());
    assertFalse(iterator.hasNext());
    assertFalse(iterator.hasNext());
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) Test(org.testng.annotations.Test)

Example 63 with AtlasVertex

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

the class GraphHelperTest method testGetVerticesForGUIDSWithDuplicates.

@Test
public void testGetVerticesForGUIDSWithDuplicates() throws Exception {
    ITypedReferenceableInstance hrDept = TestUtils.createDeptEg1(TypeSystem.getInstance());
    List<String> result = repositoryService.createEntities(hrDept).getCreatedEntities();
    String guid = result.get(0);
    Map<String, AtlasVertex> verticesForGUIDs = GraphHelper.getInstance().getVerticesForGUIDs(Arrays.asList(guid, guid));
    Assert.assertEquals(verticesForGUIDs.size(), 1);
    Assert.assertTrue(verticesForGUIDs.containsKey(guid));
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Test(org.testng.annotations.Test)

Example 64 with AtlasVertex

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

the class TitanGraphQuery method vertices.

@Override
public Iterable<AtlasVertex<V, E>> vertices() {
    LOG.debug("Executing: ");
    LOG.debug(queryCondition.toString());
    //compute the overall result by unioning the results from all of the
    //AndConditions together.
    Set<AtlasVertex<V, E>> result = new HashSet<>();
    for (AndCondition andExpr : queryCondition.getAndTerms()) {
        NativeTitanGraphQuery<V, E> andQuery = andExpr.create(getQueryFactory());
        for (AtlasVertex<V, E> vertex : andQuery.vertices()) {
            result.add(vertex);
        }
    }
    return result;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) HashSet(java.util.HashSet) AndCondition(org.apache.atlas.repository.graphdb.titan.query.expr.AndCondition)

Example 65 with AtlasVertex

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

the class AtlasClassificationDefStoreV1 method preCreate.

@Override
public AtlasVertex preCreate(AtlasClassificationDef classificationDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasClassificationDefStoreV1.preCreate({})", classificationDef);
    }
    validateType(classificationDef);
    AtlasType type = typeRegistry.getType(classificationDef.getName());
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.CLASSIFICATION) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, classificationDef.getName(), TypeCategory.TRAIT.name());
    }
    AtlasVertex ret = typeDefStore.findTypeVertexByName(classificationDef.getName());
    if (ret != null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, classificationDef.getName());
    }
    ret = typeDefStore.createTypeVertex(classificationDef);
    updateVertexPreCreate(classificationDef, (AtlasClassificationType) type, ret);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasClassificationDefStoreV1.preCreate({}): {}", classificationDef, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasType(org.apache.atlas.type.AtlasType)

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