Search in sources :

Example 1 with CleanupTriggerEvent

use of com.thinkbiganalytics.metadata.api.event.feed.CleanupTriggerEvent in project kylo by Teradata.

the class FeedManagerMetadataService method cleanupFeed.

/**
 * Runs the cleanup flow for the specified feed.
 *
 * @param feed the feed to be cleaned up
 * @throws FeedCleanupFailedException  if the cleanup flow was started but failed to complete successfully
 * @throws FeedCleanupTimeoutException if the cleanup flow was started but failed to complete in the allotted time
 * @throws RuntimeException            if the cleanup flow could not be started
 */
private void cleanupFeed(@Nonnull final FeedMetadata feed) {
    // Create event listener
    final FeedCompletionListener listener = new FeedCompletionListener(feed, Thread.currentThread());
    eventService.addListener(listener);
    try {
        // Trigger cleanup
        feedProvider.enableFeedCleanup(feed.getId());
        eventService.notify(new CleanupTriggerEvent(feedProvider.resolveFeed(feed.getId())));
        // Wait for completion
        long remaining = cleanupTimeout;
        while (remaining > 0 && (listener.getState() == null || listener.getState() == FeedOperation.State.STARTED)) {
            final long start = System.currentTimeMillis();
            try {
                Thread.sleep(remaining);
            } catch (InterruptedException e) {
            // ignored
            }
            remaining -= System.currentTimeMillis() - start;
        }
    } finally {
        eventService.removeListener(listener);
    }
    // Check result
    if (listener.getState() == null || listener.getState() == FeedOperation.State.STARTED) {
        throw new FeedCleanupTimeoutException("Cleanup timed out for feed: " + feed.getId());
    }
    if (listener.getState() != FeedOperation.State.SUCCESS) {
        throw new FeedCleanupFailedException("Cleanup state " + listener.getState() + " for feed: " + feed.getId());
    }
}
Also used : CleanupTriggerEvent(com.thinkbiganalytics.metadata.api.event.feed.CleanupTriggerEvent)

Aggregations

CleanupTriggerEvent (com.thinkbiganalytics.metadata.api.event.feed.CleanupTriggerEvent)1