Search in sources :

Example 11 with SdxRecoverableResponse

use of com.sequenceiq.sdx.api.model.SdxRecoverableResponse in project cloudbreak by hortonworks.

the class SdxRecoverySelectorServiceTest method testNoValidRecoveryValidation.

@Test
public void testNoValidRecoveryValidation() {
    SdxRecoverableResponse nonrecoverableResponse2 = new SdxRecoverableResponse("Some non reason2", RecoveryStatus.NON_RECOVERABLE);
    when(mockResizeRecoveryService.validateRecovery(cluster)).thenReturn(nonrecoverableResponse);
    when(mockSdxUpgradeRecoveryService.validateRecovery(cluster)).thenReturn(nonrecoverableResponse2);
    SdxRecoverableResponse result = sdxRecoverySelectorService.validateRecovery(cluster);
    Mockito.verify(mockResizeRecoveryService).validateRecovery(cluster);
    Mockito.verify(mockSdxUpgradeRecoveryService).validateRecovery(cluster);
    assertNotNull(result);
    assertTrue(result.getStatus().nonRecoverable());
    // "Some non reason, Some non reason2" order independent
    assertEquals(33, result.getReason().length(), result.getReason());
}
Also used : SdxRecoverableResponse(com.sequenceiq.sdx.api.model.SdxRecoverableResponse) Test(org.junit.Test)

Example 12 with SdxRecoverableResponse

use of com.sequenceiq.sdx.api.model.SdxRecoverableResponse in project cloudbreak by hortonworks.

the class SdxRecoverySelectorServiceTest method testNoValidRecoveryTrigger.

@Test
public void testNoValidRecoveryTrigger() {
    SdxRecoverableResponse nonrecoverableResponse2 = new SdxRecoverableResponse("Some non reason2", RecoveryStatus.NON_RECOVERABLE);
    SdxRecoveryRequest request = new SdxRecoveryRequest();
    when(mockResizeRecoveryService.validateRecovery(cluster, request)).thenReturn(nonrecoverableResponse);
    when(mockSdxUpgradeRecoveryService.validateRecovery(cluster, request)).thenReturn(nonrecoverableResponse2);
    BadRequestException result = assertThrows(BadRequestException.class, () -> sdxRecoverySelectorService.triggerRecovery(cluster, request));
    Mockito.verify(mockResizeRecoveryService).validateRecovery(cluster, request);
    Mockito.verify(mockSdxUpgradeRecoveryService).validateRecovery(cluster, request);
    Mockito.verify(mockSdxUpgradeRecoveryService, never()).triggerRecovery(cluster, request);
    Mockito.verify(mockSdxUpgradeRecoveryService, never()).triggerRecovery(cluster, request);
    assertNotNull(result);
    assertEquals(33, result.getMessage().length(), result.getMessage());
}
Also used : SdxRecoverableResponse(com.sequenceiq.sdx.api.model.SdxRecoverableResponse) SdxRecoveryRequest(com.sequenceiq.sdx.api.model.SdxRecoveryRequest) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.Test)

Example 13 with SdxRecoverableResponse

use of com.sequenceiq.sdx.api.model.SdxRecoverableResponse in project cloudbreak by hortonworks.

the class SdxRecoverySelectorServiceTest method testRecoveryServiceCanValidateUpgradeFailureByClusterName.

@Test
public void testRecoveryServiceCanValidateUpgradeFailureByClusterName() {
    setUpgradeTest();
    SdxRecoverableResponse result = sdxRecoverySelectorService.validateRecovery(cluster);
    // Basically, just check that we pass through
    Mockito.verify(mockSdxUpgradeRecoveryService).validateRecovery(cluster);
    assertNotNull(result);
    assertEquals(recoverableResponse, result);
}
Also used : SdxRecoverableResponse(com.sequenceiq.sdx.api.model.SdxRecoverableResponse) Test(org.junit.Test)

Example 14 with SdxRecoverableResponse

use of com.sequenceiq.sdx.api.model.SdxRecoverableResponse in project cloudbreak by hortonworks.

the class ResizeRecoveryServiceTest method testGetClusterRecoverableForStatusRecoverable.

public void testGetClusterRecoverableForStatusRecoverable(DatalakeStatusEnum status) {
    sdxStatusEntity.setStatus(status);
    SdxRecoverableResponse sdxRecoverableResponse = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.validateRecovery(cluster));
    assertEquals(RecoveryStatus.RECOVERABLE, sdxRecoverableResponse.getStatus(), status + " should be recoverable");
}
Also used : SdxRecoverableResponse(com.sequenceiq.sdx.api.model.SdxRecoverableResponse)

Example 15 with SdxRecoverableResponse

use of com.sequenceiq.sdx.api.model.SdxRecoverableResponse in project cloudbreak by hortonworks.

the class SdxRecoverySelectorService method triggerRecovery.

public SdxRecoveryResponse triggerRecovery(SdxCluster sdxCluster, SdxRecoveryRequest sdxRecoveryRequest) {
    List<String> responseReasons = new ArrayList<>();
    SdxRecoverableResponse recoverableResponse;
    for (RecoveryService recoveryService : services) {
        try {
            recoverableResponse = recoveryService.validateRecovery(sdxCluster, sdxRecoveryRequest);
        } catch (Exception e) {
            recoverableResponse = interpretValidationError(sdxCluster, e);
        }
        responseReasons.add(recoverableResponse.getReason());
        if (recoverableResponse.getStatus().recoverable()) {
            return recoveryService.triggerRecovery(sdxCluster, sdxRecoveryRequest);
        }
    }
    String reasons = String.join(", ", responseReasons);
    LOGGER.debug("Cluster is not in a recoverable state with message(s): {}", reasons);
    throw new BadRequestException(reasons);
}
Also used : SdxRecoverableResponse(com.sequenceiq.sdx.api.model.SdxRecoverableResponse) ArrayList(java.util.ArrayList) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Aggregations

SdxRecoverableResponse (com.sequenceiq.sdx.api.model.SdxRecoverableResponse)18 Test (org.junit.jupiter.api.Test)6 RecoveryValidationV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryValidationV4Response)5 Test (org.junit.Test)4 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)3 com.cloudera.thunderhead.service.datalakedr.datalakeDRProto (com.cloudera.thunderhead.service.datalakedr.datalakeDRProto)2 CloudbreakApiException (com.sequenceiq.cloudbreak.exception.CloudbreakApiException)2 SdxStatusEntity (com.sequenceiq.datalake.entity.SdxStatusEntity)2 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)2 SdxRecoveryResponse (com.sequenceiq.sdx.api.model.SdxRecoveryResponse)2 ArrayList (java.util.ArrayList)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 DatalakeStatusEnum (com.sequenceiq.datalake.entity.DatalakeStatusEnum)1 FlowLog (com.sequenceiq.flow.domain.FlowLog)1 SdxRecoveryRequest (com.sequenceiq.sdx.api.model.SdxRecoveryRequest)1