ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rle...@apache.org
Subject [21/50] [abbrv] ambari git commit: AMBARI-21164. Upgrades (RU/EU) : "stack.upgrade.bypass.prechecks" config is not honored while doing upgrades with bad entries in "execution_command" table. (aonishuk)
Date Thu, 08 Jun 2017 19:22:35 GMT
AMBARI-21164. Upgrades (RU/EU) : "stack.upgrade.bypass.prechecks" config is not honored while
doing upgrades with bad entries in "execution_command" table. (aonishuk)


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

Branch: refs/heads/branch-feature-AMBARI-20859
Commit: b3425c9841b4153b1cf3b15dc6f55e67f1754f3b
Parents: 499814a
Author: Andrew Onishuk <aonishuk@hortonworks.com>
Authored: Tue Jun 6 13:39:20 2017 +0300
Committer: Andrew Onishuk <aonishuk@hortonworks.com>
Committed: Tue Jun 6 13:39:20 2017 +0300

----------------------------------------------------------------------
 .../server/checks/AbstractCheckDescriptor.java  |  7 ----
 .../checks/ServiceCheckValidityCheck.java       |  9 +++--
 .../PreUpgradeCheckResourceProvider.java        |  6 ++-
 .../apache/ambari/server/state/CheckHelper.java | 37 ++++++++-----------
 .../checks/ServiceCheckValidityCheckTest.java   | 39 +++++++++++++++++++-
 .../PreUpgradeCheckResourceProviderTest.java    | 15 +++++++-
 .../sample/checks/SampleServiceCheck.java       |  4 --
 .../ambari/server/state/CheckHelperTest.java    | 36 ++++++++++++------
 8 files changed, 104 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b3425c98/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 a0affd0..fddded7 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
@@ -335,11 +335,4 @@ public abstract class AbstractCheckDescriptor {
     return false;
   }
 
-  /**
-   * Return a boolean indicating whether or not configs allow bypassing errors during the
RU/EU PreChecks.
-   * @return
-   */
-  public boolean isStackUpgradeAllowedToBypassPreChecks() {
-    return config.isUpgradePrecheckBypass();
-  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/b3425c98/ambari-server/src/main/java/org/apache/ambari/server/checks/ServiceCheckValidityCheck.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServiceCheckValidityCheck.java
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServiceCheckValidityCheck.java
index 750b25e..ad68a2c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServiceCheckValidityCheck.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServiceCheckValidityCheck.java
@@ -78,8 +78,10 @@ public class ServiceCheckValidityCheck extends AbstractCheckDescriptor
{
   private static SortRequest sortRequest = new SortRequestImpl(sortRequestProperties);
   private static final PageRequestImpl PAGE_REQUEST = new PageRequestImpl(PageRequest.StartingPoint.End,
1000, 0, null, null);
   private static final RequestImpl REQUEST = new RequestImpl(null, null, null, null, sortRequest,
PAGE_REQUEST);
-  private static final Predicate PREDICATE = new PredicateBuilder().property(TaskResourceProvider.TASK_COMMAND_PROPERTY_ID)
-      .equals(RoleCommand.SERVICE_CHECK.name()).toPredicate();
+  private static final Predicate PREDICATE = new PredicateBuilder()
+    .property(TaskResourceProvider.TASK_COMMAND_PROPERTY_ID).equals(RoleCommand.SERVICE_CHECK.name())
+    .and().property(TaskResourceProvider.TASK_START_TIME_PROPERTY_ID).greaterThan(-1)
+    .toPredicate();
 
 
 
@@ -89,6 +91,7 @@ public class ServiceCheckValidityCheck extends AbstractCheckDescriptor {
   @Inject
   Provider<HostRoleCommandDAO> hostRoleCommandDAOProvider;
 
+
   /**
    * Constructor.
    */
@@ -147,7 +150,7 @@ public class ServiceCheckValidityCheck extends AbstractCheckDescriptor
{
 
       boolean serviceCheckWasExecuted = false;
       for (HostRoleCommandEntity command : latestTimestamps.values()) {
-        if (command.getCommandDetail().contains(serviceName)) {
+        if (null !=  command.getCommandDetail() && command.getCommandDetail().contains(serviceName))
{
           serviceCheckWasExecuted = true;
           Long serviceCheckTimestamp = command.getStartTime();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/b3425c98/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProvider.java
index afbd981..8f00456 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProvider.java
@@ -29,6 +29,7 @@ import org.apache.ambari.server.ParentObjectNotFoundException;
 import org.apache.ambari.server.StaticallyInject;
 import org.apache.ambari.server.checks.AbstractCheckDescriptor;
 import org.apache.ambari.server.checks.UpgradeCheckRegistry;
+import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
 import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
@@ -95,6 +96,9 @@ public class PreUpgradeCheckResourceProvider extends ReadOnlyResourceProvider
{
   private static Provider<UpgradeHelper> upgradeHelper;
 
   @Inject
+  private static Provider<Configuration> config;
+
+  @Inject
   private static CheckHelper checkHelper;
 
   private static Set<String> pkPropertyIds = Collections.singleton(UPGRADE_CHECK_ID_PROPERTY_ID);
@@ -206,7 +210,7 @@ public class PreUpgradeCheckResourceProvider extends ReadOnlyResourceProvider
{
         LOG.error("Failed to register custom prechecks for the services", e);
       }
 
-      for (PrerequisiteCheck prerequisiteCheck : checkHelper.performChecks(upgradeCheckRequest,
upgradeChecksToRun)) {
+      for (PrerequisiteCheck prerequisiteCheck : checkHelper.performChecks(upgradeCheckRequest,
upgradeChecksToRun, config.get())) {
         final Resource resource = new ResourceImpl(Resource.Type.PreUpgradeCheck);
         setResourceProperty(resource, UPGRADE_CHECK_ID_PROPERTY_ID, prerequisiteCheck.getId(),
requestedIds);
         setResourceProperty(resource, UPGRADE_CHECK_CHECK_PROPERTY_ID, prerequisiteCheck.getDescription(),
requestedIds);

http://git-wip-us.apache.org/repos/asf/ambari/blob/b3425c98/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 5ea039c..f3fbc63 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
@@ -23,6 +23,7 @@ import java.util.List;
 
 import org.apache.ambari.server.ClusterNotFoundException;
 import org.apache.ambari.server.checks.AbstractCheckDescriptor;
+import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
@@ -86,44 +87,38 @@ public class CheckHelper {
    * @return list of pre-requisite check results
    */
   public List<PrerequisiteCheck> performChecks(PrereqCheckRequest request,
-      List<AbstractCheckDescriptor> checksRegistry) {
+                                               List<AbstractCheckDescriptor> checksRegistry,
Configuration config) {
 
     final String clusterName = request.getClusterName();
     final List<PrerequisiteCheck> prerequisiteCheckResults = new ArrayList<>();
+    final boolean canBypassPreChecks = config.isUpgradePrecheckBypass();
 
     List<DescriptorPreCheck> applicablePreChecks = getApplicablePrerequisiteChecks(request,
checksRegistry);
+
     for (DescriptorPreCheck descriptorPreCheck : applicablePreChecks) {
       AbstractCheckDescriptor checkDescriptor = descriptorPreCheck.descriptor;
       PrerequisiteCheck prerequisiteCheck = descriptorPreCheck.check;
       try {
         checkDescriptor.perform(prerequisiteCheck, request);
-
-        boolean canBypassPreChecks = checkDescriptor.isStackUpgradeAllowedToBypassPreChecks();
-
-        if (prerequisiteCheck.getStatus() == PrereqCheckStatus.FAIL && canBypassPreChecks)
{
-          LOG.error("Check {} failed but stack upgrade is allowed to bypass failures. Error
to bypass: {}. Failed on: {}",
-              checkDescriptor.getDescription().name(),
-              prerequisiteCheck.getFailReason(),
-              StringUtils.join(prerequisiteCheck.getFailedOn(), ", "));
-          prerequisiteCheck.setStatus(PrereqCheckStatus.BYPASS);
-        }
-        prerequisiteCheckResults.add(prerequisiteCheck);
-
-        request.addResult(checkDescriptor.getDescription(), prerequisiteCheck.getStatus());
       } catch (ClusterNotFoundException ex) {
-        prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
         prerequisiteCheck.setFailReason("Cluster with name " + clusterName + " doesn't exists");
-        prerequisiteCheckResults.add(prerequisiteCheck);
-
-        request.addResult(checkDescriptor.getDescription(), prerequisiteCheck.getStatus());
+        prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
       } catch (Exception ex) {
         LOG.error("Check " + checkDescriptor.getDescription().name() + " failed", ex);
-        prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
         prerequisiteCheck.setFailReason("Unexpected server error happened");
-        prerequisiteCheckResults.add(prerequisiteCheck);
+        prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
+      }
 
-        request.addResult(checkDescriptor.getDescription(), prerequisiteCheck.getStatus());
+      if (prerequisiteCheck.getStatus() == PrereqCheckStatus.FAIL && canBypassPreChecks)
{
+        LOG.error("Check {} failed but stack upgrade is allowed to bypass failures. Error
to bypass: {}. Failed on: {}",
+          checkDescriptor.getDescription().name(),
+          prerequisiteCheck.getFailReason(),
+          StringUtils.join(prerequisiteCheck.getFailedOn(), ", "));
+        prerequisiteCheck.setStatus(PrereqCheckStatus.BYPASS);
       }
+
+      prerequisiteCheckResults.add(prerequisiteCheck);
+      request.addResult(checkDescriptor.getDescription(), prerequisiteCheck.getStatus());
     }
 
     return prerequisiteCheckResults;

http://git-wip-us.apache.org/repos/asf/ambari/blob/b3425c98/ambari-server/src/test/java/org/apache/ambari/server/checks/ServiceCheckValidityCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServiceCheckValidityCheckTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServiceCheckValidityCheckTest.java
index 4d8a109..91fd72a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServiceCheckValidityCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServiceCheckValidityCheckTest.java
@@ -17,6 +17,7 @@
  */
 package org.apache.ambari.server.checks;
 
+import static java.util.Arrays.asList;
 import static java.util.Collections.singletonList;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
@@ -117,6 +118,42 @@ public class ServiceCheckValidityCheckTest {
   }
 
   @Test
+  public void testWithNullCommandDetailAtCommand() throws AmbariException {
+    ServiceComponent serviceComponent = mock(ServiceComponent.class);
+    when(serviceComponent.isVersionAdvertised()).thenReturn(true);
+
+    when(service.getMaintenanceState()).thenReturn(MaintenanceState.OFF);
+    when(service.getServiceComponents()).thenReturn(ImmutableMap.of(SERVICE_COMPONENT_NAME,
serviceComponent));
+
+    ServiceConfigEntity serviceConfigEntity = new ServiceConfigEntity();
+    serviceConfigEntity.setServiceName(SERVICE_NAME);
+    serviceConfigEntity.setCreateTimestamp(CONFIG_CREATE_TIMESTAMP);
+
+    HostRoleCommandEntity hostRoleCommandEntity1 = new HostRoleCommandEntity();
+    hostRoleCommandEntity1.setRoleCommand(RoleCommand.SERVICE_CHECK);
+    hostRoleCommandEntity1.setCommandDetail(null);
+    hostRoleCommandEntity1.setStartTime(SERVICE_CHECK_START_TIME);
+    hostRoleCommandEntity1.setRole(Role.ZOOKEEPER_SERVER);
+
+    HostRoleCommandEntity hostRoleCommandEntity2 = new HostRoleCommandEntity();
+    hostRoleCommandEntity2.setRoleCommand(RoleCommand.SERVICE_CHECK);
+    hostRoleCommandEntity2.setCommandDetail(COMMAND_DETAIL);
+    hostRoleCommandEntity2.setStartTime(SERVICE_CHECK_START_TIME);
+    hostRoleCommandEntity2.setRole(Role.HDFS_SERVICE_CHECK);
+
+    when(serviceConfigDAO.getLastServiceConfig(eq(CLUSTER_ID), eq(SERVICE_NAME))).thenReturn(serviceConfigEntity);
+    when(hostRoleCommandDAO.findAll(any(Request.class), any(Predicate.class))).thenReturn(asList(hostRoleCommandEntity1,
hostRoleCommandEntity2));
+
+    PrerequisiteCheck check = new PrerequisiteCheck(null, CLUSTER_NAME);
+    try {
+      serviceCheckValidityCheck.perform(check, new PrereqCheckRequest(CLUSTER_NAME));
+    } catch (NullPointerException ex){
+      Assert.fail("serviceCheckValidityCheck failed due to null at start_time were not handled");
+    }
+    Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
+  }
+
+  @Test
   public void testFailWhenServiceWithOutdatedServiceCheckExists() throws AmbariException
{
     ServiceComponent serviceComponent = mock(ServiceComponent.class);
     when(serviceComponent.isVersionAdvertised()).thenReturn(true);
@@ -188,7 +225,7 @@ public class ServiceCheckValidityCheckTest {
     hostRoleCommandEntity2.setRole(Role.HDFS_SERVICE_CHECK);
 
     when(serviceConfigDAO.getLastServiceConfig(eq(CLUSTER_ID), eq(SERVICE_NAME))).thenReturn(serviceConfigEntity);
-    when(hostRoleCommandDAO.findAll(any(Request.class), any(Predicate.class))).thenReturn(Arrays.asList(hostRoleCommandEntity1,
hostRoleCommandEntity2));
+    when(hostRoleCommandDAO.findAll(any(Request.class), any(Predicate.class))).thenReturn(asList(hostRoleCommandEntity1,
hostRoleCommandEntity2));
 
     PrerequisiteCheck check = new PrerequisiteCheck(null, CLUSTER_NAME);
     serviceCheckValidityCheck.perform(check, new PrereqCheckRequest(CLUSTER_NAME));

http://git-wip-us.apache.org/repos/asf/ambari/blob/b3425c98/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProviderTest.java
index 5287c4d..2a48fa6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProviderTest.java
@@ -38,6 +38,7 @@ import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.checks.AbstractCheckDescriptor;
 import org.apache.ambari.server.checks.UpgradeCheckRegistry;
+import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.Request;
@@ -84,6 +85,7 @@ public class PreUpgradeCheckResourceProviderTest {
 
     Clusters clusters = injector.getInstance(Clusters.class);
     UpgradeHelper upgradeHelper = injector.getInstance(UpgradeHelper.class);
+    Configuration configuration = injector.getInstance(Configuration.class);
 
     RepositoryVersionDAO repoDao = injector.getInstance(RepositoryVersionDAO.class);
     RepositoryVersionEntity repo = createNiceMock(RepositoryVersionEntity.class);
@@ -104,6 +106,7 @@ public class PreUpgradeCheckResourceProviderTest {
     Map<String, ServiceInfo> allServiceInfoMap = new HashMap<>();
     allServiceInfoMap.put("Service100", serviceInfo);
 
+    expect(configuration.isUpgradePrecheckBypass()).andReturn(false).anyTimes();
     // set expectations
     expect(managementController.getClusters()).andReturn(clusters).anyTimes();
     expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
@@ -135,7 +138,7 @@ public class PreUpgradeCheckResourceProviderTest {
 
     // replay
     replay(managementController, clusters, cluster, service, serviceInfo, repoDao, repo,
upgradeHelper,
-        ambariMetaInfo, upgradePack, config, currentStackId, targetStackId, serviceFactory);
+        ambariMetaInfo, upgradePack, config, currentStackId, targetStackId, serviceFactory,
configuration);
 
     ResourceProvider provider = getPreUpgradeCheckResourceProvider(managementController,
injector);
     // create the request
@@ -198,6 +201,15 @@ public class PreUpgradeCheckResourceProviderTest {
     }
   }
 
+  static class TestConfigurationProvider implements Provider<Configuration> {
+    private static Configuration configuration = createNiceMock(Configuration.class);
+
+    @Override
+    public Configuration get(){
+      return configuration;
+    }
+  }
+
   static class TestUpgradeHelperProvider implements Provider<UpgradeHelper> {
     private static UpgradeHelper upgradeHelper = createNiceMock(UpgradeHelper.class);
 
@@ -216,6 +228,7 @@ public class PreUpgradeCheckResourceProviderTest {
         CheckHelper checkHelper = new CheckHelper();
         UpgradeCheckRegistry registry = new UpgradeCheckRegistry();
 
+        bind(Configuration.class).toProvider(TestConfigurationProvider.class);
         bind(AmbariManagementController.class).toInstance(createNiceMock(AmbariManagementController.class));
         bind(CheckHelper.class).toInstance(checkHelper);
         bind(Clusters.class).toProvider(TestClustersProvider.class);

http://git-wip-us.apache.org/repos/asf/ambari/blob/b3425c98/ambari-server/src/test/java/org/apache/ambari/server/sample/checks/SampleServiceCheck.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/sample/checks/SampleServiceCheck.java
b/ambari-server/src/test/java/org/apache/ambari/server/sample/checks/SampleServiceCheck.java
index 1c16040..3a07928 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/sample/checks/SampleServiceCheck.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/sample/checks/SampleServiceCheck.java
@@ -44,9 +44,5 @@ public class SampleServiceCheck extends AbstractCheckDescriptor {
     prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
   }
 
-  @Override
-  public boolean isStackUpgradeAllowedToBypassPreChecks() {
-    return false;
-  }
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/b3425c98/ambari-server/src/test/java/org/apache/ambari/server/state/CheckHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/CheckHelperTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/CheckHelperTest.java
index 02e84df..a25ad08 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/CheckHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/CheckHelperTest.java
@@ -28,6 +28,7 @@ import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.checks.AbstractCheckDescriptor;
 import org.apache.ambari.server.checks.CheckDescription;
 import org.apache.ambari.server.checks.ServicesUpCheck;
+import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
 import org.apache.ambari.server.orm.dao.HostVersionDAO;
 import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
@@ -63,15 +64,18 @@ public class CheckHelperTest {
   @Test
   public void testPreUpgradeCheck() throws Exception {
     final CheckHelper helper = new CheckHelper();
+    Configuration configuration = EasyMock.createNiceMock(Configuration.class);
     List<AbstractCheckDescriptor> updateChecksRegistry = new ArrayList<>();
     AbstractCheckDescriptor descriptor = EasyMock.createNiceMock(AbstractCheckDescriptor.class);
+
+    EasyMock.expect(configuration.isUpgradePrecheckBypass()).andReturn(false);
     descriptor.perform(EasyMock.<PrerequisiteCheck> anyObject(), EasyMock.<PrereqCheckRequest>
anyObject());
     EasyMock.expectLastCall().times(1);
     EasyMock.expect(descriptor.isApplicable(EasyMock.<PrereqCheckRequest> anyObject())).andReturn(true);
-    EasyMock.replay(descriptor);
+    EasyMock.replay(descriptor, configuration);
     updateChecksRegistry.add(descriptor);
 
-    helper.performChecks(new PrereqCheckRequest("cluster"), updateChecksRegistry);
+    helper.performChecks(new PrereqCheckRequest("cluster"), updateChecksRegistry, configuration);
     EasyMock.verify(descriptor);
   }
 
@@ -81,12 +85,14 @@ public class CheckHelperTest {
   @Test
   public void testPreUpgradeCheckNotApplicable() throws Exception {
     final CheckHelper helper = new CheckHelper();
+    Configuration configuration = EasyMock.createNiceMock(Configuration.class);
     List<AbstractCheckDescriptor> updateChecksRegistry = new ArrayList<>();
     AbstractCheckDescriptor descriptor = EasyMock.createNiceMock(AbstractCheckDescriptor.class);
+    EasyMock.expect(configuration.isUpgradePrecheckBypass()).andReturn(false);
     EasyMock.expect(descriptor.isApplicable(EasyMock.<PrereqCheckRequest> anyObject())).andReturn(false);
-    EasyMock.replay(descriptor);
+    EasyMock.replay(descriptor, configuration);
     updateChecksRegistry.add(descriptor);
-    helper.performChecks(new PrereqCheckRequest("cluster"), updateChecksRegistry);
+    helper.performChecks(new PrereqCheckRequest("cluster"), updateChecksRegistry, configuration);
     EasyMock.verify(descriptor);
   }
 
@@ -98,14 +104,16 @@ public class CheckHelperTest {
     final CheckHelper helper = new CheckHelper();
     List<AbstractCheckDescriptor> updateChecksRegistry = new ArrayList<>();
     AbstractCheckDescriptor descriptor = EasyMock.createNiceMock(AbstractCheckDescriptor.class);
+    Configuration configuration = EasyMock.createNiceMock(Configuration.class);
 
+    EasyMock.expect(configuration.isUpgradePrecheckBypass()).andReturn(false);
     descriptor.perform(EasyMock.<PrerequisiteCheck> anyObject(), EasyMock.<PrereqCheckRequest>
anyObject());
     EasyMock.expectLastCall().andThrow(new AmbariException("error"));
     EasyMock.expect(descriptor.isApplicable(EasyMock.<PrereqCheckRequest> anyObject())).andReturn(true);
     EasyMock.expect(descriptor.getDescription()).andReturn(CheckDescription.HOSTS_HEARTBEAT).anyTimes();
-    EasyMock.replay(descriptor);
+    EasyMock.replay(descriptor, configuration);
     updateChecksRegistry.add(descriptor);
-    final List<PrerequisiteCheck> upgradeChecks = helper.performChecks(new PrereqCheckRequest("cluster"),
updateChecksRegistry);
+    final List<PrerequisiteCheck> upgradeChecks = helper.performChecks(new PrereqCheckRequest("cluster"),
updateChecksRegistry, configuration);
     EasyMock.verify(descriptor);
     Assert.assertEquals(PrereqCheckStatus.FAIL, upgradeChecks.get(0).getStatus());
   }
@@ -118,13 +126,15 @@ public class CheckHelperTest {
     // This mock class extends CheckHelper and overrides the getPrerequisiteChecks method
in order to return
     // a PrerequisiteCheck object whose status is FAIL.
     final CheckHelperMock helper =  new CheckHelperMock();
+    Configuration configuration = EasyMock.createNiceMock(Configuration.class);
     List<AbstractCheckDescriptor> updateChecksRegistry = new ArrayList<>();
 
     PrereqCheckRequest checkRequest = EasyMock.createNiceMock(PrereqCheckRequest.class);
+    EasyMock.expect(configuration.isUpgradePrecheckBypass()).andReturn(true);
     EasyMock.expect(checkRequest.getClusterName()).andReturn("c1").anyTimes();
-    EasyMock.replay(checkRequest);
+    EasyMock.replay(checkRequest, configuration);
 
-    final List<PrerequisiteCheck> upgradeChecks = helper.performChecks(checkRequest,
updateChecksRegistry);
+    final List<PrerequisiteCheck> upgradeChecks = helper.performChecks(checkRequest,
updateChecksRegistry, configuration);
     Assert.assertEquals(1, upgradeChecks.size());
     Assert.assertEquals(PrereqCheckStatus.BYPASS, upgradeChecks.get(0).getStatus());
   }
@@ -132,6 +142,7 @@ public class CheckHelperTest {
   @Test
   public void testPreUpgradeCheckClusterMissing() throws Exception {
     final Clusters clusters = Mockito.mock(Clusters.class);
+    Configuration configuration = EasyMock.createNiceMock(Configuration.class);
     Mockito.when(clusters.getCluster(Mockito.anyString())).thenAnswer(new Answer<Cluster>()
{
       @Override
       public Cluster answer(InvocationOnMock invocation) throws Throwable {
@@ -164,11 +175,15 @@ public class CheckHelperTest {
     final CheckHelper helper = injector.getInstance(CheckHelper.class);
     List<AbstractCheckDescriptor> updateChecksRegistry = new ArrayList<>();
 
+    EasyMock.expect(configuration.isUpgradePrecheckBypass()).andReturn(false);
+
+    EasyMock.replay(configuration);
+
     // mocked Cluster has no services, so the check should always be PASS
     updateChecksRegistry.add(injector.getInstance(ServicesUpCheck.class));
-    List<PrerequisiteCheck> upgradeChecks = helper.performChecks(new PrereqCheckRequest("existing"),
updateChecksRegistry);
+    List<PrerequisiteCheck> upgradeChecks = helper.performChecks(new PrereqCheckRequest("existing"),
updateChecksRegistry, configuration);
     Assert.assertEquals(PrereqCheckStatus.PASS, upgradeChecks.get(0).getStatus());
-    upgradeChecks = helper.performChecks(new PrereqCheckRequest("non-existing"), updateChecksRegistry);
+    upgradeChecks = helper.performChecks(new PrereqCheckRequest("non-existing"), updateChecksRegistry,
configuration);
     Assert.assertEquals(PrereqCheckStatus.FAIL, upgradeChecks.get(0).getStatus());
     //non existing cluster is an expected error
     Assert.assertTrue(!upgradeChecks.get(0).getFailReason().equals("Unexpected server error
happened"));
@@ -191,7 +206,6 @@ public class CheckHelperTest {
         EasyMock.expect(descriptor.getDescription()).andReturn(description).anyTimes();
 
         // Allow bypassing failures
-        EasyMock.expect(descriptor.isStackUpgradeAllowedToBypassPreChecks()).andReturn(true);
         EasyMock.replay(descriptor);
 
         applicablePreChecks.add(new DescriptorPreCheck(descriptor, check));


Mime
View raw message