@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()); }
@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)); }
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)); } }
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); }
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); }
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; }