@Test public void testMatchingVersions() throws Exception { StackId sourceStack = HDP_21_STACK; StackId targetStack = HDP_21_STACK; String sourceRepo = HDP_2_1_1_0; String targetRepo = HDP_2_1_1_1; makeUpgradeCluster(sourceStack, sourceRepo, targetStack, targetRepo); AmbariMetaInfo metaInfo = m_injector.getInstance(AmbariMetaInfo.class); RepositoryInfo repo = metaInfo.getRepository(sourceStack.getStackName(), sourceStack.getStackVersion(), "redhat6", sourceStack.getStackId()); assertEquals(HDP_211_CENTOS6_REPO_URL, repo.getBaseUrl()); Map<String, String> commandParams = new HashMap<String, String>(); commandParams.put(FinalizeUpgradeAction.UPGRADE_DIRECTION_KEY, "upgrade"); commandParams.put(FinalizeUpgradeAction.VERSION_KEY, targetRepo); ExecutionCommand executionCommand = new ExecutionCommand(); executionCommand.setCommandParams(commandParams); executionCommand.setClusterName("c1"); HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand)); ComponentVersionCheckAction action = m_injector.getInstance(ComponentVersionCheckAction.class); action.setExecutionCommand(executionCommand); action.setHostRoleCommand(hostRoleCommand); CommandReport report = action.execute(null); assertNotNull(report); assertEquals(HostRoleStatus.COMPLETED.name(), report.getStatus()); assertEquals(0, report.getExitCode()); }
@Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { Map<String, String> commandParams = getExecutionCommand().getCommandParams(); String version = commandParams.get(VERSION_KEY); StackId targetStackId = new StackId(commandParams.get(TARGET_STACK_KEY)); String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = clusters.getCluster(clusterName); List<InfoTuple> errors = checkHostComponentVersions(cluster, version, targetStackId); StringBuilder outSB = new StringBuilder(); StringBuilder errSB = new StringBuilder(); if (errors.isEmpty()) { outSB.append("No version mismatches found for components"); errSB.append("No errors found for components"); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", outSB.toString(), errSB.toString()); } else { String structuredOut = getErrors(outSB, errSB, errors); return createCommandReport(-1, HostRoleStatus.FAILED, structuredOut, outSB.toString(), errSB.toString()); } }
ComponentVersionCheckAction extends FinalizeUpgradeAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { Map<String, String> commandParams = getExecutionCommand().getCommandParams(); String version = commandParams.get(VERSION_KEY); StackId targetStackId = new StackId(commandParams.get(TARGET_STACK_KEY)); String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = clusters.getCluster(clusterName); List<InfoTuple> errors = checkHostComponentVersions(cluster, version, targetStackId); StringBuilder outSB = new StringBuilder(); StringBuilder errSB = new StringBuilder(); if (errors.isEmpty()) { outSB.append("No version mismatches found for components"); errSB.append("No errors found for components"); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", outSB.toString(), errSB.toString()); } else { String structuredOut = getErrors(outSB, errSB, errors); return createCommandReport(-1, HostRoleStatus.FAILED, structuredOut, outSB.toString(), errSB.toString()); } } }
ComponentVersionCheckAction extends FinalizeUpgradeAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { Map<String, String> commandParams = getExecutionCommand().getCommandParams(); String version = commandParams.get(VERSION_KEY); StackId targetStackId = new StackId(commandParams.get(TARGET_STACK_KEY)); String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = clusters.getCluster(clusterName); List<InfoTuple> errors = checkHostComponentVersions(cluster, version, targetStackId); StringBuilder outSB = new StringBuilder(); StringBuilder errSB = new StringBuilder(); if (errors.isEmpty()) { outSB.append("No version mismatches found for components"); errSB.append("No errors found for components"); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", outSB.toString(), errSB.toString()); } else { String structuredOut = getErrors(outSB, errSB, errors); return createCommandReport(-1, HostRoleStatus.FAILED, structuredOut, outSB.toString(), errSB.toString()); } }  }
ComponentVersionCheckAction extends FinalizeUpgradeAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { Map<String, String> commandParams = getExecutionCommand().getCommandParams(); String version = commandParams.get(VERSION_KEY); StackId targetStackId = new StackId(commandParams.get(TARGET_STACK_KEY)); String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = clusters.getCluster(clusterName); List<InfoTuple> errors = checkHostComponentVersions(cluster, version, targetStackId); StringBuilder outSB = new StringBuilder(); StringBuilder errSB = new StringBuilder(); if (errors.isEmpty()) { outSB.append("No version mismatches found for components"); errSB.append("No errors found for components"); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", outSB.toString(), errSB.toString()); } else { String structuredOut = getErrors(outSB, errSB, errors); return createCommandReport(-1, HostRoleStatus.FAILED, structuredOut, outSB.toString(), errSB.toString()); } }  @Override CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext); }
ComponentVersionCheckAction extends FinalizeUpgradeAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { Map<String, String> commandParams = getExecutionCommand().getCommandParams(); String version = commandParams.get(VERSION_KEY); StackId targetStackId = new StackId(commandParams.get(TARGET_STACK_KEY)); String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = clusters.getCluster(clusterName); List<InfoTuple> errors = checkHostComponentVersions(cluster, version, targetStackId); StringBuilder outSB = new StringBuilder(); StringBuilder errSB = new StringBuilder(); if (errors.isEmpty()) { outSB.append("No version mismatches found for components"); errSB.append("No errors found for components"); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", outSB.toString(), errSB.toString()); } else { String structuredOut = getErrors(outSB, errSB, errors); return createCommandReport(-1, HostRoleStatus.FAILED, structuredOut, outSB.toString(), errSB.toString()); } }  @Override CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext);  }