@Test public void testLoadAlertCreateWhenHostGroupSupported() { Set requestHostGroups = Set.of("compute", "compute1"); Set supportedHostGroups = Set.of("compute", "compute1", "compute3"); when(recommendationService.getAutoscaleRecommendations(anyString())) .thenReturn(new AutoscaleRecommendationV4Response(supportedHostGroups, supportedHostGroups)); underTest.validateSupportedHostGroup(aCluster, requestHostGroups, AlertType.LOAD); }
public void validateSupportedHostGroup(Cluster cluster, Set<String> requestHostGroups, AlertType alertType) { Set<String> supportedHostGroups = Optional.ofNullable( recommendationService.getAutoscaleRecommendations(cluster.getStackCrn())).map( recommendation -> { if (AlertType.LOAD.equals(alertType)) { return Optional.ofNullable(recommendation.getLoadBasedHostGroups()).orElse(Set.of()); } if (AlertType.TIME.equals(alertType)) { return Optional.ofNullable(recommendation.getTimeBasedHostGroups()).orElse(Set.of()); } return Set.of(""); }).orElse(Set.of("")); if (!supportedHostGroups.containsAll(requestHostGroups)) { throw new BadRequestException(messagesService.getMessage(MessageCode.UNSUPPORTED_AUTOSCALING_HOSTGROUP, List.of(requestHostGroups, alertType, cluster.getStackName(), supportedHostGroups))); } }
AlertValidator { public void validateSupportedHostGroup(Cluster cluster, Set<String> requestHostGroups, AlertType alertType) { Set<String> supportedHostGroups = Optional.ofNullable( recommendationService.getAutoscaleRecommendations(cluster.getStackCrn())).map( recommendation -> { if (AlertType.LOAD.equals(alertType)) { return Optional.ofNullable(recommendation.getLoadBasedHostGroups()).orElse(Set.of()); } if (AlertType.TIME.equals(alertType)) { return Optional.ofNullable(recommendation.getTimeBasedHostGroups()).orElse(Set.of()); } return Set.of(""); }).orElse(Set.of("")); if (!supportedHostGroups.containsAll(requestHostGroups)) { throw new BadRequestException(messagesService.getMessage(MessageCode.UNSUPPORTED_AUTOSCALING_HOSTGROUP, List.of(requestHostGroups, alertType, cluster.getStackName(), supportedHostGroups))); } } }
AlertValidator { public void validateSupportedHostGroup(Cluster cluster, Set<String> requestHostGroups, AlertType alertType) { Set<String> supportedHostGroups = Optional.ofNullable( recommendationService.getAutoscaleRecommendations(cluster.getStackCrn())).map( recommendation -> { if (AlertType.LOAD.equals(alertType)) { return Optional.ofNullable(recommendation.getLoadBasedHostGroups()).orElse(Set.of()); } if (AlertType.TIME.equals(alertType)) { return Optional.ofNullable(recommendation.getTimeBasedHostGroups()).orElse(Set.of()); } return Set.of(""); }).orElse(Set.of("")); if (!supportedHostGroups.containsAll(requestHostGroups)) { throw new BadRequestException(messagesService.getMessage(MessageCode.UNSUPPORTED_AUTOSCALING_HOSTGROUP, List.of(requestHostGroups, alertType, cluster.getStackName(), supportedHostGroups))); } }  }
AlertValidator { public void validateSupportedHostGroup(Cluster cluster, Set<String> requestHostGroups, AlertType alertType) { Set<String> supportedHostGroups = Optional.ofNullable( recommendationService.getAutoscaleRecommendations(cluster.getStackCrn())).map( recommendation -> { if (AlertType.LOAD.equals(alertType)) { return Optional.ofNullable(recommendation.getLoadBasedHostGroups()).orElse(Set.of()); } if (AlertType.TIME.equals(alertType)) { return Optional.ofNullable(recommendation.getTimeBasedHostGroups()).orElse(Set.of()); } return Set.of(""); }).orElse(Set.of("")); if (!supportedHostGroups.containsAll(requestHostGroups)) { throw new BadRequestException(messagesService.getMessage(MessageCode.UNSUPPORTED_AUTOSCALING_HOSTGROUP, List.of(requestHostGroups, alertType, cluster.getStackName(), supportedHostGroups))); } }  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 validateSupportedHostGroup(Cluster cluster, Set<String> requestHostGroups, AlertType alertType) { Set<String> supportedHostGroups = Optional.ofNullable( recommendationService.getAutoscaleRecommendations(cluster.getStackCrn())).map( recommendation -> { if (AlertType.LOAD.equals(alertType)) { return Optional.ofNullable(recommendation.getLoadBasedHostGroups()).orElse(Set.of()); } if (AlertType.TIME.equals(alertType)) { return Optional.ofNullable(recommendation.getTimeBasedHostGroups()).orElse(Set.of()); } return Set.of(""); }).orElse(Set.of("")); if (!supportedHostGroups.containsAll(requestHostGroups)) { throw new BadRequestException(messagesService.getMessage(MessageCode.UNSUPPORTED_AUTOSCALING_HOSTGROUP, List.of(requestHostGroups, alertType, cluster.getStackName(), supportedHostGroups))); } }  void validateEntitlementAndDisableIfNotEntitled(Cluster cluster); void validateSupportedHostGroup(Cluster cluster, Set<String> requestHostGroups, AlertType alertType); void validateDistroXAutoscaleClusterRequest(Cluster cluster,
            DistroXAutoscaleClusterRequest distroXAutoscaleClusterRequest); void validateSchedule(TimeAlertRequest json);  }