This is an automated email from the ASF dual-hosted git repository. pinal pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/master by this push: new 386067ebf ATLAS-4845 : Atlas Import is failing with fetchType: Incremental if there are no changes between two consecutive runs 386067ebf is described below commit 386067ebfe50b4bf8912e700933d59be44b05e39 Author: priyanshi-shah26 <priyanshi.s...@freestoneinfotech.com> AuthorDate: Mon Apr 8 17:25:34 2024 +0530 ATLAS-4845 : Atlas Import is failing with fetchType: Incremental if there are no changes between two consecutive runs Signed-off-by: Pinal Shah <pinal.s...@freestoneinfotech.com> --- .../atlas/model/impexp/AtlasExportRequest.java | 20 ++++++++++++++++++++ .../org/apache/atlas/repository/impexp/ZipSink.java | 4 ++++ .../apache/atlas/web/resources/AdminResource.java | 17 ++++++++++++++--- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/intg/src/main/java/org/apache/atlas/model/impexp/AtlasExportRequest.java b/intg/src/main/java/org/apache/atlas/model/impexp/AtlasExportRequest.java index b03b386c0..878b1d8bc 100644 --- a/intg/src/main/java/org/apache/atlas/model/impexp/AtlasExportRequest.java +++ b/intg/src/main/java/org/apache/atlas/model/impexp/AtlasExportRequest.java @@ -62,6 +62,7 @@ public class AtlasExportRequest implements Serializable { public static final String MATCH_TYPE_CONTAINS = "contains"; public static final String MATCH_TYPE_MATCHES = "matches"; public static final String MATCH_TYPE_FOR_TYPE = "forType"; + public static final String OMIT_ZIP_RESPONSE_FOR_EMPTY_EXPORT = "omitZipResponseForEmptyExport"; private List<AtlasObjectId> itemsToExport = new ArrayList<>(); private Map<String, Object> options = new HashMap<>(); @@ -151,6 +152,25 @@ public class AtlasExportRequest implements Serializable { } } + public Boolean getOmitZipResponseForEmptyExport() { + + if (MapUtils.isEmpty(getOptions()) || + !getOptions().containsKey(AtlasExportRequest.OMIT_ZIP_RESPONSE_FOR_EMPTY_EXPORT)) { + return false; + } + + Object o = getOptions().get(AtlasExportRequest.OMIT_ZIP_RESPONSE_FOR_EMPTY_EXPORT); + if (o instanceof String) { + return Boolean.parseBoolean((String) o); + } + + if (o instanceof Boolean) { + return (Boolean) o; + } + + return false; + } + public StringBuilder toString(StringBuilder sb) { if (sb == null) { sb = new StringBuilder(); diff --git a/repository/src/main/java/org/apache/atlas/repository/impexp/ZipSink.java b/repository/src/main/java/org/apache/atlas/repository/impexp/ZipSink.java index 5cec39dd6..4bb7313aa 100644 --- a/repository/src/main/java/org/apache/atlas/repository/impexp/ZipSink.java +++ b/repository/src/main/java/org/apache/atlas/repository/impexp/ZipSink.java @@ -127,4 +127,8 @@ public class ZipSink { private void recordAddedEntityGuids(AtlasEntity entity) { guids.add(entity.getGuid()); } + + public Set<String> getGuids() { + return guids; + } } diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java index 3a7777a24..89d1dd334 100755 --- a/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java +++ b/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java @@ -127,6 +127,7 @@ import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Collectors; import static org.apache.atlas.web.filters.AtlasCSRFPreventionFilter.CSRF_TOKEN; +import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT; /** @@ -624,7 +625,6 @@ public class AdminResource { Servlets.getHostName(httpServletRequest), AtlasAuthorizationUtils.getRequestIpAddress(httpServletRequest)); - exportSink.close(); httpServletResponse.addHeader("Content-Encoding","gzip"); httpServletResponse.setContentType("application/zip"); @@ -632,9 +632,20 @@ public class AdminResource { "attachment; filename=" + result.getClass().getSimpleName()); httpServletResponse.setHeader("Transfer-Encoding", "chunked"); - httpServletResponse.getOutputStream().flush(); isSuccessful = true; - return Response.ok().build(); + if (CollectionUtils.isNotEmpty(exportSink.getGuids())) { + httpServletResponse.getOutputStream().flush(); + return Response.ok().build(); + } else { + if (request.getOmitZipResponseForEmptyExport()) { + httpServletResponse.setStatus(SC_NO_CONTENT); + httpServletResponse.getOutputStream().flush(); + return Response.status(Response.Status.NO_CONTENT).build(); + } else { + httpServletResponse.getOutputStream().flush(); + return Response.ok().build(); + } + } } catch (IOException excp) { LOG.error("export() failed", excp);