Search in sources :

Example 6 with SdxRecoverableResponse

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

the class SdxRecoverySelectorService method validateRecovery.

public SdxRecoverableResponse validateRecovery(SdxCluster sdxCluster) {
    List<SdxRecoverableResponse> sdxRecoverableResponses = new ArrayList<>();
    SdxRecoverableResponse recoverableResponse;
    for (RecoveryService recoveryService : services) {
        try {
            recoverableResponse = recoveryService.validateRecovery(sdxCluster);
        } catch (Exception e) {
            recoverableResponse = interpretValidationError(sdxCluster, e);
        }
        sdxRecoverableResponses.add(recoverableResponse);
        if (recoverableResponse.getStatus().recoverable()) {
            return recoverableResponse;
        }
    }
    if (sdxRecoverableResponses.isEmpty()) {
        return new SdxRecoverableResponse("No valid Recovery Options available", RecoveryStatus.NON_RECOVERABLE);
    }
    if (sdxRecoverableResponses.size() == 1) {
        return sdxRecoverableResponses.get(0);
    }
    return new SdxRecoverableResponse(sdxRecoverableResponses.stream().map(SdxRecoverableResponse::getReason).collect(Collectors.joining(", ")), RecoveryStatus.NON_RECOVERABLE);
}
Also used : SdxRecoverableResponse(com.sequenceiq.sdx.api.model.SdxRecoverableResponse) ArrayList(java.util.ArrayList) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Example 7 with SdxRecoverableResponse

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

the class SdxUpgradeRecoveryServiceTest method testValidateStatusSuccessfulShouldStartRecoveryFlow.

@Test
public void testValidateStatusSuccessfulShouldStartRecoveryFlow() {
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    String reason = "Datalake upgrade recovery requested. Cluster will be terminated and re-launched with the original runtime.";
    RecoveryValidationV4Response recoveryV4Response = new RecoveryValidationV4Response(reason, RecoveryStatus.RECOVERABLE);
    when(stackV4Endpoint.getClusterRecoverableByNameInternal(WORKSPACE_ID, CLUSTER_NAME, USER_CRN)).thenReturn(recoveryV4Response);
    when(sdxReactorFlowManager.triggerDatalakeRuntimeRecoveryFlow(cluster, SdxRecoveryType.RECOVER_WITHOUT_DATA)).thenReturn(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"));
    SdxRecoverableResponse sdxRecoverableResponse = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.validateRecovery(cluster));
    assertEquals(reason, sdxRecoverableResponse.getReason());
    SdxRecoveryResponse response = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.triggerRecovery(cluster, request));
    assertEquals(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"), response.getFlowIdentifier());
}
Also used : RecoveryValidationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryValidationV4Response) SdxRecoverableResponse(com.sequenceiq.sdx.api.model.SdxRecoverableResponse) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) SdxRecoveryResponse(com.sequenceiq.sdx.api.model.SdxRecoveryResponse) Test(org.junit.jupiter.api.Test)

Example 8 with SdxRecoverableResponse

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

the class SdxUpgradeRecoveryServiceTest method testNonRecoverableStatusShouldReturnNonRecoverable.

@Test
public void testNonRecoverableStatusShouldReturnNonRecoverable() {
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    String errorMessage = "error message";
    RecoveryValidationV4Response recoveryV4Response = new RecoveryValidationV4Response(errorMessage, RecoveryStatus.NON_RECOVERABLE);
    when(stackV4Endpoint.getClusterRecoverableByNameInternal(WORKSPACE_ID, CLUSTER_NAME, USER_CRN)).thenReturn(recoveryV4Response);
    SdxRecoverableResponse sdxRecoverableResponse = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.validateRecovery(cluster));
    assertEquals(errorMessage, sdxRecoverableResponse.getReason());
}
Also used : RecoveryValidationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryValidationV4Response) SdxRecoverableResponse(com.sequenceiq.sdx.api.model.SdxRecoverableResponse) Test(org.junit.jupiter.api.Test)

Example 9 with SdxRecoverableResponse

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

the class SdxUpgradeRecoveryServiceTest method testValidateWithDataAndNonExistentBackupShouldThrowValidationError.

@Test
public void testValidateWithDataAndNonExistentBackupShouldThrowValidationError() {
    String errorMessage = "There is no successful backup taken yet for data lake cluster with runtime 7.2.2.";
    request.setType(SdxRecoveryType.RECOVER_WITH_DATA);
    when(cluster.getRuntime()).thenReturn(RUNTIME);
    when(datalakeDrClient.getLastSuccessfulBackup(CLUSTER_NAME, USER_CRN, Optional.of(RUNTIME))).thenReturn(null);
    SdxRecoverableResponse sdxRecoverableResponse = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.validateRecovery(cluster, request));
    assertEquals(errorMessage, sdxRecoverableResponse.getReason());
}
Also used : SdxRecoverableResponse(com.sequenceiq.sdx.api.model.SdxRecoverableResponse) Test(org.junit.jupiter.api.Test)

Example 10 with SdxRecoverableResponse

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

the class SdxUpgradeRecoveryServiceTest method testValidateWithDataAndSuccessfulBackupShouldStartRecoveryFlow.

@Test
public void testValidateWithDataAndSuccessfulBackupShouldStartRecoveryFlow() {
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    String reason = "There is no successful backup taken yet for data lake cluster with runtime 7.2.2.";
    RecoveryValidationV4Response recoveryV4Response = new RecoveryValidationV4Response(reason, RecoveryStatus.RECOVERABLE);
    request.setType(SdxRecoveryType.RECOVER_WITH_DATA);
    datalakeDRProto.DatalakeBackupInfo datalakeBackupInfo = datalakeDRProto.DatalakeBackupInfo.newBuilder().setRuntimeVersion(RUNTIME).setOverallState("SUCCESSFUL").build();
    when(cluster.getRuntime()).thenReturn(RUNTIME);
    when(stackV4Endpoint.getClusterRecoverableByNameInternal(WORKSPACE_ID, CLUSTER_NAME, USER_CRN)).thenReturn(recoveryV4Response);
    when(datalakeDrClient.getLastSuccessfulBackup(CLUSTER_NAME, USER_CRN, Optional.of(RUNTIME))).thenReturn(datalakeBackupInfo);
    when(sdxReactorFlowManager.triggerDatalakeRuntimeRecoveryFlow(cluster, SdxRecoveryType.RECOVER_WITH_DATA)).thenReturn(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"));
    SdxRecoverableResponse sdxRecoverableResponse = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.validateRecovery(cluster, request));
    assertEquals(reason, sdxRecoverableResponse.getReason());
    SdxRecoveryResponse response = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.triggerRecovery(cluster, request));
    assertEquals(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"), response.getFlowIdentifier());
}
Also used : RecoveryValidationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryValidationV4Response) SdxRecoverableResponse(com.sequenceiq.sdx.api.model.SdxRecoverableResponse) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) com.cloudera.thunderhead.service.datalakedr.datalakeDRProto(com.cloudera.thunderhead.service.datalakedr.datalakeDRProto) SdxRecoveryResponse(com.sequenceiq.sdx.api.model.SdxRecoveryResponse) Test(org.junit.jupiter.api.Test)

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