UpgradeResourceProvider extends AbstractControllerResourceProvider { @Override public RequestStatus createResources(final Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { Set<Map<String, Object>> requestMaps = request.getProperties(); if (requestMaps.size() > 1) { throw new SystemException("Can only initiate one upgrade per request."); } final Map<String, Object> requestMap = requestMaps.iterator().next(); final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME); final Cluster cluster; try { cluster = getManagementController().getClusters().getCluster(clusterName); } catch (AmbariException e) { throw new NoSuchParentResourceException( String.format("Cluster %s could not be loaded", clusterName)); } if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(), EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) { throw new AuthorizationException("The authenticated user does not have authorization to " + "manage upgrade and downgrade"); } UpgradeEntity entity = createResources(new Command<UpgradeEntity>() { @Override public UpgradeEntity invoke() throws AmbariException, AuthorizationException { final String directionProperty = (String) requestMap.get(UPGRADE_DIRECTION); if (StringUtils.isEmpty(directionProperty)) { throw new AmbariException(String.format("%s is required", UPGRADE_DIRECTION)); } final Direction direction = Direction.valueOf(directionProperty); UpgradeType upgradeType = UpgradeType.ROLLING; if (requestMap.containsKey(UPGRADE_TYPE)) { try { upgradeType = UpgradeType.valueOf(requestMap.get(UPGRADE_TYPE).toString()); } catch (Exception e) { throw new AmbariException(String.format("Property %s has an incorrect value of %s.", UPGRADE_TYPE, requestMap.get(UPGRADE_TYPE))); } } final String version = (String) requestMap.get(UPGRADE_VERSION); final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, upgradeType, direction, version, requestMap); UpgradePack upgradePack = validateRequest(upgradeContext); upgradeContext.setUpgradePack(upgradePack); try { return createUpgrade(upgradeContext); } catch (Exception e) { LOG.error("Error appears during upgrade task submitting", e); clusters.get().invalidate(cluster); throw e; } } }); if (null == entity) { throw new SystemException("Could not load upgrade"); } notifyCreate(Resource.Type.Upgrade, request); Resource res = new ResourceImpl(Resource.Type.Upgrade); res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId()); return new RequestStatusImpl(null, Collections.singleton(res)); } @Inject  UpgradeResourceProvider(@Assisted AmbariManagementController controller); @Override RequestStatus createResources(final Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(final Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); void applyStackAndProcessConfigurations(String stackName, Cluster cluster, String version, Direction direction, UpgradePack upgradePack, String userName); static final String UPGRADE_CLUSTER_NAME; static final String UPGRADE_VERSION; static final String UPGRADE_TYPE; static final String UPGRADE_PACK; static final String UPGRADE_REQUEST_ID; static final String UPGRADE_FROM_VERSION; static final String UPGRADE_TO_VERSION; static final String UPGRADE_DIRECTION; static final String UPGRADE_DOWNGRADE_ALLOWED; static final String UPGRADE_REQUEST_STATUS; static final String UPGRADE_SUSPENDED; static final String UPGRADE_ABORT_REASON; static final String UPGRADE_SKIP_PREREQUISITE_CHECKS; static final String UPGRADE_FAIL_ON_CHECK_WARNINGS; static final String CONST_UPGRADE_GROUP_NAME; static final String CONST_UPGRADE_ITEM_TEXT; static final String CONST_CUSTOM_COMMAND_NAME; }
@Test public void testCreateResourcesWithAutoSkipFailures() throws Exception { Cluster cluster = clusters.getCluster("c1"); Map<String, Object> requestProps = new HashMap<>(); requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.0.0"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test"); requestProps.put(UpgradeResourceProvider.UPGRADE_TYPE, UpgradeType.ROLLING.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_FAILURES, Boolean.TRUE.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_SC_FAILURES, Boolean.TRUE.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_MANUAL_VERIFICATION, Boolean.FALSE.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, Boolean.TRUE.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name()); ResourceProvider upgradeResourceProvider = createProvider(amc); Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null); upgradeResourceProvider.createResources(request); List<UpgradeEntity> upgrades = upgradeDao.findUpgrades(cluster.getClusterId()); assertEquals(1, upgrades.size()); UpgradeEntity entity = upgrades.get(0); assertEquals(cluster.getClusterId(), entity.getClusterId().longValue()); List<UpgradeGroupEntity> upgradeGroups = entity.getUpgradeGroups(); assertEquals(3, upgradeGroups.size()); UpgradeGroupEntity preClusterGroup = upgradeGroups.get(0); assertEquals("PRE_CLUSTER", preClusterGroup.getName()); List<UpgradeItemEntity> preClusterUpgradeItems = preClusterGroup.getItems(); assertEquals(2, preClusterUpgradeItems.size()); assertEquals("Foo", parseSingleMessage(preClusterUpgradeItems.get(0).getText())); assertEquals("Foo", parseSingleMessage(preClusterUpgradeItems.get(1).getText())); UpgradeGroupEntity zookeeperGroup = upgradeGroups.get(1); assertEquals("ZOOKEEPER", zookeeperGroup.getName()); List<UpgradeItemEntity> zookeeperUpgradeItems = zookeeperGroup.getItems(); assertEquals(5, zookeeperUpgradeItems.size()); assertEquals("This is a manual task with a placeholder of placeholder-rendered-properly", parseSingleMessage(zookeeperUpgradeItems.get(0).getText())); assertEquals("Restarting ZooKeeper Server on h1", zookeeperUpgradeItems.get(1).getText()); assertEquals("Updating configuration zookeeper-newconfig", zookeeperUpgradeItems.get(2).getText()); assertEquals("Service Check ZooKeeper", zookeeperUpgradeItems.get(3).getText()); assertTrue(zookeeperUpgradeItems.get(4).getText().contains("There are failures that were automatically skipped")); UpgradeItemEntity skippedFailureCheck = zookeeperUpgradeItems.get(zookeeperUpgradeItems.size() - 1); skippedFailureCheck.getTasks().contains(AutoSkipFailedSummaryAction.class.getName()); UpgradeGroupEntity postClusterGroup = upgradeGroups.get(2); assertEquals("POST_CLUSTER", postClusterGroup.getName()); List<UpgradeItemEntity> postClusterUpgradeItems = postClusterGroup.getItems(); assertEquals(2, postClusterUpgradeItems.size()); assertEquals("Please confirm you are ready to finalize", parseSingleMessage(postClusterUpgradeItems.get(0).getText())); assertEquals("Save Cluster State", postClusterUpgradeItems.get(1).getText()); }
@Test public void testCreateResourcesWithAutoSkipManualVerification() throws Exception { Cluster cluster = clusters.getCluster("c1"); Map<String, Object> requestProps = new HashMap<>(); requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.0.0"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test"); requestProps.put(UpgradeResourceProvider.UPGRADE_TYPE, UpgradeType.ROLLING.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_MANUAL_VERIFICATION, Boolean.TRUE.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, Boolean.TRUE.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name()); ResourceProvider upgradeResourceProvider = createProvider(amc); Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null); upgradeResourceProvider.createResources(request); List<UpgradeEntity> upgrades = upgradeDao.findUpgrades(cluster.getClusterId()); assertEquals(1, upgrades.size()); UpgradeEntity entity = upgrades.get(0); assertEquals(cluster.getClusterId(), entity.getClusterId().longValue()); List<UpgradeGroupEntity> upgradeGroups = entity.getUpgradeGroups(); assertEquals(2, upgradeGroups.size()); UpgradeGroupEntity zookeeperGroup = upgradeGroups.get(0); assertEquals("ZOOKEEPER", zookeeperGroup.getName()); List<UpgradeItemEntity> zookeeperUpgradeItems = zookeeperGroup.getItems(); assertEquals(3, zookeeperUpgradeItems.size()); assertEquals("Restarting ZooKeeper Server on h1", zookeeperUpgradeItems.get(0).getText()); assertEquals("Updating configuration zookeeper-newconfig", zookeeperUpgradeItems.get(1).getText()); assertEquals("Service Check ZooKeeper", zookeeperUpgradeItems.get(2).getText()); UpgradeGroupEntity postClusterGroup = upgradeGroups.get(1); assertEquals("POST_CLUSTER", postClusterGroup.getName()); List<UpgradeItemEntity> postClusterUpgradeItems = postClusterGroup.getItems(); assertEquals(1, postClusterUpgradeItems.size()); assertEquals("Save Cluster State", postClusterUpgradeItems.get(0).getText()); }
@Test public void testCreateResourcesWithAutoSkipAll() throws Exception { Cluster cluster = clusters.getCluster("c1"); Map<String, Object> requestProps = new HashMap<>(); requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.0.0"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test"); requestProps.put(UpgradeResourceProvider.UPGRADE_TYPE, UpgradeType.ROLLING.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_FAILURES, Boolean.TRUE.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_SC_FAILURES, Boolean.TRUE.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_MANUAL_VERIFICATION, Boolean.TRUE.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, Boolean.TRUE.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name()); ResourceProvider upgradeResourceProvider = createProvider(amc); Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null); upgradeResourceProvider.createResources(request); List<UpgradeEntity> upgrades = upgradeDao.findUpgrades(cluster.getClusterId()); assertEquals(1, upgrades.size()); UpgradeEntity entity = upgrades.get(0); assertEquals(cluster.getClusterId(), entity.getClusterId().longValue()); List<UpgradeGroupEntity> upgradeGroups = entity.getUpgradeGroups(); assertEquals(2, upgradeGroups.size()); UpgradeGroupEntity zookeeperGroup = upgradeGroups.get(0); assertEquals("ZOOKEEPER", zookeeperGroup.getName()); List<UpgradeItemEntity> zookeeperUpgradeItems = zookeeperGroup.getItems(); assertEquals(4, zookeeperUpgradeItems.size()); assertEquals("Restarting ZooKeeper Server on h1", zookeeperUpgradeItems.get(0).getText()); assertEquals("Updating configuration zookeeper-newconfig", zookeeperUpgradeItems.get(1).getText()); assertEquals("Service Check ZooKeeper", zookeeperUpgradeItems.get(2).getText()); assertTrue(zookeeperUpgradeItems.get(3).getText().contains("There are failures that were automatically skipped")); UpgradeItemEntity skippedFailureCheck = zookeeperUpgradeItems.get(zookeeperUpgradeItems.size() - 1); skippedFailureCheck.getTasks().contains(AutoSkipFailedSummaryAction.class.getName()); UpgradeGroupEntity postClusterGroup = upgradeGroups.get(1); assertEquals("POST_CLUSTER", postClusterGroup.getName()); List<UpgradeItemEntity> postClusterUpgradeItems = postClusterGroup.getItems(); assertEquals(1, postClusterUpgradeItems.size()); assertEquals("Save Cluster State", postClusterUpgradeItems.get(0).getText()); }
@Test public void testCreatePartialDowngrade() throws Exception { clusters.addHost("h2"); Host host = clusters.getHost("h2"); Map<String, String> hostAttributes = new HashMap<>(); hostAttributes.put("os_family", "redhat"); hostAttributes.put("os_release_version", "6.3"); host.setHostAttributes(hostAttributes); clusters.mapHostToCluster("h2", "c1"); Cluster cluster = clusters.getCluster("c1"); Service service = cluster.getService("ZOOKEEPER"); ServiceComponent component = service.getServiceComponent("ZOOKEEPER_SERVER"); ServiceComponentHost sch = component.addServiceComponentHost("h2"); sch.setVersion("2.2.2.2"); List<UpgradeEntity> upgrades = upgradeDao.findUpgrades(cluster.getClusterId()); assertEquals(0, upgrades.size()); RequestEntity requestEntity = new RequestEntity(); requestEntity.setRequestId(2L); requestEntity.setClusterId(cluster.getClusterId()); requestEntity.setStages(new ArrayList<StageEntity>()); requestDao.create(requestEntity); UpgradeEntity upgradeEntity = new UpgradeEntity(); upgradeEntity.setClusterId(cluster.getClusterId()); upgradeEntity.setDirection(Direction.UPGRADE); upgradeEntity.setFromVersion("2.1.1.1"); upgradeEntity.setToVersion("2.2.2.2"); upgradeEntity.setUpgradePackage("upgrade_test"); upgradeEntity.setUpgradeType(UpgradeType.ROLLING); upgradeEntity.setRequestId(2L); upgradeDao.create(upgradeEntity); upgrades = upgradeDao.findUpgrades(cluster.getClusterId()); assertEquals(1, upgrades.size()); UpgradeEntity lastUpgrade = upgradeDao.findLastUpgradeForCluster(cluster.getClusterId(), Direction.UPGRADE); assertNotNull(lastUpgrade); Map<String, Object> requestProps = new HashMap<>(); requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.1.1.1"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test"); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true"); requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.DOWNGRADE.name()); Map<String, String> requestInfoProperties = new HashMap<>(); ResourceProvider upgradeResourceProvider = createProvider(amc); Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), requestInfoProperties); upgradeResourceProvider.createResources(request); upgrades = upgradeDao.findUpgrades(cluster.getClusterId()); assertEquals(2, upgrades.size()); UpgradeEntity downgrade = upgrades.get(1); assertEquals(cluster.getClusterId(), downgrade.getClusterId().longValue()); List<UpgradeGroupEntity> upgradeGroups = downgrade.getUpgradeGroups(); assertEquals(3, upgradeGroups.size()); UpgradeGroupEntity group = upgradeGroups.get(1); assertEquals("ZOOKEEPER", group.getName()); assertEquals(4, group.getItems().size()); }
@Test public void testDowngradeToBase() throws Exception { Cluster cluster = clusters.getCluster("c1"); Map<String, Object> requestProps = new HashMap<>(); requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.1.1.1"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test"); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true"); requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name()); ResourceProvider upgradeResourceProvider = createProvider(amc); Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null); upgradeResourceProvider.createResources(request); List<UpgradeEntity> upgrades = upgradeDao.findUpgrades(cluster.getClusterId()); assertEquals(1, upgrades.size()); UpgradeEntity upgrade = upgrades.get(0); abortUpgrade(upgrade.getRequestId()); requestProps = new HashMap<>(); requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test"); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true"); request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null); try { upgradeResourceProvider.createResources(request); Assert.fail("Expected an exception going downgrade with no upgrade pack"); } catch (Exception e) { } requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.0.0"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test"); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true"); requestProps.put(UpgradeResourceProvider.UPGRADE_FROM_VERSION, "2.1.1.0"); requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.DOWNGRADE.name()); Map<String, String> requestInfoProperties = new HashMap<>(); request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), requestInfoProperties); RequestStatus status = upgradeResourceProvider.createResources(request); assertEquals(1, status.getAssociatedResources().size()); Resource r = status.getAssociatedResources().iterator().next(); String id = r.getPropertyValue("Upgrade/request_id").toString(); UpgradeEntity entity = upgradeDao.findUpgrade(Long.parseLong(id)); assertNotNull(entity); assertEquals("2.1.1.0", entity.getFromVersion()); assertEquals("2.2.0.0", entity.getToVersion()); assertEquals(Direction.DOWNGRADE, entity.getDirection()); StageDAO dao = injector.getInstance(StageDAO.class); List<StageEntity> stages = dao.findByRequestId(entity.getRequestId()); Gson gson = new Gson(); for (StageEntity se : stages) { Map<String, String> map = gson.<Map<String, String>>fromJson(se.getCommandParamsStage(), Map.class); assertTrue(map.containsKey("upgrade_direction")); assertEquals("downgrade", map.get("upgrade_direction")); } }
@Test public void testNotFullDowngrade() throws Exception { Cluster cluster = clusters.getCluster("c1"); Service service = cluster.addService("HIVE"); service.setDesiredStackVersion(cluster.getDesiredStackVersion()); ServiceComponent component = service.addServiceComponent("HIVE_SERVER"); ServiceComponentHost sch = component.addServiceComponentHost("h1"); sch.setVersion("2.1.1.0"); Map<String, Object> requestProps = new HashMap<>(); requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.0.0"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_nonrolling_new_stack"); requestProps.put(UpgradeResourceProvider.UPGRADE_TYPE, "NON_ROLLING"); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true"); requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name()); ResourceProvider upgradeResourceProvider = createProvider(amc); Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null); upgradeResourceProvider.createResources(request); List<UpgradeEntity> upgrades = upgradeDao.findUpgrades(cluster.getClusterId()); assertEquals(1, upgrades.size()); UpgradeEntity upgrade = upgrades.get(0); List<UpgradeGroupEntity> groups = upgrade.getUpgradeGroups(); boolean isHiveGroupFound = false; boolean isZKGroupFound = false; for (UpgradeGroupEntity group: groups) { if (group.getName().equalsIgnoreCase("hive")) { isHiveGroupFound = true; } else if (group.getName().equalsIgnoreCase("zookeeper")){ isZKGroupFound = true; } } assertTrue(isHiveGroupFound); assertTrue(isZKGroupFound); isHiveGroupFound = false; isZKGroupFound = false; sch.setVersion("2.2.0.0"); abortUpgrade(upgrade.getRequestId()); StackId stackId = new StackId("HDP", "2.2.0"); cluster.setDesiredStackVersion(stackId, true); requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.1.1.0"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_nonrolling_new_stack"); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true"); requestProps.put(UpgradeResourceProvider.UPGRADE_FROM_VERSION, "2.2.0.0"); requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.DOWNGRADE.name()); Map<String, String> requestInfoProperties = new HashMap<>(); request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), requestInfoProperties); RequestStatus status = upgradeResourceProvider.createResources(request); UpgradeEntity upgradeEntity = upgradeDao.findUpgradeByRequestId(getRequestId(status)); for (UpgradeGroupEntity group: upgradeEntity.getUpgradeGroups()) { if (group.getName().equalsIgnoreCase("hive")) { isHiveGroupFound = true; } else if (group.getName().equalsIgnoreCase("zookeeper")){ isZKGroupFound = true; } } assertTrue(isHiveGroupFound); assertFalse(isZKGroupFound); }
@Test public void testDirectionUpgrade() throws Exception { Cluster cluster = clusters.getCluster("c1"); StackEntity stackEntity = stackDAO.find("HDP", "2.1.1"); RepositoryVersionEntity repoVersionEntity = new RepositoryVersionEntity(); repoVersionEntity.setDisplayName("My New Version 3"); repoVersionEntity.setOperatingSystems(""); repoVersionEntity.setStack(stackEntity); repoVersionEntity.setVersion("2.2.2.3"); repoVersionDao.create(repoVersionEntity); Map<String, Object> requestProps = new HashMap<>(); requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.2.3"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_direction"); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true"); requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name()); ResourceProvider upgradeResourceProvider = createProvider(amc); Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null); upgradeResourceProvider.createResources(request); List<UpgradeEntity> upgrades = upgradeDao.findUpgrades(cluster.getClusterId()); assertEquals(1, upgrades.size()); UpgradeEntity upgrade = upgrades.get(0); Long id = upgrade.getRequestId(); assertEquals(3, upgrade.getUpgradeGroups().size()); UpgradeGroupEntity group = upgrade.getUpgradeGroups().get(2); Assert.assertEquals("POST_CLUSTER", group.getName()); Assert.assertTrue(!group.getItems().isEmpty()); for (UpgradeItemEntity item : group.getItems()) { Assert.assertFalse(item.getText().toLowerCase().contains("downgrade")); } abortUpgrade(upgrade.getRequestId()); requestProps.clear(); requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_direction"); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true"); requestProps.put(UpgradeResourceProvider.UPGRADE_FROM_VERSION, "2.2.2.3"); requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.DOWNGRADE.name()); request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null); upgradeResourceProvider.createResources(request); upgrades = upgradeDao.findUpgrades(cluster.getClusterId()); assertEquals(2, upgrades.size()); upgrade = null; for (UpgradeEntity u : upgrades) { if (!u.getRequestId().equals(id)) { upgrade = u; } } assertNotNull(upgrade); assertEquals("Downgrade groups reduced from 3 to 2", 2, upgrade.getUpgradeGroups().size()); group = upgrade.getUpgradeGroups().get(1); assertEquals("Execution items increased from 1 to 2", 2, group.getItems().size()); }
@Test public void testCreateCrossStackUpgrade() throws Exception { Cluster cluster = clusters.getCluster("c1"); StackId oldStack = cluster.getDesiredStackVersion(); for (Service s : cluster.getServices().values()) { assertEquals(oldStack, s.getDesiredStackVersion()); for (ServiceComponent sc : s.getServiceComponents().values()) { assertEquals(oldStack, sc.getDesiredStackVersion()); for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) { assertEquals(oldStack, sch.getDesiredStackVersion()); } } } Config config = configFactory.createNew(cluster, "zoo.cfg", "abcdefg", Collections.singletonMap("a", "b"), null); cluster.addDesiredConfig("admin", Collections.singleton(config)); Map<String, Object> requestProps = new HashMap<>(); requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.0.0"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test"); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true"); requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name()); ResourceProvider upgradeResourceProvider = createProvider(amc); Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null); upgradeResourceProvider.createResources(request); List<UpgradeEntity> upgrades = upgradeDao.findUpgrades(cluster.getClusterId()); assertEquals(1, upgrades.size()); UpgradeEntity upgrade = upgrades.get(0); assertEquals(3, upgrade.getUpgradeGroups().size()); UpgradeGroupEntity group = upgrade.getUpgradeGroups().get(2); assertEquals(2, group.getItems().size()); group = upgrade.getUpgradeGroups().get(0); assertEquals(2, group.getItems().size()); assertTrue(cluster.getDesiredConfigs().containsKey("zoo.cfg")); StackId newStack = cluster.getDesiredStackVersion(); assertFalse(oldStack.equals(newStack)); for (Service s : cluster.getServices().values()) { assertEquals(newStack, s.getDesiredStackVersion()); for (ServiceComponent sc : s.getServiceComponents().values()) { assertEquals(newStack, sc.getDesiredStackVersion()); for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) { assertEquals(newStack, sch.getDesiredStackVersion()); } } } }
@Test public void testRollback() throws Exception { Cluster cluster = clusters.getCluster("c1"); Map<String, Object> requestProps = new HashMap<>(); requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.0.0"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test"); requestProps.put(UpgradeResourceProvider.UPGRADE_TYPE, UpgradeType.ROLLING.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_MANUAL_VERIFICATION, Boolean.FALSE.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, Boolean.TRUE.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name()); UpgradeResourceProvider upgradeResourceProvider = createProvider(amc); UpgradeResourceProvider.s_upgradeDAO = null; try { Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null); upgradeResourceProvider.createResources(request); Assert.fail("Expected a NullPointerException"); } catch (NullPointerException npe) { } List<UpgradeEntity> upgrades = upgradeDao.findUpgrades(cluster.getClusterId()); assertEquals(0, upgrades.size()); List<Long> requestIds = requestDao.findAllRequestIds(1, true, cluster.getClusterId()); assertEquals(0, requestIds.size()); }
@Test() public void testCreateHostOrderedUpgradeThrowsExceptions() throws Exception { Map<String, Object> requestProps = new HashMap<>(); requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.0.0"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test_host_ordered"); requestProps.put(UpgradeResourceProvider.UPGRADE_TYPE, UpgradeType.HOST_ORDERED.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, Boolean.TRUE.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name()); ResourceProvider upgradeResourceProvider = createProvider(amc); Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null); try { upgradeResourceProvider.createResources(request); Assert.fail("The request should have failed due to the missing Upgrade/host_order property"); } catch( SystemException systemException ){ } Set<Map<String, List<String>>> hostsOrder = new LinkedHashSet<>(); Map<String, List<String>> hostGrouping = new HashMap<>(); hostGrouping.put("hosts", Lists.newArrayList("invalid-host")); hostsOrder.add(hostGrouping); requestProps.put(UpgradeResourceProvider.UPGRADE_HOST_ORDERED_HOSTS, hostsOrder); try { upgradeResourceProvider.createResources(request); Assert.fail("The request should have failed due to invalid hosts"); } catch (SystemException systemException) { } hostsOrder = new LinkedHashSet<>(); hostGrouping = new HashMap<>(); hostGrouping.put("hosts", Lists.newArrayList("h1")); hostsOrder.add(hostGrouping); requestProps.put(UpgradeResourceProvider.UPGRADE_HOST_ORDERED_HOSTS, hostsOrder); upgradeResourceProvider.createResources(request); }
@Test public void testCreateUpgradeDowngradeCycleAdvertisingVersion() throws Exception { Cluster cluster = clusters.getCluster("c1"); Service service = cluster.addService("STORM"); service.setDesiredStackVersion(cluster.getDesiredStackVersion()); ServiceComponent component = service.addServiceComponent("DRPC_SERVER"); ServiceComponentHost sch = component.addServiceComponentHost("h1"); sch.setVersion("2.1.1.0"); ResourceProvider upgradeResourceProvider = createProvider(amc); Map<String, Object> requestProps = new HashMap<>(); requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.0.0"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test"); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true"); requestProps.put(UpgradeResourceProvider.UPGRADE_FROM_VERSION, "2.1.1.0"); requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name()); Map<String, String> requestInfoProperties = new HashMap<>(); Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), requestInfoProperties); RequestStatus status = upgradeResourceProvider.createResources(request); assertEquals(1, status.getAssociatedResources().size()); Resource r = status.getAssociatedResources().iterator().next(); String id = r.getPropertyValue("Upgrade/request_id").toString(); component = service.getServiceComponent("DRPC_SERVER"); assertNotNull(component); assertEquals("2.2.0.0", component.getDesiredVersion()); ServiceComponentHost hostComponent = component.getServiceComponentHost("h1"); assertEquals(UpgradeState.IN_PROGRESS, hostComponent.getUpgradeState()); abortUpgrade(Long.parseLong(id)); requestProps.clear(); requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.1.1.0"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test"); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true"); requestProps.put(UpgradeResourceProvider.UPGRADE_FROM_VERSION, "2.2.0.0"); requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.DOWNGRADE.name()); request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), requestInfoProperties); status = upgradeResourceProvider.createResources(request); component = service.getServiceComponent("DRPC_SERVER"); assertNotNull(component); assertEquals("UNKNOWN", component.getDesiredVersion()); hostComponent = component.getServiceComponentHost("h1"); assertEquals(UpgradeState.NONE, hostComponent.getUpgradeState()); assertEquals("UNKNOWN", hostComponent.getVersion()); }
@Test() public void testEmptyGroupingsDoNotSkipStageIds() throws Exception { StageDAO stageDao = injector.getInstance(StageDAO.class); Assert.assertEquals(0, stageDao.findAll().size()); Cluster cluster = clusters.getCluster("c1"); List<ServiceComponentHost> schs = cluster.getServiceComponentHosts("h1"); for (ServiceComponentHost sch : schs) { if (sch.isClientComponent()) { continue; } cluster.removeServiceComponentHost(sch); } Set<Map<String, List<String>>> hostsOrder = new LinkedHashSet<>(); Map<String, List<String>> hostGrouping = new HashMap<>(); hostGrouping = new HashMap<>(); hostGrouping.put("hosts", Lists.newArrayList("h1")); hostsOrder.add(hostGrouping); Map<String, Object> requestProps = new HashMap<>(); requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.0.0"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test_host_ordered"); requestProps.put(UpgradeResourceProvider.UPGRADE_TYPE, UpgradeType.HOST_ORDERED.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS,Boolean.TRUE.toString()); requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name()); requestProps.put(UpgradeResourceProvider.UPGRADE_HOST_ORDERED_HOSTS, hostsOrder); ResourceProvider upgradeResourceProvider = createProvider(amc); Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null); upgradeResourceProvider.createResources(request); List<StageEntity> stages = stageDao.findByRequestId(cluster.getUpgradeEntity().getRequestId()); Assert.assertEquals(3, stages.size()); long expectedStageId = 1L; for (StageEntity stage : stages) { Assert.assertEquals(expectedStageId++, stage.getStageId().longValue()); } }