Search in sources :

Example 36 with BadRequestException

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

the class SdxRuntimeUpgradeServiceTest method testTriggerRuntimeUpgradeByNameWhenNotEnabledAndNoPatchUpgrades.

@Test
public void testTriggerRuntimeUpgradeByNameWhenNotEnabledAndNoPatchUpgrades() {
    ImageInfoV4Response currentImageInfo = new ImageInfoV4Response();
    currentImageInfo.setImageId(IMAGE_ID);
    currentImageInfo.setCreated(1);
    currentImageInfo.setComponentVersions(creatImageComponentVersions(MATCHING_TARGET_RUNTIME, MATCHING_TARGET_RUNTIME));
    ImageInfoV4Response imageInfo = new ImageInfoV4Response();
    imageInfo.setImageId(IMAGE_ID);
    imageInfo.setCreated(1);
    imageInfo.setComponentVersions(creatImageComponentVersions("7.2.0", "7.2.0"));
    ImageInfoV4Response imageInfo2 = new ImageInfoV4Response();
    imageInfo2.setImageId(IMAGE_ID_LAST);
    imageInfo2.setCreated(2);
    imageInfo2.setComponentVersions(creatImageComponentVersions("7.3.0", "7.3.0"));
    List<ImageInfoV4Response> candidates = List.of(imageInfo, imageInfo2);
    response.setCurrent(currentImageInfo);
    response.setUpgradeCandidates(candidates);
    SdxUpgradeResponse expectedResponse = new SdxUpgradeResponse(response.getCurrent(), List.of(), "Something went wrong", response.getFlowIdentifier());
    when(entitlementService.runtimeUpgradeEnabled(any())).thenReturn(false);
    when(stackV4Endpoint.checkForClusterUpgradeByName(anyLong(), anyString(), any(), anyString())).thenReturn(response);
    when(sdxUpgradeClusterConverter.upgradeResponseToSdxUpgradeResponse(any(UpgradeV4Response.class))).thenReturn(expectedResponse);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    BadRequestException exception = assertThrows(BadRequestException.class, () -> underTest.triggerUpgradeByName(USER_CRN, STACK_NAME, sdxUpgradeRequest, ACCOUNT_ID));
    assertTrue(exception.getMessage().contains("Something went wrong"));
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) SdxUpgradeResponse(com.sequenceiq.sdx.api.model.SdxUpgradeResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) Test(org.junit.jupiter.api.Test)

Example 37 with BadRequestException

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

the class SdxRuntimeUpgradeServiceTest method testNoImageFound.

@Test
public void testNoImageFound() {
    when(sdxService.getByCrn(anyString(), anyString())).thenReturn(sdxCluster);
    when(stackV4Endpoint.checkForClusterUpgradeByName(anyLong(), anyString(), any(), anyString())).thenReturn(response);
    when(sdxUpgradeClusterConverter.upgradeResponseToSdxUpgradeResponse(response)).thenReturn(sdxUpgradeResponse);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    response.setUpgradeCandidates(new ArrayList<>());
    sdxUpgradeResponse.setUpgradeCandidates(new ArrayList<>());
    BadRequestException exception = assertThrows(BadRequestException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.triggerUpgradeByCrn(USER_CRN, STACK_CRN, sdxUpgradeRequest, ACCOUNT_ID)));
    assertEquals("There is no compatible image to upgrade for stack " + sdxCluster.getClusterName(), exception.getMessage());
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 38 with BadRequestException

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

the class DiagnosticsCollectionValidatorTest method testWithCloudStorageWithDisabledLogging.

@Test
void testWithCloudStorageWithDisabledLogging() {
    BaseDiagnosticsCollectionRequest request = new BaseDiagnosticsCollectionRequest();
    request.setDestination(DiagnosticsDestination.CLOUD_STORAGE);
    StackV4Response stackV4Response = new StackV4Response();
    stackV4Response.setCrn(DATALAKE_CRN);
    TelemetryResponse telemetry = new TelemetryResponse();
    stackV4Response.setTelemetry(telemetry);
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> underTest.validate(request, stackV4Response));
    assertTrue(thrown.getMessage().contains("Cloud storage logging is disabled for Data Lake"));
}
Also used : TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) BaseDiagnosticsCollectionRequest(com.sequenceiq.common.api.diagnostics.BaseDiagnosticsCollectionRequest) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 39 with BadRequestException

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

the class DiagnosticsCollectionValidatorTest method testWithEngDestinationAndDisabledLogCollection.

@Test
void testWithEngDestinationAndDisabledLogCollection() {
    BaseDiagnosticsCollectionRequest request = new BaseDiagnosticsCollectionRequest();
    request.setDestination(DiagnosticsDestination.ENG);
    StackV4Response stackV4Response = new StackV4Response();
    stackV4Response.setCrn(DATALAKE_CRN);
    TelemetryResponse telemetry = new TelemetryResponse();
    stackV4Response.setTelemetry(telemetry);
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> underTest.validate(request, stackV4Response));
    assertTrue(thrown.getMessage().contains("Cluster log collection is not enabled for Data Lake"));
}
Also used : TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) BaseDiagnosticsCollectionRequest(com.sequenceiq.common.api.diagnostics.BaseDiagnosticsCollectionRequest) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 40 with BadRequestException

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

the class SdxRepairSettingsTest method throwsExceptionWhenHostGroupAndNodeIdsAreSpecified.

@Test
void throwsExceptionWhenHostGroupAndNodeIdsAreSpecified() {
    SdxRepairRequest request = new SdxRepairRequest();
    request.setHostGroupName("hg1");
    request.setNodesIds(List.of("node1", "node2"));
    BadRequestException exception = assertThrows(BadRequestException.class, () -> SdxRepairSettings.from(request));
    assertEquals("Please select one host group ('hostGroupName'), multiple host groups ('hostGroupNames'), or nodes ('nodesIds').", exception.getMessage());
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) SdxRepairRequest(com.sequenceiq.sdx.api.model.SdxRepairRequest) Test(org.junit.jupiter.api.Test)

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