private static List<Event> handleStarted(WorkflowInstance workflowInstance, RunState state) { switch (state.state()) { case PREPARE: case SUBMITTED: return ImmutableList.of(Event.started(workflowInstance)); default: return ImmutableList.of(); } }
@Override public Event toEvent() { return Event.started(WorkflowInstance.parseKey(workflowInstance)); } }
private static List<Event> handleExited(WorkflowInstance workflowInstance, RunState state, Pod pod, Optional<ContainerStatus> mainContainerStatusOpt, Stats stats) { final List<Event> generatedEvents = Lists.newArrayList(); switch (state.state()) { case PREPARE: case SUBMITTED: generatedEvents.add(Event.started(workflowInstance)); // intentional fall-through case RUNNING: final Optional<Integer> exitCode = mainContainerStatusOpt.flatMap(cs -> getExitCodeIfValid(workflowInstance.toKey(), pod, cs, stats)); generatedEvents.add(Event.terminate(workflowInstance, exitCode)); break; default: // no event break; } return ImmutableList.copyOf(generatedEvents); }
private void checkStatuses() { LOG.debug("Checking running statuses, {} statuses to check", inFlight.size()); for (String containerId : inFlight.keySet()) { final ContainerInfo containerInfo; try { containerInfo = client.inspectContainer(containerId); } catch (DockerException | InterruptedException e) { LOG.error("Error while reading status from docker", e); continue; } if (containerInfo.state().running() && !started.contains(containerId)) { final WorkflowInstance workflowInstance = inFlight.get(containerId); stateManager.receiveIgnoreClosed(Event.started(workflowInstance)); started.add(containerId); } if (!containerInfo.state().running()) { // Unlike in KubernetesDockerRunner case, where docker_termination_logging is supported, // here we are susceptible to Docker exit code bug, https://github.com/kubernetes/kubernetes/issues/41516. final Optional<Integer> exitCode = Optional.ofNullable(containerInfo.state().exitCode()); final WorkflowInstance workflowInstance = inFlight.remove(containerId); // trigger started event if we didn't see the container in running before if (!started.contains(containerId)) { stateManager.receiveIgnoreClosed(Event.started(workflowInstance)); } else { started.remove(containerId); } stateManager.receiveIgnoreClosed(Event.terminate(workflowInstance, exitCode)); } } }