use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class FlowLogDBServiceTest method createFlowLog.
private FlowLog createFlowLog(String flowId) {
FlowLog flowLog = new FlowLog();
flowLog.setFlowId(flowId);
flowLog.setFlowChainId(flowId + "chain");
return flowLog;
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class FlowLogDBServiceTest method cancelTooOldTerminationFlowForResourceTest.
@Test
public void cancelTooOldTerminationFlowForResourceTest() throws TransactionService.TransactionExecutionException {
Set<FlowLogIdWithTypeAndTimestamp> flowLogs = new LinkedHashSet<>();
FlowLogIdWithTypeAndTimestamp flowLog2 = mock(FlowLogIdWithTypeAndTimestamp.class);
when(flowLog2.getFlowType()).thenReturn(ClassValue.of(Class.class));
flowLogs.add(flowLog2);
FlowLogIdWithTypeAndTimestamp flowLog1 = mock(FlowLogIdWithTypeAndTimestamp.class);
when(flowLog1.getFlowType()).thenReturn(ClassValue.of(TerminationFlowConfig.class));
when(flowLog1.getCreated()).thenReturn(9000L);
when(flowLog1.getFlowId()).thenReturn("flow1");
flowLogs.add(flowLog1);
when(flowLogRepository.findAllRunningFlowLogByResourceId(eq(1L))).thenReturn(flowLogs);
FlowLog realFlowLog1 = mock(FlowLog.class);
when(realFlowLog1.getId()).thenReturn(10L);
when(flowLogRepository.findFirstByFlowIdOrderByCreatedDesc(eq("flow1"))).thenReturn(Optional.of(realFlowLog1));
when(applicationFlowInformation.getTerminationFlow()).thenReturn(Collections.singletonList(TerminationFlowConfig.class));
when(transactionService.required(any(Supplier.class))).thenAnswer(invocation -> ((Supplier) invocation.getArguments()[0]).get());
when(nodeConfig.getId()).thenReturn("node1");
underTest.cancelTooOldTerminationFlowForResource(1L, 10000L);
verify(flowLogRepository).finalizeByFlowId(eq("flow1"));
verify(flowLogRepository, times(0)).finalizeByFlowId(eq("flow2"));
verify(flowLogRepository).updateLastLogStatusInFlow(eq(10L), eq(StateStatus.SUCCESSFUL));
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class FlowLogDBServiceTest method createFlowLog.
private FlowLog createFlowLog(boolean pending, String flowId) {
FlowLog flowLog = createFlowLog(flowId);
flowLog.setFinalized(!pending);
flowLog.setStateStatus(pending ? StateStatus.PENDING : StateStatus.SUCCESSFUL);
return flowLog;
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class SdxStopActions method failedAction.
@Bean(name = "SDX_STOP_FAILED_STATE")
public Action<?, ?> failedAction() {
return new AbstractSdxAction<>(SdxFailedEvent.class) {
@Override
protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxFailedEvent payload) {
return SdxContext.from(flowParameters, payload);
}
@Override
protected void doExecute(SdxContext context, SdxFailedEvent payload, Map<Object, Object> variables) throws Exception {
Exception exception = payload.getException();
DatalakeStatusEnum failedStatus = DatalakeStatusEnum.STOP_FAILED;
LOGGER.info("Update SDX status to {} for resource: {}", failedStatus, payload.getResourceId(), exception);
String statusReason = "SDX stop failed";
if (exception.getMessage() != null) {
statusReason = exception.getMessage();
}
Flow flow = getFlow(context.getFlowParameters().getFlowId());
flow.setFlowFailed(payload.getException());
// If this is part of DL resize, mark failure as such in order to enable proper recovery.
Optional<FlowLog> lastFlowLog = flowLogService.getLastFlowLog(context.getFlowParameters().getFlowId());
if (lastFlowLog.isPresent()) {
Optional<FlowChainLog> flowChainLog = flowChainLogService.findFirstByFlowChainIdOrderByCreatedDesc(lastFlowLog.get().getFlowChainId());
if (flowChainLog.isPresent() && flowChainLog.get().getFlowChainType().equals(DatalakeResizeFlowEventChainFactory.class.getSimpleName())) {
statusReason = "Datalake resize failure: " + statusReason;
}
}
eventSenderService.notifyEvent(context, ResourceEvent.SDX_STOP_FAILED);
sdxStatusService.setStatusForDatalakeAndNotify(failedStatus, statusReason, payload.getResourceId());
sendEvent(context, SDX_STOP_FAILED_HANDLED_EVENT.event(), payload);
}
@Override
protected Object getFailurePayload(SdxFailedEvent payload, Optional<SdxContext> flowContext, Exception ex) {
return null;
}
};
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class FlowRetryService method retry.
public RetryResponse retry(Long stackId) {
RetryableStateResponse retryableStateResponse = getRetryableStateResponse(stackId);
switch(retryableStateResponse.getState()) {
case FLOW_PENDING:
String flowPendingMessage = "Retry cannot be performed, because there is already an active flow.";
LOGGER.info(flowPendingMessage + " stackId: {}", stackId);
throw new BadRequestException(flowPendingMessage);
case LAST_NOT_FAILED_OR_NOT_RETRYABLE:
String notFailedOrNotRetryableMessage = "Retry cannot be performed. The last flow did not fail or not retryable." + retryableStateResponse.getLastKnownStateMessage();
LOGGER.info(notFailedOrNotRetryableMessage + " stackId: {}", stackId);
throw new BadRequestException(notFailedOrNotRetryableMessage);
case NO_SUCCESSFUL_STATE:
String noSuccessfulStateMessage = "Cannot restart previous flow because there is no successful state in the flow.";
LOGGER.info(noSuccessfulStateMessage + " stackId: {}", stackId);
throw new BadRequestException(noSuccessfulStateMessage);
case RETRYABLE:
FlowLog lastSuccessfulStateFlowLog = retryableStateResponse.getLastSuccessfulStateFlowLog();
flow2Handler.restartFlow(lastSuccessfulStateFlowLog);
if (lastSuccessfulStateFlowLog.getFlowChainId() != null) {
return new RetryResponse(retryableStateResponse.getName(), new FlowIdentifier(FlowType.FLOW_CHAIN, lastSuccessfulStateFlowLog.getFlowChainId()));
} else {
return new RetryResponse(retryableStateResponse.getName(), new FlowIdentifier(FlowType.FLOW, lastSuccessfulStateFlowLog.getFlowId()));
}
default:
throw new NotImplementedException("Retry state handling is not implemented: " + retryableStateResponse.getState());
}
}
Aggregations