use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class DatalakeRestoreActions method triggerDatalakeRestore.
@Bean(name = "DATALAKE_TRIGGERING_RESTORE_STATE")
public Action<?, ?> triggerDatalakeRestore() {
return new AbstractSdxAction<>(DatalakeTriggerRestoreEvent.class) {
@Override
protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, DatalakeTriggerRestoreEvent payload) {
// When SDX is created as part of re-size flow chain, SDX in payload will not have the correct ID.
Optional<FlowLog> lastFlowLog = flowLogService.getLastFlowLog(flowParameters.getFlowId());
if (lastFlowLog.isPresent()) {
SdxContext sdxContext;
Optional<FlowChainLog> flowChainLog = flowChainLogService.findFirstByFlowChainIdOrderByCreatedDesc(lastFlowLog.get().getFlowChainId());
if (flowChainLog.isPresent() && flowChainLog.get().getFlowChainType().equals(DatalakeResizeFlowEventChainFactory.class.getSimpleName())) {
SdxCluster sdxCluster = sdxService.getByNameInAccount(payload.getUserId(), payload.getSdxName());
LOGGER.info("Updating the Sdx-id in context from {} to {}", payload.getResourceId(), sdxCluster.getId());
payload.getDrStatus().setSdxClusterId(sdxCluster.getId());
sdxContext = SdxContext.from(flowParameters, payload);
sdxContext.setSdxId(sdxCluster.getId());
return sdxContext;
}
}
return SdxContext.from(flowParameters, payload);
}
@Override
protected void prepareExecution(DatalakeTriggerRestoreEvent payload, Map<Object, Object> variables) {
super.prepareExecution(payload, variables);
}
@Override
protected void doExecute(SdxContext context, DatalakeTriggerRestoreEvent payload, Map<Object, Object> variables) {
DatalakeRestoreStatusResponse restoreStatusResponse = sdxBackupRestoreService.triggerDatalakeRestore(context.getSdxId(), payload.getBackupId(), payload.getBackupLocationOverride(), payload.getUserId());
variables.put(RESTORE_ID, restoreStatusResponse.getRestoreId());
variables.put(BACKUP_ID, restoreStatusResponse.getBackupId());
variables.put(OPERATION_ID, restoreStatusResponse.getRestoreId());
payload.getDrStatus().setOperationId(restoreStatusResponse.getRestoreId());
if (!restoreStatusResponse.failed()) {
sendEvent(context, DatalakeDatabaseRestoreStartEvent.from(payload, context.getSdxId(), restoreStatusResponse.getBackupId(), restoreStatusResponse.getRestoreId()));
} else {
LOGGER.error("Datalake restore has failed for {} ", context.getSdxId());
sendEvent(context, DATALAKE_RESTORE_FAILED_EVENT.event(), payload);
}
}
@Override
protected Object getFailurePayload(DatalakeTriggerRestoreEvent payload, Optional<SdxContext> flowContext, Exception ex) {
return DatalakeRestoreFailedEvent.from(flowContext, payload, ex);
}
};
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class SdxRetryServiceTest method retryAndRestartFlowIfStackCreationInProgressWasTheLastFailedState.
@Test
public void retryAndRestartFlowIfStackCreationInProgressWasTheLastFailedState() {
SdxCluster sdxCluster = new SdxCluster();
sdxCluster.setId(1L);
sdxCluster.setClusterName("sdxclustername");
sdxCluster.setAccountId("accountid");
FlowLog successfulFlowLog = new FlowLog();
successfulFlowLog.setFlowId("FLOW_ID_1");
successfulFlowLog.setStateStatus(StateStatus.SUCCESSFUL);
successfulFlowLog.setNextEvent(SDX_STACK_CREATION_IN_PROGRESS_EVENT.name());
successfulFlowLog.setCreated(1L);
successfulFlowLog.setCurrentState(SDX_CREATION_WAIT_RDS_STATE.name());
successfulFlowLog.setFlowType(ClassValue.of(SdxCreateFlowConfig.class));
doAnswer(invocation -> {
((Consumer<FlowLog>) invocation.getArgument(1)).accept(successfulFlowLog);
return null;
}).when(flow2Handler).retryLastFailedFlow(anyLong(), any());
when(flow2Handler.getFirstRetryableStateLogfromLatestFlow(anyLong())).thenReturn(successfulFlowLog);
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
sdxRetryService.retrySdx(sdxCluster);
verify(stackV4Endpoint, times(1)).retry(any(), eq("sdxclustername"), anyString());
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class SdxRetryServiceTest method retryOnBackupRestoreFailure.
@Test
public void retryOnBackupRestoreFailure() {
SdxCluster sdxCluster = new SdxCluster();
sdxCluster.setId(1L);
sdxCluster.setClusterName("sdxclustername");
FlowLog successfulFlowLog = new FlowLog();
successfulFlowLog.setFlowId("FLOW_ID_1");
successfulFlowLog.setStateStatus(StateStatus.SUCCESSFUL);
successfulFlowLog.setNextEvent(DATALAKE_TRIGGER_RESTORE_EVENT.name());
successfulFlowLog.setCreated(1L);
successfulFlowLog.setCurrentState(INIT_STATE.name());
successfulFlowLog.setFlowType(ClassValue.of(DatalakeRestoreFlowConfig.class));
when(flow2Handler.getFirstRetryableStateLogfromLatestFlow(anyLong())).thenReturn(successfulFlowLog);
sdxRetryService.retrySdx(sdxCluster);
verify(flow2Handler, times(1)).retryLastFailedFlowFromStart(any());
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class SdxRetryServiceTest method retryOnBackupBackupFailure.
@Test
public void retryOnBackupBackupFailure() {
SdxCluster sdxCluster = new SdxCluster();
sdxCluster.setId(1L);
sdxCluster.setClusterName("sdxclustername");
FlowLog successfulFlowLog = new FlowLog();
successfulFlowLog.setFlowId("FLOW_ID_1");
successfulFlowLog.setStateStatus(StateStatus.SUCCESSFUL);
successfulFlowLog.setNextEvent(DATALAKE_TRIGGER_BACKUP_EVENT.name());
successfulFlowLog.setCreated(1L);
successfulFlowLog.setCurrentState(INIT_STATE.name());
successfulFlowLog.setFlowType(ClassValue.of(DatalakeRestoreFlowConfig.class));
when(flow2Handler.getFirstRetryableStateLogfromLatestFlow(anyLong())).thenReturn(successfulFlowLog);
sdxRetryService.retrySdx(sdxCluster);
verify(flow2Handler, times(1)).retryLastFailedFlowFromStart(any());
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class FlowProgressResponseConverter method convert.
public FlowProgressResponse convert(List<FlowLog> flowLogs, String resourceCrn) {
FlowProgressResponse response = new FlowProgressResponse();
if (CollectionUtils.isNotEmpty(flowLogs)) {
FlowLog lastFlowLog = flowLogs.get(0);
Optional<String> flowTypeOpt = flowLogs.stream().filter(fl -> fl.getFlowType() != null).findFirst().map(fl -> fl.getFlowType().getClassValue().getName());
FlowLog firstFlowLog = flowLogs.get(flowLogs.size() - 1);
response.setFlowId(lastFlowLog.getFlowId());
response.setFlowChainId(lastFlowLog.getFlowChainId());
Integer prgoressFromSteps = flowTypeOpt.map(s -> flowProgressHolder.getProgressPercentageForState(s, lastFlowLog.getCurrentState())).orElse(UNKNOWN_PROGRESS_PERCENTAGE);
response.setProgress(prgoressFromSteps);
response.setMaxNumberOfTransitions(flowTypeOpt.map(flowProgressHolder::getTransitionsSize).orElse(null));
List<FlowLog> reversedFlowLogs = flowLogs.stream().sorted(Comparator.comparingLong(FlowLog::getCreated)).collect(Collectors.toList());
response.setTransitions(createFlowStateTransitions(reversedFlowLogs, firstFlowLog.getCreated()));
response.setFinalized(lastFlowLog.getFinalized());
response.setCreated(firstFlowLog.getCreated());
if (lastFlowLog.getFinalized()) {
response.setElapsedTimeInSeconds(getRoundedTimeInSeconds(firstFlowLog.getCreated(), lastFlowLog.getCreated()));
response.setProgress(FINISHED_PERCENTAGE);
} else {
response.setElapsedTimeInSeconds(getRoundedTimeInSeconds(firstFlowLog.getCreated(), new Date().getTime()));
}
response.setResourceCrn(resourceCrn);
}
return response;
}
Aggregations