Search in sources :

Example 1 with ZipSink

use of org.apache.atlas.repository.impexp.ZipSink in project incubator-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()");
    }
    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) 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)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)1 AtlasExportResult (org.apache.atlas.model.impexp.AtlasExportResult)1 ZipSink (org.apache.atlas.repository.impexp.ZipSink)1