Search in sources :

Example 76 with AtlasBaseException

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

the class EntityLineageService method getSchemaForHiveTableByName.

@Override
@GraphTransaction
public SchemaDetails getSchemaForHiveTableByName(final String datasetName) throws AtlasBaseException {
    if (StringUtils.isEmpty(datasetName)) {
        // TODO: Complete error handling here
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST);
    }
    AtlasEntityType hive_table = atlasTypeRegistry.getEntityTypeByName("hive_table");
    Map<String, Object> lookupAttributes = new HashMap<>();
    lookupAttributes.put("qualifiedName", datasetName);
    String guid = AtlasGraphUtilsV1.getGuidByUniqueAttributes(hive_table, lookupAttributes);
    return getSchemaForHiveTableByGuid(guid);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) HashMap(java.util.HashMap) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 77 with AtlasBaseException

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

the class AtlasClassificationFormatConverter method fromV1ToV2.

@Override
public AtlasClassification fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException {
    AtlasClassification ret = null;
    if (v1Obj != null) {
        AtlasClassificationType classificationType = (AtlasClassificationType) type;
        if (v1Obj instanceof Map) {
            final Map v1Map = (Map) v1Obj;
            final Map v1Attribs = (Map) v1Map.get(ATTRIBUTES_PROPERTY_KEY);
            if (MapUtils.isNotEmpty(v1Attribs)) {
                ret = new AtlasClassification(type.getTypeName(), fromV1ToV2(classificationType, v1Attribs, ctx));
            } else {
                ret = new AtlasClassification(type.getTypeName());
            }
        } else if (v1Obj instanceof Struct) {
            Struct struct = (Struct) v1Obj;
            ret = new AtlasClassification(type.getTypeName(), fromV1ToV2(classificationType, struct.getValues(), ctx));
        } else {
            throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map or Struct", v1Obj.getClass().getCanonicalName());
        }
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) Map(java.util.Map) Struct(org.apache.atlas.v1.model.instance.Struct)

Example 78 with AtlasBaseException

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

the class AdminResource method importData.

@POST
@Path("/import")
@Produces(Servlets.JSON_MEDIA_TYPE)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public AtlasImportResult importData(@DefaultValue("{}") @FormDataParam("request") String jsonData, @FormDataParam("data") InputStream inputStream) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AdminResource.importData(jsonData={}, inputStream={})", jsonData, (inputStream != null));
    }
    AtlasAuthorizationUtils.verifyAccess(new AtlasAdminAccessRequest(AtlasPrivilege.ADMIN_IMPORT), "importData");
    acquireExportImportLock("import");
    AtlasImportResult result;
    try {
        AtlasImportRequest request = AtlasType.fromJson(jsonData, AtlasImportRequest.class);
        ZipSource zipSource = new ZipSource(inputStream);
        result = importService.run(zipSource, request, Servlets.getUserName(httpServletRequest), Servlets.getHostName(httpServletRequest), AtlasAuthorizationUtils.getRequestIpAddress(httpServletRequest));
    } catch (Exception excp) {
        LOG.error("importData(binary) failed", excp);
        throw new AtlasBaseException(excp);
    } finally {
        releaseExportImportLock();
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== AdminResource.importData(binary)");
        }
    }
    return result;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ZipSource(org.apache.atlas.repository.impexp.ZipSource) AtlasAdminAccessRequest(org.apache.atlas.authorize.AtlasAdminAccessRequest) AtlasImportResult(org.apache.atlas.model.impexp.AtlasImportResult) AtlasImportRequest(org.apache.atlas.model.impexp.AtlasImportRequest) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) WebApplicationException(javax.ws.rs.WebApplicationException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 79 with AtlasBaseException

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

the class AdminResource method importFile.

@POST
@Path("/importfile")
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasImportResult importFile(String jsonData) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AdminResource.importFile()");
    }
    AtlasAuthorizationUtils.verifyAccess(new AtlasAdminAccessRequest(AtlasPrivilege.ADMIN_IMPORT), "importFile");
    acquireExportImportLock("importFile");
    AtlasImportResult result;
    try {
        AtlasImportRequest request = AtlasType.fromJson(jsonData, AtlasImportRequest.class);
        result = importService.run(request, Servlets.getUserName(httpServletRequest), Servlets.getHostName(httpServletRequest), AtlasAuthorizationUtils.getRequestIpAddress(httpServletRequest));
    } catch (Exception excp) {
        LOG.error("importFile() failed", excp);
        throw new AtlasBaseException(excp);
    } finally {
        releaseExportImportLock();
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== AdminResource.importFile()");
        }
    }
    return result;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasAdminAccessRequest(org.apache.atlas.authorize.AtlasAdminAccessRequest) AtlasImportResult(org.apache.atlas.model.impexp.AtlasImportResult) AtlasImportRequest(org.apache.atlas.model.impexp.AtlasImportRequest) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) WebApplicationException(javax.ws.rs.WebApplicationException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 80 with AtlasBaseException

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

the class EntityResource method partialUpdateEntityByGuid.

private Response partialUpdateEntityByGuid(String guid, HttpServletRequest request) {
    String entityJson = null;
    try {
        guid = ParamChecker.notEmpty(guid, "Guid property cannot be null");
        entityJson = Servlets.getRequestPayload(request);
        if (LOG.isDebugEnabled()) {
            LOG.debug("partially updating entity for guid {} : {} ", guid, entityJson);
        }
        Referenceable updatedEntity = AtlasType.fromV1Json(entityJson, Referenceable.class);
        // update referenceable with Id if not specified in payload
        Id updateId = updatedEntity.getId();
        if (updateId != null && !AtlasTypeUtil.isAssignedGuid(updateId.getId())) {
            updatedEntity.setId(new Id(guid, 0, updatedEntity.getTypeName()));
        }
        AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntity(updatedEntity);
        EntityMutationResponse mutationResponse = entitiesStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), true);
        CreateUpdateEntitiesResult result = restAdapters.toCreateUpdateEntitiesResult(mutationResponse);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Updated entities: {}", result.getEntityResult());
        }
        String response = getResponse(result);
        return Response.ok(response).build();
    } catch (AtlasBaseException e) {
        LOG.error("Unable to update entity by GUID {} {} ", guid, entityJson, e);
        throw toWebApplicationException(e);
    } catch (AtlasException | IllegalArgumentException e) {
        LOG.error("Unable to update entity by GUID {} {}", guid, entityJson, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to update entity by GUID {} {} ", guid, entityJson, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to update entity by GUID {} {} ", guid, entityJson, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    }
}
Also used : EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasException(org.apache.atlas.AtlasException) AtlasEntityStream(org.apache.atlas.repository.store.graph.v1.AtlasEntityStream) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) Id(org.apache.atlas.v1.model.instance.Id)

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