Search in sources :

Example 6 with NifiFeedProcessorStats

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);
}
Also used : ArrayList(java.util.ArrayList) NifiFeedProcessorStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStats) DateTime(org.joda.time.DateTime) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with NifiFeedProcessorStats

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);
}
Also used : ArrayList(java.util.ArrayList) NifiFeedProcessorStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStats) DateTime(org.joda.time.DateTime) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with NifiFeedProcessorStats

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);
}
Also used : ArrayList(java.util.ArrayList) NifiFeedProcessorStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStats) DateTime(org.joda.time.DateTime) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with NifiFeedProcessorStats

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;
}
Also used : NifiFeedProcessorStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStats)

Example 10 with NifiFeedProcessorStats

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();
    });
}
Also used : Arrays(java.util.Arrays) PathParam(javax.ws.rs.PathParam) NifiStatsJmsReceiver(com.thinkbiganalytics.metadata.jobrepo.nifi.provenance.NifiStatsJmsReceiver) Produces(javax.ws.rs.Produces) NiFiFeedProcessorErrorsContainer(com.thinkbiganalytics.metadata.rest.jobrepo.nifi.NiFiFeedProcessorErrorsContainer) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) NifiFeedProcessorStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStats) NifiFeedProcessorErrors(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorErrors) Inject(javax.inject.Inject) NiFiFeedProcessorStatsContainer(com.thinkbiganalytics.metadata.rest.jobrepo.nifi.NiFiFeedProcessorStatsContainer) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) NifiFeedProcessorStatisticsProvider(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStatisticsProvider) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) Api(io.swagger.annotations.Api) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) NifiFeedStatisticsProvider(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStatisticsProvider) NifiFeedProcessorStatsTransform(com.thinkbiganalytics.metadata.rest.jobrepo.nifi.NifiFeedProcessorStatsTransform) OperationsAccessControl(com.thinkbiganalytics.jobrepo.security.OperationsAccessControl) LabelValue(com.thinkbiganalytics.rest.model.LabelValue) DateTime(org.joda.time.DateTime) NifiFeedStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStats) Collectors(java.util.stream.Collectors) List(java.util.List) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) NiFiFeedProcessorStatsContainer(com.thinkbiganalytics.metadata.rest.jobrepo.nifi.NiFiFeedProcessorStatsContainer) NifiFeedStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStats) NifiFeedProcessorStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStats) DateTime(org.joda.time.DateTime) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

NifiFeedProcessorStats (com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStats)17 DateTime (org.joda.time.DateTime)14 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 JpaNifiFeedProcessorStats (com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.JpaNifiFeedProcessorStats)4 AggregatedFeedProcessorStatisticsHolderV2 (com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatisticsHolderV2)3 MetadataAccess (com.thinkbiganalytics.metadata.api.MetadataAccess)2 OpsManagerFeed (com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed)2 BatchJobExecution (com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution)2 NifiFeedProcessorErrors (com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorErrors)2 NifiFeedProcessorStatisticsProvider (com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStatisticsProvider)2 NifiFeedStatisticsProvider (com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStatisticsProvider)2 NifiFeedStats (com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStats)2 NiFiFeedProcessorStatsContainer (com.thinkbiganalytics.metadata.rest.jobrepo.nifi.NiFiFeedProcessorStatsContainer)2 AggregatedFeedProcessorStatistics (com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatistics)2 GroupedStatsV2 (com.thinkbiganalytics.nifi.provenance.model.stats.GroupedStatsV2)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2