@Test public void testPreUpgradeCheckBypassesFailure() throws Exception { final CheckHelperMock helper = new CheckHelperMock(); List<AbstractCheckDescriptor> updateChecksRegistry = new ArrayList<AbstractCheckDescriptor>(); PrereqCheckRequest checkRequest = EasyMock.createNiceMock(PrereqCheckRequest.class); EasyMock.expect(checkRequest.getClusterName()).andReturn("c1").anyTimes(); EasyMock.replay(checkRequest); final List<PrerequisiteCheck> upgradeChecks = helper.performChecks(checkRequest, updateChecksRegistry); Assert.assertEquals(1, upgradeChecks.size()); Assert.assertEquals(PrereqCheckStatus.BYPASS, upgradeChecks.get(0).getStatus()); }
public List<PrerequisiteCheck> performChecks(PrereqCheckRequest request, List<AbstractCheckDescriptor> checksRegistry) { final String clusterName = request.getClusterName(); final List<PrerequisiteCheck> prerequisiteCheckResults = new ArrayList<PrerequisiteCheck>(); 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()); } catch (Exception ex) { LOG.error("Check " + checkDescriptor.getDescription().name() + " failed", ex); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason("Unexpected server error happened"); prerequisiteCheckResults.add(prerequisiteCheck); request.addResult(checkDescriptor.getDescription(), prerequisiteCheck.getStatus()); } } return prerequisiteCheckResults; }
CheckHelper { public List<PrerequisiteCheck> performChecks(PrereqCheckRequest request, List<AbstractCheckDescriptor> checksRegistry) { final String clusterName = request.getClusterName(); final List<PrerequisiteCheck> prerequisiteCheckResults = new ArrayList<PrerequisiteCheck>(); 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()); } catch (Exception ex) { LOG.error("Check " + checkDescriptor.getDescription().name() + " failed", ex); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason("Unexpected server error happened"); prerequisiteCheckResults.add(prerequisiteCheck); request.addResult(checkDescriptor.getDescription(), prerequisiteCheck.getStatus()); } } return prerequisiteCheckResults; } }
CheckHelper { public List<PrerequisiteCheck> performChecks(PrereqCheckRequest request, List<AbstractCheckDescriptor> checksRegistry) { final String clusterName = request.getClusterName(); final List<PrerequisiteCheck> prerequisiteCheckResults = new ArrayList<PrerequisiteCheck>(); 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()); } catch (Exception ex) { LOG.error("Check " + checkDescriptor.getDescription().name() + " failed", ex); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason("Unexpected server error happened"); prerequisiteCheckResults.add(prerequisiteCheck); request.addResult(checkDescriptor.getDescription(), prerequisiteCheck.getStatus()); } } return prerequisiteCheckResults; }  }
CheckHelper { public List<PrerequisiteCheck> performChecks(PrereqCheckRequest request, List<AbstractCheckDescriptor> checksRegistry) { final String clusterName = request.getClusterName(); final List<PrerequisiteCheck> prerequisiteCheckResults = new ArrayList<PrerequisiteCheck>(); 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()); } catch (Exception ex) { LOG.error("Check " + checkDescriptor.getDescription().name() + " failed", ex); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason("Unexpected server error happened"); prerequisiteCheckResults.add(prerequisiteCheck); request.addResult(checkDescriptor.getDescription(), prerequisiteCheck.getStatus()); } } return prerequisiteCheckResults; }  List<DescriptorPreCheck> getApplicablePrerequisiteChecks(PrereqCheckRequest request,
                                                       List<AbstractCheckDescriptor> checksRegistry); List<PrerequisiteCheck> performChecks(PrereqCheckRequest request,
      List<AbstractCheckDescriptor> checksRegistry); }
CheckHelper { public List<PrerequisiteCheck> performChecks(PrereqCheckRequest request, List<AbstractCheckDescriptor> checksRegistry) { final String clusterName = request.getClusterName(); final List<PrerequisiteCheck> prerequisiteCheckResults = new ArrayList<PrerequisiteCheck>(); 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()); } catch (Exception ex) { LOG.error("Check " + checkDescriptor.getDescription().name() + " failed", ex); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason("Unexpected server error happened"); prerequisiteCheckResults.add(prerequisiteCheck); request.addResult(checkDescriptor.getDescription(), prerequisiteCheck.getStatus()); } } return prerequisiteCheckResults; }  List<DescriptorPreCheck> getApplicablePrerequisiteChecks(PrereqCheckRequest request,
                                                       List<AbstractCheckDescriptor> checksRegistry); List<PrerequisiteCheck> performChecks(PrereqCheckRequest request,
      List<AbstractCheckDescriptor> checksRegistry);  }