ATLAS-4845 : Atlas Import is failing with fetchType: Incremental if there are no changes between two consecutive runs

Signed-off-by: Pinal Shah <pinal.shah@freestoneinfotech.com>
This commit is contained in:
priyanshi-shah26 2024-04-08 17:25:34 +05:30 committed by Pinal Shah
parent 51691b139b
commit 386067ebfe
3 changed files with 38 additions and 3 deletions

View File

@ -62,6 +62,7 @@ public class AtlasExportRequest implements Serializable {
public static final String MATCH_TYPE_CONTAINS = "contains"; public static final String MATCH_TYPE_CONTAINS = "contains";
public static final String MATCH_TYPE_MATCHES = "matches"; public static final String MATCH_TYPE_MATCHES = "matches";
public static final String MATCH_TYPE_FOR_TYPE = "forType"; 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 List<AtlasObjectId> itemsToExport = new ArrayList<>();
private Map<String, Object> options = new HashMap<>(); 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) { public StringBuilder toString(StringBuilder sb) {
if (sb == null) { if (sb == null) {
sb = new StringBuilder(); sb = new StringBuilder();

View File

@ -127,4 +127,8 @@ public class ZipSink {
private void recordAddedEntityGuids(AtlasEntity entity) { private void recordAddedEntityGuids(AtlasEntity entity) {
guids.add(entity.getGuid()); guids.add(entity.getGuid());
} }
public Set<String> getGuids() {
return guids;
}
} }

View File

@ -127,6 +127,7 @@ import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.apache.atlas.web.filters.AtlasCSRFPreventionFilter.CSRF_TOKEN; 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), Servlets.getHostName(httpServletRequest),
AtlasAuthorizationUtils.getRequestIpAddress(httpServletRequest)); AtlasAuthorizationUtils.getRequestIpAddress(httpServletRequest));
exportSink.close();
httpServletResponse.addHeader("Content-Encoding","gzip"); httpServletResponse.addHeader("Content-Encoding","gzip");
httpServletResponse.setContentType("application/zip"); httpServletResponse.setContentType("application/zip");
@ -632,9 +632,20 @@ public class AdminResource {
"attachment; filename=" + result.getClass().getSimpleName()); "attachment; filename=" + result.getClass().getSimpleName());
httpServletResponse.setHeader("Transfer-Encoding", "chunked"); httpServletResponse.setHeader("Transfer-Encoding", "chunked");
httpServletResponse.getOutputStream().flush();
isSuccessful = true; 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) { } catch (IOException excp) {
LOG.error("export() failed", excp); LOG.error("export() failed", excp);