ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [17/30] ambari git commit: AMBARI-18371. View migration removes current permissions. (Ashwin Rajeev via dipayanb)
Date Fri, 21 Oct 2016 17:20:05 GMT
AMBARI-18371. View migration removes current permissions. (Ashwin Rajeev via dipayanb)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1d5178ce
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1d5178ce
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1d5178ce

Branch: refs/heads/branch-feature-AMBARI-18456
Commit: 1d5178ce727c02d1eb064e210e421ed54428448e
Parents: 5fdc9f9
Author: Dipayan Bhowmick <dipayan.bhowmick@gmail.com>
Authored: Thu Oct 20 22:08:48 2016 +0530
Committer: Dipayan Bhowmick <dipayan.bhowmick@gmail.com>
Committed: Thu Oct 20 22:13:39 2016 +0530

----------------------------------------------------------------------
 .../org/apache/ambari/server/view/ViewRegistry.java   | 14 ++++++++------
 .../server/view/ViewDataMigrationUtilityTest.java     |  3 ---
 2 files changed, 8 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1d5178ce/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java
index 156fd5b..455b4f1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java
@@ -711,10 +711,7 @@ public class ViewRegistry {
               targetInstanceEntity.getName());
     List<PrivilegeEntity> targetInstancePrivileges = privilegeDAO.findByResourceId(targetInstanceEntity.getResource().getId());
     if (targetInstancePrivileges.size() > 0) {
-      LOG.warn("Old privileges will be removed for " + targetInstanceEntity.getName());
-      for (PrivilegeEntity privilegeEntity : targetInstancePrivileges) {
-        removePrivilegeEntity(privilegeEntity);
-      }
+      LOG.warn("Target instance {} already has privileges assigned, these will not be deleted.
Manual clean up may be needed",targetInstanceEntity.getName());
     }
 
     List<PrivilegeEntity> sourceInstancePrivileges = privilegeDAO.findByResourceId(sourceInstanceEntity.getResource().getId());
@@ -723,9 +720,14 @@ public class ViewRegistry {
       targetPrivilege.setPrincipal(sourcePrivilege.getPrincipal());
       targetPrivilege.setResource(targetInstanceEntity.getResource());
       targetPrivilege.setPermission(sourcePrivilege.getPermission());
-      privilegeDAO.create(targetPrivilege);
+      try {
+        privilegeDAO.create(targetPrivilege);
+        targetPrivilege.getPrincipal().getPrivileges().add(sourcePrivilege);
+      } catch (Exception e){
+        LOG.warn("Could not migrate privilege {} ",targetPrivilege);
+        LOG.error("Caught exception",e);
+      }
 
-      targetPrivilege.getPrincipal().getPrivileges().add(sourcePrivilege);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/1d5178ce/ambari-server/src/test/java/org/apache/ambari/server/view/ViewDataMigrationUtilityTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewDataMigrationUtilityTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewDataMigrationUtilityTest.java
index f997589..0306c0a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewDataMigrationUtilityTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewDataMigrationUtilityTest.java
@@ -18,7 +18,6 @@
 package org.apache.ambari.server.view;
 
 import junit.framework.Assert;
-import org.apache.ambari.server.api.services.ViewDataMigrationService;
 import org.apache.ambari.server.orm.entities.ViewEntity;
 import org.apache.ambari.server.orm.entities.ViewInstanceEntity;
 import org.apache.ambari.view.migration.ViewDataMigrationContext;
@@ -34,8 +33,6 @@ import java.util.HashMap;
 import java.util.Map;
 
 import static org.easymock.EasyMock.*;
-import static org.easymock.EasyMock.replay;
-import static org.junit.Assert.*;
 
 /**
  * ViewDataMigrationUtility Tests.


Mime
View raw message