Search in sources :

Example 1 with InitializationStatus

use of com.thinkbiganalytics.metadata.rest.model.feed.InitializationStatus in project kylo by Teradata.

the class InitializeFeed method onTrigger.

/* (non-Javadoc)
     * @see org.apache.nifi.processor.AbstractProcessor#onTrigger(org.apache.nifi.processor.ProcessContext, org.apache.nifi.processor.ProcessSession)
     */
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
    FlowFile inputFF = session.get();
    if (inputFF != null) {
        inputFF = initialize(context, session, inputFF);
        InitializationStatus status = getMetadataRecorder().getInitializationStatus(getFeedId(context, inputFF)).orElse(new InitializationStatus(State.PENDING));
        switch(status.getState()) {
            case PENDING:
                pending(context, session, inputFF);
                break;
            case IN_PROGRESS:
                inProgress(context, session, inputFF);
                break;
            case FAILED:
                failed(context, session, inputFF, status.getTimestamp(), false);
                break;
            case REINITIALIZE:
                reinitialize(context, session, inputFF);
                break;
            case REINITIALIZE_FAILED:
                reinitializeFailed(context, session, inputFF, status.getTimestamp());
                break;
            case SUCCESS:
                success(context, session, inputFF);
        }
    }
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) InitializationStatus(com.thinkbiganalytics.metadata.rest.model.feed.InitializationStatus)

Example 2 with InitializationStatus

use of com.thinkbiganalytics.metadata.rest.model.feed.InitializationStatus in project kylo by Teradata.

the class MetadataClientRecorder method startFeedInitialization.

/* (non-Javadoc)
     * @see com.thinkbiganalytics.nifi.core.api.metadata.MetadataRecorder#startFeedInitialization(java.lang.String)
     */
@Override
public InitializationStatus startFeedInitialization(String feedId) {
    InitializationStatus status = new InitializationStatus(InitializationStatus.State.IN_PROGRESS);
    try {
        this.client.updateCurrentInitStatus(feedId, status);
        getInitStatusCache().put(feedId, Optional.of(status));
        return status;
    } catch (Exception e) {
        log.error("Failed to update metadata with feed initialization in-progress status: {},  feed: {}", status.getState(), feedId, e);
        getInitStatusCache().invalidate(feedId);
        throw new ProcessException("Failed to update metadata with feed initialization in-progress status: " + status + ",  feed: " + feedId, e);
    }
}
Also used : ProcessException(org.apache.nifi.processor.exception.ProcessException) InitializationStatus(com.thinkbiganalytics.metadata.rest.model.feed.InitializationStatus) ProcessException(org.apache.nifi.processor.exception.ProcessException) WaterMarkActiveException(com.thinkbiganalytics.nifi.core.api.metadata.WaterMarkActiveException) ActiveWaterMarksCancelledException(com.thinkbiganalytics.nifi.core.api.metadata.ActiveWaterMarksCancelledException) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with InitializationStatus

use of com.thinkbiganalytics.metadata.rest.model.feed.InitializationStatus in project kylo by Teradata.

the class MetadataClientRecorder method failFeedInitialization.

/* (non-Javadoc)
     * @see com.thinkbiganalytics.nifi.core.api.metadata.MetadataRecorder#failFeedInitialization(java.lang.String)
     */
@Override
public InitializationStatus failFeedInitialization(String feedId, boolean isReinitialize) {
    InitializationStatus.State state = isReinitialize ? InitializationStatus.State.REINITIALIZE_FAILED : InitializationStatus.State.FAILED;
    InitializationStatus status = new InitializationStatus(state);
    try {
        this.client.updateCurrentInitStatus(feedId, status);
        getInitStatusCache().put(feedId, Optional.of(status));
        return status;
    } catch (Exception e) {
        log.error("Failed to update feed initialization failed status: {},  feed: {}", status.getState(), feedId);
        getInitStatusCache().invalidate(feedId);
        return status;
    }
}
Also used : InitializationStatus(com.thinkbiganalytics.metadata.rest.model.feed.InitializationStatus) ProcessException(org.apache.nifi.processor.exception.ProcessException) WaterMarkActiveException(com.thinkbiganalytics.nifi.core.api.metadata.WaterMarkActiveException) ActiveWaterMarksCancelledException(com.thinkbiganalytics.nifi.core.api.metadata.ActiveWaterMarksCancelledException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with InitializationStatus

use of com.thinkbiganalytics.metadata.rest.model.feed.InitializationStatus in project kylo by Teradata.

the class MetadataClientRecorder method completeFeedInitialization.

/* (non-Javadoc)
     * @see com.thinkbiganalytics.nifi.core.api.metadata.MetadataRecorder#completeFeedInitialization(java.lang.String)
     */
@Override
public InitializationStatus completeFeedInitialization(String feedId) {
    InitializationStatus status = new InitializationStatus(InitializationStatus.State.SUCCESS);
    try {
        this.client.updateCurrentInitStatus(feedId, status);
        getInitStatusCache().put(feedId, Optional.of(status));
        return status;
    } catch (Exception e) {
        log.error("Failed to update metadata with feed initialization completion status: {},  feed: {}", status.getState(), feedId, e);
        getInitStatusCache().invalidate(feedId);
        throw new ProcessException("Failed to update metadata with feed initialization completion status: " + status + ",  feed: " + feedId, e);
    }
}
Also used : ProcessException(org.apache.nifi.processor.exception.ProcessException) InitializationStatus(com.thinkbiganalytics.metadata.rest.model.feed.InitializationStatus) ProcessException(org.apache.nifi.processor.exception.ProcessException) WaterMarkActiveException(com.thinkbiganalytics.nifi.core.api.metadata.WaterMarkActiveException) ActiveWaterMarksCancelledException(com.thinkbiganalytics.nifi.core.api.metadata.ActiveWaterMarksCancelledException) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with InitializationStatus

use of com.thinkbiganalytics.metadata.rest.model.feed.InitializationStatus in project kylo by Teradata.

the class FeedsController method putInitializationStatus.

@PUT
@Path("{id}/initstatus")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation("Sets the registration status for the specified feed.")
@ApiResponses({ @ApiResponse(code = 204, message = "The registration status was updated."), @ApiResponse(code = 404, message = "The feed could not be found.", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "The registration status could not be updated.", response = RestResponseStatus.class) })
public void putInitializationStatus(@PathParam("id") String feedIdStr, InitializationStatus status) {
    LOG.debug("Get feed initialization status {}", feedIdStr);
    // TODO Move behavior to a service?
    this.metadata.commit(() -> {
        this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_FEEDS);
        com.thinkbiganalytics.metadata.api.feed.Feed.ID feedId = feedProvider.resolveFeed(feedIdStr);
        com.thinkbiganalytics.metadata.api.feed.Feed feed = feedProvider.getFeed(feedId);
        if (feed != null) {
            com.thinkbiganalytics.metadata.api.feed.InitializationStatus.State newState = com.thinkbiganalytics.metadata.api.feed.InitializationStatus.State.valueOf(status.getState().name());
            feed.updateInitStatus(new com.thinkbiganalytics.metadata.api.feed.InitializationStatus(newState));
        } else {
            throw new WebApplicationException("A feed with the given ID does not exist: " + feedId, Status.NOT_FOUND);
        }
    });
    FeedInitializationChangeEvent event = new FeedInitializationChangeEvent(feedIdStr, status.getState());
    this.jmsMessagingTemplate.convertAndSend(this.initStatusChangeTopic, event);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) InitializationStatus(com.thinkbiganalytics.metadata.rest.model.feed.InitializationStatus) FeedInitializationChangeEvent(com.thinkbiganalytics.metadata.rest.model.event.FeedInitializationChangeEvent) Feed(com.thinkbiganalytics.metadata.rest.model.feed.Feed) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

InitializationStatus (com.thinkbiganalytics.metadata.rest.model.feed.InitializationStatus)5 ActiveWaterMarksCancelledException (com.thinkbiganalytics.nifi.core.api.metadata.ActiveWaterMarksCancelledException)3 WaterMarkActiveException (com.thinkbiganalytics.nifi.core.api.metadata.WaterMarkActiveException)3 ExecutionException (java.util.concurrent.ExecutionException)3 ProcessException (org.apache.nifi.processor.exception.ProcessException)3 FeedInitializationChangeEvent (com.thinkbiganalytics.metadata.rest.model.event.FeedInitializationChangeEvent)1 Feed (com.thinkbiganalytics.metadata.rest.model.feed.Feed)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 FlowFile (org.apache.nifi.flowfile.FlowFile)1