Search in sources :

Example 1 with AutoscaleRecommendationV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.AutoscaleRecommendationV4Response 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 AutoscaleRecommendationV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.AutoscaleRecommendationV4Response in project cloudbreak by hortonworks.

the class AlertValidatorTest method testTimeAlertCreateWhenHostGroupNotSupported.

@Test
public void testTimeAlertCreateWhenHostGroupNotSupported() {
    Set<String> requestHostGroups = Set.of("compute", "compute1");
    Set<String> supportedHostGroups = Set.of("compute1");
    when(recommendationService.getAutoscaleRecommendations(anyString())).thenReturn(new AutoscaleRecommendationV4Response(supportedHostGroups, supportedHostGroups));
    when(messagesService.getMessage(UNSUPPORTED_AUTOSCALING_HOSTGROUP, List.of(requestHostGroups, AlertType.TIME, aCluster.getStackName(), supportedHostGroups))).thenReturn("unsupported.hostgroup");
    expectedException.expect(BadRequestException.class);
    expectedException.expectMessage("unsupported.hostgroup");
    underTest.validateSupportedHostGroup(aCluster, requestHostGroups, AlertType.TIME);
}
Also used : AutoscaleRecommendationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.AutoscaleRecommendationV4Response) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 3 with AutoscaleRecommendationV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.AutoscaleRecommendationV4Response in project cloudbreak by hortonworks.

the class AlertValidatorTest method testLoadAlertCreateWhenHostGroupSupported.

@Test
public void testLoadAlertCreateWhenHostGroupSupported() {
    Set<String> requestHostGroups = Set.of("compute", "compute1");
    Set<String> supportedHostGroups = Set.of("compute", "compute1", "compute3");
    when(recommendationService.getAutoscaleRecommendations(anyString())).thenReturn(new AutoscaleRecommendationV4Response(supportedHostGroups, supportedHostGroups));
    underTest.validateSupportedHostGroup(aCluster, requestHostGroups, AlertType.LOAD);
}
Also used : AutoscaleRecommendationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.AutoscaleRecommendationV4Response) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 4 with AutoscaleRecommendationV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.AutoscaleRecommendationV4Response in project cloudbreak by hortonworks.

the class PlatformRecommendationToPlatformRecommendationV4ResponseConverter method convert.

public RecommendationV4Response convert(PlatformRecommendation source) {
    Map<String, VmTypeV4Response> result = new HashMap<>();
    source.getRecommendations().forEach((hostGroupName, vm) -> result.put(hostGroupName, vmTypeToVmTypeV4ResponseConverter.convert(vm)));
    Set<VmTypeV4Response> vmTypes = source.getVirtualMachines().stream().map(vmType -> vmTypeToVmTypeV4ResponseConverter.convert(vmType)).collect(Collectors.toSet());
    Set<DiskV4Response> diskResponses = new HashSet<>();
    for (Entry<DiskType, DisplayName> diskTypeDisplayName : source.getDiskTypes().displayNames().entrySet()) {
        for (Entry<String, VolumeParameterType> volumeParameterType : source.getDiskTypes().diskMapping().entrySet()) {
            if (diskTypeDisplayName.getKey().value().equals(volumeParameterType.getKey())) {
                DiskV4Response diskResponse = new DiskV4Response(diskTypeDisplayName.getKey().value(), volumeParameterType.getValue().name(), diskTypeDisplayName.getValue().value());
                diskResponses.add(diskResponse);
            }
        }
    }
    Map<String, InstanceCountV4Response> instanceCounts = new TreeMap<>();
    source.getInstanceCounts().forEach((hostGroupName, instanceCount) -> instanceCounts.put(hostGroupName, new InstanceCountV4Response(instanceCount.getMinimumCount(), instanceCount.getMaximumCount())));
    GatewayRecommendationV4Response gateway = new GatewayRecommendationV4Response(source.getGatewayRecommendation().getHostGroups());
    AutoscaleRecommendationV4Response autoscaleRecommendation = new AutoscaleRecommendationV4Response(source.getAutoscaleRecommendation().getTimeBasedHostGroups(), source.getAutoscaleRecommendation().getLoadBasedHostGroups());
    ResizeRecommendationV4Response resizeRecommendation = new ResizeRecommendationV4Response(source.getResizeRecommendation().getScaleUpHostGroups(), source.getResizeRecommendation().getScaleDownHostGroups());
    return new RecommendationV4Response(result, vmTypes, diskResponses, instanceCounts, gateway, autoscaleRecommendation, resizeRecommendation);
}
Also used : DisplayName(com.sequenceiq.cloudbreak.cloud.model.DisplayName) ResizeRecommendationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.ResizeRecommendationV4Response) PlatformRecommendation(com.sequenceiq.cloudbreak.cloud.model.PlatformRecommendation) DiskType(com.sequenceiq.cloudbreak.cloud.model.DiskType) Set(java.util.Set) DiskV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.DiskV4Response) HashMap(java.util.HashMap) VmTypeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.VmTypeV4Response) Collectors(java.util.stream.Collectors) VmTypeToVmTypeV4ResponseConverter(com.sequenceiq.cloudbreak.converter.v4.connectors.VmTypeToVmTypeV4ResponseConverter) HashSet(java.util.HashSet) Inject(javax.inject.Inject) AutoscaleRecommendationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.AutoscaleRecommendationV4Response) Component(org.springframework.stereotype.Component) TreeMap(java.util.TreeMap) InstanceCountV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.InstanceCountV4Response) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) Map(java.util.Map) Entry(java.util.Map.Entry) GatewayRecommendationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.GatewayRecommendationV4Response) RecommendationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.responses.RecommendationV4Response) HashMap(java.util.HashMap) VmTypeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.VmTypeV4Response) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) InstanceCountV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.InstanceCountV4Response) TreeMap(java.util.TreeMap) DiskType(com.sequenceiq.cloudbreak.cloud.model.DiskType) DiskV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.DiskV4Response) AutoscaleRecommendationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.AutoscaleRecommendationV4Response) ResizeRecommendationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.ResizeRecommendationV4Response) GatewayRecommendationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.GatewayRecommendationV4Response) DisplayName(com.sequenceiq.cloudbreak.cloud.model.DisplayName) ResizeRecommendationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.ResizeRecommendationV4Response) AutoscaleRecommendationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.AutoscaleRecommendationV4Response) GatewayRecommendationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.GatewayRecommendationV4Response) RecommendationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.responses.RecommendationV4Response) HashSet(java.util.HashSet)

Example 5 with AutoscaleRecommendationV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.AutoscaleRecommendationV4Response in project cloudbreak by hortonworks.

the class ScaleRecommendationToScaleRecommendationV4ResponseConverter method convert.

public ScaleRecommendationV4Response convert(ScaleRecommendation source) {
    AutoscaleRecommendationV4Response autoscaleRecommendation = new AutoscaleRecommendationV4Response(source.getAutoscaleRecommendation().getTimeBasedHostGroups(), source.getAutoscaleRecommendation().getLoadBasedHostGroups());
    ResizeRecommendationV4Response resizeRecommendation = new ResizeRecommendationV4Response(source.getResizeRecommendation().getScaleUpHostGroups(), source.getResizeRecommendation().getScaleDownHostGroups());
    ScaleRecommendationV4Response scaleRecommendation = new ScaleRecommendationV4Response(autoscaleRecommendation, resizeRecommendation);
    return scaleRecommendation;
}
Also used : AutoscaleRecommendationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.AutoscaleRecommendationV4Response) ResizeRecommendationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.ResizeRecommendationV4Response) ScaleRecommendationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.ScaleRecommendationV4Response)

Aggregations

AutoscaleRecommendationV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.AutoscaleRecommendationV4Response)11 Test (org.junit.Test)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 DistroXAutoscaleClusterRequest (com.sequenceiq.periscope.api.model.DistroXAutoscaleClusterRequest)4 ScalingPolicyRequest (com.sequenceiq.periscope.api.model.ScalingPolicyRequest)4 ResizeRecommendationV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.ResizeRecommendationV4Response)2 LoadAlertConfigurationRequest (com.sequenceiq.periscope.api.model.LoadAlertConfigurationRequest)2 LoadAlertRequest (com.sequenceiq.periscope.api.model.LoadAlertRequest)2 TimeAlertRequest (com.sequenceiq.periscope.api.model.TimeAlertRequest)2 ArrayList (java.util.ArrayList)2 UserManagementProto (com.cloudera.thunderhead.service.usermanagement.UserManagementProto)1 RecommendationV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.responses.RecommendationV4Response)1 DiskV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.DiskV4Response)1 GatewayRecommendationV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.GatewayRecommendationV4Response)1 InstanceCountV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.InstanceCountV4Response)1 ScaleRecommendationV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.connector.responses.ScaleRecommendationV4Response)1 VmTypeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.VmTypeV4Response)1 DiskType (com.sequenceiq.cloudbreak.cloud.model.DiskType)1 DisplayName (com.sequenceiq.cloudbreak.cloud.model.DisplayName)1 PlatformRecommendation (com.sequenceiq.cloudbreak.cloud.model.PlatformRecommendation)1