ServiceDBStore extends AbstractServiceStore { @Override public ServicePolicies getServicePoliciesIfUpdated(String serviceName, Long lastKnownVersion, boolean needsBackwardCompatibility) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug("==> ServiceDBStore.getServicePoliciesIfUpdated(" + serviceName + ", " + lastKnownVersion + ", " + needsBackwardCompatibility + ")"); } ServicePolicies ret = null; XXService serviceDbObj = daoMgr.getXXService().findByName(serviceName); if (serviceDbObj == null) { throw new Exception("service does not exist. name=" + serviceName); } XXServiceVersionInfo serviceVersionInfoDbObj = daoMgr.getXXServiceVersionInfo().findByServiceName(serviceName); if (serviceVersionInfoDbObj == null) { LOG.warn("serviceVersionInfo does not exist. name=" + serviceName); } if (lastKnownVersion == null || serviceVersionInfoDbObj == null || serviceVersionInfoDbObj.getPolicyVersion() == null || !lastKnownVersion.equals(serviceVersionInfoDbObj.getPolicyVersion())) { ret = RangerServicePoliciesCache.getInstance().getServicePolicies(serviceName, serviceDbObj.getId(), lastKnownVersion, needsBackwardCompatibility, this); } if (LOG.isDebugEnabled()) { RangerServicePoliciesCache.getInstance().dump(); } if (ret != null && lastKnownVersion != null && lastKnownVersion.equals(ret.getPolicyVersion())) { ret = null; } if (ret != null) { if (LOG.isDebugEnabled()) { LOG.debug("Checking if resource-service:[" + ret.getServiceName() +"] is disabled"); } if (!serviceDbObj.getIsenabled()) { ret = ServicePolicies.copyHeader(ret); } else if (ret.getTagPolicies() != null) { if (LOG.isDebugEnabled()) { LOG.debug("Checking if tag-service:[" + ret.getTagPolicies().getServiceName() +"] is disabled"); } String tagServiceName = ret.getTagPolicies().getServiceName(); if (StringUtils.isNotEmpty(tagServiceName)) { XXService tagService = daoMgr.getXXService().findByName(tagServiceName); if (tagService == null || !tagService.getIsenabled()) { if (LOG.isDebugEnabled()) { LOG.debug("tag-service:[" + tagServiceName +"] is disabled"); } ServicePolicies copy = ServicePolicies.copyHeader(ret); copy.setTagPolicies(null); List<RangerPolicy> copyPolicies = ret.getPolicies() != null ? new ArrayList<>(ret.getPolicies()) : null; List<RangerPolicyDelta> copyPolicyDeltas = ret.getPolicyDeltas() != null ? new ArrayList<>(ret.getPolicyDeltas()) : null; copy.setPolicies(copyPolicies); copy.setPolicyDeltas(copyPolicyDeltas); ret = copy; } } } } if (LOG.isDebugEnabled()) { LOG.debug("<== ServiceDBStore.getServicePoliciesIfUpdated(" + serviceName + ", " + lastKnownVersion + ", " + needsBackwardCompatibility + "): count=" + ((ret == null || ret.getPolicies() == null) ? 0 : ret.getPolicies().size())); } return ret; }  @Override void init(); @PostConstruct void initStore(); @Override RangerServiceDef createServiceDef(RangerServiceDef serviceDef); @Override RangerServiceDef updateServiceDef(RangerServiceDef serviceDef); void deleteServiceDef(Long serviceDefId, Boolean forceDelete); void deleteXXAccessTypeDef(XXAccessTypeDef xAccess); void deleteXXResourceDef(XXResourceDef xRes); @Override RangerServiceDef getServiceDef(Long id); @Override RangerServiceDef getServiceDefByName(String name); @Override RangerServiceDef getServiceDefByDisplayName(String displayName); @Override List<RangerServiceDef> getServiceDefs(SearchFilter filter); @Override PList<RangerServiceDef> getPaginatedServiceDefs(SearchFilter filter); @Override RangerService createService(RangerService service); @Override RangerService updateService(RangerService service, Map<String, Object> options); @Override void deleteService(Long id); @Override List<RangerPolicy> getPoliciesByResourceSignature(String serviceName, String policySignature, Boolean isPolicyEnabled); @Override RangerService getService(Long id); @Override RangerService getServiceByName(String name); @Override RangerService getServiceByDisplayName(String displayName); RangerService getServiceByNameForDP(String name); @Override List<RangerService> getServices(SearchFilter filter); PList<RangerService> getPaginatedServices(SearchFilter filter); @Override RangerPolicy createPolicy(RangerPolicy policy); void createOrMapLabels(XXPolicy xPolicy, Set<String> uniquePolicyLabels); @Override RangerPolicy updatePolicy(RangerPolicy policy); @Override void deletePolicy(RangerPolicy policy); @Override void deletePolicy(RangerPolicy policy, RangerService service); @Override boolean policyExists(Long id); @Override RangerPolicy getPolicy(Long id); @Override List<RangerPolicy> getPolicies(SearchFilter filter); @Override Long getPolicyId(final Long serviceId, final String policyName, final Long zoneId); void getPoliciesInExcel(List<RangerPolicy> policies, HttpServletResponse response); void getPoliciesInCSV(List<RangerPolicy> policies,
			HttpServletResponse response); void getPoliciesInJson(List<RangerPolicy> policies,
			HttpServletResponse response); PList<RangerPolicy> getPaginatedPolicies(SearchFilter filter); @Override List<RangerPolicy> getServicePolicies(Long serviceId, SearchFilter filter); List<RangerPolicy> noZoneFilter(List<RangerPolicy> servicePolicies); PList<RangerPolicy> getPaginatedServicePolicies(Long serviceId, SearchFilter filter); @Override List<RangerPolicy> getServicePolicies(String serviceName, SearchFilter filter); PList<RangerPolicy> getPaginatedServicePolicies(String serviceName, SearchFilter filter); @Override ServicePolicies getServicePoliciesIfUpdated(String serviceName, Long lastKnownVersion, boolean needsBackwardCompatibility); @Override Long getServicePolicyVersion(String serviceName); @Override ServicePolicies getServicePolicyDeltasOrPolicies(String serviceName, Long lastKnownVersion); @Override ServicePolicies getServicePolicyDeltas(String serviceName, Long lastKnownVersion); @Override ServicePolicies getServicePolicies(String serviceName, Long lastKnownVersion); void createZoneDefaultPolicies(Collection<String> serviceNames, RangerSecurityZone zone); void deleteZonePolicies(Collection<String> serviceNames, Long zoneId); static void persistVersionChange(ServiceVersionUpdater serviceVersionUpdater); @Override Boolean getPopulateExistingBaseFields(); @Override void setPopulateExistingBaseFields(Boolean populateExistingBaseFields); RangerPolicy getPolicyFromEventTime(String eventTime, Long policyId); VXString getPolicyVersionList(Long policyId); RangerPolicy getPolicyForVersionNumber(Long policyId, int versionNo); @Override RangerSecurityZone getSecurityZone(Long id); @Override RangerSecurityZone getSecurityZone(String name); @Override long getPoliciesCount(final String serviceName); void putMetaDataInfo(RangerExportPolicyList rangerExportPolicyList); Map<String, String> getMapFromInputStream(InputStream mapStream); Map<String, RangerPolicy> setPolicyMapKeyValue(Map<String, RangerPolicy> policiesMap, RangerPolicy policy); Map<String, RangerPolicy> createPolicyMap(Map<String, String> zoneMappingMap, List<String> sourceZones,
			String destinationZoneName, Map<String, String> servicesMappingMap, List<String> sourceServices,
			List<String> destinationServices, RangerPolicy policy, Map<String, RangerPolicy> policiesMap); void getServiceUpgraded(); void resetPolicyUpdateLog(int retentionInDays, Integer policyChangeType); void resetTagUpdateLog(int retentionInDays, ServiceTags.TagsChangeType tagChangeType); List<String> getPolicyLabels(SearchFilter searchFilter); String getMetricByType(String type); boolean isServiceAdminUser(String serviceName, String userName); static boolean isSupportsPolicyDeltas(); static boolean isSupportsRolesDownloadByService(); @Override Map<String, String> getServiceConfigForPlugin(Long serviceId); static final String SERVICE_ADMIN_USERS; static final String CRYPT_ALGO; static final String ENCRYPT_KEY; static final String SALT; static final Integer ITERATION_COUNT; static boolean SUPPORTS_POLICY_DELTAS; static Integer RETENTION_PERIOD_IN_DAYS; static Integer TAG_RETENTION_PERIOD_IN_DAYS; static final String HIDDEN_PASSWORD_STR; static final String CONFIG_KEY_PASSWORD; static final String ACCESS_TYPE_DECRYPT_EEK; static final String ACCESS_TYPE_GENERATE_EEK; static final String ACCESS_TYPE_GET_METADATA; }
@Test public void test33getServicePoliciesIfUpdated() throws Exception { XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class); XXServiceVersionInfoDao xServiceVersionInfoDao = Mockito.mock(XXServiceVersionInfoDao.class); XXService xService = new XXService(); xService.setAddedByUserId(Id); xService.setCreateTime(new Date()); xService.setDescription("Hdfs service"); xService.setGuid("serviceguid"); xService.setId(Id); xService.setIsEnabled(true); xService.setName("Hdfs"); xService.setPolicyUpdateTime(new Date()); xService.setPolicyVersion(1L); xService.setType(1L); xService.setUpdatedByUserId(Id); xService.setUpdateTime(new Date()); XXServiceVersionInfo xServiceVersionInfo = new XXServiceVersionInfo(); xServiceVersionInfo.setServiceId(Id); xServiceVersionInfo.setPolicyVersion(1L); xServiceVersionInfo.setPolicyUpdateTime(new Date()); xServiceVersionInfo.setTagVersion(1L); xServiceVersionInfo.setTagUpdateTime(new Date()); String serviceName = "HDFS_1"; Long lastKnownVersion = 1l; Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao); Mockito.when(daoManager.getXXServiceVersionInfo()).thenReturn(xServiceVersionInfoDao); Mockito.when(xServiceDao.findByName(serviceName)).thenReturn(xService); Mockito.when(xServiceVersionInfoDao.findByServiceName(serviceName)).thenReturn(xServiceVersionInfo); ServicePolicies dbServicePolicies = serviceDBStore .getServicePoliciesIfUpdated(serviceName, lastKnownVersion, true); Assert.assertNull(dbServicePolicies); }