private JobManager(@NonNull final Configuration conf, @NotEmpty final String appName, @NotEmpty final String frequency, final boolean shouldLockFrequency) { this.conf = conf; this.appName = appName; this.jobMetrics = new JobMetrics(appName); this.reporters = new Reporters(); this.reporters.addReporter(new ConsoleReporter()); this.jobLockManager = new JobLockManager(conf, frequency, shouldLockFrequency); this.postJobManagerActions = new JobDagActions(this.reporters, "jobManager"); }
@Override public boolean execute(final boolean success) { if (success) { this.reporters.getReporters().forEach(reporter -> { this.jobMetrics.gaugeAll(reporter); this.dataFeedMetrics.gaugeAll(reporter); }); } else { log.warn("No metrics produced or actions being executed on reporter because errors were encountered"); } return success; }
@Test public void testTimeoutForLongRunningActions() { final JobDagActions jobDagActions = new JobDagActions(new Reporters()); final MultiThreadTestCoordinator coordinator = new MultiThreadTestCoordinator(); final AtomicBoolean success = new AtomicBoolean(true); jobDagActions.addAction(new TestParallelJobActionFailure(coordinator)); success.set(jobDagActions.execute(true)); assertTrue(!success.get()); }
@Test public void testWaitForActionsToFinish() { final JobDagActions jobDagActions = new JobDagActions(new Reporters()); final AtomicBoolean success = new AtomicBoolean(false); final IJobDagAction act = new IJobDagAction() { public boolean execute(final boolean dagSuccess) { try { Thread.sleep(10000); success.set(true); } catch (Exception e) { throw new IllegalStateException(e); } return success.get(); } public int getTimeoutSeconds() { return 20; } }; jobDagActions.addAction(act); jobDagActions.execute(true); assertTrue(success.get()); }
private void verifyJobMetricResult(@NonNull final IJobDagAction jobDagAction, final boolean dagSuccess, final long expectedMetricValue, final boolean isFailureExpected) { final Reporters reporters = new Reporters(); final IReporter mockReporter = spy(new TestReporter()); reporters.addReporter(mockReporter); final JobDagActions jobDagActions = new JobDagActions(reporters); jobDagActions.addAction(jobDagAction); Assert.assertEquals(!isFailureExpected, jobDagActions.execute(dagSuccess)); final ArgumentCaptor<LongMetric> metricCapture = ArgumentCaptor.forClass(LongMetric.class); verify(mockReporter, times(2)).gauge(metricCapture.capture()); Assert.assertEquals(expectedMetricValue, metricCapture.getValue().getMetricValue().longValue()); }
@Test public void testExecuteHandlesException() { final JobDagActions jobDagActions = new JobDagActions(new Reporters()); final List<Boolean> output = new ArrayList<>(2); jobDagActions.addAction(new TestSuccessfulJobDagAction(output)); jobDagActions.addAction(new TestFailedJobDagAction()); jobDagActions.addAction(new TestSuccessfulJobDagAction(output)); final AtomicBoolean isSuccess = new AtomicBoolean(true); isSuccess.set(jobDagActions.execute(true)); assertEquals(false, isSuccess.get()); assertEquals(2, output.size()); assertEquals(output.get(0), true); assertEquals(output.get(1), true); }
private void reportExecuteTime(@NonNull final IJobDagAction action, final long timeInMillis) { final LongMetric timeMetric = new LongMetric(TIME_METRIC, TimeUnit.MILLISECONDS.toSeconds(timeInMillis)); timeMetric.addTags(action.getMetricTags()); this.reporters.getReporters().stream().forEach(r -> r.gauge(timeMetric)); }
private void reportStatus(final boolean successful) { final long statusValue = successful ? DataFeedMetricNames.RESULT_SUCCESS : DataFeedMetricNames.RESULT_FAILURE; final LongMetric successMetric = new LongMetric( DataFeedMetricNames.RESULT, statusValue); successMetric.addTags(this.dataFeedMetrics.getBaseTags()); this.reporters.report(successMetric); } }
@Test public void testActionsRunInParallel() { final MultiThreadTestCoordinator coordinator = new MultiThreadTestCoordinator(); final JobDagActions jobDagActions = new JobDagActions(new Reporters()); jobDagActions.addAction(new TestParallelJobAction2(coordinator)); jobDagActions.addAction(new TestParallelJobAction1(coordinator)); jobDagActions.execute(true); }
private void reportActionStatus(@NonNull final IJobDagAction action, final boolean isSuccess) { final LongMetric resultMetric = new LongMetric(RESULT_METRIC, isSuccess ? RESULT_SUCCESS : RESULT_FAILURE); resultMetric.addTags(action.getMetricTags()); this.reporters.getReporters().stream().forEach(r -> r.gauge(resultMetric)); } }
this.reporters.getReporters().forEach(IReporter::finish);