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;
}
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());
}
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()));
}
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));
}
}
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());
}
Aggregations