Search in sources :

Example 56 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class NetworkV1ToNetworkV4Converter method convertToAwsStackRequest.

private AwsNetworkV4Parameters convertToAwsStackRequest(Pair<AwsNetworkV1Parameters, EnvironmentNetworkResponse> source) {
    EnvironmentNetworkResponse value = source.getValue();
    AwsNetworkV1Parameters key = source.getKey();
    AwsNetworkV4Parameters response = new AwsNetworkV4Parameters();
    if (key != null) {
        response.setVpcId(value.getAws().getVpcId());
        String subnetId = key.getSubnetId();
        if (!Strings.isNullOrEmpty(subnetId)) {
            response.setSubnetId(key.getSubnetId());
        } else if (value != null) {
            response.setSubnetId(value.getPreferedSubnetId());
        }
        if (PublicEndpointAccessGateway.ENABLED.equals(value.getPublicEndpointAccessGateway())) {
            ValidationResult validationResult = endpointGatewayNetworkValidator.validate(new ImmutablePair<>(response.getSubnetId(), value));
            if (validationResult.getState() == ValidationResult.State.ERROR || validationResult.hasError()) {
                throw new BadRequestException("Endpoint gateway subnet validation failed: " + validationResult.getFormattedErrors());
            }
            Optional<CloudSubnet> endpointGatewaySubnet = subnetSelector.chooseSubnetForEndpointGateway(value, response.getSubnetId());
            if (endpointGatewaySubnet.isPresent()) {
                response.setEndpointGatewaySubnetId(endpointGatewaySubnet.get().getId());
            }
        }
    }
    return response;
}
Also used : EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) AwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.AwsNetworkV1Parameters) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) AwsNetworkV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.network.AwsNetworkV4Parameters)

Example 57 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class StackOperationServiceTest method testStartWhenStackStopFailed.

@Test
public void testStartWhenStackStopFailed() {
    Stack stack = new Stack();
    stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.STOP_FAILED));
    stack.setId(1L);
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.start(stack));
    assertEquals("Can't start the cluster because it is in STOP_FAILED state.", badRequestException.getMessage());
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 58 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class UpdateNodeCountValidatorTest method checkExecutableThrowsException.

private void checkExecutableThrowsException(Optional<String> errorMessageSegment, Stack stack, Executable executable) {
    BadRequestException badRequestException = assertThrows(BadRequestException.class, executable);
    Assert.assertEquals(errorMessageSegment.get(), badRequestException.getMessage());
    Assert.assertTrue(badRequestException.getMessage().contains(errorMessageSegment.get()));
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Example 59 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class UpdateNodeCountValidatorTest method testValidateScalabilityOfInstanceGroup.

@ParameterizedTest(name = "The master node count is {0} this will be scaled with {2} " + "node and the minimum is {1} the ScalabilityOption is {3}.")
@MethodSource("testValidateScalabilityOfInstanceGroupData")
public void testValidateScalabilityOfInstanceGroup(int instanceGroupNodeCount, int minimumNodeCount, int scalingNodeCount, ScalabilityOption scalabilityOption, Optional<String> errorMessageSegment) {
    Stack stack = mock(Stack.class);
    InstanceGroupAdjustmentV4Request instanceGroupAdjustmentV4Request = mock(InstanceGroupAdjustmentV4Request.class);
    InstanceGroup instanceGroup = mock(InstanceGroup.class);
    when(instanceGroupAdjustmentV4Request.getInstanceGroup()).thenReturn("master");
    when(instanceGroupAdjustmentV4Request.getScalingAdjustment()).thenReturn(scalingNodeCount);
    when(stack.getInstanceGroupByInstanceGroupName("master")).thenReturn(instanceGroup);
    when(stack.getName()).thenReturn("master-stack");
    when(instanceGroup.getGroupName()).thenReturn("master");
    when(instanceGroup.getMinimumNodeCount()).thenReturn(minimumNodeCount);
    when(instanceGroup.getNodeCount()).thenReturn(instanceGroupNodeCount);
    when(instanceGroup.getScalabilityOption()).thenReturn(scalabilityOption);
    if (errorMessageSegment.isPresent()) {
        BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> {
            underTest.validateScalabilityOfInstanceGroup(stack, instanceGroupAdjustmentV4Request);
        });
        Assert.assertTrue(badRequestException.getMessage().contains(errorMessageSegment.get()));
    } else {
        assertDoesNotThrow(() -> underTest.validateScalabilityOfInstanceGroup(stack, instanceGroupAdjustmentV4Request));
    }
}
Also used : InstanceGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 60 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class UpdateNodeCountValidatorTest method validateClusterStatusDownscaleNodeFailureTargetedUpscaleNotSupported.

@Test
void validateClusterStatusDownscaleNodeFailureTargetedUpscaleNotSupported() {
    when(targetedUpscaleSupportService.targetedUpscaleEntitlementsEnabled(any())).thenReturn(Boolean.FALSE);
    Stack stack = new Stack();
    stack.setName("stack");
    Cluster cluster = mock(Cluster.class);
    stack.setCluster(cluster);
    stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.NODE_FAILURE));
    BadRequestException e = Assertions.assertThrows(BadRequestException.class, () -> underTest.validateClusterStatus(stack, false));
    assertEquals("Data Hub 'stack' is currently in 'NODE_FAILURE' state. Node count can only be updated if it's running.", e.getMessage());
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)298 Test (org.junit.jupiter.api.Test)134 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)45 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)34 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)26 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)23 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)22 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)21 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)21 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)19 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 Stack (com.sequenceiq.freeipa.entity.Stack)18 BaseDiagnosticsCollectionRequest (com.sequenceiq.common.api.diagnostics.BaseDiagnosticsCollectionRequest)14 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)14 SdxClusterRequest (com.sequenceiq.sdx.api.model.SdxClusterRequest)14 Set (java.util.Set)14 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)13 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)12 Json (com.sequenceiq.cloudbreak.common.json.Json)12 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)12