use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class HeartbeatServiceTest method createFlowDistribution.
private Map<Node, List<String>> createFlowDistribution(Set<FlowLog> failedFLowLogs1, Set<FlowLog> failedFlowLogs2) {
Map<Node, List<String>> distribution = new HashMap<>();
distribution.put(new Node(UUID.randomUUID().toString()), failedFLowLogs1.stream().map(FlowLog::getFlowId).collect(Collectors.toList()));
return distribution;
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class HeartbeatServiceTest method testOneNodeTakesAllFlowsWithCleanup.
@Test
public void testOneNodeTakesAllFlowsWithCleanup() {
List<Node> clusterNodes = getClusterNodes();
// myself
clusterNodes.get(0).setLastUpdated(200_000L);
// set all nodes to failed except myself
for (int i = 1; i < clusterNodes.size(); i++) {
Node node = clusterNodes.get(i);
node.setLastUpdated(50_000L);
}
when(nodeService.findAll()).thenReturn(clusterNodes);
when(clock.getCurrentTimeMillis()).thenReturn(200_000L);
// all flows that need to be re-distributed
List<FlowLog> node1FlowLogs = getFlowLogs(2, 5000);
List<String> suspendedFlows = node1FlowLogs.stream().map(FlowLog::getFlowId).distinct().collect(Collectors.toList());
when(flowLogService.findAllByCloudbreakNodeId(NODE_1_ID)).thenReturn(new HashSet<>(node1FlowLogs)).thenReturn(Collections.emptySet());
Set<FlowLog> node2FlowLogs = new HashSet<>(getFlowLogs(3, 3000));
suspendedFlows.addAll(node2FlowLogs.stream().map(FlowLog::getFlowId).distinct().collect(Collectors.toList()));
when(flowLogService.findAllByCloudbreakNodeId(NODE_2_ID)).thenReturn(node2FlowLogs).thenReturn(Collections.emptySet());
Map<Node, List<String>> distribution = new HashMap<>();
distribution.computeIfAbsent(clusterNodes.get(0), v -> new ArrayList<>()).addAll(Arrays.asList(suspendedFlows.get(0), suspendedFlows.get(1), suspendedFlows.get(2), suspendedFlows.get(3), suspendedFlows.get(4)));
when(flowDistributor.distribute(any(), any())).thenReturn(distribution);
Set<FlowLog> myNewFlowLogs = new HashSet<>();
myNewFlowLogs.addAll(node1FlowLogs);
myNewFlowLogs.addAll(node2FlowLogs);
when(flowLogService.findAllByCloudbreakNodeId(MY_ID)).thenReturn(myNewFlowLogs);
when(runningFlows.get(any())).thenReturn(null);
heartbeatService.scheduledFlowDistribution();
verify(flowLogService).saveAll(flowLogListCaptor.capture());
List<FlowLog> updatedFlows = flowLogListCaptor.getValue();
assertEquals(myNewFlowLogs.size(), updatedFlows.size());
for (FlowLog updatedFlow : updatedFlows) {
assertEquals(MY_ID, updatedFlow.getCloudbreakNodeId());
}
verify(flow2Handler, times(5)).restartFlow(stringCaptor.capture());
List<String> allFlowIds = stringCaptor.getAllValues();
assertEquals(5L, allFlowIds.size());
for (String flowId : suspendedFlows) {
assertTrue(allFlowIds.contains(flowId));
}
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class FlowLogUtilTest method getMostRecentFailedLog.
@Test
public void getMostRecentFailedLog() {
List<FlowLog> flowLogs = new ArrayList<>();
FlowLog successfulFlowLog1 = new FlowLog();
successfulFlowLog1.setStateStatus(StateStatus.SUCCESSFUL);
successfulFlowLog1.setNextEvent("NEXT_EVENT1");
successfulFlowLog1.setCreated(1L);
successfulFlowLog1.setCurrentState("CURRENT_STATE1");
flowLogs.add(successfulFlowLog1);
FlowLog failedFlowLog2 = new FlowLog();
failedFlowLog2.setStateStatus(StateStatus.FAILED);
failedFlowLog2.setCurrentState("FAILED_CURRENT_STATE");
failedFlowLog2.setCreated(5L);
flowLogs.add(failedFlowLog2);
FlowLog successfulFlowLog4 = new FlowLog();
successfulFlowLog4.setStateStatus(StateStatus.SUCCESSFUL);
successfulFlowLog4.setNextEvent("NEXT_EVENT3");
successfulFlowLog4.setCreated(4L);
successfulFlowLog4.setCurrentState("CURRENT_STATE3");
flowLogs.add(successfulFlowLog4);
FlowLog successfulFlowLog3 = new FlowLog();
successfulFlowLog3.setStateStatus(StateStatus.SUCCESSFUL);
successfulFlowLog3.setNextEvent("NEXT_EVENT1");
successfulFlowLog3.setCreated(3L);
successfulFlowLog3.setCurrentState("CURRENT_STATE1");
flowLogs.add(successfulFlowLog3);
FlowLog failedFlowLog = new FlowLog();
failedFlowLog.setStateStatus(StateStatus.FAILED);
failedFlowLog.setCurrentState("FAILED_CURRENT_STATE");
failedFlowLog.setCreated(2L);
flowLogs.add(failedFlowLog);
Optional<FlowLog> mostRecentFailedLog = FlowLogUtil.getMostRecentFailedLog(flowLogs);
assertEquals(mostRecentFailedLog.get(), failedFlowLog2);
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class FlowLogUtilTest method isFlowPending.
@Test
public void isFlowPending() {
List<FlowLog> flowLogs = new ArrayList<>();
FlowLog successfulFlowLog1 = new FlowLog();
successfulFlowLog1.setStateStatus(StateStatus.SUCCESSFUL);
successfulFlowLog1.setNextEvent("NEXT_EVENT1");
successfulFlowLog1.setCreated(1L);
successfulFlowLog1.setCurrentState("CURRENT_STATE1");
flowLogs.add(successfulFlowLog1);
FlowLog failedFlowLog2 = new FlowLog();
failedFlowLog2.setStateStatus(StateStatus.FAILED);
failedFlowLog2.setCurrentState("FAILED_CURRENT_STATE2");
failedFlowLog2.setCreated(5L);
flowLogs.add(failedFlowLog2);
FlowLog successfulFlowLog4 = new FlowLog();
successfulFlowLog4.setStateStatus(StateStatus.SUCCESSFUL);
successfulFlowLog4.setNextEvent("NEXT_EVENT3");
successfulFlowLog4.setCreated(4L);
successfulFlowLog4.setCurrentState("CURRENT_STATE3");
flowLogs.add(successfulFlowLog4);
FlowLog successfulFlowLog3 = new FlowLog();
successfulFlowLog3.setStateStatus(StateStatus.SUCCESSFUL);
successfulFlowLog3.setNextEvent("NEXT_EVENT1");
successfulFlowLog3.setCreated(3L);
successfulFlowLog3.setCurrentState("CURRENT_STATE1");
flowLogs.add(successfulFlowLog3);
FlowLog failedFlowLog = new FlowLog();
failedFlowLog.setStateStatus(StateStatus.FAILED);
failedFlowLog.setCurrentState("FAILED_CURRENT_STATE1");
failedFlowLog.setCreated(2L);
flowLogs.add(failedFlowLog);
FlowLog pendingFlowLog = new FlowLog();
pendingFlowLog.setStateStatus(StateStatus.PENDING);
pendingFlowLog.setCurrentState("PENDING_CURRENT_STATE");
pendingFlowLog.setCreated(6L);
flowLogs.add(pendingFlowLog);
assertTrue(FlowLogUtil.getPendingFlowLog(flowLogs).isPresent());
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class FlowLogUtilTest method isFlowPendingButNoPending.
@Test
public void isFlowPendingButNoPending() {
List<FlowLog> flowLogs = new ArrayList<>();
FlowLog successfulFlowLog1 = new FlowLog();
successfulFlowLog1.setStateStatus(StateStatus.SUCCESSFUL);
successfulFlowLog1.setNextEvent("NEXT_EVENT1");
successfulFlowLog1.setCreated(1L);
successfulFlowLog1.setCurrentState("CURRENT_STATE1");
flowLogs.add(successfulFlowLog1);
FlowLog failedFlowLog2 = new FlowLog();
failedFlowLog2.setStateStatus(StateStatus.FAILED);
failedFlowLog2.setCurrentState("FAILED_CURRENT_STATE2");
failedFlowLog2.setCreated(5L);
flowLogs.add(failedFlowLog2);
FlowLog successfulFlowLog4 = new FlowLog();
successfulFlowLog4.setStateStatus(StateStatus.SUCCESSFUL);
successfulFlowLog4.setNextEvent("NEXT_EVENT3");
successfulFlowLog4.setCreated(4L);
successfulFlowLog4.setCurrentState("CURRENT_STATE3");
flowLogs.add(successfulFlowLog4);
FlowLog successfulFlowLog3 = new FlowLog();
successfulFlowLog3.setStateStatus(StateStatus.SUCCESSFUL);
successfulFlowLog3.setNextEvent("NEXT_EVENT1");
successfulFlowLog3.setCreated(3L);
successfulFlowLog3.setCurrentState("CURRENT_STATE1");
flowLogs.add(successfulFlowLog3);
FlowLog failedFlowLog = new FlowLog();
failedFlowLog.setStateStatus(StateStatus.FAILED);
failedFlowLog.setCurrentState("FAILED_CURRENT_STATE1");
failedFlowLog.setCreated(2L);
flowLogs.add(failedFlowLog);
assertFalse(FlowLogUtil.getPendingFlowLog(flowLogs).isPresent());
}
Aggregations