Browse Source

AMBARI-17302. Ambari-server upgrade results in "DB configs consistency check failed. ".(vbrodetskyi)

Vitaly Brodetskyi 9 years ago
parent
commit
de89a9d4e7

+ 2 - 2
ambari-server/pom.xml

@@ -83,8 +83,8 @@
             <configuration>
               <name>ambariFullVersion</name>
               <value>${project.version}</value>
-              <regex>^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\-([0-9]+).*</regex>
-              <replacement>$1.$2.$3.$4-$5</replacement>
+              <regex>^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)(\.|-)([0-9]+).*</regex>
+              <replacement>$1.$2.$3.$4-$6</replacement>
               <failIfNoMatch>false</failIfNoMatch>
             </configuration>
           </execution>

+ 26 - 4
ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java

@@ -18,6 +18,10 @@
 
 package org.apache.ambari.server.upgrade;
 
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import javax.persistence.TypedQuery;
+
 import java.io.File;
 import java.io.FileReader;
 import java.lang.reflect.Type;
@@ -111,10 +115,6 @@ import com.google.inject.Inject;
 import com.google.inject.Injector;
 import com.google.inject.persist.Transactional;
 
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-import javax.persistence.TypedQuery;
-
 /**
  * Upgrade catalog for version 2.4.0.
  */
@@ -160,8 +160,11 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
   protected static final String HOST_VERSION_TABLE = "host_version";
   protected static final String PHOENIX_QUERY_SERVER_PRINCIPAL_KEY = "phoenix.queryserver.kerberos.principal";
   protected static final String PHOENIX_QUERY_SERVER_KEYTAB_KEY = "phoenix.queryserver.keytab.file";
+  protected static final String DEFAULT_CONFIG_VERSION = "version1";
+  protected static final String SLIDER_SERVICE_NAME = "SLIDER";
 
   private static final String OOZIE_ENV_CONFIG = "oozie-env";
+  private static final String SLIDER_CLIENT_CONFIG = "slider-client";
   private static final String HIVE_ENV_CONFIG = "hive-env";
   private static final String AMS_SITE = "ams-site";
   public static final String TIMELINE_METRICS_SINK_COLLECTION_PERIOD = "timeline.metrics.sink.collection.period";
@@ -385,6 +388,7 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
     fixAuthorizationDescriptions();
     removeAuthorizations();
     addConnectionTimeoutParamForWebAndMetricAlerts();
+    addSliderClientConfig();
   }
 
   protected void updateClusterInheritedPermissionsConfig() throws SQLException {
@@ -601,6 +605,24 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
     }
   }
 
+  protected void addSliderClientConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    ConfigHelper configHelper = ambariManagementController.getConfigHelper();
+    Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+
+    for (final Cluster cluster : clusterMap.values()) {
+      Set<String> installedServices = cluster.getServices().keySet();
+      if (installedServices.contains(SLIDER_SERVICE_NAME)) {
+        Config sliderClientConfig = cluster.getDesiredConfigByType(SLIDER_CLIENT_CONFIG);
+        if (sliderClientConfig == null) {
+          configHelper.createConfigType(cluster, ambariManagementController, SLIDER_CLIENT_CONFIG,
+                  new HashMap<String, String>(), AUTHENTICATED_USER_NAME, "");
+        }
+      }
+    }
+  }
+
   protected void updateAlerts() {
     // map of alert_name -> property_name -> visibility_value
     final Map<String, String> hdfsVisibilityMap = new HashMap<String, String>(){{

+ 49 - 0
ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java

@@ -557,6 +557,7 @@ public class UpgradeCatalog240Test {
     Method fixAuthorizationDescriptions = UpgradeCatalog240.class.getDeclaredMethod("fixAuthorizationDescriptions");
     Method removeAuthorizations = UpgradeCatalog240.class.getDeclaredMethod("removeAuthorizations");
     Method addConnectionTimeoutParamForWebAndMetricAlerts = AbstractUpgradeCatalog.class.getDeclaredMethod("addConnectionTimeoutParamForWebAndMetricAlerts");
+    Method addSliderClientConfig = UpgradeCatalog240.class.getDeclaredMethod("addSliderClientConfig");
 
     Capture<String> capturedStatements = newCapture(CaptureType.ALL);
 
@@ -597,6 +598,7 @@ public class UpgradeCatalog240Test {
             .addMockedMethod(removeAuthorizations)
             .addMockedMethod(addConnectionTimeoutParamForWebAndMetricAlerts)
             .addMockedMethod(updateHBaseConfigs)
+            .addMockedMethod(addSliderClientConfig)
             .createMock();
 
     Field field = AbstractUpgradeCatalog.class.getDeclaredField("dbAccessor");
@@ -632,6 +634,7 @@ public class UpgradeCatalog240Test {
     upgradeCatalog240.removeAuthorizations();
     upgradeCatalog240.addConnectionTimeoutParamForWebAndMetricAlerts();
     upgradeCatalog240.updateHBaseConfigs();
+    upgradeCatalog240.addSliderClientConfig();
 
     replay(upgradeCatalog240, dbAccessor);
 
@@ -2056,5 +2059,51 @@ public class UpgradeCatalog240Test {
     upgradeCatalog240.updatePhoenixConfigs();
     easyMockSupport.verifyAll();
   }
+
+
+  @Test
+  public void testAddSliderClientConfig() throws Exception{
+    EasyMockSupport easyMockSupport = new EasyMockSupport();
+    final AmbariManagementController mockAmbariManagementController = easyMockSupport.createNiceMock(AmbariManagementController.class);
+    final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class);
+    final Cluster mockClusterExpected = easyMockSupport.createNiceMock(Cluster.class);
+    final ConfigHelper configHelper = easyMockSupport.createNiceMock(ConfigHelper.class);
+    final Service serviceSlider = easyMockSupport.createNiceMock(Service.class);
+
+    Map<String, Service> servicesMap = new HashMap<>();
+    servicesMap.put("SLIDER", serviceSlider);
+
+    final Injector mockInjector = Guice.createInjector(new AbstractModule() {
+      @Override
+      protected void configure() {
+        bind(AmbariManagementController.class).toInstance(mockAmbariManagementController);
+        bind(Clusters.class).toInstance(mockClusters);
+        bind(EntityManager.class).toInstance(entityManager);
+        bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class));
+        bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
+      }
+    });
+
+    expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once();
+    expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{
+      put("normal", mockClusterExpected);
+    }}).atLeastOnce();
+    expect(mockAmbariManagementController.getConfigHelper()).andReturn(configHelper).once();
+    expect(mockClusterExpected.getServices()).andReturn(servicesMap).once();
+    expect(mockClusterExpected.getDesiredConfigByType("slider-client")).andReturn(null).once();
+
+
+    configHelper.createConfigType(mockClusterExpected, mockAmbariManagementController, "slider-client",
+            new HashMap<String, String>(), "ambari-upgrade", "");
+    expectLastCall().once();
+
+    easyMockSupport.replayAll();
+    mockInjector.getInstance(UpgradeCatalog240.class).addSliderClientConfig();
+    easyMockSupport.verifyAll();
+
+
+  }
+
+
 }