From 45125fb446e6687ac1d141d42dc7eb80812f48d0 Mon Sep 17 00:00:00 2001 From: arpit-at Date: Sat, 11 Jan 2025 19:28:22 +0530 Subject: [PATCH] POLICY-171 Incident fix --- .github/workflows/maven.yml | 1 + .../model/instance/BusinessPolicyRequest.java | 58 +++++++++++-------- .../store/graph/v2/EntityGraphMapper.java | 40 +++++++------ 3 files changed, 57 insertions(+), 42 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index f8a09b5589..a6b5274717 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -26,6 +26,7 @@ on: - development - master - lineageondemand + - arpitbulklinkingmaster2 jobs: build: diff --git a/intg/src/main/java/org/apache/atlas/model/instance/BusinessPolicyRequest.java b/intg/src/main/java/org/apache/atlas/model/instance/BusinessPolicyRequest.java index df6883e77b..a7b1878e6c 100644 --- a/intg/src/main/java/org/apache/atlas/model/instance/BusinessPolicyRequest.java +++ b/intg/src/main/java/org/apache/atlas/model/instance/BusinessPolicyRequest.java @@ -64,17 +64,16 @@ public String toString() { public static class AssetComplianceInfo implements Serializable { private static final long serialVersionUID = 1L; - //guids for asset private String assetId; - //guids for complaint rules - private Set complaintRules; + private Set addCompliantGUIDs; - //guids for non complaint rules - private Set nonComplaintRules; + private Set removeCompliantGUIDs; - //guids for complaint policies - private Set complaintPolicies; + + private Set addNonCompliantGUIDs; + + private Set removeNonCompliantGUIDs; public String getAssetId() { @@ -85,39 +84,48 @@ public void setAssetId(String assetId) { this.assetId = assetId; } - public Set getComplaintRules() { - return complaintRules; + public Set getAddCompliantGUIDs() { + return addCompliantGUIDs; } - public void setComplaintRules(Set complaintRules) { - this.complaintRules = complaintRules; + public void setAddCompliantGUIDs(Set addCompliantGUIDs) { + this.addCompliantGUIDs = addCompliantGUIDs; } - public Set getNonComplaintRules() { - return nonComplaintRules; + public Set getRemoveCompliantGUIDs() { + return removeCompliantGUIDs; } - public void setNonComplaintRules(Set nonComplaintRules) { - this.nonComplaintRules = nonComplaintRules; + public void setRemoveCompliantGUIDs(Set removeCompliantGUIDs) { + this.removeCompliantGUIDs = removeCompliantGUIDs; } - public Set getComplaintPolicies() { - return complaintPolicies; + public Set getAddNonCompliantGUIDs() { + return addNonCompliantGUIDs; } - public void setComplaintPolicies(Set complaintPolicies) { - this.complaintPolicies = complaintPolicies; + public void setAddNonCompliantGUIDs(Set addNonCompliantGUIDs) { + this.addNonCompliantGUIDs = addNonCompliantGUIDs; } + public Set getRemoveNonCompliantGUIDs() { + return removeNonCompliantGUIDs; + } + + public void setRemoveNonCompliantGUIDs(Set removeNonCompliantGUIDs) { + this.removeNonCompliantGUIDs = removeNonCompliantGUIDs; + } @Override public String toString() { - return "AssetComplianceInfo{" + - "assetId='" + assetId + '\'' + - ", complaintRules=" + complaintRules + - ", nonComplaintRules=" + nonComplaintRules + - ", complaintPolicies=" + complaintPolicies + - '}'; + final StringBuilder sb = new StringBuilder("AssetComplianceInfo{"); + sb.append("assetId='").append(assetId).append('\''); + sb.append(", addCompliantGUIDs=").append(addCompliantGUIDs); + sb.append(", removeCompliantGUIDs=").append(removeCompliantGUIDs); + sb.append(", addNonCompliantGUIDs=").append(addNonCompliantGUIDs); + sb.append(", removeNonCompliantGUIDs=").append(removeNonCompliantGUIDs); + sb.append('}'); + return sb.toString(); } } } diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java index 6fb58ae1f3..a9531aec5e 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java @@ -4779,21 +4779,28 @@ public AtlasVertex linkBusinessPolicy(final BusinessPolicyRequest.AssetComplianc Set existingNonCompliant = getVertexPolicies(vertex, NON_COMPLIANT_ASSET_POLICY_GUIDS); // Retrieve new policies - Set newCompliantRulesGUIDs = data.getComplaintRules(); - Set newNonCompliantRulesGUIDs = data.getNonComplaintRules(); - Set newCompliantPolicyGUIDs = data.getComplaintPolicies(); + Set addCompliantGUIDs = data.getAddCompliantGUIDs(); + Set addNonCompliantGUIDs = data.getAddNonCompliantGUIDs(); + Set removeCompliantGUIDs = data.getRemoveCompliantGUIDs(); + Set removeNonCompliantGUIDs = data.getAddNonCompliantGUIDs(); - // Calculate effective compliant and non-compliant policies - Set effectiveCompliantGUIDs = calculateEffectivePolicies(existingCompliant, newCompliantRulesGUIDs, newCompliantPolicyGUIDs); - Set effectiveNonCompliantGUIDs = calculateEffectivePolicies(existingNonCompliant, newNonCompliantRulesGUIDs); // Update vertex properties - updateVertexPolicies(vertex, ASSET_POLICY_GUIDS, effectiveCompliantGUIDs); - updateVertexPolicies(vertex, NON_COMPLIANT_ASSET_POLICY_GUIDS, effectiveNonCompliantGUIDs); + addToAttribute(vertex, ASSET_POLICY_GUIDS, addCompliantGUIDs); + removeFromAttribute(vertex, ASSET_POLICY_GUIDS, removeCompliantGUIDs); + + + addToAttribute(vertex, NON_COMPLIANT_ASSET_POLICY_GUIDS, addNonCompliantGUIDs); + removeFromAttribute(vertex, NON_COMPLIANT_ASSET_POLICY_GUIDS, removeNonCompliantGUIDs); // Count and set policies + + Set effectiveCompliantGUIDs = getVertexPolicies(vertex, ASSET_POLICY_GUIDS); + Set effectiveNonCompliantGUIDs = getVertexPolicies(vertex, NON_COMPLIANT_ASSET_POLICY_GUIDS); + int compliantPolicyCount = countPoliciesExcluding(effectiveCompliantGUIDs, "rule"); int nonCompliantPolicyCount = countPoliciesExcluding(effectiveNonCompliantGUIDs, "rule"); + int totalPolicyCount = compliantPolicyCount + nonCompliantPolicyCount; vertex.setProperty(ASSET_POLICIES_COUNT, totalPolicyCount); @@ -4807,20 +4814,19 @@ public AtlasVertex linkBusinessPolicy(final BusinessPolicyRequest.AssetComplianc return vertex; } - @SafeVarargs - private final Set calculateEffectivePolicies(Set existing, Set... additions) { - Set effective = new HashSet<>(existing); - for (Set addition : additions) { - effective.addAll(addition); + private void addToAttribute(AtlasVertex vertex, String propertyKey, Set policies) { + if(ASSET_POLICY_GUIDS.equals(propertyKey)){ + policies.forEach(policyGuid -> vertex.setProperty(ASSET_POLICY_GUIDS, policyGuid)); + }else { + policies.forEach(policyGuid -> vertex.setProperty(NON_COMPLIANT_ASSET_POLICY_GUIDS, policyGuid)); } - return effective; } - private void updateVertexPolicies(AtlasVertex vertex, String propertyKey, Set policies) { + private void removeFromAttribute(AtlasVertex vertex, String propertyKey, Set policies) { if(ASSET_POLICY_GUIDS.equals(propertyKey)){ - policies.forEach(policyGuid -> vertex.setProperty(ASSET_POLICY_GUIDS, policyGuid)); + policies.forEach(policyGuid -> vertex.removePropertyValue(ASSET_POLICY_GUIDS, policyGuid)); }else { - policies.forEach(policyGuid -> vertex.setProperty(NON_COMPLIANT_ASSET_POLICY_GUIDS, policyGuid)); + policies.forEach(policyGuid -> vertex.removePropertyValue(NON_COMPLIANT_ASSET_POLICY_GUIDS, policyGuid)); } }