Repository: atlas
Updated Branches:
  refs/heads/branch-0.8 0c4c3b581 -> 7b999b177


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/7b999b17
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/7b999b17
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/7b999b17

Branch: refs/heads/branch-0.8
Commit: 7b999b17750cbd4a97c72c196c64873d275a13e9
Parents: 0c4c3b5
Author: Ashutosh Mestry <ames...@hortonworks.com>
Authored: Tue Oct 30 10:43:21 2018 -0700
Committer: Ashutosh Mestry <ames...@hortonworks.com>
Committed: Wed Oct 31 10:41:04 2018 -0700

----------------------------------------------------------------------
 .../atlas/model/impexp/AtlasExportRequest.java  | 12 ++++++++++
 .../atlas/model/impexp/AtlasImportRequest.java  | 17 +++++++++++--
 .../atlas/repository/impexp/AuditsWriter.java   | 25 ++++----------------
 3 files changed, 32 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/7b999b17/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 be726a8..6e7d7f3 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
@@ -22,8 +22,10 @@ import org.apache.atlas.model.instance.AtlasObjectId;
 import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
 import org.apache.commons.collections.MapUtils;
 import org.codehaus.jackson.annotate.JsonAutoDetect;
+import org.codehaus.jackson.annotate.JsonIgnore;
 import org.codehaus.jackson.annotate.JsonIgnoreProperties;
 import org.codehaus.jackson.map.annotate.JsonSerialize;
+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/7b999b17/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 aa5fe00..6a99856 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
@@ -18,11 +18,13 @@
 package org.apache.atlas.model.impexp;
 
 import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
+import org.apache.commons.collections.MapUtils;
 import org.codehaus.jackson.annotate.JsonAnySetter;
 import org.codehaus.jackson.annotate.JsonAutoDetect;
 import org.codehaus.jackson.annotate.JsonIgnore;
 import org.codehaus.jackson.annotate.JsonIgnoreProperties;
 import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.apache.commons.lang.StringUtils;
 
 import java.io.Serializable;
 import java.util.HashMap;
@@ -100,13 +102,24 @@ 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);
     }
- @JsonAnySetter
+
+    @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) {
             options = new HashMap<>();

http://git-wip-us.apache.org/repos/asf/atlas/blob/7b999b17/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..1281fd2 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
@@ -22,11 +22,11 @@ import org.apache.atlas.ApplicationProperties;
 import org.apache.atlas.AtlasConstants;
 import org.apache.atlas.AtlasException;
 import org.apache.atlas.exception.AtlasBaseException;
-import org.apache.atlas.model.impexp.AtlasServer;
 import org.apache.atlas.model.impexp.AtlasExportRequest;
 import org.apache.atlas.model.impexp.AtlasExportResult;
 import org.apache.atlas.model.impexp.AtlasImportRequest;
 import org.apache.atlas.model.impexp.AtlasImportResult;
+import org.apache.atlas.model.impexp.AtlasServer;
 import org.apache.atlas.model.impexp.ExportImportAuditEntry;
 import org.apache.atlas.repository.Constants;
 import org.apache.atlas.type.AtlasType;
@@ -38,7 +38,6 @@ import org.springframework.util.CollectionUtils;
 
 import javax.inject.Inject;
 import java.util.List;
-import java.util.Map;
 
 @Component
 public class AuditsWriter {
@@ -70,10 +69,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 +82,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 +127,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,
@@ -170,19 +157,17 @@ public class AuditsWriter {
         private AtlasImportRequest request;
         private boolean replicationOptionState;
         private String sourceServerName;
-        private String optionKeyReplicatedFrom;
         private String sourceServerFullName;
 
         public void add(String userName, AtlasImportResult result,
                         long startTime, long endTime,
                         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(),

Reply via email to