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;
}
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);
}
}
Aggregations