@Test public void testValidateDistroXAutoscaleClusterRequestWhenInvalidTimeZone() { DistroXAutoscaleClusterRequest request = new DistroXAutoscaleClusterRequest(); List<TimeAlertRequest> timeAlertRequests = new ArrayList<>(); List.of("compute", "compute", "compute1").forEach( hostGroup -> { ScalingPolicyRequest sp1 = new ScalingPolicyRequest(); sp1.setHostGroup("compute"); TimeAlertRequest timeAlertRequest1 = new TimeAlertRequest(); timeAlertRequest1.setScalingPolicy(sp1); timeAlertRequest1.setCron("1 0 1 1 1 1"); timeAlertRequest1.setTimeZone("GMT"); timeAlertRequests.add(timeAlertRequest1); } ); ScalingPolicyRequest sp2 = new ScalingPolicyRequest(); sp2.setHostGroup("compute3"); TimeAlertRequest timeAlertRequest2 = new TimeAlertRequest(); timeAlertRequest2.setScalingPolicy(sp2); timeAlertRequest2.setCron("1 0 1 1 1 1"); timeAlertRequest2.setTimeZone("GMT-434343"); timeAlertRequests.add(timeAlertRequest2); request.setTimeAlertRequests(timeAlertRequests); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Invalid ID for offset-based ZoneId: GMT-4343"); 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);  }