Search in sources :

Example 71 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException 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 72 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class DataAccess method save.

public <T extends AtlasBaseModelObject> T save(T obj) throws AtlasBaseException {
    DataTransferObject<T> dto = (DataTransferObject<T>) dtoRegistry.get(obj.getClass());
    AtlasEntityWithExtInfo entityWithExtInfo = dto.toEntityWithExtInfo(obj);
    EntityMutationResponse entityMutationResponse = entityStore.createOrUpdate(new AtlasEntityStream(entityWithExtInfo), false);
    if (hasError(entityMutationResponse)) {
        throw new AtlasBaseException(AtlasErrorCode.DATA_ACCESS_SAVE_FAILED, obj.toString());
    }
    return this.load(obj);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityStream(org.apache.atlas.repository.store.graph.v1.AtlasEntityStream)

Example 73 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class AtlasTypeDefStoreInitializer method applyTypePatches.

private void applyTypePatches(String typesDirName) {
    String typePatchesDirName = typesDirName + File.separator + PATCHES_FOLDER_NAME;
    File typePatchesDir = new File(typePatchesDirName);
    File[] typePatchFiles = typePatchesDir.exists() ? typePatchesDir.listFiles() : null;
    if (typePatchFiles == null || typePatchFiles.length == 0) {
        LOG.info("Type patches directory {} does not exist or not readable or has no patches", typePatchesDirName);
    } else {
        LOG.info("Type patches directory {} is being processed", typePatchesDirName);
        // sort the files by filename
        Arrays.sort(typePatchFiles);
        PatchHandler[] patchHandlers = new PatchHandler[] { new AddAttributePatchHandler(atlasTypeDefStore, atlasTypeRegistry), new UpdateTypeDefOptionsPatchHandler(atlasTypeDefStore, atlasTypeRegistry), new UpdateAttributePatchHandler(atlasTypeDefStore, atlasTypeRegistry) };
        Map<String, PatchHandler> patchHandlerRegistry = new HashMap<>();
        for (PatchHandler patchHandler : patchHandlers) {
            for (String supportedAction : patchHandler.getSupportedActions()) {
                patchHandlerRegistry.put(supportedAction, patchHandler);
            }
        }
        for (File typePatchFile : typePatchFiles) {
            if (typePatchFile.isFile()) {
                LOG.info("Applying patches in file {}", typePatchFile.getAbsolutePath());
                try {
                    String jsonStr = new String(Files.readAllBytes(typePatchFile.toPath()), StandardCharsets.UTF_8);
                    TypeDefPatches patches = AtlasType.fromJson(jsonStr, TypeDefPatches.class);
                    if (patches == null || CollectionUtils.isEmpty(patches.getPatches())) {
                        LOG.info("No patches in file {}", typePatchFile.getAbsolutePath());
                        continue;
                    }
                    for (TypeDefPatch patch : patches.getPatches()) {
                        PatchHandler patchHandler = patchHandlerRegistry.get(patch.getAction());
                        if (patchHandler == null) {
                            LOG.error("Unknown patch action {} in file {}. Ignored", patch.getAction(), typePatchFile.getAbsolutePath());
                            continue;
                        }
                        try {
                            patchHandler.applyPatch(patch);
                        } catch (AtlasBaseException excp) {
                            LOG.error("Failed to apply {} patch in file {}. Ignored", patch.getAction(), typePatchFile.getAbsolutePath(), excp);
                        }
                    }
                } catch (Throwable t) {
                    LOG.error("Failed to apply patches in file {}. Ignored", typePatchFile.getAbsolutePath(), t);
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) File(java.io.File)

Example 74 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class EntityLineageService method getSchemaForHiveTableByGuid.

@Override
@GraphTransaction
public SchemaDetails getSchemaForHiveTableByGuid(final String guid) throws AtlasBaseException {
    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST);
    }
    SchemaDetails ret = new SchemaDetails();
    AtlasEntityType hive_column = atlasTypeRegistry.getEntityTypeByName("hive_column");
    ret.setDataType(AtlasTypeUtil.toClassTypeDefinition(hive_column));
    AtlasEntityWithExtInfo entityWithExtInfo = entityRetriever.toAtlasEntityWithExtInfo(guid);
    AtlasEntity entity = entityWithExtInfo.getEntity();
    AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(atlasTypeRegistry, AtlasPrivilege.ENTITY_READ, new AtlasEntityHeader(entity)), "read entity schema: guid=", guid);
    Map<String, AtlasEntity> referredEntities = entityWithExtInfo.getReferredEntities();
    List<String> columnIds = getColumnIds(entity);
    if (MapUtils.isNotEmpty(referredEntities)) {
        List<Map<String, Object>> rows = referredEntities.entrySet().stream().filter(e -> isColumn(columnIds, e)).map(e -> AtlasTypeUtil.toMap(e.getValue())).collect(Collectors.toList());
        ret.setRows(rows);
    }
    return ret;
}
Also used : AtlasPrivilege(org.apache.atlas.authorize.AtlasPrivilege) StringUtils(org.apache.commons.lang.StringUtils) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasTypeUtil(org.apache.atlas.type.AtlasTypeUtil) LoggerFactory(org.slf4j.LoggerFactory) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) HashMap(java.util.HashMap) Constants(org.apache.atlas.repository.Constants) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) AtlasErrorCode(org.apache.atlas.AtlasErrorCode) GraphTransaction(org.apache.atlas.annotation.GraphTransaction) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Map(java.util.Map) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) LineageDirection(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityGraphRetriever(org.apache.atlas.repository.store.graph.v1.EntityGraphRetriever) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) Logger(org.slf4j.Logger) SchemaDetails(org.apache.atlas.v1.model.lineage.SchemaResponse.SchemaDetails) MapUtils(org.apache.commons.collections.MapUtils) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Set(java.util.Set) AtlasGremlinQuery(org.apache.atlas.util.AtlasGremlinQueryProvider.AtlasGremlinQuery) AtlasAuthorizationUtils(org.apache.atlas.authorize.AtlasAuthorizationUtils) Collectors(java.util.stream.Collectors) AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) AtlasGraphUtilsV1(org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1) List(java.util.List) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasClient(org.apache.atlas.AtlasClient) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasGremlinQueryProvider(org.apache.atlas.util.AtlasGremlinQueryProvider) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) SchemaDetails(org.apache.atlas.v1.model.lineage.SchemaResponse.SchemaDetails) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) HashMap(java.util.HashMap) Map(java.util.Map) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 75 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class EntityLineageService method getAtlasLineageInfo.

@Override
@GraphTransaction
public AtlasLineageInfo getAtlasLineageInfo(String guid, LineageDirection direction, int depth) throws AtlasBaseException {
    AtlasLineageInfo lineageInfo;
    AtlasEntityHeader entity = entityRetriever.toAtlasEntityHeaderWithClassifications(guid);
    AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(atlasTypeRegistry, AtlasPrivilege.ENTITY_READ, entity), "read entity lineage: guid=", guid);
    AtlasEntityType entityType = atlasTypeRegistry.getEntityTypeByName(entity.getTypeName());
    if (entityType == null || !entityType.getTypeAndAllSuperTypes().contains(AtlasClient.DATA_SET_SUPER_TYPE)) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_DATASET, guid);
    }
    if (direction != null) {
        if (direction.equals(LineageDirection.INPUT)) {
            lineageInfo = getLineageInfo(guid, LineageDirection.INPUT, depth);
        } else if (direction.equals(LineageDirection.OUTPUT)) {
            lineageInfo = getLineageInfo(guid, LineageDirection.OUTPUT, depth);
        } else if (direction.equals(LineageDirection.BOTH)) {
            lineageInfo = getBothLineageInfo(guid, depth);
        } else {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_LINEAGE_INVALID_PARAMS, "direction", direction.toString());
        }
    } else {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_LINEAGE_INVALID_PARAMS, "direction", null);
    }
    return lineageInfo;
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Aggregations

AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)437 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)129 ArrayList (java.util.ArrayList)60 Test (org.testng.annotations.Test)60 AtlasType (org.apache.atlas.type.AtlasType)51 AtlasException (org.apache.atlas.AtlasException)50 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)48 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)45 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)43 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)36 HashMap (java.util.HashMap)34 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)33 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)31 Produces (javax.ws.rs.Produces)29 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)29 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)29 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)26 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)26 Path (javax.ws.rs.Path)25 Map (java.util.Map)24