Search in sources :

Example 1 with DistroXAutoscaleClusterRequest

use of com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterRequest in project cloudbreak by hortonworks.

the class AlertValidatorTest method testValidateDistroXAutoscaleClusterRequestWhenInvalidHostGroup.

@Test
public void testValidateDistroXAutoscaleClusterRequestWhenInvalidHostGroup() {
    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("computeNotSupported");
    TimeAlertRequest timeAlertRequest2 = new TimeAlertRequest();
    timeAlertRequest2.setScalingPolicy(sp2);
    timeAlertRequest2.setCron("1 0 1 1 1 1");
    timeAlertRequest2.setTimeZone("GMT");
    timeAlertRequests.add(timeAlertRequest2);
    request.setTimeAlertRequests(timeAlertRequests);
    Set<String> 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("compute", "computeNotSupported"), AlertType.TIME, aCluster.getStackName(), supportedHostGroups))).thenReturn("unsupported.hostgroup");
    expectedException.expect(BadRequestException.class);
    expectedException.expectMessage("unsupported.hostgroup");
    underTest.validateDistroXAutoscaleClusterRequest(aCluster, request);
}
Also used : ScalingPolicyRequest(com.sequenceiq.periscope.api.model.ScalingPolicyRequest) AutoscaleRecommendationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.AutoscaleRecommendationV4Response) TimeAlertRequest(com.sequenceiq.periscope.api.model.TimeAlertRequest) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DistroXAutoscaleClusterRequest(com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterRequest) Test(org.junit.Test)

Example 2 with DistroXAutoscaleClusterRequest

use of com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterRequest in project cloudbreak by hortonworks.

the class AlertValidatorTest method testValidateDistroXAutoscaleClusterRequestWhenInvalidTimeZone.

@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);
}
Also used : ScalingPolicyRequest(com.sequenceiq.periscope.api.model.ScalingPolicyRequest) TimeAlertRequest(com.sequenceiq.periscope.api.model.TimeAlertRequest) ArrayList(java.util.ArrayList) DistroXAutoscaleClusterRequest(com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterRequest) Test(org.junit.Test)

Example 3 with DistroXAutoscaleClusterRequest

use of com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterRequest in project cloudbreak by hortonworks.

the class AlertValidatorTest method testEnableStopStartInRequestWithTimeAlertPreCreated.

@Test
public void testEnableStopStartInRequestWithTimeAlertPreCreated() {
    DistroXAutoscaleClusterRequest autoscaleRequest = new DistroXAutoscaleClusterRequest();
    autoscaleRequest.setEnableAutoscaling(Boolean.TRUE);
    autoscaleRequest.setUseStopStartMechanism(Boolean.TRUE);
    TimeAlert timeAlert = new TimeAlert();
    timeAlert.setTimeZone("Asia/Calcutta");
    timeAlert.setCluster(aCluster);
    timeAlert.setCron("1 0 1 1 1 1");
    aCluster.setTimeAlerts(Set.of(timeAlert));
    when(messagesService.getMessage(VALIDATION_TIME_STOP_START_UNSUPPORTED)).thenReturn("Schedule-Based Autoscaling does not support the stop / start scaling mechanism.");
    expectedException.expect(BadRequestException.class);
    expectedException.expectMessage("Schedule-Based Autoscaling does not support the stop / start scaling mechanism.");
    underTest.validateScheduleWithStopStart(aCluster, autoscaleRequest);
}
Also used : TimeAlert(com.sequenceiq.periscope.domain.TimeAlert) DistroXAutoscaleClusterRequest(com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterRequest) Test(org.junit.Test)

Example 4 with DistroXAutoscaleClusterRequest

use of com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterRequest in project cloudbreak by hortonworks.

the class AlertValidatorTest method testTimeAlertCreateWhenStopStartEnabledInRequest.

@Test
public void testTimeAlertCreateWhenStopStartEnabledInRequest() {
    DistroXAutoscaleClusterRequest autoscaleClusterRequest = new DistroXAutoscaleClusterRequest();
    List<TimeAlertRequest> timeAlerts = 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");
        timeAlerts.add(timeAlertRequest1);
    });
    autoscaleClusterRequest.setUseStopStartMechanism(Boolean.TRUE);
    autoscaleClusterRequest.setTimeAlertRequests(timeAlerts);
    when(messagesService.getMessage(VALIDATION_TIME_STOP_START_UNSUPPORTED)).thenReturn("Schedule-Based Autoscaling does not support the stop / start scaling mechanism.");
    expectedException.expect(BadRequestException.class);
    expectedException.expectMessage("Schedule-Based Autoscaling does not support the stop / start scaling mechanism.");
    underTest.validateScheduleWithStopStart(aCluster, autoscaleClusterRequest);
}
Also used : ScalingPolicyRequest(com.sequenceiq.periscope.api.model.ScalingPolicyRequest) TimeAlertRequest(com.sequenceiq.periscope.api.model.TimeAlertRequest) ArrayList(java.util.ArrayList) DistroXAutoscaleClusterRequest(com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterRequest) Test(org.junit.Test)

Example 5 with DistroXAutoscaleClusterRequest

use of com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterRequest in project cloudbreak by hortonworks.

the class DistroXAutoScaleClusterV1EndpointTest method testUpdateAutoscaleConfigWhenMultipleAlertTypes.

@Test(expected = BadRequestException.class)
public void testUpdateAutoscaleConfigWhenMultipleAlertTypes() {
    List<TimeAlertRequest> timeAlertRequests = getTimeAlertRequests(2, List.of("compute", "compute"));
    List<LoadAlertRequest> loadAlertRequests = getLoadAlertRequests(2, List.of("group1", "group2"));
    DistroXAutoscaleClusterRequest distroXAutoscaleClusterRequest = new DistroXAutoscaleClusterRequest();
    distroXAutoscaleClusterRequest.setTimeAlertRequests(timeAlertRequests);
    distroXAutoscaleClusterRequest.setLoadAlertRequests(loadAlertRequests);
    distroXAutoscaleClusterRequest.setEnableAutoscaling(true);
    distroXAutoScaleClusterV1Endpoint.updateAutoscaleConfigByClusterName(TEST_CLUSTER_NAME, distroXAutoscaleClusterRequest);
}
Also used : TimeAlertRequest(com.sequenceiq.periscope.api.model.TimeAlertRequest) LoadAlertRequest(com.sequenceiq.periscope.api.model.LoadAlertRequest) DistroXAutoscaleClusterRequest(com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterRequest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

DistroXAutoscaleClusterRequest (com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterRequest)29 Test (org.junit.Test)28 TimeAlertRequest (com.sequenceiq.periscope.api.model.TimeAlertRequest)17 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 LoadAlertRequest (com.sequenceiq.periscope.api.model.LoadAlertRequest)11 ScalingPolicyRequest (com.sequenceiq.periscope.api.model.ScalingPolicyRequest)11 DistroXAutoscaleClusterResponse (com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterResponse)8 ArrayList (java.util.ArrayList)8 AutoscaleRecommendationV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.AutoscaleRecommendationV4Response)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 LoadAlertConfigurationRequest (com.sequenceiq.periscope.api.model.LoadAlertConfigurationRequest)3 TimeAlert (com.sequenceiq.periscope.domain.TimeAlert)1