ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lpus...@apache.org
Subject [08/32] ambari git commit: AMBARI-21677 - Upgrade Pre-Checks Should Take PATCH/SERVICE Types Into Account (jonathanhurley)
Date Mon, 14 Aug 2017 12:02:21 GMT
http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/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 ba4b61e..f41b34c 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
@@ -17,8 +17,9 @@
  */
 package org.apache.ambari.server.checks;
 
-import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
@@ -30,6 +31,8 @@ import org.apache.ambari.server.state.stack.UpgradePack.PrerequisiteCheckConfig;
 import org.apache.ambari.server.utils.VersionUtils;
 import org.apache.commons.lang.BooleanUtils;
 
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
 import com.google.inject.Singleton;
 
 /**
@@ -55,43 +58,16 @@ public class YarnTimelineServerStatePreservingCheck extends AbstractCheckDescrip
    * {@inheritDoc}
    */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws AmbariException {
-    if (!super.isApplicable(request, Arrays.asList("YARN"), true)) {
-      return false;
-    }
-
-    final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName());
-
-    String minApplicableStackVersion = null;
-    PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig();
-    Map<String, String> checkProperties = null;
-    if(prerequisiteCheckConfig != null) {
-      checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName());
-    }
-    if(checkProperties != null && checkProperties.containsKey(MIN_APPLICABLE_STACK_VERSION_PROPERTY_NAME)) {
-      minApplicableStackVersion = checkProperties.get(MIN_APPLICABLE_STACK_VERSION_PROPERTY_NAME);
-    }
-
-    // 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.
-    // Applicable only if min-applicable-stack-version config property is not defined, or
-    // version equals or exceeds the configured version.
-    if(minApplicableStackVersion != null && !minApplicableStackVersion.isEmpty()) {
-      String[] minStack = minApplicableStackVersion.split("-");
-      if(minStack.length == 2) {
-        String minStackName = minStack[0];
-        String minStackVersion = minStack[1];
-        Service yarnService = cluster.getService("YARN");
-        String stackName = yarnService.getDesiredStackId().getStackName();
-        if (minStackName.equals(stackName)) {
-          String currentRepositoryVersion = yarnService.getDesiredRepositoryVersion().getVersion();
-          return VersionUtils.compareVersions(currentRepositoryVersion, minStackVersion) >= 0;
-        }
-      }
-    }
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet("YARN");
+  }
 
-    return true;
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public List<CheckQualification> getQualifications() {
+    return Lists.<CheckQualification> newArrayList(new YarnTimelineServerMinVersionQualification());
   }
 
   /**
@@ -108,4 +84,53 @@ public class YarnTimelineServerStatePreservingCheck extends AbstractCheckDescrip
       prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
     }
   }
+
+  /**
+   * The {@link YarnTimelineServerMinVersionQualification} is used to determine
+   * if the ATS component needs to have the
+   * {@value #MIN_APPLICABLE_STACK_VERSION_PROPERTY_NAME} set.
+   */
+  private class YarnTimelineServerMinVersionQualification implements CheckQualification {
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isApplicable(PrereqCheckRequest request) throws AmbariException {
+      final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName());
+
+      String minApplicableStackVersion = null;
+      PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig();
+      Map<String, String> checkProperties = null;
+      if(prerequisiteCheckConfig != null) {
+        checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName());
+      }
+
+      if(checkProperties != null && checkProperties.containsKey(MIN_APPLICABLE_STACK_VERSION_PROPERTY_NAME)) {
+        minApplicableStackVersion = checkProperties.get(MIN_APPLICABLE_STACK_VERSION_PROPERTY_NAME);
+      }
+
+      // 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.
+      // Applicable only if min-applicable-stack-version config property is not defined, or
+      // version equals or exceeds the configured version.
+      if(minApplicableStackVersion != null && !minApplicableStackVersion.isEmpty()) {
+        String[] minStack = minApplicableStackVersion.split("-");
+        if(minStack.length == 2) {
+          String minStackName = minStack[0];
+          String minStackVersion = minStack[1];
+          Service yarnService = cluster.getService("YARN");
+          String stackName = yarnService.getDesiredStackId().getStackName();
+          if (minStackName.equals(stackName)) {
+            String currentRepositoryVersion = yarnService.getDesiredRepositoryVersion().getVersion();
+            return VersionUtils.compareVersions(currentRepositoryVersion, minStackVersion) >= 0;
+          }
+        }
+      }
+
+      return true;
+
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/controller/PrereqCheckRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/PrereqCheckRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/PrereqCheckRequest.java
index f0a8df1..6d9f655 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/PrereqCheckRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/PrereqCheckRequest.java
@@ -64,14 +64,6 @@ public class PrereqCheckRequest {
     return m_upgradeType;
   }
 
-  public String getTargetVersion() {
-    if (null == m_targetRepositoryVersion) {
-      return null;
-    }
-
-    return m_targetRepositoryVersion.getVersion();
-  }
-
   /**
    * Sets the result of a check.
    * @param description the description
@@ -110,19 +102,6 @@ public class PrereqCheckRequest {
   }
 
   /**
-   * Gets the target stack of the upgrade.
-   *
-   * @return the targetStackId
-   */
-  public StackId getTargetStackId() {
-    if (null == m_targetRepositoryVersion) {
-      return null;
-    }
-
-    return m_targetRepositoryVersion.getStackId();
-  }
-
-  /**
    * Gets the target repository of the upgrade.
    *
    * @return the target repository.

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/state/CheckHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/CheckHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/state/CheckHelper.java
index 8cf3afd..7fe3256 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/CheckHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/CheckHelper.java
@@ -73,7 +73,9 @@ public class CheckHelper {
           applicablePreChecks.add(new DescriptorPreCheck(checkDescriptor, prerequisiteCheck));
         }
       } catch (Exception ex) {
-        LOG.error("Check " + checkDescriptor.getDescription().name() + " failed", ex);
+        LOG.error(
+            "Unable to determine whether the pre-upgrade check {} is applicable to this upgrade",
+            checkDescriptor.getDescription().name(), ex);
       }
     }
     return applicablePreChecks;

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-START/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-START/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-START/scripts/params.py
index 2449d66..c8880ae 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-START/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-START/scripts/params.py
@@ -337,12 +337,11 @@ if dfs_ha_enabled:
      namenode_rpc = nn_host
    pass
  pass
-elif 'dfs.namenode.rpc-address' in config['configurations']['hdfs-site']:
-  namenode_rpc = default('/configurations/hdfs-site/dfs.namenode.rpc-address', None)
 else:
-  namenode_rpc = default_fs
+  namenode_rpc = default('/configurations/hdfs-site/dfs.namenode.rpc-address', default_fs)
 
-if namenode_rpc:
+# if HDFS is not installed in the cluster, then don't try to access namenode_rpc
+if "core-site" in config['configurations'] and namenode_rpc:
   port_str = namenode_rpc.split(':')[-1].strip()
   try:
     nn_rpc_client_port = int(port_str)

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/resources/stacks/HDP/3.0/hooks/before-START/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/3.0/hooks/before-START/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/3.0/hooks/before-START/scripts/params.py
index ecbb6a4..d70030d 100644
--- a/ambari-server/src/main/resources/stacks/HDP/3.0/hooks/before-START/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/3.0/hooks/before-START/scripts/params.py
@@ -311,12 +311,11 @@ if dfs_ha_enabled:
      namenode_rpc = nn_host
    pass
  pass
-elif 'dfs.namenode.rpc-address' in config['configurations']['hdfs-site']:
-  namenode_rpc = default('/configurations/hdfs-site/dfs.namenode.rpc-address', None)
 else:
-  namenode_rpc = default_fs
+  namenode_rpc = default('/configurations/hdfs-site/dfs.namenode.rpc-address', default_fs)
 
-if namenode_rpc:
+# if HDFS is not installed in the cluster, then don't try to access namenode_rpc
+if "core-site" in config['configurations'] and namenode_rpc:
   port_str = namenode_rpc.split(':')[-1].strip()
   try:
     nn_rpc_client_port = int(port_str)

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/AbstractCheckDescriptorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/AbstractCheckDescriptorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/AbstractCheckDescriptorTest.java
index 9fbd012..1b87b30 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/AbstractCheckDescriptorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/AbstractCheckDescriptorTest.java
@@ -17,125 +17,58 @@
  */
 package org.apache.ambari.server.checks;
 
-import static org.easymock.EasyMock.anyLong;
 import static org.easymock.EasyMock.anyString;
 import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.reset;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashSet;
-import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
-import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
-import org.apache.ambari.server.state.RepositoryType;
 import org.apache.ambari.server.state.Service;
-import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
 import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.PrereqCheckType;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
+import org.apache.hadoop.metrics2.sink.relocated.google.common.collect.Sets;
 import org.easymock.EasyMock;
-import org.junit.Assert;
+import org.easymock.EasyMockSupport;
+import org.easymock.Mock;
+import org.junit.Before;
 import org.junit.Test;
 
 import com.google.inject.Provider;
 
+import junit.framework.Assert;
+
 /**
  * Unit tests for AbstractCheckDescriptor
  */
-public class AbstractCheckDescriptorTest {
-  final private Clusters clusters = EasyMock.createNiceMock(Clusters.class);
-  private final RepositoryVersionDAO repositoryVersionDao = EasyMock.createNiceMock(RepositoryVersionDAO.class);
-
-  @UpgradeCheck(
-      group = UpgradeCheckGroup.DEFAULT,
-      order = 1.0f,
-      required = { UpgradeType.ROLLING, UpgradeType.NON_ROLLING, UpgradeType.HOST_ORDERED })
-  private class TestCheckImpl extends AbstractCheckDescriptor {
-    private PrereqCheckType m_type;
-
-    TestCheckImpl(PrereqCheckType type) {
-      super(null);
-      m_type = type;
-
-      clustersProvider = new Provider<Clusters>() {
-        @Override
-        public Clusters get() {
-          return clusters;
-        }
-      };
-
-      repositoryVersionDaoProvider = new Provider<RepositoryVersionDAO>() {
-        @Override
-        public RepositoryVersionDAO get() {
-          return repositoryVersionDao;
-        }
-      };
-    }
-
-    @Override
-    public PrereqCheckType getType() {
-      return m_type;
-    }
-
-    @Override
-    public void perform(PrerequisiteCheck prerequisiteCheck,
-        PrereqCheckRequest request) throws AmbariException {
-    }
-  }
-
-  @UpgradeCheck(group = UpgradeCheckGroup.DEFAULT, order = 1.0f, required = { UpgradeType.ROLLING })
-  private class RollingTestCheckImpl extends AbstractCheckDescriptor {
-    private PrereqCheckType m_type;
-
-    RollingTestCheckImpl(PrereqCheckType type) {
-      super(null);
-      m_type = type;
-
-      clustersProvider = new Provider<Clusters>() {
-        @Override
-        public Clusters get() {
-          return clusters;
-        }
-      };
-    }
-
-    @Override
-    public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
-        throws AmbariException {
-    }
-  }
+public class AbstractCheckDescriptorTest extends EasyMockSupport {
+  @Mock
+  private Clusters clusters;
 
-  @UpgradeCheck(group = UpgradeCheckGroup.DEFAULT, order = 1.0f)
-  private class NotRequiredCheckTest extends AbstractCheckDescriptor {
-    private PrereqCheckType m_type;
-
-    NotRequiredCheckTest(PrereqCheckType type) {
-      super(null);
-      m_type = type;
+  /**
+   * Used to mock out what services will be provided to us by the VDF/cluster.
+   */
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
 
-      clustersProvider = new Provider<Clusters>() {
-        @Override
-        public Clusters get() {
-          return clusters;
-        }
-      };
-    }
+  /**
+   *
+   */
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
 
-    @Override
-    public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
-        throws AmbariException {
-    }
+  @Before
+  public void setup() throws Exception {
+    injectMocks(this);
   }
 
   @Test
@@ -169,7 +102,7 @@ public class AbstractCheckDescriptorTest {
   @Test
   public void testIsApplicable() throws Exception{
     final String clusterName = "c1";
-    final Cluster cluster = EasyMock.createMock(Cluster.class);
+    final Cluster cluster = createMock(Cluster.class);
 
 
     Map<String, Service> services = new HashMap<String, Service>(){{
@@ -178,88 +111,88 @@ public class AbstractCheckDescriptorTest {
       put("SERVICE3", null);
     }};
 
+    Set<String> oneServiceList = Sets.newHashSet("SERVICE1");
+    Set<String> atLeastOneServiceList = Sets.newHashSet("SERVICE1", "MISSING_SERVICE");
+    Set<String> allServicesList = Sets.newHashSet("SERVICE1", "SERVICE2");
+    Set<String> missingServiceList = Sets.newHashSet("MISSING_SERVICE");
+
     expect(clusters.getCluster(anyString())).andReturn(cluster).atLeastOnce();
     expect(cluster.getServices()).andReturn(services).atLeastOnce();
 
-    replay(clusters, cluster);
-
-    AbstractCheckDescriptor check = new TestCheckImpl(PrereqCheckType.SERVICE);
-    PrereqCheckRequest request = new PrereqCheckRequest(clusterName, UpgradeType.ROLLING);
-
-    List<String> oneServiceList = Arrays.asList("SERVICE1");
+    RepositoryVersionEntity repositoryVersion = createNiceMock(RepositoryVersionEntity.class);
+    expect(repositoryVersion.getRepositoryXml()).andReturn(m_vdfXml).atLeastOnce();
+    expect(m_vdfXml.getClusterSummary(EasyMock.anyObject(Cluster.class))).andReturn(
+        m_clusterVersionSummary).atLeastOnce();
 
-    List<String> atLeastOneServiceList = Arrays.asList("SERVICE1", "NON_EXISTED_SERVICE");
+    expect(m_clusterVersionSummary.getAvailableServiceNames()).andReturn(
+        allServicesList).atLeastOnce();
 
-    List<String> allServicesList = Arrays.asList("SERVICE1", "SERVICE2");
 
-    List<String> nonExistedList = Arrays.asList("NON_EXISTED_SERVICE");
+    replayAll();
 
+    TestCheckImpl check = new TestCheckImpl(PrereqCheckType.SERVICE);
+    PrereqCheckRequest request = new PrereqCheckRequest(clusterName, UpgradeType.ROLLING);
+    request.setTargetRepositoryVersion(repositoryVersion);
 
     // case, where we need at least one service to be present
-    Assert.assertEquals(true, check.isApplicable(request, oneServiceList, false));
-    Assert.assertEquals(true, check.isApplicable(request, atLeastOneServiceList, false));
+    check.setApplicableServices(oneServiceList);
+    Assert.assertTrue(check.isApplicable(request));
 
-    // case, where all services need to be present
-    Assert.assertEquals(false, check.isApplicable(request,atLeastOneServiceList, true));
-    Assert.assertEquals(true, check.isApplicable(request, allServicesList, true));
+    check.setApplicableServices(atLeastOneServiceList);
+    Assert.assertTrue(check.isApplicable(request));
 
-    // Case with empty list of the required services
-    Assert.assertEquals(false, check.isApplicable(request, new ArrayList<String>(), true));
-    Assert.assertEquals(false, check.isApplicable(request, new ArrayList<String>(), false));
-
-    // Case with non existed services
-    Assert.assertEquals(false, check.isApplicable(request, nonExistedList, false));
-    Assert.assertEquals(false, check.isApplicable(request, nonExistedList, true));
+    check.setApplicableServices(missingServiceList);
+    Assert.assertFalse(check.isApplicable(request));
   }
 
+  /**
+   * Tests that even though the services are installed, the check doesn't match
+   * since it's for a service not in the PATCH.
+   *
+   * @throws Exception
+   */
   @Test
-  public void testIsApplicableWithVDF() throws Exception{
+  public void testIsApplicableForPatch() throws Exception {
     final String clusterName = "c1";
-    final Cluster cluster = EasyMock.createMock(Cluster.class);
+    final Cluster cluster = createMock(Cluster.class);
 
-    Map<String, Service> services = new HashMap<String, Service>(){{
-      put("SERVICE1", null);
-      put("SERVICE2", null);
-      put("SERVICE3", null);
-    }};
+    Map<String, Service> services = new HashMap<String, Service>() {
+      {
+        put("SERVICE1", null);
+        put("SERVICE2", null);
+        put("SERVICE3", null);
+      }
+    };
+
+    Set<String> oneServiceList = Sets.newHashSet("SERVICE1");
 
     expect(clusters.getCluster(anyString())).andReturn(cluster).atLeastOnce();
     expect(cluster.getServices()).andReturn(services).atLeastOnce();
 
-    RepositoryVersionEntity repoVersion = EasyMock.createMock(RepositoryVersionEntity.class);
-    VersionDefinitionXml repoXml = EasyMock.createMock(VersionDefinitionXml.class);
-    expect(repoVersion.getType()).andReturn(RepositoryType.PATCH).atLeastOnce();
-    expect(repoVersion.getRepositoryXml()).andReturn(repoXml).atLeastOnce();
-    expect(repoVersion.getStackId()).andReturn(new StackId("HDP-2.5")).atLeastOnce();
-    expect(repoVersion.getVersion()).andReturn("2.5.0.0-1234").atLeastOnce();
-    expect(repoXml.getAvailableServiceNames()).andReturn(Collections.singleton("SERVICE2")).atLeastOnce();
+    RepositoryVersionEntity repositoryVersion = createNiceMock(RepositoryVersionEntity.class);
+    expect(repositoryVersion.getRepositoryXml()).andReturn(m_vdfXml).atLeastOnce();
+    expect(m_vdfXml.getClusterSummary(EasyMock.anyObject(Cluster.class))).andReturn(
+        m_clusterVersionSummary).atLeastOnce();
 
-    expect(repositoryVersionDao.findByPK(anyLong())).andReturn(repoVersion).atLeastOnce();
+    // the cluster summary will only return 1 service for the upgrade, even
+    // though this cluster has 2 services installed
+    expect(m_clusterVersionSummary.getAvailableServiceNames()).andReturn(
+        oneServiceList).atLeastOnce();
 
-    expect(repositoryVersionDao.findByStackNameAndVersion(anyString(), anyString())).andReturn(
-        repoVersion).atLeastOnce();
+    replayAll();
 
-    replay(clusters, cluster, repositoryVersionDao, repoVersion, repoXml);
-
-    AbstractCheckDescriptor check = new TestCheckImpl(PrereqCheckType.SERVICE);
+    TestCheckImpl check = new TestCheckImpl(PrereqCheckType.SERVICE);
     PrereqCheckRequest request = new PrereqCheckRequest(clusterName, UpgradeType.ROLLING);
-    request.setTargetRepositoryVersion(repoVersion);
-
-    List<String> allServicesList = Arrays.asList("SERVICE1", "SERVICE2");
-
-    // SERVICE2 is the only thing in VDF
-    Assert.assertEquals(true, check.isApplicable(request, allServicesList, false));
+    request.setTargetRepositoryVersion(repositoryVersion);
 
-    List<String> oneServicesList = Arrays.asList("SERVICE1");
+    // since the check is for SERVICE2, it should not match even though its
+    // installed since the repository is only for SERVICE1
+    check.setApplicableServices(Sets.newHashSet("SERVICE2"));
+    Assert.assertFalse(check.isApplicable(request));
 
-    // SERVICE2 is the only thing in VDF, a check for only SERVICE1 fail
-    Assert.assertEquals(false, check.isApplicable(request, oneServicesList, false));
-
-    // a VDF without available services is technically invalid, so expect any passed services to return false
-    reset(repoXml);
-    expect(repoXml.getAvailableServiceNames()).andReturn(Collections.<String>emptySet()).atLeastOnce();
-    replay(repoXml);
-    Assert.assertEquals(false, check.isApplicable(request, allServicesList, false));
+    // ok, so now change the check to match against SERVICE1
+    check.setApplicableServices(Sets.newHashSet("SERVICE1"));
+    Assert.assertTrue(check.isApplicable(request));
   }
 
   /**
@@ -284,4 +217,90 @@ public class AbstractCheckDescriptorTest {
     Assert.assertTrue(requiredCheck.isRequired(UpgradeType.HOST_ORDERED));
   }
 
-}
+  @UpgradeCheck(
+      group = UpgradeCheckGroup.DEFAULT,
+      order = 1.0f,
+      required = { UpgradeType.ROLLING, UpgradeType.NON_ROLLING, UpgradeType.HOST_ORDERED })
+  private class TestCheckImpl extends AbstractCheckDescriptor {
+    private PrereqCheckType m_type;
+    private Set<String> m_applicableServices = Sets.newHashSet();
+
+    TestCheckImpl(PrereqCheckType type) {
+      super(null);
+      m_type = type;
+
+      clustersProvider = new Provider<Clusters>() {
+        @Override
+        public Clusters get() {
+          return clusters;
+        }
+      };
+    }
+
+    @Override
+    public PrereqCheckType getType() {
+      return m_type;
+    }
+
+    @Override
+    public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
+        throws AmbariException {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Set<String> getApplicableServices() {
+      return m_applicableServices;
+    }
+
+    void setApplicableServices(Set<String> applicableServices) {
+      m_applicableServices = applicableServices;
+    }
+  }
+
+  @UpgradeCheck(group = UpgradeCheckGroup.DEFAULT, order = 1.0f, required = { UpgradeType.ROLLING })
+  private class RollingTestCheckImpl extends AbstractCheckDescriptor {
+    private PrereqCheckType m_type;
+
+    RollingTestCheckImpl(PrereqCheckType type) {
+      super(null);
+      m_type = type;
+
+      clustersProvider = new Provider<Clusters>() {
+        @Override
+        public Clusters get() {
+          return clusters;
+        }
+      };
+    }
+
+    @Override
+    public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
+        throws AmbariException {
+    }
+  }
+
+  @UpgradeCheck(group = UpgradeCheckGroup.DEFAULT, order = 1.0f)
+  private class NotRequiredCheckTest extends AbstractCheckDescriptor {
+    private PrereqCheckType m_type;
+
+    NotRequiredCheckTest(PrereqCheckType type) {
+      super(null);
+      m_type = type;
+
+      clustersProvider = new Provider<Clusters>() {
+        @Override
+        public Clusters get() {
+          return clusters;
+        }
+      };
+    }
+
+    @Override
+    public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
+        throws AmbariException {
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/ClientRetryPropertyCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ClientRetryPropertyCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ClientRetryPropertyCheckTest.java
index 46a00b8..ecc3165 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ClientRetryPropertyCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ClientRetryPropertyCheckTest.java
@@ -22,7 +22,6 @@ import java.util.Map;
 
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
-import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
@@ -30,32 +29,45 @@ import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 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.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
 import com.google.inject.Provider;
 
 /**
  * Tests for {@link ClientRetryPropertyCheckTest}
  */
+@RunWith(MockitoJUnitRunner.class)
 public class ClientRetryPropertyCheckTest {
   private final Clusters m_clusters = Mockito.mock(Clusters.class);
 
   private final ClientRetryPropertyCheck m_check = new ClientRetryPropertyCheck();
 
-  final RepositoryVersionEntity m_repositoryVersion = Mockito.mock(RepositoryVersionEntity.class);
-  private final RepositoryVersionDAO repositoryVersionDAO = Mockito.mock(
-      RepositoryVersionDAO.class);
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
 
   /**
    *
    */
   @Before
-  public void setup() {
+  public void setup() throws Exception {
     m_check.clustersProvider = new Provider<Clusters>() {
 
       @Override
@@ -68,6 +80,11 @@ public class ClientRetryPropertyCheckTest {
 
     Mockito.when(m_repositoryVersion.getVersion()).thenReturn("2.3.0.0-1234");
     Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.3"));
+
+    m_services.clear();
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
   }
 
   /**
@@ -79,8 +96,7 @@ public class ClientRetryPropertyCheckTest {
     Mockito.when(cluster.getClusterId()).thenReturn(1L);
     Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster);
 
-    Map<String, Service> services = new HashMap<>();
-    Mockito.when(cluster.getServices()).thenReturn(services);
+    Mockito.when(cluster.getServices()).thenReturn(m_services);
 
     PrereqCheckRequest request = new PrereqCheckRequest("cluster");
     request.setTargetRepositoryVersion(m_repositoryVersion);
@@ -88,23 +104,13 @@ public class ClientRetryPropertyCheckTest {
     // nothing installed
     Assert.assertFalse(m_check.isApplicable(request));
 
-    m_check.repositoryVersionDaoProvider = new Provider<RepositoryVersionDAO>() {
-      @Override
-      public RepositoryVersionDAO get() {
-        return repositoryVersionDAO;
-      }
-    };
-
-    Mockito.when(repositoryVersionDAO.findByStackNameAndVersion(Mockito.anyString(),
-        Mockito.anyString())).thenReturn(m_repositoryVersion);
-
     // HDFS installed
-    services.put("HDFS", Mockito.mock(Service.class));
+    m_services.put("HDFS", Mockito.mock(Service.class));
     Assert.assertTrue(m_check.isApplicable(request));
 
     // OOZIE installed
-    services.clear();
-    services.put("OOZIE", Mockito.mock(Service.class));
+    m_services.clear();
+    m_services.put("OOZIE", Mockito.mock(Service.class));
     Assert.assertTrue(m_check.isApplicable(request));
   }
 
@@ -182,4 +188,4 @@ public class ClientRetryPropertyCheckTest {
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
 
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/ComponentExistsInRepoCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ComponentExistsInRepoCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ComponentExistsInRepoCheckTest.java
new file mode 100644
index 0000000..ede1daa
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ComponentExistsInRepoCheckTest.java
@@ -0,0 +1,352 @@
+/**
+ * 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 static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.expect;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.StackAccessException;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.controller.PrereqCheckRequest;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.ComponentInfo;
+import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceComponent;
+import org.apache.ambari.server.state.ServiceInfo;
+import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
+import org.apache.ambari.server.state.stack.PrereqCheckStatus;
+import org.apache.ambari.server.state.stack.PrerequisiteCheck;
+import org.apache.commons.lang.StringUtils;
+import org.easymock.EasyMockSupport;
+import org.easymock.Mock;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.inject.Provider;
+
+/**
+ * Tests for {@link ComponentsExistInRepoCheck}
+ */
+public class ComponentExistsInRepoCheckTest extends EasyMockSupport {
+
+  private final ComponentsExistInRepoCheck m_check = new ComponentsExistInRepoCheck();
+
+  @Mock
+  private Clusters m_clusters;
+
+  @Mock
+  private Cluster m_cluster;
+
+  // pick two stacks which have different services
+  private final StackId SOURCE_STACK = new StackId("HDP", "0.1");
+  private final StackId TARGET_STACK = new StackId("HDP", "2.2.0");
+
+  private final Map<String, Service> CLUSTER_SERVICES = new HashMap<>();
+  private final Map<String, ServiceComponent> FOO_SERVICE_COMPONENTS = new HashMap<>();
+  private final Map<String, ServiceComponent> ZK_SERVICE_COMPONENTS = new HashMap<>();
+
+  @Mock
+  private AmbariMetaInfo m_ambariMetaInfo;
+
+  @Mock
+  private Service m_fooService;
+
+  @Mock
+  private Service m_zookeeperService;
+
+  @Mock
+  private ServiceInfo m_fooInfo;
+
+  @Mock
+  private ServiceInfo m_zookeeperInfo;
+
+  @Mock
+  private ComponentInfo m_fooComponentInfo;
+
+  @Mock
+  private ComponentInfo m_zookeeperServerInfo;
+
+  @Mock
+  private ServiceComponent m_fooComponent;
+
+  @Mock
+  private ServiceComponent m_zookeeperServer;
+
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  @Before
+  public void before() throws Exception {
+
+    EasyMockSupport.injectMocks(this);
+
+    m_check.clustersProvider = new Provider<Clusters>() {
+      @Override
+      public Clusters get() {
+        return m_clusters;
+      }
+    };
+
+    m_check.ambariMetaInfo = new Provider<AmbariMetaInfo>() {
+      @Override
+      public AmbariMetaInfo get() {
+        return m_ambariMetaInfo;
+      }
+    };
+
+    expect(m_cluster.getServices()).andReturn(CLUSTER_SERVICES).atLeastOnce();
+    expect(m_cluster.getService("ZOOKEEPER")).andReturn(m_zookeeperService).anyTimes();
+    expect(m_cluster.getService("FOO_SERVICE")).andReturn(m_fooService).anyTimes();
+
+    expect(m_clusters.getCluster((String) anyObject())).andReturn(m_cluster).anyTimes();
+
+    ZK_SERVICE_COMPONENTS.put("ZOOKEEPER_SERVER", m_zookeeperServer);
+    FOO_SERVICE_COMPONENTS.put("FOO_COMPONENT", m_fooComponent);
+
+    expect(m_zookeeperService.getServiceComponents()).andReturn(ZK_SERVICE_COMPONENTS).anyTimes();
+    expect(m_fooService.getServiceComponents()).andReturn(FOO_SERVICE_COMPONENTS).anyTimes();
+
+    expect(m_zookeeperInfo.getComponentByName("ZOOKEEPER_SERVER")).andReturn(
+        m_zookeeperServerInfo).anyTimes();
+
+    expect(m_fooInfo.getComponentByName("FOO_COMPONENT")).andReturn(m_fooComponentInfo).anyTimes();
+
+    expect(m_ambariMetaInfo.getService(TARGET_STACK.getStackName(), TARGET_STACK.getStackVersion(),
+        "ZOOKEEPER")).andReturn(m_zookeeperInfo).anyTimes();
+
+    expect(m_ambariMetaInfo.getComponent(TARGET_STACK.getStackName(),
+        TARGET_STACK.getStackVersion(), "ZOOKEEPER", "ZOOKEEPER_SERVER")).andReturn(
+            m_zookeeperServerInfo).anyTimes();
+
+    expect(m_repositoryVersion.getStackId()).andReturn(TARGET_STACK).anyTimes();
+    expect(m_repositoryVersion.getVersion()).andReturn("2.2.0").anyTimes();
+
+    expect(m_repositoryVersion.getRepositoryXml()).andReturn(m_vdfXml).anyTimes();
+    expect(m_vdfXml.getClusterSummary(anyObject(Cluster.class))).andReturn(m_clusterVersionSummary).anyTimes();
+    expect(m_clusterVersionSummary.getAvailableServiceNames()).andReturn(CLUSTER_SERVICES.keySet()).anyTimes();
+
+  }
+
+  /**
+   * Tests that the check passes when services and components exist.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testCheckPassesWhenServicAndComponentsExist() throws Exception {
+    PrerequisiteCheck check = new PrerequisiteCheck(CheckDescription.COMPONENTS_EXIST_IN_TARGET_REPO, "c1");
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setSourceStackId(SOURCE_STACK);
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+
+    CLUSTER_SERVICES.put("ZOOKEEPER", m_zookeeperService);
+    expect(m_zookeeperInfo.isValid()).andReturn(true).atLeastOnce();
+    expect(m_zookeeperInfo.isDeleted()).andReturn(false).atLeastOnce();
+    expect(m_zookeeperServerInfo.isVersionAdvertised()).andReturn(true).atLeastOnce();
+    expect(m_zookeeperServerInfo.isDeleted()).andReturn(false).atLeastOnce();
+
+    replayAll();
+
+    Assert.assertTrue(m_check.isApplicable(request));
+
+    m_check.perform(check, request);
+
+    Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
+    Assert.assertTrue(StringUtils.isBlank(check.getFailReason()));
+  }
+
+  /**
+   * Tests that the check passes when a service doesn't exist but isn't
+   * advertising its version.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testCheckPassesWhenComponentNotAdvertisingVersion() throws Exception {
+    PrerequisiteCheck check = new PrerequisiteCheck(CheckDescription.COMPONENTS_EXIST_IN_TARGET_REPO, "c1");
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setSourceStackId(SOURCE_STACK);
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+
+    CLUSTER_SERVICES.put("FOO_SERVICE", m_fooService);
+
+    expect(m_ambariMetaInfo.getService(TARGET_STACK.getStackName(), TARGET_STACK.getStackVersion(),
+        "FOO_SERVICE")).andReturn(m_fooInfo).anyTimes();
+
+    expect(m_ambariMetaInfo.getComponent(TARGET_STACK.getStackName(),
+        TARGET_STACK.getStackVersion(), "FOO_SERVICE", "FOO_COMPONENT")).andReturn(
+            m_fooComponentInfo).atLeastOnce();
+
+    expect(m_fooInfo.isValid()).andReturn(true).atLeastOnce();
+    expect(m_fooInfo.isDeleted()).andReturn(false).atLeastOnce();
+    expect(m_fooComponentInfo.isVersionAdvertised()).andReturn(false).atLeastOnce();
+    expect(m_fooComponentInfo.isDeleted()).andReturn(true).atLeastOnce();
+
+    replayAll();
+
+    Assert.assertTrue(m_check.isApplicable(request));
+
+    m_check.perform(check, request);
+
+    Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
+    Assert.assertTrue(StringUtils.isBlank(check.getFailReason()));
+  }
+
+  /**
+   * Tests that the check fails when the service exists but was deleted.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testCheckFailsWhenServiceExistsButIsDeleted() throws Exception {
+    PrerequisiteCheck check = new PrerequisiteCheck(CheckDescription.COMPONENTS_EXIST_IN_TARGET_REPO, "c1");
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setSourceStackId(SOURCE_STACK);
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+
+    CLUSTER_SERVICES.put("ZOOKEEPER", m_zookeeperService);
+    expect(m_zookeeperInfo.isValid()).andReturn(true).atLeastOnce();
+    expect(m_zookeeperInfo.isDeleted()).andReturn(true).atLeastOnce();
+
+    replayAll();
+
+    Assert.assertTrue(m_check.isApplicable(request));
+
+    m_check.perform(check, request);
+
+    Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
+    Assert.assertTrue(check.getFailedOn().contains("ZOOKEEPER"));
+  }
+
+  /**
+   * Tests that the check fails when the component exists but what deleted.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testCheckFailsWhenComponentExistsButIsDeleted() throws Exception {
+    PrerequisiteCheck check = new PrerequisiteCheck(CheckDescription.COMPONENTS_EXIST_IN_TARGET_REPO, "c1");
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setSourceStackId(SOURCE_STACK);
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+
+    CLUSTER_SERVICES.put("ZOOKEEPER", m_zookeeperService);
+    expect(m_zookeeperInfo.isValid()).andReturn(true).atLeastOnce();
+    expect(m_zookeeperInfo.isDeleted()).andReturn(false).atLeastOnce();
+    expect(m_zookeeperServerInfo.isVersionAdvertised()).andReturn(true).atLeastOnce();
+    expect(m_zookeeperServerInfo.isDeleted()).andReturn(true).atLeastOnce();
+
+    replayAll();
+
+    Assert.assertTrue(m_check.isApplicable(request));
+
+    m_check.perform(check, request);
+
+    Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
+    Assert.assertTrue(check.getFailedOn().contains("ZOOKEEPER_SERVER"));
+  }
+
+  /**
+   * Tests that the check fails when the component exists but what deleted.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testCheckFailsWhenServiceIsMissing() throws Exception {
+    PrerequisiteCheck check = new PrerequisiteCheck(
+        CheckDescription.COMPONENTS_EXIST_IN_TARGET_REPO, "c1");
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setSourceStackId(SOURCE_STACK);
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+
+    CLUSTER_SERVICES.put("ZOOKEEPER", m_zookeeperService);
+    CLUSTER_SERVICES.put("FOO_SERVICE", m_fooService);
+
+    expect(m_ambariMetaInfo.getService(TARGET_STACK.getStackName(), TARGET_STACK.getStackVersion(),
+        "FOO_SERVICE")).andThrow(new StackAccessException(""));
+
+    expect(m_zookeeperInfo.isValid()).andReturn(true).atLeastOnce();
+    expect(m_zookeeperInfo.isDeleted()).andReturn(false).atLeastOnce();
+    expect(m_zookeeperServerInfo.isVersionAdvertised()).andReturn(true).atLeastOnce();
+    expect(m_zookeeperServerInfo.isDeleted()).andReturn(false).atLeastOnce();
+
+    replayAll();
+
+    Assert.assertTrue(m_check.isApplicable(request));
+
+    m_check.perform(check, request);
+
+    Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
+    Assert.assertTrue(check.getFailedOn().contains("FOO_SERVICE"));
+  }
+
+  /**
+   * Tests that the check fails when the component exists but what deleted.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testCheckFailsWhenComponentIsMissing() throws Exception {
+    PrerequisiteCheck check = new PrerequisiteCheck(
+        CheckDescription.COMPONENTS_EXIST_IN_TARGET_REPO, "c1");
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setSourceStackId(SOURCE_STACK);
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+
+    CLUSTER_SERVICES.put("FOO_SERVICE", m_fooService);
+
+    expect(m_ambariMetaInfo.getService(TARGET_STACK.getStackName(), TARGET_STACK.getStackVersion(),
+        "FOO_SERVICE")).andReturn(m_fooInfo).anyTimes();
+
+    expect(m_ambariMetaInfo.getComponent(TARGET_STACK.getStackName(),
+        TARGET_STACK.getStackVersion(), "FOO_SERVICE", "FOO_COMPONENT")).andThrow(
+            new StackAccessException(""));
+
+    expect(m_zookeeperInfo.isValid()).andReturn(true).atLeastOnce();
+    expect(m_zookeeperInfo.isDeleted()).andReturn(false).atLeastOnce();
+    expect(m_zookeeperServerInfo.isVersionAdvertised()).andReturn(true).atLeastOnce();
+    expect(m_zookeeperServerInfo.isDeleted()).andReturn(false).atLeastOnce();
+
+    expect(m_fooInfo.isValid()).andReturn(true).atLeastOnce();
+    expect(m_fooInfo.isDeleted()).andReturn(false).atLeastOnce();
+
+    replayAll();
+
+    Assert.assertTrue(m_check.isApplicable(request));
+
+    m_check.perform(check, request);
+
+    Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
+    Assert.assertTrue(check.getFailedOn().contains("FOO_COMPONENT"));
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/ComponentsInstallationCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ComponentsInstallationCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ComponentsInstallationCheckTest.java
index ef833b0..4ae33f8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ComponentsInstallationCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ComponentsInstallationCheckTest.java
@@ -37,13 +37,17 @@ import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.State;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 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.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 import org.powermock.api.mockito.PowerMockito;
@@ -63,15 +67,30 @@ public class ComponentsInstallationCheckTest {
   private final Clusters clusters = Mockito.mock(Clusters.class);
   private AmbariMetaInfo ambariMetaInfo = Mockito.mock(AmbariMetaInfo.class);
 
-  final RepositoryVersionEntity m_repositoryVersion = Mockito.mock(RepositoryVersionEntity.class);
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
 
   /**
    *
    */
   @Before
-  public void setup() {
+  public void setup() throws Exception {
+    MockitoAnnotations.initMocks(this);
+
+    m_services.clear();
     Mockito.when(m_repositoryVersion.getVersion()).thenReturn("2.2.0.0-1234");
     Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.2"));
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
   }
 
   @Test
@@ -118,10 +137,9 @@ public class ComponentsInstallationCheckTest {
     Mockito.when(tezService.getMaintenanceState()).thenReturn(MaintenanceState.OFF);
     Mockito.when(amsService.getMaintenanceState()).thenReturn(MaintenanceState.OFF);
 
-    HashMap<String, Service> clusterServices = new HashMap<>();
-    clusterServices.put("HDFS", hdfsService);
-    clusterServices.put("TEZ", tezService);
-    clusterServices.put("AMBARI_METRICS", amsService);
+    m_services.put("HDFS", hdfsService);
+    m_services.put("TEZ", tezService);
+    m_services.put("AMBARI_METRICS", amsService);
 
     Mockito.when(hdfsService.getName()).thenReturn("HDFS");
     Mockito.when(tezService.getName()).thenReturn("TEZ");
@@ -131,7 +149,11 @@ public class ComponentsInstallationCheckTest {
     Mockito.when(tezService.isClientOnlyService()).thenReturn(true);
     Mockito.when(amsService.isClientOnlyService()).thenReturn(false);
 
-    Mockito.when(cluster.getServices()).thenReturn(clusterServices);
+    Mockito.when(cluster.getServices()).thenReturn(m_services);
+
+    Mockito.when(cluster.getService("HDFS")).thenReturn(hdfsService);
+    Mockito.when(cluster.getService("TEZ")).thenReturn(tezService);
+    Mockito.when(cluster.getService("AMBARI_METRICS")).thenReturn(amsService);
 
     Mockito.when(ambariMetaInfo.getComponent(Mockito.anyString(), Mockito.anyString(),
         Mockito.anyString(), Mockito.anyString())).thenAnswer(new Answer<ComponentInfo>() {
@@ -260,22 +282,26 @@ public class ComponentsInstallationCheckTest {
       Mockito.when(hcs.getDesiredState()).thenReturn(State.INSTALLED);
       Mockito.when(hcs.getCurrentState()).thenReturn(State.STARTED);
     }
+
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+
     Mockito.when(hcsTezClient.getCurrentState()).thenReturn(State.INSTALLED);
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
-    componentsInstallationCheck.perform(check, new PrereqCheckRequest("cluster"));
+    componentsInstallationCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
 
     // Case 2. Ensure that AMS is ignored even if their current state is not INSTALLED
     Mockito.when(hcsMetricsCollector.getCurrentState()).thenReturn(State.INSTALL_FAILED);
     Mockito.when(hcsMetricsMonitor.getCurrentState()).thenReturn(State.INSTALL_FAILED);
     check = new PrerequisiteCheck(null, null);
-    componentsInstallationCheck.perform(check, new PrereqCheckRequest("cluster"));
+    componentsInstallationCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
 
     // Case 3: Change TEZ client state to INSTALL_FAILED, should fail
     Mockito.when(hcsTezClient.getCurrentState()).thenReturn(State.INSTALL_FAILED);
     check = new PrerequisiteCheck(null, null);
-    componentsInstallationCheck.perform(check, new PrereqCheckRequest("cluster"));
+    componentsInstallationCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
     Assert.assertTrue(check.getFailReason().indexOf("Service components in INSTALL_FAILED state") > -1);
 
@@ -283,7 +309,7 @@ public class ComponentsInstallationCheckTest {
     Mockito.when(tezService.getMaintenanceState()).thenReturn(MaintenanceState.ON);
     Mockito.when(hcsTezClient.getCurrentState()).thenReturn(State.INSTALL_FAILED);
     check = new PrerequisiteCheck(null, null);
-    componentsInstallationCheck.perform(check, new PrereqCheckRequest("cluster"));
+    componentsInstallationCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
 
     // Case 5: Change TEZ client state to INSTALL_FAILED and place host2 in Maintenance mode, should succeed
@@ -291,7 +317,7 @@ public class ComponentsInstallationCheckTest {
     Mockito.when(host2.getMaintenanceState(1L)).thenReturn(MaintenanceState.ON);
     Mockito.when(hcsTezClient.getCurrentState()).thenReturn(State.INSTALL_FAILED);
     check = new PrerequisiteCheck(null, null);
-    componentsInstallationCheck.perform(check, new PrereqCheckRequest("cluster"));
+    componentsInstallationCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/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
index 14fab7c..606d4b7 100644
--- 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
@@ -52,7 +52,7 @@ public class HiveDynamicServiceDiscoveryCheckTest {
    *
    */
   @Before
-  public void setup() {
+  public void setup() throws Exception {
     m_check.clustersProvider = new Provider<Clusters>() {
 
       @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheckTest.java
index 7a6748b..3dfe2f8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheckTest.java
@@ -31,31 +31,46 @@ import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 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.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
 import com.google.inject.Provider;
 
 /**
  * Tests {@link HiveMultipleMetastoreCheck}
  */
+@RunWith(MockitoJUnitRunner.class)
 public class HiveMultipleMetastoreCheckTest {
   private final Clusters m_clusters = Mockito.mock(Clusters.class);
   private final HiveMultipleMetastoreCheck m_check = new HiveMultipleMetastoreCheck();
   private final RepositoryVersionDAO repositoryVersionDAO = Mockito.mock(
       RepositoryVersionDAO.class);
 
-  final RepositoryVersionEntity m_repositoryVersion = Mockito.mock(RepositoryVersionEntity.class);
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
 
   /**
    *
    */
   @Before
-  public void setup() {
+  public void setup() throws Exception {
     m_check.clustersProvider = new Provider<Clusters>() {
 
       @Override
@@ -68,6 +83,11 @@ public class HiveMultipleMetastoreCheckTest {
 
     Mockito.when(m_repositoryVersion.getVersion()).thenReturn("1.0.0.0-1234");
     Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "1.0"));
+
+    m_services.clear();
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
   }
 
   /**
@@ -81,10 +101,9 @@ public class HiveMultipleMetastoreCheckTest {
 
     Mockito.when(cluster.getClusterId()).thenReturn(1L);
     Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster);
-    Map<String, Service> services = new HashMap<>();
-    Mockito.when(cluster.getServices()).thenReturn(services);
+    Mockito.when(cluster.getServices()).thenReturn(m_services);
 
-    services.put("HDFS", Mockito.mock(Service.class));
+    m_services.put("HDFS", Mockito.mock(Service.class));
 
     PrereqCheckRequest request = new PrereqCheckRequest("cluster");
     request.setTargetRepositoryVersion(m_repositoryVersion);
@@ -93,7 +112,7 @@ public class HiveMultipleMetastoreCheckTest {
     Assert.assertFalse(m_check.isApplicable(request));
 
     // install HIVE
-    services.put("HIVE", Mockito.mock(Service.class));
+    m_services.put("HIVE", Mockito.mock(Service.class));
 
     m_check.repositoryVersionDaoProvider = new Provider<RepositoryVersionDAO>() {
       @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveNotRollingWarningTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveNotRollingWarningTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveNotRollingWarningTest.java
index 665d6ec..3b0c900 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveNotRollingWarningTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveNotRollingWarningTest.java
@@ -21,28 +21,57 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.ambari.server.controller.PrereqCheckRequest;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
 import org.easymock.EasyMock;
 import org.easymock.EasyMockSupport;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
 import com.google.inject.Provider;
 
 /**
  * Tests {@link HiveNotRollingWarning}.
  */
+@RunWith(MockitoJUnitRunner.class)
 public class HiveNotRollingWarningTest extends EasyMockSupport {
 
   private final String m_clusterName = "c1";
   private final Clusters m_clusters = niceMock(Clusters.class);
 
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
+
+  @Before
+  public void setup() throws Exception {
+    m_services.clear();
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
+  }
+
+
   /**
    * @throws Exception
    */
@@ -60,18 +89,18 @@ public class HiveNotRollingWarningTest extends EasyMockSupport {
     final Cluster cluster = niceMock(Cluster.class);
     final Service hive = niceMock(Service.class);
 
-    final Map<String, Service> services = new HashMap<>();
-    services.put("HIVE", hive);
+    m_services.put("HIVE", hive);
 
     EasyMock.expect(cluster.getClusterId()).andReturn(1L).anyTimes();
 
     EasyMock.expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.3")).anyTimes();
-    EasyMock.expect(cluster.getServices()).andReturn(services).atLeastOnce();
+    EasyMock.expect(cluster.getServices()).andReturn(m_services).anyTimes();
     EasyMock.expect(m_clusters.getCluster(m_clusterName)).andReturn(cluster).atLeastOnce();
 
     PrereqCheckRequest request = niceMock(PrereqCheckRequest.class);
-    EasyMock.expect(request.getClusterName()).andReturn(m_clusterName);
-    EasyMock.expect(request.getUpgradeType()).andReturn(UpgradeType.ROLLING);
+    EasyMock.expect(request.getClusterName()).andReturn(m_clusterName).anyTimes();
+    EasyMock.expect(request.getUpgradeType()).andReturn(UpgradeType.ROLLING).anyTimes();
+    EasyMock.expect(request.getTargetRepositoryVersion()).andReturn(m_repositoryVersion).atLeastOnce();
 
     replayAll();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsHeartbeatCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsHeartbeatCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsHeartbeatCheckTest.java
index a15f9c1..daf2e4c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsHeartbeatCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsHeartbeatCheckTest.java
@@ -52,7 +52,7 @@ public class HostsHeartbeatCheckTest {
    *
    */
   @Before
-  public void setup() {
+  public void setup() throws Exception {
     Mockito.when(m_repositoryVersion.getVersion()).thenReturn("2.2.0.0-1234");
     Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.2"));
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsMasterMaintenanceCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsMasterMaintenanceCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsMasterMaintenanceCheckTest.java
index 6399166..0cc3e73 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsMasterMaintenanceCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsMasterMaintenanceCheckTest.java
@@ -30,6 +30,8 @@ import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.apache.ambari.server.state.stack.UpgradePack;
@@ -37,8 +39,12 @@ import org.apache.ambari.server.state.stack.UpgradePack.ProcessingComponent;
 import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
 import com.google.inject.Provider;
 
@@ -46,22 +52,39 @@ import com.google.inject.Provider;
  * Unit tests for HostsMasterMaintenanceCheck
  *
  */
+@RunWith(MockitoJUnitRunner.class)
 public class HostsMasterMaintenanceCheckTest {
   private final Clusters clusters = Mockito.mock(Clusters.class);
   private final RepositoryVersionDAO repositoryVersionDAO = Mockito.mock(RepositoryVersionDAO.class);
   private final RepositoryVersionHelper repositoryVersionHelper = Mockito.mock(RepositoryVersionHelper.class);
   private final AmbariMetaInfo ambariMetaInfo = Mockito.mock(AmbariMetaInfo.class);
 
-  final RepositoryVersionEntity repositoryVersion = Mockito.mock(
-      RepositoryVersionEntity.class);
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
+
+  @Before
+  public void setup() throws Exception {
+    m_services.clear();
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
+  }
 
   @Test
   public void testIsApplicable() throws Exception {
-    Mockito.when(repositoryVersion.getVersion()).thenReturn("1.0.0.0-1234");
-    Mockito.when(repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "1.0"));
+    Mockito.when(m_repositoryVersion.getVersion()).thenReturn("1.0.0.0-1234");
+    Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "1.0"));
 
     final PrereqCheckRequest request = new PrereqCheckRequest("cluster");
-    request.setTargetRepositoryVersion(repositoryVersion);
+    request.setTargetRepositoryVersion(m_repositoryVersion);
     HostsMasterMaintenanceCheck hmmc = new HostsMasterMaintenanceCheck();
     Configuration config = Mockito.mock(Configuration.class);
     hmmc.config = config;
@@ -71,19 +94,13 @@ public class HostsMasterMaintenanceCheckTest {
     HostsMasterMaintenanceCheck hmmc2 = new HostsMasterMaintenanceCheck();
     hmmc2.config = config;
     Assert.assertTrue(hmmc2.isApplicable(request));
-    request.setTargetRepositoryVersion(repositoryVersion);
-
-    // reset the mock
-    Mockito.reset(repositoryVersion);
-
-    hmmc2.config = config;
-    Assert.assertFalse(hmmc2.isApplicable(request));
+    request.setTargetRepositoryVersion(m_repositoryVersion);
   }
 
   @Test
   public void testPerform() throws Exception {
-    Mockito.when(repositoryVersion.getVersion()).thenReturn("1.0.0.0-1234");
-    Mockito.when(repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "1.0"));
+    Mockito.when(m_repositoryVersion.getVersion()).thenReturn("1.0.0.0-1234");
+    Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "1.0"));
 
     final String upgradePackName = "upgrade_pack";
     final HostsMasterMaintenanceCheck hostsMasterMaintenanceCheck = new HostsMasterMaintenanceCheck();
@@ -120,21 +137,22 @@ public class HostsMasterMaintenanceCheckTest {
     Mockito.when(repositoryVersionHelper.getUpgradePackageName(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), (UpgradeType) Mockito.anyObject())).thenReturn(null);
 
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
-    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
-    request.setSourceStackId(new StackId("HDP-1.0"));
-    request.setTargetRepositoryVersion(repositoryVersion);
-    hostsMasterMaintenanceCheck.perform(check, request);
+    PrereqCheckRequest checkRequest = new PrereqCheckRequest("cluster");
+    checkRequest.setSourceStackId(new StackId("HDP-1.0"));
+    checkRequest.setTargetRepositoryVersion(m_repositoryVersion);
+
+    hostsMasterMaintenanceCheck.perform(check, checkRequest);
     Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
 
     Mockito.when(repositoryVersionHelper.getUpgradePackageName(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), (UpgradeType) Mockito.anyObject())).thenReturn(upgradePackName);
     Mockito.when(ambariMetaInfo.getUpgradePacks(Mockito.anyString(), Mockito.anyString())).thenReturn(new HashMap<String, UpgradePack>());
 
     check = new PrerequisiteCheck(null, null);
-    request = new PrereqCheckRequest("cluster");
-    request.setSourceStackId(new StackId("HDP-1.0"));
-    request.setTargetRepositoryVersion(repositoryVersion);
+    checkRequest = new PrereqCheckRequest("cluster");
+    checkRequest.setSourceStackId(new StackId("HDP-1.0"));
+    checkRequest.setTargetRepositoryVersion(m_repositoryVersion);
 
-    hostsMasterMaintenanceCheck.perform(check, request);
+    hostsMasterMaintenanceCheck.perform(check, checkRequest);
     Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
 
     final Map<String, UpgradePack> upgradePacks = new HashMap<>();
@@ -147,11 +165,11 @@ public class HostsMasterMaintenanceCheckTest {
     Mockito.when(clusters.getHostsForCluster(Mockito.anyString())).thenReturn(new HashMap<String, Host>());
 
     check = new PrerequisiteCheck(null, null);
-    request = new PrereqCheckRequest("cluster");
-    request.setSourceStackId(new StackId("HDP-1.0"));
-    request.setTargetRepositoryVersion(repositoryVersion);
+    checkRequest = new PrereqCheckRequest("cluster");
+    checkRequest.setSourceStackId(new StackId("HDP-1.0"));
+    checkRequest.setTargetRepositoryVersion(m_repositoryVersion);
 
-    hostsMasterMaintenanceCheck.perform(check, request);
+    hostsMasterMaintenanceCheck.perform(check, checkRequest);
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsRepositoryVersionCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsRepositoryVersionCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsRepositoryVersionCheckTest.java
index 67e8dfa..5539618 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsRepositoryVersionCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsRepositoryVersionCheckTest.java
@@ -17,7 +17,6 @@
  */
 package org.apache.ambari.server.checks;
 
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -33,13 +32,19 @@ import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.MaintenanceState;
 import org.apache.ambari.server.state.RepositoryVersionState;
+import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 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.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
 import com.google.inject.Provider;
 
@@ -47,23 +52,38 @@ import com.google.inject.Provider;
  * Unit tests for HostsRepositoryVersionCheck
  *
  */
+@RunWith(MockitoJUnitRunner.class)
 public class HostsRepositoryVersionCheckTest {
   private final Clusters clusters = Mockito.mock(Clusters.class);
   private final HostVersionDAO hostVersionDAO = Mockito.mock(HostVersionDAO.class);
   private final RepositoryVersionDAO repositoryVersionDAO = Mockito.mock(RepositoryVersionDAO.class);
 
-  final RepositoryVersionEntity repositoryVersion = Mockito.mock(RepositoryVersionEntity.class);
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
 
   @Before
-  public void setup() {
-    Mockito.when(repositoryVersion.getVersion()).thenReturn("1.0.0.0-1234");
-    Mockito.when(repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "1.0"));
+  public void setup() throws Exception {
+    m_services.clear();
+
+    Mockito.when(m_repositoryVersion.getVersion()).thenReturn("1.0.0.0-1234");
+    Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "1.0"));
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
   }
 
   @Test
   public void testIsApplicable() throws Exception {
     final PrereqCheckRequest request = new PrereqCheckRequest("cluster");
-    request.setTargetRepositoryVersion(repositoryVersion);
+    request.setTargetRepositoryVersion(m_repositoryVersion);
     HostsRepositoryVersionCheck hrvc = new HostsRepositoryVersionCheck();
     Configuration config = Mockito.mock(Configuration.class);
     hrvc.config = config;
@@ -72,13 +92,6 @@ public class HostsRepositoryVersionCheckTest {
     HostsRepositoryVersionCheck hrvc2 = new HostsRepositoryVersionCheck();
     hrvc2.config = config;
     Assert.assertTrue(hrvc2.isApplicable(request));
-
-    Mockito.reset(repositoryVersion);
-    request.setTargetRepositoryVersion(repositoryVersion);
-
-    HostsMasterMaintenanceCheck hmmc2 = new HostsMasterMaintenanceCheck();
-    hmmc2.config = config;
-    Assert.assertFalse(hmmc2.isApplicable(request));
   }
 
   @Test
@@ -131,7 +144,7 @@ public class HostsRepositoryVersionCheckTest {
 
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
     PrereqCheckRequest checkRequest = new PrereqCheckRequest("cluster");
-    checkRequest.setTargetRepositoryVersion(repositoryVersion);
+    checkRequest.setTargetRepositoryVersion(m_repositoryVersion);
 
     hostsRepositoryVersionCheck.perform(check, checkRequest);
     Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
@@ -201,22 +214,29 @@ public class HostsRepositoryVersionCheckTest {
     Mockito.when(host1.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
     Mockito.when(host2.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
     Mockito.when(host3.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
+
+    Mockito.when(host1.getHostName()).thenReturn("host1");
+    Mockito.when(host2.getHostName()).thenReturn("host2");
+    Mockito.when(host3.getHostName()).thenReturn("host3");
+
     hosts.put("host1", host1);
     hosts.put("host2", host2);
     hosts.put("host3", host3);
     Mockito.when(clusters.getHostsForCluster("cluster")).thenReturn(hosts);
 
     HostVersionEntity hve = new HostVersionEntity();
-    hve.setRepositoryVersion(repositoryVersion);
+    hve.setRepositoryVersion(m_repositoryVersion);
     hve.setState(RepositoryVersionState.INSTALLED);
 
-    Mockito.when(
-        hostVersionDAO.findByHost(Mockito.anyString())).thenReturn(
-            Collections.singletonList(hve));
+    for (String hostName : hosts.keySet()) {
+      Mockito.when(hostVersionDAO.findByClusterStackVersionAndHost("cluster",
+          m_repositoryVersion.getStackId(), m_repositoryVersion.getVersion(), hostName)).thenReturn(
+              hve);
+    }
 
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
     PrereqCheckRequest request = new PrereqCheckRequest("cluster");
-    request.setTargetRepositoryVersion(repositoryVersion);
+    request.setTargetRepositoryVersion(m_repositoryVersion);
 
     hostsRepositoryVersionCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
@@ -256,22 +276,30 @@ public class HostsRepositoryVersionCheckTest {
     Mockito.when(host1.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
     Mockito.when(host2.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
     Mockito.when(host3.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
+
+    Mockito.when(host1.getHostName()).thenReturn("host1");
+    Mockito.when(host2.getHostName()).thenReturn("host2");
+    Mockito.when(host3.getHostName()).thenReturn("host3");
+
     hosts.put("host1", host1);
     hosts.put("host2", host2);
     hosts.put("host3", host3);
     Mockito.when(clusters.getHostsForCluster("cluster")).thenReturn(hosts);
 
     HostVersionEntity hve = new HostVersionEntity();
-    hve.setRepositoryVersion(repositoryVersion);
+    hve.setRepositoryVersion(m_repositoryVersion);
     hve.setState(RepositoryVersionState.NOT_REQUIRED);
 
-    Mockito.when(
-        hostVersionDAO.findByHost(Mockito.anyString())).thenReturn(
-            Collections.singletonList(hve));
+    for (String hostName : hosts.keySet()) {
+      Mockito.when(hostVersionDAO.findByClusterStackVersionAndHost("cluster",
+          m_repositoryVersion.getStackId(), m_repositoryVersion.getVersion(), hostName)).thenReturn(
+              hve);
+    }
 
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
     PrereqCheckRequest request = new PrereqCheckRequest("cluster");
-    request.setTargetRepositoryVersion(repositoryVersion);
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+
     hostsRepositoryVersionCheck.perform(check, request);
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java
index 9d623ec..cdfbb0a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java
@@ -72,7 +72,7 @@ public class InstallPackagesCheckTest {
    *
    */
   @Before
-  public void setup() {
+  public void setup() throws Exception {
     Mockito.when(m_repositoryVersion.getVersion()).thenReturn(repositoryVersion);
     Mockito.when(m_repositoryVersion.getStackId()).thenReturn(targetStackId);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/KafkaKerberosCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/KafkaKerberosCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/KafkaKerberosCheckTest.java
index 41962f9..9a95c42 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/KafkaKerberosCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/KafkaKerberosCheckTest.java
@@ -21,26 +21,44 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.ambari.server.controller.PrereqCheckRequest;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.SecurityType;
 import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 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.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
 import com.google.inject.Provider;
 
+@RunWith(MockitoJUnitRunner.class)
 public class KafkaKerberosCheckTest {
   private final Clusters clusters = Mockito.mock(Clusters.class);
 
   private final KafkaKerberosCheck kafkaKerberosCheck = new KafkaKerberosCheck();
 
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
+
   @Before
-  public void setup() {
+  public void setup() throws Exception {
     kafkaKerberosCheck.clustersProvider = new Provider<Clusters>() {
 
       @Override
@@ -48,24 +66,31 @@ public class KafkaKerberosCheckTest {
         return clusters;
       }
     };
+
+    m_services.clear();
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
   }
 
   @Test
   public void testIsApplicable() throws Exception {
     final Cluster cluster = Mockito.mock(Cluster.class);
-    final Map<String, Service> services = new HashMap<>();
     final Service service = Mockito.mock(Service.class);
 
-    services.put("KAFKA", service);
+    m_services.put("KAFKA", service);
 
-    Mockito.when(cluster.getServices()).thenReturn(services);
+    Mockito.when(cluster.getServices()).thenReturn(m_services);
     Mockito.when(cluster.getClusterId()).thenReturn(1L);
     Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
 
-    Assert.assertTrue(kafkaKerberosCheck.isApplicable(new PrereqCheckRequest("cluster")));
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+
+    Assert.assertTrue(kafkaKerberosCheck.isApplicable(request));
 
-    services.remove("KAFKA");
-    Assert.assertFalse(kafkaKerberosCheck.isApplicable(new PrereqCheckRequest("cluster")));
+    m_services.remove("KAFKA");
+    Assert.assertFalse(kafkaKerberosCheck.isApplicable(request));
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/test/java/org/apache/ambari/server/checks/MapReduce2JobHistoryStatePreservingCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/MapReduce2JobHistoryStatePreservingCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/MapReduce2JobHistoryStatePreservingCheckTest.java
index 32ecc26..096781c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/MapReduce2JobHistoryStatePreservingCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/MapReduce2JobHistoryStatePreservingCheckTest.java
@@ -31,31 +31,46 @@ import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.RepositoryType;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 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.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
 
 import com.google.inject.Provider;
 
 /**
  * Tests for {@link org.apache.ambari.server.checks.MapReduce2JobHistoryStatePreservingCheckTest}
  */
+@RunWith(MockitoJUnitRunner.class)
 public class MapReduce2JobHistoryStatePreservingCheckTest {
   private final Clusters m_clusters = Mockito.mock(Clusters.class);
   private final RepositoryVersionDAO m_repositoryVersionDao = Mockito.mock(RepositoryVersionDAO.class);
 
   private final MapReduce2JobHistoryStatePreservingCheck m_check = new MapReduce2JobHistoryStatePreservingCheck();
 
-  final RepositoryVersionEntity m_repositoryVersion = Mockito.mock(RepositoryVersionEntity.class);
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
 
   /**
    *
    */
   @Before
-  public void setup() {
+  public void setup() throws Exception {
     m_check.clustersProvider = new Provider<Clusters>() {
 
       @Override
@@ -80,6 +95,11 @@ public class MapReduce2JobHistoryStatePreservingCheckTest {
 
     Mockito.when(m_repositoryVersion.getVersion()).thenReturn("2.3.1.1-1234");
     Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.3"));
+
+    m_services.clear();
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
   }
 
   /**
@@ -92,8 +112,7 @@ public class MapReduce2JobHistoryStatePreservingCheckTest {
     Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster);
     Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.3"));
 
-    Map<String, Service> services = new HashMap<>();
-    Mockito.when(cluster.getServices()).thenReturn(services);
+    Mockito.when(cluster.getServices()).thenReturn(m_services);
 
     PrereqCheckRequest request = new PrereqCheckRequest("cluster");
     request.setSourceStackId(new StackId("HDP", "2.3.0.0"));
@@ -103,7 +122,7 @@ public class MapReduce2JobHistoryStatePreservingCheckTest {
     Assert.assertFalse(m_check.isApplicable(request));
 
     // MAPREDUCE2 installed
-    services.put("MAPREDUCE2", Mockito.mock(Service.class));
+    m_services.put("MAPREDUCE2", Mockito.mock(Service.class));
     Assert.assertTrue(m_check.isApplicable(request));
   }
 
@@ -157,11 +176,15 @@ public class MapReduce2JobHistoryStatePreservingCheckTest {
       }
     });
     Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("MYSTACK-12.2"));
-    RepositoryVersionEntity repositoryVersionEntity = Mockito.mock(RepositoryVersionEntity.class);
     Mockito.when(m_clusters.getCluster("c1")).thenReturn(cluster);
     PrereqCheckRequest request = new PrereqCheckRequest("c1");
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+
+    Mockito.when(m_repositoryVersion.getVersion()).thenReturn("2.0.0.1");
+
+    // MAPREDUCE2 installed
+    m_services.put("MAPREDUCE2", Mockito.mock(Service.class));
 
-    Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.0.0.1");
     boolean isApplicable = m_check.isApplicable(request);
     Assert.assertTrue(isApplicable);
   }


Mime
View raw message