Skip to content

Commit

Permalink
Revert "Use service name to separate tag policies during delta apply"
Browse files Browse the repository at this point in the history
This reverts commit 4bf4f76.
  • Loading branch information
sumandas0 committed Dec 10, 2024
1 parent 4bf4f76 commit ed4a51e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ public RangerPolicyDelta(final Long id, final Integer changeType, final Long pol

public void setPolicy(RangerPolicy policy) { this.policy = policy; }

@JsonIgnore
public String getPolicyServiceName() { return policy != null ? policy.getService() : null;}

@Override
public String toString() {
return "id:" + id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class EmbeddedServiceDefsUtil {
private static final String PROPERTY_SUPPORTED_SERVICE_DEFS = "ranger.supportedcomponents";
private Set<String> supportedServiceDefs;
public static final String EMBEDDED_SERVICEDEF_TAG_NAME = "tag";
public static final String EMBEDDED_SERVICEDEF_TAG_SERVICE_NAME = "atlas_tag";
public static final String EMBEDDED_SERVICEDEF_HDFS_NAME = "hdfs";
public static final String EMBEDDED_SERVICEDEF_HBASE_NAME = "hbase";
public static final String EMBEDDED_SERVICEDEF_HIVE_NAME = "hive";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public class RangerPolicyDeltaUtil {

private static final Log PERF_POLICY_DELTA_LOG = RangerPerfTracer.getPerfLogger("policy.delta");

public static List<RangerPolicy> applyDeltas(List<RangerPolicy> policies, List<RangerPolicyDelta> deltas, String serviceName) {
public static List<RangerPolicy> applyDeltas(List<RangerPolicy> policies, List<RangerPolicyDelta> deltas, String serviceType) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> applyDeltas(serviceType=" + serviceName + ")");
LOG.debug("==> applyDeltas(serviceType=" + serviceType + ")");
}

List<RangerPolicy> ret;
Expand All @@ -52,27 +52,27 @@ public static List<RangerPolicy> applyDeltas(List<RangerPolicy> policies, List<R
perf = RangerPerfTracer.getPerfTracer(PERF_POLICY_DELTA_LOG, "RangerPolicyDelta.applyDeltas()");
}

boolean hasExpectedServiceName = false;
boolean hasExpectedServiceType = false;

if (CollectionUtils.isNotEmpty(deltas)) {
if (LOG.isDebugEnabled()) {
LOG.debug("applyDeltas(deltas=" + Arrays.toString(deltas.toArray()) + ", serviceType=" + serviceName + ")");
LOG.debug("applyDeltas(deltas=" + Arrays.toString(deltas.toArray()) + ", serviceType=" + serviceType + ")");
}

for (RangerPolicyDelta delta : deltas) {
if (serviceName.equals(delta.getPolicyServiceName())) {
hasExpectedServiceName = true;
if (serviceType.equals(delta.getServiceType())) {
hasExpectedServiceType = true;
break;
} else if (!serviceName.equals(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_TAG_SERVICE_NAME) && !delta.getPolicyServiceName().equals(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_TAG_SERVICE_NAME)) {
LOG.warn("Found unexpected serviceType in policyDelta:[" + delta + "]. Was expecting serviceType:[" + serviceName + "]. Should NOT have come here!! Ignoring delta and continuing");
} else if (!serviceType.equals(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_TAG_NAME) && !delta.getServiceType().equals(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_TAG_NAME)) {
LOG.warn("Found unexpected serviceType in policyDelta:[" + delta + "]. Was expecting serviceType:[" + serviceType + "]. Should NOT have come here!! Ignoring delta and continuing");
}
}

if (hasExpectedServiceName) {
if (hasExpectedServiceType) {
ret = new ArrayList<>(policies);

for (RangerPolicyDelta delta : deltas) {
if (!serviceName.equals(delta.getPolicyServiceName())) {
if (!serviceType.equals(delta.getServiceType())) {
continue;
}

Expand Down Expand Up @@ -132,7 +132,7 @@ public static List<RangerPolicy> applyDeltas(List<RangerPolicy> policies, List<R
}
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("applyDeltas - none of the deltas is for " + serviceName + ")");
LOG.debug("applyDeltas - none of the deltas is for " + serviceType + ")");
}
ret = policies;
}
Expand All @@ -146,7 +146,7 @@ public static List<RangerPolicy> applyDeltas(List<RangerPolicy> policies, List<R
RangerPerfTracer.log(perf);

if (LOG.isDebugEnabled()) {
LOG.debug("<== applyDeltas(serviceType=" + serviceName + "): " + ret);
LOG.debug("<== applyDeltas(serviceType=" + serviceType + "): " + ret);
}
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public static ServicePolicies applyDelta(final ServicePolicies servicePolicies,
List<RangerPolicy> oldResourcePolicies = policyEngine.getResourcePolicies();
List<RangerPolicy> oldTagPolicies = policyEngine.getTagPolicies();

List<RangerPolicy> newResourcePolicies = RangerPolicyDeltaUtil.applyDeltas(oldResourcePolicies, servicePolicies.getPolicyDeltas(), servicePolicies.getServiceName());
List<RangerPolicy> newResourcePolicies = RangerPolicyDeltaUtil.applyDeltas(oldResourcePolicies, servicePolicies.getPolicyDeltas(), servicePolicies.getServiceDef().getName());

ret.setPolicies(newResourcePolicies);

Expand All @@ -402,7 +402,7 @@ public static ServicePolicies applyDelta(final ServicePolicies servicePolicies,
if (LOG.isDebugEnabled()) {
LOG.debug("applyingDeltas for tag policies");
}
newTagPolicies = RangerPolicyDeltaUtil.applyDeltas(oldTagPolicies, servicePolicies.getPolicyDeltas(), servicePolicies.getTagPolicies().getServiceName());
newTagPolicies = RangerPolicyDeltaUtil.applyDeltas(oldTagPolicies, servicePolicies.getPolicyDeltas(), servicePolicies.getTagPolicies().getServiceDef().getName());
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("No need to apply deltas for tag policies");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,13 +710,13 @@ private RangerPolicy getRangerPolicy(AtlasEntityHeader atlasPolicy, String servi
//policy.setId(atlasPolicy.getGuid());
policy.setName((String) atlasPolicy.getAttribute(QUALIFIED_NAME));
policy.setService((String) atlasPolicy.getAttribute(ATTR_POLICY_SERVICE_NAME));
policy.setServiceType(serviceType);
// // Adding atlas as serviceType for tag policies, as atlas_tag doesn't have all the resource available for evaluation
// if (serviceType != null && serviceType.equals(TAG_RESOURCE_NAME) && policy.getService().equals("atlas")) {
// policy.setServiceType("atlas");
// } else {
// policy.setServiceType(serviceType);
// }

// Adding atlas as serviceType for tag policies, as atlas_tag doesn't have all the resource available for evaluation
if (serviceType != null && serviceType.equals(TAG_RESOURCE_NAME) && policy.getService().equals("atlas")) {
policy.setServiceType("atlas");
} else {
policy.setServiceType(serviceType);
}

policy.setGuid(atlasPolicy.getGuid());
policy.setCreatedBy(atlasPolicy.getCreatedBy());
Expand Down

0 comments on commit ed4a51e

Please sign in to comment.