Search in sources :

Example 1 with AtlasAdminAccessRequest

use of org.apache.atlas.authorize.AtlasAdminAccessRequest 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 2 with AtlasAdminAccessRequest

use of org.apache.atlas.authorize.AtlasAdminAccessRequest 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 3 with AtlasAdminAccessRequest

use of org.apache.atlas.authorize.AtlasAdminAccessRequest in project atlas by apache.

the class AdminResource method export.

@POST
@Path("/export")
@Consumes(Servlets.JSON_MEDIA_TYPE)
public Response export(AtlasExportRequest request) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AdminResource.export()");
    }
    AtlasAuthorizationUtils.verifyAccess(new AtlasAdminAccessRequest(AtlasPrivilege.ADMIN_EXPORT), "export");
    acquireExportImportLock("export");
    ZipSink exportSink = null;
    try {
        exportSink = new ZipSink(httpServletResponse.getOutputStream());
        AtlasExportResult result = exportService.run(exportSink, request, Servlets.getUserName(httpServletRequest), Servlets.getHostName(httpServletRequest), AtlasAuthorizationUtils.getRequestIpAddress(httpServletRequest));
        exportSink.close();
        httpServletResponse.addHeader("Content-Encoding", "gzip");
        httpServletResponse.setContentType("application/zip");
        httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + result.getClass().getSimpleName());
        httpServletResponse.setHeader("Transfer-Encoding", "chunked");
        httpServletResponse.getOutputStream().flush();
        return Response.ok().build();
    } catch (IOException excp) {
        LOG.error("export() failed", excp);
        throw new AtlasBaseException(excp);
    } finally {
        releaseExportImportLock();
        if (exportSink != null) {
            exportSink.close();
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== AdminResource.export()");
        }
    }
}
Also used : AtlasExportResult(org.apache.atlas.model.impexp.AtlasExportResult) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasAdminAccessRequest(org.apache.atlas.authorize.AtlasAdminAccessRequest) ZipSink(org.apache.atlas.repository.impexp.ZipSink) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Aggregations

IOException (java.io.IOException)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 AtlasAdminAccessRequest (org.apache.atlas.authorize.AtlasAdminAccessRequest)3 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)3 Consumes (javax.ws.rs.Consumes)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 AtlasImportRequest (org.apache.atlas.model.impexp.AtlasImportRequest)2 AtlasImportResult (org.apache.atlas.model.impexp.AtlasImportResult)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 AtlasExportResult (org.apache.atlas.model.impexp.AtlasExportResult)1 ZipSink (org.apache.atlas.repository.impexp.ZipSink)1 ZipSource (org.apache.atlas.repository.impexp.ZipSource)1