Search in sources :

Example 6 with AtlasException

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

the class AtlasRelationshipDefStoreV1 method updateVertexPreCreate.

private void updateVertexPreCreate(AtlasRelationshipDef relationshipDef, AtlasRelationshipType relationshipType, AtlasVertex vertex) throws AtlasBaseException {
    AtlasRelationshipEndDef end1 = relationshipDef.getEndDef1();
    AtlasRelationshipEndDef end2 = relationshipDef.getEndDef2();
    // check whether the names added on the relationship Ends are reserved if required.
    final boolean allowReservedKeywords;
    try {
        allowReservedKeywords = ApplicationProperties.get().getBoolean(ALLOW_RESERVED_KEYWORDS, true);
    } catch (AtlasException e) {
        throw new AtlasBaseException(e);
    }
    if (!allowReservedKeywords) {
        if (AtlasDSL.Parser.isKeyword(end1.getName())) {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END1_NAME_INVALID, end1.getName());
        }
        if (AtlasDSL.Parser.isKeyword(end2.getName())) {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END2_NAME_INVALID, end2.getName());
        }
    }
    AtlasStructDefStoreV1.updateVertexPreCreate(relationshipDef, relationshipType, vertex, typeDefStore);
    // Update ends
    setVertexPropertiesFromRelationshipDef(relationshipDef, vertex);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasException(org.apache.atlas.AtlasException) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef)

Example 7 with AtlasException

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

the class AtlasRepositoryConfiguration method getTypeUpdateLockMaxWaitTimeInSeconds.

public static int getTypeUpdateLockMaxWaitTimeInSeconds() {
    Integer ret = typeUpdateLockMaxWaitTimeInSeconds;
    if (ret == null) {
        try {
            Configuration config = ApplicationProperties.get();
            ret = config.getInteger(CONFIG_TYPE_UPDATE_LOCK_MAX_WAIT_TIME_IN_SECONDS, DEFAULT_TYPE_UPDATE_LOCK_MAX_WAIT_TIME_IN_SECONDS);
            typeUpdateLockMaxWaitTimeInSeconds = ret;
        } catch (AtlasException e) {
        // ignore
        }
    }
    return ret == null ? DEFAULT_TYPE_UPDATE_LOCK_MAX_WAIT_TIME_IN_SECONDS : ret;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) AtlasException(org.apache.atlas.AtlasException)

Example 8 with AtlasException

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

the class HBaseBasedAuditRepository method putEventsV2.

@Override
public void putEventsV2(List<EntityAuditEventV2> events) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Putting {} events", events.size());
    }
    Table table = null;
    try {
        table = connection.getTable(tableName);
        List<Put> puts = new ArrayList<>(events.size());
        for (EntityAuditEventV2 event : events) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Adding entity audit event {}", event);
            }
            Put put = new Put(getKey(event.getEntityId(), event.getTimestamp()));
            addColumn(put, COLUMN_ACTION, event.getAction());
            addColumn(put, COLUMN_USER, event.getUser());
            addColumn(put, COLUMN_DETAIL, event.getDetails());
            if (persistEntityDefinition) {
                addColumn(put, COLUMN_DEFINITION, event.getEntity());
            }
            puts.add(put);
        }
        table.put(puts);
    } catch (IOException e) {
        throw new AtlasBaseException(e);
    } finally {
        try {
            close(table);
        } catch (AtlasException e) {
            throw new AtlasBaseException(e);
        }
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) EntityAuditEventV2(org.apache.atlas.model.audit.EntityAuditEventV2) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AtlasException(org.apache.atlas.AtlasException) Put(org.apache.hadoop.hbase.client.Put)

Example 9 with AtlasException

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

the class HBaseBasedAuditRepository method listEventsV1.

/**
 * 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> listEventsV1(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.fromString(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 10 with AtlasException

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

the class HBaseBasedAuditRepository method putEventsV1.

/**
 * Add events to the event repository
 * @param events events to be added
 * @throws AtlasException
 */
@Override
public void putEventsV1(List<EntityAuditEvent> events) throws AtlasException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Putting {} events", events.size());
    }
    Table table = null;
    try {
        table = connection.getTable(tableName);
        List<Put> puts = new ArrayList<>(events.size());
        for (EntityAuditEvent event : events) {
            LOG.debug("Adding entity audit event {}", event);
            Put put = new Put(getKey(event.getEntityId(), event.getTimestamp()));
            addColumn(put, COLUMN_ACTION, event.getAction());
            addColumn(put, COLUMN_USER, event.getUser());
            addColumn(put, COLUMN_DETAIL, event.getDetails());
            if (persistEntityDefinition) {
                addColumn(put, COLUMN_DEFINITION, event.getEntityDefinitionString());
            }
            puts.add(put);
        }
        table.put(puts);
    } catch (IOException e) {
        throw new AtlasException(e);
    } finally {
        close(table);
    }
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) Table(org.apache.hadoop.hbase.client.Table) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AtlasException(org.apache.atlas.AtlasException) Put(org.apache.hadoop.hbase.client.Put)

Aggregations

AtlasException (org.apache.atlas.AtlasException)139 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)36 IOException (java.io.IOException)27 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)26 Configuration (org.apache.commons.configuration.Configuration)19 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)14 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)13 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)13 ArrayList (java.util.ArrayList)12 RepositoryException (org.apache.atlas.repository.RepositoryException)12 JSONObject (org.codehaus.jettison.json.JSONObject)12 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)10 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)9 HashMap (java.util.HashMap)8 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)8 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)8 Properties (java.util.Properties)7 File (java.io.File)6 InputStream (java.io.InputStream)6 EntityChangeListener (org.apache.atlas.listener.EntityChangeListener)6