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