Search in sources :

Example 11 with RepositoryException

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

the class GraphBackedMetadataRepository method updateEntities.

@Override
@GraphTransaction
public CreateUpdateEntitiesResult updateEntities(ITypedReferenceableInstance... entitiesUpdated) throws RepositoryException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("updating entity {}", entitiesUpdated);
    }
    try {
        TypedInstanceToGraphMapper instanceToGraphMapper = new TypedInstanceToGraphMapper(graphToInstanceMapper, deleteHandler);
        instanceToGraphMapper.mapTypedInstanceToGraph(TypedInstanceToGraphMapper.Operation.UPDATE_FULL, entitiesUpdated);
        CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
        RequestContext requestContext = RequestContext.get();
        result.setEntityResult(createEntityResultFromContext(requestContext));
        GuidMapping mapping = instanceToGraphMapper.createGuidMapping();
        result.setGuidMapping(mapping);
        return result;
    } catch (AtlasException e) {
        throw new RepositoryException(e);
    }
}
Also used : CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) RepositoryException(org.apache.atlas.repository.RepositoryException) RequestContext(org.apache.atlas.RequestContext) AtlasException(org.apache.atlas.AtlasException) GuidMapping(org.apache.atlas.model.instance.GuidMapping) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 12 with RepositoryException

use of org.apache.atlas.repository.RepositoryException 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 13 with RepositoryException

use of org.apache.atlas.repository.RepositoryException 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 14 with RepositoryException

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

the class GraphBackedMetadataRepository method addTraitImpl.

private void addTraitImpl(String guid, ITypedStruct traitInstance) throws RepositoryException {
    final String traitName = traitInstance.getTypeName();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Adding a new trait={} for entity={}", traitName, guid);
    }
    try {
        AtlasVertex instanceVertex = graphHelper.getVertexForGUID(guid);
        // add the trait instance as a new vertex
        final String typeName = GraphHelper.getTypeName(instanceVertex);
        TypedInstanceToGraphMapper instanceToGraphMapper = new TypedInstanceToGraphMapper(graphToInstanceMapper, deleteHandler);
        instanceToGraphMapper.mapTraitInstanceToVertex(traitInstance, typeSystem.getDataType(ClassType.class, typeName), instanceVertex);
        // update the traits in entity once adding trait instance is successful
        GraphHelper.addProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, traitName);
        GraphHelper.setProperty(instanceVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime());
        GraphHelper.setProperty(instanceVertex, Constants.MODIFIED_BY_KEY, RequestContext.get().getUser());
    } catch (RepositoryException e) {
        throw e;
    } catch (Exception e) {
        throw new RepositoryException(e);
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) RepositoryException(org.apache.atlas.repository.RepositoryException) ClassType(org.apache.atlas.typesystem.types.ClassType) RepositoryException(org.apache.atlas.repository.RepositoryException) TraitNotFoundException(org.apache.atlas.typesystem.exception.TraitNotFoundException) EntityExistsException(org.apache.atlas.typesystem.exception.EntityExistsException) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) AtlasException(org.apache.atlas.AtlasException)

Example 15 with RepositoryException

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

the class GraphBackedMetadataRepository method updatePartial.

@Override
@GraphTransaction
public CreateUpdateEntitiesResult updatePartial(ITypedReferenceableInstance entity) throws RepositoryException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("updating entity {}", entity);
    }
    try {
        TypedInstanceToGraphMapper instanceToGraphMapper = new TypedInstanceToGraphMapper(graphToInstanceMapper, deleteHandler);
        instanceToGraphMapper.mapTypedInstanceToGraph(TypedInstanceToGraphMapper.Operation.UPDATE_PARTIAL, entity);
        RequestContext requestContext = RequestContext.get();
        CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
        GuidMapping mapping = instanceToGraphMapper.createGuidMapping();
        result.setEntityResult(createEntityResultFromContext(requestContext));
        result.setGuidMapping(mapping);
        return result;
    } catch (AtlasException e) {
        throw new RepositoryException(e);
    }
}
Also used : CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) RepositoryException(org.apache.atlas.repository.RepositoryException) RequestContext(org.apache.atlas.RequestContext) AtlasException(org.apache.atlas.AtlasException) GuidMapping(org.apache.atlas.model.instance.GuidMapping) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

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