use of com.thinkbiganalytics.policy.rest.model.PreconditionRule 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