Search in sources :

Example 1 with Feed

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

the class FeedOpsUpgradeAction method upgradeTo.

/* (non-Javadoc)
     * @see com.thinkbiganalytics.metadata.upgrade.UpgradeState#upgradeFrom(com.thinkbiganalytics.metadata.api.app.KyloVersion)
     */
@Override
public void upgradeTo(KyloVersion startingVersion) {
    log.info("Upgrading from version: " + startingVersion);
    for (Category category : categoryProvider.findAll()) {
        // Ensure each category has an allowedActions (gets create if not present.)
        category.getAllowedActions();
    }
    // get all feeds defined in feed manager
    List<Feed> domainFeeds = feedProvider.findAll();
    Map<String, Feed> feedManagerFeedMap = new HashMap<>();
    if (domainFeeds != null && !domainFeeds.isEmpty()) {
        List<OpsManagerFeed.ID> opsManagerFeedIds = new ArrayList<OpsManagerFeed.ID>();
        for (Feed feedManagerFeed : domainFeeds) {
            opsManagerFeedIds.add(opsManagerFeedProvider.resolveId(feedManagerFeed.getId().toString()));
            feedManagerFeedMap.put(feedManagerFeed.getId().toString(), feedManagerFeed);
            // Ensure each feed has an allowedActions (gets create if not present.)
            feedManagerFeed.getAllowedActions();
        }
        // find those that match
        List<? extends OpsManagerFeed> opsManagerFeeds = opsManagerFeedProvider.findByFeedIds(opsManagerFeedIds);
        if (opsManagerFeeds != null) {
            for (OpsManagerFeed opsManagerFeed : opsManagerFeeds) {
                feedManagerFeedMap.remove(opsManagerFeed.getId().toString());
            }
        }
        List<OpsManagerFeed> feedsToAdd = new ArrayList<>();
        for (Feed feed : feedManagerFeedMap.values()) {
            String fullName = FeedNameUtil.fullName(feed.getCategory().getSystemName(), feed.getName());
            OpsManagerFeed.ID opsManagerFeedId = opsManagerFeedProvider.resolveId(feed.getId().toString());
            OpsManagerFeed opsManagerFeed = new JpaOpsManagerFeed(opsManagerFeedId, fullName);
            feedsToAdd.add(opsManagerFeed);
        }
        log.info("Synchronizing Feeds from Feed Manager. About to insert {} feed ids/names into Operations Manager", feedsToAdd.size());
        opsManagerFeedProvider.save(feedsToAdd);
    }
}
Also used : Category(com.thinkbiganalytics.metadata.api.category.Category) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.JpaOpsManagerFeed) JpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.JpaOpsManagerFeed) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) JpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.JpaOpsManagerFeed) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed)

Example 2 with Feed

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

the class EnsureTemplateFeedRelationshipsUpgradeAction method ensureFeedTemplateFeedRelationships.

private void ensureFeedTemplateFeedRelationships() {
    // ensure the templates have the feed relationships
    List<Feed> feeds = feedProvider.findAll();
    if (feeds != null) {
        feeds.stream().forEach(feed -> {
            FeedManagerTemplate template = feed.getTemplate();
            if (template != null) {
                // ensure the template has feeds.
                List<Feed> templateFeeds = null;
                try {
                    templateFeeds = template.getFeeds();
                } catch (MetadataRepositoryException e) {
                    // templateFeeds are weak references.
                    // if the template feeds return itemNotExists we need to reset it
                    Throwable rootCause = ExceptionUtils.getRootCause(e);
                    if (rootCause != null && rootCause instanceof ItemNotFoundException) {
                        // reset the reference collection.  It will be rebuilt in the subsequent call
                        JcrPropertyUtil.removeAllFromSetProperty(((JcrFeedTemplate) template).getNode(), JcrFeedTemplate.FEEDS);
                    }
                }
                if (templateFeeds == null || !templateFeeds.contains(feed)) {
                    log.info("Updating relationship temlate: {} -> feed: {}", template.getName(), feed.getName());
                    template.addFeed(feed);
                    feedManagerTemplateProvider.update(template);
                }
            }
        });
    }
    feedProvider.populateInverseFeedDependencies();
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) JcrFeedTemplate(com.thinkbiganalytics.metadata.modeshape.template.JcrFeedTemplate) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) JcrFeed(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 3 with Feed

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

the class FeedSlaUpgradeAction method upgradeFeedSla.

private void upgradeFeedSla(ExtensibleType type) {
    List<ExtensibleEntity> slaRels = entityProvider.getEntities(SLA_REL_TYPE_NAME);
    for (ExtensibleEntity rel : slaRels) {
        ServiceLevelAgreement sla = JcrUtil.getJcrObject(rel.getProperty("sla"), JcrServiceLevelAgreement.class);
        Set<Feed> feeds = rel.getPropertyAsSet("feeds", Node.class).stream().map(JcrFeed::new).collect(Collectors.toSet());
        feedSlaProvider.relateFeeds(sla, feeds);
        entityProvider.deleteEntity(rel.getId());
    }
    this.typeProvider.deleteType(type.getId());
}
Also used : Node(javax.jcr.Node) JcrServiceLevelAgreement(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreement) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) ExtensibleEntity(com.thinkbiganalytics.metadata.api.extension.ExtensibleEntity) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) JcrFeed(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed)

Example 4 with Feed

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

the class JobExecutionChangedNotifier method newFeedOperationStatusEvent.

private FeedOperationStatusEvent newFeedOperationStatusEvent(Long jobExecutionId, OpsManagerFeed feed, FeedOperation.State state, String status) {
    String feedName = feed != null ? feed.getName() : null;
    Feed.ID feedId = feed != null ? feed.getId() : null;
    FeedOperation.FeedType feedType = feed != null ? FeedOperation.FeedType.valueOf(feed.getFeedType().name()) : FeedOperation.FeedType.FEED;
    return new FeedOperationStatusEvent(new OperationStatus(feedId, feedName, feedType, new OpId(jobExecutionId), state, status));
}
Also used : FeedOperationStatusEvent(com.thinkbiganalytics.metadata.api.event.feed.FeedOperationStatusEvent) OperationStatus(com.thinkbiganalytics.metadata.api.event.feed.OperationStatus) FeedOperation(com.thinkbiganalytics.metadata.api.op.FeedOperation) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed)

Example 5 with Feed

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

the class FeedExecutedSinceFeedAssessorTest method setUpAssessor.

/**
 * @param triggeredFeedStartTime pass negative value for empty operations list
 * @param mainFeedStopTime       pass negative for empty operations list
 */
private FeedExecutedSinceFeedAssessor setUpAssessor(int triggeredFeedStartTime, boolean isTriggeredFeedRunning, int mainFeedStopTime, boolean isMainFeedRunning) {
    FeedCriteria dummyCriteria = mock(FeedCriteria.class);
    when(dummyCriteria.name(Mockito.anyString())).thenReturn(dummyCriteria);
    when(dummyCriteria.category(Mockito.anyString())).thenReturn(dummyCriteria);
    FeedProvider feedProvider = mock(FeedProvider.class);
    when(feedProvider.feedCriteria()).thenReturn(dummyCriteria);
    List<Feed> triggeredFeeds = new ArrayList<>();
    Feed triggeredFeed = mock(Feed.class);
    Feed.ID triggeredFeedId = mock(Feed.ID.class);
    when(triggeredFeed.getId()).thenReturn(triggeredFeedId);
    triggeredFeeds.add(triggeredFeed);
    List<Feed> mainFeeds = new ArrayList<>();
    Feed mainFeed = mock(Feed.class);
    Feed.ID mainFeedId = mock(Feed.ID.class);
    when(mainFeed.getId()).thenReturn(mainFeedId);
    mainFeeds.add(mainFeed);
    when(feedProvider.getFeeds(dummyCriteria)).thenReturn(mainFeeds, triggeredFeeds);
    FeedOperationsProvider opsProvider = mock(FeedOperationsProvider.class);
    List<FeedOperation> triggeredFeedOps = new ArrayList<>();
    if (triggeredFeedStartTime > 0) {
        FeedOperation triggeredOp = mock(FeedOperation.class);
        when(triggeredOp.getStartTime()).thenReturn(new DateTime(triggeredFeedStartTime));
        triggeredFeedOps.add(triggeredOp);
    }
    List<FeedOperation> mainFeedOps = new ArrayList<>();
    if (mainFeedStopTime > 0) {
        FeedOperation mainFeedOp = mock(FeedOperation.class);
        when(mainFeedOp.getStopTime()).thenReturn(new DateTime(mainFeedStopTime));
        mainFeedOps.add(mainFeedOp);
    }
    when(opsProvider.findLatestCompleted(mainFeedId)).thenReturn(mainFeedOps);
    when(opsProvider.findLatest(triggeredFeedId)).thenReturn(triggeredFeedOps);
    when(opsProvider.isFeedRunning(mainFeedId)).thenReturn(isMainFeedRunning);
    when(opsProvider.isFeedRunning(triggeredFeedId)).thenReturn(isTriggeredFeedRunning);
    return new FeedExecutedSinceFeedAssessor() {

        @Override
        protected FeedProvider getFeedProvider() {
            return feedProvider;
        }

        @Override
        protected FeedOperationsProvider getFeedOperationsProvider() {
            return opsProvider;
        }
    };
}
Also used : ArrayList(java.util.ArrayList) FeedOperation(com.thinkbiganalytics.metadata.api.op.FeedOperation) FeedOperationsProvider(com.thinkbiganalytics.metadata.api.op.FeedOperationsProvider) FeedCriteria(com.thinkbiganalytics.metadata.api.feed.FeedCriteria) FeedProvider(com.thinkbiganalytics.metadata.api.feed.FeedProvider) DateTime(org.joda.time.DateTime) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) FeedExecutedSinceFeed(com.thinkbiganalytics.metadata.api.sla.FeedExecutedSinceFeed)

Aggregations

Feed (com.thinkbiganalytics.metadata.api.feed.Feed)89 ArrayList (java.util.ArrayList)29 UIFeed (com.thinkbiganalytics.feedmgr.rest.model.UIFeed)26 NifiFeed (com.thinkbiganalytics.feedmgr.rest.model.NifiFeed)23 Category (com.thinkbiganalytics.metadata.api.category.Category)23 FeedNotFoundException (com.thinkbiganalytics.metadata.api.feed.FeedNotFoundException)23 FeedManagerTemplate (com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate)23 HashMap (java.util.HashMap)21 List (java.util.List)21 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)20 FeedProvider (com.thinkbiganalytics.metadata.api.feed.FeedProvider)20 Collectors (java.util.stream.Collectors)19 Inject (javax.inject.Inject)19 DateTime (org.joda.time.DateTime)19 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)18 AccessController (com.thinkbiganalytics.security.AccessController)18 HashSet (java.util.HashSet)18 Map (java.util.Map)18 Set (java.util.Set)18 FeedAccessControl (com.thinkbiganalytics.metadata.api.feed.security.FeedAccessControl)17