@Test public void testValidateDistroXAutoscaleClusterRequestWhenHostGroupNotSupported() { DistroXAutoscaleClusterRequest request = new DistroXAutoscaleClusterRequest(); ScalingPolicyRequest sp1 = new ScalingPolicyRequest(); sp1.setHostGroup("notsupported"); LoadAlertRequest loadAlertRequest = new LoadAlertRequest(); loadAlertRequest.setScalingPolicy(sp1); request.setLoadAlertRequests(List.of(loadAlertRequest)); Set supportedHostGroups = Set.of("compute", "compute1", "compute3"); when(recommendationService.getAutoscaleRecommendations(anyString())) .thenReturn(new AutoscaleRecommendationV4Response(supportedHostGroups, supportedHostGroups)); when(messagesService.getMessage(UNSUPPORTED_AUTOSCALING_HOSTGROUP, List.of(Set.of("notsupported"), AlertType.LOAD, aCluster.getStackName(), supportedHostGroups))) .thenReturn("unsupported.hostgroup"); expectedException.expect(BadRequestException.class); expectedException.expectMessage("unsupported.hostgroup"); underTest.validateDistroXAutoscaleClusterRequest(aCluster, request); }
public void validateDistroXAutoscaleClusterRequest(Cluster cluster, DistroXAutoscaleClusterRequest distroXAutoscaleClusterRequest) { if (!distroXAutoscaleClusterRequest.getTimeAlertRequests().isEmpty()) { Set<String> timeAlertHostGroups = distroXAutoscaleClusterRequest.getTimeAlertRequests().stream() .map(timeAlertRequest -> { validateSchedule(timeAlertRequest); return timeAlertRequest; }) .map(TimeAlertRequest::getScalingPolicy) .map(ScalingPolicyBase::getHostGroup) .collect(Collectors.toSet()); validateSupportedHostGroup(cluster, timeAlertHostGroups, AlertType.TIME); } if (!distroXAutoscaleClusterRequest.getLoadAlertRequests().isEmpty()) { Set<String> loadAlertHostGroups = distroXAutoscaleClusterRequest.getLoadAlertRequests().stream() .map(LoadAlertRequest::getScalingPolicy) .map(ScalingPolicyBase::getHostGroup) .collect(Collectors.toSet()); validateSupportedHostGroup(cluster, loadAlertHostGroups, AlertType.LOAD); } }
AlertValidator { public void validateDistroXAutoscaleClusterRequest(Cluster cluster, DistroXAutoscaleClusterRequest distroXAutoscaleClusterRequest) { if (!distroXAutoscaleClusterRequest.getTimeAlertRequests().isEmpty()) { Set<String> timeAlertHostGroups = distroXAutoscaleClusterRequest.getTimeAlertRequests().stream() .map(timeAlertRequest -> { validateSchedule(timeAlertRequest); return timeAlertRequest; }) .map(TimeAlertRequest::getScalingPolicy) .map(ScalingPolicyBase::getHostGroup) .collect(Collectors.toSet()); validateSupportedHostGroup(cluster, timeAlertHostGroups, AlertType.TIME); } if (!distroXAutoscaleClusterRequest.getLoadAlertRequests().isEmpty()) { Set<String> loadAlertHostGroups = distroXAutoscaleClusterRequest.getLoadAlertRequests().stream() .map(LoadAlertRequest::getScalingPolicy) .map(ScalingPolicyBase::getHostGroup) .collect(Collectors.toSet()); validateSupportedHostGroup(cluster, loadAlertHostGroups, AlertType.LOAD); } } }
AlertValidator { public void validateDistroXAutoscaleClusterRequest(Cluster cluster, DistroXAutoscaleClusterRequest distroXAutoscaleClusterRequest) { if (!distroXAutoscaleClusterRequest.getTimeAlertRequests().isEmpty()) { Set<String> timeAlertHostGroups = distroXAutoscaleClusterRequest.getTimeAlertRequests().stream() .map(timeAlertRequest -> { validateSchedule(timeAlertRequest); return timeAlertRequest; }) .map(TimeAlertRequest::getScalingPolicy) .map(ScalingPolicyBase::getHostGroup) .collect(Collectors.toSet()); validateSupportedHostGroup(cluster, timeAlertHostGroups, AlertType.TIME); } if (!distroXAutoscaleClusterRequest.getLoadAlertRequests().isEmpty()) { Set<String> loadAlertHostGroups = distroXAutoscaleClusterRequest.getLoadAlertRequests().stream() .map(LoadAlertRequest::getScalingPolicy) .map(ScalingPolicyBase::getHostGroup) .collect(Collectors.toSet()); validateSupportedHostGroup(cluster, loadAlertHostGroups, AlertType.LOAD); } }  }
AlertValidator { public void validateDistroXAutoscaleClusterRequest(Cluster cluster, DistroXAutoscaleClusterRequest distroXAutoscaleClusterRequest) { if (!distroXAutoscaleClusterRequest.getTimeAlertRequests().isEmpty()) { Set<String> timeAlertHostGroups = distroXAutoscaleClusterRequest.getTimeAlertRequests().stream() .map(timeAlertRequest -> { validateSchedule(timeAlertRequest); return timeAlertRequest; }) .map(TimeAlertRequest::getScalingPolicy) .map(ScalingPolicyBase::getHostGroup) .collect(Collectors.toSet()); validateSupportedHostGroup(cluster, timeAlertHostGroups, AlertType.TIME); } if (!distroXAutoscaleClusterRequest.getLoadAlertRequests().isEmpty()) { Set<String> loadAlertHostGroups = distroXAutoscaleClusterRequest.getLoadAlertRequests().stream() .map(LoadAlertRequest::getScalingPolicy) .map(ScalingPolicyBase::getHostGroup) .collect(Collectors.toSet()); validateSupportedHostGroup(cluster, loadAlertHostGroups, AlertType.LOAD); } }  void validateEntitlementAndDisableIfNotEntitled(Cluster cluster); void validateSupportedHostGroup(Cluster cluster, Set<String> requestHostGroups, AlertType alertType); void validateDistroXAutoscaleClusterRequest(Cluster cluster,
            DistroXAutoscaleClusterRequest distroXAutoscaleClusterRequest); void validateSchedule(TimeAlertRequest json); }
AlertValidator { public void validateDistroXAutoscaleClusterRequest(Cluster cluster, DistroXAutoscaleClusterRequest distroXAutoscaleClusterRequest) { if (!distroXAutoscaleClusterRequest.getTimeAlertRequests().isEmpty()) { Set<String> timeAlertHostGroups = distroXAutoscaleClusterRequest.getTimeAlertRequests().stream() .map(timeAlertRequest -> { validateSchedule(timeAlertRequest); return timeAlertRequest; }) .map(TimeAlertRequest::getScalingPolicy) .map(ScalingPolicyBase::getHostGroup) .collect(Collectors.toSet()); validateSupportedHostGroup(cluster, timeAlertHostGroups, AlertType.TIME); } if (!distroXAutoscaleClusterRequest.getLoadAlertRequests().isEmpty()) { Set<String> loadAlertHostGroups = distroXAutoscaleClusterRequest.getLoadAlertRequests().stream() .map(LoadAlertRequest::getScalingPolicy) .map(ScalingPolicyBase::getHostGroup) .collect(Collectors.toSet()); validateSupportedHostGroup(cluster, loadAlertHostGroups, AlertType.LOAD); } }  void validateEntitlementAndDisableIfNotEntitled(Cluster cluster); void validateSupportedHostGroup(Cluster cluster, Set<String> requestHostGroups, AlertType alertType); void validateDistroXAutoscaleClusterRequest(Cluster cluster,
            DistroXAutoscaleClusterRequest distroXAutoscaleClusterRequest); void validateSchedule(TimeAlertRequest json);  }