ExportService { 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; } @Inject  ExportService(final AtlasTypeRegistry typeRegistry, AtlasGraph atlasGraph); AtlasExportResult run(ZipSink exportSink, AtlasExportRequest request, String userName, String hostName,
                                 String requestingIP);  }
@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()); }
@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()); }