Search in sources :

Example 1 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project atlas by apache.

the class EntityGraphMapper method createVertex.

private AtlasEdge createVertex(AtlasStruct struct, AtlasVertex referringVertex, String edgeLabel, EntityMutationContext context) throws AtlasBaseException {
    AtlasVertex vertex = createStructVertex(struct);
    mapAttributes(struct, vertex, CREATE, context);
    try {
        // TODO - Map directly in AtlasGraphUtilsV1
        return graphHelper.getOrCreateEdge(referringVertex, vertex, edgeLabel);
    } catch (RepositoryException e) {
        throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) RepositoryException(org.apache.atlas.repository.RepositoryException)

Example 2 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project atlas by apache.

the class EntityGraphMapper method createInverseReference.

// legacy method to create edges for inverse reference
private AtlasEdge createInverseReference(AtlasAttribute inverseAttribute, AtlasStructType inverseAttributeType, AtlasVertex inverseVertex, AtlasVertex vertex) throws AtlasBaseException {
    String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(inverseAttributeType, inverseAttribute.getName());
    String inverseEdgeLabel = AtlasGraphUtilsV1.getEdgeLabel(propertyName);
    AtlasEdge ret;
    try {
        ret = graphHelper.getOrCreateEdge(inverseVertex, vertex, inverseEdgeLabel);
    } catch (RepositoryException e) {
        throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 3 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project atlas by apache.

the class EntityGraphMapper method updateEdge.

private AtlasEdge updateEdge(AtlasAttributeDef attributeDef, Object value, AtlasEdge currentEdge, final AtlasVertex entityVertex) throws AtlasBaseException {
    LOG.debug("Updating entity reference {} for reference attribute {}", attributeDef.getName());
    // Update edge if it exists
    AtlasVertex currentVertex = currentEdge.getInVertex();
    String currentEntityId = getIdFromVertex(currentVertex);
    String newEntityId = getIdFromVertex(entityVertex);
    AtlasEdge newEdge = currentEdge;
    if (!currentEntityId.equals(newEntityId)) {
        // add an edge to the class vertex from the instance
        if (entityVertex != null) {
            try {
                newEdge = graphHelper.getOrCreateEdge(currentEdge.getOutVertex(), entityVertex, currentEdge.getLabel());
            } catch (RepositoryException e) {
                throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
            }
        }
    }
    return newEdge;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 4 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project atlas by apache.

the class GraphBackedSearchIndexer method initialize.

/**
 * Initializes the indices for the graph - create indices for Global AtlasVertex and AtlasEdge Keys
 */
private void initialize(AtlasGraph graph) throws RepositoryException, IndexException {
    AtlasGraphManagement management = graph.getManagementSystem();
    try {
        LOG.info("Creating indexes for graph.");
        if (management.getGraphIndex(VERTEX_INDEX) == null) {
            management.createVertexMixedIndex(VERTEX_INDEX, BACKING_INDEX, Collections.emptyList());
            LOG.info("Created index : {}", VERTEX_INDEX);
        }
        if (management.getGraphIndex(EDGE_INDEX) == null) {
            management.createEdgeMixedIndex(EDGE_INDEX, BACKING_INDEX, Collections.emptyList());
            LOG.info("Created index : {}", EDGE_INDEX);
        }
        if (management.getGraphIndex(FULLTEXT_INDEX) == null) {
            management.createFullTextMixedIndex(FULLTEXT_INDEX, BACKING_INDEX, Collections.emptyList());
            LOG.info("Created index : {}", FULLTEXT_INDEX);
        }
        // create vertex indexes
        createVertexIndex(management, GUID_PROPERTY_KEY, String.class, true, SINGLE, true, true);
        createVertexIndex(management, TIMESTAMP_PROPERTY_KEY, Long.class, false, SINGLE, false, false);
        createVertexIndex(management, MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class, false, SINGLE, false, false);
        createVertexIndex(management, STATE_PROPERTY_KEY, String.class, false, SINGLE, false, false);
        createVertexIndex(management, CREATED_BY_KEY, String.class, false, SINGLE, true, true);
        createVertexIndex(management, MODIFIED_BY_KEY, String.class, false, SINGLE, true, true);
        createVertexIndex(management, ENTITY_TYPE_PROPERTY_KEY, String.class, false, SINGLE, true, true);
        createVertexIndex(management, SUPER_TYPES_PROPERTY_KEY, String.class, false, SET, true, true);
        createVertexIndex(management, TRAIT_NAMES_PROPERTY_KEY, String.class, false, SET, true, true);
        createVertexIndex(management, PROPAGATED_TRAIT_NAMES_PROPERTY_KEY, String.class, false, LIST, true, true);
        createVertexIndex(management, TYPENAME_PROPERTY_KEY, String.class, true, SINGLE, true, true);
        createVertexIndex(management, VERTEX_TYPE_PROPERTY_KEY, String.class, false, SINGLE, true, true);
        // create vertex-centric index
        createVertexCentricIndex(management, CLASSIFICATION_LABEL, AtlasEdgeDirection.BOTH, CLASSIFICATION_EDGE_NAME_PROPERTY_KEY, String.class, SINGLE);
        createVertexCentricIndex(management, CLASSIFICATION_LABEL, AtlasEdgeDirection.BOTH, CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY, Boolean.class, SINGLE);
        createVertexCentricIndex(management, CLASSIFICATION_LABEL, AtlasEdgeDirection.BOTH, Arrays.asList(CLASSIFICATION_EDGE_NAME_PROPERTY_KEY, CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY));
        // create edge indexes
        createEdgeIndex(management, RELATIONSHIP_GUID_PROPERTY_KEY, String.class, SINGLE, true);
        // create fulltext indexes
        createFullTextIndex(management, ENTITY_TEXT_PROPERTY_KEY, String.class, SINGLE);
        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 5 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project 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)

Aggregations

RepositoryException (org.apache.atlas.repository.RepositoryException)31 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)12 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 AtlasException (org.apache.atlas.AtlasException)11 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)10 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)6 AtlasGraphManagement (org.apache.atlas.repository.graphdb.AtlasGraphManagement)5 RequestContext (org.apache.atlas.RequestContext)4 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)4 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)3 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)3 GuidMapping (org.apache.atlas.model.instance.GuidMapping)3 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)3 EntityExistsException (org.apache.atlas.typesystem.exception.EntityExistsException)3 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)3 Id (org.apache.atlas.typesystem.persistence.Id)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 EntityResult (org.apache.atlas.model.legacy.EntityResult)2 AtlasBaseTypeDef (org.apache.atlas.model.typedef.AtlasBaseTypeDef)2