Search in sources :

Example 1 with FeedDataHistoryReindexParams

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

the class FeedsController method updateDataHistoryReindexStatus.

@POST
@Path("{id}/update-data-history-reindex-status")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation("Sets the data history reindexing status for the specified feed")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the feed's updated data history reindex status and columns to index", response = FeedDataHistoryReindexParams.class), @ApiResponse(code = 500, message = "The data history reindex status could not be updated for the feed", response = RestResponseStatus.class) })
public FeedDataHistoryReindexParams updateDataHistoryReindexStatus(@PathParam("id") String feedIdStr, HistoryReindexingStatus status) {
    LOG.debug("Update data history reindexing status for feed with id: {}", feedIdStr);
    FeedDataHistoryReindexParams feedDataHistoryReindexParams = 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) {
            FeedDataHistoryReindexParams reindexParams = new FeedDataHistoryReindexParams();
            com.thinkbiganalytics.metadata.api.feed.reindex.HistoryReindexingState newHistoryReindexingState = com.thinkbiganalytics.metadata.api.feed.reindex.HistoryReindexingState.valueOf(status.getHistoryReindexingState().name());
            com.thinkbiganalytics.metadata.api.feed.Feed updatedDomainFeed = feed.updateHistoryReindexingStatus(new com.thinkbiganalytics.metadata.api.feed.reindex.HistoryReindexingStatus(newHistoryReindexingState));
            Feed updatedRestFeed = metadataTransform.domainToFeed().apply(updatedDomainFeed);
            // updated reindexing status
            reindexParams.setHistoryReindexingStatus(updatedRestFeed.getCurrentHistoryReindexingStatus());
            reindexParams.setFeedId(updatedRestFeed.getId());
            reindexParams.setFeedSystemName(updatedRestFeed.getSystemName());
            reindexParams.setCategorySystemName(updatedRestFeed.getCategory().getSystemName());
            if (updatedDomainFeed != null) {
                FeedMetadata feedMetadata = getMetadataService().getFeedById(updatedDomainFeed.getId().toString());
                if (feedMetadata != null && feedMetadata.getTable() != null) {
                    List<String> commaSepColumns = new ArrayList<>();
                    List<FieldPolicy> fieldPolicies = feedMetadata.getTable().getFieldPolicies();
                    for (FieldPolicy fieldPolicy : fieldPolicies) {
                        if (fieldPolicy.isIndex()) {
                            commaSepColumns.add(fieldPolicy.getFieldName().toLowerCase().trim());
                        }
                    }
                    // columns to index as comma separated string
                    reindexParams.setCommaSeparatedColumnsForIndexing(StringUtils.join(commaSepColumns.toArray(), ","));
                }
            }
            return reindexParams;
        } else {
            throw new WebApplicationException("A feed with the given ID does not exist: " + feedId, Status.NOT_FOUND);
        }
    });
    return feedDataHistoryReindexParams;
}
Also used : FieldPolicy(com.thinkbiganalytics.policy.rest.model.FieldPolicy) WebApplicationException(javax.ws.rs.WebApplicationException) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) ArrayList(java.util.ArrayList) FeedDataHistoryReindexParams(com.thinkbiganalytics.metadata.rest.model.feed.reindex.FeedDataHistoryReindexParams) Feed(com.thinkbiganalytics.metadata.rest.model.feed.Feed) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with FeedDataHistoryReindexParams

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

the class UpdateFeedHistoryReindex method onTrigger.

@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
    final ComponentLog logger = getLog();
    FlowFile flowFile = session.get();
    if (flowFile == null) {
        logger.warn("Update feed history reindex status processor called without an in-coming flow file. " + "Ensure that this is the intended usage.");
        flowFile = session.create();
    }
    final MetadataProviderService metadataProviderService = context.getProperty(METADATA_SERVICE).asControllerService(MetadataProviderService.class);
    final String feedId = context.getProperty(FEED_ID).evaluateAttributeExpressions(flowFile).getValue();
    final String historyReindexingStateAsString = context.getProperty(FEED_REINDEX_STATUS).evaluateAttributeExpressions(flowFile).getValue();
    logger.debug("Updating history reindex status for feed with id {}. New status for update is {}...", new Object[] { feedId, historyReindexingStateAsString });
    if (feedId != null && metadataProviderService != null && metadataProviderService.getRecorder() != null) {
        try {
            FeedDataHistoryReindexParams feedDataHistoryReindexParams = metadataProviderService.getRecorder().updateFeedHistoryReindexing(feedId, new HistoryReindexingStatus(HistoryReindexingState.valueOf(historyReindexingStateAsString)));
            if (feedDataHistoryReindexParams == null) {
                logger.error("Error updating history reindex status to {} for feed with id {}", new Object[] { feedId, historyReindexingStateAsString });
                session.transfer(flowFile, REL_FAILURE);
            } else {
                flowFile = session.putAttribute(flowFile, UPDATED_FEED_INFO_FOR_HISTORY_REINDEX_KEY, getFeedInfo(feedDataHistoryReindexParams));
                flowFile = session.putAttribute(flowFile, UPDATED_FEED_STATUS_FOR_HISTORY_REINDEX_KEY, feedDataHistoryReindexParams.getHistoryReindexingStatus().getHistoryReindexingState().toString());
                flowFile = session.putAttribute(flowFile, UPDATED_TIME_UTC_FOR_HISTORY_REINDEX_KEY, feedDataHistoryReindexParams.getHistoryReindexingStatus().getLastModifiedTimestamp().toString());
                flowFile = session.putAttribute(flowFile, UPDATED_INDEX_COLUMNS_STRING_FOR_HISTORY_REINDEX_KEY, feedDataHistoryReindexParams.getCommaSeparatedColumnsForIndexing());
                logger.info("Updated reindex history status to {} for feed with id {}", new Object[] { feedDataHistoryReindexParams.getHistoryReindexingStatus().getHistoryReindexingState().toString(), feedDataHistoryReindexParams.getFeedId() });
                session.transfer(flowFile, REL_SUCCESS);
            }
        } catch (Exception e) {
            logger.error("An exception was thrown during updating history reindex status to {} for feed id {}: {}", new Object[] { feedId, historyReindexingStateAsString, e });
            session.transfer(flowFile, REL_FAILURE);
        }
    } else {
        logger.error("One or more of {feed id, metadata service, metadata service recorder} is null for updating history reindex status operation");
        session.transfer(flowFile, REL_FAILURE);
    }
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) HistoryReindexingStatus(com.thinkbiganalytics.metadata.rest.model.feed.reindex.HistoryReindexingStatus) FeedDataHistoryReindexParams(com.thinkbiganalytics.metadata.rest.model.feed.reindex.FeedDataHistoryReindexParams) ComponentLog(org.apache.nifi.logging.ComponentLog) MetadataProviderService(com.thinkbiganalytics.nifi.core.api.metadata.MetadataProviderService) ProcessException(org.apache.nifi.processor.exception.ProcessException)

Aggregations

FeedDataHistoryReindexParams (com.thinkbiganalytics.metadata.rest.model.feed.reindex.FeedDataHistoryReindexParams)2 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)1 Feed (com.thinkbiganalytics.metadata.rest.model.feed.Feed)1 HistoryReindexingStatus (com.thinkbiganalytics.metadata.rest.model.feed.reindex.HistoryReindexingStatus)1 MetadataProviderService (com.thinkbiganalytics.nifi.core.api.metadata.MetadataProviderService)1 FieldPolicy (com.thinkbiganalytics.policy.rest.model.FieldPolicy)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)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 ComponentLog (org.apache.nifi.logging.ComponentLog)1 ProcessException (org.apache.nifi.processor.exception.ProcessException)1