@Test public void testGetResources() throws Exception { RequestStatus status = testCreateResources(); Set<Resource> createdResources = status.getAssociatedResources(); assertEquals(1, createdResources.size()); Resource res = createdResources.iterator().next(); Long id = (Long) res.getPropertyValue("Upgrade/request_id"); assertNotNull(id); assertEquals(Long.valueOf(1), id); Set<String> propertyIds = new HashSet<>(); propertyIds.add("Upgrade"); Predicate predicate = new PredicateBuilder() .property(UpgradeResourceProvider.UPGRADE_REQUEST_ID).equals("1").and() .property(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME).equals("c1") .toPredicate(); Request request = PropertyHelper.getReadRequest(propertyIds); ResourceProvider upgradeResourceProvider = createProvider(amc); Set<Resource> resources = upgradeResourceProvider.getResources(request, predicate); assertEquals(1, resources.size()); res = resources.iterator().next(); assertNotNull(res.getPropertyValue("Upgrade/progress_percent")); assertNotNull(res.getPropertyValue(UpgradeResourceProvider.UPGRADE_DIRECTION)); assertEquals(Direction.UPGRADE, res.getPropertyValue(UpgradeResourceProvider.UPGRADE_DIRECTION)); assertEquals(false, res.getPropertyValue(UpgradeResourceProvider.UPGRADE_SKIP_FAILURES)); assertEquals(false, res.getPropertyValue(UpgradeResourceProvider.UPGRADE_SKIP_SC_FAILURES)); assertEquals(UpgradeType.ROLLING, res.getPropertyValue(UpgradeResourceProvider.UPGRADE_TYPE)); propertyIds.clear(); propertyIds.add("UpgradeGroup"); predicate = new PredicateBuilder() .property(UpgradeGroupResourceProvider.UPGRADE_REQUEST_ID).equals("1").and() .property(UpgradeGroupResourceProvider.UPGRADE_CLUSTER_NAME).equals("c1") .toPredicate(); request = PropertyHelper.getReadRequest(propertyIds); ResourceProvider upgradeGroupResourceProvider = new UpgradeGroupResourceProvider(amc); resources = upgradeGroupResourceProvider.getResources(request, predicate); assertEquals(3, resources.size()); res = resources.iterator().next(); assertNotNull(res.getPropertyValue("UpgradeGroup/status")); assertNotNull(res.getPropertyValue("UpgradeGroup/group_id")); assertNotNull(res.getPropertyValue("UpgradeGroup/total_task_count")); assertNotNull(res.getPropertyValue("UpgradeGroup/in_progress_task_count")); assertNotNull(res.getPropertyValue("UpgradeGroup/completed_task_count")); propertyIds.clear(); propertyIds.add("UpgradeItem"); predicate = new PredicateBuilder() .property(UpgradeItemResourceProvider.UPGRADE_GROUP_ID).equals("1").and() .property(UpgradeItemResourceProvider.UPGRADE_REQUEST_ID).equals("1").and() .property(UpgradeItemResourceProvider.UPGRADE_CLUSTER_NAME).equals("c1") .toPredicate(); request = PropertyHelper.getReadRequest(propertyIds); ResourceProvider upgradeItemResourceProvider = new UpgradeItemResourceProvider(amc); resources = upgradeItemResourceProvider.getResources(request, predicate); assertEquals(2, resources.size()); res = resources.iterator().next(); assertNotNull(res.getPropertyValue("UpgradeItem/status")); propertyIds.clear(); propertyIds.add("UpgradeItem"); predicate = new PredicateBuilder() .property(UpgradeItemResourceProvider.UPGRADE_GROUP_ID).equals("3").and() .property(UpgradeItemResourceProvider.UPGRADE_REQUEST_ID).equals("1").and() .property(UpgradeItemResourceProvider.UPGRADE_CLUSTER_NAME).equals("c1") .toPredicate(); request = PropertyHelper.getReadRequest(propertyIds); upgradeItemResourceProvider = new UpgradeItemResourceProvider(amc); resources = upgradeItemResourceProvider.getResources(request, predicate); assertEquals(2, resources.size()); res = resources.iterator().next(); assertEquals("Confirm Finalize", res.getPropertyValue("UpgradeItem/context")); String msgStr = res.getPropertyValue("UpgradeItem/text").toString(); JsonParser parser = new JsonParser(); JsonArray msgArray = (JsonArray) parser.parse(msgStr); JsonObject msg = (JsonObject) msgArray.get(0); assertTrue(msg.get("message").getAsString().startsWith("Please confirm")); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new HashSet<>(); Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate); for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { String clusterName = (String) propertyMap.get(UPGRADE_CLUSTER_NAME); if (null == clusterName || clusterName.isEmpty()) { throw new IllegalArgumentException( "The cluster name is required when querying for upgrades"); } Cluster cluster; try { cluster = getManagementController().getClusters().getCluster(clusterName); } catch (AmbariException e) { throw new NoSuchResourceException( String.format("Cluster %s could not be loaded", clusterName)); } List<UpgradeEntity> upgrades = new ArrayList<>(); String upgradeIdStr = (String) propertyMap.get(UPGRADE_REQUEST_ID); if (null != upgradeIdStr) { UpgradeEntity upgrade = s_upgradeDAO.findUpgradeByRequestId(Long.valueOf(upgradeIdStr)); if (null != upgrade) { upgrades.add(upgrade); } } else { upgrades = s_upgradeDAO.findUpgrades(cluster.getClusterId()); } for (UpgradeEntity entity : upgrades) { Resource r = toResource(entity, clusterName, requestPropertyIds); results.add(r); RequestEntity rentity = s_requestDAO.findByPK(entity.getRequestId()); setResourceProperty(r, REQUEST_CONTEXT_ID, rentity.getRequestContext(), requestPropertyIds); setResourceProperty(r, REQUEST_TYPE_ID, rentity.getRequestType(), requestPropertyIds); setResourceProperty(r, REQUEST_CREATE_TIME_ID, rentity.getCreateTime(), requestPropertyIds); setResourceProperty(r, REQUEST_START_TIME_ID, rentity.getStartTime(), requestPropertyIds); setResourceProperty(r, REQUEST_END_TIME_ID, rentity.getEndTime(), requestPropertyIds); setResourceProperty(r, REQUEST_EXCLUSIVE_ID, rentity.isExclusive(), requestPropertyIds); Map<Long, HostRoleCommandStatusSummaryDTO> summary = s_hostRoleCommandDAO.findAggregateCounts( entity.getRequestId()); CalculatedStatus calc = CalculatedStatus.statusFromStageSummary(summary, summary.keySet()); setResourceProperty(r, REQUEST_STATUS_PROPERTY_ID, calc.getStatus(), requestPropertyIds); setResourceProperty(r, REQUEST_PROGRESS_PERCENT_ID, calc.getPercent(), requestPropertyIds); } } return results; }
UpgradeResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new HashSet<>(); Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate); for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { String clusterName = (String) propertyMap.get(UPGRADE_CLUSTER_NAME); if (null == clusterName || clusterName.isEmpty()) { throw new IllegalArgumentException( "The cluster name is required when querying for upgrades"); } Cluster cluster; try { cluster = getManagementController().getClusters().getCluster(clusterName); } catch (AmbariException e) { throw new NoSuchResourceException( String.format("Cluster %s could not be loaded", clusterName)); } List<UpgradeEntity> upgrades = new ArrayList<>(); String upgradeIdStr = (String) propertyMap.get(UPGRADE_REQUEST_ID); if (null != upgradeIdStr) { UpgradeEntity upgrade = s_upgradeDAO.findUpgradeByRequestId(Long.valueOf(upgradeIdStr)); if (null != upgrade) { upgrades.add(upgrade); } } else { upgrades = s_upgradeDAO.findUpgrades(cluster.getClusterId()); } for (UpgradeEntity entity : upgrades) { Resource r = toResource(entity, clusterName, requestPropertyIds); results.add(r); RequestEntity rentity = s_requestDAO.findByPK(entity.getRequestId()); setResourceProperty(r, REQUEST_CONTEXT_ID, rentity.getRequestContext(), requestPropertyIds); setResourceProperty(r, REQUEST_TYPE_ID, rentity.getRequestType(), requestPropertyIds); setResourceProperty(r, REQUEST_CREATE_TIME_ID, rentity.getCreateTime(), requestPropertyIds); setResourceProperty(r, REQUEST_START_TIME_ID, rentity.getStartTime(), requestPropertyIds); setResourceProperty(r, REQUEST_END_TIME_ID, rentity.getEndTime(), requestPropertyIds); setResourceProperty(r, REQUEST_EXCLUSIVE_ID, rentity.isExclusive(), requestPropertyIds); Map<Long, HostRoleCommandStatusSummaryDTO> summary = s_hostRoleCommandDAO.findAggregateCounts( entity.getRequestId()); CalculatedStatus calc = CalculatedStatus.statusFromStageSummary(summary, summary.keySet()); setResourceProperty(r, REQUEST_STATUS_PROPERTY_ID, calc.getStatus(), requestPropertyIds); setResourceProperty(r, REQUEST_PROGRESS_PERCENT_ID, calc.getPercent(), requestPropertyIds); } } return results; } }
UpgradeResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new HashSet<>(); Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate); for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { String clusterName = (String) propertyMap.get(UPGRADE_CLUSTER_NAME); if (null == clusterName || clusterName.isEmpty()) { throw new IllegalArgumentException( "The cluster name is required when querying for upgrades"); } Cluster cluster; try { cluster = getManagementController().getClusters().getCluster(clusterName); } catch (AmbariException e) { throw new NoSuchResourceException( String.format("Cluster %s could not be loaded", clusterName)); } List<UpgradeEntity> upgrades = new ArrayList<>(); String upgradeIdStr = (String) propertyMap.get(UPGRADE_REQUEST_ID); if (null != upgradeIdStr) { UpgradeEntity upgrade = s_upgradeDAO.findUpgradeByRequestId(Long.valueOf(upgradeIdStr)); if (null != upgrade) { upgrades.add(upgrade); } } else { upgrades = s_upgradeDAO.findUpgrades(cluster.getClusterId()); } for (UpgradeEntity entity : upgrades) { Resource r = toResource(entity, clusterName, requestPropertyIds); results.add(r); RequestEntity rentity = s_requestDAO.findByPK(entity.getRequestId()); setResourceProperty(r, REQUEST_CONTEXT_ID, rentity.getRequestContext(), requestPropertyIds); setResourceProperty(r, REQUEST_TYPE_ID, rentity.getRequestType(), requestPropertyIds); setResourceProperty(r, REQUEST_CREATE_TIME_ID, rentity.getCreateTime(), requestPropertyIds); setResourceProperty(r, REQUEST_START_TIME_ID, rentity.getStartTime(), requestPropertyIds); setResourceProperty(r, REQUEST_END_TIME_ID, rentity.getEndTime(), requestPropertyIds); setResourceProperty(r, REQUEST_EXCLUSIVE_ID, rentity.isExclusive(), requestPropertyIds); Map<Long, HostRoleCommandStatusSummaryDTO> summary = s_hostRoleCommandDAO.findAggregateCounts( entity.getRequestId()); CalculatedStatus calc = CalculatedStatus.statusFromStageSummary(summary, summary.keySet()); setResourceProperty(r, REQUEST_STATUS_PROPERTY_ID, calc.getStatus(), requestPropertyIds); setResourceProperty(r, REQUEST_PROGRESS_PERCENT_ID, calc.getPercent(), requestPropertyIds); } } return results; } @Inject  UpgradeResourceProvider(@Assisted AmbariManagementController controller); }
UpgradeResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new HashSet<>(); Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate); for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { String clusterName = (String) propertyMap.get(UPGRADE_CLUSTER_NAME); if (null == clusterName || clusterName.isEmpty()) { throw new IllegalArgumentException( "The cluster name is required when querying for upgrades"); } Cluster cluster; try { cluster = getManagementController().getClusters().getCluster(clusterName); } catch (AmbariException e) { throw new NoSuchResourceException( String.format("Cluster %s could not be loaded", clusterName)); } List<UpgradeEntity> upgrades = new ArrayList<>(); String upgradeIdStr = (String) propertyMap.get(UPGRADE_REQUEST_ID); if (null != upgradeIdStr) { UpgradeEntity upgrade = s_upgradeDAO.findUpgradeByRequestId(Long.valueOf(upgradeIdStr)); if (null != upgrade) { upgrades.add(upgrade); } } else { upgrades = s_upgradeDAO.findUpgrades(cluster.getClusterId()); } for (UpgradeEntity entity : upgrades) { Resource r = toResource(entity, clusterName, requestPropertyIds); results.add(r); RequestEntity rentity = s_requestDAO.findByPK(entity.getRequestId()); setResourceProperty(r, REQUEST_CONTEXT_ID, rentity.getRequestContext(), requestPropertyIds); setResourceProperty(r, REQUEST_TYPE_ID, rentity.getRequestType(), requestPropertyIds); setResourceProperty(r, REQUEST_CREATE_TIME_ID, rentity.getCreateTime(), requestPropertyIds); setResourceProperty(r, REQUEST_START_TIME_ID, rentity.getStartTime(), requestPropertyIds); setResourceProperty(r, REQUEST_END_TIME_ID, rentity.getEndTime(), requestPropertyIds); setResourceProperty(r, REQUEST_EXCLUSIVE_ID, rentity.isExclusive(), requestPropertyIds); Map<Long, HostRoleCommandStatusSummaryDTO> summary = s_hostRoleCommandDAO.findAggregateCounts( entity.getRequestId()); CalculatedStatus calc = CalculatedStatus.statusFromStageSummary(summary, summary.keySet()); setResourceProperty(r, REQUEST_STATUS_PROPERTY_ID, calc.getStatus(), requestPropertyIds); setResourceProperty(r, REQUEST_PROGRESS_PERCENT_ID, calc.getPercent(), requestPropertyIds); } } return results; } @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 Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new HashSet<>(); Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate); for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { String clusterName = (String) propertyMap.get(UPGRADE_CLUSTER_NAME); if (null == clusterName || clusterName.isEmpty()) { throw new IllegalArgumentException( "The cluster name is required when querying for upgrades"); } Cluster cluster; try { cluster = getManagementController().getClusters().getCluster(clusterName); } catch (AmbariException e) { throw new NoSuchResourceException( String.format("Cluster %s could not be loaded", clusterName)); } List<UpgradeEntity> upgrades = new ArrayList<>(); String upgradeIdStr = (String) propertyMap.get(UPGRADE_REQUEST_ID); if (null != upgradeIdStr) { UpgradeEntity upgrade = s_upgradeDAO.findUpgradeByRequestId(Long.valueOf(upgradeIdStr)); if (null != upgrade) { upgrades.add(upgrade); } } else { upgrades = s_upgradeDAO.findUpgrades(cluster.getClusterId()); } for (UpgradeEntity entity : upgrades) { Resource r = toResource(entity, clusterName, requestPropertyIds); results.add(r); RequestEntity rentity = s_requestDAO.findByPK(entity.getRequestId()); setResourceProperty(r, REQUEST_CONTEXT_ID, rentity.getRequestContext(), requestPropertyIds); setResourceProperty(r, REQUEST_TYPE_ID, rentity.getRequestType(), requestPropertyIds); setResourceProperty(r, REQUEST_CREATE_TIME_ID, rentity.getCreateTime(), requestPropertyIds); setResourceProperty(r, REQUEST_START_TIME_ID, rentity.getStartTime(), requestPropertyIds); setResourceProperty(r, REQUEST_END_TIME_ID, rentity.getEndTime(), requestPropertyIds); setResourceProperty(r, REQUEST_EXCLUSIVE_ID, rentity.isExclusive(), requestPropertyIds); Map<Long, HostRoleCommandStatusSummaryDTO> summary = s_hostRoleCommandDAO.findAggregateCounts( entity.getRequestId()); CalculatedStatus calc = CalculatedStatus.statusFromStageSummary(summary, summary.keySet()); setResourceProperty(r, REQUEST_STATUS_PROPERTY_ID, calc.getStatus(), requestPropertyIds); setResourceProperty(r, REQUEST_PROGRESS_PERCENT_ID, calc.getPercent(), requestPropertyIds); } } return results; } @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; }