You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by pr...@apache.org on 2022/08/15 19:24:00 UTC
[ranger] branch master updated (4ec6c5599 -> 1671b142a)
This is an automated email from the ASF dual-hosted git repository.
pradeep pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git
from 4ec6c5599 RANGER-3816: getResourceACLs() updated to handle macros in resource values
new c4ee5a860 RANGER-3853: Persist db updates immediately using Transaction Management
new 1671b142a RANGER-3854: Persist db updates immediately using Transaction Management in J10056
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../PatchForExternalUserStatusUpdate_J10056.java | 29 ++++++++-
.../patch/PatchForSyncSourceUpdate_J10054.java | 74 +++++++++++++++++-----
2 files changed, 83 insertions(+), 20 deletions(-)
[ranger] 01/02: RANGER-3853: Persist db updates immediately using Transaction Management
Posted by pr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pradeep pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git
commit c4ee5a860424e335025b7eaa261c2289c9c93301
Author: Abhishek Kumar <ab...@gmail.com>
AuthorDate: Tue Aug 9 14:53:04 2022 -0700
RANGER-3853: Persist db updates immediately using Transaction Management
Signed-off-by: pradeep <pr...@apache.org>
---
.../patch/PatchForSyncSourceUpdate_J10054.java | 74 +++++++++++++++++-----
1 file changed, 57 insertions(+), 17 deletions(-)
diff --git a/security-admin/src/main/java/org/apache/ranger/patch/PatchForSyncSourceUpdate_J10054.java b/security-admin/src/main/java/org/apache/ranger/patch/PatchForSyncSourceUpdate_J10054.java
index bbde1a4df..99de47310 100644
--- a/security-admin/src/main/java/org/apache/ranger/patch/PatchForSyncSourceUpdate_J10054.java
+++ b/security-admin/src/main/java/org/apache/ranger/patch/PatchForSyncSourceUpdate_J10054.java
@@ -28,7 +28,13 @@ import org.apache.ranger.util.CLIUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.transaction.support.TransactionTemplate;
import java.util.List;
import java.util.Map;
@@ -39,6 +45,10 @@ public class PatchForSyncSourceUpdate_J10054 extends BaseLoader{
@Autowired
RangerDaoManager daoManager;
+ @Autowired
+ @Qualifier(value = "transactionManager")
+ PlatformTransactionManager txManager;
+
private static final Logger logger = LoggerFactory.getLogger(PatchForSyncSourceUpdate_J10054.class);
@Override
@@ -87,23 +97,39 @@ public class PatchForSyncSourceUpdate_J10054 extends BaseLoader{
if (StringUtils.isNotEmpty(otherAttributes) && StringUtils.isEmpty(syncSource)){
syncSource = (String) gson.fromJson(otherAttributes, Map.class).get(UgsyncCommonConstants.SYNC_SOURCE);
xUser.setSyncSource(syncSource);
- if (StringUtils.isNotEmpty(syncSource)) {
- XXPortalUser xXPortalUser = daoManager.getXXPortalUser().findByLoginId(xUser.getName());
- if (xXPortalUser != null && xXPortalUser.getUserSource() == 0){
- /* updating the user source to external for users which had some sync source prior to upgrade
- but the user source was marked internal to due bugs which were fixed later.
- See RANGER-3297 for more info
- */
- xXPortalUser.setUserSource(1);
- daoManager.getXXPortalUser().update(xXPortalUser);
- if (logger.isDebugEnabled()) {
- logger.debug("USER: Name: " + xUser.getName() + " userSource changed to External");
+
+ TransactionTemplate txTemplate = new TransactionTemplate(txManager);
+ txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
+
+ String finalSyncSource = syncSource;
+ try {
+ txTemplate.execute(new TransactionCallback<Object>() {
+ @Override
+ public Object doInTransaction(TransactionStatus status) {
+ if (StringUtils.isNotEmpty(finalSyncSource)) {
+ XXPortalUser xXPortalUser = daoManager.getXXPortalUser().findByLoginId(xUser.getName());
+ if (xXPortalUser != null && xXPortalUser.getUserSource() == 0){
+ /* updating the user source to external for users which had some sync source prior to upgrade
+ but the user source was marked internal to due bugs which were fixed later.
+ See RANGER-3297 for more info
+ */
+ xXPortalUser.setUserSource(1);
+ daoManager.getXXPortalUser().update(xXPortalUser);
+ if (logger.isDebugEnabled()) {
+ logger.debug("USER: Name: " + xUser.getName() + " userSource changed to External");
+ }
+ }
+ }
+ daoManager.getXXUser().update(xUser);
+ if (logger.isDebugEnabled()) {
+ logger.debug("USER: Name: " + xUser.getName() + " syncSource updated to " + finalSyncSource);
+ }
+ return null;
}
- }
- }
- daoManager.getXXUser().update(xUser);
- if (logger.isDebugEnabled()) {
- logger.debug("USER: Name: " + xUser.getName() + " syncSource updated to " + syncSource);
+ });
+ } catch (Throwable ex) {
+ logger.error("updateSyncSourceForUsers(): Failed to update DB for user: " + xUser.getName() + " ", ex);
+ throw new RuntimeException(ex);
}
} else if (logger.isDebugEnabled()) {
logger.debug("Skipping syncSource update for user: " + xUser.getName() );
@@ -130,7 +156,21 @@ public class PatchForSyncSourceUpdate_J10054 extends BaseLoader{
if (logger.isDebugEnabled()) {
logger.debug("GROUP: Name: " + xGroup.getName() + " syncSource updated to " + syncSource);
}
- daoManager.getXXGroup().update(xGroup);
+
+ TransactionTemplate txTemplate = new TransactionTemplate(txManager);
+ txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
+ try {
+ txTemplate.execute(new TransactionCallback<Object>() {
+ @Override
+ public Object doInTransaction(TransactionStatus status) {
+ daoManager.getXXGroup().update(xGroup);
+ return null;
+ }
+ });
+ } catch (Throwable ex) {
+ logger.error("updateSyncSourceForGroups(): Failed to update DB for group: " + xGroup.getName() + " ", ex);
+ throw new RuntimeException(ex);
+ }
} else if (logger.isDebugEnabled()) {
logger.debug("Skipping syncSource update for group: " + xGroup.getName() );
}
[ranger] 02/02: RANGER-3854: Persist db updates immediately using Transaction Management in J10056
Posted by pr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pradeep pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git
commit 1671b142aed7b7f37257a94f71ea0bce6708b709
Author: Abhishek Kumar <ab...@gmail.com>
AuthorDate: Wed Aug 10 12:56:39 2022 -0700
RANGER-3854: Persist db updates immediately using Transaction Management in J10056
Signed-off-by: pradeep <pr...@apache.org>
---
.../PatchForExternalUserStatusUpdate_J10056.java | 29 +++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/security-admin/src/main/java/org/apache/ranger/patch/PatchForExternalUserStatusUpdate_J10056.java b/security-admin/src/main/java/org/apache/ranger/patch/PatchForExternalUserStatusUpdate_J10056.java
index f1ed0978c..f4a122b38 100644
--- a/security-admin/src/main/java/org/apache/ranger/patch/PatchForExternalUserStatusUpdate_J10056.java
+++ b/security-admin/src/main/java/org/apache/ranger/patch/PatchForExternalUserStatusUpdate_J10056.java
@@ -28,7 +28,13 @@ import org.apache.ranger.util.CLIUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.transaction.support.TransactionTemplate;
@Component
public class PatchForExternalUserStatusUpdate_J10056 extends BaseLoader {
@@ -36,7 +42,11 @@ public class PatchForExternalUserStatusUpdate_J10056 extends BaseLoader {
private static final Logger logger = LoggerFactory.getLogger(PatchForExternalUserStatusUpdate_J10056.class);
@Autowired
- private RangerDaoManager rngrDaoMgr;
+ private RangerDaoManager daoManager;
+
+ @Autowired
+ @Qualifier(value = "transactionManager")
+ PlatformTransactionManager txManager;
public static void main(String[] args) {
try {
@@ -70,14 +80,27 @@ public class PatchForExternalUserStatusUpdate_J10056 extends BaseLoader {
}
private void updateExternalUserStatus() {
- XXPortalUserDao dao = this.rngrDaoMgr.getXXPortalUser();
+ XXPortalUserDao dao = this.daoManager.getXXPortalUser();
List<XXPortalUser> xXPortalUsers = dao.findByUserSourceAndStatus(RangerCommonEnums.USER_EXTERNAL,RangerCommonEnums.ACT_STATUS_DISABLED);
if(CollectionUtils.isNotEmpty(xXPortalUsers)) {
for (XXPortalUser xxPortalUser : xXPortalUsers) {
if (xxPortalUser != null) {
xxPortalUser.setStatus(RangerCommonEnums.ACT_STATUS_ACTIVE);
- dao.update(xxPortalUser, true);
+ TransactionTemplate txTemplate = new TransactionTemplate(txManager);
+ txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
+ try {
+ txTemplate.execute(new TransactionCallback<Object>() {
+ @Override
+ public Object doInTransaction(TransactionStatus status) {
+ dao.update(xxPortalUser, true);
+ return null;
+ }
+ });
+ } catch (Throwable ex) {
+ logger.error("updateExternalUserStatus(): Failed to update DB for user: " + xxPortalUser.getLoginId() + " ", ex);
+ throw new RuntimeException(ex);
+ }
}
}
}