@Test public void testConditionalDeleteTask() throws Exception { Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.1.1"); assertTrue(upgrades.containsKey("upgrade_test")); UpgradePack upgrade = upgrades.get("upgrade_test"); ConfigUpgradePack cup = ambariMetaInfo.getConfigUpgradePack("HDP", "2.1.1"); assertNotNull(upgrade); Cluster cluster = makeCluster(); UpgradeContext context = m_upgradeContextFactory.create(cluster, UpgradeType.ROLLING, Direction.UPGRADE, UPGRADE_VERSION, new HashMap<String, Object>()); context.setResolver(m_masterHostResolver); List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context); assertEquals(7, groups.size()); UpgradeGroupHolder hiveGroup = groups.get(4); assertEquals("HIVE", hiveGroup.name); ConfigureTask configureTask = (ConfigureTask) hiveGroup.items.get(1).getTasks().get(0).getTasks().get(0); Map<String, String> hiveConfigs = new HashMap<>(); hiveConfigs.put("hive.server2.transport.mode", "http"); hiveConfigs.put("hive.server2.thrift.port", "10001"); hiveConfigs.put("condition", "1"); ConfigurationRequest configurationRequest = new ConfigurationRequest(); configurationRequest.setClusterName(cluster.getClusterName()); configurationRequest.setType("hive-site"); configurationRequest.setVersionTag("version2"); configurationRequest.setProperties(hiveConfigs); final ClusterRequest clusterRequest = new ClusterRequest( cluster.getClusterId(), cluster.getClusterName(), cluster.getDesiredStackVersion().getStackVersion(), null); clusterRequest.setDesiredConfig(Collections.singletonList(configurationRequest)); m_managementController.updateClusters(new HashSet<ClusterRequest>() { { add(clusterRequest); } }, null); Map<String, String> configProperties = configureTask.getConfigurationChanges(cluster, cup); assertFalse(configProperties.isEmpty()); assertEquals(configProperties.get(ConfigureTask.PARAMETER_CONFIG_TYPE), "hive-site"); String configurationJson = configProperties.get(ConfigureTask.PARAMETER_TRANSFERS); assertNotNull(configurationJson); List<ConfigUpgradeChangeDefinition.Transfer> transfers = m_gson.fromJson(configurationJson, new TypeToken<List<ConfigUpgradeChangeDefinition.Transfer>>() { }.getType()); System.out.println(">> transfers"+transfers); assertEquals(6, transfers.size()); assertEquals("copy-key", transfers.get(0).fromKey); assertEquals("copy-key-to", transfers.get(0).toKey); assertEquals("move-key", transfers.get(1).fromKey); assertEquals("move-key-to", transfers.get(1).toKey); assertEquals("delete-key", transfers.get(2).deleteKey); assertEquals("delete-http-1", transfers.get(3).deleteKey); assertEquals("delete-http-2", transfers.get(4).deleteKey); assertEquals("delete-http-3", transfers.get(5).deleteKey); }
public List<UpgradeGroupHolder> createSequence(UpgradePack upgradePack, UpgradeContext context) throws AmbariException { context.setAmbariMetaInfo(m_ambariMetaInfo.get()); Cluster cluster = context.getCluster(); MasterHostResolver mhr = context.getResolver(); Map<String, Map<String, ProcessingComponent>> allTasks = upgradePack.getTasks(); List<UpgradeGroupHolder> groups = new ArrayList<>(); for (Grouping group : upgradePack.getGroups(context.getDirection())) { if (!context.isScoped(group.scope)) { continue; } if (null != group.condition && !group.condition.isSatisfied(context)) { LOG.info("Skipping {} while building upgrade orchestration due to {}", group, group.condition ); continue; } UpgradeGroupHolder groupHolder = new UpgradeGroupHolder(); groupHolder.name = group.name; groupHolder.title = group.title; groupHolder.groupClass = group.getClass(); groupHolder.skippable = group.skippable; groupHolder.supportsAutoSkipOnFailure = group.supportsAutoSkipOnFailure; groupHolder.allowRetry = group.allowRetry; if (context.getDirection().isDowngrade()) { groupHolder.skippable = true; } Task.Type functionName = null; if (group instanceof UpgradeFunction) { functionName = ((UpgradeFunction) group).getFunction(); } if (upgradePack.getType() == UpgradeType.NON_ROLLING) { group.performServiceCheck = false; } StageWrapperBuilder builder = group.getBuilder(); List<UpgradePack.OrderService> services = group.services; if (upgradePack.getType() == UpgradeType.ROLLING) { if (context.getDirection().isDowngrade() && !services.isEmpty()) { List<UpgradePack.OrderService> reverse = new ArrayList<>(services); Collections.reverse(reverse); services = reverse; } } for (UpgradePack.OrderService service : services) { if (!context.isServiceSupported(service.serviceName)) { continue; } if (upgradePack.getType() == UpgradeType.ROLLING && !allTasks.containsKey(service.serviceName)) { continue; } for (String component : service.components) { if (upgradePack.getType() == UpgradeType.ROLLING && !allTasks.get(service.serviceName).containsKey(component)) { continue; } HostsType hostsType = mhr.getMasterAndHosts(service.serviceName, component); if (null == hostsType) { continue; } if (!hostsType.unhealthy.isEmpty()) { context.addUnhealthy(hostsType.unhealthy); } Service svc = cluster.getService(service.serviceName); ProcessingComponent pc = null; if (null == functionName) { pc = allTasks.get(service.serviceName).get(component); } else { if (functionName == Type.STOP) { pc = new ProcessingComponent(); pc.name = component; pc.tasks = new ArrayList<>(); pc.tasks.add(new StopTask()); } else { if (allTasks.containsKey(service.serviceName) && allTasks.get(service.serviceName).containsKey(component)) { pc = allTasks.get(service.serviceName).get(component); } else { pc = new ProcessingComponent(); pc.name = component; pc.tasks = new ArrayList<>(); if (functionName == Type.START) { pc.tasks.add(new StartTask()); } if (functionName == Type.RESTART) { pc.tasks.add(new RestartTask()); } } } } if (pc == null) { LOG.error(MessageFormat.format("Couldn't create a processing component for service {0} and component {1}.", service.serviceName, component)); continue; } setDisplayNames(context, service.serviceName, component); if (service.serviceName.equalsIgnoreCase("HDFS") && component.equalsIgnoreCase("NAMENODE")) { switch (upgradePack.getType()) { case ROLLING: if (!hostsType.hosts.isEmpty() && hostsType.master != null && hostsType.secondary != null) { LinkedHashSet<String> order = new LinkedHashSet<String>(); order.add(hostsType.secondary); order.add(hostsType.master); hostsType.hosts = order; builder.add(context, hostsType, service.serviceName, svc.isClientOnlyService(), pc, null); } else { LOG.warn("Could not orchestrate NameNode. Hosts could not be resolved: hosts={}, active={}, standby={}", StringUtils.join(hostsType.hosts, ','), hostsType.master, hostsType.secondary); } break; case NON_ROLLING: boolean isNameNodeHA = mhr.isNameNodeHA(); if (isNameNodeHA && hostsType.master != null && hostsType.secondary != null) { HostsType ht1 = new HostsType(); LinkedHashSet<String> h1Hosts = new LinkedHashSet<String>(); h1Hosts.add(hostsType.master); ht1.hosts = h1Hosts; Map<String, String> h1Params = new HashMap<String, String>(); h1Params.put("desired_namenode_role", "active"); HostsType ht2 = new HostsType(); LinkedHashSet<String> h2Hosts = new LinkedHashSet<String>(); h2Hosts.add(hostsType.secondary); ht2.hosts = h2Hosts; Map<String, String> h2Params = new HashMap<String, String>(); h2Params.put("desired_namenode_role", "standby"); builder.add(context, ht1, service.serviceName, svc.isClientOnlyService(), pc, h1Params); builder.add(context, ht2, service.serviceName, svc.isClientOnlyService(), pc, h2Params); } else { builder.add(context, hostsType, service.serviceName, svc.isClientOnlyService(), pc, null); } break; } } else { builder.add(context, hostsType, service.serviceName, svc.isClientOnlyService(), pc, null); } } } List<StageWrapper> proxies = builder.build(context); if (CollectionUtils.isNotEmpty(proxies)) { groupHolder.items = proxies; postProcess(context, groupHolder); groups.add(groupHolder); } } if (LOG.isDebugEnabled()) { for (UpgradeGroupHolder group : groups) { LOG.debug(group.name); int i = 0; for (StageWrapper proxy : group.items) { LOG.debug(" Stage {}", Integer.valueOf(i++)); int j = 0; for (TaskWrapper task : proxy.getTasks()) { LOG.debug(" Task {} {}", Integer.valueOf(j++), task); } } } } return groups; }
UpgradeHelper { public List<UpgradeGroupHolder> createSequence(UpgradePack upgradePack, UpgradeContext context) throws AmbariException { context.setAmbariMetaInfo(m_ambariMetaInfo.get()); Cluster cluster = context.getCluster(); MasterHostResolver mhr = context.getResolver(); Map<String, Map<String, ProcessingComponent>> allTasks = upgradePack.getTasks(); List<UpgradeGroupHolder> groups = new ArrayList<>(); for (Grouping group : upgradePack.getGroups(context.getDirection())) { if (!context.isScoped(group.scope)) { continue; } if (null != group.condition && !group.condition.isSatisfied(context)) { LOG.info("Skipping {} while building upgrade orchestration due to {}", group, group.condition ); continue; } UpgradeGroupHolder groupHolder = new UpgradeGroupHolder(); groupHolder.name = group.name; groupHolder.title = group.title; groupHolder.groupClass = group.getClass(); groupHolder.skippable = group.skippable; groupHolder.supportsAutoSkipOnFailure = group.supportsAutoSkipOnFailure; groupHolder.allowRetry = group.allowRetry; if (context.getDirection().isDowngrade()) { groupHolder.skippable = true; } Task.Type functionName = null; if (group instanceof UpgradeFunction) { functionName = ((UpgradeFunction) group).getFunction(); } if (upgradePack.getType() == UpgradeType.NON_ROLLING) { group.performServiceCheck = false; } StageWrapperBuilder builder = group.getBuilder(); List<UpgradePack.OrderService> services = group.services; if (upgradePack.getType() == UpgradeType.ROLLING) { if (context.getDirection().isDowngrade() && !services.isEmpty()) { List<UpgradePack.OrderService> reverse = new ArrayList<>(services); Collections.reverse(reverse); services = reverse; } } for (UpgradePack.OrderService service : services) { if (!context.isServiceSupported(service.serviceName)) { continue; } if (upgradePack.getType() == UpgradeType.ROLLING && !allTasks.containsKey(service.serviceName)) { continue; } for (String component : service.components) { if (upgradePack.getType() == UpgradeType.ROLLING && !allTasks.get(service.serviceName).containsKey(component)) { continue; } HostsType hostsType = mhr.getMasterAndHosts(service.serviceName, component); if (null == hostsType) { continue; } if (!hostsType.unhealthy.isEmpty()) { context.addUnhealthy(hostsType.unhealthy); } Service svc = cluster.getService(service.serviceName); ProcessingComponent pc = null; if (null == functionName) { pc = allTasks.get(service.serviceName).get(component); } else { if (functionName == Type.STOP) { pc = new ProcessingComponent(); pc.name = component; pc.tasks = new ArrayList<>(); pc.tasks.add(new StopTask()); } else { if (allTasks.containsKey(service.serviceName) && allTasks.get(service.serviceName).containsKey(component)) { pc = allTasks.get(service.serviceName).get(component); } else { pc = new ProcessingComponent(); pc.name = component; pc.tasks = new ArrayList<>(); if (functionName == Type.START) { pc.tasks.add(new StartTask()); } if (functionName == Type.RESTART) { pc.tasks.add(new RestartTask()); } } } } if (pc == null) { LOG.error(MessageFormat.format("Couldn't create a processing component for service {0} and component {1}.", service.serviceName, component)); continue; } setDisplayNames(context, service.serviceName, component); if (service.serviceName.equalsIgnoreCase("HDFS") && component.equalsIgnoreCase("NAMENODE")) { switch (upgradePack.getType()) { case ROLLING: if (!hostsType.hosts.isEmpty() && hostsType.master != null && hostsType.secondary != null) { LinkedHashSet<String> order = new LinkedHashSet<String>(); order.add(hostsType.secondary); order.add(hostsType.master); hostsType.hosts = order; builder.add(context, hostsType, service.serviceName, svc.isClientOnlyService(), pc, null); } else { LOG.warn("Could not orchestrate NameNode. Hosts could not be resolved: hosts={}, active={}, standby={}", StringUtils.join(hostsType.hosts, ','), hostsType.master, hostsType.secondary); } break; case NON_ROLLING: boolean isNameNodeHA = mhr.isNameNodeHA(); if (isNameNodeHA && hostsType.master != null && hostsType.secondary != null) { HostsType ht1 = new HostsType(); LinkedHashSet<String> h1Hosts = new LinkedHashSet<String>(); h1Hosts.add(hostsType.master); ht1.hosts = h1Hosts; Map<String, String> h1Params = new HashMap<String, String>(); h1Params.put("desired_namenode_role", "active"); HostsType ht2 = new HostsType(); LinkedHashSet<String> h2Hosts = new LinkedHashSet<String>(); h2Hosts.add(hostsType.secondary); ht2.hosts = h2Hosts; Map<String, String> h2Params = new HashMap<String, String>(); h2Params.put("desired_namenode_role", "standby"); builder.add(context, ht1, service.serviceName, svc.isClientOnlyService(), pc, h1Params); builder.add(context, ht2, service.serviceName, svc.isClientOnlyService(), pc, h2Params); } else { builder.add(context, hostsType, service.serviceName, svc.isClientOnlyService(), pc, null); } break; } } else { builder.add(context, hostsType, service.serviceName, svc.isClientOnlyService(), pc, null); } } } List<StageWrapper> proxies = builder.build(context); if (CollectionUtils.isNotEmpty(proxies)) { groupHolder.items = proxies; postProcess(context, groupHolder); groups.add(groupHolder); } } if (LOG.isDebugEnabled()) { for (UpgradeGroupHolder group : groups) { LOG.debug(group.name); int i = 0; for (StageWrapper proxy : group.items) { LOG.debug(" Stage {}", Integer.valueOf(i++)); int j = 0; for (TaskWrapper task : proxy.getTasks()) { LOG.debug(" Task {} {}", Integer.valueOf(j++), task); } } } } return groups; } }
UpgradeHelper { public List<UpgradeGroupHolder> createSequence(UpgradePack upgradePack, UpgradeContext context) throws AmbariException { context.setAmbariMetaInfo(m_ambariMetaInfo.get()); Cluster cluster = context.getCluster(); MasterHostResolver mhr = context.getResolver(); Map<String, Map<String, ProcessingComponent>> allTasks = upgradePack.getTasks(); List<UpgradeGroupHolder> groups = new ArrayList<>(); for (Grouping group : upgradePack.getGroups(context.getDirection())) { if (!context.isScoped(group.scope)) { continue; } if (null != group.condition && !group.condition.isSatisfied(context)) { LOG.info("Skipping {} while building upgrade orchestration due to {}", group, group.condition ); continue; } UpgradeGroupHolder groupHolder = new UpgradeGroupHolder(); groupHolder.name = group.name; groupHolder.title = group.title; groupHolder.groupClass = group.getClass(); groupHolder.skippable = group.skippable; groupHolder.supportsAutoSkipOnFailure = group.supportsAutoSkipOnFailure; groupHolder.allowRetry = group.allowRetry; if (context.getDirection().isDowngrade()) { groupHolder.skippable = true; } Task.Type functionName = null; if (group instanceof UpgradeFunction) { functionName = ((UpgradeFunction) group).getFunction(); } if (upgradePack.getType() == UpgradeType.NON_ROLLING) { group.performServiceCheck = false; } StageWrapperBuilder builder = group.getBuilder(); List<UpgradePack.OrderService> services = group.services; if (upgradePack.getType() == UpgradeType.ROLLING) { if (context.getDirection().isDowngrade() && !services.isEmpty()) { List<UpgradePack.OrderService> reverse = new ArrayList<>(services); Collections.reverse(reverse); services = reverse; } } for (UpgradePack.OrderService service : services) { if (!context.isServiceSupported(service.serviceName)) { continue; } if (upgradePack.getType() == UpgradeType.ROLLING && !allTasks.containsKey(service.serviceName)) { continue; } for (String component : service.components) { if (upgradePack.getType() == UpgradeType.ROLLING && !allTasks.get(service.serviceName).containsKey(component)) { continue; } HostsType hostsType = mhr.getMasterAndHosts(service.serviceName, component); if (null == hostsType) { continue; } if (!hostsType.unhealthy.isEmpty()) { context.addUnhealthy(hostsType.unhealthy); } Service svc = cluster.getService(service.serviceName); ProcessingComponent pc = null; if (null == functionName) { pc = allTasks.get(service.serviceName).get(component); } else { if (functionName == Type.STOP) { pc = new ProcessingComponent(); pc.name = component; pc.tasks = new ArrayList<>(); pc.tasks.add(new StopTask()); } else { if (allTasks.containsKey(service.serviceName) && allTasks.get(service.serviceName).containsKey(component)) { pc = allTasks.get(service.serviceName).get(component); } else { pc = new ProcessingComponent(); pc.name = component; pc.tasks = new ArrayList<>(); if (functionName == Type.START) { pc.tasks.add(new StartTask()); } if (functionName == Type.RESTART) { pc.tasks.add(new RestartTask()); } } } } if (pc == null) { LOG.error(MessageFormat.format("Couldn't create a processing component for service {0} and component {1}.", service.serviceName, component)); continue; } setDisplayNames(context, service.serviceName, component); if (service.serviceName.equalsIgnoreCase("HDFS") && component.equalsIgnoreCase("NAMENODE")) { switch (upgradePack.getType()) { case ROLLING: if (!hostsType.hosts.isEmpty() && hostsType.master != null && hostsType.secondary != null) { LinkedHashSet<String> order = new LinkedHashSet<String>(); order.add(hostsType.secondary); order.add(hostsType.master); hostsType.hosts = order; builder.add(context, hostsType, service.serviceName, svc.isClientOnlyService(), pc, null); } else { LOG.warn("Could not orchestrate NameNode. Hosts could not be resolved: hosts={}, active={}, standby={}", StringUtils.join(hostsType.hosts, ','), hostsType.master, hostsType.secondary); } break; case NON_ROLLING: boolean isNameNodeHA = mhr.isNameNodeHA(); if (isNameNodeHA && hostsType.master != null && hostsType.secondary != null) { HostsType ht1 = new HostsType(); LinkedHashSet<String> h1Hosts = new LinkedHashSet<String>(); h1Hosts.add(hostsType.master); ht1.hosts = h1Hosts; Map<String, String> h1Params = new HashMap<String, String>(); h1Params.put("desired_namenode_role", "active"); HostsType ht2 = new HostsType(); LinkedHashSet<String> h2Hosts = new LinkedHashSet<String>(); h2Hosts.add(hostsType.secondary); ht2.hosts = h2Hosts; Map<String, String> h2Params = new HashMap<String, String>(); h2Params.put("desired_namenode_role", "standby"); builder.add(context, ht1, service.serviceName, svc.isClientOnlyService(), pc, h1Params); builder.add(context, ht2, service.serviceName, svc.isClientOnlyService(), pc, h2Params); } else { builder.add(context, hostsType, service.serviceName, svc.isClientOnlyService(), pc, null); } break; } } else { builder.add(context, hostsType, service.serviceName, svc.isClientOnlyService(), pc, null); } } } List<StageWrapper> proxies = builder.build(context); if (CollectionUtils.isNotEmpty(proxies)) { groupHolder.items = proxies; postProcess(context, groupHolder); groups.add(groupHolder); } } if (LOG.isDebugEnabled()) { for (UpgradeGroupHolder group : groups) { LOG.debug(group.name); int i = 0; for (StageWrapper proxy : group.items) { LOG.debug(" Stage {}", Integer.valueOf(i++)); int j = 0; for (TaskWrapper task : proxy.getTasks()) { LOG.debug(" Task {} {}", Integer.valueOf(j++), task); } } } } return groups; }  }
UpgradeHelper { public List<UpgradeGroupHolder> createSequence(UpgradePack upgradePack, UpgradeContext context) throws AmbariException { context.setAmbariMetaInfo(m_ambariMetaInfo.get()); Cluster cluster = context.getCluster(); MasterHostResolver mhr = context.getResolver(); Map<String, Map<String, ProcessingComponent>> allTasks = upgradePack.getTasks(); List<UpgradeGroupHolder> groups = new ArrayList<>(); for (Grouping group : upgradePack.getGroups(context.getDirection())) { if (!context.isScoped(group.scope)) { continue; } if (null != group.condition && !group.condition.isSatisfied(context)) { LOG.info("Skipping {} while building upgrade orchestration due to {}", group, group.condition ); continue; } UpgradeGroupHolder groupHolder = new UpgradeGroupHolder(); groupHolder.name = group.name; groupHolder.title = group.title; groupHolder.groupClass = group.getClass(); groupHolder.skippable = group.skippable; groupHolder.supportsAutoSkipOnFailure = group.supportsAutoSkipOnFailure; groupHolder.allowRetry = group.allowRetry; if (context.getDirection().isDowngrade()) { groupHolder.skippable = true; } Task.Type functionName = null; if (group instanceof UpgradeFunction) { functionName = ((UpgradeFunction) group).getFunction(); } if (upgradePack.getType() == UpgradeType.NON_ROLLING) { group.performServiceCheck = false; } StageWrapperBuilder builder = group.getBuilder(); List<UpgradePack.OrderService> services = group.services; if (upgradePack.getType() == UpgradeType.ROLLING) { if (context.getDirection().isDowngrade() && !services.isEmpty()) { List<UpgradePack.OrderService> reverse = new ArrayList<>(services); Collections.reverse(reverse); services = reverse; } } for (UpgradePack.OrderService service : services) { if (!context.isServiceSupported(service.serviceName)) { continue; } if (upgradePack.getType() == UpgradeType.ROLLING && !allTasks.containsKey(service.serviceName)) { continue; } for (String component : service.components) { if (upgradePack.getType() == UpgradeType.ROLLING && !allTasks.get(service.serviceName).containsKey(component)) { continue; } HostsType hostsType = mhr.getMasterAndHosts(service.serviceName, component); if (null == hostsType) { continue; } if (!hostsType.unhealthy.isEmpty()) { context.addUnhealthy(hostsType.unhealthy); } Service svc = cluster.getService(service.serviceName); ProcessingComponent pc = null; if (null == functionName) { pc = allTasks.get(service.serviceName).get(component); } else { if (functionName == Type.STOP) { pc = new ProcessingComponent(); pc.name = component; pc.tasks = new ArrayList<>(); pc.tasks.add(new StopTask()); } else { if (allTasks.containsKey(service.serviceName) && allTasks.get(service.serviceName).containsKey(component)) { pc = allTasks.get(service.serviceName).get(component); } else { pc = new ProcessingComponent(); pc.name = component; pc.tasks = new ArrayList<>(); if (functionName == Type.START) { pc.tasks.add(new StartTask()); } if (functionName == Type.RESTART) { pc.tasks.add(new RestartTask()); } } } } if (pc == null) { LOG.error(MessageFormat.format("Couldn't create a processing component for service {0} and component {1}.", service.serviceName, component)); continue; } setDisplayNames(context, service.serviceName, component); if (service.serviceName.equalsIgnoreCase("HDFS") && component.equalsIgnoreCase("NAMENODE")) { switch (upgradePack.getType()) { case ROLLING: if (!hostsType.hosts.isEmpty() && hostsType.master != null && hostsType.secondary != null) { LinkedHashSet<String> order = new LinkedHashSet<String>(); order.add(hostsType.secondary); order.add(hostsType.master); hostsType.hosts = order; builder.add(context, hostsType, service.serviceName, svc.isClientOnlyService(), pc, null); } else { LOG.warn("Could not orchestrate NameNode. Hosts could not be resolved: hosts={}, active={}, standby={}", StringUtils.join(hostsType.hosts, ','), hostsType.master, hostsType.secondary); } break; case NON_ROLLING: boolean isNameNodeHA = mhr.isNameNodeHA(); if (isNameNodeHA && hostsType.master != null && hostsType.secondary != null) { HostsType ht1 = new HostsType(); LinkedHashSet<String> h1Hosts = new LinkedHashSet<String>(); h1Hosts.add(hostsType.master); ht1.hosts = h1Hosts; Map<String, String> h1Params = new HashMap<String, String>(); h1Params.put("desired_namenode_role", "active"); HostsType ht2 = new HostsType(); LinkedHashSet<String> h2Hosts = new LinkedHashSet<String>(); h2Hosts.add(hostsType.secondary); ht2.hosts = h2Hosts; Map<String, String> h2Params = new HashMap<String, String>(); h2Params.put("desired_namenode_role", "standby"); builder.add(context, ht1, service.serviceName, svc.isClientOnlyService(), pc, h1Params); builder.add(context, ht2, service.serviceName, svc.isClientOnlyService(), pc, h2Params); } else { builder.add(context, hostsType, service.serviceName, svc.isClientOnlyService(), pc, null); } break; } } else { builder.add(context, hostsType, service.serviceName, svc.isClientOnlyService(), pc, null); } } } List<StageWrapper> proxies = builder.build(context); if (CollectionUtils.isNotEmpty(proxies)) { groupHolder.items = proxies; postProcess(context, groupHolder); groups.add(groupHolder); } } if (LOG.isDebugEnabled()) { for (UpgradeGroupHolder group : groups) { LOG.debug(group.name); int i = 0; for (StageWrapper proxy : group.items) { LOG.debug(" Stage {}", Integer.valueOf(i++)); int j = 0; for (TaskWrapper task : proxy.getTasks()) { LOG.debug(" Task {} {}", Integer.valueOf(j++), task); } } } } return groups; }  UpgradePack suggestUpgradePack(String clusterName, String upgradeFromVersion, String upgradeToVersion,
    Direction direction, UpgradeType upgradeType, String preferredUpgradePackName); List<UpgradeGroupHolder> createSequence(UpgradePack upgradePack,
      UpgradeContext context); Set<Resource> getStageResources(String clusterName, Long requestId, List<Long> stageIds); Resource getTaskResource(String clusterName, Long requestId, Long stageId, Long taskId); @Transactional void putComponentsToUpgradingState(String version,
      Map<Service, Set<ServiceComponent>> targetServices, StackId targetStack); }
UpgradeHelper { public List<UpgradeGroupHolder> createSequence(UpgradePack upgradePack, UpgradeContext context) throws AmbariException { context.setAmbariMetaInfo(m_ambariMetaInfo.get()); Cluster cluster = context.getCluster(); MasterHostResolver mhr = context.getResolver(); Map<String, Map<String, ProcessingComponent>> allTasks = upgradePack.getTasks(); List<UpgradeGroupHolder> groups = new ArrayList<>(); for (Grouping group : upgradePack.getGroups(context.getDirection())) { if (!context.isScoped(group.scope)) { continue; } if (null != group.condition && !group.condition.isSatisfied(context)) { LOG.info("Skipping {} while building upgrade orchestration due to {}", group, group.condition ); continue; } UpgradeGroupHolder groupHolder = new UpgradeGroupHolder(); groupHolder.name = group.name; groupHolder.title = group.title; groupHolder.groupClass = group.getClass(); groupHolder.skippable = group.skippable; groupHolder.supportsAutoSkipOnFailure = group.supportsAutoSkipOnFailure; groupHolder.allowRetry = group.allowRetry; if (context.getDirection().isDowngrade()) { groupHolder.skippable = true; } Task.Type functionName = null; if (group instanceof UpgradeFunction) { functionName = ((UpgradeFunction) group).getFunction(); } if (upgradePack.getType() == UpgradeType.NON_ROLLING) { group.performServiceCheck = false; } StageWrapperBuilder builder = group.getBuilder(); List<UpgradePack.OrderService> services = group.services; if (upgradePack.getType() == UpgradeType.ROLLING) { if (context.getDirection().isDowngrade() && !services.isEmpty()) { List<UpgradePack.OrderService> reverse = new ArrayList<>(services); Collections.reverse(reverse); services = reverse; } } for (UpgradePack.OrderService service : services) { if (!context.isServiceSupported(service.serviceName)) { continue; } if (upgradePack.getType() == UpgradeType.ROLLING && !allTasks.containsKey(service.serviceName)) { continue; } for (String component : service.components) { if (upgradePack.getType() == UpgradeType.ROLLING && !allTasks.get(service.serviceName).containsKey(component)) { continue; } HostsType hostsType = mhr.getMasterAndHosts(service.serviceName, component); if (null == hostsType) { continue; } if (!hostsType.unhealthy.isEmpty()) { context.addUnhealthy(hostsType.unhealthy); } Service svc = cluster.getService(service.serviceName); ProcessingComponent pc = null; if (null == functionName) { pc = allTasks.get(service.serviceName).get(component); } else { if (functionName == Type.STOP) { pc = new ProcessingComponent(); pc.name = component; pc.tasks = new ArrayList<>(); pc.tasks.add(new StopTask()); } else { if (allTasks.containsKey(service.serviceName) && allTasks.get(service.serviceName).containsKey(component)) { pc = allTasks.get(service.serviceName).get(component); } else { pc = new ProcessingComponent(); pc.name = component; pc.tasks = new ArrayList<>(); if (functionName == Type.START) { pc.tasks.add(new StartTask()); } if (functionName == Type.RESTART) { pc.tasks.add(new RestartTask()); } } } } if (pc == null) { LOG.error(MessageFormat.format("Couldn't create a processing component for service {0} and component {1}.", service.serviceName, component)); continue; } setDisplayNames(context, service.serviceName, component); if (service.serviceName.equalsIgnoreCase("HDFS") && component.equalsIgnoreCase("NAMENODE")) { switch (upgradePack.getType()) { case ROLLING: if (!hostsType.hosts.isEmpty() && hostsType.master != null && hostsType.secondary != null) { LinkedHashSet<String> order = new LinkedHashSet<String>(); order.add(hostsType.secondary); order.add(hostsType.master); hostsType.hosts = order; builder.add(context, hostsType, service.serviceName, svc.isClientOnlyService(), pc, null); } else { LOG.warn("Could not orchestrate NameNode. Hosts could not be resolved: hosts={}, active={}, standby={}", StringUtils.join(hostsType.hosts, ','), hostsType.master, hostsType.secondary); } break; case NON_ROLLING: boolean isNameNodeHA = mhr.isNameNodeHA(); if (isNameNodeHA && hostsType.master != null && hostsType.secondary != null) { HostsType ht1 = new HostsType(); LinkedHashSet<String> h1Hosts = new LinkedHashSet<String>(); h1Hosts.add(hostsType.master); ht1.hosts = h1Hosts; Map<String, String> h1Params = new HashMap<String, String>(); h1Params.put("desired_namenode_role", "active"); HostsType ht2 = new HostsType(); LinkedHashSet<String> h2Hosts = new LinkedHashSet<String>(); h2Hosts.add(hostsType.secondary); ht2.hosts = h2Hosts; Map<String, String> h2Params = new HashMap<String, String>(); h2Params.put("desired_namenode_role", "standby"); builder.add(context, ht1, service.serviceName, svc.isClientOnlyService(), pc, h1Params); builder.add(context, ht2, service.serviceName, svc.isClientOnlyService(), pc, h2Params); } else { builder.add(context, hostsType, service.serviceName, svc.isClientOnlyService(), pc, null); } break; } } else { builder.add(context, hostsType, service.serviceName, svc.isClientOnlyService(), pc, null); } } } List<StageWrapper> proxies = builder.build(context); if (CollectionUtils.isNotEmpty(proxies)) { groupHolder.items = proxies; postProcess(context, groupHolder); groups.add(groupHolder); } } if (LOG.isDebugEnabled()) { for (UpgradeGroupHolder group : groups) { LOG.debug(group.name); int i = 0; for (StageWrapper proxy : group.items) { LOG.debug(" Stage {}", Integer.valueOf(i++)); int j = 0; for (TaskWrapper task : proxy.getTasks()) { LOG.debug(" Task {} {}", Integer.valueOf(j++), task); } } } } return groups; }  UpgradePack suggestUpgradePack(String clusterName, String upgradeFromVersion, String upgradeToVersion,
    Direction direction, UpgradeType upgradeType, String preferredUpgradePackName); List<UpgradeGroupHolder> createSequence(UpgradePack upgradePack,
      UpgradeContext context); Set<Resource> getStageResources(String clusterName, Long requestId, List<Long> stageIds); Resource getTaskResource(String clusterName, Long requestId, Long stageId, Long taskId); @Transactional void putComponentsToUpgradingState(String version,
      Map<Service, Set<ServiceComponent>> targetServices, StackId targetStack);  }