use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class ExistingStackPatchService method apply.
/**
* @param stack the stack to apply the patch for
* @return whether the patch was applied successfully
* @throws ExistingStackPatchApplyException when something unexpected goes wrong while applying the patch
*/
public boolean apply(Stack stack) throws ExistingStackPatchApplyException {
if (flowLogService.isOtherFlowRunning(stack.getId())) {
LOGGER.info("Another flow is running for stack {}, skipping patch apply to let the flow finish", stack.getResourceCrn());
return false;
} else {
Optional<FlowLog> lastRetryableFailedFlow = flowRetryService.getLastRetryableFailedFlow(stack.getId());
if (lastRetryableFailedFlow.isEmpty()) {
try {
LOGGER.info("Starting stack {} patching for {}", stack.getResourceCrn(), getStackPatchType());
boolean success = checkedMeasure(() -> doApply(stack), LOGGER, "Existing stack patching took {} ms for stack {} and patch {}.", stack.getResourceCrn(), getStackPatchType());
if (success) {
LOGGER.info("Stack {} was patched successfully for {}", stack.getResourceCrn(), getStackPatchType());
stackPatchRepository.save(new StackPatch(stack, getStackPatchType()));
} else {
LOGGER.info("Stack {} was not patched for {}", stack.getResourceCrn(), getStackPatchType());
}
return success;
} catch (ExistingStackPatchApplyException e) {
throw e;
} catch (Exception e) {
String message = String.format("Something unexpected went wrong with stack %s while applying patch %s", stack.getResourceCrn(), getStackPatchType());
throw new ExistingStackPatchApplyException(message, e);
}
} else {
LOGGER.info("Stack {} has a retryable failed flow, skipping patch apply to preserve possible retry", stack.getResourceCrn());
return false;
}
}
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class CcmUpgradeFlowIntegrationTest method testCcmUpgradeWhenReRegisterFail.
@Test
public void testCcmUpgradeWhenReRegisterFail() {
doThrow(new BadRequestException()).when(ccmUpgradeService).reregister(STACK_ID);
FlowIdentifier flowIdentifier = triggerFlow();
letItFlow(flowIdentifier);
ArgumentCaptor<FlowLog> flowLog = ArgumentCaptor.forClass(FlowLog.class);
verify(flowLogRepository, times(2)).save(flowLog.capture());
Assertions.assertTrue(flowLog.getAllValues().stream().anyMatch(f -> f.getFinalized()), "flow has not finalized");
verify(ccmUpgradeService, times(1)).prepare(STACK_ID);
verify(ccmUpgradeService, times(1)).ccmUpgradeFailed(STACK_ID);
verify(ccmUpgradeService, times(1)).reregister(STACK_ID);
verify(ccmUpgradeService, never()).ccmUpgradePreparationFailed(STACK_ID);
verify(ccmUpgradeService, never()).unregister(STACK_ID);
verify(ccmUpgradeService, never()).removeAutoSsh(STACK_ID);
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class CcmUpgradeFlowIntegrationTest method testCcmUpgradeWhenPrepFail.
@Test
public void testCcmUpgradeWhenPrepFail() {
doThrow(new BadRequestException()).when(ccmUpgradeService).prepare(STACK_ID);
FlowIdentifier flowIdentifier = triggerFlow();
letItFlow(flowIdentifier);
ArgumentCaptor<FlowLog> flowLog = ArgumentCaptor.forClass(FlowLog.class);
verify(flowLogRepository, times(2)).save(flowLog.capture());
Assertions.assertTrue(flowLog.getAllValues().stream().anyMatch(f -> f.getFinalized()), "flow has not finalized");
verify(ccmUpgradeService, times(1)).prepare(STACK_ID);
verify(ccmUpgradeService, times(1)).ccmUpgradePreparationFailed(STACK_ID);
verify(ccmUpgradeService, never()).ccmUpgradeFailed(STACK_ID);
verify(ccmUpgradeService, never()).reregister(STACK_ID);
verify(ccmUpgradeService, never()).unregister(STACK_ID);
verify(ccmUpgradeService, never()).removeAutoSsh(STACK_ID);
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class TerminationTriggerService method handleIfStackIsNotTerminated.
private void handleIfStackIsNotTerminated(Stack stack, boolean forced) {
LOGGER.info("stack {} in environment {} is not deleted. Current termination request is {}", stack.getName(), stack.getEnvironmentCrn(), getForcedOrNotString(forced));
Optional<FlowLog> optionalFlowLog = findLatestTerminationFlowLogWithInitState(stack);
if (optionalFlowLog.isPresent()) {
FlowLog flowLog = optionalFlowLog.get();
LOGGER.debug("Found termination flowlog with id [{}] and payload [{}]", flowLog.getFlowId(), flowLog.getPayload());
handleIfFlowLogExistsForTermination(stack, forced, flowLog);
} else {
LOGGER.debug("Couldn't find termination FlowLog with 'INIT_STATE'. Triggering termination");
fireTerminationEvent(stack, forced);
}
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class Flow2Handler method handleFlowConflict.
private AcceptResult handleFlowConflict(String key, Payload payload, String flowChainId, Set<FlowLogIdWithTypeAndTimestamp> flowLogItems) {
AcceptResult acceptResult = null;
Optional<FlowLog> initFlowLog = flowLogService.findAllByFlowIdOrderByCreatedDesc(flowLogItems.iterator().next().getFlowId()).stream().min(Comparator.comparing(FlowLog::getCreated));
if (initFlowLog.isPresent()) {
LOGGER.info("Found previous init flow log: {}", initFlowLog.get());
if (NullUtil.allNotNull(initFlowLog.get().getFlowChainId(), flowChainId)) {
Optional<Pair<String, Payload>> previousTrigger = flowChains.getRootTriggerEvent(initFlowLog.get().getFlowChainId());
Optional<Pair<String, Payload>> currentTrigger = flowChains.getRootTriggerEvent(flowChainId);
if (previousTrigger.isPresent() && currentTrigger.isPresent()) {
if (isIdempotentTriggers(previousTrigger.get().getRight(), currentTrigger.get().getRight())) {
LOGGER.info("Idempotent flow chain trigger. Running {}, requested {}", previousTrigger, currentTrigger);
acceptResult = FlowAcceptResult.runningInFlowChain(previousTrigger.get().getLeft());
}
}
} else if (NullUtil.allNull(initFlowLog.get().getFlowChainId(), flowChainId)) {
Payload previousTrigger = FlowLogUtil.tryDeserializePayload(initFlowLog.get());
if (isIdempotentTriggers(previousTrigger, payload)) {
LOGGER.info("Idempotent flow trigger. Running {}, requested {}", previousTrigger, payload);
acceptResult = FlowAcceptResult.runningInFlow(initFlowLog.get().getFlowId());
}
}
}
if (acceptResult == null) {
LOGGER.info("Flow operation not allowed, other flow is running. Resource ID {}, event {}", payload.getResourceId(), key);
acceptResult = FlowAcceptResult.alreadyExistingFlow(flowLogItems);
}
flowChains.removeFullFlowChain(flowChainId, false);
return acceptResult;
}
Aggregations