Search in sources :

Example 11 with DistroXAutoscaleClusterRequest

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

the class DistroXAutoscaleRequestValidatorTest method testIsValidWhenNegativeTargeTimeAlertsThenFalse.

@Test
public void testIsValidWhenNegativeTargeTimeAlertsThenFalse() {
    List<String> timeHostGroups = Arrays.asList("compute2", "hdfs1", "hdfs3");
    DistroXAutoscaleClusterRequest request = getTestRequest(timeHostGroups, List.of(), Optional.empty());
    request.getTimeAlertRequests().stream().forEach(timeAlertRequest -> timeAlertRequest.getScalingPolicy().setScalingAdjustment(-10));
    boolean underTestValid = underTest.isValid(request, validatorContext);
    assertFalse("Target for Time Alert with Exact Adjustment cannot be negative.", underTestValid);
}
Also used : DistroXAutoscaleClusterRequest(com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterRequest) Test(org.junit.Test)

Example 12 with DistroXAutoscaleClusterRequest

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

Example 13 with DistroXAutoscaleClusterRequest

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

the class DistroXAutoScaleClusterV1EndpointTest method testUpdateAutoscaleConfigByClusterNameForLoadAlerts.

@Test
public void testUpdateAutoscaleConfigByClusterNameForLoadAlerts() {
    List<LoadAlertRequest> loadAlertRequests = getLoadAlertRequests(1, List.of("compute"));
    DistroXAutoscaleClusterRequest distroXAutoscaleClusterRequest = new DistroXAutoscaleClusterRequest();
    distroXAutoscaleClusterRequest.setLoadAlertRequests(loadAlertRequests);
    distroXAutoscaleClusterRequest.setEnableAutoscaling(true);
    DistroXAutoscaleClusterResponse xAutoscaleClusterResponse = distroXAutoScaleClusterV1Endpoint.updateAutoscaleConfigByClusterName(TEST_CLUSTER_NAME, distroXAutoscaleClusterRequest);
    assertEquals("Retrieved Alerts Size Should Match", 1, xAutoscaleClusterResponse.getLoadAlerts().size());
    assertTrue("Autoscaling should be enabled", xAutoscaleClusterResponse.isAutoscalingEnabled());
    xAutoscaleClusterResponse.getLoadAlerts().stream().forEach(this::validateLoadAlertResponse);
}
Also used : DistroXAutoscaleClusterResponse(com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterResponse) 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 14 with DistroXAutoscaleClusterRequest

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

the class DistroXAutoScaleClusterV1EndpointTest method testDeleteAlertByClusterNameForTimeAlerts.

@Test
public void testDeleteAlertByClusterNameForTimeAlerts() {
    List<TimeAlertRequest> timeAlertRequests = getTimeAlertRequests(2, List.of("compute", "compute"));
    DistroXAutoscaleClusterRequest distroXAutoscaleClusterRequest = new DistroXAutoscaleClusterRequest();
    distroXAutoscaleClusterRequest.setTimeAlertRequests(timeAlertRequests);
    distroXAutoscaleClusterRequest.setEnableAutoscaling(true);
    DistroXAutoscaleClusterResponse xAutoscaleClusterResponse = distroXAutoScaleClusterV1Endpoint.updateAutoscaleConfigByClusterName(TEST_CLUSTER_NAME, distroXAutoscaleClusterRequest);
    assertEquals("Retrieved Alerts Size Should Match", 2, xAutoscaleClusterResponse.getTimeAlerts().size());
    distroXAutoScaleClusterV1Endpoint.deleteAlertsForClusterName(TEST_CLUSTER_NAME);
    xAutoscaleClusterResponse = distroXAutoScaleClusterV1Endpoint.getClusterByName(TEST_CLUSTER_NAME);
    assertEquals("Retrieved Alerts Size Should Match", 0, xAutoscaleClusterResponse.getTimeAlerts().size());
}
Also used : TimeAlertRequest(com.sequenceiq.periscope.api.model.TimeAlertRequest) DistroXAutoscaleClusterResponse(com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterResponse) DistroXAutoscaleClusterRequest(com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterRequest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 15 with DistroXAutoscaleClusterRequest

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

the class DistroXAutoScaleClusterV1EndpointTest method testUpdateAutoscaleConfigByClusterCrnForEnableDisableStopStartScaling.

@Test
public void testUpdateAutoscaleConfigByClusterCrnForEnableDisableStopStartScaling() {
    DistroXAutoscaleClusterRequest clusterRequest = new DistroXAutoscaleClusterRequest();
    clusterRequest.setEnableAutoscaling(true);
    clusterRequest.setUseStopStartMechanism(null);
    DistroXAutoscaleClusterResponse clusterResponse = distroXAutoScaleClusterV1Endpoint.updateAutoscaleConfigByClusterCrn(TEST_CLUSTER_CRN, clusterRequest);
    assertFalse("StopStart scaling should be disabled if not specified in reuqest", clusterResponse.isStopStartScalingEnabled());
    clusterRequest.setUseStopStartMechanism(true);
    clusterResponse = distroXAutoScaleClusterV1Endpoint.updateAutoscaleConfigByClusterCrn(TEST_CLUSTER_CRN, clusterRequest);
    assertTrue("StopStart scaling should be enabled", clusterResponse.isStopStartScalingEnabled());
    clusterRequest.setUseStopStartMechanism(false);
    clusterResponse = distroXAutoScaleClusterV1Endpoint.updateAutoscaleConfigByClusterCrn(TEST_CLUSTER_CRN, clusterRequest);
    assertFalse("StopStart scaling should be disabled", clusterResponse.isStopStartScalingEnabled());
}
Also used : DistroXAutoscaleClusterResponse(com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterResponse) 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