Search in sources :

Example 1 with AtlasGraphIndex

use of org.apache.atlas.repository.graphdb.AtlasGraphIndex in project atlas by apache.

the class GraphBackedSearchIndexer method getVertexIndexKeys.

public Set<String> getVertexIndexKeys() {
    if (recomputeIndexedKeys) {
        AtlasGraphManagement management = null;
        try {
            management = provider.get().getManagementSystem();
            if (management != null) {
                AtlasGraphIndex vertexIndex = management.getGraphIndex(VERTEX_INDEX);
                if (vertexIndex != null) {
                    recomputeIndexedKeys = false;
                    Set<String> indexKeys = new HashSet<>();
                    for (AtlasPropertyKey fieldKey : vertexIndex.getFieldKeys()) {
                        indexKeys.add(fieldKey.getName());
                    }
                    vertexIndexKeys = indexKeys;
                }
                management.commit();
            }
        } catch (Exception excp) {
            LOG.error("getVertexIndexKeys(): failed to get indexedKeys from graph", excp);
            if (management != null) {
                try {
                    management.rollback();
                } catch (Exception e) {
                    LOG.error("getVertexIndexKeys(): rollback failed", e);
                }
            }
        }
    }
    return vertexIndexKeys;
}
Also used : AtlasGraphManagement(org.apache.atlas.repository.graphdb.AtlasGraphManagement) AtlasPropertyKey(org.apache.atlas.repository.graphdb.AtlasPropertyKey) AtlasGraphIndex(org.apache.atlas.repository.graphdb.AtlasGraphIndex) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) IndexException(org.apache.atlas.repository.IndexException) AtlasException(org.apache.atlas.AtlasException) HashSet(java.util.HashSet)

Example 2 with AtlasGraphIndex

use of org.apache.atlas.repository.graphdb.AtlasGraphIndex in project atlas by apache.

the class GraphBackedSearchIndexer method createVertexCompositeIndex.

private void createVertexCompositeIndex(AtlasGraphManagement management, Class propertyClass, AtlasPropertyKey propertyKey, boolean enforceUniqueness) {
    String propertyName = propertyKey.getName();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating composite index for property {} of type {}; isUnique={} ", propertyName, propertyClass.getName(), enforceUniqueness);
    }
    AtlasGraphIndex existingIndex = management.getGraphIndex(propertyName);
    if (existingIndex == null) {
        management.createVertexCompositeIndex(propertyName, enforceUniqueness, Collections.singletonList(propertyKey));
        LOG.info("Created composite index for property {} of type {}; isUnique={} ", propertyName, propertyClass.getName(), enforceUniqueness);
    }
}
Also used : AtlasGraphIndex(org.apache.atlas.repository.graphdb.AtlasGraphIndex)

Example 3 with AtlasGraphIndex

use of org.apache.atlas.repository.graphdb.AtlasGraphIndex in project atlas by apache.

the class GraphBackedSearchIndexer method createVertexCompositeIndexWithSystemProperty.

private void createVertexCompositeIndexWithSystemProperty(AtlasGraphManagement management, Class propertyClass, AtlasPropertyKey propertyKey, final String systemPropertyKey, AtlasCardinality cardinality) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating composite index for property {} of type {} and {}", propertyKey.getName(), propertyClass.getName(), systemPropertyKey);
    }
    AtlasPropertyKey typePropertyKey = management.getPropertyKey(systemPropertyKey);
    if (typePropertyKey == null) {
        typePropertyKey = management.makePropertyKey(systemPropertyKey, String.class, cardinality);
    }
    final String indexName = propertyKey.getName() + systemPropertyKey;
    AtlasGraphIndex existingIndex = management.getGraphIndex(indexName);
    if (existingIndex == null) {
        List<AtlasPropertyKey> keys = new ArrayList<>(2);
        keys.add(propertyKey);
        keys.add(typePropertyKey);
        management.createVertexCompositeIndex(indexName, false, keys);
        LOG.info("Created composite index for property {} of type {} and {}", propertyKey.getName(), propertyClass.getName(), systemPropertyKey);
    }
}
Also used : AtlasPropertyKey(org.apache.atlas.repository.graphdb.AtlasPropertyKey) AtlasGraphIndex(org.apache.atlas.repository.graphdb.AtlasGraphIndex) ArrayList(java.util.ArrayList)

Example 4 with AtlasGraphIndex

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

the class GraphBackedSearchIndexerTest method verifySystemMixedIndexes.

@Test
public void verifySystemMixedIndexes() {
    AtlasGraph graph = TestUtils.getGraph();
    AtlasGraphManagement managementSystem = graph.getManagementSystem();
    try {
        AtlasGraphIndex vertexIndex = managementSystem.getGraphIndex(Constants.VERTEX_INDEX);
        assertNotNull(vertexIndex);
        assertTrue(vertexIndex.isMixedIndex());
        assertFalse(vertexIndex.isEdgeIndex());
        assertTrue(vertexIndex.isVertexIndex());
        AtlasGraphIndex edgeIndex = managementSystem.getGraphIndex(Constants.EDGE_INDEX);
        assertNotNull(edgeIndex);
        assertTrue(edgeIndex.isMixedIndex());
        assertTrue(edgeIndex.isEdgeIndex());
        assertFalse(edgeIndex.isVertexIndex());
        verifyVertexIndexContains(managementSystem, Constants.STATE_PROPERTY_KEY);
    } finally {
        managementSystem.rollback();
    }
}
Also used : AtlasGraphManagement(org.apache.atlas.repository.graphdb.AtlasGraphManagement) AtlasGraphIndex(org.apache.atlas.repository.graphdb.AtlasGraphIndex) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) Test(org.testng.annotations.Test)

Example 5 with AtlasGraphIndex

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

the class GraphBackedSearchIndexer method createExactMatchIndexWithSystemProperty.

private void createExactMatchIndexWithSystemProperty(AtlasGraphManagement management, Class propertyClass, AtlasPropertyKey propertyKey, final String systemPropertyKey, AtlasCardinality cardinality) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating composite index for property {} of type {} and {}", propertyKey.getName(), propertyClass.getName(), systemPropertyKey);
    }
    AtlasPropertyKey typePropertyKey = management.getPropertyKey(systemPropertyKey);
    if (typePropertyKey == null) {
        typePropertyKey = management.makePropertyKey(systemPropertyKey, String.class, cardinality);
    }
    final String indexName = propertyKey.getName() + systemPropertyKey;
    AtlasGraphIndex existingIndex = management.getGraphIndex(indexName);
    if (existingIndex == null) {
        List<AtlasPropertyKey> keys = new ArrayList<>(2);
        keys.add(propertyKey);
        keys.add(typePropertyKey);
        management.createExactMatchIndex(indexName, false, keys);
        LOG.info("Created composite index for property {} of type {} and {}", propertyKey.getName(), propertyClass.getName(), systemPropertyKey);
    }
}
Also used : AtlasPropertyKey(org.apache.atlas.repository.graphdb.AtlasPropertyKey) AtlasGraphIndex(org.apache.atlas.repository.graphdb.AtlasGraphIndex) ArrayList(java.util.ArrayList)

Aggregations

AtlasGraphIndex (org.apache.atlas.repository.graphdb.AtlasGraphIndex)11 AtlasPropertyKey (org.apache.atlas.repository.graphdb.AtlasPropertyKey)5 AtlasGraphManagement (org.apache.atlas.repository.graphdb.AtlasGraphManagement)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 RepositoryException (org.apache.atlas.repository.RepositoryException)2 AtlasGraph (org.apache.atlas.repository.graphdb.AtlasGraph)2 Test (org.testng.annotations.Test)2 AtlasException (org.apache.atlas.AtlasException)1 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)1 IndexException (org.apache.atlas.repository.IndexException)1