Search in sources :

Example 81 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class Titan1GraphDatabase method getGraphInstance.

public static TitanGraph getGraphInstance() {
    if (graphInstance == null) {
        synchronized (Titan1GraphDatabase.class) {
            if (graphInstance == null) {
                Configuration config;
                try {
                    config = getConfiguration();
                } catch (AtlasException e) {
                    throw new RuntimeException(e);
                }
                graphInstance = TitanFactory.open(config);
                atlasGraphInstance = new Titan1Graph();
                validateIndexBackend(config);
            }
        }
    }
    return graphInstance;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) AtlasException(org.apache.atlas.AtlasException)

Example 82 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class HBaseBasedAuditRepository method listEvents.

/**
     * List events for the given entity id in decreasing order of timestamp, from the given startKey. Returns n results
     * @param entityId entity id
     * @param startKey key for the first event to be returned, used for pagination
     * @param n number of events to be returned
     * @return list of events
     * @throws AtlasException
     */
public List<EntityAuditEvent> listEvents(String entityId, String startKey, short n) throws AtlasException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Listing events for entity id {}, starting timestamp {}, #records {}", entityId, startKey, n);
    }
    Table table = null;
    ResultScanner scanner = null;
    try {
        table = connection.getTable(tableName);
        /**
             * Scan Details:
             * In hbase, the events are stored in increasing order of timestamp. So, doing reverse scan to get the latest event first
             * Page filter is set to limit the number of results returned.
             * Stop row is set to the entity id to avoid going past the current entity while scanning
             * small is set to true to optimise RPC calls as the scanner is created per request
             */
        Scan scan = new Scan().setReversed(true).setFilter(new PageFilter(n)).setStopRow(Bytes.toBytes(entityId)).setCaching(n).setSmall(true);
        if (StringUtils.isEmpty(startKey)) {
            //Set start row to entity id + max long value
            byte[] entityBytes = getKey(entityId, Long.MAX_VALUE);
            scan = scan.setStartRow(entityBytes);
        } else {
            scan = scan.setStartRow(Bytes.toBytes(startKey));
        }
        scanner = table.getScanner(scan);
        Result result;
        List<EntityAuditEvent> events = new ArrayList<>();
        //So, adding extra check on n here
        while ((result = scanner.next()) != null && events.size() < n) {
            EntityAuditEvent event = fromKey(result.getRow());
            //In case the user sets random start key, guarding against random events
            if (!event.getEntityId().equals(entityId)) {
                continue;
            }
            event.setUser(getResultString(result, COLUMN_USER));
            event.setAction(EntityAuditEvent.EntityAuditAction.valueOf(getResultString(result, COLUMN_ACTION)));
            event.setDetails(getResultString(result, COLUMN_DETAIL));
            if (persistEntityDefinition) {
                String colDef = getResultString(result, COLUMN_DEFINITION);
                if (colDef != null) {
                    event.setEntityDefinition(colDef);
                }
            }
            events.add(event);
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Got events for entity id {}, starting timestamp {}, #records {}", entityId, startKey, events.size());
        }
        return events;
    } catch (IOException e) {
        throw new AtlasException(e);
    } finally {
        close(scanner);
        close(table);
    }
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) PageFilter(org.apache.hadoop.hbase.filter.PageFilter) IOException(java.io.IOException) AtlasException(org.apache.atlas.AtlasException) Result(org.apache.hadoop.hbase.client.Result)

Example 83 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class AtlasEntityChangeNotifier method onClassificationDeletedFromEntity.

public void onClassificationDeletedFromEntity(String entityId, List<String> traitNames) throws AtlasBaseException {
    // Since the entity has already been modified in the graph, we need to recursively remap the entity
    doFullTextMapping(entityId);
    ITypedReferenceableInstance entity = toITypedReferenceable(entityId);
    if (entity == null || CollectionUtils.isEmpty(traitNames)) {
        return;
    }
    for (EntityChangeListener listener : entityChangeListeners) {
        try {
            listener.onTraitsDeleted(entity, traitNames);
        } catch (AtlasException e) {
            throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), "TraitDelete");
        }
    }
}
Also used : EntityChangeListener(org.apache.atlas.listener.EntityChangeListener) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) AtlasException(org.apache.atlas.AtlasException)

Example 84 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class AtlasEntityChangeNotifier method onClassificationUpdatedToEntity.

public void onClassificationUpdatedToEntity(String entityId, List<AtlasClassification> classifications) throws AtlasBaseException {
    // Since the classification attributes are updated in the graph, we need to recursively remap the entityText
    doFullTextMapping(entityId);
    ITypedReferenceableInstance entity = toITypedReferenceable(entityId);
    List<ITypedStruct> traits = toITypedStructs(classifications);
    if (entity == null || CollectionUtils.isEmpty(traits)) {
        return;
    }
    for (EntityChangeListener listener : entityChangeListeners) {
        try {
            listener.onTraitsUpdated(entity, traits);
        } catch (AtlasException e) {
            throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), "TraitUpdate");
        }
    }
}
Also used : EntityChangeListener(org.apache.atlas.listener.EntityChangeListener) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) AtlasException(org.apache.atlas.AtlasException)

Example 85 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class AtlasEntityChangeNotifier method onClassificationAddedToEntity.

public void onClassificationAddedToEntity(String entityId, List<AtlasClassification> classifications) throws AtlasBaseException {
    // Only new classifications need to be used for a partial full text string which can be
    // appended to the existing fullText
    updateFullTextMapping(entityId, classifications);
    ITypedReferenceableInstance entity = toITypedReferenceable(entityId);
    List<ITypedStruct> traits = toITypedStructs(classifications);
    if (entity == null || CollectionUtils.isEmpty(traits)) {
        return;
    }
    for (EntityChangeListener listener : entityChangeListeners) {
        try {
            listener.onTraitsAdded(entity, traits);
        } catch (AtlasException e) {
            throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), "TraitAdd");
        }
    }
}
Also used : EntityChangeListener(org.apache.atlas.listener.EntityChangeListener) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) AtlasException(org.apache.atlas.AtlasException)

Aggregations

AtlasException (org.apache.atlas.AtlasException)101 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)26 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)19 IOException (java.io.IOException)13 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)13 RepositoryException (org.apache.atlas.repository.RepositoryException)12 JSONObject (org.codehaus.jettison.json.JSONObject)12 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)9 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)9 Configuration (org.apache.commons.configuration.Configuration)9 ArrayList (java.util.ArrayList)7 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)7 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)6 Id (org.apache.atlas.typesystem.persistence.Id)6 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)6 HashMap (java.util.HashMap)5 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)5 CatalogRuntimeException (org.apache.atlas.catalog.exception.CatalogRuntimeException)5 Referenceable (org.apache.atlas.typesystem.Referenceable)5 EntityExistsException (org.apache.atlas.typesystem.exception.EntityExistsException)5