Search in sources :

Example 1 with LoadAlertRequest

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

the class LoadAlertRequestConverterTest method testConvertLoadAlertRequestToLoadAlert.

@Test
public void testConvertLoadAlertRequestToLoadAlert() {
    LoadAlertRequest req = new LoadAlertRequest();
    req.setAlertName("loadalert");
    req.setDescription("loadalertdesc");
    ScalingPolicyRequest scalingPolicyRequest = getScalingPolicyRequest();
    req.setScalingPolicy(scalingPolicyRequest);
    when(scalingPolicyRequestConverter.convert(any(ScalingPolicyRequest.class))).thenCallRealMethod();
    LoadAlert loadAlert = underTest.convert(req);
    assertEquals("LoadAlert Name should match", loadAlert.getName(), "loadalert");
    assertEquals("LoadAlert Desc should match", loadAlert.getDescription(), "loadalertdesc");
    assertEquals("LoadAlert Hostgroup should match", loadAlert.getScalingPolicy().getHostGroup(), "compute");
    assertEquals("LoadAlert Adjustment Type should match", loadAlert.getScalingPolicy().getAdjustmentType(), LOAD_BASED);
    assertEquals("LoadAlert Adjustment should match", loadAlert.getScalingPolicy().getScalingAdjustment(), 10);
}
Also used : ScalingPolicyRequest(com.sequenceiq.periscope.api.model.ScalingPolicyRequest) LoadAlertRequest(com.sequenceiq.periscope.api.model.LoadAlertRequest) LoadAlert(com.sequenceiq.periscope.domain.LoadAlert) Test(org.junit.Test)

Example 2 with LoadAlertRequest

use of com.sequenceiq.periscope.api.model.LoadAlertRequest 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)

Example 3 with LoadAlertRequest

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

the class DistroXAutoScaleClusterV1EndpointTest method testUpdateAutoscaleConfigByClusterCrnForMultipleLoadAlertsAndHostGroups.

@Test(expected = BadRequestException.class)
public void testUpdateAutoscaleConfigByClusterCrnForMultipleLoadAlertsAndHostGroups() {
    List<LoadAlertRequest> loadAlertRequests = getLoadAlertRequests(2, List.of("group1", "group2"));
    DistroXAutoscaleClusterRequest distroXAutoscaleClusterRequest = new DistroXAutoscaleClusterRequest();
    distroXAutoscaleClusterRequest.setLoadAlertRequests(loadAlertRequests);
    distroXAutoscaleClusterRequest.setEnableAutoscaling(true);
    distroXAutoScaleClusterV1Endpoint.updateAutoscaleConfigByClusterCrn(TEST_CLUSTER_CRN, distroXAutoscaleClusterRequest);
}
Also used : 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)

Example 4 with LoadAlertRequest

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

the class DistroXAutoScaleClusterV1EndpointTest method testCreateTimeAlertWithPreExistingStopStartLoadAlert.

@Test(expected = BadRequestException.class)
public void testCreateTimeAlertWithPreExistingStopStartLoadAlert() {
    DistroXAutoscaleClusterRequest autoscaleRequest = new DistroXAutoscaleClusterRequest();
    List<LoadAlertRequest> loadAlertRequests = getLoadAlertRequests(1, List.of("compute"));
    autoscaleRequest.setLoadAlertRequests(loadAlertRequests);
    autoscaleRequest.setUseStopStartMechanism(true);
    autoscaleRequest.setEnableAutoscaling(true);
    distroXAutoScaleClusterV1Endpoint.updateAutoscaleConfigByClusterName(TEST_CLUSTER_NAME, autoscaleRequest);
    List<TimeAlertRequest> timeAlertRequests = getTimeAlertRequests(2, List.of("compute", "compute"));
    autoscaleRequest.setTimeAlertRequests(timeAlertRequests);
    autoscaleRequest.setLoadAlertRequests(null);
    autoscaleRequest.setUseStopStartMechanism(null);
    distroXAutoScaleClusterV1Endpoint.updateAutoscaleConfigByClusterName(TEST_CLUSTER_NAME, autoscaleRequest);
}
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)

Example 5 with LoadAlertRequest

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

the class DistroXAutoscaleRequestValidatorTest method getTestRequest.

private DistroXAutoscaleClusterRequest getTestRequest(List<String> timeHostGroups, List<String> loadHostGroups, Optional<AdjustmentType> testAdjustmentType) {
    DistroXAutoscaleClusterRequest testRequest = new DistroXAutoscaleClusterRequest();
    List<TimeAlertRequest> timeAlertRequests = new ArrayList<>();
    List<LoadAlertRequest> loadAlertRequests = new ArrayList<>();
    if (timeHostGroups != null) {
        for (String hostGroup : timeHostGroups) {
            TimeAlertRequest request = new TimeAlertRequest();
            ScalingPolicyRequest scalingPolicyRequest = new ScalingPolicyRequest();
            scalingPolicyRequest.setHostGroup(hostGroup);
            scalingPolicyRequest.setAdjustmentType(testAdjustmentType.orElse(AdjustmentType.EXACT));
            scalingPolicyRequest.setScalingAdjustment(10);
            request.setScalingPolicy(scalingPolicyRequest);
            timeAlertRequests.add(request);
        }
        testRequest.setTimeAlertRequests(timeAlertRequests);
    }
    if (loadHostGroups != null) {
        for (String hostGroup : loadHostGroups) {
            LoadAlertRequest request = new LoadAlertRequest();
            ScalingPolicyRequest scalingPolicyRequest = new ScalingPolicyRequest();
            scalingPolicyRequest.setHostGroup(hostGroup);
            scalingPolicyRequest.setAdjustmentType(testAdjustmentType.orElse(AdjustmentType.LOAD_BASED));
            request.setScalingPolicy(scalingPolicyRequest);
            loadAlertRequests.add(request);
        }
        testRequest.setLoadAlertRequests(loadAlertRequests);
    }
    return testRequest;
}
Also used : ScalingPolicyRequest(com.sequenceiq.periscope.api.model.ScalingPolicyRequest) TimeAlertRequest(com.sequenceiq.periscope.api.model.TimeAlertRequest) ArrayList(java.util.ArrayList) LoadAlertRequest(com.sequenceiq.periscope.api.model.LoadAlertRequest) DistroXAutoscaleClusterRequest(com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterRequest)

Aggregations

LoadAlertRequest (com.sequenceiq.periscope.api.model.LoadAlertRequest)13 DistroXAutoscaleClusterRequest (com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterRequest)11 Test (org.junit.Test)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 ScalingPolicyRequest (com.sequenceiq.periscope.api.model.ScalingPolicyRequest)6 LoadAlertConfigurationRequest (com.sequenceiq.periscope.api.model.LoadAlertConfigurationRequest)4 DistroXAutoscaleClusterResponse (com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterResponse)3 TimeAlertRequest (com.sequenceiq.periscope.api.model.TimeAlertRequest)3 AutoscaleRecommendationV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.AutoscaleRecommendationV4Response)2 ArrayList (java.util.ArrayList)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 LoadAlert (com.sequenceiq.periscope.domain.LoadAlert)1