use of org.apache.ranger.plugin.util.ServicePolicies in project ranger by apache.
the class RangerServicePoliciesCache method getServicePolicies.
public ServicePolicies getServicePolicies(String serviceName, Long serviceId, ServiceStore serviceStore) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> RangerServicePoliciesCache.getServicePolicies(" + serviceName + ", " + serviceId + ")");
}
ServicePolicies ret = null;
if (StringUtils.isNotBlank(serviceName) && serviceId != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("useServicePoliciesCache=" + useServicePoliciesCache);
}
ServicePolicies servicePolicies = null;
if (!useServicePoliciesCache) {
if (serviceStore != null) {
try {
servicePolicies = serviceStore.getServicePolicies(serviceName);
} catch (Exception exception) {
LOG.error("getServicePolicies(" + serviceName + "): failed to get latest policies from service-store", exception);
}
} else {
LOG.error("getServicePolicies(" + serviceName + "): failed to get latest policies as service-store is null!");
}
} else {
ServicePoliciesWrapper servicePoliciesWrapper = null;
synchronized (this) {
servicePoliciesWrapper = servicePoliciesMap.get(serviceName);
if (servicePoliciesWrapper != null) {
if (!serviceId.equals(servicePoliciesWrapper.getServiceId())) {
if (LOG.isDebugEnabled()) {
LOG.debug("Service [" + serviceName + "] changed service-id from " + servicePoliciesWrapper.getServiceId() + " to " + serviceId);
LOG.debug("Recreating servicePoliciesWrapper for serviceName [" + serviceName + "]");
}
servicePoliciesMap.remove(serviceName);
servicePoliciesWrapper = null;
}
}
if (servicePoliciesWrapper == null) {
servicePoliciesWrapper = new ServicePoliciesWrapper(serviceId);
servicePoliciesMap.put(serviceName, servicePoliciesWrapper);
}
}
if (serviceStore != null) {
boolean refreshed = servicePoliciesWrapper.getLatestOrCached(serviceName, serviceStore);
if (LOG.isDebugEnabled()) {
LOG.debug("getLatestOrCached returned " + refreshed);
}
} else {
LOG.error("getServicePolicies(" + serviceName + "): failed to get latest policies as service-store is null!");
}
servicePolicies = servicePoliciesWrapper.getServicePolicies();
}
ret = servicePolicies;
} else {
LOG.error("getServicePolicies() failed to get policies as serviceName is null or blank and/or serviceId is null!");
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== RangerServicePoliciesCache.getServicePolicies(" + serviceName + ", " + serviceId + "): count=" + ((ret == null || ret.getPolicies() == null) ? 0 : ret.getPolicies().size()));
}
return ret;
}
Aggregations