ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From srima...@apache.org
Subject ambari git commit: AMBARI-12114. RU: prereqs need to be upgrade pack specific (srimanth)
Date Wed, 24 Jun 2015 18:21:04 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk ecb7eb740 -> be85313e2


AMBARI-12114. RU: prereqs need to be upgrade pack specific (srimanth)


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

Branch: refs/heads/trunk
Commit: be85313e2048af7bde5e197ecd9d5527b02542ee
Parents: ecb7eb7
Author: Srimanth Gunturi <sgunturi@hortonworks.com>
Authored: Tue Jun 23 19:09:47 2015 -0700
Committer: Srimanth Gunturi <sgunturi@hortonworks.com>
Committed: Wed Jun 24 11:20:54 2015 -0700

----------------------------------------------------------------------
 .../HiveDynamicServiceDiscoveryCheck.java       |  11 +-
 .../checks/ServicesNamenodeTruncateCheck.java   |  11 +-
 .../YarnTimelineServerStatePreservingCheck.java |  52 ++++++---
 .../server/configuration/Configuration.java     |  27 -----
 .../HiveDynamicServiceDiscoveryCheckTest.java   | 112 +++++++++++++++++++
 .../ServicesNamenodeTruncateCheckTest.java      |  17 ++-
 ...nTimelineServerStatePreservingCheckTest.java |  97 ++++++++++------
 7 files changed, 245 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/be85313e/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveDynamicServiceDiscoveryCheck.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveDynamicServiceDiscoveryCheck.java
b/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveDynamicServiceDiscoveryCheck.java
index 74bed8a..4ea5484 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveDynamicServiceDiscoveryCheck.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveDynamicServiceDiscoveryCheck.java
@@ -27,6 +27,7 @@ import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
+import org.apache.ambari.server.utils.VersionUtils;
 import org.apache.commons.lang.StringUtils;
 
 import com.google.inject.Singleton;
@@ -96,7 +97,15 @@ public class HiveDynamicServiceDiscoveryCheck extends AbstractCheckDescriptor
{
     if (!errorMessages.isEmpty()) {
       prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " "));
       prerequisiteCheck.getFailedOn().add("HIVE");
-      prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
+      PrereqCheckStatus checkStatus = PrereqCheckStatus.FAIL;
+      if ("HDP".equals(request.getSourceStackId().getStackName())) {
+        if (VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), "2.3.0.0")
< 0
+            && VersionUtils.compareVersions(request.getTargetStackId().getStackVersion(),
"2.3.0.0") < 0
+            && VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(),
request.getTargetStackId().getStackVersion()) < 0) {
+          checkStatus = PrereqCheckStatus.WARNING;
+        }
+      }
+      prerequisiteCheck.setStatus(checkStatus);
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/be85313e/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheck.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheck.java
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheck.java
index 4159c65..51369c9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheck.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheck.java
@@ -24,6 +24,7 @@ import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
+import org.apache.ambari.server.utils.VersionUtils;
 
 import com.google.inject.Singleton;
 
@@ -72,7 +73,15 @@ public class ServicesNamenodeTruncateCheck extends AbstractCheckDescriptor
{
 
     if (Boolean.valueOf(truncateEnabled)) {
       prerequisiteCheck.getFailedOn().add("HDFS");
-      prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
+      PrereqCheckStatus checkStatus = PrereqCheckStatus.FAIL;
+      if ("HDP".equals(request.getSourceStackId().getStackName())) {
+        if (VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), "2.3.0.0")
>= 0
+            && VersionUtils.compareVersions(request.getTargetStackId().getStackVersion(),
"2.3.0.0") >= 0
+            && VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(),
request.getTargetStackId().getStackVersion()) < 0) {
+          checkStatus = PrereqCheckStatus.PASS;
+        }
+      }
+      prerequisiteCheck.setStatus(checkStatus);
       prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
 
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/be85313e/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheck.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheck.java
b/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheck.java
index 0624f63..eca0967 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheck.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheck.java
@@ -20,7 +20,6 @@ package org.apache.ambari.server.checks;
 import java.util.Map;
 
 import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Service;
@@ -41,7 +40,34 @@ import com.google.inject.Singleton;
 public class YarnTimelineServerStatePreservingCheck extends AbstractCheckDescriptor {
 
   private final static String YARN_TIMELINE_STATE_RECOVERY_ENABLED_KEY = "yarn.timeline-service.recovery.enabled";
-  Configuration _configuration = null;
+
+  /**
+   * Due to the introduction of YARN Timeline state recovery only from certain
+   * stack-versions onwards, this check is not applicable to earlier versions
+   * of the stack.
+   *
+   * This enumeration lists the minimum stack-versions for which this check is applicable.
+   * If a stack is not specified in this enumeration, this check will be applicable.
+   */
+  private enum MinimumApplicableStackVersion {
+    HDP_STACK("HDP", "2.2.4.2");
+
+    private String stackName;
+    private String stackVersion;
+
+    private MinimumApplicableStackVersion(String stackName, String stackVersion) {
+      this.stackName = stackName;
+      this.stackVersion = stackVersion;
+    }
+
+    public String getStackName() {
+      return stackName;
+    }
+
+    public String getStackVersion() {
+      return stackVersion;
+    }
+  }
 
   /**
    * Constructor.
@@ -65,20 +91,14 @@ public class YarnTimelineServerStatePreservingCheck extends AbstractCheckDescrip
       return false;
     }
 
-    if(null == _configuration)
-      _configuration = new Configuration();
-    
-    String rollingUpgradeStack = _configuration.getRollingUpgradeStack(); 
-    // not applicable if not HDP 2.2.4.2 or later    
-    String stackName = cluster.getCurrentStackVersion().getStackName();
-    if (!rollingUpgradeStack.equals(stackName)) {
-      return false;
-    }
-
-    String rollingUpgradeVersion = _configuration.getRollingUpgradeVersion();
-    String currentClusterRepositoryVersion = cluster.getCurrentClusterVersion().getRepositoryVersion().getVersion();
-    if (VersionUtils.compareVersions(currentClusterRepositoryVersion, rollingUpgradeVersion)
< 0) {
-      return false;
+    // Applicable only if stack not defined in MinimumApplicableStackVersion, or
+    // version equals or exceeds the enumerated version.
+    for (MinimumApplicableStackVersion minimumStackVersion : MinimumApplicableStackVersion.values())
{
+      String stackName = cluster.getCurrentStackVersion().getStackName();
+      if (minimumStackVersion.getStackName().equals(stackName)){
+        String currentClusterRepositoryVersion = cluster.getCurrentClusterVersion().getRepositoryVersion().getVersion();
+        return VersionUtils.compareVersions(currentClusterRepositoryVersion, minimumStackVersion.getStackVersion())
>= 0;
+      }
     }
 
     return true;

http://git-wip-us.apache.org/repos/asf/ambari/blob/be85313e/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index 20d31fd..6c98457 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -391,15 +391,6 @@ 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";
 
-
-  /**
-   * Rolling upgrade stack and version
-   */
-  private static final String ROLLINGUPGRADE_VERSION = "rollingupgrade.version";
-  private static final String ROLLINGUPGRADE_STACK = "rollingupgrade.stack";
-  private static final String ROLLINGUPGRADE_VERSION_DEFAULT = "2.2.4.2";
-  private static final String ROLLINGUPGRADE_STACK_DEFAULT = "HDP";
-
   private static final Logger LOG = LoggerFactory.getLogger(
       Configuration.class);
 
@@ -1703,24 +1694,6 @@ public class Configuration {
         DEFAULT_JDBC_POOL_IDLE_TEST_INTERVAL));
   }
 
- /**
-  * Get the current stack that supports rolling upgrade 
-  * 
-  * @return default of {@value #ROLLINGUPGRADE_STACK_DEFAULT}
-  */
-  public String getRollingUpgradeStack(){
-    return properties.getProperty(ROLLINGUPGRADE_STACK, ROLLINGUPGRADE_STACK_DEFAULT);
-  }
-
-  /**
-   * Get the stack version that supports rolling upgrade 
-   * 
-   * @return default of {@value #ROLLINGUPGRADE_VERSION_DEFAULT}
-   */
-  public String getRollingUpgradeVersion(){
-    return properties.getProperty(ROLLINGUPGRADE_VERSION, ROLLINGUPGRADE_VERSION_DEFAULT);
-  } 
-
   /**
    * Sets a property on the configuration.
    *

http://git-wip-us.apache.org/repos/asf/ambari/blob/be85313e/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveDynamicServiceDiscoveryCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveDynamicServiceDiscoveryCheckTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveDynamicServiceDiscoveryCheckTest.java
new file mode 100644
index 0000000..e4b3438
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveDynamicServiceDiscoveryCheckTest.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.checks;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.controller.PrereqCheckRequest;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Config;
+import org.apache.ambari.server.state.DesiredConfig;
+import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.stack.PrereqCheckStatus;
+import org.apache.ambari.server.state.stack.PrerequisiteCheck;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.google.inject.Provider;
+
+/**
+ * Tests for {@link HiveDynamicServiceDiscoveryCheck}
+ */
+public class HiveDynamicServiceDiscoveryCheckTest {
+  private final Clusters m_clusters = Mockito.mock(Clusters.class);
+
+  private final HiveDynamicServiceDiscoveryCheck m_check = new HiveDynamicServiceDiscoveryCheck();
+
+  /**
+   *
+   */
+  @Before
+  public void setup() {
+    m_check.clustersProvider = new Provider<Clusters>() {
+
+      @Override
+      public Clusters get() {
+        return m_clusters;
+      }
+    };
+  }
+
+  @Test
+  public void testPerform() throws Exception {
+    final Cluster cluster = Mockito.mock(Cluster.class);
+    Mockito.when(cluster.getClusterId()).thenReturn(1L);
+    Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster);
+
+    final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class);
+    Mockito.when(desiredConfig.getTag()).thenReturn("tag");
+    Map<String, DesiredConfig> configMap = new HashMap<String, DesiredConfig>();
+    configMap.put("hive-site", desiredConfig);
+
+    Mockito.when(cluster.getDesiredConfigs()).thenReturn(configMap);
+    final Config config = Mockito.mock(Config.class);
+    Mockito.when(cluster.getConfig(Mockito.anyString(), Mockito.anyString())).thenReturn(config);
+    final Map<String, String> properties = new HashMap<String, String>();
+    Mockito.when(config.getProperties()).thenReturn(properties);
+    PrerequisiteCheck check = new PrerequisiteCheck(null, null);
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+
+    // Check HDP-2.2.x => HDP-2.2.y
+    request.setSourceStackId(new StackId("HDP-2.2.4.2"));
+    request.setTargetStackId(new StackId("HDP-2.2.8.4"));
+    m_check.perform(check, request);
+    Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus());
+
+    // Check HDP-2.2.x => HDP-2.3.y
+    request.setSourceStackId(new StackId("HDP-2.2.4.2"));
+    request.setTargetStackId(new StackId("HDP-2.3.8.4"));
+    m_check.perform(check, request);
+    Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
+
+    // Check HDP-2.3.x => HDP-2.3.y
+    request.setSourceStackId(new StackId("HDP-2.3.4.2"));
+    request.setTargetStackId(new StackId("HDP-2.3.8.4"));
+    m_check.perform(check, request);
+    Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
+
+    // Check HDP-2.3.x => HDP-2.4.y
+    request.setSourceStackId(new StackId("HDP-2.3.4.2"));
+    request.setTargetStackId(new StackId("HDP-2.4.8.4"));
+    m_check.perform(check, request);
+    Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
+
+    // Check when properties are specified
+    properties.put("hive.server2.support.dynamic.service.discovery", "true");
+    properties.put("hive.zookeeper.quorum", "host");
+    properties.put("hive.server2.zookeeper.namespace", "namespace");
+    check = new PrerequisiteCheck(null, null);
+    m_check.perform(check, request);
+    Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/be85313e/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java
index c484b90..b83f26c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java
@@ -86,17 +86,28 @@ public class ServicesNamenodeTruncateCheckTest {
   @Test
   public void testPerform() throws Exception {
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
-    m_check.perform(check, new PrereqCheckRequest("c1"));
+    PrereqCheckRequest request = new PrereqCheckRequest("c1");
+    m_check.perform(check, request);
     assertEquals(PrereqCheckStatus.PASS, check.getStatus());
 
+    // Check HDP-2.2.x => HDP-2.2.y is FAIL
     m_configMap.put("dfs.allow.truncate", "true");
+    request.setSourceStackId(new StackId("HDP-2.2.4.2"));
+    request.setTargetStackId(new StackId("HDP-2.2.8.4"));
     check = new PrerequisiteCheck(null, null);
-    m_check.perform(check, new PrereqCheckRequest("c1"));
+    m_check.perform(check, request);
     assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
 
+    // Check HDP-2.3.x => HDP-2.3.y is PASS
+    request.setSourceStackId(new StackId("HDP-2.3.4.2"));
+    request.setTargetStackId(new StackId("HDP-2.3.8.4"));
+    check = new PrerequisiteCheck(null, null);
+    m_check.perform(check, request);
+    assertEquals(PrereqCheckStatus.PASS, check.getStatus());
+
     m_configMap.put("dfs.allow.truncate", "false");
     check = new PrerequisiteCheck(null, null);
-    m_check.perform(check, new PrereqCheckRequest("c1"));
+    m_check.perform(check, request);
     assertEquals(PrereqCheckStatus.PASS, check.getStatus());
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/be85313e/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java
index 62fe67d..1a10db7 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java
@@ -19,9 +19,7 @@ package org.apache.ambari.server.checks;
 
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Properties;
 
-import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
 import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
@@ -67,10 +65,6 @@ public class YarnTimelineServerStatePreservingCheckTest {
    */
   @Test
   public void testIsApplicable() throws Exception {
-    //Default value
-    Configuration conf = new Configuration(new Properties());
-    m_check._configuration = conf;
-
     final Cluster cluster = Mockito.mock(Cluster.class);
     Mockito.when(cluster.getClusterId()).thenReturn(1L);
     Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster);
@@ -101,34 +95,6 @@ public class YarnTimelineServerStatePreservingCheckTest {
 
     Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.2.4.2");
     Assert.assertTrue(m_check.isApplicable(request));
-    
-    //Custom stack name and version
-    Properties ambariProperties = new Properties();
-    ambariProperties.setProperty("rollingupgrade.stack", "MYSTACK");
-    ambariProperties.setProperty("rollingupgrade.version", "2.0.0.0");
-    conf = new Configuration(ambariProperties);
-    m_check._configuration = conf;
-    
-    Mockito.when(cluster.getClusterId()).thenReturn(1L);
-    Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster);
-    Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("MYSTACK-2.0"));
-
-    services = new HashMap<String, Service>();
-    Mockito.when(cluster.getServices()).thenReturn(services);
-
-    clusterVersionEntity = Mockito.mock(ClusterVersionEntity.class);
-    Mockito.when(cluster.getCurrentClusterVersion()).thenReturn(clusterVersionEntity);
-
-    repositoryVersionEntity = Mockito.mock(RepositoryVersionEntity.class);
-    Mockito.when(clusterVersionEntity.getRepositoryVersion()).thenReturn(repositoryVersionEntity);
-    
-    services.put("YARN", Mockito.mock(Service.class));
-
-    Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("1.0.0.0");
-    Assert.assertFalse(m_check.isApplicable(request));
-
-    Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("4.1.0.0");
-    Assert.assertTrue(m_check.isApplicable(request));
   }
 
   @Test
@@ -158,4 +124,67 @@ public class YarnTimelineServerStatePreservingCheckTest {
     m_check.perform(check, new PrereqCheckRequest("cluster"));
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
   }
+
+  @SuppressWarnings("serial")
+  @Test
+  public void testIsApplicableMinimumHDPStackVersion() throws Exception {
+    final Cluster cluster = Mockito.mock(Cluster.class);
+    Mockito.when(cluster.getClusterId()).thenReturn(1L);
+    Mockito.when(cluster.getServices()).thenReturn(new HashMap<String, Service>() {
+      {
+        put("YARN", null);
+      }
+    });
+    Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.2"));
+    ClusterVersionEntity clusterVersionEntity = Mockito.mock(ClusterVersionEntity.class);
+    Mockito.when(cluster.getCurrentClusterVersion()).thenReturn(clusterVersionEntity);
+    RepositoryVersionEntity repositoryVersionEntity = Mockito.mock(RepositoryVersionEntity.class);
+    Mockito.when(clusterVersionEntity.getRepositoryVersion()).thenReturn(repositoryVersionEntity);
+    Mockito.when(m_clusters.getCluster("c1")).thenReturn(cluster);
+    PrereqCheckRequest request = new PrereqCheckRequest("c1");
+
+    // Check < 2.2.4.2
+    Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.1.1.1");
+    boolean isApplicable = m_check.isApplicable(request);
+    Assert.assertFalse(isApplicable);
+    Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.2.4.1");
+    isApplicable = m_check.isApplicable(request);
+    Assert.assertFalse(isApplicable);
+
+    // Check == 2.2.4.2
+    Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.2.4.2");
+    isApplicable = m_check.isApplicable(request);
+    Assert.assertTrue(isApplicable);
+
+    // Check > 2.2.4.2
+    Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.2.4.4");
+    isApplicable = m_check.isApplicable(request);
+    Assert.assertTrue(isApplicable);
+    Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.3.1.1");
+    isApplicable = m_check.isApplicable(request);
+    Assert.assertTrue(isApplicable);
+  }
+
+  @SuppressWarnings("serial")
+  @Test
+  public void testIsApplicableMinimumStackVersion() throws Exception {
+    final Cluster cluster = Mockito.mock(Cluster.class);
+    Mockito.when(cluster.getClusterId()).thenReturn(1L);
+    Mockito.when(cluster.getServices()).thenReturn(new HashMap<String, Service>() {
+      {
+        put("YARN", null);
+      }
+    });
+    Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("MYSTACK-12.2"));
+    ClusterVersionEntity clusterVersionEntity = Mockito.mock(ClusterVersionEntity.class);
+    Mockito.when(cluster.getCurrentClusterVersion()).thenReturn(clusterVersionEntity);
+    RepositoryVersionEntity repositoryVersionEntity = Mockito.mock(RepositoryVersionEntity.class);
+    Mockito.when(clusterVersionEntity.getRepositoryVersion()).thenReturn(repositoryVersionEntity);
+    Mockito.when(m_clusters.getCluster("c1")).thenReturn(cluster);
+    PrereqCheckRequest request = new PrereqCheckRequest("c1");
+
+    Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.3.0.1");
+    boolean isApplicable = m_check.isApplicable(request);
+    Assert.assertTrue(isApplicable);
+  }
 }


Mime
View raw message