Search in sources :

Example 11 with AtlasExportResult

use of org.apache.atlas.model.impexp.AtlasExportResult 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)

Example 12 with AtlasExportResult

use of org.apache.atlas.model.impexp.AtlasExportResult in project atlas by apache.

the class ZipSinkTest method getDefaultExportResult.

private AtlasExportResult getDefaultExportResult() {
    AtlasExportRequest request = new AtlasExportRequest();
    List<AtlasObjectId> itemsToExport = new ArrayList<>();
    itemsToExport.add(new AtlasObjectId("hive_db", "qualifiedName", "default"));
    request.setItemsToExport(itemsToExport);
    defaultExportResult = new AtlasExportResult(request, "admin", "1.0.0.0", "root", 100);
    return defaultExportResult;
}
Also used : AtlasExportResult(org.apache.atlas.model.impexp.AtlasExportResult) AtlasExportRequest(org.apache.atlas.model.impexp.AtlasExportRequest) ArrayList(java.util.ArrayList) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId)

Example 13 with AtlasExportResult

use of org.apache.atlas.model.impexp.AtlasExportResult in project atlas by apache.

the class ExportServiceTest method requestingEntityNotFound_NoData.

@Test
public void requestingEntityNotFound_NoData() throws AtlasBaseException, IOException {
    String requestingIP = "1.0.0.0";
    String hostName = "root";
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ZipSink zipSink = new ZipSink(baos);
    AtlasExportResult result = exportService.run(zipSink, getRequestForFullFetch(), "admin", hostName, requestingIP);
    Assert.assertNull(result.getData());
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ZipSource zipSource = new ZipSource(bais);
    assertNotNull(exportService);
    assertNotNull(zipSource.getCreationOrder());
    Assert.assertFalse(zipSource.hasNext());
}
Also used : AtlasExportResult(org.apache.atlas.model.impexp.AtlasExportResult) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 14 with AtlasExportResult

use of org.apache.atlas.model.impexp.AtlasExportResult in project incubator-atlas by apache.

the class ZipSinkTest method getDefaultExportResult.

private AtlasExportResult getDefaultExportResult() {
    AtlasExportRequest request = new AtlasExportRequest();
    List<AtlasObjectId> itemsToExport = new ArrayList<>();
    itemsToExport.add(new AtlasObjectId("hive_db", "qualifiedName", "default"));
    request.setItemsToExport(itemsToExport);
    defaultExportResult = new AtlasExportResult(request, "admin", "1.0.0.0", "root", 100);
    return defaultExportResult;
}
Also used : AtlasExportResult(org.apache.atlas.model.impexp.AtlasExportResult) AtlasExportRequest(org.apache.atlas.model.impexp.AtlasExportRequest) ArrayList(java.util.ArrayList) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId)

Example 15 with AtlasExportResult

use of org.apache.atlas.model.impexp.AtlasExportResult in project incubator-atlas by apache.

the class ExportServiceTest method exportType_Succeeds.

@Test
public void exportType_Succeeds() throws AtlasBaseException, FileNotFoundException {
    String requestingIP = "1.0.0.0";
    String hostName = "root";
    AtlasExportRequest request = getRequestForFullFetch();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ZipSink zipSink = new ZipSink(baos);
    AtlasExportResult result = exportService.run(zipSink, request, "admin", hostName, requestingIP);
    assertNotNull(exportService);
    assertEquals(result.getHostName(), hostName);
    assertEquals(result.getClientIpAddress(), requestingIP);
    assertEquals(request, result.getRequest());
}
Also used : AtlasExportResult(org.apache.atlas.model.impexp.AtlasExportResult) AtlasExportRequest(org.apache.atlas.model.impexp.AtlasExportRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Aggregations

AtlasExportResult (org.apache.atlas.model.impexp.AtlasExportResult)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)4 AtlasExportRequest (org.apache.atlas.model.impexp.AtlasExportRequest)4 Test (org.testng.annotations.Test)4 AtlasImportRequest (org.apache.atlas.model.impexp.AtlasImportRequest)3 AtlasImportResult (org.apache.atlas.model.impexp.AtlasImportResult)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ScriptException (javax.script.ScriptException)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 AtlasException (org.apache.atlas.AtlasException)2 AtlasServiceException (org.apache.atlas.AtlasServiceException)2 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)2 ZipSink (org.apache.atlas.repository.impexp.ZipSink)2 BeforeTest (org.testng.annotations.BeforeTest)2 AtlasAdminAccessRequest (org.apache.atlas.authorize.AtlasAdminAccessRequest)1