Skip to content

Commit

Permalink
RANGER-5104: Ranger Upgrade is failing while executing the PatchPreSq…
Browse files Browse the repository at this point in the history
…l057_ForUpdateToUniqueGUID_J10052 (#511)

* RANGER-5104: Ranger Upgrade is failing while executing the PatchPreSql057_ForUpdateToUniqueGUID_J10052

* Fix typo in db_setup.py

---------

Co-authored-by: Abhishek Kumar <[email protected]>
Change-Id: I214907b0487c1f38bf7e5854ea43810da8767c1c
  • Loading branch information
pradeepagrawal8184 and kumaab committed Jan 27, 2025
1 parent bb80bb4 commit 36fcf76
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
4 changes: 2 additions & 2 deletions security-admin/scripts/db_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ def apply_patches(self, db_name, db_user, db_password, PATCHES_PATH):
#getting Java patch which needs to be run before this DB patch.
pre_dict = self.get_pre_post_java_patches(prefix_for_preSql_patch)
if pre_dict:
log ("[I] ruunig pre java patch:[{}]".format(pre_dict),"info")
log ("[I] Running Pre Java Patch:[{}]".format(pre_dict),"info")
self.execute_java_patches(xa_db_host, db_user, db_password, db_name, pre_dict)
self.import_db_patches(db_name, db_user, db_password, currentPatch)
#getting Java patch which needs to be run immediately after this DB patch.
post_dict = self.get_pre_post_java_patches(prefix_for_postSql_patch)
if post_dict:
log ("[I] ruunig post java patch:[{}]".format(post_dict),"info")
log ("[I] Running Post Java Patch:[{}]".format(post_dict),"info")
self.execute_java_patches(xa_db_host, db_user, db_password, db_name, post_dict)
self.update_applied_patches_status(db_name, db_user, db_password, "DB_PATCHES")
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,19 @@ public List<RangerSecurityZoneHeaderInfo> findAllZoneHeaderInfosByServiceId(Long

return securityZoneList;
}

public List<XXSecurityZone> getAllZoneIdNames() {
@SuppressWarnings("unchecked")
List<Object[]> results = getEntityManager().createNamedQuery("XXSecurityZone.getAllZoneIdNames").getResultList();

List<XXSecurityZone> securityZoneList = new ArrayList<XXSecurityZone>(results.size());
for (Object[] result : results) {
XXSecurityZone xXSecurityZone = new XXSecurityZone();
xXSecurityZone.setId((Long) result[0]);
xXSecurityZone.setName((String) result[1]);
securityZoneList.add(xXSecurityZone);
}

return securityZoneList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,19 @@ public void printStats() {
private void updatePolicyGUIDToUniqueValue() throws Exception {
logger.info("==> updatePolicyGUIDToUniqueValue() ");

List<XXSecurityZone> allXXZones = null;
List<XXService> allXXService = null;

allXXZones = daoMgr.getXXSecurityZoneDao().getAll();
allXXService = daoMgr.getXXService().getAll();
List<XXSecurityZone> allXXZones = daoMgr.getXXSecurityZoneDao().getAllZoneIdNames();
List<XXService> allXXService = daoMgr.getXXService().getAll();

if (CollectionUtils.isNotEmpty(allXXZones) && CollectionUtils.isNotEmpty(allXXService)) {
logger.info("Total number of zones " + allXXZones.size() +", service :" +allXXService.size());
for (XXSecurityZone xSecurityZone : allXXZones) {
for (XXService xService : allXXService) {
logger.info("serching duplicate guid policies for service :" + xService.getName() + " zone : "
+ xSecurityZone.getName());
List<String> duplicateGuidList = daoMgr.getXXPolicy()
.findDuplicateGUIDByServiceIdAndZoneId(xService.getId(), xSecurityZone.getId());
logger.info("searching duplicate guid policies for service :" + xService.getName() + " zone : " + xSecurityZone.getName());
List<String> duplicateGuidList = daoMgr.getXXPolicy().findDuplicateGUIDByServiceIdAndZoneId(xService.getId(), xSecurityZone.getId());
if (CollectionUtils.isNotEmpty(duplicateGuidList)) {
logger.info("Total number of duplicate GUIDs :" + duplicateGuidList.size() + " for service :"
+ xService.getName() + " and zone :" + xSecurityZone.getName());
logger.info("Total number of duplicate GUIDs :" + duplicateGuidList.size() + " for service :" + xService.getName() + " and zone :" + xSecurityZone.getName());
for (String guid : duplicateGuidList) {
List<XXPolicy> xxPolicyList = daoMgr.getXXPolicy().findPolicyByGUIDAndServiceIdAndZoneId(
guid, xService.getId(), xSecurityZone.getId());
List<XXPolicy> xxPolicyList = daoMgr.getXXPolicy().findPolicyByGUIDAndServiceIdAndZoneId(guid, xService.getId(), xSecurityZone.getId());
boolean isFirstElement = false;
if (CollectionUtils.isNotEmpty(xxPolicyList)) {
isFirstElement = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,12 @@
</query>
</named-query>

<named-query name="XXSecurityZone.getAllZoneIdNames">
<query>
select obj.id, obj.name from XXSecurityZone obj
</query>
</named-query>

<named-query name="XXSecurityZoneRefGroup.findByZoneId">
<query>
select obj from XXSecurityZoneRefGroup obj where obj.zoneId = :zoneId
Expand Down

0 comments on commit 36fcf76

Please sign in to comment.