ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pallav...@apache.org
Subject ambari git commit: AMBARI-16289. Upgrade existing capacity scheduler view instance after the Remote Ambari Cluster changes.(Gaurav Nagar via pallavkul)
Date Fri, 27 May 2016 12:01:11 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 2a632995b -> 37af1f039


AMBARI-16289. Upgrade existing capacity scheduler view instance after the Remote Ambari Cluster
changes.(Gaurav Nagar via pallavkul)


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

Branch: refs/heads/trunk
Commit: 37af1f039941c32b702fcdd02a3879dc4f37bf69
Parents: 2a63299
Author: Pallav Kulshreshtha <pallav.kul@gmail.com>
Authored: Fri May 27 17:30:25 2016 +0530
Committer: Pallav Kulshreshtha <pallav.kul@gmail.com>
Committed: Fri May 27 17:30:25 2016 +0530

----------------------------------------------------------------------
 .../server/upgrade/UpgradeCatalog240.java       | 45 ++++++++++++++
 .../server/upgrade/UpgradeCatalog240Test.java   | 64 ++++++++++++++++++++
 2 files changed, 109 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/37af1f03/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
index 870fd15..0deba5d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
@@ -27,6 +27,7 @@ import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -47,9 +48,11 @@ import org.apache.ambari.server.orm.dao.PermissionDAO;
 import org.apache.ambari.server.orm.dao.PrincipalDAO;
 import org.apache.ambari.server.orm.dao.PrincipalTypeDAO;
 import org.apache.ambari.server.orm.dao.PrivilegeDAO;
+import org.apache.ambari.server.orm.dao.RemoteAmbariClusterDAO;
 import org.apache.ambari.server.orm.dao.ResourceTypeDAO;
 import org.apache.ambari.server.orm.dao.RoleAuthorizationDAO;
 import org.apache.ambari.server.orm.dao.UserDAO;
+import org.apache.ambari.server.orm.dao.ViewInstanceDAO;
 import org.apache.ambari.server.orm.dao.WidgetDAO;
 import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
@@ -57,11 +60,13 @@ import org.apache.ambari.server.orm.entities.PermissionEntity;
 import org.apache.ambari.server.orm.entities.PrincipalEntity;
 import org.apache.ambari.server.orm.entities.PrincipalTypeEntity;
 import org.apache.ambari.server.orm.entities.PrivilegeEntity;
+import org.apache.ambari.server.orm.entities.RemoteAmbariClusterEntity;
 import org.apache.ambari.server.orm.entities.ResourceEntity;
 import org.apache.ambari.server.orm.entities.ResourceTypeEntity;
 import org.apache.ambari.server.orm.entities.RoleAuthorizationEntity;
 import org.apache.ambari.server.orm.entities.UserEntity;
 import org.apache.ambari.server.orm.entities.ViewEntityEntity;
+import org.apache.ambari.server.orm.entities.ViewInstanceEntity;
 import org.apache.ambari.server.orm.entities.WidgetEntity;
 import org.apache.ambari.server.security.authorization.ResourceType;
 import org.apache.ambari.server.state.AlertFirmness;
@@ -76,7 +81,9 @@ import org.apache.ambari.server.state.StackInfo;
 import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.state.stack.WidgetLayout;
 import org.apache.ambari.server.state.stack.WidgetLayoutInfo;
+import org.apache.ambari.server.view.DefaultMasker;
 import org.apache.ambari.view.ClusterType;
+import org.apache.ambari.view.MaskException;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -338,6 +345,7 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
     createRolePrincipals();
     updateHDFSWidgetDefinition();
     updateTezViewProperty();
+    upgradeCapSchedulerView();
   }
 
   protected void updateClusterInheritedPermissionsConfig() throws SQLException {
@@ -2170,4 +2178,41 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
     dbAccessor.renameColumn(VIEWINSTANCE_TABLE, cluster_handle_dummy,
       new DBColumnInfo(CLUSTER_HANDLE_COLUMN, Long.class, null, null, true));
   }
+
+  /**
+   *  If Capacity Scheduler instances configured as CUSTOM
+   *  then upgrade them to Remote cluster
+   *
+   * @throws SQLException
+   */
+  protected void upgradeCapSchedulerView() throws SQLException {
+    String capSchedulerViewName = "CAPACITY-SCHEDULER{1.0.0}";
+
+    RemoteAmbariClusterDAO remoteClusterDAO = injector.getInstance(RemoteAmbariClusterDAO.class);
+    ViewInstanceDAO instanceDAO = injector.getInstance(ViewInstanceDAO.class);
+
+    List<ViewInstanceEntity> instances = instanceDAO.findAll();
+
+    for (ViewInstanceEntity instance : instances) {
+      if (instance.getViewName().equals(capSchedulerViewName) && instance.getClusterHandle()
== null) {
+        RemoteAmbariClusterEntity clusterEntity = new RemoteAmbariClusterEntity();
+        clusterEntity.setName(instance.getName() + "-cluster");
+        Map<String, String> propertyMap = instance.getPropertyMap();
+        clusterEntity.setUrl(propertyMap.get("ambari.server.url"));
+        clusterEntity.setUsername(propertyMap.get("ambari.server.username"));
+        try {
+          clusterEntity.setPassword(new DefaultMasker().unmask(propertyMap.get("ambari.server.password")));
+        } catch (MaskException e) {
+          // ignore
+        }
+
+        remoteClusterDAO.save(clusterEntity);
+
+        instance.setClusterHandle(clusterEntity.getId());
+        instance.setClusterType(ClusterType.REMOTE_AMBARI);
+
+        instanceDAO.merge(instance);
+      }
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/37af1f03/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
index 6511cb4..4dedc98 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
@@ -61,17 +61,21 @@ import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.dao.AlertDefinitionDAO;
 import org.apache.ambari.server.orm.dao.ClusterDAO;
 import org.apache.ambari.server.orm.dao.PrivilegeDAO;
+import org.apache.ambari.server.orm.dao.RemoteAmbariClusterDAO;
 import org.apache.ambari.server.orm.dao.StackDAO;
 import org.apache.ambari.server.orm.dao.UserDAO;
+import org.apache.ambari.server.orm.dao.ViewInstanceDAO;
 import org.apache.ambari.server.orm.dao.WidgetDAO;
 import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
 import org.apache.ambari.server.orm.entities.PermissionEntity;
 import org.apache.ambari.server.orm.entities.PrincipalEntity;
 import org.apache.ambari.server.orm.entities.PrivilegeEntity;
+import org.apache.ambari.server.orm.entities.RemoteAmbariClusterEntity;
 import org.apache.ambari.server.orm.entities.ResourceEntity;
 import org.apache.ambari.server.orm.entities.ResourceTypeEntity;
 import org.apache.ambari.server.orm.entities.UserEntity;
+import org.apache.ambari.server.orm.entities.ViewInstanceEntity;
 import org.apache.ambari.server.orm.entities.WidgetEntity;
 import org.apache.ambari.server.security.authorization.ResourceType;
 import org.apache.ambari.server.stack.StackManagerFactory;
@@ -85,6 +89,9 @@ import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.StackInfo;
 import org.apache.ambari.server.state.stack.OsFamily;
+import org.apache.ambari.server.view.DefaultMasker;
+import org.apache.ambari.view.ClusterType;
+import org.apache.ambari.view.MaskException;
 import org.apache.commons.io.FileUtils;
 import org.easymock.Capture;
 import org.easymock.CaptureType;
@@ -473,6 +480,7 @@ public class UpgradeCatalog240Test {
     Method updateClusterInheritedPermissionsConfig = UpgradeCatalog240.class.getDeclaredMethod("updateClusterInheritedPermissionsConfig");
     Method createRolePrincipals = UpgradeCatalog240.class.getDeclaredMethod("createRolePrincipals");
     Method updateHDFSWidget = UpgradeCatalog240.class.getDeclaredMethod("updateHDFSWidgetDefinition");
+    Method upgradeCapSchedulerView = UpgradeCatalog240.class.getDeclaredMethod("upgradeCapSchedulerView");
 
     Capture<String> capturedStatements = newCapture(CaptureType.ALL);
 
@@ -502,6 +510,7 @@ public class UpgradeCatalog240Test {
             .addMockedMethod(updateClusterInheritedPermissionsConfig)
             .addMockedMethod(createRolePrincipals)
             .addMockedMethod(updateHDFSWidget)
+            .addMockedMethod(upgradeCapSchedulerView)
             .createMock();
 
     Field field = AbstractUpgradeCatalog.class.getDeclaredField("dbAccessor");
@@ -526,6 +535,7 @@ public class UpgradeCatalog240Test {
     upgradeCatalog240.createRolePrincipals();
     upgradeCatalog240.updateClusterInheritedPermissionsConfig();
     upgradeCatalog240.updateHDFSWidgetDefinition();
+    upgradeCatalog240.upgradeCapSchedulerView();
 
     replay(upgradeCatalog240, dbAccessor);
 
@@ -1557,5 +1567,59 @@ public class UpgradeCatalog240Test {
     String result = (String) updateAmsEnvContent.invoke(upgradeCatalog240, oldContent);
     Assert.assertEquals(expectedContent, result);
   }
+
+  @Test
+  public void testUpgradeCapSchedulerView() throws SQLException, MaskException {
+    final RemoteAmbariClusterDAO clusterDAO = createNiceMock(RemoteAmbariClusterDAO.class);
+    final ViewInstanceDAO instanceDAO = createNiceMock(ViewInstanceDAO.class);
+
+    final Injector mockInjector = Guice.createInjector(new AbstractModule() {
+      @Override
+      protected void configure() {
+        bind(EntityManager.class).toInstance(createNiceMock(EntityManager.class));
+        bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class));
+        bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
+        bind(RemoteAmbariClusterDAO.class).toInstance(clusterDAO);
+        bind(ViewInstanceDAO.class).toInstance(instanceDAO);
+      }
+    });
+
+    List<ViewInstanceEntity> instances = new ArrayList<ViewInstanceEntity>();
+
+    ViewInstanceEntity instance1 = createNiceMock(ViewInstanceEntity.class);
+    expect(instance1.getViewName()).andReturn("CAPACITY-SCHEDULER{1.0.0}");
+    expect(instance1.getClusterHandle()).andReturn(null);
+    instances.add(instance1);
+
+    Map<String,String> propertyMap = new HashMap<String,String>();
+    String url = "url";
+    String username = "user";
+    String password = "password";
+    propertyMap.put("ambari.server.url",url);
+    propertyMap.put("ambari.server.username",username);
+    propertyMap.put("ambari.server.password",new DefaultMasker().mask(password));
+
+    expect(instance1.getPropertyMap()).andReturn(propertyMap);
+    expect(instance1.getName()).andReturn("instance");
+
+    expect(instanceDAO.findAll()).andReturn(instances);
+
+    Capture<RemoteAmbariClusterEntity> clusterEntityCapture = newCapture();
+    clusterDAO.save(capture(clusterEntityCapture));
+
+    instance1.setClusterType(ClusterType.REMOTE_AMBARI);
+    instance1.setClusterHandle(null);
+    expect(instanceDAO.merge(eq(instance1))).andReturn(instance1);
+
+    replay(clusterDAO, instanceDAO, instance1);
+    mockInjector.getInstance(UpgradeCatalog240.class).upgradeCapSchedulerView();
+
+    assertEquals("instance-cluster", clusterEntityCapture.getValue().getName());
+    assertEquals(url, clusterEntityCapture.getValue().getUrl());
+    assertEquals(username, clusterEntityCapture.getValue().getUsername());
+    assertEquals(password, clusterEntityCapture.getValue().getPassword());
+
+    verify(clusterDAO, instanceDAO, instance1);
+  }
 }
 


Mime
View raw message