Skip to content

Commit

Permalink
Merge pull request #3960 from atlanhq/ns/fix/policy-last-updated
Browse files Browse the repository at this point in the history
DG-1986 | Use policy update time as last refresh time
  • Loading branch information
krsoninikhil authored Jan 9, 2025
2 parents 62996aa + b3f6392 commit a5fb1be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ public ServicePolicies getPoliciesDelta(String serviceName, Map<String, EntityAu

ArrayList<String> policyGuids = new ArrayList<>(policyChanges.keySet());
List<AtlasEntityHeader> allAtlasPolicies = getAtlasPolicies(serviceName, POLICY_BATCH_SIZE, policyGuids);
Date latestUpdateTime = allAtlasPolicies.stream().map(AtlasEntityHeader::getUpdateTime).max(Date::compareTo).orElse(null);
servicePolicies.setPolicyUpdateTime(latestUpdateTime);

List<AtlasEntityHeader> atlasServicePolicies = allAtlasPolicies.stream().filter(x -> serviceName.equals(x.getAttribute(ATTR_POLICY_SERVICE_NAME))).collect(Collectors.toList());
List<RangerPolicyDelta> policiesDelta = getRangerPolicyDelta(service, policyChanges, atlasServicePolicies);
Expand Down
9 changes: 4 additions & 5 deletions webapp/src/main/java/org/apache/atlas/web/rest/AuthREST.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,12 @@ public ServicePolicies downloadPolicies(@PathParam("serviceName") final String s
ServicePolicies ret;
if (usePolicyDelta) {
List<EntityAuditEventV2> auditEvents = getPolicyAuditLogs(serviceName, lastUpdatedTime);
long lastEventTime = auditEvents.isEmpty() ? 0 : auditEvents.get(auditEvents.size() - 1).getCreated();
LOG.info("PolicyDelta: serviceName={}, lastUpdatedTime={}, audit events found={}", serviceName, lastEventTime, auditEvents.size());
LOG.info("PolicyDelta: serviceName={}, lastUpdatedTime={}, audit events found={}", serviceName, lastUpdatedTime, auditEvents.size());
if (auditEvents.isEmpty()) {
return null;
}
Map<String, EntityAuditEventV2.EntityAuditActionV2> policyChanges = policyTransformer.createPolicyChangeMap(serviceName, auditEvents);
ret = policyTransformer.getPoliciesDelta(serviceName, policyChanges, lastEventTime);
ret = policyTransformer.getPoliciesDelta(serviceName, policyChanges, lastUpdatedTime);
} else {
if (!isPolicyUpdated(serviceName, lastUpdatedTime)) {
return null;
Expand Down Expand Up @@ -196,12 +195,12 @@ private List<EntityAuditEventV2> getPolicyAuditLogs(String serviceName, long las
mustClauseList.add(getMap("terms", getMap("typeName", entityUpdateToWatch)));

lastUpdatedTime = lastUpdatedTime == -1 ? 0 : lastUpdatedTime;
mustClauseList.add(getMap("range", getMap("created", getMap("gt", lastUpdatedTime))));
mustClauseList.add(getMap("range", getMap("timestamp", getMap("gt", lastUpdatedTime))));

dsl.put("query", getMap("bool", getMap("must", mustClauseList)));

List<Map<String, Object>> sortClause = new ArrayList<>();
sortClause.add(getMap("created", getMap("order", "asc")));
sortClause.add(getMap("timestamp", getMap("order", "asc")));
dsl.put("sort", sortClause);

int from = 0;
Expand Down

0 comments on commit a5fb1be

Please sign in to comment.