Search in sources :

Example 1 with NiFiFeedProcessorStatsContainer

use of com.thinkbiganalytics.metadata.rest.jobrepo.nifi.NiFiFeedProcessorStatsContainer 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)

Example 2 with NiFiFeedProcessorStatsContainer

use of com.thinkbiganalytics.metadata.rest.jobrepo.nifi.NiFiFeedProcessorStatsContainer in project kylo by Teradata.

the class NifiFeedProcessorStatisticsRestControllerV2 method findStats.

@GET
@Path("/{feedName}/processor-duration")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Returns the list of stats for each processor within the given timeframe relative to now")
@ApiResponses(@ApiResponse(code = 200, message = "Returns the list of stats for each processor within the given timeframe relative to now", response = com.thinkbiganalytics.metadata.rest.jobrepo.nifi.NifiFeedProcessorStats.class, responseContainer = "List"))
public Response findStats(@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);
        List<? extends NifiFeedProcessorStats> list = statsProvider.findFeedProcessorStatisticsByProcessorName(feedName, statsContainer.getStartTime(), statsContainer.getEndTime());
        List<? extends NifiFeedProcessorErrors> errors = statsProvider.findFeedProcessorErrors(feedName, statsContainer.getStartTime(), statsContainer.getEndTime());
        List<com.thinkbiganalytics.metadata.rest.jobrepo.nifi.NifiFeedProcessorStats> model = NifiFeedProcessorStatsTransform.toModel(list);
        statsContainer.setStats(model);
        return Response.ok(statsContainer).build();
    });
}
Also used : NiFiFeedProcessorStatsContainer(com.thinkbiganalytics.metadata.rest.jobrepo.nifi.NiFiFeedProcessorStatsContainer) 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)2 NiFiFeedProcessorStatsContainer (com.thinkbiganalytics.metadata.rest.jobrepo.nifi.NiFiFeedProcessorStatsContainer)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 DateTime (org.joda.time.DateTime)2 OperationsAccessControl (com.thinkbiganalytics.jobrepo.security.OperationsAccessControl)1 MetadataAccess (com.thinkbiganalytics.metadata.api.MetadataAccess)1 NifiFeedProcessorErrors (com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorErrors)1 NifiFeedProcessorStatisticsProvider (com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStatisticsProvider)1 NifiFeedStatisticsProvider (com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStatisticsProvider)1 NifiFeedStats (com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStats)1 NifiStatsJmsReceiver (com.thinkbiganalytics.metadata.jobrepo.nifi.provenance.NifiStatsJmsReceiver)1 NiFiFeedProcessorErrorsContainer (com.thinkbiganalytics.metadata.rest.jobrepo.nifi.NiFiFeedProcessorErrorsContainer)1 NifiFeedProcessorStatsTransform (com.thinkbiganalytics.metadata.rest.jobrepo.nifi.NifiFeedProcessorStatsTransform)1 LabelValue (com.thinkbiganalytics.rest.model.LabelValue)1 AccessController (com.thinkbiganalytics.security.AccessController)1 Api (io.swagger.annotations.Api)1