AMBARI-21677 - Upgrade Pre-Checks Should Take PATCH/SERVICE Types Into Account 
(jonathanhurley)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 108ad9b4a0d154abcfff9e4fe5fd965ae81d62e5
Parents: b4de620
Author: Jonathan Hurley <jhur...@hortonworks.com>
Authored: Mon Aug 7 23:46:47 2017 -0400
Committer: Jonathan Hurley <jhur...@hortonworks.com>
Committed: Wed Aug 9 14:01:29 2017 -0400

----------------------------------------------------------------------
 .../server/checks/AbstractCheckDescriptor.java  | 252 ++++++++-----
 .../server/checks/AtlasPresenceCheck.java       |  13 +-
 .../server/checks/AutoStartDisabledCheck.java   |  11 +
 .../ambari/server/checks/CheckDescription.java  |  53 +--
 .../server/checks/ClientRetryPropertyCheck.java |   8 +-
 .../checks/ComponentsExistInRepoCheck.java      | 140 ++++++++
 .../checks/ComponentsInstallationCheck.java     |   5 +-
 .../server/checks/ConfigurationMergeCheck.java  |   3 +-
 .../ambari/server/checks/HealthCheck.java       |   3 +-
 .../HiveDynamicServiceDiscoveryCheck.java       |  15 +-
 .../checks/HiveMultipleMetastoreCheck.java      |   7 +-
 .../server/checks/HiveNotRollingWarning.java    |  11 +-
 .../checks/HostsMasterMaintenanceCheck.java     |  17 +-
 .../checks/HostsRepositoryVersionCheck.java     |  60 +---
 .../server/checks/InstallPackagesCheck.java     |  18 +-
 .../server/checks/KafkaKerberosCheck.java       |  10 +-
 ...apReduce2JobHistoryStatePreservingCheck.java |   7 +-
 .../server/checks/RangerAuditDbCheck.java       |  10 +-
 .../server/checks/RangerPasswordCheck.java      |  29 +-
 .../server/checks/RangerSSLConfigCheck.java     |   7 +-
 .../checks/SecondaryNamenodeDeletedCheck.java   |  24 +-
 .../server/checks/ServicePresenceCheck.java     |   4 +-
 .../checks/ServicesMaintenanceModeCheck.java    |  11 +-
 .../ServicesMapReduceDistributedCacheCheck.java |  27 +-
 .../ServicesNamenodeHighAvailabilityCheck.java  |  11 +-
 .../checks/ServicesNamenodeTruncateCheck.java   |  26 +-
 .../ServicesTezDistributedCacheCheck.java       |  25 +-
 .../ambari/server/checks/ServicesUpCheck.java   |  11 +-
 .../checks/ServicesYarnWorkPreservingCheck.java |   7 +-
 .../server/checks/StormShutdownWarning.java     |  11 +-
 .../checks/YarnRMHighAvailabilityCheck.java     |   8 +-
 .../YarnTimelineServerStatePreservingCheck.java |  99 ++++--
 .../server/controller/PrereqCheckRequest.java   |  21 --
 .../apache/ambari/server/state/CheckHelper.java |   4 +-
 .../2.0.6/hooks/before-START/scripts/params.py  |   7 +-
 .../3.0/hooks/before-START/scripts/params.py    |   7 +-
 .../checks/AbstractCheckDescriptorTest.java     | 317 +++++++++--------
 .../checks/ClientRetryPropertyCheckTest.java    |  48 +--
 .../checks/ComponentExistsInRepoCheckTest.java  | 352 +++++++++++++++++++
 .../checks/ComponentsInstallationCheckTest.java |  50 ++-
 .../HiveDynamicServiceDiscoveryCheckTest.java   |   2 +-
 .../checks/HiveMultipleMetastoreCheckTest.java  |  31 +-
 .../checks/HiveNotRollingWarningTest.java       |  39 +-
 .../server/checks/HostsHeartbeatCheckTest.java  |   2 +-
 .../checks/HostsMasterMaintenanceCheckTest.java |  72 ++--
 .../checks/HostsRepositoryVersionCheckTest.java |  76 ++--
 .../server/checks/InstallPackagesCheckTest.java |   2 +-
 .../server/checks/KafkaKerberosCheckTest.java   |  39 +-
 ...duce2JobHistoryStatePreservingCheckTest.java |  37 +-
 .../server/checks/RangerAuditDbCheckTest.java   |  42 ++-
 .../server/checks/RangerPasswordCheckTest.java  |  47 +--
 .../server/checks/RangerSSLConfigCheckTest.java |  38 +-
 .../SecondaryNamenodeDeletedCheckTest.java      |  51 ++-
 .../server/checks/ServicePresenceCheckTest.java |  21 +-
 .../ServicesMaintenanceModeCheckTest.java       |  34 +-
 ...vicesMapReduceDistributedCacheCheckTest.java |  50 ++-
 ...rvicesNamenodeHighAvailabilityCheckTest.java |  39 +-
 .../ServicesNamenodeTruncateCheckTest.java      |  60 ++--
 .../ServicesTezDistributedCacheCheckTest.java   |  39 +-
 .../server/checks/ServicesUpCheckTest.java      |  67 ++--
 .../ServicesYarnWorkPreservingCheckTest.java    |  38 +-
 .../server/checks/StormShutdownWarningTest.java |  38 +-
 ...nTimelineServerStatePreservingCheckTest.java |   2 +-
 .../ambari/server/state/CheckHelperTest.java    | 246 +++++++------
 64 files changed, 1960 insertions(+), 901 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/AbstractCheckDescriptor.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/AbstractCheckDescriptor.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/AbstractCheckDescriptor.java
index bda2c07..4eae3aa 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/AbstractCheckDescriptor.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/AbstractCheckDescriptor.java
@@ -17,13 +17,12 @@
  */
 package org.apache.ambari.server.checks;
 
+import java.util.Collections;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.ambari.annotations.Experimental;
-import org.apache.ambari.annotations.ExperimentalFeature;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
@@ -36,19 +35,20 @@ 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.RepositoryType;
-import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceInfo;
+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.PrereqCheckType;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.apache.ambari.server.state.stack.UpgradePack;
 import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
-import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Lists;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
 
@@ -62,7 +62,7 @@ public abstract class AbstractCheckDescriptor {
   protected static final String DEFAULT = "default";
 
   @Inject
-  Provider<Clusters> clustersProvider;
+  protected Provider<Clusters> clustersProvider;
 
   @Inject
   Provider<HostVersionDAO> hostVersionDaoProvider;
@@ -94,75 +94,54 @@ public abstract class AbstractCheckDescriptor {
   }
 
   /**
-   * Tests if the prerequisite check is applicable to given cluster. This
-   * method's default logic is to ensure that the cluster stack source and
-   * target are compatible with the prerequisite check. When overridding this
-   * method, call {@code super#isApplicable(PrereqCheckRequest)}.
+   * Gets the set of services that this check is associated with. If the check
+   * is not associated with a particular service, then this should be an empty
+   * set.
    *
-   * @param request
-   *          prerequisite check request
-   * @return true if check should be performed
+   * @return a set of services which will determine whether this check is
+   *         applicable.
+   */
+  public Set<String> getApplicableServices() {
+    return Collections.emptySet();
+  }
+
+  /**
+   * Gets any additional qualifications which an upgrade check should run in
+   * order to determine if it's applicable to the upgrade.
    *
-   * @throws org.apache.ambari.server.AmbariException
-   *           if server error happens
+   * @return a list of qualifications, or an empty list.
    */
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    // this is default behaviour
-   return true;
+  public List<CheckQualification> getQualifications() {
+    return Collections.emptyList();
   }
 
   /**
-   * Same like {@code isApplicable(PrereqCheckRequest request)}, but with 
service presence check
+   * Tests if the prerequisite check is applicable to given upgrade request. If
+   * a check requires some extra processing
+   *
    * @param request
    *          prerequisite check request
-   * @param requiredServices
-   *          set of services, which need to be present to allow check 
execution
-   * @param requiredAll
-   *          require all services in the list or at least one need to present
    * @return true if check should be performed
+   *
    * @throws org.apache.ambari.server.AmbariException
    *           if server error happens
    */
-  @Experimental(feature = ExperimentalFeature.PATCH_UPGRADES)
-  public boolean isApplicable(PrereqCheckRequest request, List<String> 
requiredServices, boolean requiredAll) throws AmbariException {
-    final Cluster cluster = 
clustersProvider.get().getCluster(request.getClusterName());
-    Set<String> services = cluster.getServices().keySet();
-
-    // default return value depends on assign inside check block
-    boolean serviceFound = requiredAll && !requiredServices.isEmpty();
-
-    for (String service : requiredServices) {
-      if ( services.contains(service) && !requiredAll) {
-        serviceFound = true;
-        break;
-      } else if (!services.contains(service) && requiredAll) {
-        serviceFound = false;
-        break;
-      }
-    }
-
-    // !!! service is found and deployed - now check if it is part of the VDF
-    if (serviceFound && null != request.getTargetStackId()) {
-      String stackName = request.getTargetStackId().getStackName();
-      RepositoryVersionEntity rve = repositoryVersionDaoProvider.get().
-          findByStackNameAndVersion(stackName, request.getTargetVersion());
-
-      if (RepositoryType.STANDARD != rve.getType()) {
-        try {
-          Set<String> availableServices = 
rve.getRepositoryXml().getAvailableServiceNames();
-
-          if (!CollectionUtils.containsAny(availableServices, 
requiredServices)) {
-            serviceFound = false;
-          }
-        } catch (Exception e) {
-          LOG.warn("Could not parse xml for %s", request.getTargetVersion(), 
e);
-        }
+  public final boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
+    List<CheckQualification> qualifications = Lists.<CheckQualification> 
newArrayList(
+        new ServiceQualification());
+
+    // add any others from the concrete check
+    qualifications.addAll(getQualifications());
+    for (CheckQualification qualification : qualifications) {
+      if (!qualification.isApplicable(request)) {
+        return false;
       }
     }
 
-    return serviceFound;
+    return true;
   }
 
+
   /**
    * Executes check against given cluster.
    *
@@ -198,7 +177,8 @@ public abstract class AbstractCheckDescriptor {
    * @param request           the request
    * @return the failure string
    */
-  protected String getFailReason(PrerequisiteCheck prerequisiteCheck, 
PrereqCheckRequest request) {
+  protected String getFailReason(PrerequisiteCheck prerequisiteCheck, 
PrereqCheckRequest request)
+      throws AmbariException {
     return getFailReason(DEFAULT, prerequisiteCheck, request);
   }
 
@@ -233,15 +213,6 @@ public abstract class AbstractCheckDescriptor {
     return properties.get(propertyName);
   }
 
-  protected Cluster getCluster(PrereqCheckRequest request) throws 
AmbariException {
-    String clusterName = request.getClusterName();
-    if (null != clusterName) {
-      return clustersProvider.get().getCluster(clusterName);
-    }
-
-    return null;
-  }
-
   /**
    * Gets the fail reason
    * @param key               the failure text key
@@ -249,12 +220,13 @@ public abstract class AbstractCheckDescriptor {
    * @param request           the request
    * @return the failure string
    */
-  protected String getFailReason(String key,
-      PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) {
+  protected String getFailReason(String key, PrerequisiteCheck 
prerequisiteCheck,
+      PrereqCheckRequest request) throws AmbariException {
     String fail = m_description.getFail(key);
 
-    if (fail.contains("{{version}}") && null != request.getTargetVersion()) {
-      fail = fail.replace("{{version}}", request.getTargetVersion());
+    RepositoryVersionEntity repositoryVersion = 
request.getTargetRepositoryVersion();
+    if (fail.contains("{{version}}") && null != repositoryVersion) {
+      fail = fail.replace("{{version}}", repositoryVersion.getVersion());
     }
 
     if (fail.contains("{{fails}}")) {
@@ -265,26 +237,21 @@ public abstract class AbstractCheckDescriptor {
         Clusters clusters = clustersProvider.get();
         AmbariMetaInfo metaInfo = ambariMetaInfo.get();
 
-        try {
-          Cluster c = clusters.getCluster(request.getClusterName());
-
-          LinkedHashSet<String> displays = new LinkedHashSet<>();
-
-          for (Service service : c.getServices().values()) {
-            if (names.contains(service.getName())) {
-              try {
-                ServiceInfo serviceInfo = metaInfo.getService(service);
-                displays.add(serviceInfo.getDisplayName());
-              } catch (Exception e) {
-                displays.add(service.getName());
-              }
-            }
+        Cluster c = clusters.getCluster(request.getClusterName());
+        Map<String, ServiceInfo> services = metaInfo.getServices(
+            c.getDesiredStackVersion().getStackName(),
+            c.getDesiredStackVersion().getStackVersion());
+
+        LinkedHashSet<String> displays = new LinkedHashSet<>();
+        for (String name : names) {
+          if (services.containsKey(name)) {
+            displays.add(services.get(name).getDisplayName());
+          } else {
+            displays.add(name);
           }
-          names = displays;
-
-        } catch (Exception e) {
-          LOG.warn("Could not load service info map");
         }
+        names = displays;
+
       }
 
       fail = fail.replace("{{fails}}", formatEntityList(names));
@@ -293,7 +260,6 @@ public abstract class AbstractCheckDescriptor {
     return fail;
   }
 
-
   /**
    * Formats lists of given entities to human readable form:
    * [entity1] -> {entity1} {noun}
@@ -335,4 +301,106 @@ public abstract class AbstractCheckDescriptor {
     return false;
   }
 
-}
+  /**
+   * Gets the services participating in the upgrade from the VDF.
+   *
+   * @param request
+   *          the upgrade check request.
+   * @return the services participating in the upgrade, which can either be all
+   *         of the cluster's services or a subset based on repository type.
+   */
+  final Set<String> getServicesInUpgrade(PrereqCheckRequest request) throws 
AmbariException {
+    final Cluster cluster = 
clustersProvider.get().getCluster(request.getClusterName());
+    RepositoryVersionEntity repositoryVersion = 
request.getTargetRepositoryVersion();
+
+    // the check is scoped to some services, so determine if any of those
+    // services are included in this upgrade
+    try {
+      VersionDefinitionXml vdf = repositoryVersion.getRepositoryXml();
+      ClusterVersionSummary clusterVersionSummary = 
vdf.getClusterSummary(cluster);
+      return clusterVersionSummary.getAvailableServiceNames();
+    } catch (Exception exception) {
+      throw new AmbariException("Unable to run upgrade checks because of an 
invalid VDF",
+          exception);
+    }
+  }
+
+  /**
+   * The {@link CheckQualification} interface is used to provide multiple
+   * different qualifications against which an upgrade check is determined to 
be
+   * applicable to the upgrade.
+   */
+  interface CheckQualification {
+
+    /**
+     * Gets whether the upgrade check meets this qualification and should
+     * therefore be run before the upgrade.
+     *
+     * @param request
+     * @return
+     * @throws AmbariException
+     */
+    boolean isApplicable(PrereqCheckRequest request) throws AmbariException;
+  }
+
+  /**
+   * The {@link ServiceQualification} class is used to determine if the
+   * service(s) associated with an upgraade check are both installed in the
+   * cluster and included in thr upgrade.
+   * <p/>
+   * If a service is installed but not included in the upgrade (for example of
+   * the upgrade is a patch upgrade), then the check should not qualify to run.
+   */
+  final class ServiceQualification implements CheckQualification {
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
+
+      Set<String> applicableServices = getApplicableServices();
+
+      // if the check is not scoped to any particular service, then it passes
+      // this qualification
+      if (applicableServices.isEmpty()) {
+        return true;
+      }
+
+      Set<String> servicesForUpgrade = getServicesInUpgrade(request);
+
+      for (String serviceInUpgrade : servicesForUpgrade) {
+        if (applicableServices.contains(serviceInUpgrade)) {
+          return true;
+        }
+      }
+
+      return false;
+    }
+  }
+
+  /**
+   * The {@link PriorCheckQualification} class is used to determine if a prior 
check has run.
+   */
+  final class PriorCheckQualification implements CheckQualification {
+
+    private final CheckDescription m_checkDescription;
+
+    public PriorCheckQualification(CheckDescription checkDescription) {
+      m_checkDescription = checkDescription;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
+      PrereqCheckStatus checkStatus = request.getResult(m_checkDescription);
+      if (null != checkStatus && checkStatus == PrereqCheckStatus.FAIL) {
+        return false;
+      }
+
+      return true;
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/AtlasPresenceCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/AtlasPresenceCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/AtlasPresenceCheck.java
index 617ffa0..035116a 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/AtlasPresenceCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/AtlasPresenceCheck.java
@@ -17,15 +17,14 @@
  */
 package org.apache.ambari.server.checks;
 
-import java.util.Arrays;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Sets;
 import com.google.inject.Singleton;
 
 /**
@@ -36,16 +35,18 @@ import com.google.inject.Singleton;
 @UpgradeCheck(group = UpgradeCheckGroup.DEFAULT)
 public class AtlasPresenceCheck extends AbstractCheckDescriptor{
 
-  private static final Logger LOG = 
LoggerFactory.getLogger(AtlasPresenceCheck.class);
   private static final String serviceName = "ATLAS";
 
   public AtlasPresenceCheck(){
     super(CheckDescription.ATLAS_SERVICE_PRESENCE_CHECK);
   }
 
+  /**
+   * {@inheritDoc}
+   */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    return super.isApplicable(request, Arrays.asList(serviceName), true);
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet(serviceName);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/AutoStartDisabledCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/AutoStartDisabledCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/AutoStartDisabledCheck.java
index c41ad20..6b0698e 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/AutoStartDisabledCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/AutoStartDisabledCheck.java
@@ -17,6 +17,9 @@
  */
 package org.apache.ambari.server.checks;
 
+import java.util.Collections;
+import java.util.Set;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
@@ -52,6 +55,14 @@ public class AutoStartDisabledCheck extends 
AbstractCheckDescriptor {
    * {@inheritDoc}
    */
   @Override
+  public Set<String> getApplicableServices() {
+    return Collections.emptySet();
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
   public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest 
request) throws AmbariException {
 
     String autoStartEnabled = getProperty(request, CLUSTER_ENV_TYPE, 
RECOVERY_ENABLED_KEY);

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java
index 3f63117..4fd37dc 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java
@@ -1,4 +1,4 @@
-/*
+/**
  * 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
@@ -86,9 +86,7 @@ public class CheckDescription {
     "All hosts should have target version installed",
     new ImmutableMap.Builder<String, String>()
       .put(AbstractCheckDescriptor.DEFAULT,
-          "The following hosts must have version {{version}} installed: 
{{fails}}.")
-      .put(HostsRepositoryVersionCheck.KEY_NO_REPO_VERSION,
-          "Repository version {{version}} does not exist.").build());
+          "The following hosts must have version {{version}} installed: 
{{fails}}.").build());
 
   public static CheckDescription SECONDARY_NAMENODE_MUST_BE_DELETED = new 
CheckDescription("SECONDARY_NAMENODE_MUST_BE_DELETED",
     PrereqCheckType.HOST,
@@ -272,20 +270,17 @@ public class CheckDescription {
           "After upgrading, Atlas can be reinstalled").build());
 
   public static CheckDescription SERVICE_PRESENCE_CHECK = new 
CheckDescription("SERVICE_PRESENCE_CHECK",
-      PrereqCheckType.SERVICE,
-      "Service Is Not Supported For Upgrades",
-      new ImmutableMap.Builder<String, String>()
-        .put(AbstractCheckDescriptor.DEFAULT,
-            "The %s service is currently installed on the cluster. " +
-            "This service does not support upgrades and must be removed before 
the upgrade can continue. " +
-            "After upgrading, %s can be reinstalled")
-        .put(ServicePresenceCheck.KEY_SERVICE_REMOVED,
-             "The %s service is currently installed on the cluster. " +
-             "This service is removed from the new release and must be removed 
before the upgrade can continue.")
-        .put(ServicePresenceCheck.KEY_SERVICE_REPLACED,
-            "The %s service is currently installed on the cluster. " +
-            "This service is removed from the new release and must be removed 
before the upgrade can continue. " +
-            "After upgrading, %s can be installed as the 
replacement.").build());
+    PrereqCheckType.SERVICE,
+    "Service Is Not Supported For Upgrades",
+    new ImmutableMap.Builder<String, String>()
+      .put(AbstractCheckDescriptor.DEFAULT,
+          "The %s service is currently installed on the cluster. " +
+          "This service does not support upgrades and must be removed before 
the upgrade can continue. " +
+          "After upgrading, %s can be reinstalled")
+      .put(ServicePresenceCheck.KEY_SERVICE_REMOVED,
+          "The %s service is currently installed on the cluster. " +
+          "This service is removed from the new release and must be removed 
before the upgrade can continue. " +
+          "After upgrading, %s can be installed").build());
 
   public static CheckDescription RANGER_SERVICE_AUDIT_DB_CHECK = new 
CheckDescription("RANGER_SERVICE_AUDIT_DB_CHECK",
     PrereqCheckType.SERVICE,
@@ -328,9 +323,23 @@ public class CheckDescription {
     PrereqCheckType.SERVICE,
     "Change Ranger SSL configuration path for Keystore and Truststore.",
     new ImmutableMap.Builder<String, String>()
-            .put(AbstractCheckDescriptor.DEFAULT,
-              "As Ranger is SSL enabled, Ranger SSL configurations will need 
to be changed from default value of /etc/ranger/*/conf folder to 
/etc/ranger/security. " +
-              "Since the certificates/keystores/truststores in this path may 
affect the upgrade/downgrade process, it is recommended to manually move the 
certificates/keystores/truststores out of the conf folders and change the 
appropriate config values before proceeding.").build());
+      .put(AbstractCheckDescriptor.DEFAULT,
+        "As Ranger is SSL enabled, Ranger SSL configurations will need to be 
changed from default value of /etc/ranger/*/conf folder to 
/etc/ranger/security. " +
+        "Since the certificates/keystores/truststores in this path may affect 
the upgrade/downgrade process, it is recommended to manually move the 
certificates/keystores/truststores out of the conf folders and change the 
appropriate config values before proceeding.").build());
+
+  public static CheckDescription JAVA_VERSION = new 
CheckDescription("JAVA_VERSION",
+      PrereqCheckType.CLUSTER,
+      "Verify Java version requirement",
+      new ImmutableMap.Builder<String, String>()
+        .put(AbstractCheckDescriptor.DEFAULT, "Ambari requires JDK with 
minimum version %s. Reconfigure Ambari with a JDK that meets the version 
requirement.")
+          .build());
+
+  public static CheckDescription COMPONENTS_EXIST_IN_TARGET_REPO = new 
CheckDescription("COMPONENTS_EXIST_IN_TARGET_REPO",
+      PrereqCheckType.CLUSTER,
+      "Verify Cluster Components Exist In Target Repository",
+      new ImmutableMap.Builder<String, String>()
+        .put(AbstractCheckDescriptor.DEFAULT, "The following components do not 
exist in the target repository's stack. They must be removed from the cluster 
before upgrading.")
+          .build());
 
   private String m_name;
   private PrereqCheckType m_type;
@@ -371,4 +380,4 @@ public class CheckDescription {
   public String getFail(String key) {
     return m_fails.containsKey(key) ? m_fails.get(key) : "";
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/ClientRetryPropertyCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ClientRetryPropertyCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ClientRetryPropertyCheck.java
index 714731d..f26202d 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ClientRetryPropertyCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ClientRetryPropertyCheck.java
@@ -18,9 +18,9 @@
 package org.apache.ambari.server.checks;
 
 import java.util.ArrayList;
-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;
@@ -31,6 +31,7 @@ import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
 import org.apache.commons.lang.StringUtils;
 
+import com.google.common.collect.Sets;
 import com.google.inject.Singleton;
 
 /**
@@ -58,10 +59,11 @@ public class ClientRetryPropertyCheck extends 
AbstractCheckDescriptor {
    * {@inheritDoc}
    */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    return super.isApplicable(request, Arrays.asList("HDFS", "HIVE", "OOZIE"), 
false);
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet("HDFS", "HIVE", "OOZIE");
   }
 
+
   /**
    * {@inheritDoc}
    */

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/ComponentsExistInRepoCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ComponentsExistInRepoCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ComponentsExistInRepoCheck.java
new file mode 100644
index 0000000..6949257
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ComponentsExistInRepoCheck.java
@@ -0,0 +1,140 @@
+/*
+ * 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.text.MessageFormat;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.StackAccessException;
+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.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.stack.PrereqCheckStatus;
+import org.apache.ambari.server.state.stack.PrerequisiteCheck;
+import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
+import org.apache.commons.lang.StringUtils;
+
+import com.google.inject.Singleton;
+
+/**
+ * The {@link ComponentsExistInRepoCheck} is used to determine if any of the
+ * components scheduled for upgrade do not exist in the target repository or
+ * stack.
+ */
+@Singleton
+@UpgradeCheck(
+    group = UpgradeCheckGroup.TOPOLOGY,
+    required = { UpgradeType.ROLLING, UpgradeType.NON_ROLLING, 
UpgradeType.HOST_ORDERED })
+public class ComponentsExistInRepoCheck extends AbstractCheckDescriptor {
+
+  /**
+   * Constructor.
+   */
+  public ComponentsExistInRepoCheck() {
+    super(CheckDescription.COMPONENTS_EXIST_IN_TARGET_REPO);
+  }
+
+  @Override
+  public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest 
request)
+      throws AmbariException {
+    final String clusterName = request.getClusterName();
+    final Cluster cluster = clustersProvider.get().getCluster(clusterName);
+    RepositoryVersionEntity repositoryVersion = 
request.getTargetRepositoryVersion();
+
+    StackId sourceStack = request.getSourceStackId();
+    StackId targetStack = repositoryVersion.getStackId();
+
+    Set<String> failedServices = new TreeSet<>();
+    Set<String> failedComponents = new TreeSet<>();
+
+    Set<String> servicesInUpgrade = getServicesInUpgrade(request);
+    for (String serviceName : servicesInUpgrade) {
+      try {
+        ServiceInfo serviceInfo = 
ambariMetaInfo.get().getService(targetStack.getStackName(),
+            targetStack.getStackVersion(), serviceName);
+
+        if (serviceInfo.isDeleted() || !serviceInfo.isValid()) {
+          failedServices.add(serviceName);
+          continue;
+        }
+
+        Service service = cluster.getService(serviceName);
+        Map<String, ServiceComponent> componentsInUpgrade = 
service.getServiceComponents();
+        for (String componentName : componentsInUpgrade.keySet()) {
+          try {
+            ComponentInfo componentInfo = ambariMetaInfo.get().getComponent(
+                targetStack.getStackName(), targetStack.getStackVersion(), 
serviceName,
+                componentName);
+
+            // if this component isn't included in the upgrade, then skip it
+            if (!componentInfo.isVersionAdvertised()) {
+              continue;
+            }
+
+            if (componentInfo.isDeleted()) {
+              failedComponents.add(componentName);
+            }
+
+          } catch (StackAccessException stackAccessException) {
+            failedComponents.add(componentName);
+          }
+        }
+      } catch (StackAccessException stackAccessException) {
+        failedServices.add(serviceName);
+      }
+    }
+
+    if( failedServices.isEmpty() && failedComponents.isEmpty() ){
+      prerequisiteCheck.setStatus(PrereqCheckStatus.PASS);
+      return;
+    }
+
+    LinkedHashSet<String> failedOn = new LinkedHashSet<>();
+    failedOn.addAll(failedServices);
+    failedOn.addAll(failedComponents);
+
+    prerequisiteCheck.setFailedOn(failedOn);
+    prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
+
+    String message = "The following {0} exist in {1} but are not included in 
{2}. They must be removed before upgrading.";
+    String messageFragment = "";
+    if (!failedServices.isEmpty()) {
+      messageFragment = "services";
+    }
+
+    if( !failedComponents.isEmpty() ){
+      if(!StringUtils.isEmpty(messageFragment)){
+        messageFragment += " and ";
+      }
+
+      messageFragment += "components";
+    }
+
+    message = MessageFormat.format(message, messageFragment, sourceStack, 
targetStack);
+    prerequisiteCheck.setFailReason(message);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/ComponentsInstallationCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ComponentsInstallationCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ComponentsInstallationCheck.java
index 988fc78..ce7ec64 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ComponentsInstallationCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ComponentsInstallationCheck.java
@@ -66,8 +66,9 @@ public class ComponentsInstallationCheck extends 
AbstractCheckDescriptor {
     // Preq-req check should fail if any service component is in 
INSTALL_FAILED state
     Set<String> installFailedHostComponents = new HashSet<>();
 
-    for (Map.Entry<String, Service> serviceEntry : 
cluster.getServices().entrySet()) {
-      final Service service = serviceEntry.getValue();
+    Set<String> servicesInUpgrade = getServicesInUpgrade(request);
+    for (String serviceName : servicesInUpgrade) {
+      final Service service = cluster.getService(serviceName);
       // Skip service if it is in maintenance mode
       if (service.getMaintenanceState() != MaintenanceState.ON) {
         Map<String, ServiceComponent> serviceComponents = 
service.getServiceComponents();

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/ConfigurationMergeCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ConfigurationMergeCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ConfigurationMergeCheck.java
index 48c652f..75730d8 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ConfigurationMergeCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ConfigurationMergeCheck.java
@@ -63,8 +63,7 @@ public class ConfigurationMergeCheck extends 
AbstractCheckDescriptor {
   public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest 
request)
       throws AmbariException {
 
-    String stackName = request.getTargetStackId().getStackName();
-    RepositoryVersionEntity rve = 
repositoryVersionDaoProvider.get().findByStackNameAndVersion(stackName, 
request.getTargetVersion());
+    RepositoryVersionEntity rve = request.getTargetRepositoryVersion();
 
     Map<String, Map<String, ThreeWayValue>> changes =
         m_mergeHelper.getConflicts(request.getClusterName(), rve.getStackId());

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/HealthCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/HealthCheck.java 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/HealthCheck.java
index b804f8b..f08be16 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/HealthCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/HealthCheck.java
@@ -99,7 +99,8 @@ public class HealthCheck extends AbstractCheckDescriptor {
       prerequisiteCheck.getFailedOn().add(clusterName);
       prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
       String failReason = getFailReason(prerequisiteCheck, request);
-      prerequisiteCheck.setFailReason(String.format(failReason, 
StringUtils.join(errorMessages, "\n")));
+      prerequisiteCheck.setFailReason(
+          String.format(failReason, StringUtils.join(errorMessages, 
System.lineSeparator())));
     }
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/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 ed7a49a..34e5bfd 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
@@ -18,12 +18,14 @@
 package org.apache.ambari.server.checks;
 
 import java.util.ArrayList;
-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;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
+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.apache.ambari.server.state.stack.UpgradePack.PrerequisiteCheckConfig;
@@ -31,6 +33,7 @@ import 
org.apache.ambari.server.state.stack.upgrade.UpgradeType;
 import org.apache.ambari.server.utils.VersionUtils;
 import org.apache.commons.lang.StringUtils;
 
+import com.google.common.collect.Sets;
 import com.google.inject.Singleton;
 
 /**
@@ -60,8 +63,8 @@ public class HiveDynamicServiceDiscoveryCheck extends 
AbstractCheckDescriptor {
    * {@inheritDoc}
    */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    return super.isApplicable(request, Arrays.asList("HIVE"), true);
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet("HIVE");
   }
 
   /**
@@ -109,9 +112,11 @@ public class HiveDynamicServiceDiscoveryCheck extends 
AbstractCheckDescriptor {
           String minStackName = minStack[0];
           String minStackVersion = minStack[1];
           if (minStackName.equals(request.getSourceStackId().getStackName())) {
+            RepositoryVersionEntity repositoryVersion = 
request.getTargetRepositoryVersion();
+            StackId targetStackId = repositoryVersion.getStackId();
             if 
(VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), 
minStackVersion) < 0
-                && 
VersionUtils.compareVersions(request.getTargetStackId().getStackVersion(), 
minStackVersion) < 0
-                && 
VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), 
request.getTargetStackId().getStackVersion()) < 0) {
+                && 
VersionUtils.compareVersions(targetStackId.getStackVersion(), minStackVersion) 
< 0
+                && 
VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), 
targetStackId.getStackVersion()) < 0) {
               checkStatus = PrereqCheckStatus.WARNING;
             }
           }

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheck.java
index ea20a55..e876696 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheck.java
@@ -17,8 +17,8 @@
  */
 package org.apache.ambari.server.checks;
 
-import java.util.Arrays;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ServiceComponentNotFoundException;
@@ -30,6 +30,7 @@ import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 
+import com.google.common.collect.Sets;
 import com.google.inject.Singleton;
 
 /**
@@ -51,8 +52,8 @@ public class HiveMultipleMetastoreCheck extends 
AbstractCheckDescriptor {
    * {@inheritDoc}
    */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    return super.isApplicable(request, Arrays.asList("HIVE"), true);
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet("HIVE");
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveNotRollingWarning.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveNotRollingWarning.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveNotRollingWarning.java
index 2b1c62e..8e862c8 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveNotRollingWarning.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveNotRollingWarning.java
@@ -17,7 +17,7 @@
  */
 package org.apache.ambari.server.checks;
 
-import java.util.Arrays;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
@@ -25,6 +25,7 @@ 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 com.google.common.collect.Sets;
 import com.google.inject.Singleton;
 
 /**
@@ -52,14 +53,10 @@ public class HiveNotRollingWarning extends 
AbstractCheckDescriptor {
 
   /**
    * {@inheritDoc}
-   * <p/>
-   * This check is only applicable if Hive is installed and the upgrade type is
-   * {@link UpgradeType#ROLLING}.
    */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    boolean isApplicable = super.isApplicable(request, Arrays.asList("HIVE"), 
true);
-    return isApplicable && request.getUpgradeType() == UpgradeType.ROLLING;
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet("HIVE");
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/HostsMasterMaintenanceCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/HostsMasterMaintenanceCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/HostsMasterMaintenanceCheck.java
index 1c59d2e..5094843 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/HostsMasterMaintenanceCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/HostsMasterMaintenanceCheck.java
@@ -23,6 +23,7 @@ import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 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.Host;
 import org.apache.ambari.server.state.MaintenanceState;
@@ -58,11 +59,6 @@ public class HostsMasterMaintenanceCheck extends 
AbstractCheckDescriptor {
   }
 
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-      return super.isApplicable(request) && request.getTargetVersion() != null;
-  }
-
-  @Override
   public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest 
request) throws AmbariException {
     final String clusterName = request.getClusterName();
     final Cluster cluster = clustersProvider.get().getCluster(clusterName);
@@ -70,13 +66,18 @@ public class HostsMasterMaintenanceCheck extends 
AbstractCheckDescriptor {
     final Set<String> hostsWithMasterComponent = new HashSet<>();
 
     // TODO AMBARI-12698, need to pass the upgrade pack to use in the request, 
or at least the type.
-    final String upgradePackName = 
repositoryVersionHelper.get().getUpgradePackageName(stackId.getStackName(), 
stackId.getStackVersion(), request.getTargetVersion(), null);
+    RepositoryVersionEntity repositoryVersion = 
request.getTargetRepositoryVersion();
+
+    final String upgradePackName = 
repositoryVersionHelper.get().getUpgradePackageName(
+        stackId.getStackName(), stackId.getStackVersion(), 
repositoryVersion.getVersion(), null);
+
     if (upgradePackName == null) {
       prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
       String fail = getFailReason(KEY_NO_UPGRADE_NAME, prerequisiteCheck, 
request);
       prerequisiteCheck.setFailReason(String.format(fail, 
stackId.getStackName(), stackId.getStackVersion()));
       return;
     }
+
     final UpgradePack upgradePack = 
ambariMetaInfo.get().getUpgradePacks(stackId.getStackName(), 
stackId.getStackVersion()).get(upgradePackName);
     if (upgradePack == null) {
       prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
@@ -84,10 +85,12 @@ public class HostsMasterMaintenanceCheck extends 
AbstractCheckDescriptor {
       prerequisiteCheck.setFailReason(String.format(fail, upgradePackName));
       return;
     }
+
     final Set<String> componentsFromUpgradePack = new HashSet<>();
     for (Map<String, ProcessingComponent> task: 
upgradePack.getTasks().values()) {
       componentsFromUpgradePack.addAll(task.keySet());
     }
+
     for (Service service: cluster.getServices().values()) {
       for (ServiceComponent serviceComponent: 
service.getServiceComponents().values()) {
         if (serviceComponent.isMasterComponent() && 
componentsFromUpgradePack.contains(serviceComponent.getName())) {
@@ -95,6 +98,7 @@ public class HostsMasterMaintenanceCheck extends 
AbstractCheckDescriptor {
         }
       }
     }
+
     final Map<String, Host> clusterHosts = 
clustersProvider.get().getHostsForCluster(clusterName);
     for (Map.Entry<String, Host> hostEntry : clusterHosts.entrySet()) {
       final Host host = hostEntry.getValue();
@@ -102,6 +106,7 @@ public class HostsMasterMaintenanceCheck extends 
AbstractCheckDescriptor {
         prerequisiteCheck.getFailedOn().add(host.getHostName());
       }
     }
+
     if (!prerequisiteCheck.getFailedOn().isEmpty()) {
       prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
       prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, 
request));

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/HostsRepositoryVersionCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/HostsRepositoryVersionCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/HostsRepositoryVersionCheck.java
index f83c39b..ae36c65 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/HostsRepositoryVersionCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/HostsRepositoryVersionCheck.java
@@ -25,7 +25,6 @@ import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
 import org.apache.ambari.server.orm.entities.HostVersionEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
-import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.MaintenanceState;
@@ -49,8 +48,6 @@ import com.google.inject.Singleton;
     required = { UpgradeType.ROLLING, UpgradeType.NON_ROLLING, 
UpgradeType.HOST_ORDERED })
 public class HostsRepositoryVersionCheck extends AbstractCheckDescriptor {
 
-  static final String KEY_NO_REPO_VERSION = "no_repo_version";
-
   /**
    * Constructor.
    */
@@ -59,17 +56,11 @@ public class HostsRepositoryVersionCheck extends 
AbstractCheckDescriptor {
   }
 
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    return super.isApplicable(request) && request.getTargetVersion() != null;
-  }
-
-  @Override
   public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest 
request)
       throws AmbariException {
     final String clusterName = request.getClusterName();
     final Cluster cluster = clustersProvider.get().getCluster(clusterName);
     final Map<String, Host> clusterHosts = 
clustersProvider.get().getHostsForCluster(clusterName);
-    final StackId stackId = request.getSourceStackId();
 
     for (Host host : clusterHosts.values()) {
       // hosts in MM will produce a warning if they do not have the repo 
version
@@ -78,48 +69,19 @@ public class HostsRepositoryVersionCheck extends 
AbstractCheckDescriptor {
         continue;
       }
 
-      if (null != request.getTargetVersion()) {
-        boolean found = false;
-
-        Set<RepositoryVersionState> allowed = 
EnumSet.of(RepositoryVersionState.INSTALLED,
-            RepositoryVersionState.NOT_REQUIRED);
-        if (request.isRevert()) {
-          allowed.add(RepositoryVersionState.CURRENT);
-        }
-
-        for (HostVersionEntity hve : 
hostVersionDaoProvider.get().findByHost(host.getHostName())) {
-
-          if 
(hve.getRepositoryVersion().getVersion().equals(request.getTargetVersion())
-              && allowed.contains(hve.getState())) {
-            found = true;
-            break;
-          }
-        }
-
-        if (!found) {
-          prerequisiteCheck.getFailedOn().add(host.getHostName());
-        }
-      } else {
-        final RepositoryVersionEntity repositoryVersion = 
repositoryVersionDaoProvider.get().findByStackAndVersion(
-            stackId, request.getTargetVersion());
-        if (repositoryVersion == null) {
-          prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
-          prerequisiteCheck.setFailReason(
-              getFailReason(KEY_NO_REPO_VERSION, prerequisiteCheck, request));
-          prerequisiteCheck.getFailedOn().addAll(clusterHosts.keySet());
-          return;
-        }
+      RepositoryVersionEntity repositoryVersion = 
request.getTargetRepositoryVersion();
+      StackId repositoryStackId = repositoryVersion.getStackId();
 
-        StackEntity repositoryStackEntity = repositoryVersion.getStack();
-        StackId repositoryStackId = new 
StackId(repositoryStackEntity.getStackName(),
-            repositoryStackEntity.getStackVersion());
+      // get the host version entity for this host and repository
+      final HostVersionEntity hostVersion = 
hostVersionDaoProvider.get().findByClusterStackVersionAndHost(
+          clusterName, repositoryStackId, repositoryVersion.getVersion(), 
host.getHostName());
 
-        final HostVersionEntity hostVersion = 
hostVersionDaoProvider.get().findByClusterStackVersionAndHost(
-            clusterName, repositoryStackId, repositoryVersion.getVersion(), 
host.getHostName());
+      // the repo needs to either be installed or not required
+      Set<RepositoryVersionState> okStates = 
EnumSet.of(RepositoryVersionState.INSTALLED,
+          RepositoryVersionState.NOT_REQUIRED);
 
-        if (hostVersion == null || hostVersion.getState() != 
RepositoryVersionState.INSTALLED) {
-          prerequisiteCheck.getFailedOn().add(host.getHostName());
-        }
+      if (hostVersion == null || !okStates.contains(hostVersion.getState())) {
+        prerequisiteCheck.getFailedOn().add(host.getHostName());
       }
     }
 
@@ -128,4 +90,4 @@ public class HostsRepositoryVersionCheck extends 
AbstractCheckDescriptor {
       prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, 
request));
     }
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/InstallPackagesCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/InstallPackagesCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/InstallPackagesCheck.java
index 7c84e5c..3e02572 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/InstallPackagesCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/InstallPackagesCheck.java
@@ -59,16 +59,15 @@ public class InstallPackagesCheck extends 
AbstractCheckDescriptor {
   public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest 
request) throws AmbariException {
     final String clusterName = request.getClusterName();
     final Cluster cluster = clustersProvider.get().getCluster(clusterName);
-    final StackId targetStackId = request.getTargetStackId();
-    final String stackName = targetStackId.getStackName();
-    final String repoVersion = request.getTargetVersion();
+    RepositoryVersionEntity repositoryVersion = 
request.getTargetRepositoryVersion();
 
-    final RepositoryVersionEntity rve = 
repositoryVersionDaoProvider.get().findByStackNameAndVersion(stackName, 
request.getTargetVersion());
-    if (StringUtils.isBlank(rve.getVersion()) || 
!rve.getVersion().matches("^\\d+(\\.\\d+)*\\-\\d+$")) {
+    final StackId targetStackId = repositoryVersion.getStackId();
+
+    if (!repositoryVersion.getVersion().matches("^\\d+(\\.\\d+)*\\-\\d+$")) {
       String message = MessageFormat.format("The Repository Version {0} for 
Stack {1} must contain a \"-\" followed by a build number. " +
               "Make sure that another registered repository does not have the 
same repo URL or " +
-              "shares the same build number. Next, try reinstalling the 
Repository Version.", rve.getVersion(), rve.getStackVersion());
-      prerequisiteCheck.getFailedOn().add("Repository Version " + 
rve.getVersion());
+              "shares the same build number. Next, try reinstalling the 
Repository Version.", repositoryVersion.getVersion(), 
repositoryVersion.getStackVersion());
+      prerequisiteCheck.getFailedOn().add("Repository Version " + 
repositoryVersion.getVersion());
       prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
       prerequisiteCheck.setFailReason(message);
       return;
@@ -79,7 +78,7 @@ public class InstallPackagesCheck extends 
AbstractCheckDescriptor {
     for (Host host : cluster.getHosts()) {
       if (host.getMaintenanceState(cluster.getClusterId()) != 
MaintenanceState.ON) {
         for (HostVersionEntity hve : 
hostVersionDaoProvider.get().findByHost(host.getHostName())) {
-          if 
(hve.getRepositoryVersion().getVersion().equals(request.getTargetVersion())
+          if (StringUtils.equals(hve.getRepositoryVersion().getVersion(), 
repositoryVersion.getVersion())
               && hve.getState() == RepositoryVersionState.INSTALL_FAILED) {
             failedHosts.add(host.getHostName());
           }
@@ -91,7 +90,8 @@ public class InstallPackagesCheck extends 
AbstractCheckDescriptor {
       String message = MessageFormat.format("Hosts in cluster 
[{0},{1},{2},{3}] are in INSTALL_FAILED state because " +
               "Install Packages had failed. Please re-run Install Packages, if 
necessary place following hosts " +
               "in Maintenance mode: {4}", cluster.getClusterName(), 
targetStackId.getStackName(),
-          targetStackId.getStackVersion(), repoVersion, 
StringUtils.join(failedHosts, ", "));
+          targetStackId.getStackVersion(), repositoryVersion.getVersion(),
+          StringUtils.join(failedHosts, ", "));
       prerequisiteCheck.setFailedOn(new LinkedHashSet<>(failedHosts));
       prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
       prerequisiteCheck.setFailReason(message);

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/KafkaKerberosCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/KafkaKerberosCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/KafkaKerberosCheck.java
index 69721d9..724feab 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/KafkaKerberosCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/KafkaKerberosCheck.java
@@ -18,7 +18,7 @@
 
 package org.apache.ambari.server.checks;
 
-import java.util.Arrays;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
@@ -27,6 +27,7 @@ import org.apache.ambari.server.state.SecurityType;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 
+import com.google.common.collect.Sets;
 import com.google.inject.Singleton;
 
 /**
@@ -47,9 +48,12 @@ public class KafkaKerberosCheck extends 
AbstractCheckDescriptor {
     super(CheckDescription.KAFKA_KERBEROS_CHECK);
   }
 
+  /**
+   * {@inheritDoc}
+   */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    return super.isApplicable(request, Arrays.asList(KAFKA_SERVICE), true);
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet(KAFKA_SERVICE);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/MapReduce2JobHistoryStatePreservingCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/MapReduce2JobHistoryStatePreservingCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/MapReduce2JobHistoryStatePreservingCheck.java
index 8ab3c11..2015be3 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/MapReduce2JobHistoryStatePreservingCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/MapReduce2JobHistoryStatePreservingCheck.java
@@ -18,8 +18,8 @@
 package org.apache.ambari.server.checks;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
@@ -27,6 +27,7 @@ import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.apache.commons.lang.StringUtils;
 
+import com.google.common.collect.Sets;
 import com.google.inject.Singleton;
 
 /**
@@ -57,8 +58,8 @@ public class MapReduce2JobHistoryStatePreservingCheck extends 
AbstractCheckDescr
    * {@inheritDoc}
    */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    return super.isApplicable(request, Arrays.asList("MAPREDUCE2"), true);
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet("MAPREDUCE2");
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerAuditDbCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerAuditDbCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerAuditDbCheck.java
index 8d1abdb..e5f0257 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerAuditDbCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerAuditDbCheck.java
@@ -17,7 +17,7 @@
  */
 package org.apache.ambari.server.checks;
 
-import java.util.Arrays;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
@@ -26,6 +26,7 @@ import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Sets;
 import com.google.inject.Singleton;
 
 /**
@@ -42,9 +43,12 @@ public class RangerAuditDbCheck extends 
AbstractCheckDescriptor{
     super(CheckDescription.RANGER_SERVICE_AUDIT_DB_CHECK);
   }
 
+  /**
+   * {@inheritDoc}
+   */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    return super.isApplicable(request, Arrays.asList(serviceName), true);
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet(serviceName);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerPasswordCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerPasswordCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerPasswordCheck.java
index 4a36be0..79f52d7 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerPasswordCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerPasswordCheck.java
@@ -27,22 +27,21 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
 import org.apache.ambari.server.controller.internal.URLStreamProvider;
-import org.apache.ambari.server.state.Service;
-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.apache.ambari.server.state.stack.upgrade.UpgradeType;
-import org.apache.ambari.server.utils.VersionUtils;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Sets;
 import com.google.gson.Gson;
 import com.google.inject.Singleton;
 
@@ -74,25 +73,11 @@ public class RangerPasswordCheck extends 
AbstractCheckDescriptor {
   }
 
   /**
-   * Verifies that the check can be run.  If the stack is HDP and 2.3 or 
higher, allow
-   * this to run.  If the stack is not HDP, the check should run.
+   * {@inheritDoc}
    */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    if (!super.isApplicable(request, Arrays.asList("RANGER"), true)) {
-      return false;
-    }
-
-    Service service = getCluster(request).getService("RANGER");
-
-    StackId stackId = service.getDesiredStackId();
-    if (stackId.getStackName().equals("HDP")) {
-      String sourceVersion = request.getSourceStackId().getStackVersion();
-
-      return VersionUtils.compareVersions(sourceVersion, "2.3.0.0") >= 0;
-    }
-
-    return true;
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet("RANGER");
   }
 
   @Override
@@ -293,7 +278,7 @@ public class RangerPasswordCheck extends 
AbstractCheckDescriptor {
    */
   private boolean checkRangerUser(URLStreamProvider streamProvider, String 
rangerUserUrl,
       String username, String password, String userToSearch, PrerequisiteCheck 
check,
-      PrereqCheckRequest request, List<String> warnReasons) {
+      PrereqCheckRequest request, List<String> warnReasons) throws 
AmbariException {
 
     String url = String.format("%s?name=%s", rangerUserUrl, userToSearch);
 
@@ -390,4 +375,4 @@ public class RangerPasswordCheck extends 
AbstractCheckDescriptor {
   }
 
 
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerSSLConfigCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerSSLConfigCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerSSLConfigCheck.java
index 2014ff7..540fd3e 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerSSLConfigCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerSSLConfigCheck.java
@@ -18,7 +18,7 @@
 package org.apache.ambari.server.checks;
 
 
-import java.util.Arrays;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
@@ -27,6 +27,7 @@ import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Sets;
 import com.google.inject.Singleton;
 
 
@@ -54,8 +55,8 @@ public class RangerSSLConfigCheck extends 
AbstractCheckDescriptor {
    * {@inheritDoc}
    */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    return super.isApplicable(request, Arrays.asList(serviceName), true);
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet(serviceName);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/SecondaryNamenodeDeletedCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/SecondaryNamenodeDeletedCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/SecondaryNamenodeDeletedCheck.java
index 543df26..e83b118 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/SecondaryNamenodeDeletedCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/SecondaryNamenodeDeletedCheck.java
@@ -33,6 +33,7 @@ import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 
+import com.google.common.collect.Sets;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 
@@ -53,18 +54,21 @@ public class SecondaryNamenodeDeletedCheck extends 
AbstractCheckDescriptor {
     super(CheckDescription.SECONDARY_NAMENODE_MUST_BE_DELETED);
   }
 
+  /**
+   * {@inheritDoc}
+   */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    if (!super.isApplicable(request, Arrays.asList(HDFS_SERVICE_NAME), true)) {
-      return false;
-    }
-
-    PrereqCheckStatus ha = 
request.getResult(CheckDescription.SERVICES_NAMENODE_HA);
-    if (null != ha && ha == PrereqCheckStatus.FAIL) {
-      return false;
-    }
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet(HDFS_SERVICE_NAME);
+  }
 
-    return true;
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public List<CheckQualification> getQualifications() {
+    return Arrays.<CheckQualification> asList(
+        new PriorCheckQualification(CheckDescription.SERVICES_NAMENODE_HA));
   }
 
   // TODO AMBARI-12698, there are 2 ways to filter the prechecks.

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicePresenceCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicePresenceCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicePresenceCheck.java
index 950ca11..d5d84f4 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicePresenceCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicePresenceCheck.java
@@ -109,7 +109,7 @@ public class ServicePresenceCheck extends 
AbstractCheckDescriptor{
     for(String service: removedServices){
       if (installedServices.contains(service.toUpperCase())){
         prerequisiteCheck.getFailedOn().add(service);
-        String msg = String.format(reason, service);
+        String msg = String.format(reason, service, service);
         failReasons.add(msg);
       }
     }
@@ -159,7 +159,7 @@ public class ServicePresenceCheck extends 
AbstractCheckDescriptor{
   +   * @return service names
   +   * */
   private List<String> getRemovedServices(PrereqCheckRequest request){
-    List<String> result = new ArrayList<String>();
+    List<String> result = new ArrayList<>();
     String value = getPropertyValue(request, REMOVED_SERVICES_PROPERTY_NAME);
     if (null != value){
       String[] services = value.split(",");

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesMaintenanceModeCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesMaintenanceModeCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesMaintenanceModeCheck.java
index 08f4fd8..aa7b6db 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesMaintenanceModeCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesMaintenanceModeCheck.java
@@ -17,7 +17,7 @@
  */
 package org.apache.ambari.server.checks;
 
-import java.util.Map;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
@@ -49,10 +49,11 @@ public class ServicesMaintenanceModeCheck extends 
AbstractCheckDescriptor {
 
   @Override
   public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest 
request) throws AmbariException {
-    final String clusterName = request.getClusterName();
-    final Cluster cluster = clustersProvider.get().getCluster(clusterName);
-    for (Map.Entry<String, Service> serviceEntry : 
cluster.getServices().entrySet()) {
-      final Service service = serviceEntry.getValue();
+    final Cluster cluster = 
clustersProvider.get().getCluster(request.getClusterName());
+    Set<String> servicesInUpgrade = getServicesInUpgrade(request);
+
+    for (String serviceName : servicesInUpgrade) {
+      final Service service = cluster.getService(serviceName);
       if (!service.isClientOnlyService() && service.getMaintenanceState() == 
MaintenanceState.ON) {
         prerequisiteCheck.getFailedOn().add(service.getName());
       }

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesMapReduceDistributedCacheCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesMapReduceDistributedCacheCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesMapReduceDistributedCacheCheck.java
index 3fd55b7..ab7e798 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesMapReduceDistributedCacheCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesMapReduceDistributedCacheCheck.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
 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;
@@ -32,6 +33,7 @@ import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import 
org.apache.ambari.server.state.stack.UpgradePack.PrerequisiteCheckConfig;
 import org.apache.commons.lang.StringUtils;
 
+import com.google.common.collect.Sets;
 import com.google.inject.Singleton;
 
 /**
@@ -47,20 +49,21 @@ public class ServicesMapReduceDistributedCacheCheck extends 
AbstractCheckDescrip
   static final String DFS_PROTOCOLS_REGEX_PROPERTY_NAME = 
"dfs-protocols-regex";
   static final String DFS_PROTOCOLS_REGEX_DEFAULT = "^([^:]*dfs|wasb|ecs):.*";
 
+  /**
+   * {@inheritDoc}
+   */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request)
-    throws AmbariException {
-
-    if (!super.isApplicable(request, Arrays.asList("YARN"), true)) {
-      return false;
-    }
-
-    PrereqCheckStatus ha = 
request.getResult(CheckDescription.SERVICES_NAMENODE_HA);
-    if (null != ha && ha == PrereqCheckStatus.FAIL) {
-      return false;
-    }
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet("YARN");
+  }
 
-    return true;
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public List<CheckQualification> getQualifications() {
+    return Arrays.<CheckQualification> asList(
+        new PriorCheckQualification(CheckDescription.SERVICES_NAMENODE_HA));
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheck.java
index 67999e8..ecd88ed 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheck.java
@@ -17,8 +17,8 @@
  */
 package org.apache.ambari.server.checks;
 
-import java.util.Arrays;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
@@ -28,6 +28,7 @@ import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 
+import com.google.common.collect.Sets;
 import com.google.inject.Singleton;
 
 /**
@@ -44,11 +45,15 @@ public class ServicesNamenodeHighAvailabilityCheck extends 
AbstractCheckDescript
     super(CheckDescription.SERVICES_NAMENODE_HA);
   }
 
+  /**
+   * {@inheritDoc}
+   */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    return super.isApplicable(request, Arrays.asList("HDFS"), true);
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet("HDFS");
   }
 
+
   @Override
   public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest 
request) throws AmbariException {
     final String clusterName = request.getClusterName();

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/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 269de82..ce1b4bf 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
@@ -18,6 +18,8 @@
 package org.apache.ambari.server.checks;
 
 import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
@@ -26,6 +28,7 @@ import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 
+import com.google.common.collect.Sets;
 import com.google.inject.Singleton;
 
 /**
@@ -42,18 +45,21 @@ public class ServicesNamenodeTruncateCheck extends 
AbstractCheckDescriptor {
     super(CheckDescription.SERVICES_NAMENODE_TRUNCATE);
   }
 
+  /**
+   * {@inheritDoc}
+   */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    if (!super.isApplicable(request, Arrays.asList("HDFS"), true)) {
-      return false;
-    }
-
-    PrereqCheckStatus ha = 
request.getResult(CheckDescription.SERVICES_NAMENODE_HA);
-    if (null != ha && ha == PrereqCheckStatus.FAIL) {
-      return false;
-    }
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet("HDFS");
+  }
 
-    return true;
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public List<CheckQualification> getQualifications() {
+    return Arrays.<CheckQualification> asList(
+        new PriorCheckQualification(CheckDescription.SERVICES_NAMENODE_HA));
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheck.java
index a564957..cb0c9ae 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheck.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
 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;
@@ -32,6 +33,7 @@ import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import 
org.apache.ambari.server.state.stack.UpgradePack.PrerequisiteCheckConfig;
 import org.apache.commons.lang.StringUtils;
 
+import com.google.common.collect.Sets;
 import com.google.inject.Singleton;
 
 /**
@@ -49,18 +51,21 @@ public class ServicesTezDistributedCacheCheck extends 
AbstractCheckDescriptor {
   static final String DFS_PROTOCOLS_REGEX_PROPERTY_NAME = 
"dfs-protocols-regex";
   static final String DFS_PROTOCOLS_REGEX_DEFAULT = "^([^:]*dfs|wasb|ecs):.*";
 
+  /**
+   * {@inheritDoc}
+   */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    if (!super.isApplicable(request, Arrays.asList("TEZ"), true)) {
-      return false;
-    }
-
-    PrereqCheckStatus ha = 
request.getResult(CheckDescription.SERVICES_NAMENODE_HA);
-    if (null != ha && ha == PrereqCheckStatus.FAIL) {
-      return false;
-    }
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet("TEZ");
+  }
 
-    return true;
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public List<CheckQualification> getQualifications() {
+    return Arrays.<CheckQualification> asList(
+        new PriorCheckQualification(CheckDescription.SERVICES_NAMENODE_HA));
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesUpCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesUpCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesUpCheck.java
index 6b03249..c9f3cc3 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesUpCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesUpCheck.java
@@ -91,9 +91,9 @@ public class ServicesUpCheck extends AbstractCheckDescriptor {
     List<String> errorMessages = new ArrayList<>();
     Set<String> failedServiceNames = new HashSet<>();
 
-    for (Map.Entry<String, Service> serviceEntry : 
cluster.getServices().entrySet()) {
-      final Service service = serviceEntry.getValue();
-      StackId stackId = service.getDesiredStackId();
+    Set<String> servicesInUpgrade = getServicesInUpgrade(request);
+    for (String serviceName : servicesInUpgrade) {
+      final Service service = cluster.getService(serviceName);
 
       // Ignore services like Tez that are clientOnly.
       if (service.isClientOnlyService()) {
@@ -131,6 +131,7 @@ public class ServicesUpCheck extends 
AbstractCheckDescriptor {
         // non-master, "true" slaves with cardinality 1+
         boolean checkThreshold = false;
         if (!serviceComponent.isMasterComponent()) {
+          StackId stackId = service.getDesiredStackId();
           ComponentInfo componentInfo = 
ambariMetaInfo.get().getComponent(stackId.getStackName(),
               stackId.getStackVersion(), serviceComponent.getServiceName(),
               serviceComponent.getName());
@@ -194,6 +195,8 @@ public class ServicesUpCheck extends 
AbstractCheckDescriptor {
    * purposes of this check. Component type, maintenance mode, and state are
    * taken into account.
    *
+   * @param clusters
+   *          the clusters instance
    * @param cluster
    *          the cluster
    * @param serviceComponent
@@ -225,4 +228,4 @@ public class ServicesUpCheck extends 
AbstractCheckDescriptor {
         return false;
     }
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheck.java
index 8c73fa9..0b102a9 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheck.java
@@ -17,7 +17,7 @@
  */
 package org.apache.ambari.server.checks;
 
-import java.util.Arrays;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
@@ -25,6 +25,7 @@ import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.apache.commons.lang.BooleanUtils;
 
+import com.google.common.collect.Sets;
 import com.google.inject.Singleton;
 
 /**
@@ -45,8 +46,8 @@ public class ServicesYarnWorkPreservingCheck extends 
AbstractCheckDescriptor {
    * {@inheritDoc}
    */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    return super.isApplicable(request, Arrays.asList("YARN"), true);
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet("YARN");
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/StormShutdownWarning.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/StormShutdownWarning.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/StormShutdownWarning.java
index b5435f1..067cd80 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/StormShutdownWarning.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/StormShutdownWarning.java
@@ -17,7 +17,7 @@
  */
 package org.apache.ambari.server.checks;
 
-import java.util.Arrays;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
@@ -25,6 +25,7 @@ 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 com.google.common.collect.Sets;
 import com.google.inject.Singleton;
 
 /**
@@ -50,14 +51,10 @@ public class StormShutdownWarning extends 
AbstractCheckDescriptor {
 
   /**
    * {@inheritDoc}
-   * <p/>
-   * This check is only applicable if Storm is installed and the upgrade type 
is
-   * {@link UpgradeType#ROLLING}.
    */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    boolean isApplicable = super.isApplicable(request, Arrays.asList("STORM"), 
true);
-    return isApplicable && request.getUpgradeType() == UpgradeType.ROLLING;
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet("STORM");
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/108ad9b4/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnRMHighAvailabilityCheck.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnRMHighAvailabilityCheck.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnRMHighAvailabilityCheck.java
index 6206dd3..e0d3df7 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnRMHighAvailabilityCheck.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnRMHighAvailabilityCheck.java
@@ -17,7 +17,7 @@
  */
 package org.apache.ambari.server.checks;
 
-import java.util.Arrays;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
@@ -25,6 +25,7 @@ import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.apache.commons.lang.BooleanUtils;
 
+import com.google.common.collect.Sets;
 import com.google.inject.Singleton;
 
 /**
@@ -46,10 +47,9 @@ public class YarnRMHighAvailabilityCheck extends 
AbstractCheckDescriptor {
    * {@inheritDoc}
    */
   @Override
-  public boolean isApplicable(PrereqCheckRequest request) throws 
AmbariException {
-    return super.isApplicable(request, Arrays.asList("YARN"), true);
+  public Set<String> getApplicableServices() {
+    return Sets.newHashSet("YARN");
   }
-
   /**
    * {@inheritDoc}
    */

Reply via email to