protected void complete(final State completionState) { LOG.trace("Program {} completed with state {}", programId, completionState); if (!state.compareAndSet(State.STARTING, completionState) && !state.compareAndSet(State.ALIVE, completionState) && !state.compareAndSet(State.SUSPENDED, completionState)) { LOG.warn("Cannot transit to COMPLETED state from {} state: {}", state.get(), name); return; } executor.execute(() -> { state.set(completionState); if (State.KILLED.equals(completionState)) { caller.killed(); } else { caller.completed(); } }); }
@Override public List<RuntimeInfo> listAll(ProgramType... types) { List<RuntimeInfo> runningPrograms = new ArrayList<>(); for (ProgramType type : types) { for (Map.Entry<RunId, RuntimeInfo> entry : list(type).entrySet()) { ProgramController.State programState = entry.getValue().getController().getState(); if (programState.isDone()) { continue; } runningPrograms.add(entry.getValue()); } } return runningPrograms; }
ArtifactId artifactId = programId.getNamespaceId().artifact("testArtifact", "1.0").toApiArtifactId(); setStartAndRunning(programId.run(run1.getId()), artifactId); store.setStop(programId.run(run1.getId()), startTimeSecs - 10, ProgramController.State.ERROR.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId)); store.setStop(programId.run(run2.getId()), startTimeSecs - 5, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId)); RunId run4 = RunIds.generate(now - 5000); setStartAndRunning(programId2.run(run4.getId()), artifactId); store.setStop(programId2.run(run4.getId()), startTimeSecs - 4, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId)); Assert.assertEquals(startTimeSecs - 10, run.getStartTs()); Assert.assertEquals(Long.valueOf(startTimeSecs - 5), run.getStopTs()); Assert.assertEquals(ProgramController.State.COMPLETED.getRunStatus(), run.getStatus()); Assert.assertEquals(ProgramController.State.ERROR.getRunStatus(), run.getStatus()); Assert.assertEquals(ProgramController.State.SUSPENDED.getRunStatus(), run.getStatus()); Map<String, String> emptyArgs = ImmutableMap.of(); setStart(programId.run(run7.getId()), emptyArgs, emptyArgs, artifactId); store.setStop(programId.run(run7.getId()), startTimeSecs + 1, ProgramController.State.ERROR.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId)); RunRecordMeta expectedRunRecord7 = RunRecordMeta.builder()
while (!controller.getState().equals(ProgramController.State.COMPLETED)) { TimeUnit.MILLISECONDS.sleep(100);
ProgramController.State.ERROR.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
store.setStop(mapreduceProgramRunId1, now, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId)); store.setStop(workflowProgramId1.run(runId.getId()), now, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId)); store.setStop(serviceRunId, now, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
@Test public void testRunsLimit() { ApplicationSpecification spec = Specifications.from(new AllProgramsApp()); ApplicationId appId = new ApplicationId("testRunsLimit", spec.getName()); store.addApplication(appId, spec); ProgramId mapreduceProgramId = new ApplicationId("testRunsLimit", spec.getName()) .mr(AllProgramsApp.NoOpMR.class.getSimpleName()); ArtifactId artifactId = appId.getNamespaceId().artifact("testArtifact", "1.0").toApiArtifactId(); Assert.assertNotNull(store.getApplication(appId)); long now = System.currentTimeMillis(); ProgramRunId programRunId = mapreduceProgramId.run(RunIds.generate(now - 3000)); setStartAndRunning(programRunId, artifactId); store.setStop(programRunId, now - 100, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId)); setStartAndRunning(mapreduceProgramId.run(RunIds.generate(now - 2000)), artifactId); // even though there's two separate run records (one that's complete and one that's active), only one should be // returned by the query, because the limit parameter of 1 is being passed in. Map<ProgramRunId, RunRecordMeta> historymap = store.getRuns(mapreduceProgramId, ProgramRunStatus.ALL, 0, Long.MAX_VALUE, 1); Assert.assertEquals(1, historymap.size()); }
@Test public void testConcurrentStopStart() { // Two programs that start/stop at same time // Should have two run history. ProgramId programId = new ProgramId("account1", "concurrentApp", ProgramType.MAPREDUCE, "concurrentMR"); long now = System.currentTimeMillis(); long nowSecs = TimeUnit.MILLISECONDS.toSeconds(now); RunId run1 = RunIds.generate(now - 10000); ArtifactId artifactId = programId.getNamespaceId().artifact("testArtifact", "1.0").toApiArtifactId(); setStartAndRunning(programId.run(run1.getId()), artifactId); RunId run2 = RunIds.generate(now - 10000); setStartAndRunning(programId.run(run2.getId()), artifactId); store.setStop(programId.run(run1.getId()), nowSecs, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId)); store.setStop(programId.run(run2.getId()), nowSecs, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId)); Map<ProgramRunId, RunRecordMeta> historymap = store.getRuns(programId, ProgramRunStatus.ALL, 0, Long.MAX_VALUE, Integer.MAX_VALUE); Assert.assertEquals(2, historymap.size()); }
protected void complete(final State completionState) { LOG.trace("Program {} completed with state {}", programId, completionState); if (!state.compareAndSet(State.STARTING, completionState) && !state.compareAndSet(State.ALIVE, completionState) && !state.compareAndSet(State.SUSPENDED, completionState)) { LOG.warn("Cannot transit to COMPLETED state from {} state: {}", state.get(), name); return; } executor.execute(() -> { state.set(completionState); if (State.KILLED.equals(completionState)) { caller.killed(); } else { caller.completed(); } }); }
@Override public List<RuntimeInfo> listAll(ProgramType... types) { List<RuntimeInfo> runningPrograms = new ArrayList<>(); for (ProgramType type : types) { for (Map.Entry<RunId, RuntimeInfo> entry : list(type).entrySet()) { ProgramController.State programState = entry.getValue().getController().getState(); if (programState.isDone()) { continue; } runningPrograms.add(entry.getValue()); } } return runningPrograms; }
private Predicate<RunRecordMeta> getPredicate(final ProgramController.State state) { return (record) -> record.getStatus().equals(state.getRunStatus()); }
private Predicate<RunRecordMeta> getPredicate(final ProgramController.State state) { return (record) -> record.getStatus().equals(state.getRunStatus()); }
@Test public void testStopBeforeStart() throws RuntimeException { ProgramId programId = new ProgramId("account1", "invalidApp", ProgramType.MAPREDUCE, "InvalidMR"); long now = System.currentTimeMillis(); String pid = RunIds.generate().getId(); store.setStop(programId.run(pid), now, ProgramController.State.ERROR.getRunStatus(), ByteBuffer.allocate(0).array()); Assert.assertNull(store.getRun(programId.run(pid))); }