Repository: atlas Updated Branches: refs/heads/branch-0.8 c3bd5098e -> 660ca463c
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/660ca463 Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/660ca463 Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/660ca463 Branch: refs/heads/branch-0.8 Commit: 660ca463c41ecc5efbc71b6147e40e102724a777 Parents: c3bd509 Author: Ashutosh Mestry <[email protected]> Authored: Wed Aug 29 21:20:19 2018 -0700 Committer: Ashutosh Mestry <[email protected]> Committed: Wed Aug 29 21:20:19 2018 -0700 ---------------------------------------------------------------------- addons/models/0010-base_model.json | 6 +- .../004-base_model_replication_attributes.json | 8 +- .../java/org/apache/atlas/AtlasBaseClient.java | 10 +- .../org/apache/atlas/repository/Constants.java | 4 +- .../views/detail_page/DetailPageLayoutView.js | 2 +- .../apache/atlas/model/impexp/AtlasCluster.java | 155 ------------------- .../apache/atlas/model/impexp/AtlasServer.java | 154 ++++++++++++++++++ .../model/impexp/ExportImportAuditEntry.java | 8 +- .../repository/impexp/AtlasServerService.java | 145 +++++++++++++++++ .../atlas/repository/impexp/AuditsWriter.java | 84 +++++----- .../atlas/repository/impexp/ClusterService.java | 142 ----------------- .../impexp/ExportImportAuditService.java | 14 +- .../atlas/repository/ogm/AtlasClusterDTO.java | 78 ---------- .../atlas/repository/ogm/AtlasServerDTO.java | 78 ++++++++++ .../atlas/repository/ogm/DTORegistry.java | 2 +- .../ogm/ExportImportAuditEntryDTO.java | 14 +- .../impexp/AtlasServerServiceTest.java | 125 +++++++++++++++ .../repository/impexp/ClusterServiceTest.java | 125 --------------- .../impexp/ExportImportAuditServiceTest.java | 14 +- .../impexp/ReplicationEntityAttributeTest.java | 18 +-- .../stocksDB-Entities/replicationAttrs.json | 4 +- .../atlas/web/resources/AdminResource.java | 30 ++-- .../web/resources/AdminExportImportTestIT.java | 18 +-- 23 files changed, 619 insertions(+), 619 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/atlas/blob/660ca463/addons/models/0010-base_model.json ---------------------------------------------------------------------- diff --git a/addons/models/0010-base_model.json b/addons/models/0010-base_model.json index c6d251c..dc9e9d6 100644 --- a/addons/models/0010-base_model.json +++ b/addons/models/0010-base_model.json @@ -116,7 +116,7 @@ ] }, { - "name": "AtlasCluster", + "name": "AtlasServer", "typeVersion": "1.0", "superTypes": [ ], @@ -274,7 +274,7 @@ "isUnique": false }, { - "name": "sourceClusterName", + "name": "sourceServerName", "typeName": "string", "cardinality": "SINGLE", "isIndexable": true, @@ -282,7 +282,7 @@ "isUnique": false }, { - "name": "targetClusterName", + "name": "targetServerName", "typeName": "string", "cardinality": "SINGLE", "isIndexable": true, http://git-wip-us.apache.org/repos/asf/atlas/blob/660ca463/addons/models/patches/004-base_model_replication_attributes.json ---------------------------------------------------------------------- diff --git a/addons/models/patches/004-base_model_replication_attributes.json b/addons/models/patches/004-base_model_replication_attributes.json index 1b49ff7..92c561f 100644 --- a/addons/models/patches/004-base_model_replication_attributes.json +++ b/addons/models/patches/004-base_model_replication_attributes.json @@ -8,8 +8,8 @@ "params": null, "attributeDefs": [ { - "name": "replicatedFromCluster", - "typeName": "array<AtlasCluster>", + "name": "replicatedFrom", + "typeName": "array<AtlasServer>", "cardinality": "SET", "isIndexable": false, "isOptional": true, @@ -19,8 +19,8 @@ } }, { - "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/660ca463/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 d6d2057..96271b7 100644 --- a/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java +++ b/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java @@ -34,7 +34,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; @@ -77,7 +77,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"; @@ -516,9 +516,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/660ca463/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 2733583..311c408 100644 --- a/common/src/main/java/org/apache/atlas/repository/Constants.java +++ b/common/src/main/java/org/apache/atlas/repository/Constants.java @@ -102,8 +102,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/660ca463/dashboardv2/public/js/views/detail_page/DetailPageLayoutView.js ---------------------------------------------------------------------- diff --git a/dashboardv2/public/js/views/detail_page/DetailPageLayoutView.js b/dashboardv2/public/js/views/detail_page/DetailPageLayoutView.js index 14be792..08a3dea 100644 --- a/dashboardv2/public/js/views/detail_page/DetailPageLayoutView.js +++ b/dashboardv2/public/js/views/detail_page/DetailPageLayoutView.js @@ -207,7 +207,7 @@ define(['require', } //to display ReplicationAudit tab - if (collectionJSON && collectionJSON.typeName === "AtlasCluster") { + if (collectionJSON && collectionJSON.typeName === "AtlasServer") { this.$('.replicationTab').show(); this.renderReplicationAuditTableLayoutView(obj); } http://git-wip-us.apache.org/repos/asf/atlas/blob/660ca463/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 320c0c7..0000000 --- a/intg/src/main/java/org/apache/atlas/model/impexp/AtlasCluster.java +++ /dev/null @@ -1,155 +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 org.apache.atlas.model.AtlasBaseModelObject; -import org.apache.atlas.model.instance.AtlasObjectId; -import org.apache.atlas.type.AtlasType; -import org.codehaus.jackson.annotate.JsonAutoDetect; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.map.annotate.JsonSerialize; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE; -import static org.codehaus.jackson.annotate.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/660ca463/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..67d0110 --- /dev/null +++ b/intg/src/main/java/org/apache/atlas/model/impexp/AtlasServer.java @@ -0,0 +1,154 @@ +/** + * 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 org.apache.atlas.model.AtlasBaseModelObject; +import org.apache.atlas.type.AtlasType; +import org.codehaus.jackson.annotate.JsonAutoDetect; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; +import org.codehaus.jackson.map.annotate.JsonSerialize; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE; +import static org.codehaus.jackson.annotate.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 qualifiedName; + private Map<String, String> additionalInfo; + private List<String> urls; + + public AtlasServer() { + urls = new ArrayList<>(); + additionalInfo = new HashMap<>(); + } + + public AtlasServer(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/660ca463/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 2c83c42..6fff6be 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 @@ -95,19 +95,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/660ca463/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..1be7817 --- /dev/null +++ b/repository/src/main/java/org/apache/atlas/repository/impexp/AtlasServerService.java @@ -0,0 +1,145 @@ +/** + * 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.AtlasException; +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.v1.EntityGraphMapper; +import org.apache.atlas.repository.store.graph.v1.EntityGraphRetriever; +import org.apache.atlas.type.AtlasEntityType; +import org.apache.atlas.type.AtlasStructType; +import org.apache.atlas.type.AtlasTypeRegistry; +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; + } + } + + @GraphTransaction + public AtlasServer save(AtlasServer server) throws AtlasBaseException { + return dataAccess.save(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 (list == null) { + 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); + } catch (AtlasException ex) { + LOG.error("error setting property to vertex with 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/660ca463/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..7fb2a3b 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,33 @@ 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 clusterName) throws AtlasBaseException { + AtlasServer cluster = new AtlasServer(clusterName, clusterName); + return atlasServerService.save(cluster); } - 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 clusterName, + String entityGuid, + long lastModifiedTimestamp) throws AtlasBaseException { + + AtlasServer server = new AtlasServer(clusterName, clusterName); + 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 +118,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 +134,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 +144,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 +161,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 +171,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 +182,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/660ca463/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 4462f2c..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/impexp/ClusterService.java +++ /dev/null @@ -1,142 +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.AtlasException; -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.v1.EntityGraphMapper; -import org.apache.atlas.repository.store.graph.v1.EntityGraphRetriever; -import org.apache.atlas.type.AtlasEntityType; -import org.apache.atlas.type.AtlasStructType; -import org.apache.atlas.type.AtlasTypeRegistry; -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 cluster) throws AtlasBaseException { - return dataAccess.save(cluster); - } - - @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 (list == null) { - 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); - } catch (AtlasException ex) { - LOG.error("error setting property to vertex with 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/660ca463/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 8bd52e6..d433c2a 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 @@ -119,18 +119,18 @@ 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(FilterCriteria parentCriteria, String cluster) { + private void addServerFilterCriteria(FilterCriteria parentCriteria, String cluster) { if (StringUtils.isEmpty(cluster)) { return; } FilterCriteria criteria = new FilterCriteria(FilterCriteria.Condition.OR, new ArrayList<FilterCriteria>()); - 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); } @@ -150,8 +150,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); @@ -159,6 +159,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/660ca463/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 a96ca49..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/ogm/AtlasClusterDTO.java +++ /dev/null @@ -1,78 +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 java.util.HashMap; -import java.util.List; -import java.util.Map; - -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"; - - 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/660ca463/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..6343a5d --- /dev/null +++ b/repository/src/main/java/org/apache/atlas/repository/ogm/AtlasServerDTO.java @@ -0,0 +1,78 @@ +/** + * 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 java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class AtlasServerDTO extends AbstractDataTransferObject<AtlasServer> { + private final String PROPERTY_DISPLAY_NAME = "displayName"; + private final String PROPERTY_QUALIFIED_NAME = "qualifiedName"; + private final String PROPERTY_ADDITIONAL_INFO = "additionalInfo"; + private final String PROPERTY_URLS = "urls"; + + 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_DISPLAY_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 AtlasServer from(AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo) { + return from(entityWithExtInfo.getEntity()); + } + + @Override + public AtlasEntity toEntity(AtlasServer obj) { + AtlasEntity entity = getDefaultAtlasEntity(obj); + + entity.setAttribute(PROPERTY_DISPLAY_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(AtlasServer obj) { + return new AtlasEntity.AtlasEntityWithExtInfo(toEntity(obj)); + } + + @Override + public Map<String, Object> getUniqueAttributes(final AtlasServer obj) { + return new HashMap<String, Object>() {{ + put(PROPERTY_QUALIFIED_NAME, obj.getQualifiedName()); + }}; + } +} http://git-wip-us.apache.org/repos/asf/atlas/blob/660ca463/repository/src/main/java/org/apache/atlas/repository/ogm/DTORegistry.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/ogm/DTORegistry.java b/repository/src/main/java/org/apache/atlas/repository/ogm/DTORegistry.java index d417ce7..efcbab5 100644 --- a/repository/src/main/java/org/apache/atlas/repository/ogm/DTORegistry.java +++ b/repository/src/main/java/org/apache/atlas/repository/ogm/DTORegistry.java @@ -37,7 +37,7 @@ public class DTORegistry { registerDTO(savedSearchDTO); registerDTO(userProfileDTO); - registerDTO(new AtlasClusterDTO(typeRegistry)); + registerDTO(new AtlasServerDTO(typeRegistry)); registerDTO(new ExportImportAuditEntryDTO(typeRegistry)); } http://git-wip-us.apache.org/repos/asf/atlas/blob/660ca463/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 963ca51..5f19253 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 @@ -36,14 +36,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)); protected ExportImportAuditEntryDTO(AtlasTypeRegistry typeRegistry) { super(typeRegistry, ExportImportAuditEntry.class); @@ -62,8 +62,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; @@ -88,8 +88,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/660ca463/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..243c64f --- /dev/null +++ b/repository/src/test/java/org/apache/atlas/repository/impexp/AtlasServerServiceTest.java @@ -0,0 +1,125 @@ +/** + * 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"; + + private AtlasTypeDefStore typeDefStore; + private AtlasTypeRegistry typeRegistry; + private AtlasServerService atlasServerService; + private String topLevelEntityGuid = "AAA-BBB-CCC"; + + @Inject + public void UserProfileServiceTest(AtlasTypeRegistry typeRegistry, + AtlasTypeDefStore typeDefStore, + AtlasServerService atlasServerService) { + this.typeRegistry = typeRegistry; + this.typeDefStore = typeDefStore; + this.atlasServerService = atlasServerService; + } + + @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.getQualifiedName(), expected.getQualifiedName()); + } + + 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 = new AtlasServer(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/660ca463/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 6f624c3..0000000 --- a/repository/src/test/java/org/apache/atlas/repository/impexp/ClusterServiceTest.java +++ /dev/null @@ -1,125 +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 AtlasTypeDefStore typeDefStore; - private AtlasTypeRegistry typeRegistry; - private ClusterService clusterService; - private String topLevelEntityGuid = "AAA-BBB-CCC"; - - @Inject - public void UserProfileServiceTest(AtlasTypeRegistry typeRegistry, - AtlasTypeDefStore typeDefStore, - ClusterService clusterService) { - this.typeRegistry = typeRegistry; - this.typeDefStore = typeDefStore; - this.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/660ca463/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/660ca463/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 90232b7..719d6ca 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,21 +24,17 @@ import org.apache.atlas.RequestContextV1; 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; import org.apache.atlas.model.instance.AtlasEntity; -import org.apache.atlas.model.typedef.AtlasBaseTypeDef; import org.apache.atlas.model.typedef.AtlasEntityDef; -import org.apache.atlas.model.typedef.AtlasStructDef; -import org.apache.atlas.model.typedef.AtlasTypesDef; import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.store.graph.v1.AtlasEntityStoreV1; import org.apache.atlas.repository.store.graph.v1.EntityGraphMapper; import org.apache.atlas.store.AtlasTypeDefStore; import org.apache.atlas.type.AtlasEntityType; -import org.apache.atlas.type.AtlasStructType; import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.utils.TestResourceFileUtils; @@ -53,8 +49,6 @@ import java.io.IOException; import java.util.List; import static org.apache.atlas.model.impexp.AtlasExportRequest.OPTION_KEY_REPLICATED_TO; -import static org.apache.atlas.repository.impexp.ZipFileResourceTestUtils.loadBaseModel; -import static org.apache.atlas.repository.impexp.ZipFileResourceTestUtils.loadHiveModel; import static org.apache.atlas.repository.impexp.ZipFileResourceTestUtils.runExportWithParameters; import static org.apache.atlas.repository.impexp.ZipFileResourceTestUtils.runImportWithParameters; import static org.testng.Assert.assertEquals; @@ -89,7 +83,7 @@ public class ReplicationEntityAttributeTest extends ExportImportTestBase { ImportService importService; @Inject - ClusterService clusterService; + AtlasServerService atlasServerService; private AtlasEntityStoreV1 entityStore; private ZipSource zipSource; @@ -123,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") @@ -132,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 { @@ -148,7 +142,7 @@ public class ReplicationEntityAttributeTest extends ExportImportTestBase { } 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); @@ -158,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/660ca463/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/660ca463/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 7d23125..f6cd73a 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 @@ -28,14 +28,14 @@ import org.apache.atlas.authorize.AtlasResourceTypes; import org.apache.atlas.authorize.simple.AtlasAuthorizationUtils; import org.apache.atlas.discovery.SearchContext; 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; import org.apache.atlas.model.impexp.AtlasImportResult; import org.apache.atlas.model.impexp.ExportImportAuditEntry; import org.apache.atlas.model.metrics.AtlasMetrics; -import org.apache.atlas.repository.impexp.ClusterService; +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; @@ -122,7 +122,7 @@ public class AdminResource { private final ExportService exportService; private final ImportService importService; private final SearchTracker activeSearches; - private ClusterService clusterService; + private AtlasServerService atlasServerService; private ExportImportAuditService exportImportAuditService; static { @@ -136,14 +136,14 @@ public class AdminResource { @Inject public AdminResource(ServiceState serviceState, MetricsService metricsService, ExportService exportService, ImportService importService, SearchTracker activeSearches, - ClusterService clusterService, + AtlasServerService serverService, ExportImportAuditService exportImportAuditService) { this.serviceState = serviceState; this.metricsService = metricsService; this.exportService = exportService; this.importService = importService; this.activeSearches = activeSearches; - this.clusterService = clusterService; + this.atlasServerService = serverService; this.exportImportAuditService = exportImportAuditService; this.importExportOperationLock = new ReentrantLock(); } @@ -439,24 +439,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); } @@ -466,7 +466,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, @@ -477,10 +477,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); } http://git-wip-us.apache.org/repos/asf/atlas/blob/660ca463/webapp/src/test/java/org/apache/atlas/web/resources/AdminExportImportTestIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/AdminExportImportTestIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/AdminExportImportTestIT.java index d156054..babf275 100644 --- a/webapp/src/test/java/org/apache/atlas/web/resources/AdminExportImportTestIT.java +++ b/webapp/src/test/java/org/apache/atlas/web/resources/AdminExportImportTestIT.java @@ -21,7 +21,7 @@ package org.apache.atlas.web.resources; import org.apache.atlas.AtlasServiceException; 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; @@ -44,10 +44,10 @@ import static org.testng.Assert.assertTrue; public class AdminExportImportTestIT extends BaseResourceIT { private final String FILE_TO_IMPORT = "stocks-base.zip"; private final String EXPORT_REQUEST_FILE = "export-incremental"; - private final String SOURCE_CLUSTER_NAME = "cl1"; + private final String SOURCE_SERVER_NAME = "cl1"; static final String IMPORT_TRANSFORM_CLEAR_ATTRS = - "{ \"Asset\": { \"*\":[ \"clearAttrValue:replicatedToCluster,replicatedFromCluster\" ] } }"; + "{ \"Asset\": { \"*\":[ \"clearAttrValue:replicatedTo,replicatedFrom\" ] } }"; static final String IMPORT_TRANSFORM_SET_DELETED = "{ \"Asset\": { \"*\":[ \"setDeleted\" ] } }"; @@ -77,7 +77,7 @@ public class AdminExportImportTestIT extends BaseResourceIT { private void performImport(String fileToImport) throws AtlasServiceException { AtlasImportRequest request = new AtlasImportRequest(); - request.getOptions().put(AtlasImportRequest.OPTION_KEY_REPLICATED_FROM, SOURCE_CLUSTER_NAME); + request.getOptions().put(AtlasImportRequest.OPTION_KEY_REPLICATED_FROM, SOURCE_SERVER_NAME); request.getOptions().put(AtlasImportRequest.TRANSFORMS_KEY, IMPORT_TRANSFORM_CLEAR_ATTRS); performImport(fileToImport, request); @@ -100,11 +100,11 @@ public class AdminExportImportTestIT extends BaseResourceIT { assertEquals(result.getProcessedEntities().size(), 37); } - private void assertReplicationData(String clusterName) throws AtlasServiceException { - AtlasCluster cluster = atlasClientV2.getCluster(clusterName); - assertNotNull(cluster); - assertNotNull(cluster.getAdditionalInfo()); - assertTrue(cluster.getAdditionalInfo().size() > 0); + private void assertReplicationData(String serverName) throws AtlasServiceException { + AtlasServer server = atlasClientV2.getServer(serverName); + assertNotNull(server); + assertNotNull(server.getAdditionalInfo()); + assertTrue(server.getAdditionalInfo().size() > 0); } @AfterClass
