ATLAS-2845: Rename AtlasCluster to AtlasServer.
Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/116fb62c Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/116fb62c Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/116fb62c Branch: refs/heads/master Commit: 116fb62c9a26efeff389d280f26e3c172ef98cf8 Parents: c0a91c7 Author: Ashutosh Mestry <[email protected]> Authored: Wed Aug 29 21:20:19 2018 -0700 Committer: Ashutosh Mestry <[email protected]> Committed: Thu Oct 11 14:05:48 2018 -0700 ---------------------------------------------------------------------- addons/models/0000-Area0/0010-base_model.json | 16 +- .../001-base_model_replication_attributes.json | 8 +- .../java/org/apache/atlas/AtlasBaseClient.java | 10 +- .../org/apache/atlas/repository/Constants.java | 4 +- .../apache/atlas/model/impexp/AtlasCluster.java | 154 ----------------- .../apache/atlas/model/impexp/AtlasServer.java | 168 +++++++++++++++++++ .../model/impexp/ExportImportAuditEntry.java | 8 +- .../repository/impexp/AtlasServerService.java | 165 ++++++++++++++++++ .../atlas/repository/impexp/AuditsWriter.java | 83 ++++----- .../atlas/repository/impexp/ClusterService.java | 143 ---------------- .../impexp/ExportImportAuditService.java | 14 +- .../atlas/repository/ogm/AtlasClusterDTO.java | 82 --------- .../atlas/repository/ogm/AtlasServerDTO.java | 85 ++++++++++ .../ogm/ExportImportAuditEntryDTO.java | 14 +- .../test/java/org/apache/atlas/TestModules.java | 4 +- .../impexp/AtlasServerServiceTest.java | 121 +++++++++++++ .../repository/impexp/ClusterServiceTest.java | 121 ------------- .../impexp/ExportImportAuditServiceTest.java | 14 +- .../impexp/ReplicationEntityAttributeTest.java | 19 +-- .../stocksDB-Entities/replicationAttrs.json | 4 +- .../atlas/web/resources/AdminResource.java | 37 ++-- .../web/resources/AdminExportImportTestIT.java | 18 +- 22 files changed, 671 insertions(+), 621 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/addons/models/0000-Area0/0010-base_model.json ---------------------------------------------------------------------- diff --git a/addons/models/0000-Area0/0010-base_model.json b/addons/models/0000-Area0/0010-base_model.json index 77774e2..3af0e0e 100644 --- a/addons/models/0000-Area0/0010-base_model.json +++ b/addons/models/0000-Area0/0010-base_model.json @@ -100,12 +100,20 @@ ] }, { - "name": "AtlasCluster", + "name": "AtlasServer", "typeVersion": "1.0", "superTypes": [ ], "attributeDefs": [ { + "name": "name", + "typeName": "string", + "cardinality": "SINGLE", + "isIndexable": true, + "isOptional": false, + "isUnique": false + }, + { "name": "displayName", "typeName": "string", "cardinality": "SINGLE", @@ -114,7 +122,7 @@ "isUnique": false }, { - "name": "qualifiedName", + "name": "fullName", "typeName": "string", "cardinality": "SINGLE", "isIndexable": true, @@ -258,7 +266,7 @@ "isUnique": false }, { - "name": "sourceClusterName", + "name": "sourceServerName", "typeName": "string", "cardinality": "SINGLE", "isIndexable": true, @@ -266,7 +274,7 @@ "isUnique": false }, { - "name": "targetClusterName", + "name": "targetServerName", "typeName": "string", "cardinality": "SINGLE", "isIndexable": true, http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/addons/models/0000-Area0/patches/001-base_model_replication_attributes.json ---------------------------------------------------------------------- diff --git a/addons/models/0000-Area0/patches/001-base_model_replication_attributes.json b/addons/models/0000-Area0/patches/001-base_model_replication_attributes.json index bee3718..323a818 100644 --- a/addons/models/0000-Area0/patches/001-base_model_replication_attributes.json +++ b/addons/models/0000-Area0/patches/001-base_model_replication_attributes.json @@ -8,16 +8,16 @@ "params": null, "attributeDefs": [ { - "name": "replicatedFromCluster", - "typeName": "array<AtlasCluster>", + "name": "replicatedFrom", + "typeName": "array<AtlasServer>", "cardinality": "SET", "isIndexable": false, "isOptional": true, "isUnique": false }, { - "name": "replicatedToCluster", - "typeName": "array<AtlasCluster>", + "name": "replicatedTo", + "typeName": "array<AtlasServer>", "cardinality": "SET", "isIndexable": false, "isOptional": true, http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java ---------------------------------------------------------------------- diff --git a/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java b/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java index ca772a7..cb7340f 100644 --- a/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java +++ b/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java @@ -37,7 +37,7 @@ import com.sun.jersey.multipart.MultiPart; import com.sun.jersey.multipart.file.FileDataBodyPart; import com.sun.jersey.multipart.file.StreamDataBodyPart; import com.sun.jersey.multipart.impl.MultiPartWriter; -import org.apache.atlas.model.impexp.AtlasCluster; +import org.apache.atlas.model.impexp.AtlasServer; import org.apache.atlas.model.impexp.AtlasExportRequest; import org.apache.atlas.model.impexp.AtlasImportRequest; import org.apache.atlas.model.impexp.AtlasImportResult; @@ -80,7 +80,7 @@ public abstract class AtlasBaseClient { public static final String ADMIN_METRICS = "admin/metrics"; public static final String ADMIN_IMPORT = "admin/import"; public static final String ADMIN_EXPORT = "admin/export"; - public static final String ADMIN_CLUSTER_TEMPLATE = "%sadmin/cluster/%s"; + public static final String ADMIN_SERVER_TEMPLATE = "%sadmin/server/%s"; public static final String QUERY = "query"; public static final String LIMIT = "limit"; @@ -526,9 +526,9 @@ public abstract class AtlasBaseClient { return new FormDataBodyPart(IMPORT_REQUEST_PARAMTER, AtlasType.toJson(request), MediaType.APPLICATION_JSON_TYPE); } - public AtlasCluster getCluster(String clusterName) throws AtlasServiceException { - API api = new API(String.format(ADMIN_CLUSTER_TEMPLATE, BASE_URI, clusterName), HttpMethod.GET, Response.Status.OK); - return callAPI(api, AtlasCluster.class, null); + public AtlasServer getServer(String serverName) throws AtlasServiceException { + API api = new API(String.format(ADMIN_SERVER_TEMPLATE, BASE_URI, serverName), HttpMethod.GET, Response.Status.OK); + return callAPI(api, AtlasServer.class, null); } boolean isRetryableException(ClientHandlerException che) { http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/common/src/main/java/org/apache/atlas/repository/Constants.java ---------------------------------------------------------------------- diff --git a/common/src/main/java/org/apache/atlas/repository/Constants.java b/common/src/main/java/org/apache/atlas/repository/Constants.java index 444dc39..ed2ca4c 100644 --- a/common/src/main/java/org/apache/atlas/repository/Constants.java +++ b/common/src/main/java/org/apache/atlas/repository/Constants.java @@ -164,8 +164,8 @@ public final class Constants { */ public static final String ATTR_NAME_REFERENCEABLE = "Referenceable."; - public static final String ATTR_NAME_REPLICATED_TO_CLUSTER = "replicatedToCluster"; - public static final String ATTR_NAME_REPLICATED_FROM_CLUSTER = "replicatedFromCluster"; + public static final String ATTR_NAME_REPLICATED_TO = "replicatedTo"; + public static final String ATTR_NAME_REPLICATED_FROM = "replicatedFrom"; private Constants() { } http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/intg/src/main/java/org/apache/atlas/model/impexp/AtlasCluster.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/model/impexp/AtlasCluster.java b/intg/src/main/java/org/apache/atlas/model/impexp/AtlasCluster.java deleted file mode 100644 index f70a219..0000000 --- a/intg/src/main/java/org/apache/atlas/model/impexp/AtlasCluster.java +++ /dev/null @@ -1,154 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.atlas.model.impexp; - -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import org.apache.atlas.model.AtlasBaseModelObject; -import org.apache.atlas.type.AtlasType; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; -import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; - -@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE) -@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown = true) -public class AtlasCluster extends AtlasBaseModelObject implements Serializable { - private static final long serialVersionUID = 1L; - - public static final String KEY_REPLICATION_DETAILS = "REPL_DETAILS"; - - private String name; - private String qualifiedName; - private Map<String, String> additionalInfo; - private List<String> urls; - - public AtlasCluster() { - urls = new ArrayList<>(); - additionalInfo = new HashMap<>(); - } - - public AtlasCluster(String name, String qualifiedName) { - this(); - this.name = name; - this.qualifiedName = qualifiedName; - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return this.name; - } - - public void setAdditionalInfo(Map<String, String> additionalInfo) { - this.additionalInfo = additionalInfo; - } - - public void setAdditionalInfo(String key, String value) { - if(additionalInfo == null) { - additionalInfo = new HashMap<>(); - } - - additionalInfo.put(key, value); - } - - public void setAdditionalInfoRepl(String guid, long modifiedTimestamp) { - Map<String, Object> replicationDetailsMap = null; - - if(additionalInfo != null && additionalInfo.containsKey(KEY_REPLICATION_DETAILS)) { - replicationDetailsMap = AtlasType.fromJson(getAdditionalInfo().get(KEY_REPLICATION_DETAILS), Map.class); - } - - if(replicationDetailsMap == null) { - replicationDetailsMap = new HashMap<>(); - } - - if(modifiedTimestamp == 0) { - replicationDetailsMap.remove(guid); - } else { - replicationDetailsMap.put(guid, modifiedTimestamp); - } - - updateReplicationMap(replicationDetailsMap); - } - - private void updateReplicationMap(Map<String, Object> replicationDetailsMap) { - String json = AtlasType.toJson(replicationDetailsMap); - setAdditionalInfo(KEY_REPLICATION_DETAILS, json); - } - - - public Object getAdditionalInfoRepl(String guid) { - if(additionalInfo == null || !additionalInfo.containsKey(KEY_REPLICATION_DETAILS)) { - return null; - } - - String key = guid; - String mapJson = additionalInfo.get(KEY_REPLICATION_DETAILS); - - Map<String, String> replicationDetailsMap = AtlasType.fromJson(mapJson, Map.class); - if(!replicationDetailsMap.containsKey(key)) { - return null; - } - - return replicationDetailsMap.get(key); - } - - public Map<String, String> getAdditionalInfo() { - return this.additionalInfo; - } - - public String getAdditionalInfo(String key) { - return additionalInfo.get(key); - } - - public String getQualifiedName() { - return qualifiedName; - } - - public void setQualifiedName(String qualifiedName) { - this.qualifiedName = qualifiedName; - } - - public void setUrls(List<String> urls) { - this.urls = urls; - } - - public List<String> getUrls() { - return this.urls; - } - - @Override - public StringBuilder toString(StringBuilder sb) { - sb.append(", name=").append(name); - sb.append(", qualifiedName=").append(getQualifiedName()); - sb.append(", urls=").append(urls); - sb.append(", additionalInfo=").append(additionalInfo); - sb.append("}"); - return sb; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/intg/src/main/java/org/apache/atlas/model/impexp/AtlasServer.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/model/impexp/AtlasServer.java b/intg/src/main/java/org/apache/atlas/model/impexp/AtlasServer.java new file mode 100644 index 0000000..517a23e --- /dev/null +++ b/intg/src/main/java/org/apache/atlas/model/impexp/AtlasServer.java @@ -0,0 +1,168 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.atlas.model.impexp; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.apache.atlas.model.AtlasBaseModelObject; +import org.apache.atlas.type.AtlasType; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE) +@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class AtlasServer extends AtlasBaseModelObject implements Serializable { + private static final long serialVersionUID = 1L; + + public static final String KEY_REPLICATION_DETAILS = "REPL_DETAILS"; + + private String name; + private String fullName; + private String displayName; + private Map<String, String> additionalInfo = new HashMap<>(); + private List<String> urls = new ArrayList<>(); + + public AtlasServer() { + } + + public AtlasServer(String name, String fullName) { + this(name, name, fullName); + } + + public AtlasServer(String name, String displayName, String fullName) { + this.name = name; + this.displayName = displayName; + this.fullName = fullName; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } + + public String getFullName() { + return fullName; + } + + public void setFullName(String fullName) { + this.fullName = fullName; + } + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public void setAdditionalInfo(Map<String, String> additionalInfo) { + this.additionalInfo = additionalInfo; + } + + public Map<String, String> getAdditionalInfo() { + return this.additionalInfo; + } + + public String getAdditionalInfo(String key) { + return additionalInfo.get(key); + } + + public void setUrls(List<String> urls) { + this.urls = urls; + } + + public List<String> getUrls() { + return this.urls; + } + + + public void setAdditionalInfo(String key, String value) { + if (additionalInfo == null) { + additionalInfo = new HashMap<>(); + } + + additionalInfo.put(key, value); + } + + public void setAdditionalInfoRepl(String guid, long modifiedTimestamp) { + Map<String, Object> replicationDetailsMap = null; + + if (additionalInfo != null && additionalInfo.containsKey(KEY_REPLICATION_DETAILS)) { + replicationDetailsMap = AtlasType.fromJson(getAdditionalInfo().get(KEY_REPLICATION_DETAILS), Map.class); + } + + if (replicationDetailsMap == null) { + replicationDetailsMap = new HashMap<>(); + } + + if (modifiedTimestamp == 0) { + replicationDetailsMap.remove(guid); + } else { + replicationDetailsMap.put(guid, modifiedTimestamp); + } + + updateReplicationMap(replicationDetailsMap); + } + + public Object getAdditionalInfoRepl(String guid) { + if (additionalInfo == null || !additionalInfo.containsKey(KEY_REPLICATION_DETAILS)) { + return null; + } + + String key = guid; + String mapJson = additionalInfo.get(KEY_REPLICATION_DETAILS); + + Map<String, String> replicationDetailsMap = AtlasType.fromJson(mapJson, Map.class); + + if (!replicationDetailsMap.containsKey(key)) { + return null; + } + + return replicationDetailsMap.get(key); + } + + @Override + public StringBuilder toString(StringBuilder sb) { + sb.append(", name=").append(name); + sb.append(", fullName=").append(fullName); + sb.append(", displayName=").append(displayName); + sb.append(", additionalInfo=").append(additionalInfo); + sb.append(", urls=").append(urls); + + return sb; + } + + private void updateReplicationMap(Map<String, Object> replicationDetailsMap) { + String json = AtlasType.toJson(replicationDetailsMap); + + setAdditionalInfo(KEY_REPLICATION_DETAILS, json); + } +} http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/intg/src/main/java/org/apache/atlas/model/impexp/ExportImportAuditEntry.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/model/impexp/ExportImportAuditEntry.java b/intg/src/main/java/org/apache/atlas/model/impexp/ExportImportAuditEntry.java index a3d7a0e..a199c6e 100644 --- a/intg/src/main/java/org/apache/atlas/model/impexp/ExportImportAuditEntry.java +++ b/intg/src/main/java/org/apache/atlas/model/impexp/ExportImportAuditEntry.java @@ -93,19 +93,19 @@ public class ExportImportAuditEntry extends AtlasBaseModelObject implements Seri return this.endTime; } - public String getTargetClusterName() { + public String getTargetServerName() { return this.targetClusterName; } - public String getSourceClusterName() { + public String getSourceServerName() { return this.sourceClusterName; } - public void setSourceClusterName(String sourceClusterName) { + public void setSourceServerName(String sourceClusterName) { this.sourceClusterName = sourceClusterName; } - public void setTargetClusterName(String targetClusterName) { + public void setTargetServerName(String targetClusterName) { this.targetClusterName = targetClusterName; } http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/repository/src/main/java/org/apache/atlas/repository/impexp/AtlasServerService.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/impexp/AtlasServerService.java b/repository/src/main/java/org/apache/atlas/repository/impexp/AtlasServerService.java new file mode 100644 index 0000000..0761441 --- /dev/null +++ b/repository/src/main/java/org/apache/atlas/repository/impexp/AtlasServerService.java @@ -0,0 +1,165 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.atlas.repository.impexp; + +import org.apache.atlas.annotation.AtlasService; +import org.apache.atlas.annotation.GraphTransaction; +import org.apache.atlas.exception.AtlasBaseException; +import org.apache.atlas.model.impexp.AtlasServer; +import org.apache.atlas.model.instance.AtlasEntity; +import org.apache.atlas.model.instance.AtlasObjectId; +import org.apache.atlas.repository.graphdb.AtlasVertex; +import org.apache.atlas.repository.ogm.DataAccess; +import org.apache.atlas.repository.store.graph.AtlasEntityStore; +import org.apache.atlas.repository.store.graph.v2.EntityGraphMapper; +import org.apache.atlas.repository.store.graph.v2.EntityGraphRetriever; +import org.apache.atlas.type.AtlasEntityType; +import org.apache.atlas.type.AtlasStructType; +import org.apache.atlas.type.AtlasTypeRegistry; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.List; + +@AtlasService +public class AtlasServerService { + private static final Logger LOG = LoggerFactory.getLogger(AtlasServerService.class); + + private final DataAccess dataAccess; + private final AtlasEntityStore entityStore; + private final AtlasTypeRegistry typeRegistry; + private final EntityGraphRetriever entityGraphRetriever; + + @Inject + public AtlasServerService(DataAccess dataAccess, AtlasEntityStore entityStore, + AtlasTypeRegistry typeRegistry, + EntityGraphRetriever entityGraphRetriever) { + + this.dataAccess = dataAccess; + this.entityStore = entityStore; + this.typeRegistry = typeRegistry; + this.entityGraphRetriever = entityGraphRetriever; + } + + public AtlasServer get(AtlasServer server) throws AtlasBaseException { + try { + return dataAccess.load(server); + } catch (AtlasBaseException e) { + LOG.error("dataAccess", e); + throw e; + } + } + + public AtlasServer getCreateAtlasServer(String name, String fullName) throws AtlasBaseException { + AtlasServer defaultServer = new AtlasServer(name, fullName); + AtlasServer server = getAtlasServer(defaultServer); + if (server == null) { + return save(defaultServer); + } + + return server; + } + + private AtlasServer getAtlasServer(AtlasServer server) { + try { + return get(server); + } catch (AtlasBaseException ex) { + return null; + } + } + + @GraphTransaction + public AtlasServer save(AtlasServer server) { + + try { + return dataAccess.save(server); + } catch (AtlasBaseException e) { + return server; + } + } + + @GraphTransaction + public void updateEntitiesWithServer(AtlasServer server, List<String> entityGuids, String attributeName) throws AtlasBaseException { + if (server != null && StringUtils.isEmpty(server.getGuid())) { + return; + } + + AtlasObjectId objectId = getObjectId(server); + for (String guid : entityGuids) { + AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo = entityStore.getById(guid); + updateAttribute(entityWithExtInfo, attributeName, objectId); + } + } + + private AtlasObjectId getObjectId(AtlasServer server) { + return new AtlasObjectId(server.getGuid(), AtlasServer.class.getSimpleName()); + } + + + /** + * Attribute passed by name is updated with the value passed. + * @param entityWithExtInfo Entity to be updated + * @param propertyName attribute name + * @param objectId Value to be set for attribute + */ + private void updateAttribute(AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo, + String propertyName, + AtlasObjectId objectId) { + String value = EntityGraphMapper.getSoftRefFormattedValue(objectId); + updateAttribute(entityWithExtInfo.getEntity(), propertyName, value); + for (AtlasEntity e : entityWithExtInfo.getReferredEntities().values()) { + updateAttribute(e, propertyName, value); + } + } + + private void updateAttribute(AtlasEntity entity, String attributeName, Object value) { + if(entity.hasAttribute(attributeName) == false) return; + + try { + AtlasVertex vertex = entityGraphRetriever.getEntityVertex(entity.getGuid()); + if(vertex == null) { + return; + } + + String qualifiedFieldName = getVertexPropertyName(entity, attributeName); + List list = vertex.getListProperty(qualifiedFieldName); + if (CollectionUtils.isEmpty(list)) { + list = new ArrayList(); + } + + if (!list.contains(value)) { + list.add(value); + vertex.setListProperty(qualifiedFieldName, list); + } + } + catch (AtlasBaseException ex) { + LOG.error("error retrieving vertex from guid: {}", entity.getGuid(), ex); + } + } + + private String getVertexPropertyName(AtlasEntity entity, String attributeName) throws AtlasBaseException { + AtlasEntityType type = (AtlasEntityType) typeRegistry.getType(entity.getTypeName()); + AtlasStructType.AtlasAttribute attribute = type.getAttribute(attributeName); + return attribute.getVertexPropertyName(); + } +} http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/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 ced00b9..5b5d022 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,7 +22,7 @@ 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.AtlasCluster; +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; @@ -45,15 +45,15 @@ public class AuditsWriter { private static final Logger LOG = LoggerFactory.getLogger(AuditsWriter.class); private static final String CLUSTER_NAME_DEFAULT = "default"; - private ClusterService clusterService; + private AtlasServerService atlasServerService; private ExportImportAuditService auditService; private ExportAudits auditForExport = new ExportAudits(); private ImportAudits auditForImport = new ImportAudits(); @Inject - public AuditsWriter(ClusterService clusterService, ExportImportAuditService auditService) { - this.clusterService = clusterService; + public AuditsWriter(AtlasServerService atlasServerService, ExportImportAuditService auditService) { + this.atlasServerService = atlasServerService; this.auditService = auditService; } @@ -63,7 +63,9 @@ public class AuditsWriter { auditForExport.add(userName, result, startTime, endTime, entityCreationOrder); } - public void write(String userName, AtlasImportResult result, long startTime, long endTime, List<String> entityCreationOrder) throws AtlasBaseException { + public void write(String userName, AtlasImportResult result, + long startTime, long endTime, + List<String> entityCreationOrder) throws AtlasBaseException { auditForImport.add(userName, result, startTime, endTime, entityCreationOrder); } @@ -72,7 +74,7 @@ public class AuditsWriter { } private void updateReplicationAttribute(boolean isReplicationSet, - String clusterName, + String serverName, List<String> exportedGuids, String attrNameReplicated, long lastModifiedTimestamp) throws AtlasBaseException { @@ -80,30 +82,32 @@ public class AuditsWriter { return; } - AtlasCluster cluster = saveCluster(clusterName, exportedGuids.get(0), lastModifiedTimestamp); - clusterService.updateEntitiesWithCluster(cluster, exportedGuids, attrNameReplicated); + AtlasServer server = saveServer(serverName, exportedGuids.get(0), lastModifiedTimestamp); + atlasServerService.updateEntitiesWithServer(server, exportedGuids, attrNameReplicated); } private String getClusterNameFromOptions(Map options, String key) { return options.containsKey(key) ? (String) options.get(key) - : ""; + : StringUtils.EMPTY; } - private AtlasCluster saveCluster(String clusterName) throws AtlasBaseException { - AtlasCluster cluster = new AtlasCluster(clusterName, clusterName); - return clusterService.save(cluster); + private AtlasServer saveServer(String name) throws AtlasBaseException { + return atlasServerService.save(new AtlasServer(name, name)); } - private AtlasCluster saveCluster(String clusterName, String entityGuid, long lastModifiedTimestamp) throws AtlasBaseException { - AtlasCluster cluster = new AtlasCluster(clusterName, clusterName); - cluster.setAdditionalInfoRepl(entityGuid, lastModifiedTimestamp); + private AtlasServer saveServer(String name, + String entityGuid, + long lastModifiedTimestamp) throws AtlasBaseException { + + AtlasServer server = new AtlasServer(name, name); + server.setAdditionalInfoRepl(entityGuid, lastModifiedTimestamp); if (LOG.isDebugEnabled()) { - LOG.debug("saveCluster: {}", cluster); + LOG.debug("saveServer: {}", server); } - return clusterService.save(cluster); + return atlasServerService.save(server); } public static String getCurrentClusterName() { @@ -113,12 +117,12 @@ public class AuditsWriter { LOG.error("getCurrentClusterName", e); } - return ""; + return StringUtils.EMPTY; } private class ExportAudits { private AtlasExportRequest request; - private String targetClusterName; + private String targetServerName; private String optionKeyReplicatedTo; private boolean replicationOptionState; @@ -129,9 +133,9 @@ public class AuditsWriter { request = result.getRequest(); replicationOptionState = isReplicationOptionSet(request.getOptions(), optionKeyReplicatedTo); - saveClusters(); + saveServers(); - auditService.add(userName, getCurrentClusterName(), targetClusterName, + auditService.add(userName, getCurrentClusterName(), targetServerName, ExportImportAuditEntry.OPERATION_EXPORT, AtlasType.toJson(result), startTime, endTime, !entityGuids.isEmpty()); @@ -139,16 +143,16 @@ public class AuditsWriter { return; } - updateReplicationAttribute(replicationOptionState, targetClusterName, - entityGuids, Constants.ATTR_NAME_REPLICATED_TO_CLUSTER, result.getLastModifiedTimestamp()); + updateReplicationAttribute(replicationOptionState, targetServerName, + entityGuids, Constants.ATTR_NAME_REPLICATED_TO, result.getLastModifiedTimestamp()); } - private void saveClusters() throws AtlasBaseException { - saveCluster(getCurrentClusterName()); + private void saveServers() throws AtlasBaseException { + saveServer(getCurrentClusterName()); - targetClusterName = getClusterNameFromOptions(request.getOptions(), optionKeyReplicatedTo); - if(StringUtils.isNotEmpty(targetClusterName)) { - saveCluster(targetClusterName); + targetServerName = getClusterNameFromOptions(request.getOptions(), optionKeyReplicatedTo); + if(StringUtils.isNotEmpty(targetServerName)) { + saveServer(targetServerName); } } } @@ -156,8 +160,7 @@ public class AuditsWriter { private class ImportAudits { private AtlasImportRequest request; private boolean replicationOptionState; - private String sourceClusterName; - private AtlasCluster sourceCluster; + private String sourceServerName; private String optionKeyReplicatedFrom; public void add(String userName, AtlasImportResult result, @@ -167,10 +170,10 @@ public class AuditsWriter { request = result.getRequest(); replicationOptionState = isReplicationOptionSet(request.getOptions(), optionKeyReplicatedFrom); - saveClusters(); + saveServers(); auditService.add(userName, - sourceClusterName, getCurrentClusterName(), + sourceServerName, getCurrentClusterName(), ExportImportAuditEntry.OPERATION_IMPORT, AtlasType.toJson(result), startTime, endTime, !entityGuids.isEmpty()); @@ -178,23 +181,23 @@ public class AuditsWriter { return; } - updateReplicationAttribute(replicationOptionState, this.sourceClusterName, entityGuids, - Constants.ATTR_NAME_REPLICATED_FROM_CLUSTER, result.getExportResult().getLastModifiedTimestamp()); + updateReplicationAttribute(replicationOptionState, this.sourceServerName, entityGuids, + Constants.ATTR_NAME_REPLICATED_FROM, result.getExportResult().getLastModifiedTimestamp()); } - private void saveClusters() throws AtlasBaseException { - saveCluster(getCurrentClusterName()); + private void saveServers() throws AtlasBaseException { + saveServer(getCurrentClusterName()); - sourceClusterName = getClusterNameFromOptionsState(); - if(StringUtils.isNotEmpty(sourceClusterName)) { - this.sourceCluster = saveCluster(sourceClusterName); + sourceServerName = getClusterNameFromOptionsState(); + if(StringUtils.isNotEmpty(sourceServerName)) { + saveServer(sourceServerName); } } private String getClusterNameFromOptionsState() { return replicationOptionState ? getClusterNameFromOptions(request.getOptions(), optionKeyReplicatedFrom) - : ""; + : StringUtils.EMPTY; } } } http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/repository/src/main/java/org/apache/atlas/repository/impexp/ClusterService.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/impexp/ClusterService.java b/repository/src/main/java/org/apache/atlas/repository/impexp/ClusterService.java deleted file mode 100644 index 5da4b75..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/impexp/ClusterService.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.atlas.repository.impexp; - -import org.apache.atlas.annotation.AtlasService; -import org.apache.atlas.annotation.GraphTransaction; -import org.apache.atlas.exception.AtlasBaseException; -import org.apache.atlas.model.impexp.AtlasCluster; -import org.apache.atlas.model.instance.AtlasEntity; -import org.apache.atlas.model.instance.AtlasObjectId; -import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.apache.atlas.repository.ogm.DataAccess; -import org.apache.atlas.repository.store.graph.AtlasEntityStore; -import org.apache.atlas.repository.store.graph.v2.EntityGraphMapper; -import org.apache.atlas.repository.store.graph.v2.EntityGraphRetriever; -import org.apache.atlas.type.AtlasEntityType; -import org.apache.atlas.type.AtlasStructType; -import org.apache.atlas.type.AtlasTypeRegistry; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; -import java.util.ArrayList; -import java.util.List; - -@AtlasService -public class ClusterService { - private static final Logger LOG = LoggerFactory.getLogger(ClusterService.class); - - private final DataAccess dataAccess; - private final AtlasEntityStore entityStore; - private final AtlasTypeRegistry typeRegistry; - private final EntityGraphRetriever entityGraphRetriever; - - @Inject - public ClusterService(DataAccess dataAccess, AtlasEntityStore entityStore, AtlasTypeRegistry typeRegistry, EntityGraphRetriever entityGraphRetriever) { - this.dataAccess = dataAccess; - this.entityStore = entityStore; - this.typeRegistry = typeRegistry; - this.entityGraphRetriever = entityGraphRetriever; - } - - public AtlasCluster get(AtlasCluster cluster) throws AtlasBaseException { - try { - return dataAccess.load(cluster); - } catch (AtlasBaseException e) { - LOG.error("dataAccess", e); - throw e; - } - } - - @GraphTransaction - public AtlasCluster save(AtlasCluster clusterInfo) { - try { - return dataAccess.save(clusterInfo); - } catch (AtlasBaseException e) { - return clusterInfo; - } - } - - @GraphTransaction - public void updateEntitiesWithCluster(AtlasCluster cluster, List<String> entityGuids, String attributeName) throws AtlasBaseException { - if (cluster != null && StringUtils.isEmpty(cluster.getGuid())) { - return; - } - - AtlasObjectId objectId = getObjectId(cluster); - for (String guid : entityGuids) { - AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo = entityStore.getById(guid); - updateAttribute(entityWithExtInfo, attributeName, objectId); - } - } - - private AtlasObjectId getObjectId(AtlasCluster cluster) { - return new AtlasObjectId(cluster.getGuid(), AtlasCluster.class.getSimpleName()); - } - - - /** - * Attribute passed by name is updated with the value passed. - * @param entityWithExtInfo Entity to be updated - * @param propertyName attribute name - * @param objectId Value to be set for attribute - */ - private void updateAttribute(AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo, - String propertyName, - AtlasObjectId objectId) { - String value = EntityGraphMapper.getSoftRefFormattedValue(objectId); - updateAttribute(entityWithExtInfo.getEntity(), propertyName, value); - for (AtlasEntity e : entityWithExtInfo.getReferredEntities().values()) { - updateAttribute(e, propertyName, value); - } - } - - private void updateAttribute(AtlasEntity entity, String attributeName, Object value) { - if(entity.hasAttribute(attributeName) == false) return; - - try { - AtlasVertex vertex = entityGraphRetriever.getEntityVertex(entity.getGuid()); - if(vertex == null) { - return; - } - - String qualifiedFieldName = getVertexPropertyName(entity, attributeName); - List list = vertex.getListProperty(qualifiedFieldName); - if (CollectionUtils.isEmpty(list)) { - list = new ArrayList(); - } - - if (!list.contains(value)) { - list.add(value); - vertex.setListProperty(qualifiedFieldName, list); - } - } - catch (AtlasBaseException ex) { - LOG.error("error retrieving vertex from guid: {}", entity.getGuid(), ex); - } - } - - private String getVertexPropertyName(AtlasEntity entity, String attributeName) throws AtlasBaseException { - AtlasEntityType type = (AtlasEntityType) typeRegistry.getType(entity.getTypeName()); - AtlasStructType.AtlasAttribute attribute = type.getAttribute(attributeName); - return attribute.getVertexPropertyName(); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/repository/src/main/java/org/apache/atlas/repository/impexp/ExportImportAuditService.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/impexp/ExportImportAuditService.java b/repository/src/main/java/org/apache/atlas/repository/impexp/ExportImportAuditService.java index 89b1110..255b72f 100644 --- a/repository/src/main/java/org/apache/atlas/repository/impexp/ExportImportAuditService.java +++ b/repository/src/main/java/org/apache/atlas/repository/impexp/ExportImportAuditService.java @@ -120,10 +120,10 @@ public class ExportImportAuditService { addParameterIfValueNotEmpty(criteria, ExportImportAuditEntryDTO.PROPERTY_START_TIME, startTime); addParameterIfValueNotEmpty(criteria, ExportImportAuditEntryDTO.PROPERTY_END_TIME, endTime); - addClusterFilterCriteria(criteria, cluster); + addServerFilterCriteria(criteria, cluster); } - private void addClusterFilterCriteria(SearchParameters.FilterCriteria parentCriteria, String cluster) { + private void addServerFilterCriteria(SearchParameters.FilterCriteria parentCriteria, String cluster) { if (StringUtils.isEmpty(cluster)) { return; } @@ -132,8 +132,8 @@ public class ExportImportAuditService { criteria.setCondition(SearchParameters.FilterCriteria.Condition.OR); criteria.setCriterion(new ArrayList<>()); - addParameterIfValueNotEmpty(criteria, ExportImportAuditEntryDTO.PROPERTY_SOURCE_CLUSTER_NAME, cluster); - addParameterIfValueNotEmpty(criteria, ExportImportAuditEntryDTO.PROPERTY_TARGET_CLUSTER_NAME, cluster); + addParameterIfValueNotEmpty(criteria, ExportImportAuditEntryDTO.PROPERTY_SOURCE_SERVER_NAME, cluster); + addParameterIfValueNotEmpty(criteria, ExportImportAuditEntryDTO.PROPERTY_TARGET_SERVER_NAME, cluster); parentCriteria.getCriterion().add(criteria); } @@ -158,8 +158,8 @@ public class ExportImportAuditService { ExportImportAuditEntry entry = new ExportImportAuditEntry(); entry.setUserName(userName); - entry.setSourceClusterName(sourceCluster); - entry.setTargetClusterName(targetCluster); + entry.setSourceServerName(sourceCluster); + entry.setTargetServerName(targetCluster); entry.setOperation(operation); entry.setResultSummary(result); entry.setStartTime(startTime); @@ -167,6 +167,6 @@ public class ExportImportAuditService { save(entry); LOG.info("addAuditEntry: user: {}, source: {}, target: {}, operation: {}", entry.getUserName(), - entry.getSourceClusterName(), entry.getTargetClusterName(), entry.getOperation()); + entry.getSourceServerName(), entry.getTargetServerName(), entry.getOperation()); } } http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/repository/src/main/java/org/apache/atlas/repository/ogm/AtlasClusterDTO.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/ogm/AtlasClusterDTO.java b/repository/src/main/java/org/apache/atlas/repository/ogm/AtlasClusterDTO.java deleted file mode 100644 index 3427bd6..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/ogm/AtlasClusterDTO.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.atlas.repository.ogm; - -import org.apache.atlas.model.impexp.AtlasCluster; -import org.apache.atlas.model.instance.AtlasEntity; -import org.apache.atlas.type.AtlasTypeRegistry; -import org.springframework.stereotype.Component; - -import javax.inject.Inject; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Component -public class AtlasClusterDTO extends AbstractDataTransferObject<AtlasCluster> { - private final String PROPERTY_CLUSTER_NAME = "displayName"; - private final String PROPERTY_QUALIFIED_NAME = "qualifiedName"; - private final String PROPERTY_ADDITIONAL_INFO = "additionalInfo"; - private final String PROPERTY_URLS = "urls"; - - @Inject - public AtlasClusterDTO(AtlasTypeRegistry typeRegistry) { - super(typeRegistry, AtlasCluster.class, AtlasCluster.class.getSimpleName()); - } - - public AtlasCluster from(AtlasEntity entity) { - AtlasCluster cluster = new AtlasCluster(); - - setGuid(cluster, entity); - cluster.setName((String) entity.getAttribute(PROPERTY_CLUSTER_NAME)); - cluster.setQualifiedName((String) entity.getAttribute(PROPERTY_QUALIFIED_NAME)); - cluster.setAdditionalInfo((Map<String,String>) entity.getAttribute(PROPERTY_ADDITIONAL_INFO)); - cluster.setUrls((List<String>) entity.getAttribute(PROPERTY_URLS)); - - return cluster; - } - - public AtlasCluster from(AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo) { - return from(entityWithExtInfo.getEntity()); - } - - @Override - public AtlasEntity toEntity(AtlasCluster obj) { - AtlasEntity entity = getDefaultAtlasEntity(obj); - - entity.setAttribute(PROPERTY_CLUSTER_NAME, obj.getName()); - entity.setAttribute(PROPERTY_QUALIFIED_NAME, obj.getQualifiedName()); - entity.setAttribute(PROPERTY_ADDITIONAL_INFO, obj.getAdditionalInfo()); - entity.setAttribute(PROPERTY_URLS, obj.getUrls()); - - return entity; - } - - @Override - public AtlasEntity.AtlasEntityWithExtInfo toEntityWithExtInfo(AtlasCluster obj) { - return new AtlasEntity.AtlasEntityWithExtInfo(toEntity(obj)); - } - - @Override - public Map<String, Object> getUniqueAttributes(final AtlasCluster obj) { - return new HashMap<String, Object>() {{ - put(PROPERTY_QUALIFIED_NAME, obj.getQualifiedName()); - }}; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/repository/src/main/java/org/apache/atlas/repository/ogm/AtlasServerDTO.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/ogm/AtlasServerDTO.java b/repository/src/main/java/org/apache/atlas/repository/ogm/AtlasServerDTO.java new file mode 100644 index 0000000..2f7ca11 --- /dev/null +++ b/repository/src/main/java/org/apache/atlas/repository/ogm/AtlasServerDTO.java @@ -0,0 +1,85 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.atlas.repository.ogm; + +import org.apache.atlas.model.impexp.AtlasServer; +import org.apache.atlas.model.instance.AtlasEntity; +import org.apache.atlas.type.AtlasTypeRegistry; +import org.springframework.stereotype.Component; + +import javax.inject.Inject; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Component +public class AtlasServerDTO extends AbstractDataTransferObject<AtlasServer> { + private final String PROPERTY_NAME = "name"; + private final String PROPERTY_DISPLAY_NAME = "displayName"; + private final String PROPERTY_FULL_NAME = "fullName"; + private final String PROPERTY_ADDITIONAL_INFO = "additionalInfo"; + private final String PROPERTY_URLS = "urls"; + + @Inject + public AtlasServerDTO(AtlasTypeRegistry typeRegistry) { + super(typeRegistry, AtlasServer.class, AtlasServer.class.getSimpleName()); + } + + public AtlasServer from(AtlasEntity entity) { + AtlasServer cluster = new AtlasServer(); + + setGuid(cluster, entity); + cluster.setName((String) entity.getAttribute(PROPERTY_NAME)); + cluster.setFullName((String) entity.getAttribute(PROPERTY_FULL_NAME)); + cluster.setDisplayName((String) entity.getAttribute(PROPERTY_DISPLAY_NAME)); + cluster.setAdditionalInfo((Map<String,String>) entity.getAttribute(PROPERTY_ADDITIONAL_INFO)); + cluster.setUrls((List<String>) entity.getAttribute(PROPERTY_URLS)); + + return cluster; + } + + public AtlasServer from(AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo) { + return from(entityWithExtInfo.getEntity()); + } + + @Override + public AtlasEntity toEntity(AtlasServer obj) { + AtlasEntity entity = getDefaultAtlasEntity(obj); + + entity.setAttribute(PROPERTY_NAME, obj.getName()); + entity.setAttribute(PROPERTY_DISPLAY_NAME, obj.getDisplayName()); + entity.setAttribute(PROPERTY_FULL_NAME, obj.getFullName()); + entity.setAttribute(PROPERTY_ADDITIONAL_INFO, obj.getAdditionalInfo()); + entity.setAttribute(PROPERTY_URLS, obj.getUrls()); + + return entity; + } + + @Override + public AtlasEntity.AtlasEntityWithExtInfo toEntityWithExtInfo(AtlasServer obj) { + return new AtlasEntity.AtlasEntityWithExtInfo(toEntity(obj)); + } + + @Override + public Map<String, Object> getUniqueAttributes(final AtlasServer obj) { + return new HashMap<String, Object>() {{ + put(PROPERTY_FULL_NAME, obj.getFullName()); + }}; + } +} http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/repository/src/main/java/org/apache/atlas/repository/ogm/ExportImportAuditEntryDTO.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/ogm/ExportImportAuditEntryDTO.java b/repository/src/main/java/org/apache/atlas/repository/ogm/ExportImportAuditEntryDTO.java index fd19c80..f7bc85c 100644 --- a/repository/src/main/java/org/apache/atlas/repository/ogm/ExportImportAuditEntryDTO.java +++ b/repository/src/main/java/org/apache/atlas/repository/ogm/ExportImportAuditEntryDTO.java @@ -40,14 +40,14 @@ public class ExportImportAuditEntryDTO extends AbstractDataTransferObject<Export public static final String PROPERTY_START_TIME = "operationStartTime"; public static final String PROPERTY_END_TIME = "operationEndTime"; public static final String PROPERTY_RESULT_SUMMARY = "resultSummary"; - public static final String PROPERTY_SOURCE_CLUSTER_NAME = "sourceClusterName"; - public static final String PROPERTY_TARGET_CLUSTER_NAME = "targetClusterName"; + public static final String PROPERTY_SOURCE_SERVER_NAME = "sourceServerName"; + public static final String PROPERTY_TARGET_SERVER_NAME = "targetServerName"; private static final Set<String> ATTRIBUTE_NAMES = new HashSet<>(Arrays.asList(PROPERTY_USER_NAME, PROPERTY_OPERATION, PROPERTY_OPERATION_PARAMS, PROPERTY_START_TIME, PROPERTY_END_TIME, PROPERTY_RESULT_SUMMARY, - PROPERTY_SOURCE_CLUSTER_NAME, PROPERTY_TARGET_CLUSTER_NAME)); + PROPERTY_SOURCE_SERVER_NAME, PROPERTY_TARGET_SERVER_NAME)); @Inject public ExportImportAuditEntryDTO(AtlasTypeRegistry typeRegistry) { @@ -68,8 +68,8 @@ public class ExportImportAuditEntryDTO extends AbstractDataTransferObject<Export entry.setOperationParams((String) attributes.get(PROPERTY_OPERATION_PARAMS)); entry.setStartTime((long) attributes.get(PROPERTY_START_TIME)); entry.setEndTime((long) attributes.get(PROPERTY_END_TIME)); - entry.setSourceClusterName((String) attributes.get(PROPERTY_SOURCE_CLUSTER_NAME)); - entry.setTargetClusterName((String) attributes.get(PROPERTY_TARGET_CLUSTER_NAME)); + entry.setSourceServerName((String) attributes.get(PROPERTY_SOURCE_SERVER_NAME)); + entry.setTargetServerName((String) attributes.get(PROPERTY_TARGET_SERVER_NAME)); entry.setResultSummary((String) attributes.get(PROPERTY_RESULT_SUMMARY)); return entry; @@ -94,8 +94,8 @@ public class ExportImportAuditEntryDTO extends AbstractDataTransferObject<Export entity.setAttribute(PROPERTY_OPERATION_PARAMS, obj.getOperationParams()); entity.setAttribute(PROPERTY_START_TIME, obj.getStartTime()); entity.setAttribute(PROPERTY_END_TIME, obj.getEndTime()); - entity.setAttribute(PROPERTY_SOURCE_CLUSTER_NAME, obj.getSourceClusterName()); - entity.setAttribute(PROPERTY_TARGET_CLUSTER_NAME, obj.getTargetClusterName()); + entity.setAttribute(PROPERTY_SOURCE_SERVER_NAME, obj.getSourceServerName()); + entity.setAttribute(PROPERTY_TARGET_SERVER_NAME, obj.getTargetServerName()); entity.setAttribute(PROPERTY_RESULT_SUMMARY, obj.getResultSummary()); return entity; http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/repository/src/test/java/org/apache/atlas/TestModules.java ---------------------------------------------------------------------- diff --git a/repository/src/test/java/org/apache/atlas/TestModules.java b/repository/src/test/java/org/apache/atlas/TestModules.java index 4549d6b..d3d30d5 100644 --- a/repository/src/test/java/org/apache/atlas/TestModules.java +++ b/repository/src/test/java/org/apache/atlas/TestModules.java @@ -41,7 +41,7 @@ import org.apache.atlas.repository.graphdb.AtlasGraph; import org.apache.atlas.repository.graphdb.GraphDBMigrator; import org.apache.atlas.repository.graphdb.janus.migration.GraphDBGraphSONMigrator; import org.apache.atlas.repository.impexp.ExportService; -import org.apache.atlas.repository.ogm.AtlasClusterDTO; +import org.apache.atlas.repository.ogm.AtlasServerDTO; import org.apache.atlas.repository.ogm.ExportImportAuditEntryDTO; import org.apache.atlas.repository.ogm.profiles.AtlasSavedSearchDTO; import org.apache.atlas.repository.ogm.profiles.AtlasUserProfileDTO; @@ -172,7 +172,7 @@ public class TestModules { availableDTOs.addBinding().to(AtlasGlossaryDTO.class); availableDTOs.addBinding().to(AtlasGlossaryTermDTO.class); availableDTOs.addBinding().to(AtlasGlossaryCategoryDTO.class); - availableDTOs.addBinding().to(AtlasClusterDTO.class); + availableDTOs.addBinding().to(AtlasServerDTO.class); availableDTOs.addBinding().to(ExportImportAuditEntryDTO.class); bind(DTORegistry.class).asEagerSingleton(); http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/repository/src/test/java/org/apache/atlas/repository/impexp/AtlasServerServiceTest.java ---------------------------------------------------------------------- diff --git a/repository/src/test/java/org/apache/atlas/repository/impexp/AtlasServerServiceTest.java b/repository/src/test/java/org/apache/atlas/repository/impexp/AtlasServerServiceTest.java new file mode 100644 index 0000000..78865c5 --- /dev/null +++ b/repository/src/test/java/org/apache/atlas/repository/impexp/AtlasServerServiceTest.java @@ -0,0 +1,121 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.atlas.repository.impexp; + +import org.apache.atlas.TestModules; +import org.apache.atlas.exception.AtlasBaseException; +import org.apache.atlas.model.impexp.AtlasServer; +import org.apache.atlas.model.instance.AtlasObjectId; +import org.apache.atlas.repository.Constants; +import org.apache.atlas.store.AtlasTypeDefStore; +import org.apache.atlas.type.AtlasTypeRegistry; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import javax.inject.Inject; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import static org.apache.atlas.repository.Constants.ATTR_NAME_REFERENCEABLE; +import static org.apache.atlas.repository.impexp.ZipFileResourceTestUtils.loadBaseModel; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertNotNull; + +@Guice(modules = TestModules.TestOnlyModule.class) +public class AtlasServerServiceTest { + private final String TOP_LEVEL_ENTITY_NAME = "db1@cl1"; + private final String SERVER_NAME = "testCl1"; + private final String TARGET_SERVER_NAME = "testCl2"; + private final String QUALIFIED_NAME_STOCKS = "stocks@cl1"; + private final String TYPE_HIVE_DB = "hive_db"; + + @Inject + private AtlasTypeDefStore typeDefStore; + + @Inject + private AtlasTypeRegistry typeRegistry; + + @Inject + private AtlasServerService atlasServerService; + private String topLevelEntityGuid = "AAA-BBB-CCC"; + + @BeforeClass + public void setup() throws IOException, AtlasBaseException { + loadBaseModel(typeDefStore, typeRegistry); + } + + @Test + public void saveAndRetrieveServerInfo() throws AtlasBaseException { + AtlasServer expected = getServer(SERVER_NAME + "_1", TOP_LEVEL_ENTITY_NAME, "EXPORT", 0l, TARGET_SERVER_NAME); + AtlasServer expected2 = getServer(TARGET_SERVER_NAME + "_1", TOP_LEVEL_ENTITY_NAME, "IMPORT", 0L, TARGET_SERVER_NAME); + AtlasServer expected3 = getServer(TARGET_SERVER_NAME + "_3", TOP_LEVEL_ENTITY_NAME, "IMPORT", 0, TARGET_SERVER_NAME); + + AtlasServer actual = atlasServerService.save(expected); + AtlasServer actual2 = atlasServerService.save(expected2); + AtlasServer actual3 = atlasServerService.save(expected3); + AtlasServer actual2x = atlasServerService.get(expected2); + + assertNotNull(actual.getGuid()); + assertNotNull(actual2.getGuid()); + assertNotEquals(actual.getGuid(), actual2.getGuid()); + assertNotEquals(actual2.getGuid(), actual3.getGuid()); + + assertEquals(actual2.getGuid(), actual2x.getGuid()); + + + assertEquals(actual.getName(), expected.getName()); + assertEquals(actual.getFullName(), expected.getFullName()); + } + + private AtlasServer getServer(String serverName, String topLevelEntity, String operation, long nextModifiedTimestamp, String targetServerName) { + AtlasServer cluster = new AtlasServer(serverName, serverName); + + Map<String, String> syncMap = new HashMap<>(); + + syncMap.put("topLevelEntity", topLevelEntity); + syncMap.put("operation", operation); + syncMap.put("nextModifiedTimestamp", Long.toString(nextModifiedTimestamp)); + syncMap.put("targetCluster", targetServerName); + + cluster.setAdditionalInfo(syncMap); + + return cluster; + } + + @Test + public void verifyAdditionalInfo() throws AtlasBaseException { + final long expectedLastModifiedTimestamp = 200L; + + AtlasServer expectedCluster = atlasServerService.getCreateAtlasServer(SERVER_NAME, SERVER_NAME); + + String qualifiedNameAttr = Constants.QUALIFIED_NAME.replace(ATTR_NAME_REFERENCEABLE, ""); + AtlasObjectId objectId = new AtlasObjectId(TYPE_HIVE_DB, qualifiedNameAttr, QUALIFIED_NAME_STOCKS); + expectedCluster.setAdditionalInfoRepl(topLevelEntityGuid, expectedLastModifiedTimestamp); + + AtlasServer actualCluster = atlasServerService.save(expectedCluster); + assertEquals(actualCluster.getName(), expectedCluster.getName()); + + int actualModifiedTimestamp = (int) actualCluster.getAdditionalInfoRepl(topLevelEntityGuid); + + assertEquals(actualModifiedTimestamp, expectedLastModifiedTimestamp); + } +} http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/repository/src/test/java/org/apache/atlas/repository/impexp/ClusterServiceTest.java ---------------------------------------------------------------------- diff --git a/repository/src/test/java/org/apache/atlas/repository/impexp/ClusterServiceTest.java b/repository/src/test/java/org/apache/atlas/repository/impexp/ClusterServiceTest.java deleted file mode 100644 index 2e4481e..0000000 --- a/repository/src/test/java/org/apache/atlas/repository/impexp/ClusterServiceTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.atlas.repository.impexp; - -import org.apache.atlas.TestModules; -import org.apache.atlas.exception.AtlasBaseException; -import org.apache.atlas.model.impexp.AtlasCluster; -import org.apache.atlas.model.instance.AtlasObjectId; -import org.apache.atlas.repository.Constants; -import org.apache.atlas.store.AtlasTypeDefStore; -import org.apache.atlas.type.AtlasTypeRegistry; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; - -import javax.inject.Inject; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import static org.apache.atlas.repository.Constants.ATTR_NAME_REFERENCEABLE; -import static org.apache.atlas.repository.impexp.ZipFileResourceTestUtils.loadBaseModel; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotEquals; -import static org.testng.Assert.assertNotNull; - -@Guice(modules = TestModules.TestOnlyModule.class) -public class ClusterServiceTest { - private final String TOP_LEVEL_ENTITY_NAME = "db1@cl1"; - private final String CLUSTER_NAME = "testCl1"; - private final String TARGET_CLUSTER_NAME = "testCl2"; - private final String QUALIFIED_NAME_STOCKS = "stocks@cl1"; - private final String TYPE_HIVE_DB = "hive_db"; - private final String topLevelEntityGuid = "AAA-BBB-CCC"; - - @Inject - private AtlasTypeDefStore typeDefStore; - - @Inject - private AtlasTypeRegistry typeRegistry; - - @Inject - private ClusterService clusterService; - - @BeforeClass - public void setup() throws IOException, AtlasBaseException { - loadBaseModel(typeDefStore, typeRegistry); - } - - @Test - public void saveAndRetrieveClusterInfo() throws AtlasBaseException { - AtlasCluster expected = getCluster(CLUSTER_NAME + "_1", TOP_LEVEL_ENTITY_NAME, "EXPORT", 0l, TARGET_CLUSTER_NAME); - AtlasCluster expected2 = getCluster(TARGET_CLUSTER_NAME + "_1", TOP_LEVEL_ENTITY_NAME, "IMPORT", 0L, TARGET_CLUSTER_NAME); - AtlasCluster expected3 = getCluster(TARGET_CLUSTER_NAME + "_3", TOP_LEVEL_ENTITY_NAME, "IMPORT", 0, TARGET_CLUSTER_NAME); - - AtlasCluster actual = clusterService.save(expected); - AtlasCluster actual2 = clusterService.save(expected2); - AtlasCluster actual3 = clusterService.save(expected3); - AtlasCluster actual2x = clusterService.get(expected2); - - assertNotNull(actual.getGuid()); - assertNotNull(actual2.getGuid()); - assertNotEquals(actual.getGuid(), actual2.getGuid()); - assertNotEquals(actual2.getGuid(), actual3.getGuid()); - - assertEquals(actual2.getGuid(), actual2x.getGuid()); - - - assertEquals(actual.getName(), expected.getName()); - assertEquals(actual.getQualifiedName(), expected.getQualifiedName()); - } - - private AtlasCluster getCluster(String clusterName, String topLevelEntity, String operation, long nextModifiedTimestamp, String targetClusterName) { - AtlasCluster cluster = new AtlasCluster(clusterName, clusterName); - - Map<String, String> syncMap = new HashMap<>(); - - syncMap.put("topLevelEntity", topLevelEntity); - syncMap.put("operation", operation); - syncMap.put("nextModifiedTimestamp", Long.toString(nextModifiedTimestamp)); - syncMap.put("targetCluster", targetClusterName); - - cluster.setAdditionalInfo(syncMap); - - return cluster; - } - - @Test - public void verifyAdditionalInfo() throws AtlasBaseException { - final long expectedLastModifiedTimestamp = 200L; - - AtlasCluster expectedCluster = new AtlasCluster(CLUSTER_NAME, CLUSTER_NAME); - - String qualifiedNameAttr = Constants.QUALIFIED_NAME.replace(ATTR_NAME_REFERENCEABLE, ""); - AtlasObjectId objectId = new AtlasObjectId(TYPE_HIVE_DB, qualifiedNameAttr, QUALIFIED_NAME_STOCKS); - expectedCluster.setAdditionalInfoRepl(topLevelEntityGuid, expectedLastModifiedTimestamp); - - AtlasCluster actualCluster = clusterService.save(expectedCluster); - assertEquals(actualCluster.getName(), expectedCluster.getName()); - - int actualModifiedTimestamp = (int) actualCluster.getAdditionalInfoRepl(topLevelEntityGuid); - - assertEquals(actualModifiedTimestamp, expectedLastModifiedTimestamp); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/repository/src/test/java/org/apache/atlas/repository/impexp/ExportImportAuditServiceTest.java ---------------------------------------------------------------------- diff --git a/repository/src/test/java/org/apache/atlas/repository/impexp/ExportImportAuditServiceTest.java b/repository/src/test/java/org/apache/atlas/repository/impexp/ExportImportAuditServiceTest.java index 13277a3..16fd39d 100644 --- a/repository/src/test/java/org/apache/atlas/repository/impexp/ExportImportAuditServiceTest.java +++ b/repository/src/test/java/org/apache/atlas/repository/impexp/ExportImportAuditServiceTest.java @@ -76,14 +76,14 @@ public class ExportImportAuditServiceTest extends ExportImportTestBase { assertNotEquals(actualEntry.getGuid(), actualEntry2.getGuid()); assertNotNull(actualEntry.getGuid()); - assertEquals(actualEntry.getSourceClusterName(), entry.getSourceClusterName()); - assertEquals(actualEntry.getTargetClusterName(), entry.getTargetClusterName()); + assertEquals(actualEntry.getSourceServerName(), entry.getSourceServerName()); + assertEquals(actualEntry.getTargetServerName(), entry.getTargetServerName()); assertEquals(actualEntry.getOperation(), entry.getOperation()); } @Test public void numberOfSavedEntries_Retrieved() throws AtlasBaseException, InterruptedException { - final String source1 = "cluster1"; + final String source1 = "server1"; final String target1 = "cly"; int MAX_ENTRIES = 5; @@ -100,7 +100,7 @@ public class ExportImportAuditServiceTest extends ExportImportTestBase { private ExportImportAuditEntry retrieveEntry(ExportImportAuditEntry entry) throws AtlasBaseException { List<ExportImportAuditEntry> result = auditService.get(entry.getUserName(), entry.getOperation(), - entry.getSourceClusterName(), + entry.getSourceServerName(), Long.toString(entry.getStartTime()), "", 10, 0); assertNotNull(result); assertEquals(result.size(), 1); @@ -108,10 +108,10 @@ public class ExportImportAuditServiceTest extends ExportImportTestBase { return auditService.get(entry); } - private ExportImportAuditEntry saveAndGet(String sourceClusterName, String operation, String targetClusterName) throws AtlasBaseException { - ExportImportAuditEntry entry = new ExportImportAuditEntry(sourceClusterName, operation); + private ExportImportAuditEntry saveAndGet(String sourceServerName, String operation, String targetServerName) throws AtlasBaseException { + ExportImportAuditEntry entry = new ExportImportAuditEntry(sourceServerName, operation); - entry.setTargetClusterName(targetClusterName); + entry.setTargetServerName(targetServerName); entry.setUserName("default"); entry.setStartTime(System.currentTimeMillis()); entry.setEndTime(System.currentTimeMillis() + 1000L); http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/repository/src/test/java/org/apache/atlas/repository/impexp/ReplicationEntityAttributeTest.java ---------------------------------------------------------------------- diff --git a/repository/src/test/java/org/apache/atlas/repository/impexp/ReplicationEntityAttributeTest.java b/repository/src/test/java/org/apache/atlas/repository/impexp/ReplicationEntityAttributeTest.java index d462491..7ffef7f 100644 --- a/repository/src/test/java/org/apache/atlas/repository/impexp/ReplicationEntityAttributeTest.java +++ b/repository/src/test/java/org/apache/atlas/repository/impexp/ReplicationEntityAttributeTest.java @@ -24,7 +24,7 @@ import org.apache.atlas.RequestContext; import org.apache.atlas.TestModules; import org.apache.atlas.TestUtilsV2; import org.apache.atlas.exception.AtlasBaseException; -import org.apache.atlas.model.impexp.AtlasCluster; +import org.apache.atlas.model.impexp.AtlasServer; import org.apache.atlas.model.impexp.AtlasExportRequest; import org.apache.atlas.model.impexp.AtlasImportRequest; import org.apache.atlas.model.impexp.AtlasImportResult; @@ -63,9 +63,6 @@ public class ReplicationEntityAttributeTest extends ExportImportTestBase { private final String EXPORT_REQUEST_FILE = "export-replicatedTo"; private final String IMPORT_REQUEST_FILE = "import-replicatedFrom"; - private final String DB_GUID = "1637a33e-6512-447b-ade7-249c8cb5344b"; - private final String TABLE_GUID = "df122fc3-5555-40f8-a30f-3090b8a622f8"; - private String REPLICATED_TO_CLUSTER_NAME = ""; private String REPLICATED_FROM_CLUSTER_NAME = ""; @@ -85,7 +82,7 @@ public class ReplicationEntityAttributeTest extends ExportImportTestBase { ImportService importService; @Inject - ClusterService clusterService; + AtlasServerService atlasServerService; private AtlasEntityChangeNotifier mockChangeNotifier = mock(AtlasEntityChangeNotifier.class); private AtlasEntityStoreV2 entityStore; @@ -120,7 +117,7 @@ public class ReplicationEntityAttributeTest extends ExportImportTestBase { assertEquals(zipSource.getCreationOrder().size(), expectedEntityCount); assertCluster(REPLICATED_TO_CLUSTER_NAME, null); - assertReplicationAttribute(Constants.ATTR_NAME_REPLICATED_TO_CLUSTER); + assertReplicationAttribute(Constants.ATTR_NAME_REPLICATED_TO); } @Test(dependsOnMethods = "exportWithReplicationToOption_AddsClusterObjectIdToReplicatedFromAttribute", enabled = false) @@ -129,7 +126,7 @@ public class ReplicationEntityAttributeTest extends ExportImportTestBase { AtlasImportResult importResult = runImportWithParameters(importService, request, zipSource); assertCluster(REPLICATED_FROM_CLUSTER_NAME, importResult); - assertReplicationAttribute(Constants.ATTR_NAME_REPLICATED_FROM_CLUSTER); + assertReplicationAttribute(Constants.ATTR_NAME_REPLICATED_FROM); } private void assertReplicationAttribute(String attrNameReplication) throws AtlasBaseException { @@ -139,13 +136,13 @@ public class ReplicationEntityAttributeTest extends ExportImportTestBase { Object ex = e.getAttribute(attrNameReplication); assertNotNull(ex); - List<String> clusterNameSyncType = (List) ex; - assertEquals(clusterNameSyncType.size(), 1); + List<String> attrValue = (List) ex; + assertEquals(attrValue.size(), 1); } } private void assertCluster(String name, AtlasImportResult importResult) throws AtlasBaseException { - AtlasCluster actual = clusterService.get(new AtlasCluster(name, name)); + AtlasServer actual = atlasServerService.get(new AtlasServer(name, name)); assertNotNull(actual); assertEquals(actual.getName(), name); @@ -155,7 +152,7 @@ public class ReplicationEntityAttributeTest extends ExportImportTestBase { } } - private void assertClusterAdditionalInfo(AtlasCluster cluster, AtlasImportResult importResult) throws AtlasBaseException { + private void assertClusterAdditionalInfo(AtlasServer cluster, AtlasImportResult importResult) throws AtlasBaseException { AtlasExportRequest request = importResult.getExportResult().getRequest(); AtlasEntityType type = (AtlasEntityType) typeRegistry.getType(request.getItemsToExport().get(0).getTypeName()); AtlasEntity.AtlasEntityWithExtInfo entity = entityStore.getByUniqueAttributes(type, request.getItemsToExport().get(0).getUniqueAttributes()); http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/repository/src/test/resources/json/stocksDB-Entities/replicationAttrs.json ---------------------------------------------------------------------- diff --git a/repository/src/test/resources/json/stocksDB-Entities/replicationAttrs.json b/repository/src/test/resources/json/stocksDB-Entities/replicationAttrs.json index 4441036..20279c7 100644 --- a/repository/src/test/resources/json/stocksDB-Entities/replicationAttrs.json +++ b/repository/src/test/resources/json/stocksDB-Entities/replicationAttrs.json @@ -1,6 +1,6 @@ { - "name": "replicatedFromCluster", - "typeName": "array<AtlasCluster>", + "name": "replicatedFrom", + "typeName": "array<AtlasServer>", "cardinality": "SET", "isIndexable": false, "isOptional": true, http://git-wip-us.apache.org/repos/asf/atlas/blob/116fb62c/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java ---------------------------------------------------------------------- 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 6f6921f..55e8b9e 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 @@ -29,18 +29,21 @@ import org.apache.atlas.authorize.AtlasAuthorizationUtils; import org.apache.atlas.discovery.SearchContext; import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.discovery.AtlasSearchResult; +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.*; +import org.apache.atlas.model.impexp.ExportImportAuditEntry; +import org.apache.atlas.model.impexp.MigrationStatus; import org.apache.atlas.model.metrics.AtlasMetrics; +import org.apache.atlas.repository.impexp.AtlasServerService; +import org.apache.atlas.repository.impexp.ExportImportAuditService; import org.apache.atlas.repository.impexp.ExportService; import org.apache.atlas.repository.impexp.ImportService; +import org.apache.atlas.repository.impexp.MigrationProgressService; import org.apache.atlas.repository.impexp.ZipSink; import org.apache.atlas.repository.impexp.ZipSource; -import org.apache.atlas.repository.impexp.ExportImportAuditService; -import org.apache.atlas.repository.impexp.*; import org.apache.atlas.services.MetricsService; import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasTypeRegistry; @@ -126,10 +129,10 @@ public class AdminResource { private final ImportService importService; private final SearchTracker activeSearches; private final AtlasTypeRegistry typeRegistry; - private final MigrationProgressService migrationProgressService; + private final MigrationProgressService migrationProgressService; private final ReentrantLock importExportOperationLock; private final ExportImportAuditService exportImportAuditService; - private final ClusterService clusterService; + private final AtlasServerService atlasServerService; static { try { @@ -143,7 +146,7 @@ public class AdminResource { public AdminResource(ServiceState serviceState, MetricsService metricsService, AtlasTypeRegistry typeRegistry, ExportService exportService, ImportService importService, SearchTracker activeSearches, MigrationProgressService migrationProgressService, - ClusterService clusterService, + AtlasServerService serverService, ExportImportAuditService exportImportAuditService) { this.serviceState = serviceState; this.metricsService = metricsService; @@ -152,7 +155,7 @@ public class AdminResource { this.activeSearches = activeSearches; this.typeRegistry = typeRegistry; this.migrationProgressService = migrationProgressService; - this.clusterService = clusterService; + this.atlasServerService = serverService; this.exportImportAuditService = exportImportAuditService; this.importExportOperationLock = new ReentrantLock(); } @@ -448,24 +451,24 @@ public class AdminResource { /** * Fetch details of a cluster. - * @param clusterName name of target cluster with which it is paired - * @return AtlasCluster + * @param serverName name of target cluster with which it is paired + * @return AtlasServer * @throws AtlasBaseException */ @GET - @Path("/cluster/{clusterName}") + @Path("/server/{serverName}") @Consumes(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE) - public AtlasCluster getCluster(@PathParam("clusterName") String clusterName) throws AtlasBaseException { + public AtlasServer getCluster(@PathParam("serverName") String serverName) throws AtlasBaseException { AtlasPerfTracer perf = null; try { if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "cluster.getCluster(" + clusterName + ")"); + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "cluster.getServer(" + serverName + ")"); } - AtlasCluster cluster = new AtlasCluster(clusterName, clusterName); - return clusterService.get(cluster); + AtlasServer cluster = new AtlasServer(serverName, serverName); + return atlasServerService.get(cluster); } finally { AtlasPerfTracer.log(perf); } @@ -475,7 +478,7 @@ public class AdminResource { @Path("/expimp/audit") @Consumes(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE) - public List<ExportImportAuditEntry> getExportImportAudit(@QueryParam("clusterName") String cluster, + public List<ExportImportAuditEntry> getExportImportAudit(@QueryParam("serverName") String serverName, @QueryParam("userName") String userName, @QueryParam("operation") String operation, @QueryParam("startTime") String startTime, @@ -486,10 +489,10 @@ public class AdminResource { try { if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "getExportImportAudit(" + cluster + ")"); + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "getExportImportAudit(" + serverName + ")"); } - return exportImportAuditService.get(userName, operation, cluster, startTime, endTime, limit, offset); + return exportImportAuditService.get(userName, operation, serverName, startTime, endTime, limit, offset); } finally { AtlasPerfTracer.log(perf); }
