Search in sources :

Example 41 with ServiceLevelAgreement

use of com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement in project kylo by Teradata.

the class JcrFeedSlaTest method createFeedSla.

public ServiceLevelAgreement.ID createFeedSla(Set<Feed.ID> feedIdList, String title) {
    return metadata.commit(() -> {
        ServiceLevelAgreement sla = slaProvider.builder().name(title).description(title + " DESC").build();
        FeedServiceLevelAgreementRelationship fsla = feedSlaProvider.relate(sla, feedIdList);
        return fsla.getAgreement().getId();
    }, MetadataAccess.SERVICE);
}
Also used : FeedServiceLevelAgreementRelationship(com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreementRelationship) FeedServiceLevelAgreement(com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreement) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement)

Example 42 with ServiceLevelAgreement

use of com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement 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 43 with ServiceLevelAgreement

use of com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement 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 44 with ServiceLevelAgreement

use of com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement in project kylo by Teradata.

the class JcrServiceLevelAgreementProvider method addPostSlaChangeAction.

private void addPostSlaChangeAction(ServiceLevelAgreement sla, MetadataChange.ChangeType changeType) {
    ServiceLevelAgreement.ID id = sla.getId();
    String name = sla.getName();
    final Principal principal = SecurityContextHolder.getContext().getAuthentication();
    Consumer<Boolean> action = (success) -> {
        if (success) {
            ServiceLevelAgreementChange change = new ServiceLevelAgreementChange(changeType, id, name);
            ServiceLevelAgreementEvent event = new ServiceLevelAgreementEvent(change, DateTime.now(), principal);
            metadataEventService.notify(event);
        }
    };
    JcrMetadataAccess.addPostTransactionAction(action);
}
Also used : EntityUtil(com.thinkbiganalytics.metadata.modeshape.common.EntityUtil) Metric(com.thinkbiganalytics.metadata.sla.api.Metric) JcrTools(org.modeshape.jcr.api.JcrTools) SlaId(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreement.SlaId) ServiceLevelAgreementActionConfiguration(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration) QueryResult(javax.jcr.query.QueryResult) Obligation(com.thinkbiganalytics.metadata.sla.api.Obligation) JcrPropertyConstants(com.thinkbiganalytics.metadata.modeshape.common.JcrPropertyConstants) JcrQueryUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrQueryUtil) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) ServiceLevelAgreementChange(com.thinkbiganalytics.metadata.api.event.sla.ServiceLevelAgreementChange) JcrPropertyUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil) ImmutableMap(com.google.common.collect.ImmutableMap) Session(javax.jcr.Session) Collection(java.util.Collection) Set(java.util.Set) UUID(java.util.UUID) MetadataEventService(com.thinkbiganalytics.metadata.api.event.MetadataEventService) ItemNotFoundException(javax.jcr.ItemNotFoundException) Serializable(java.io.Serializable) List(java.util.List) Principal(java.security.Principal) FeedServiceLevelAgreementProvider(com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreementProvider) ServiceLevelAgreementEvent(com.thinkbiganalytics.metadata.api.event.sla.ServiceLevelAgreementEvent) BaseJcrProvider(com.thinkbiganalytics.metadata.modeshape.BaseJcrProvider) JcrMetadataAccess(com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess) JcrEntity(com.thinkbiganalytics.metadata.modeshape.common.JcrEntity) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) ServiceLevelAgreementBuilder(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementBuilder) Iterators(com.google.common.collect.Iterators) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Lists(com.google.common.collect.Lists) ObligationGroupBuilder(com.thinkbiganalytics.metadata.sla.spi.ObligationGroupBuilder) RepositoryException(javax.jcr.RepositoryException) Node(javax.jcr.Node) ServiceLevelAgreementCheckBuilder(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementCheckBuilder) MetadataChange(com.thinkbiganalytics.metadata.api.event.MetadataChange) JcrFeedPrecondition(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeedPrecondition) ID(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement.ID) Iterator(java.util.Iterator) DateTime(org.joda.time.DateTime) ServiceLevelAgreementActionConfig(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfig) ServiceLevelAgreementProvider(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementProvider) ServiceLevelAgreementCheck(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementCheck) Consumer(java.util.function.Consumer) Condition(com.thinkbiganalytics.metadata.sla.api.ObligationGroup.Condition) JcrUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrUtil) ObligationBuilder(com.thinkbiganalytics.metadata.sla.spi.ObligationBuilder) ServiceLevelAgreementEvent(com.thinkbiganalytics.metadata.api.event.sla.ServiceLevelAgreementEvent) ServiceLevelAgreementChange(com.thinkbiganalytics.metadata.api.event.sla.ServiceLevelAgreementChange) ID(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement.ID) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) Principal(java.security.Principal)

Aggregations

ServiceLevelAgreement (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement)44 Test (org.junit.Test)20 ServiceLevelAssessment (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment)19 JcrServiceLevelAgreement (com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreement)8 ArrayList (java.util.ArrayList)6 Feed (com.thinkbiganalytics.metadata.api.feed.Feed)5 Obligation (com.thinkbiganalytics.metadata.sla.api.Obligation)5 Node (javax.jcr.Node)5 JobIdentifier (com.thinkbiganalytics.scheduler.JobIdentifier)4 DefaultJobIdentifier (com.thinkbiganalytics.scheduler.model.DefaultJobIdentifier)4 List (java.util.List)4 Set (java.util.Set)4 Lists (com.google.common.collect.Lists)3 FeedServiceLevelAgreement (com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreement)3 FeedServiceLevelAgreementProvider (com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreementProvider)3 FeedServiceLevelAgreementRelationship (com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreementRelationship)3 JcrMetadataAccess (com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess)3 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)3 JcrFeed (com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed)3 JcrPropertyUtil (com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil)3