Search in sources :

Example 21 with JcrFeed

use of com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed in project kylo by Teradata.

the class RemoveDuplicateOpsManagerFeedsUpgradeAction method upgradeTo.

@Override
public void upgradeTo(final KyloVersion startingVersion) {
    log.info("remove duplicate ops manager feeds from version: {}", startingVersion);
    List<? extends OpsManagerFeed> feeds = opsManagerFeedProvider.findFeedsWithSameName();
    if (feeds != null) {
        final List<OpsManagerFeed> feedsToDelete = new ArrayList<>();
        final Map<String, OpsManagerFeed> feedsToKeep = new HashMap<>();
        feeds.stream().forEach(feed -> {
            log.info("Found duplicate feed {} - {} ", feed.getId(), feed.getName());
            Feed jcrFeed = feedProvider.getFeed(feed.getId());
            if (jcrFeed == null) {
                feedsToDelete.add(feed);
            } else {
                feedsToKeep.put(feed.getName(), feed);
            }
        });
        feedsToDelete.stream().forEach(feed -> {
            OpsManagerFeed feedToKeep = feedsToKeep.get(feed.getName());
            if (feedToKeep != null) {
                // remove it
                log.info("Unable to find feed {} - {} in JCR metadata.  A feed with id of {} already exists with this same name {}.  Attempt to remove its data from Operations Manager", feed.getId(), feed.getName(), feedToKeep.getId(), feedToKeep.getName());
                opsManagerFeedProvider.delete(feed.getId());
            }
        });
    }
}
Also used : OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) JcrFeed(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed)

Example 22 with JcrFeed

use of com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed in project kylo by Teradata.

the class JcrFeedTemplate method addFeed.

public boolean addFeed(Feed feed) {
    JcrFeed jcrFeed = (JcrFeed) feed;
    Node feedNode = jcrFeed.getNode();
    return JcrPropertyUtil.addToSetProperty(getNode(), FEEDS, feedNode, true);
}
Also used : JcrFeed(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed) Node(javax.jcr.Node)

Example 23 with JcrFeed

use of com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed in project kylo by Teradata.

the class JcrFeedServiceLevelAgreementProvider method relateFeeds.

@Override
public FeedServiceLevelAgreementRelationship relateFeeds(ServiceLevelAgreement sla, Set<Feed> feeds) {
    Node slaNode = ((JcrServiceLevelAgreement) sla).getNode();
    JcrFeedServiceLevelAgreementRelationship relationship = JcrUtil.getOrCreateNode(slaNode, RELATED_FEEDS_NODE, JcrFeedServiceLevelAgreementRelationship.NODE_TYPE, JcrFeedServiceLevelAgreementRelationship.class);
    feeds.stream().map(feed -> feedProvider.updateFeedServiceLevelAgreement(feed.getId(), sla)).map(JcrFeed.class::cast).map(JcrFeed::getNode).forEach(node -> JcrPropertyUtil.addToSetProperty(relationship.getNode(), JcrFeedServiceLevelAgreementRelationship.FEEDS, node, true));
    return relationship;
}
Also used : JcrPropertyUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) Session(javax.jcr.Session) Set(java.util.Set) HashMap(java.util.HashMap) QueryResult(javax.jcr.query.QueryResult) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) FeedServiceLevelAgreementRelationship(com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreementRelationship) List(java.util.List) FeedProvider(com.thinkbiganalytics.metadata.api.feed.FeedProvider) Stream(java.util.stream.Stream) JcrQueryUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrQueryUtil) RepositoryException(javax.jcr.RepositoryException) FeedServiceLevelAgreement(com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreement) JcrFeed(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed) FeedServiceLevelAgreementProvider(com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreementProvider) Node(javax.jcr.Node) Map(java.util.Map) JcrUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrUtil) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) JcrMetadataAccess(com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess) JcrFeed(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed) Node(javax.jcr.Node)

Example 24 with JcrFeed

use of com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed in project kylo by Teradata.

the class JcrFeedSlaTest method testCreateFeedSLAEntity.

@Test
public void testCreateFeedSLAEntity() {
    // create 2 feeds
    final int numberOfFeeds = 2;
    Set<Feed.ID> feedIds = createFeeds(numberOfFeeds);
    final String feedSlaTitle = "My New SLA";
    final String nonFeedSlaTitle = "No Feed SLA";
    ServiceLevelAgreement.ID feedSlaId = createFeedSla(feedIds, feedSlaTitle);
    ServiceLevelAgreement.ID nonFeedSla = createGenericSla(nonFeedSlaTitle);
    ServiceLevelAgreement.ID slaId = metadata.read(() -> {
        JcrFeedServiceLevelAgreementProvider jcrFeedSlaProvider = (JcrFeedServiceLevelAgreementProvider) feedSlaProvider;
        // ASSERT everything is good
        // Assert query returns the correct result
        List<FeedServiceLevelAgreementRelationship> rels = jcrFeedSlaProvider.findAllRelationships();
        Assert.assertEquals(rels.size(), 1);
        // Assert relationships are correct
        JcrFeedServiceLevelAgreementRelationship relationship = (JcrFeedServiceLevelAgreementRelationship) jcrFeedSlaProvider.findRelationship(feedSlaId);
        ServiceLevelAgreement feedSla = relationship.getAgreement();
        Assert.assertNotNull(feedSla);
        List<? extends ServiceLevelAgreement> agreements = slaProvider.getAgreements();
        // assert both agreements are there
        Assert.assertEquals(agreements.size(), 2);
        Set<JcrFeed> feeds = relationship.getPropertyAsSet(JcrFeedServiceLevelAgreementRelationship.FEEDS, JcrFeed.class);
        Assert.assertEquals(feeds.size(), numberOfFeeds);
        for (JcrFeed feed : feeds) {
            Assert.assertTrue(feedIds.contains(feed.getId()));
        }
        // find it by the SLA now
        JcrFeedServiceLevelAgreementRelationship finalFeedSla = (JcrFeedServiceLevelAgreementRelationship) jcrFeedSlaProvider.findRelationship(feedSla.getId());
        Assert.assertNotNull(finalFeedSla);
        // query for SLA objects and assert the result is correct
        List<FeedServiceLevelAgreement> feedAgreements = jcrFeedSlaProvider.findAllAgreements();
        Assert.assertEquals(feedAgreements.size(), 1);
        int nonFeedSlaCount = 0;
        for (FeedServiceLevelAgreement agreement : feedAgreements) {
            Set<? extends Feed> slaFeeds = agreement.getFeeds();
            String title = agreement.getName();
            if (slaFeeds != null) {
                Assert.assertEquals(title, feedSlaTitle);
                Assert.assertEquals(slaFeeds.size(), numberOfFeeds);
                for (Feed feed : slaFeeds) {
                    Assert.assertTrue(feedIds.contains(feed.getId()));
                }
            } else {
                Assert.assertEquals(title, nonFeedSlaTitle);
                nonFeedSlaCount++;
            }
        }
        Assert.assertEquals(nonFeedSlaCount, 0);
        // find by Feed
        for (Feed.ID feedId : feedIds) {
            List<FeedServiceLevelAgreement> feedServiceLevelAgreements = jcrFeedSlaProvider.findFeedServiceLevelAgreements(feedId);
            Assert.assertTrue(feedServiceLevelAgreements != null && !feedServiceLevelAgreements.isEmpty());
        }
        return feedSla.getId();
    }, MetadataAccess.SERVICE);
    // now remove the feed relationships
    boolean removedFeedRelationships = metadata.commit(() -> {
        ServiceLevelAgreement sla = slaProvider.getAgreement(slaId);
        return feedSlaProvider.removeFeedRelationships(slaId);
    }, MetadataAccess.SERVICE);
    Assert.assertTrue(removedFeedRelationships);
    // query for the feeds related to this SLA and verify there are none
    metadata.read(() -> {
        FeedServiceLevelAgreement feedServiceLevelAgreement = feedSlaProvider.findAgreement(slaId);
        Assert.assertTrue(feedServiceLevelAgreement.getFeeds() == null || (feedServiceLevelAgreement.getFeeds().isEmpty()));
        return null;
    }, MetadataAccess.SERVICE);
}
Also used : FeedServiceLevelAgreement(com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreement) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) FeedServiceLevelAgreement(com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreement) FeedServiceLevelAgreementRelationship(com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreementRelationship) JcrFeed(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) JcrFeed(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed) Test(org.junit.Test)

Example 25 with JcrFeed

use of com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed in project kylo by Teradata.

the class FeedWeakReferenceUpgradeAction method upgradeTo.

@Override
public void upgradeTo(final KyloVersion targetVersion) {
    log.info("Updating template feed references: {}", targetVersion);
    this.templateProvider.findAll().stream().map(JcrFeedTemplate.class::cast).map(JcrFeedTemplate::getNode).forEach(templateNode -> {
        Set<Node> feedNodes = JcrPropertyUtil.getSetProperty(templateNode, JcrFeedTemplate.FEEDS);
        JcrPropertyUtil.removeAllFromCollectionProperty(templateNode, JcrFeedTemplate.FEEDS);
        feedNodes.forEach(feedNode -> JcrPropertyUtil.addToSetProperty(templateNode, JcrFeedTemplate.FEEDS, feedNode, true));
    });
    this.feedProvider.findAll().stream().map(JcrFeed.class::cast).map(JcrFeed::getFeedDetails).filter(Optional::isPresent).map(Optional::get).map(FeedDetails::getNode).forEach(detailsNode -> {
        Node templateNode = JcrPropertyUtil.getProperty(detailsNode, FeedDetails.TEMPLATE);
        JcrPropertyUtil.setProperty(detailsNode, FeedDetails.TEMPLATE, null);
        JcrPropertyUtil.setWeakReferenceProperty(detailsNode, FeedDetails.TEMPLATE, templateNode);
    });
}
Also used : JcrFeedTemplate(com.thinkbiganalytics.metadata.modeshape.template.JcrFeedTemplate) JcrFeed(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed) Optional(java.util.Optional) Node(javax.jcr.Node)

Aggregations

JcrFeed (com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed)26 Node (javax.jcr.Node)13 Feed (com.thinkbiganalytics.metadata.api.feed.Feed)11 JcrAllowedActions (com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions)6 UpgradeException (com.thinkbiganalytics.server.upgrade.UpgradeException)5 JcrCategory (com.thinkbiganalytics.metadata.modeshape.category.JcrCategory)4 ServiceLevelAgreement (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement)4 AllowedActions (com.thinkbiganalytics.security.action.AllowedActions)4 SecurityRole (com.thinkbiganalytics.security.role.SecurityRole)4 Principal (java.security.Principal)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 Category (com.thinkbiganalytics.metadata.api.category.Category)2 ExtensibleEntity (com.thinkbiganalytics.metadata.api.extension.ExtensibleEntity)2 FeedProvider (com.thinkbiganalytics.metadata.api.feed.FeedProvider)2 FeedSource (com.thinkbiganalytics.metadata.api.feed.FeedSource)2 OpsManagerFeed (com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed)2 FeedServiceLevelAgreement (com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreement)2 FeedServiceLevelAgreementRelationship (com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreementRelationship)2