class CloudbreakFlowService {

    public FlowState getLastKnownFlowState(SdxCluster sdxCluster) {
        try {
            if (sdxCluster.getLastCbFlowChainId() != null) {
                LOGGER.info("Checking cloudbreak {} {}", FlowType.FLOW_CHAIN, sdxCluster.getLastCbFlowChainId());
                Boolean hasActiveFlow = ThreadBasedUserCrnProvider.doAsInternalActor(() ->
                        flowEndpoint.hasFlowRunningByChainId(sdxCluster.getLastCbFlowChainId()).getHasActiveFlow());
                logCbFlowChainStatus(sdxCluster, hasActiveFlow);
                return getFlowState(hasActiveFlow);
            } else if (sdxCluster.getLastCbFlowId() != null) {
                LOGGER.info("Checking cloudbreak {} {}", FlowType.FLOW, sdxCluster.getLastCbFlowId());
                Boolean hasActiveFlow = ThreadBasedUserCrnProvider.doAsInternalActor(() ->
                        flowEndpoint.hasFlowRunningByFlowId(sdxCluster.getLastCbFlowId()).getHasActiveFlow());
                logCbFlowStatus(sdxCluster, hasActiveFlow);
                return getFlowState(hasActiveFlow);
            }
            return FlowState.UNKNOWN;
        } catch (NotFoundException e) {
            LOGGER.error("Flow chain id or resource {} not found in CB: {}, so there is no active flow!", sdxCluster.getClusterName(), e.getMessage());
            return FlowState.UNKNOWN;
        } catch (Exception e) {
            LOGGER.error("Exception occured during checking if there is a flow for cluster {} in CB: {}", sdxCluster.getClusterName(), e.getMessage());
            return FlowState.UNKNOWN;
        }
    }

}