Search in sources :

Example 1 with RecoveryV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryV4Response in project cloudbreak by hortonworks.

the class SdxRecoveryServiceTest method triggerCloudbreakRecovery.

@Test
public void triggerCloudbreakRecovery() {
    Long clusterId = cluster.getId();
    doNothing().when(cloudbreakFlowService).saveLastCloudbreakFlowChainId(any(), any());
    FlowIdentifier flowId = new FlowIdentifier(FlowType.FLOW, "FLOW_ID_1");
    RecoveryV4Response recoveryV4Response = new RecoveryV4Response(flowId);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(sdxService.getById(clusterId)).thenReturn(cluster);
    when(ThreadBasedUserCrnProvider.doAsInternalActor("crn:cdp:iam:us-west-1:cloudera:user:__internal__actor__", () -> stackV4Endpoint.recoverClusterByNameInternal(0L, cluster.getClusterName(), ThreadBasedUserCrnProvider.getUserCrn()))).thenReturn(recoveryV4Response);
    ThreadBasedUserCrnProvider.doAsInternalActor("crn:cdp:iam:us-west-1:cloudera:user:__internal__actor__", () -> underTest.recoverCluster(clusterId));
    verify(stackV4Endpoint).recoverClusterByNameInternal(eq(0L), eq(CLUSTER_NAME), nullable(String.class));
    verify(sdxStatusService, times(1)).setStatusForDatalakeAndNotify(DatalakeStatusEnum.RECOVERY_IN_PROGRESS, DATALAKE_RECOVERY_REQUESTED, "Recovering datalake stack", cluster);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) RecoveryV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryV4Response) Test(org.junit.jupiter.api.Test)

Example 2 with RecoveryV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryV4Response 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 3 with RecoveryV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryV4Response 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 4 with RecoveryV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryV4Response 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

Test (org.junit.jupiter.api.Test)4 RecoveryValidationV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryValidationV4Response)3 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)3 SdxRecoverableResponse (com.sequenceiq.sdx.api.model.SdxRecoverableResponse)3 SdxRecoveryResponse (com.sequenceiq.sdx.api.model.SdxRecoveryResponse)2 com.cloudera.thunderhead.service.datalakedr.datalakeDRProto (com.cloudera.thunderhead.service.datalakedr.datalakeDRProto)1 RecoveryV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryV4Response)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1