Search in sources :

Example 1 with MetadataProviderService

use of com.thinkbiganalytics.nifi.core.api.metadata.MetadataProviderService in project kylo by Teradata.

the class GetFeedsHistoryReindex method onTrigger.

@Override
public void onTrigger(ProcessContext context, ProcessSession session) {
    final ComponentLog logger = getLog();
    FlowFile flowFile = session.get();
    if (flowFile == null) {
        flowFile = session.create();
    }
    logger.debug("Checking for feeds requiring reindexing historical data");
    try {
        MetadataProviderService metadataProviderService = getMetadataService(context);
        if ((metadataProviderService != null) && (metadataProviderService.getProvider() != null)) {
            String dateTimeOfCheck = String.valueOf(DateTime.now(DateTimeZone.UTC));
            FeedsForDataHistoryReindex feedsForHistoryReindexing = getMetadataService(context).getProvider().getFeedsForHistoryReindexing();
            if (feedsForHistoryReindexing != null) {
                logger.info("Found {} feeds requiring reindexing historical data", new Object[] { feedsForHistoryReindexing.getFeeds().size() });
                if (feedsForHistoryReindexing.getFeedCount() > 0) {
                    for (Feed feedForHistoryReindexing : feedsForHistoryReindexing.getFeeds()) {
                        Map<String, String> attributes = new HashMap<>();
                        attributes.put(FEED_ID_FOR_HISTORY_REINDEX_KEY, feedForHistoryReindexing.getId());
                        attributes.put(FEED_SYSTEM_NAME_FOR_HISTORY_REINDEX_KEY, feedForHistoryReindexing.getSystemName());
                        attributes.put(FEED_CATEGORY_SYSTEM_NAME_FOR_HISTORY_REINDEX_KEY, feedForHistoryReindexing.getCategory().getSystemName());
                        attributes.put(FEED_STATUS_FOR_HISTORY_REINDEX_KEY, feedForHistoryReindexing.getCurrentHistoryReindexingStatus().getHistoryReindexingState().toString());
                        attributes.put(FEED_LAST_MODIFIED_UTC_FOR_HISTORY_REINDEX_KEY, feedForHistoryReindexing.getCurrentHistoryReindexingStatus().getLastModifiedTimestamp().toString());
                        attributes.put(FEEDS_TOTAL_COUNT_FOR_HISTORY_REINDEX_KEY, String.valueOf(feedsForHistoryReindexing.getFeedCount()));
                        attributes.put(FEEDS_TOTAL_IDS_FOR_HISTORY_REINDEX_KEY, feedsForHistoryReindexing.getFeedIds().toString());
                        attributes.put(FEEDS_CHECK_TIME_UTC_FOR_HISTORY_REINDEX_KEY, dateTimeOfCheck);
                        // all attributes from parent flow file copied except uuid, creates a FORK event
                        FlowFile feedFlowFile = session.create(flowFile);
                        feedFlowFile = session.putAllAttributes(feedFlowFile, attributes);
                        session.transfer(feedFlowFile, REL_FOUND);
                        logger.info("Flow file created for reindexing feed's historical data: feed id {}, category name {}, feed name {}", new Object[] { FEED_ID_FOR_HISTORY_REINDEX_KEY, FEED_CATEGORY_SYSTEM_NAME_FOR_HISTORY_REINDEX_KEY, FEED_SYSTEM_NAME_FOR_HISTORY_REINDEX_KEY });
                    }
                    flowFile = session.putAttribute(flowFile, FEEDS_TOTAL_COUNT_FOR_HISTORY_REINDEX_KEY, String.valueOf(feedsForHistoryReindexing.getFeedCount()));
                    flowFile = session.putAttribute(flowFile, FEEDS_CHECK_TIME_UTC_FOR_HISTORY_REINDEX_KEY, dateTimeOfCheck);
                    // only for found case
                    session.transfer(flowFile, REL_ORIGINAL);
                } else {
                    // this will always be 0 here
                    flowFile = session.putAttribute(flowFile, FEEDS_TOTAL_COUNT_FOR_HISTORY_REINDEX_KEY, String.valueOf(feedsForHistoryReindexing.getFeedCount()));
                    // this will always be empty list here
                    flowFile = session.putAttribute(flowFile, FEEDS_TOTAL_IDS_FOR_HISTORY_REINDEX_KEY, feedsForHistoryReindexing.getFeedIds().toString());
                    flowFile = session.putAttribute(flowFile, FEEDS_CHECK_TIME_UTC_FOR_HISTORY_REINDEX_KEY, dateTimeOfCheck);
                    session.transfer(flowFile, REL_NOT_FOUND);
                }
            }
        } else {
            logger.error("Error checking for feeds requiring reindexing historical data. Check if Kylo services is running, and accessible from NiFi.");
            session.transfer(flowFile, REL_FAILURE);
        }
    } catch (Exception e) {
        logger.error("An exception was thrown during check for feeds requiring reindexing historical data: {}", new Object[] { e });
        session.transfer(flowFile, REL_FAILURE);
    }
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) HashMap(java.util.HashMap) FeedsForDataHistoryReindex(com.thinkbiganalytics.metadata.rest.model.feed.reindex.FeedsForDataHistoryReindex) ComponentLog(org.apache.nifi.logging.ComponentLog) MetadataProviderService(com.thinkbiganalytics.nifi.core.api.metadata.MetadataProviderService) Feed(com.thinkbiganalytics.metadata.rest.model.feed.Feed)

Example 2 with MetadataProviderService

use of com.thinkbiganalytics.nifi.core.api.metadata.MetadataProviderService in project kylo by Teradata.

the class GetTableDataTest method setUp.

/**
 * Initialize instance variables
 */
@Before
public void setUp() throws Exception {
    // Setup services
    final DBCPService jdbcService = new MockDBCPService();
    final MetadataProviderService metadataService = new MockMetadataService();
    // Setup test runner
    runner.addControllerService(JDBC_SERVICE_IDENTIFIER, jdbcService);
    runner.addControllerService(METADATA_SERVICE_IDENTIFIER, metadataService);
    runner.enableControllerService(jdbcService);
    runner.enableControllerService(metadataService);
    runner.setProperty(GetTableData.JDBC_SERVICE, JDBC_SERVICE_IDENTIFIER);
    runner.setProperty(CommonProperties.METADATA_SERVICE, METADATA_SERVICE_IDENTIFIER);
    runner.setProperty(GetTableData.TABLE_NAME, "mytable");
    runner.setProperty(GetTableData.TABLE_SPECS, "id\nfirst_name\nlast_name\nemail  \n last_updated  \n\n");
}
Also used : DBCPService(org.apache.nifi.dbcp.DBCPService) MetadataProviderService(com.thinkbiganalytics.nifi.core.api.metadata.MetadataProviderService) Before(org.junit.Before)

Example 3 with MetadataProviderService

use of com.thinkbiganalytics.nifi.core.api.metadata.MetadataProviderService in project kylo by Teradata.

the class TriggerCleanupTest method setUp.

/**
 * Initialize instance variables.
 */
@Before
public void setUp() throws Exception {
    // Setup services
    final CleanupEventService cleanupService = new MockCleanupEventService();
    final MetadataProviderService metadataService = new MockMetadataProviderService();
    // Setup test runner
    runner.addControllerService(CLEANUP_SERVICE_IDENTIFIER, cleanupService);
    runner.addControllerService(METADATA_SERVICE_IDENTIFIER, metadataService);
    runner.enableControllerService(cleanupService);
    runner.enableControllerService(metadataService);
    runner.setProperty(TriggerCleanup.CLEANUP_SERVICE, CLEANUP_SERVICE_IDENTIFIER);
    runner.setProperty(TriggerCleanup.METADATA_SERVICE, METADATA_SERVICE_IDENTIFIER);
}
Also used : CleanupEventService(com.thinkbiganalytics.nifi.core.api.cleanup.CleanupEventService) MetadataProviderService(com.thinkbiganalytics.nifi.core.api.metadata.MetadataProviderService) Before(org.junit.Before)

Example 4 with MetadataProviderService

use of com.thinkbiganalytics.nifi.core.api.metadata.MetadataProviderService in project kylo by Teradata.

the class GetFeedsHistoryReindexTest method testGeneralExceptionGettingFeedsToReindex.

@Test
public void testGeneralExceptionGettingFeedsToReindex() throws Exception {
    final String METADATA_SERVICE_IDENTIFIER = "MockMetadataProviderService_GeneralExceptionGettingFeedsToReindex";
    final TestRunner runner = TestRunners.newTestRunner(GetFeedsHistoryReindex.class);
    final MetadataProviderService metadataService = new MockMetadataProviderService_GeneralExceptionGettingFeedsToReindex();
    runner.addControllerService(METADATA_SERVICE_IDENTIFIER, metadataService);
    runner.enableControllerService(metadataService);
    runner.setProperty(GetFeedsHistoryReindex.METADATA_SERVICE, METADATA_SERVICE_IDENTIFIER);
    runner.run(1);
    runner.assertQueueEmpty();
    runner.assertTransferCount(GetFeedsHistoryReindex.REL_FOUND, 0);
    runner.assertTransferCount(GetFeedsHistoryReindex.REL_NOT_FOUND, 0);
    runner.assertTransferCount(GetFeedsHistoryReindex.REL_FAILURE, 1);
    runner.assertTransferCount(GetFeedsHistoryReindex.REL_ORIGINAL, 0);
    List<MockFlowFile> results = runner.getFlowFilesForRelationship(GetFeedsHistoryReindex.REL_FAILURE);
    MockFlowFile resultFlowFile = results.get(0);
    resultFlowFile.assertAttributeNotExists(GetFeedsHistoryReindex.FEEDS_TOTAL_COUNT_FOR_HISTORY_REINDEX_KEY);
    resultFlowFile.assertAttributeNotExists(GetFeedsHistoryReindex.FEEDS_TOTAL_IDS_FOR_HISTORY_REINDEX_KEY);
    resultFlowFile.assertAttributeNotExists(GetFeedsHistoryReindex.FEEDS_CHECK_TIME_UTC_FOR_HISTORY_REINDEX_KEY);
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) MetadataProviderService(com.thinkbiganalytics.nifi.core.api.metadata.MetadataProviderService) Test(org.junit.Test)

Example 5 with MetadataProviderService

use of com.thinkbiganalytics.nifi.core.api.metadata.MetadataProviderService in project kylo by Teradata.

the class GetFeedsHistoryReindexTest method testErrorGettingFeedsToReindex.

@Test
public void testErrorGettingFeedsToReindex() throws Exception {
    final String METADATA_SERVICE_IDENTIFIER = "MockMetadataProviderService_ErrorGettingFeedsToReindex";
    final TestRunner runner = TestRunners.newTestRunner(GetFeedsHistoryReindex.class);
    final MetadataProviderService metadataService = new MockMetadataProviderService_ErrorGettingFeedsToReindex();
    runner.addControllerService(METADATA_SERVICE_IDENTIFIER, metadataService);
    runner.enableControllerService(metadataService);
    runner.setProperty(GetFeedsHistoryReindex.METADATA_SERVICE, METADATA_SERVICE_IDENTIFIER);
    runner.run(1);
    runner.assertQueueEmpty();
    runner.assertTransferCount(GetFeedsHistoryReindex.REL_FOUND, 0);
    runner.assertTransferCount(GetFeedsHistoryReindex.REL_NOT_FOUND, 0);
    runner.assertTransferCount(GetFeedsHistoryReindex.REL_FAILURE, 1);
    runner.assertTransferCount(GetFeedsHistoryReindex.REL_ORIGINAL, 0);
    List<MockFlowFile> results = runner.getFlowFilesForRelationship(GetFeedsHistoryReindex.REL_FAILURE);
    MockFlowFile resultFlowFile = results.get(0);
    resultFlowFile.assertAttributeNotExists(GetFeedsHistoryReindex.FEEDS_TOTAL_COUNT_FOR_HISTORY_REINDEX_KEY);
    resultFlowFile.assertAttributeNotExists(GetFeedsHistoryReindex.FEEDS_TOTAL_IDS_FOR_HISTORY_REINDEX_KEY);
    resultFlowFile.assertAttributeNotExists(GetFeedsHistoryReindex.FEEDS_CHECK_TIME_UTC_FOR_HISTORY_REINDEX_KEY);
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) MetadataProviderService(com.thinkbiganalytics.nifi.core.api.metadata.MetadataProviderService) Test(org.junit.Test)

Aggregations

MetadataProviderService (com.thinkbiganalytics.nifi.core.api.metadata.MetadataProviderService)21 Test (org.junit.Test)14 TestRunner (org.apache.nifi.util.TestRunner)13 Matchers.anyString (org.mockito.Matchers.anyString)9 MockFlowFile (org.apache.nifi.util.MockFlowFile)5 FlowFile (org.apache.nifi.flowfile.FlowFile)4 ComponentLog (org.apache.nifi.logging.ComponentLog)4 ProcessException (org.apache.nifi.processor.exception.ProcessException)3 Before (org.junit.Before)3 IOException (java.io.IOException)2 DBCPService (org.apache.nifi.dbcp.DBCPService)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 GetTableDataSupport (com.thinkbiganalytics.ingest.GetTableDataSupport)1 Feed (com.thinkbiganalytics.metadata.rest.model.feed.Feed)1 FeedDataHistoryReindexParams (com.thinkbiganalytics.metadata.rest.model.feed.reindex.FeedDataHistoryReindexParams)1 FeedsForDataHistoryReindex (com.thinkbiganalytics.metadata.rest.model.feed.reindex.FeedsForDataHistoryReindex)1 HistoryReindexingStatus (com.thinkbiganalytics.metadata.rest.model.feed.reindex.HistoryReindexingStatus)1 CleanupEventService (com.thinkbiganalytics.nifi.core.api.cleanup.CleanupEventService)1 ApplySecurityPolicy (com.thinkbiganalytics.nifi.security.ApplySecurityPolicy)1 InputStreamReaderRunnable (com.thinkbiganalytics.nifi.util.InputStreamReaderRunnable)1