use of com.thinkbiganalytics.metadata.rest.model.sla.Obligation 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.rest.model.sla.Obligation in project kylo by Teradata.
the class ServiceLevelAgreementMetricTransformerHelper method toServiceLevelAgreementGroup.
/**
* Transform the Rest Model back to the form model
*/
public ServiceLevelAgreementGroup toServiceLevelAgreementGroup(ServiceLevelAgreement sla) {
ServiceLevelAgreementGroup slaGroup = new ServiceLevelAgreementGroup();
slaGroup.setId(sla.getId());
slaGroup.setName(sla.getName());
slaGroup.setDescription(sla.getDescription());
slaGroup.setActionErrors(sla.getSlaCheckErrors());
slaGroup.setRuleErrors(sla.getObligationErrors());
for (ObligationGroup group : sla.getGroups()) {
List<Obligation> obligations = group.getObligations();
for (Obligation obligation : obligations) {
List<Metric> metrics = obligation.getMetrics();
for (Metric metric : metrics) {
ServiceLevelAgreementRule rule = ServiceLevelAgreementMetricTransformer.instance().toUIModel(metric);
rule.setCondition(com.thinkbiganalytics.metadata.sla.api.ObligationGroup.Condition.valueOf(group.getCondition()));
slaGroup.addServiceLevelAgreementRule(rule);
}
}
}
// transform the Actions if they exist.
if (sla.getSlaChecks() != null) {
List<ServiceLevelAgreementActionUiConfigurationItem> agreementActionUiConfigurationItems = new ArrayList<>();
for (ServiceLevelAgreementCheck check : sla.getSlaChecks()) {
for (ServiceLevelAgreementActionConfiguration actionConfig : check.getActionConfigurations()) {
if (actionConfig != null) {
ServiceLevelAgreementActionUiConfigurationItem uiModel = ServiceLevelAgreementActionConfigTransformer.instance().toUIModel(actionConfig);
agreementActionUiConfigurationItems.add(uiModel);
}
}
}
slaGroup.setActionConfigurations(agreementActionUiConfigurationItems);
}
slaGroup.setCanEdit(sla.isCanEdit());
return slaGroup;
}
use of com.thinkbiganalytics.metadata.rest.model.sla.Obligation in project kylo by Teradata.
the class FeedPrecondition method addMetrics.
public void addMetrics(String description, List<Metric> metrics) {
Obligation ob = new Obligation(description, metrics);
this.sla.addObligation(ob);
}
use of com.thinkbiganalytics.metadata.rest.model.sla.Obligation in project kylo by Teradata.
the class FeedExecutedSinceFeedsOrTime method buildPreconditionObligations.
@Override
public Set<com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup> buildPreconditionObligations() {
Set<com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup> preconditionGroups = new HashSet<>();
preconditionGroups.addAll(super.buildPreconditionObligations());
try {
Period p = new Period(0, 0, 1, 0);
String withinPeriod = p.toString();
WithinSchedule metric = new WithinSchedule(cronExpression, withinPeriod);
Obligation obligation = new Obligation();
obligation.setMetrics(Lists.newArrayList(metric));
com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup group = new com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup();
group.addObligation(obligation);
group.setCondition(ObligationGroup.Condition.SUFFICIENT.name());
preconditionGroups.add(group);
} catch (ParseException e) {
}
return preconditionGroups;
}
use of com.thinkbiganalytics.metadata.rest.model.sla.Obligation in project kylo by Teradata.
the class DefaultFeedManagerFeedService method assignFeedDependencies.
/**
* Looks for the Feed Preconditions and assigns the Feed Dependencies
*/
private void assignFeedDependencies(FeedMetadata feed, Feed domainFeed) {
final Feed.ID domainFeedId = domainFeed.getId();
List<PreconditionRule> preconditions = feed.getSchedule().getPreconditions();
if (preconditions != null) {
PreconditionPolicyTransformer transformer = new PreconditionPolicyTransformer(preconditions);
transformer.applyFeedNameToCurrentFeedProperties(feed.getCategory().getSystemName(), feed.getSystemFeedName());
List<com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup> transformedPreconditions = transformer.getPreconditionObligationGroups();
ServiceLevelAgreementBuilder preconditionBuilder = feedProvider.buildPrecondition(domainFeed.getId()).name("Precondition for feed " + feed.getCategoryAndFeedName() + " (" + domainFeed.getId() + ")");
for (com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup precondition : transformedPreconditions) {
for (Obligation group : precondition.getObligations()) {
preconditionBuilder.obligationGroupBuilder(ObligationGroup.Condition.valueOf(precondition.getCondition())).obligationBuilder().metric(group.getMetrics()).build();
}
}
preconditionBuilder.build();
// add in the lineage dependency relationships
// will the feed exist in the jcr store here if it is new??
// store the existing list of dependent feeds to track and delete those that dont match
Set<Feed.ID> oldDependentFeedIds = new HashSet<Feed.ID>();
Set<Feed.ID> newDependentFeedIds = new HashSet<Feed.ID>();
List<Feed> dependentFeeds = domainFeed.getDependentFeeds();
if (dependentFeeds != null && !dependentFeeds.isEmpty()) {
dependentFeeds.stream().forEach(dependentFeed -> {
oldDependentFeedIds.add(dependentFeed.getId());
});
}
// find those preconditions that are marked as dependent feed types
List<Precondition> preconditionPolicies = transformer.getPreconditionPolicies();
preconditionPolicies.stream().filter(precondition -> precondition instanceof DependentFeedPrecondition).forEach(dependentFeedPrecondition -> {
DependentFeedPrecondition feedPrecondition = (DependentFeedPrecondition) dependentFeedPrecondition;
List<String> dependentFeedNames = feedPrecondition.getDependentFeedNames();
if (dependentFeedNames != null && !dependentFeedNames.isEmpty()) {
// find the feed
for (String dependentFeedName : dependentFeedNames) {
Feed dependentFeed = feedProvider.findBySystemName(dependentFeedName);
if (dependentFeed != null) {
Feed.ID newDependentFeedId = dependentFeed.getId();
newDependentFeedIds.add(newDependentFeedId);
// add and persist it if it doesnt already exist
if (!oldDependentFeedIds.contains(newDependentFeedId)) {
feedProvider.addDependent(domainFeedId, dependentFeed.getId());
}
}
}
}
});
// delete any of those dependent feed ids from the oldDependentFeeds that are not part of the newDependentFeedIds
oldDependentFeedIds.stream().filter(oldFeedId -> !newDependentFeedIds.contains(oldFeedId)).forEach(dependentFeedToDelete -> feedProvider.removeDependent(domainFeedId, dependentFeedToDelete));
}
}
Aggregations