Search in sources :

Example 1 with FeedCleanupTriggerEvent

use of com.thinkbiganalytics.metadata.rest.model.event.FeedCleanupTriggerEvent in project kylo by Teradata.

the class TriggerCleanup method onTrigger.

@Override
public void onTrigger(@Nonnull final ProcessContext context, @Nonnull final ProcessSession session) throws ProcessException {
    getLog().trace("Triggered for feed {}.{}", new Object[] { category, feed });
    // Look for an event to process
    FeedCleanupTriggerEvent event = queue.poll();
    if (event == null) {
        getLog().trace("Triggered, but no message in queue");
        context.yield();
        // nothing to do
        return;
    }
    String feedId;
    try {
        feedId = getMetadataService(context).getProvider().getFeedId(category, feed);
        getLog().debug("Triggered for feed " + feedId);
    } catch (Exception e) {
        getLog().error("Failure retrieving metadata for feed: {}.{}", new Object[] { category, feed }, e);
        throw new IllegalStateException("Failed to retrieve feed metadata", e);
    }
    // Verify feed properties
    Properties properties = (feedId != null) ? getMetadataService(context).getProvider().getFeedProperties(feedId) : null;
    getLog().debug("Feed properties " + properties);
    if (properties == null) {
        throw new IllegalStateException("Failed to fetch properties for feed: " + feedId);
    }
    if (!properties.containsKey(FeedProperties.CLEANUP_ENABLED) || !"true".equals(properties.getProperty(FeedProperties.CLEANUP_ENABLED))) {
        getLog().info("Ignoring cleanup event because deleteEnabled is false for feed: {}", new Object[] { feedId });
        context.yield();
        // ignore events if deleteEnabled is not true
        return;
    }
    // Create attributes for FlowFile
    Map<String, String> attributes = Maps.newHashMap();
    for (Map.Entry<Object, Object> property : properties.entrySet()) {
        attributes.put((String) property.getKey(), (String) property.getValue());
    }
    attributes.put("category", context.getProperty(CATEGORY_NAME).getValue());
    attributes.put("feed", context.getProperty(FEED_NAME).getValue());
    // Create a FlowFile from the event
    FlowFile flowFile = session.create();
    flowFile = session.putAllAttributes(flowFile, attributes);
    getLog().debug("Transferring flow file to Success relationship");
    session.transfer(flowFile, REL_SUCCESS);
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) FeedCleanupTriggerEvent(com.thinkbiganalytics.metadata.rest.model.event.FeedCleanupTriggerEvent) Properties(java.util.Properties) FeedProperties(com.thinkbiganalytics.metadata.api.feed.FeedProperties) Map(java.util.Map) ProcessException(org.apache.nifi.processor.exception.ProcessException)

Example 2 with FeedCleanupTriggerEvent

use of com.thinkbiganalytics.metadata.rest.model.event.FeedCleanupTriggerEvent in project kylo by Teradata.

the class TriggerCleanupTest method testTriggeredWhenDisabled.

/**
 * Verify triggering the processor when the cleanup property is disabled.
 */
@Test
public void testTriggeredWhenDisabled() {
    runner.setProperty(TriggerCleanup.CATEGORY_NAME, "cat");
    runner.setProperty(TriggerCleanup.FEED_NAME, "disabled");
    ((TriggerCleanup) runner.getProcessor()).triggered(new FeedCleanupTriggerEvent("FEEDID"));
    runner.run();
    Assert.assertEquals(0, runner.getFlowFilesForRelationship(TriggerCleanup.REL_SUCCESS).size());
}
Also used : FeedCleanupTriggerEvent(com.thinkbiganalytics.metadata.rest.model.event.FeedCleanupTriggerEvent) Test(org.junit.Test)

Example 3 with FeedCleanupTriggerEvent

use of com.thinkbiganalytics.metadata.rest.model.event.FeedCleanupTriggerEvent in project kylo by Teradata.

the class TriggerCleanupTest method testTriggeredWithException.

/**
 * Verify exception when scheduling the processor.
 */
@Test(expected = AssertionError.class)
public void testTriggeredWithException() {
    runner.setProperty(TriggerCleanup.CATEGORY_NAME, "invalid");
    runner.setProperty(TriggerCleanup.FEED_NAME, "invalid");
    ((TriggerCleanup) runner.getProcessor()).triggered(new FeedCleanupTriggerEvent("FEEDID"));
    runner.run();
}
Also used : FeedCleanupTriggerEvent(com.thinkbiganalytics.metadata.rest.model.event.FeedCleanupTriggerEvent) Test(org.junit.Test)

Example 4 with FeedCleanupTriggerEvent

use of com.thinkbiganalytics.metadata.rest.model.event.FeedCleanupTriggerEvent in project kylo by Teradata.

the class TriggerCleanupTest method testTriggered.

/**
 * Verify triggering the processor.
 */
@Test
public void testTriggered() {
    runner.setProperty(TriggerCleanup.CATEGORY_NAME, "cat");
    runner.setProperty(TriggerCleanup.FEED_NAME, "feed");
    ((TriggerCleanup) runner.getProcessor()).triggered(new FeedCleanupTriggerEvent("FEEDID"));
    runner.run();
    List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(TriggerCleanup.REL_SUCCESS);
    Assert.assertEquals(1, flowFiles.size());
    flowFiles.get(0).assertAttributeEquals("category", "cat");
    flowFiles.get(0).assertAttributeEquals("feed", "feed");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) FeedCleanupTriggerEvent(com.thinkbiganalytics.metadata.rest.model.event.FeedCleanupTriggerEvent) Test(org.junit.Test)

Example 5 with FeedCleanupTriggerEvent

use of com.thinkbiganalytics.metadata.rest.model.event.FeedCleanupTriggerEvent in project kylo by Teradata.

the class TriggerCleanupTest method testTriggeredWhenUnavailable.

/**
 * Verify exception when the metadata service is unavailable.
 */
@Test(expected = AssertionError.class)
public void testTriggeredWhenUnavailable() {
    runner.setProperty(TriggerCleanup.CATEGORY_NAME, "cat");
    runner.setProperty(TriggerCleanup.FEED_NAME, "unavailable");
    ((TriggerCleanup) runner.getProcessor()).triggered(new FeedCleanupTriggerEvent("FEEDID"));
    runner.run();
    Assert.assertEquals(0, runner.getFlowFilesForRelationship(TriggerCleanup.REL_SUCCESS).size());
}
Also used : FeedCleanupTriggerEvent(com.thinkbiganalytics.metadata.rest.model.event.FeedCleanupTriggerEvent) Test(org.junit.Test)

Aggregations

FeedCleanupTriggerEvent (com.thinkbiganalytics.metadata.rest.model.event.FeedCleanupTriggerEvent)6 Test (org.junit.Test)5 FeedProperties (com.thinkbiganalytics.metadata.api.feed.FeedProperties)1 CleanupListener (com.thinkbiganalytics.nifi.core.api.cleanup.CleanupListener)1 Map (java.util.Map)1 Properties (java.util.Properties)1 FlowFile (org.apache.nifi.flowfile.FlowFile)1 ProcessException (org.apache.nifi.processor.exception.ProcessException)1 MockFlowFile (org.apache.nifi.util.MockFlowFile)1