Search in sources :

Example 1 with AtlasGraphManagement

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

the class Titan0DatabaseTest method getGraph.

private <V, E> AtlasGraph<V, E> getGraph() {
    GraphSandboxUtil.create();
    if (atlasGraph == null) {
        Titan0GraphDatabase db = new Titan0GraphDatabase();
        atlasGraph = db.getGraph();
        AtlasGraphManagement mgmt = atlasGraph.getManagementSystem();
        // many)
        for (String propertyName : new String[] { "__superTypeNames", "__traitNames" }) {
            AtlasPropertyKey propertyKey = mgmt.getPropertyKey(propertyName);
            if (propertyKey == null) {
                propertyKey = mgmt.makePropertyKey(propertyName, String.class, AtlasCardinality.SET);
                mgmt.createExactMatchIndex(propertyName, false, Collections.singletonList(propertyKey));
            }
        }
        mgmt.commit();
    }
    return (AtlasGraph<V, E>) atlasGraph;
}
Also used : AtlasGraphManagement(org.apache.atlas.repository.graphdb.AtlasGraphManagement) AtlasPropertyKey(org.apache.atlas.repository.graphdb.AtlasPropertyKey) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph)

Example 2 with AtlasGraphManagement

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

the class GraphBackedSearchIndexer method onAdd.

/**
     * This is upon adding a new type to Store.
     *
     * @param dataTypes data type
     * @throws AtlasException
     */
@Override
public void onAdd(Collection<? extends IDataType> dataTypes) throws AtlasException {
    AtlasGraphManagement management = provider.get().getManagementSystem();
    for (IDataType dataType : dataTypes) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Creating indexes for type name={}, definition={}", dataType.getName(), dataType.getClass());
        }
        try {
            addIndexForType(management, dataType);
            LOG.info("Index creation for type {} complete", dataType.getName());
        } catch (Throwable throwable) {
            LOG.error("Error creating index for type {}", dataType, throwable);
            //Rollback indexes if any failure
            rollback(management);
            throw new IndexCreationException("Error while creating index for type " + dataType, throwable);
        }
    }
    //Commit indexes
    commit(management);
}
Also used : AtlasGraphManagement(org.apache.atlas.repository.graphdb.AtlasGraphManagement) IndexCreationException(org.apache.atlas.repository.IndexCreationException) IDataType(org.apache.atlas.typesystem.types.IDataType)

Example 3 with AtlasGraphManagement

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

the class GraphBackedSearchIndexer method initialize.

/**
     * Initializes the indices for the graph - create indices for Global AtlasVertex Keys
     */
private void initialize(AtlasGraph graph) throws RepositoryException, IndexException {
    AtlasGraphManagement management = graph.getManagementSystem();
    try {
        if (management.containsPropertyKey(Constants.VERTEX_TYPE_PROPERTY_KEY)) {
            LOG.info("Global indexes already exist for graph");
            management.commit();
            return;
        }
        /* This is called only once, which is the first time Atlas types are made indexable .*/
        LOG.info("Indexes do not exist, Creating indexes for graph.");
        management.createVertexIndex(Constants.VERTEX_INDEX, Constants.BACKING_INDEX, Collections.<AtlasPropertyKey>emptyList());
        management.createEdgeIndex(Constants.EDGE_INDEX, Constants.BACKING_INDEX);
        // create a composite index for guid as its unique
        createIndexes(management, Constants.GUID_PROPERTY_KEY, String.class, true, AtlasCardinality.SINGLE, true, true);
        // Add creation_timestamp property to Vertex Index (mixed index)
        createIndexes(management, Constants.TIMESTAMP_PROPERTY_KEY, Long.class, false, AtlasCardinality.SINGLE, false, false);
        // Add modification_timestamp property to Vertex Index (mixed index)
        createIndexes(management, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class, false, AtlasCardinality.SINGLE, false, false);
        // create a mixed index for entity state. Set systemProperty flag deliberately to false
        // so that it doesnt create a composite index which has issues with
        // titan 0.5.4 - Refer https://groups.google.com/forum/#!searchin/aureliusgraphs/hemanth/aureliusgraphs/bx7T843mzXU/fjAsclx7GAAJ
        createIndexes(management, Constants.STATE_PROPERTY_KEY, String.class, false, AtlasCardinality.SINGLE, false, false);
        // Create a composite and mixed index for created by property
        createIndexes(management, Constants.CREATED_BY_KEY, String.class, false, AtlasCardinality.SINGLE, true, true);
        // Create a composite and mixed index for modified by property
        createIndexes(management, Constants.MODIFIED_BY_KEY, String.class, false, AtlasCardinality.SINGLE, true, true);
        // create a composite and mixed index for type since it can be combined with other keys
        createIndexes(management, Constants.ENTITY_TYPE_PROPERTY_KEY, String.class, false, AtlasCardinality.SINGLE, true, true);
        // create a composite and mixed index for type since it can be combined with other keys
        createIndexes(management, Constants.SUPER_TYPES_PROPERTY_KEY, String.class, false, AtlasCardinality.SET, true, true);
        // create a composite and mixed index for traitNames since it can be combined with other
        // keys. Traits must be a set and not a list.
        createIndexes(management, Constants.TRAIT_NAMES_PROPERTY_KEY, String.class, false, AtlasCardinality.SET, true, true);
        // Index for full text search
        createFullTextIndex(management);
        //Indexes for graph backed type system store
        createTypeStoreIndexes(management);
        commit(management);
        LOG.info("Index creation for global keys complete.");
    } catch (Throwable t) {
        rollback(management);
        throw new RepositoryException(t);
    }
}
Also used : AtlasGraphManagement(org.apache.atlas.repository.graphdb.AtlasGraphManagement) RepositoryException(org.apache.atlas.repository.RepositoryException)

Example 4 with AtlasGraphManagement

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

the class GraphBackedSearchIndexer method onChange.

@Override
public void onChange(ChangedTypeDefs changedTypeDefs) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Processing changed typedefs {}", changedTypeDefs);
    }
    AtlasGraphManagement management = null;
    try {
        management = provider.get().getManagementSystem();
        // Update index for newly created types
        if (CollectionUtils.isNotEmpty(changedTypeDefs.getCreateTypeDefs())) {
            for (AtlasBaseTypeDef typeDef : changedTypeDefs.getCreateTypeDefs()) {
                updateIndexForTypeDef(management, typeDef);
            }
        }
        // Update index for updated types
        if (CollectionUtils.isNotEmpty(changedTypeDefs.getUpdatedTypeDefs())) {
            for (AtlasBaseTypeDef typeDef : changedTypeDefs.getUpdatedTypeDefs()) {
                updateIndexForTypeDef(management, typeDef);
            }
        }
        // Invalidate the property key for deleted types
        if (CollectionUtils.isNotEmpty(changedTypeDefs.getDeletedTypeDefs())) {
            for (AtlasBaseTypeDef typeDef : changedTypeDefs.getDeletedTypeDefs()) {
                cleanupIndices(management, typeDef);
            }
        }
        //Commit indexes
        commit(management);
    } catch (RepositoryException | IndexException e) {
        LOG.error("Failed to update indexes for changed typedefs", e);
        attemptRollback(changedTypeDefs, management);
    }
}
Also used : AtlasGraphManagement(org.apache.atlas.repository.graphdb.AtlasGraphManagement) IndexException(org.apache.atlas.repository.IndexException) AtlasBaseTypeDef(org.apache.atlas.model.typedef.AtlasBaseTypeDef) RepositoryException(org.apache.atlas.repository.RepositoryException)

Example 5 with AtlasGraphManagement

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

the class GraphBackedSearchIndexerTest method verifyUserDefinedTypeIndex.

@Test
public void verifyUserDefinedTypeIndex() throws AtlasException {
    AtlasGraph graph = TestUtils.getGraph();
    AtlasGraphManagement managementSystem = graph.getManagementSystem();
    try {
        TypeSystem typeSystem = TypeSystem.getInstance();
        String enumName = "randomEnum" + RandomStringUtils.randomAlphanumeric(10);
        EnumType managedType = typeSystem.defineEnumType(enumName, new EnumValue("randomEnumValue", 0));
        HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = createClassTypeDef("Database", "Database type description", null, TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("managedType", managedType));
        ClassType databaseType = typeSystem.defineClassType(databaseTypeDefinition);
        graphBackedSearchIndexer.onAdd(Arrays.asList(databaseType));
        verifySystemCompositeIndex(managementSystem, "Database.name" + Constants.ENTITY_TYPE_PROPERTY_KEY, false);
        verifyVertexIndexContains(managementSystem, "Database.name" + Constants.ENTITY_TYPE_PROPERTY_KEY);
        verifySystemCompositeIndex(managementSystem, "Database.name" + Constants.SUPER_TYPES_PROPERTY_KEY, false);
        verifyVertexIndexContains(managementSystem, "Database.managedType");
    } finally {
        //search indexer uses its own titan management transaction
        managementSystem.rollback();
    }
}
Also used : AtlasGraphManagement(org.apache.atlas.repository.graphdb.AtlasGraphManagement) TypeSystem(org.apache.atlas.typesystem.types.TypeSystem) EnumType(org.apache.atlas.typesystem.types.EnumType) EnumValue(org.apache.atlas.typesystem.types.EnumValue) ClassType(org.apache.atlas.typesystem.types.ClassType) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) Test(org.testng.annotations.Test)

Aggregations

AtlasGraphManagement (org.apache.atlas.repository.graphdb.AtlasGraphManagement)19 AtlasGraph (org.apache.atlas.repository.graphdb.AtlasGraph)9 RepositoryException (org.apache.atlas.repository.RepositoryException)5 AtlasPropertyKey (org.apache.atlas.repository.graphdb.AtlasPropertyKey)5 Test (org.testng.annotations.Test)5 BeforeClass (org.testng.annotations.BeforeClass)4 IndexException (org.apache.atlas.repository.IndexException)3 AtlasGraphIndex (org.apache.atlas.repository.graphdb.AtlasGraphIndex)3 AtlasBaseTypeDef (org.apache.atlas.model.typedef.AtlasBaseTypeDef)2 HashSet (java.util.HashSet)1 AtlasException (org.apache.atlas.AtlasException)1 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)1 IndexCreationException (org.apache.atlas.repository.IndexCreationException)1 ClassType (org.apache.atlas.typesystem.types.ClassType)1 EnumType (org.apache.atlas.typesystem.types.EnumType)1 EnumValue (org.apache.atlas.typesystem.types.EnumValue)1 IDataType (org.apache.atlas.typesystem.types.IDataType)1 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)1