Search in sources :

Example 6 with AtlasExportResult

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

Example 7 with AtlasExportResult

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

the class ExportServiceTest method runExportWithParameters.

private ZipSource runExportWithParameters(AtlasExportRequest request) throws AtlasBaseException, IOException {
    final String requestingIP = "1.0.0.0";
    final String hostName = "localhost";
    final String userName = "admin";
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ZipSink zipSink = new ZipSink(baos);
    AtlasExportResult result = exportService.run(zipSink, request, userName, hostName, requestingIP);
    zipSink.close();
    ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
    ZipSource zipSource = new ZipSource(bis);
    return zipSource;
}
Also used : AtlasExportResult(org.apache.atlas.model.impexp.AtlasExportResult) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 8 with AtlasExportResult

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

the class ImportServiceTestUtils method runAndVerifyQuickStart_v1_Import.

public static void runAndVerifyQuickStart_v1_Import(ImportService importService, ZipSource zipSource) throws AtlasBaseException, IOException {
    AtlasExportResult exportResult = zipSource.getExportResult();
    List<String> creationOrder = zipSource.getCreationOrder();
    AtlasImportRequest request = getDefaultImportRequest();
    AtlasImportResult result = runImportWithParameters(importService, request, zipSource);
    Assert.assertNotNull(result);
    verifyImportedMetrics(exportResult, result);
    verifyImportedEntities(creationOrder, result.getProcessedEntities());
}
Also used : AtlasExportResult(org.apache.atlas.model.impexp.AtlasExportResult) AtlasImportResult(org.apache.atlas.model.impexp.AtlasImportResult) AtlasImportRequest(org.apache.atlas.model.impexp.AtlasImportRequest)

Example 9 with AtlasExportResult

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

the class ExportService method run.

public AtlasExportResult run(ZipSink exportSink, AtlasExportRequest request, String userName, String hostName, String requestingIP) throws AtlasBaseException {
    long startTime = System.currentTimeMillis();
    AtlasExportResult result = new AtlasExportResult(request, userName, requestingIP, hostName, startTime);
    ExportContext context = new ExportContext(result, exportSink);
    try {
        LOG.info("==> export(user={}, from={})", userName, requestingIP);
        AtlasExportResult.OperationStatus[] statuses = processItems(request, context);
        processTypesDef(context);
        updateSinkWithOperationMetrics(context, statuses, getOperationDuration(startTime));
    } catch (Exception ex) {
        LOG.error("Operation failed: ", ex);
    } finally {
        atlasGraph.releaseGremlinScriptEngine(context.scriptEngine);
        LOG.info("<== export(user={}, from={}): status {}", userName, requestingIP, context.result.getOperationStatus());
        context.clear();
        result.clear();
    }
    return context.result;
}
Also used : AtlasExportResult(org.apache.atlas.model.impexp.AtlasExportResult) ScriptException(javax.script.ScriptException) AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasException(org.apache.atlas.AtlasException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException)

Example 10 with AtlasExportResult

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

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