Browse Source

AMBARI-12811: Disable old APIs to manage baseurl values (Nahappan Somasundaram via jluniya)

Jayush Luniya 10 years ago
parent
commit
bbb042f32d

+ 3 - 0
ambari-server/conf/unix/ambari.properties

@@ -92,3 +92,6 @@ skip.service.checks=false
 
 rolling.upgrade.min.stack=HDP-2.2
 rolling.upgrade.max.stack=
+
+# stack version for deprecating base url in metainfo table
+baseurl.api.metainfo.deprecate.min.version=2.2

+ 9 - 0
ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java

@@ -438,6 +438,12 @@ public class Configuration {
   public static final String ALERTS_EXECUTION_SCHEDULER_THREADS_KEY = "alerts.execution.scheduler.maxThreads";
   public static final String ALERTS_EXECUTION_SCHEDULER_THREADS_DEFAULT = "2";
 
+  /**
+   * Repository Base URL is no longer stored in metainfo table starting HDP version 2.2. It is in repo_version table.
+   */
+  public static final String BASEURL_API_DEPRECATED_STACK_VERSION = "baseurl.api.metainfo.deprecate.min.version";
+  public static final String BASEURL_API_DEPRECATED_STACK_VERSION_DEFAULT = "2.2";
+
   private static final Logger LOG = LoggerFactory.getLogger(
       Configuration.class);
 
@@ -636,6 +642,9 @@ public class Configuration {
     configsMap.put(PROXY_ALLOWED_HOST_PORTS, properties.getProperty(
         PROXY_ALLOWED_HOST_PORTS, PROXY_ALLOWED_HOST_PORTS_DEFAULT));
 
+    configsMap.put(BASEURL_API_DEPRECATED_STACK_VERSION, properties.getProperty(
+            BASEURL_API_DEPRECATED_STACK_VERSION, BASEURL_API_DEPRECATED_STACK_VERSION_DEFAULT));
+
     File passFile = new File(configsMap.get(SRVR_KSTR_DIR_KEY) + File.separator
         + configsMap.get(SRVR_CRT_PASS_FILE_KEY));
     String password = null;

+ 19 - 4
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java

@@ -160,6 +160,7 @@ import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartEvent
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStopEvent;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostUpgradeEvent;
 import org.apache.ambari.server.utils.StageUtils;
+import org.apache.ambari.server.utils.VersionUtils;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MultiMap;
 import org.apache.commons.io.IOUtils;
@@ -3501,14 +3502,28 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
   @Override
   public void updateRepositories(Set<RepositoryRequest> requests) throws AmbariException {
     for (RepositoryRequest rr : requests) {
-      if (null == rr.getStackName() || rr.getStackName().isEmpty()) {
-        throw new AmbariException("Stack name must be specified.");
-      }
-
       if (null == rr.getStackVersion() || rr.getStackVersion().isEmpty()) {
         throw new AmbariException("Stack version must be specified.");
       }
 
+      //
+      // If stack version is 2.2.0.0 or greater, error out.
+      //
+      String stackVersion = rr.getStackVersion();
+      String baseUrlDeprecatedStackVersion = configs.getConfigsMap().get(Configuration.BASEURL_API_DEPRECATED_STACK_VERSION);
+      try {
+        if (VersionUtils.compareVersions(stackVersion, baseUrlDeprecatedStackVersion) >= 0) {
+          throw new AmbariException("Stack version (" + stackVersion + ") is not supported");
+        }
+      }
+      catch (NumberFormatException e) {
+        throw new AmbariException("Stack version (" + stackVersion + ") is not supported");
+      }
+
+      if (null == rr.getStackName() || rr.getStackName().isEmpty()) {
+        throw new AmbariException("Stack name must be specified.");
+      }
+
       if (null == rr.getOsType() || rr.getOsType().isEmpty()) {
         throw new AmbariException("OS type must be specified.");
       }

+ 42 - 0
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java

@@ -8481,6 +8481,48 @@ public class AmbariManagementControllerTest {
       LOG.error("Can not complete test. " + exceptionMsg);
     }
 
+    //
+    // HDP stack version 2.2 and above are not supported since the base_url information is stored in repo_version table
+    //
+
+    // Test with stack version 2.2
+    requests.clear();
+    request = new RepositoryRequest(STACK_NAME, "2.2", OS_TYPE, REPO_ID);
+    request.setBaseUrl(baseUrl);
+    requests.add(request);
+    try {
+      controller.updateRepositories(requests);
+    } catch (Exception e) {
+      String exceptionMsg = e.getMessage();
+      assertTrue(exceptionMsg.contains("is not supported"));
+      LOG.error("Can not complete test. " + exceptionMsg);
+    }
+
+    // Test with stack version 2.3 (minor version bumped up)
+    requests.clear();
+    request = new RepositoryRequest(STACK_NAME, "2.3", OS_TYPE, REPO_ID);
+    request.setBaseUrl(baseUrl);
+    requests.add(request);
+    try {
+      controller.updateRepositories(requests);
+    } catch (Exception e) {
+      String exceptionMsg = e.getMessage();
+      assertTrue(exceptionMsg.contains("is not supported"));
+      LOG.error("Can not complete test. " + exceptionMsg);
+    }
+
+    // Test with stack version 3.2 (major version bumped up)
+    requests.clear();
+    request = new RepositoryRequest(STACK_NAME, "3.2", OS_TYPE, REPO_ID);
+    request.setBaseUrl(baseUrl);
+    requests.add(request);
+    try {
+      controller.updateRepositories(requests);
+    } catch (Exception e) {
+      String exceptionMsg = e.getMessage();
+      assertTrue(exceptionMsg.contains("is not supported"));
+      LOG.error("Can not complete test. " + exceptionMsg);
+    }
   }
 
   @Test