use of com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreementRelationship in project kylo by Teradata.
the class DefaultServiceLevelAgreementService method saveAndScheduleSla.
/**
* In order to Save an SLA if it is related to a Feed(s) the user needs to have EDIT_DETAILS permission on the Feed(s)
*
* @param serviceLevelAgreement the sla to save
* @param feed an option Feed to relate to this SLA. If this is not present the related feeds are also embedded in the SLA policies. The Feed is a pointer access to the current
* feed the user is editing if they are creating an SLA from the Feed Details page. If creating an SLA from the main SLA page the feed property will not be populated.
*/
private ServiceLevelAgreement saveAndScheduleSla(ServiceLevelAgreementGroup serviceLevelAgreement, FeedMetadata feed) {
// ensure user has permissions to edit the SLA
if (serviceLevelAgreement != null) {
ServiceLevelAgreementMetricTransformerHelper transformer = new ServiceLevelAgreementMetricTransformerHelper();
// Read the feeds on the SLA as a Service. Then verify the current user has access to edit these feeds
List<String> feedsOnSla = metadataAccess.read(() -> {
List<String> feedIds = new ArrayList<>();
// all referencing Feeds
List<String> systemCategoryAndFeedNames = transformer.getCategoryFeedNames(serviceLevelAgreement);
for (String categoryAndFeed : systemCategoryAndFeedNames) {
// fetch and update the reference to the sla
String categoryName = StringUtils.trim(StringUtils.substringBefore(categoryAndFeed, "."));
String feedName = StringUtils.trim(StringUtils.substringAfterLast(categoryAndFeed, "."));
Feed feedEntity = feedProvider.findBySystemName(categoryName, feedName);
if (feedEntity != null) {
feedIds.add(feedEntity.getId().toString());
}
}
return feedIds;
}, MetadataAccess.SERVICE);
boolean allowedToEdit = feedsOnSla.isEmpty() ? true : feedsOnSla.stream().allMatch(feedId -> feedManagerFeedService.checkFeedPermission(feedId, FeedAccessControl.EDIT_DETAILS));
if (allowedToEdit) {
return metadataAccess.commit(() -> {
// Re read back in the Feeds for this session
Set<Feed> slaFeeds = new HashSet<Feed>();
Set<Feed.ID> slaFeedIds = new HashSet<Feed.ID>();
feedsOnSla.stream().forEach(feedId -> {
Feed feedEntity = feedProvider.findById(feedProvider.resolveId(feedId));
if (feedEntity != null) {
slaFeeds.add(feedEntity);
slaFeedIds.add(feedEntity.getId());
}
});
if (feed != null) {
feedManagerFeedService.checkFeedPermission(feed.getId(), FeedAccessControl.EDIT_DETAILS);
}
if (feed != null) {
transformer.applyFeedNameToCurrentFeedProperties(serviceLevelAgreement, feed.getCategory().getSystemName(), feed.getSystemFeedName());
}
ServiceLevelAgreement sla = transformer.getServiceLevelAgreement(serviceLevelAgreement);
ServiceLevelAgreementBuilder slaBuilder = null;
com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement.ID existingId = null;
if (StringUtils.isNotBlank(sla.getId())) {
existingId = slaProvider.resolve(sla.getId());
}
if (existingId != null) {
slaBuilder = slaProvider.builder(existingId);
} else {
slaBuilder = slaProvider.builder();
}
slaBuilder.name(sla.getName()).description(sla.getDescription());
for (com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup group : sla.getGroups()) {
ObligationGroupBuilder groupBuilder = slaBuilder.obligationGroupBuilder(ObligationGroup.Condition.valueOf(group.getCondition()));
for (Obligation o : group.getObligations()) {
groupBuilder.obligationBuilder().metric(o.getMetrics()).description(o.getDescription()).build();
}
groupBuilder.build();
}
com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement savedSla = slaBuilder.build();
List<ServiceLevelAgreementActionConfiguration> actions = transformer.getActionConfigurations(serviceLevelAgreement);
// now assign the sla checks
slaProvider.slaCheckBuilder(savedSla.getId()).removeSlaChecks().actionConfigurations(actions).build();
// relate them
Set<Feed.ID> feedIds = new HashSet<>();
FeedServiceLevelAgreementRelationship feedServiceLevelAgreementRelationship = feedSlaProvider.relateFeeds(savedSla, slaFeeds);
if (feedServiceLevelAgreementRelationship != null && feedServiceLevelAgreementRelationship.getFeeds() != null) {
feedIds = feedServiceLevelAgreementRelationship.getFeeds().stream().map(f -> f.getId()).collect(Collectors.toSet());
}
Set<VelocityTemplate.ID> velocityTemplates = findVelocityTemplates(serviceLevelAgreement);
// Update the JPA mapping in Ops Manager for this SLA and its related Feeds
serviceLevelAgreementDescriptionProvider.updateServiceLevelAgreement(savedSla.getId(), savedSla.getName(), savedSla.getDescription(), feedIds, velocityTemplates);
com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement restModel = serviceLevelAgreementTransform.toModel(savedSla, slaFeeds, true);
// schedule it
serviceLevelAgreementScheduler.scheduleServiceLevelAgreement(savedSla);
return restModel;
});
}
}
return null;
}
use of com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreementRelationship 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);
}
use of com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreementRelationship 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);
}
use of com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreementRelationship 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;
}
Aggregations