Commit 2f896628 by Ashutosh Mestry

ATLAS-2943: Export options null check added.

parent 3051df25
...@@ -19,11 +19,13 @@ package org.apache.atlas.model.impexp; ...@@ -19,11 +19,13 @@ package org.apache.atlas.model.impexp;
import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.apache.atlas.model.instance.AtlasObjectId; import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef; import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
...@@ -133,6 +135,16 @@ public class AtlasExportRequest implements Serializable { ...@@ -133,6 +135,16 @@ public class AtlasExportRequest implements Serializable {
return Long.parseLong(getOptions().get(AtlasExportRequest.FETCH_TYPE_INCREMENTAL_CHANGE_MARKER).toString()); 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) { public StringBuilder toString(StringBuilder sb) {
if (sb == null) { if (sb == null) {
sb = new StringBuilder(); sb = new StringBuilder();
......
...@@ -25,6 +25,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; ...@@ -25,6 +25,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef; 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.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
...@@ -102,13 +104,23 @@ public class AtlasImportRequest implements Serializable { ...@@ -102,13 +104,23 @@ public class AtlasImportRequest implements Serializable {
} }
private String getOptionForKey(String key) { 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 null;
} }
return (String) this.options.get(key); 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 @JsonAnySetter
public void setOption(String key, String value) { public void setOption(String key, String value) {
if (null == options) { if (null == options) {
......
...@@ -30,6 +30,7 @@ import org.apache.atlas.model.impexp.AtlasImportResult; ...@@ -30,6 +30,7 @@ import org.apache.atlas.model.impexp.AtlasImportResult;
import org.apache.atlas.model.impexp.ExportImportAuditEntry; import org.apache.atlas.model.impexp.ExportImportAuditEntry;
import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.Constants;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -70,10 +71,6 @@ public class AuditsWriter { ...@@ -70,10 +71,6 @@ public class AuditsWriter {
auditForImport.add(userName, result, startTime, endTime, entityCreationOrder); 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, private void updateReplicationAttribute(boolean isReplicationSet,
String serverName, String serverFullName, String serverName, String serverFullName,
List<String> exportedGuids, List<String> exportedGuids,
...@@ -87,12 +84,6 @@ public class AuditsWriter { ...@@ -87,12 +84,6 @@ public class AuditsWriter {
atlasServerService.updateEntitiesWithServer(server, exportedGuids, attrNameReplicated); 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, private AtlasServer saveServer(String clusterName, String serverFullName,
String entityGuid, String entityGuid,
long lastModifiedTimestamp) throws AtlasBaseException { long lastModifiedTimestamp) throws AtlasBaseException {
...@@ -138,20 +129,18 @@ public class AuditsWriter { ...@@ -138,20 +129,18 @@ public class AuditsWriter {
private class ExportAudits { private class ExportAudits {
private AtlasExportRequest request; private AtlasExportRequest request;
private String targetServerName; private String targetServerName;
private String optionKeyReplicatedTo;
private boolean replicationOptionState; private boolean replicationOptionState;
private String targetServerFullName; private String targetServerFullName;
public void add(String userName, AtlasExportResult result, public void add(String userName, AtlasExportResult result,
long startTime, long endTime, long startTime, long endTime,
List<String> entityGuids) throws AtlasBaseException { List<String> entityGuids) throws AtlasBaseException {
optionKeyReplicatedTo = AtlasExportRequest.OPTION_KEY_REPLICATED_TO;
request = result.getRequest(); request = result.getRequest();
replicationOptionState = isReplicationOptionSet(request.getOptions(), optionKeyReplicatedTo); replicationOptionState = request.isReplicationOptionSet();
saveCurrentServer(); saveCurrentServer();
targetServerFullName = getClusterNameFromOptions(request.getOptions(), optionKeyReplicatedTo); targetServerFullName = request.getOptionKeyReplicatedTo();
targetServerName = getServerNameFromFullName(targetServerFullName); targetServerName = getServerNameFromFullName(targetServerFullName);
auditService.add(userName, getCurrentClusterName(), targetServerName, auditService.add(userName, getCurrentClusterName(), targetServerName,
ExportImportAuditEntry.OPERATION_EXPORT, ExportImportAuditEntry.OPERATION_EXPORT,
...@@ -178,11 +167,11 @@ public class AuditsWriter { ...@@ -178,11 +167,11 @@ public class AuditsWriter {
List<String> entityGuids) throws AtlasBaseException { List<String> entityGuids) throws AtlasBaseException {
optionKeyReplicatedFrom = AtlasImportRequest.OPTION_KEY_REPLICATED_FROM; optionKeyReplicatedFrom = AtlasImportRequest.OPTION_KEY_REPLICATED_FROM;
request = result.getRequest(); request = result.getRequest();
replicationOptionState = isReplicationOptionSet(request.getOptions(), optionKeyReplicatedFrom); replicationOptionState = request.isReplicationOptionSet();
saveCurrentServer(); saveCurrentServer();
sourceServerFullName = getClusterNameFromOptions(request.getOptions(), optionKeyReplicatedFrom); sourceServerFullName = request.getOptionKeyReplicatedFrom();
sourceServerName = getServerNameFromFullName(sourceServerFullName); sourceServerName = getServerNameFromFullName(sourceServerFullName);
auditService.add(userName, auditService.add(userName,
sourceServerName, getCurrentClusterName(), sourceServerName, getCurrentClusterName(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment