Search in sources :

Example 1 with AtlasPropertyKey

use of org.apache.atlas.repository.graphdb.AtlasPropertyKey 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 AtlasPropertyKey

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

the class GraphBackedSearchIndexer method createVertexCentricIndex.

private void createVertexCentricIndex(AtlasGraphManagement management, String edgeLabel, AtlasEdgeDirection edgeDirection, List<String> propertyNames) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating vertex-centric index for edge label: {} direction: {} for properties: {}", edgeLabel, edgeDirection.name(), propertyNames);
    }
    String indexName = edgeLabel;
    List<AtlasPropertyKey> propertyKeys = new ArrayList<>();
    for (String propertyName : propertyNames) {
        AtlasPropertyKey propertyKey = management.getPropertyKey(propertyName);
        if (propertyKey != null) {
            propertyKeys.add(propertyKey);
            indexName = indexName + propertyKey.getName();
        }
    }
    if (!management.edgeIndexExist(edgeLabel, indexName) && CollectionUtils.isNotEmpty(propertyKeys)) {
        management.createEdgeIndex(edgeLabel, indexName, edgeDirection, propertyKeys);
        LOG.info("Created vertex-centric index for edge label: {} direction: {} for properties: {}", edgeLabel, edgeDirection.name(), propertyNames);
    }
}
Also used : AtlasPropertyKey(org.apache.atlas.repository.graphdb.AtlasPropertyKey) ArrayList(java.util.ArrayList)

Example 3 with AtlasPropertyKey

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

the class GraphBackedSearchIndexer method createVertexIndex.

private AtlasPropertyKey createVertexIndex(AtlasGraphManagement management, String propertyName, Class propertyClass, boolean isUnique, AtlasCardinality cardinality, boolean createCompositeIndex, boolean createCompositeIndexWithTypeAndSuperTypes) {
    AtlasPropertyKey propertyKey = management.getPropertyKey(propertyName);
    if (propertyKey == null) {
        propertyKey = management.makePropertyKey(propertyName, propertyClass, cardinality);
        if (isIndexApplicable(propertyClass, cardinality)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Creating backing index for vertex property {} of type {} ", propertyName, propertyClass.getName());
            }
            management.addMixedIndex(VERTEX_INDEX, propertyKey);
            LOG.info("Created backing index for vertex property {} of type {} ", propertyName, propertyClass.getName());
        }
    }
    if (propertyKey != null) {
        if (createCompositeIndex) {
            createVertexCompositeIndex(management, propertyClass, propertyKey, isUnique);
        } else if (createCompositeIndexWithTypeAndSuperTypes) {
            createVertexCompositeIndexWithTypeName(management, propertyClass, propertyKey);
            createVertexCompositeIndexWithSuperTypeName(management, propertyClass, propertyKey);
        }
    } else {
        LOG.warn("Index not created for {}: propertyKey is null", propertyName);
    }
    return propertyKey;
}
Also used : AtlasPropertyKey(org.apache.atlas.repository.graphdb.AtlasPropertyKey)

Example 4 with AtlasPropertyKey

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

the class GraphBackedSearchIndexer method createVertexCentricIndex.

private void createVertexCentricIndex(AtlasGraphManagement management, String edgeLabel, AtlasEdgeDirection edgeDirection, String propertyName, Class propertyClass, AtlasCardinality cardinality) {
    AtlasPropertyKey propertyKey = management.getPropertyKey(propertyName);
    if (propertyKey == null) {
        propertyKey = management.makePropertyKey(propertyName, propertyClass, cardinality);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating vertex-centric index for edge label: {} direction: {} for property: {} of type: {} ", edgeLabel, edgeDirection.name(), propertyName, propertyClass.getName());
    }
    final String indexName = edgeLabel + propertyKey.getName();
    if (!management.edgeIndexExist(edgeLabel, indexName)) {
        management.createEdgeIndex(edgeLabel, indexName, edgeDirection, Collections.singletonList(propertyKey));
        LOG.info("Created vertex-centric index for edge label: {} direction: {} for property: {} of type: {}", edgeLabel, edgeDirection.name(), propertyName, propertyClass.getName());
    }
}
Also used : AtlasPropertyKey(org.apache.atlas.repository.graphdb.AtlasPropertyKey)

Example 5 with AtlasPropertyKey

use of org.apache.atlas.repository.graphdb.AtlasPropertyKey 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)

Aggregations

AtlasPropertyKey (org.apache.atlas.repository.graphdb.AtlasPropertyKey)46 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)20 PropertyKey (org.janusgraph.core.PropertyKey)10 TitanManagement (com.thinkaurelius.titan.core.schema.TitanManagement)7 HashSet (java.util.HashSet)6 AtlasGraphManagement (org.apache.atlas.repository.graphdb.AtlasGraphManagement)6 AtlasGraphIndex (org.apache.atlas.repository.graphdb.AtlasGraphIndex)5 IndexBuilder (org.janusgraph.core.schema.JanusGraphManagement.IndexBuilder)5 AtlasCardinality (org.apache.atlas.repository.graphdb.AtlasCardinality)4 AtlasGraph (org.apache.atlas.repository.graphdb.AtlasGraph)4 Cardinality (com.thinkaurelius.titan.core.Cardinality)3 PropertyKeyMaker (com.thinkaurelius.titan.core.schema.PropertyKeyMaker)3 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)3 ArrayList (java.util.ArrayList)3 RepositoryException (org.apache.atlas.repository.RepositoryException)2 AtlasEdgeDirection (org.apache.atlas.repository.graphdb.AtlasEdgeDirection)2 AtlasEdgeLabel (org.apache.atlas.repository.graphdb.AtlasEdgeLabel)2 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)1 Direction (com.tinkerpop.blueprints.Direction)1 AtlasException (org.apache.atlas.AtlasException)1