@Test public void testPreUpgradeCheck() throws Exception { final CheckHelper helper = new CheckHelper(); List<AbstractCheckDescriptor> updateChecksRegistry = new ArrayList<AbstractCheckDescriptor>(); AbstractCheckDescriptor descriptor = EasyMock.createNiceMock(AbstractCheckDescriptor.class); descriptor.perform(EasyMock.<PrerequisiteCheck> anyObject(), EasyMock.<PrereqCheckRequest> anyObject()); EasyMock.expectLastCall().times(1); EasyMock.expect(descriptor.isApplicable(EasyMock.<PrereqCheckRequest> anyObject())).andReturn(true); EasyMock.replay(descriptor); updateChecksRegistry.add(descriptor); helper.performChecks(new PrereqCheckRequest("cluster"), updateChecksRegistry); EasyMock.verify(descriptor); }
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);  }