Search in sources :

Example 1 with SdxRecoverableResponse

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

the class ResizeRecoveryServiceTest method testEmptyFlowLogValidateNonRecoverable.

@Test
public void testEmptyFlowLogValidateNonRecoverable() {
    lenient().when(flow2Handler.getFirstStateLogfromLatestFlow(cluster.getId())).thenReturn(Optional.empty());
    sdxStatusEntity.setStatus(DatalakeStatusEnum.REQUESTED);
    SdxRecoverableResponse sdxRecoverableResponse = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.validateRecovery(cluster));
    assertEquals(RecoveryStatus.NON_RECOVERABLE, sdxRecoverableResponse.getStatus(), "No recent flowlog should be non-recoverable");
}
Also used : SdxRecoverableResponse(com.sequenceiq.sdx.api.model.SdxRecoverableResponse) Test(org.junit.jupiter.api.Test)

Example 2 with SdxRecoverableResponse

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

the class SdxRecoverySelectorServiceTest method testRecoveryServiceCanValidateResizeRecovery.

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

Example 3 with SdxRecoverableResponse

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

the class ResizeRecoveryServiceTest method testNoEntitlementValidate.

@Test
public void testNoEntitlementValidate() {
    when(entitlementService.isDatalakeResizeRecoveryEnabled(anyString())).thenReturn(false);
    sdxStatusEntity.setStatus(STOP_FAILED);
    SdxRecoverableResponse sdxRecoverableResponse = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.validateRecovery(cluster));
    assertEquals(RecoveryStatus.NON_RECOVERABLE, sdxRecoverableResponse.getStatus());
    assertEquals("Resize Recovery entitlement not enabled", sdxRecoverableResponse.getReason());
}
Also used : SdxRecoverableResponse(com.sequenceiq.sdx.api.model.SdxRecoverableResponse) Test(org.junit.jupiter.api.Test)

Example 4 with SdxRecoverableResponse

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

the class ResizeRecoveryServiceTest method testGetClusterRecoverableForStatusNotRecoverable.

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

Example 5 with SdxRecoverableResponse

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

the class SdxUpgradeRecoveryService method validateRecovery.

@Override
public SdxRecoverableResponse validateRecovery(SdxCluster sdxCluster, SdxRecoveryRequest request) {
    MDCBuilder.buildMdcContext(sdxCluster);
    try {
        String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
        if (Objects.nonNull(request) && request.getType() == SdxRecoveryType.RECOVER_WITH_DATA) {
            String clusterRuntime = sdxCluster.getRuntime();
            datalakeDRProto.DatalakeBackupInfo lastSuccessfulBackup = datalakeDrClient.getLastSuccessfulBackup(sdxCluster.getClusterName(), initiatorUserCrn, Optional.of(clusterRuntime));
            if (Objects.isNull(lastSuccessfulBackup)) {
                return new SdxRecoverableResponse("There is no successful backup taken yet for data lake cluster with runtime " + clusterRuntime + ".", RecoveryStatus.NON_RECOVERABLE);
            }
        }
        RecoveryValidationV4Response response = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.getClusterRecoverableByNameInternal(0L, sdxCluster.getClusterName(), initiatorUserCrn));
        return new SdxRecoverableResponse(response.getReason(), response.getStatus());
    } catch (WebApplicationException e) {
        String exceptionMessage = exceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Stack recovery validation failed on cluster: [%s]. Message: [%s]", sdxCluster.getClusterName(), exceptionMessage);
        throw new CloudbreakApiException(message, e);
    }
}
Also used : RecoveryValidationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryValidationV4Response) WebApplicationException(javax.ws.rs.WebApplicationException) SdxRecoverableResponse(com.sequenceiq.sdx.api.model.SdxRecoverableResponse) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) com.cloudera.thunderhead.service.datalakedr.datalakeDRProto(com.cloudera.thunderhead.service.datalakedr.datalakeDRProto)

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