@Test public void testSaveFlowInfoResetWhenThereIsNoFlow() { SdxCluster cluster = new SdxCluster(); cluster.setLastCbFlowChainId(FLOW_CHAIN_ID); cluster.setInitiatorUserCrn(USER_CRN); cluster.setClusterName(CLUSTER_NAME); when(flowEndpoint.getLastFlowByResourceName(anyString())).thenThrow(new NotFoundException("something")); underTest.saveLastCloudbreakFlowChainId(cluster, null); verify(flowEndpoint).getLastFlowByResourceName(anyString()); verify(sdxClusterRepository).save(clusterCaptor.capture()); assertNull(clusterCaptor.getValue().getLastCbFlowId()); assertNull(clusterCaptor.getValue().getLastCbFlowChainId()); }
public void saveLastCloudbreakFlowChainId(SdxCluster sdxCluster, FlowIdentifier flowIdentifier) { if (flowIdentifier == null) { LOGGER.info("Cloudbreak not sent flow identifier for cluster falling back to flow API."); trySaveLastCbFlowIdOrFlowChainId(sdxCluster); } else { LOGGER.info("Received cloudbreak flow identifier {} for cluster {}", flowIdentifier, sdxCluster.getClusterName()); switch (flowIdentifier.getType()) { case FLOW: setFlowIdAndResetFlowChainId(sdxCluster, flowIdentifier.getPollableId()); break; case FLOW_CHAIN: setFlowChainIdAndResetFlowId(sdxCluster, flowIdentifier.getPollableId()); break; case NOT_TRIGGERED: resetFlowIdAndFlowChainId(sdxCluster); break; default: throw new IllegalArgumentException("Unsupported flow type " + flowIdentifier.getType()); } sdxClusterRepository.save(sdxCluster); } }
CloudbreakFlowService { public void saveLastCloudbreakFlowChainId(SdxCluster sdxCluster, FlowIdentifier flowIdentifier) { if (flowIdentifier == null) { LOGGER.info("Cloudbreak not sent flow identifier for cluster falling back to flow API."); trySaveLastCbFlowIdOrFlowChainId(sdxCluster); } else { LOGGER.info("Received cloudbreak flow identifier {} for cluster {}", flowIdentifier, sdxCluster.getClusterName()); switch (flowIdentifier.getType()) { case FLOW: setFlowIdAndResetFlowChainId(sdxCluster, flowIdentifier.getPollableId()); break; case FLOW_CHAIN: setFlowChainIdAndResetFlowId(sdxCluster, flowIdentifier.getPollableId()); break; case NOT_TRIGGERED: resetFlowIdAndFlowChainId(sdxCluster); break; default: throw new IllegalArgumentException("Unsupported flow type " + flowIdentifier.getType()); } sdxClusterRepository.save(sdxCluster); } } }
CloudbreakFlowService { public void saveLastCloudbreakFlowChainId(SdxCluster sdxCluster, FlowIdentifier flowIdentifier) { if (flowIdentifier == null) { LOGGER.info("Cloudbreak not sent flow identifier for cluster falling back to flow API."); trySaveLastCbFlowIdOrFlowChainId(sdxCluster); } else { LOGGER.info("Received cloudbreak flow identifier {} for cluster {}", flowIdentifier, sdxCluster.getClusterName()); switch (flowIdentifier.getType()) { case FLOW: setFlowIdAndResetFlowChainId(sdxCluster, flowIdentifier.getPollableId()); break; case FLOW_CHAIN: setFlowChainIdAndResetFlowId(sdxCluster, flowIdentifier.getPollableId()); break; case NOT_TRIGGERED: resetFlowIdAndFlowChainId(sdxCluster); break; default: throw new IllegalArgumentException("Unsupported flow type " + flowIdentifier.getType()); } sdxClusterRepository.save(sdxCluster); } }  }
CloudbreakFlowService { public void saveLastCloudbreakFlowChainId(SdxCluster sdxCluster, FlowIdentifier flowIdentifier) { if (flowIdentifier == null) { LOGGER.info("Cloudbreak not sent flow identifier for cluster falling back to flow API."); trySaveLastCbFlowIdOrFlowChainId(sdxCluster); } else { LOGGER.info("Received cloudbreak flow identifier {} for cluster {}", flowIdentifier, sdxCluster.getClusterName()); switch (flowIdentifier.getType()) { case FLOW: setFlowIdAndResetFlowChainId(sdxCluster, flowIdentifier.getPollableId()); break; case FLOW_CHAIN: setFlowChainIdAndResetFlowId(sdxCluster, flowIdentifier.getPollableId()); break; case NOT_TRIGGERED: resetFlowIdAndFlowChainId(sdxCluster); break; default: throw new IllegalArgumentException("Unsupported flow type " + flowIdentifier.getType()); } sdxClusterRepository.save(sdxCluster); } }  void getAndSaveLastCloudbreakFlowChainId(SdxCluster sdxCluster); FlowState getLastKnownFlowState(SdxCluster sdxCluster); void saveLastCloudbreakFlowChainId(SdxCluster sdxCluster, FlowIdentifier flowIdentifier); }
CloudbreakFlowService { public void saveLastCloudbreakFlowChainId(SdxCluster sdxCluster, FlowIdentifier flowIdentifier) { if (flowIdentifier == null) { LOGGER.info("Cloudbreak not sent flow identifier for cluster falling back to flow API."); trySaveLastCbFlowIdOrFlowChainId(sdxCluster); } else { LOGGER.info("Received cloudbreak flow identifier {} for cluster {}", flowIdentifier, sdxCluster.getClusterName()); switch (flowIdentifier.getType()) { case FLOW: setFlowIdAndResetFlowChainId(sdxCluster, flowIdentifier.getPollableId()); break; case FLOW_CHAIN: setFlowChainIdAndResetFlowId(sdxCluster, flowIdentifier.getPollableId()); break; case NOT_TRIGGERED: resetFlowIdAndFlowChainId(sdxCluster); break; default: throw new IllegalArgumentException("Unsupported flow type " + flowIdentifier.getType()); } sdxClusterRepository.save(sdxCluster); } }  void getAndSaveLastCloudbreakFlowChainId(SdxCluster sdxCluster); FlowState getLastKnownFlowState(SdxCluster sdxCluster); void saveLastCloudbreakFlowChainId(SdxCluster sdxCluster, FlowIdentifier flowIdentifier);  }