Search in sources :

Example 61 with Feed

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

the class JcrFeedAllowedActionsTest method testSeeOwnFeedContentOnly.

@Test
public void testSeeOwnFeedContentOnly() {
    metadata.read(() -> {
        Feed feedA = this.feedProvider.getFeed(idA);
        assertThat(feedA.getDescription()).isNotNull().isEqualTo("Feed A");
        assertThat(feedA.getJson()).isNotNull();
        assertThat(feedA.getState()).isNotNull();
        Feed feedB = this.feedProvider.getFeed(idB);
        assertThat(feedB).isNull();
    }, TEST_USER1);
}
Also used : Feed(com.thinkbiganalytics.metadata.api.feed.Feed) Test(org.junit.Test)

Example 62 with Feed

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

the class JcrFeedRolesTest method testAddMembership.

@Test
public void testAddMembership() {
    metadata.read(() -> {
        Feed feedA = this.feedProvider.getFeed(idA);
        assertThat(feedA).isNull();
        Feed feedB = this.feedProvider.getFeed(idB);
        assertThat(feedB).isNull();
    }, TEST_USER3);
    metadata.commit(() -> {
        this.feedProvider.findById(idA).getRoleMembership("testViewer").ifPresent(m -> m.addMember(TEST_USER3));
        this.feedProvider.findById(idB).getRoleMembership("testEditor").ifPresent(m -> m.addMember(TEST_USER3));
    }, JcrMetadataAccess.SERVICE);
    metadata.read(() -> {
        Feed feedA = this.feedProvider.getFeed(idA);
        assertThat(feedA.getDescription()).isNotNull().isEqualTo("Feed A");
        assertThat(feedA.getJson()).isNull();
        assertThat(feedA.getState()).isNull();
        Feed feedB = this.feedProvider.getFeed(idB);
        assertThat(feedB.getDescription()).isNotNull().isEqualTo("Feed B");
        assertThat(feedB.getJson()).isNotNull();
        assertThat(feedB.getState()).isNotNull();
    }, TEST_USER3);
}
Also used : Feed(com.thinkbiganalytics.metadata.api.feed.Feed) Test(org.junit.Test)

Example 63 with Feed

use of com.thinkbiganalytics.metadata.api.feed.Feed 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 64 with Feed

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

the class JobRepoFeedOperationsProvider method findLatest.

@Override
public List<FeedOperation> findLatest(Feed.ID feedId) {
    return metadata.read(() -> {
        List<FeedOperation> operations = new ArrayList<>();
        Feed feed = this.feedProvider.getFeed(feedId);
        if (feed != null) {
            BatchJobExecution latestJobExecution = this.jobExecutionProvider.findLatestJobForFeed(feed.getQualifiedName());
            if (latestJobExecution != null) {
                operations.add(createOperation(latestJobExecution));
            }
        }
        return operations;
    });
}
Also used : BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution) FeedOperation(com.thinkbiganalytics.metadata.api.op.FeedOperation) ArrayList(java.util.ArrayList) Feed(com.thinkbiganalytics.metadata.api.feed.Feed)

Example 65 with Feed

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

the class JobRepoFeedOperationsProvider method getDependentDeltaResults.

@Override
public FeedDependencyDeltaResults getDependentDeltaResults(Feed.ID feedId, Set<String> props) {
    Feed feed = this.feedProvider.getFeed(feedId);
    if (feed != null) {
        String systemFeedName = FeedNameUtil.fullName(feed.getCategory().getSystemName(), feed.getName());
        FeedDependencyDeltaResults results = new FeedDependencyDeltaResults(feed.getId().toString(), systemFeedName);
        // find this feeds latest completion
        BatchJobExecution latest = jobExecutionProvider.findLatestCompletedJobForFeed(systemFeedName);
        // get the dependent feeds
        List<Feed> dependents = feed.getDependentFeeds();
        if (dependents != null) {
            for (Feed depFeed : dependents) {
                String depFeedSystemName = FeedNameUtil.fullName(depFeed.getCategory().getSystemName(), depFeed.getName());
                // find Completed feeds executed since time
                Set<BatchJobExecution> jobs = null;
                if (latest != null) {
                    jobs = (Set<BatchJobExecution>) jobExecutionProvider.findJobsForFeedCompletedSince(depFeedSystemName, latest.getStartTime());
                } else {
                    BatchJobExecution job = jobExecutionProvider.findLatestCompletedJobForFeed(depFeedSystemName);
                    if (job != null) {
                        jobs = new HashSet<>();
                        jobs.add(job);
                    }
                }
                if (jobs != null) {
                    for (BatchJobExecution job : jobs) {
                        DateTime endTime = job.getEndTime();
                        Map<String, String> executionContext = job.getJobExecutionContextAsMap();
                        Map<String, Object> map = new HashMap<>();
                        // filter the map
                        if (executionContext != null) {
                            // add those requested to the results map
                            for (Entry<String, String> entry : executionContext.entrySet()) {
                                if (props == null || props.isEmpty() || props.contains(entry.getKey())) {
                                    map.put(entry.getKey(), entry.getValue());
                                }
                            }
                        }
                        results.addFeedExecutionContext(depFeedSystemName, job.getJobExecutionId(), job.getStartTime(), endTime, map);
                    }
                } else {
                    results.getDependentFeedNames().add(depFeedSystemName);
                }
            }
        }
        return results;
    } else {
        throw new FeedNotFoundException(feedId);
    }
}
Also used : HashMap(java.util.HashMap) FeedNotFoundException(com.thinkbiganalytics.metadata.api.feed.FeedNotFoundException) FeedDependencyDeltaResults(com.thinkbiganalytics.metadata.api.op.FeedDependencyDeltaResults) DateTime(org.joda.time.DateTime) BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution) Feed(com.thinkbiganalytics.metadata.api.feed.Feed)

Aggregations

Feed (com.thinkbiganalytics.metadata.api.feed.Feed)69 ArrayList (java.util.ArrayList)19 UIFeed (com.thinkbiganalytics.feedmgr.rest.model.UIFeed)17 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)15 NifiFeed (com.thinkbiganalytics.feedmgr.rest.model.NifiFeed)15 Category (com.thinkbiganalytics.metadata.api.category.Category)14 FeedNotFoundException (com.thinkbiganalytics.metadata.api.feed.FeedNotFoundException)14 FeedManagerTemplate (com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate)13 List (java.util.List)13 FeedProvider (com.thinkbiganalytics.metadata.api.feed.FeedProvider)12 HashMap (java.util.HashMap)12 DateTime (org.joda.time.DateTime)12 ID (com.thinkbiganalytics.metadata.api.feed.Feed.ID)11 Collectors (java.util.stream.Collectors)11 Inject (javax.inject.Inject)11 Test (org.junit.Test)11 FeedAccessControl (com.thinkbiganalytics.metadata.api.feed.security.FeedAccessControl)10 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)10 AccessController (com.thinkbiganalytics.security.AccessController)10 HashSet (java.util.HashSet)10