ATLAS-2943: Export options null check added.
Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/e0ef989e Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/e0ef989e Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/e0ef989e Branch: refs/heads/branch-1.0 Commit: e0ef989ea759356e26cdad72fc969c045a7a763c Parents: 1f9ec2c Author: Ashutosh Mestry <ames...@hortonworks.com> Authored: Tue Oct 30 10:43:21 2018 -0700 Committer: Ashutosh Mestry <ames...@hortonworks.com> Committed: Thu Nov 1 15:42:59 2018 -0700 ---------------------------------------------------------------------- .../atlas/model/impexp/AtlasExportRequest.java | 12 +++++++++++ .../atlas/model/impexp/AtlasImportRequest.java | 14 ++++++++++++- .../atlas/repository/impexp/AuditsWriter.java | 21 +++++--------------- 3 files changed, 30 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/atlas/blob/e0ef989e/intg/src/main/java/org/apache/atlas/model/impexp/AtlasExportRequest.java ---------------------------------------------------------------------- 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 8fb7c68..0e93744 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 @@ -19,11 +19,13 @@ package org.apache.atlas.model.impexp; import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.apache.atlas.model.instance.AtlasObjectId; import org.apache.atlas.model.typedef.AtlasBaseTypeDef; import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang.StringUtils; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -133,6 +135,16 @@ public class AtlasExportRequest implements Serializable { return Long.parseLong(getOptions().get(AtlasExportRequest.FETCH_TYPE_INCREMENTAL_CHANGE_MARKER).toString()); } + @JsonIgnore + public boolean isReplicationOptionSet() { + return MapUtils.isNotEmpty(options) && options.containsKey(OPTION_KEY_REPLICATED_TO); + } + + @JsonIgnore + public String getOptionKeyReplicatedTo() { + return isReplicationOptionSet() ? (String) options.get(OPTION_KEY_REPLICATED_TO) : StringUtils.EMPTY; + } + public StringBuilder toString(StringBuilder sb) { if (sb == null) { sb = new StringBuilder(); http://git-wip-us.apache.org/repos/asf/atlas/blob/e0ef989e/intg/src/main/java/org/apache/atlas/model/impexp/AtlasImportRequest.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/model/impexp/AtlasImportRequest.java b/intg/src/main/java/org/apache/atlas/model/impexp/AtlasImportRequest.java index 06bc231..0b3ede9 100644 --- a/intg/src/main/java/org/apache/atlas/model/impexp/AtlasImportRequest.java +++ b/intg/src/main/java/org/apache/atlas/model/impexp/AtlasImportRequest.java @@ -25,6 +25,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.apache.atlas.model.typedef.AtlasBaseTypeDef; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang.StringUtils; import java.io.Serializable; import java.util.HashMap; @@ -102,13 +104,23 @@ public class AtlasImportRequest implements Serializable { } private String getOptionForKey(String key) { - if (this.options == null || !this.options.containsKey(key)) { + if (MapUtils.isEmpty(this.options) || !this.options.containsKey(key)) { return null; } return (String) this.options.get(key); } + @JsonIgnore + public boolean isReplicationOptionSet() { + return MapUtils.isNotEmpty(options) && options.containsKey(OPTION_KEY_REPLICATED_FROM); + } + + @JsonIgnore + public String getOptionKeyReplicatedFrom() { + return isReplicationOptionSet() ? options.get(OPTION_KEY_REPLICATED_FROM) : StringUtils.EMPTY; + } + @JsonAnySetter public void setOption(String key, String value) { if (null == options) { http://git-wip-us.apache.org/repos/asf/atlas/blob/e0ef989e/repository/src/main/java/org/apache/atlas/repository/impexp/AuditsWriter.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/impexp/AuditsWriter.java b/repository/src/main/java/org/apache/atlas/repository/impexp/AuditsWriter.java index 3612c45..9bf30f1 100644 --- a/repository/src/main/java/org/apache/atlas/repository/impexp/AuditsWriter.java +++ b/repository/src/main/java/org/apache/atlas/repository/impexp/AuditsWriter.java @@ -30,6 +30,7 @@ import org.apache.atlas.model.impexp.AtlasImportResult; import org.apache.atlas.model.impexp.ExportImportAuditEntry; import org.apache.atlas.repository.Constants; import org.apache.atlas.type.AtlasType; +import org.apache.commons.collections.MapUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -70,10 +71,6 @@ public class AuditsWriter { auditForImport.add(userName, result, startTime, endTime, entityCreationOrder); } - private boolean isReplicationOptionSet(Map<String, ? extends Object> options, String replicatedKey) { - return options.containsKey(replicatedKey); - } - private void updateReplicationAttribute(boolean isReplicationSet, String serverName, String serverFullName, List<String> exportedGuids, @@ -87,12 +84,6 @@ public class AuditsWriter { atlasServerService.updateEntitiesWithServer(server, exportedGuids, attrNameReplicated); } - private String getClusterNameFromOptions(Map options, String key) { - return options.containsKey(key) - ? (String) options.get(key) - : StringUtils.EMPTY; - } - private AtlasServer saveServer(String clusterName, String serverFullName, String entityGuid, long lastModifiedTimestamp) throws AtlasBaseException { @@ -138,20 +129,18 @@ public class AuditsWriter { private class ExportAudits { private AtlasExportRequest request; private String targetServerName; - private String optionKeyReplicatedTo; private boolean replicationOptionState; private String targetServerFullName; public void add(String userName, AtlasExportResult result, long startTime, long endTime, List<String> entityGuids) throws AtlasBaseException { - optionKeyReplicatedTo = AtlasExportRequest.OPTION_KEY_REPLICATED_TO; request = result.getRequest(); - replicationOptionState = isReplicationOptionSet(request.getOptions(), optionKeyReplicatedTo); + replicationOptionState = request.isReplicationOptionSet(); saveCurrentServer(); - targetServerFullName = getClusterNameFromOptions(request.getOptions(), optionKeyReplicatedTo); + targetServerFullName = request.getOptionKeyReplicatedTo(); targetServerName = getServerNameFromFullName(targetServerFullName); auditService.add(userName, getCurrentClusterName(), targetServerName, ExportImportAuditEntry.OPERATION_EXPORT, @@ -178,11 +167,11 @@ public class AuditsWriter { List<String> entityGuids) throws AtlasBaseException { optionKeyReplicatedFrom = AtlasImportRequest.OPTION_KEY_REPLICATED_FROM; request = result.getRequest(); - replicationOptionState = isReplicationOptionSet(request.getOptions(), optionKeyReplicatedFrom); + replicationOptionState = request.isReplicationOptionSet(); saveCurrentServer(); - sourceServerFullName = getClusterNameFromOptions(request.getOptions(), optionKeyReplicatedFrom); + sourceServerFullName = request.getOptionKeyReplicatedFrom(); sourceServerName = getServerNameFromFullName(sourceServerFullName); auditService.add(userName, sourceServerName, getCurrentClusterName(),