use of com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStats in project kylo by Teradata.
the class FeedFailureMetricAssessorTest method testNoStreamingFeeds.
/**
* Tests no streaming feed jobs
*/
@Test
public void testNoStreamingFeeds() throws ParseException {
DateTime lastAssessedTime = DateTime.now();
String feedName = "feed";
List<NifiFeedProcessorStats> streamingStats = new ArrayList<>();
boolean isStream = true;
this.metric.setFeedName(feedName);
when(feedProvider.findByName(feedName)).thenReturn(newOpsManagerFeed(feedName, isStream));
when(this.nifiFeedProcessorStatisticsProvider.findLatestFinishedStatsSince(Mockito.anyString(), Mockito.any(DateTime.class))).thenReturn(streamingStats);
this.assessor.assess(metric, this.builder);
verify(this.builder).result(AssessmentResult.SUCCESS);
}
use of com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStats in project kylo by Teradata.
the class FeedFailureMetricAssessorTest method testNoBatchJobs.
/**
* Tests when there are no batch jobs.
*/
@Test
public void testNoBatchJobs() throws ParseException {
DateTime lastAssessedTime = DateTime.now();
String feedName = "feed";
List<NifiFeedProcessorStats> streamingStats = new ArrayList<>();
boolean isStream = false;
this.metric.setFeedName(feedName);
when(feedProvider.findByName(feedName)).thenReturn(newOpsManagerFeed(feedName, isStream));
// completed, failed, completed.
// should fail
DateTime startingEvent = DateTime.now().minusMinutes(5);
List<? extends BatchJobExecution> batchJobs = new ArrayList<>();
Mockito.when(this.jobExecutionProvider.findLatestFinishedJobForFeedSince(Mockito.anyString(), Mockito.any(DateTime.class))).thenAnswer(x -> batchJobs);
Mockito.when(this.jobExecutionProvider.findLatestFinishedJobForFeed(Mockito.anyString())).thenAnswer(x -> null);
this.assessor.assess(metric, this.builder);
verify(this.builder).result(AssessmentResult.SUCCESS);
}
use of com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStats in project kylo by Teradata.
the class FeedFailureMetricAssessorTest method testStreamingSuccess.
/**
* Test successful streaming jobs
*/
@Test
public void testStreamingSuccess() throws ParseException {
DateTime lastAssessedTime = DateTime.now();
String feedName = "feed";
List<NifiFeedProcessorStats> streamingStats = new ArrayList<>();
boolean isStream = true;
this.metric.setFeedName(feedName);
when(feedProvider.findByName(feedName)).thenReturn(newOpsManagerFeed(feedName, isStream));
// completed, failed, completed.
// should fail
DateTime startingEvent = DateTime.now().minusMinutes(5);
streamingStats.add(newStats(feedName, startingEvent, 0L));
streamingStats.add(newStats(feedName, startingEvent.plusMinutes(4), 0L));
when(this.nifiFeedProcessorStatisticsProvider.findLatestFinishedStatsSince(Mockito.anyString(), Mockito.any(DateTime.class))).thenReturn(streamingStats);
this.assessor.assess(metric, this.builder);
verify(this.builder).result(AssessmentResult.SUCCESS);
}
use of com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStats in project kylo by Teradata.
the class FeedFailureMetricAssessorTest method newStats.
private NifiFeedProcessorStats newStats(String feedName, DateTime eventTime, Long failedCount) {
NifiFeedProcessorStats stats = new MockNifiFeedProcessorStats();
stats.setFeedName(feedName);
stats.setMinEventTime(eventTime);
stats.setMaxEventTime(eventTime);
stats.setFailedCount(failedCount);
return stats;
}
use of com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStats in project kylo by Teradata.
the class NifiFeedProcessorStatisticsRestControllerV2 method findFeedStats.
@GET
@Path("/{feedName}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets the statistics for the specified feed.")
@ApiResponses(@ApiResponse(code = 200, message = "Returns the feed statistics.", response = com.thinkbiganalytics.metadata.rest.jobrepo.nifi.NifiFeedProcessorStats.class, responseContainer = "List"))
public Response findFeedStats(@PathParam("feedName") String feedName, @QueryParam("from") Long fromMillis, @QueryParam("to") Long toMillis) {
this.accessController.checkPermission(AccessController.SERVICES, OperationsAccessControl.ACCESS_OPS);
final DateTime endTime = getToDateTime(toMillis);
final DateTime startTime = getFromDateTime(fromMillis);
return metadataAccess.read(() -> {
NiFiFeedProcessorStatsContainer statsContainer = new NiFiFeedProcessorStatsContainer(startTime, endTime);
NifiFeedStats feedStats = nifiFeedStatisticsProvider.findLatestStatsForFeed(feedName);
List<? extends NifiFeedProcessorStats> list = statsProvider.findForFeedStatisticsGroupedByTime(feedName, statsContainer.getStartTime(), statsContainer.getEndTime());
List<com.thinkbiganalytics.metadata.rest.jobrepo.nifi.NifiFeedProcessorStats> model = NifiFeedProcessorStatsTransform.toModel(list);
statsContainer.setStats(model);
if (feedStats != null) {
statsContainer.setRunningFlows(feedStats.getRunningFeedFlows());
} else {
// calc diff from finished - started
Long started = model.stream().mapToLong(s -> s.getJobsStarted()).sum();
Long finished = model.stream().mapToLong(s -> s.getJobsFinished()).sum();
Long running = started - finished;
if (running < 0) {
running = 0L;
}
statsContainer.setRunningFlows(running);
}
return Response.ok(statsContainer).build();
});
}
Aggregations