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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations