Search in sources :

Example 1 with ServiceLevelAgreementActionConfiguration

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

the class JcrServiceLevelAgreementCheck method getActionConfigurations.

public List<? extends ServiceLevelAgreementActionConfiguration> getActionConfigurations(boolean allowClassNotFound) {
    try {
        @SuppressWarnings("unchecked") Iterator<Node> itr = (Iterator<Node>) this.node.getNodes(ACTION_CONFIGURATIONS);
        List<Node> list = new ArrayList<>();
        itr.forEachRemaining((e) -> list.add(e));
        return list.stream().map((actionConfigNode) -> {
            return (ServiceLevelAgreementActionConfiguration) JcrUtil.getGenericJson(actionConfigNode, JcrPropertyConstants.JSON, allowClassNotFound);
        }).filter(configuration -> configuration != null).collect(Collectors.toList());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to retrieve the metric nodes", e);
    }
}
Also used : JcrPropertyUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil) Iterator(java.util.Iterator) ServiceLevelAgreementActionConfiguration(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration) ServiceLevelAgreementActionConfig(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfig) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) ServiceLevelAgreementCheck(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementCheck) JcrPropertyConstants(com.thinkbiganalytics.metadata.modeshape.common.JcrPropertyConstants) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryException(javax.jcr.RepositoryException) Node(javax.jcr.Node) JcrUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrUtil) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) NodeIterator(javax.jcr.NodeIterator) AbstractJcrAuditableSystemEntity(com.thinkbiganalytics.metadata.modeshape.common.AbstractJcrAuditableSystemEntity) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) Node(javax.jcr.Node) Iterator(java.util.Iterator) NodeIterator(javax.jcr.NodeIterator) ArrayList(java.util.ArrayList) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) ServiceLevelAgreementActionConfiguration(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration)

Example 2 with ServiceLevelAgreementActionConfiguration

use of com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration 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;
}
Also used : ServiceLevelAgreementDescriptionProvider(com.thinkbiganalytics.metadata.api.sla.ServiceLevelAgreementDescriptionProvider) JpaVelocityTemplate(com.thinkbiganalytics.metadata.jpa.common.JpaVelocityTemplate) ServiceLevelAgreementActionConfiguration(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) FeedServiceLevelAgreementRelationship(com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreementRelationship) FeedProvider(com.thinkbiganalytics.metadata.api.feed.FeedProvider) FeedAccessControl(com.thinkbiganalytics.metadata.api.feed.security.FeedAccessControl) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) PolicyPropertyTypes(com.thinkbiganalytics.policy.PolicyPropertyTypes) Obligation(com.thinkbiganalytics.metadata.rest.model.sla.Obligation) LabelValue(com.thinkbiganalytics.rest.model.LabelValue) ServiceLevelAgreementDescription(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementDescription) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) ServiceLevelAgreementActionTemplate(com.thinkbiganalytics.metadata.api.sla.ServiceLevelAgreementActionTemplate) FeedServiceLevelAgreementProvider(com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreementProvider) AccessControlException(java.security.AccessControlException) JcrMetadataAccess(com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess) FeedManagerFeedService(com.thinkbiganalytics.feedmgr.service.feed.FeedManagerFeedService) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) ServicesApplicationStartupListener(com.thinkbiganalytics.app.ServicesApplicationStartupListener) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) ServiceLevelAgreementBuilder(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementBuilder) ServiceLevelAgreementEmailTemplate(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementEmailTemplate) Function(java.util.function.Function) 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) FeedServiceLevelAgreement(com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreement) ServiceLevelAgreementActionValidation(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionValidation) ObligationGroup(com.thinkbiganalytics.metadata.sla.api.ObligationGroup) FeedNotFoundException(com.thinkbiganalytics.metadata.api.feed.FeedNotFoundException) ServiceLevelAgreement(com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreement) Logger(org.slf4j.Logger) DateTime(org.joda.time.DateTime) ServiceLevelAgreementProvider(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementProvider) ServiceLevelAgreementActionTemplateProvider(com.thinkbiganalytics.metadata.api.sla.ServiceLevelAgreementActionTemplateProvider) FieldRuleProperty(com.thinkbiganalytics.policy.rest.model.FieldRuleProperty) VelocityTemplateProvider(com.thinkbiganalytics.common.velocity.service.VelocityTemplateProvider) VelocityTemplate(com.thinkbiganalytics.common.velocity.model.VelocityTemplate) ServiceLevelAgreementScheduler(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementScheduler) Collections(java.util.Collections) Obligation(com.thinkbiganalytics.metadata.rest.model.sla.Obligation) ServiceLevelAgreementBuilder(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementBuilder) ArrayList(java.util.ArrayList) ObligationGroupBuilder(com.thinkbiganalytics.metadata.sla.spi.ObligationGroupBuilder) ServiceLevelAgreementActionConfiguration(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) HashSet(java.util.HashSet) FeedServiceLevelAgreement(com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreement) ServiceLevelAgreement(com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreement) FeedServiceLevelAgreementRelationship(com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreementRelationship)

Example 3 with ServiceLevelAgreementActionConfiguration

use of com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration 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;
}
Also used : Obligation(com.thinkbiganalytics.metadata.rest.model.sla.Obligation) ServiceLevelAgreementCheck(com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreementCheck) ArrayList(java.util.ArrayList) Metric(com.thinkbiganalytics.metadata.sla.api.Metric) ServiceLevelAgreementActionConfiguration(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration) ObligationGroup(com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup)

Example 4 with ServiceLevelAgreementActionConfiguration

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

the class ServiceLevelAgreementActionAlertResponderFactory method handleViolation.

/**
 * handle the violation.  Return true if the sla has actions configured in additional generating an alert.
 * @param alert the alert
 * @return true if additional actions were triggered, false if not
 */
private boolean handleViolation(Alert alert) {
    return metadataAccess.read(() -> {
        ServiceLevelAssessment.ID assessmentId = alert.getContent();
        ServiceLevelAssessment assessment = assessmentProvider.findServiceLevelAssessment(assessmentId);
        ServiceLevelAgreement agreement = assessment.getAgreement();
        assessmentProvider.ensureServiceLevelAgreementOnAssessment(assessment);
        agreement = assessment.getAgreement();
        boolean hasActions = false;
        if (agreement != null && agreement.getSlaChecks() != null && !agreement.getSlaChecks().isEmpty()) {
            for (ServiceLevelAgreementCheck check : agreement.getSlaChecks()) {
                for (ServiceLevelAgreementActionConfiguration configuration : ((JcrServiceLevelAgreementCheck) check).getActionConfigurations(true)) {
                    List<Class<? extends ServiceLevelAgreementAction>> responders = configuration.getActionClasses();
                    if (responders != null) {
                        // first check to see if there is a Spring Bean configured for this class type... if so call that
                        for (Class<? extends ServiceLevelAgreementAction> responderClass : responders) {
                            ServiceLevelAgreementAction action = ServiceLevelAgreementActionUtil.instantiate(responderClass);
                            if (action != null) {
                                hasActions = true;
                                log.info("Found {} action", action.getClass().getName());
                                // reassign the content of the alert to the ServiceLevelAssessment
                                // validate the action is ok
                                ServiceLevelAgreementActionValidation validation = ServiceLevelAgreementActionUtil.validateConfiguration(action);
                                if (validation.isValid()) {
                                    action.respond(configuration, assessment, alert);
                                } else {
                                    log.error("Unable to invoke SLA ImmutableAction {} while assessing {} due to Configuration error: {}.  Please fix.", action.getClass(), agreement.getName(), validation.getValidationMessage());
                                }
                            }
                        }
                    }
                }
            }
        }
        return hasActions;
    }, MetadataAccess.SERVICE);
}
Also used : ServiceLevelAssessment(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment) ServiceLevelAgreementAction(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementAction) JcrServiceLevelAgreementCheck(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreementCheck) ServiceLevelAgreementCheck(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementCheck) JcrServiceLevelAgreementCheck(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreementCheck) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) ServiceLevelAgreementActionValidation(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionValidation) ServiceLevelAgreementActionConfiguration(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration)

Example 5 with ServiceLevelAgreementActionConfiguration

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

the class ServiceLevelAgreementMetricTransformerHelper method getActionConfigurations.

public List<ServiceLevelAgreementActionConfiguration> getActionConfigurations(ServiceLevelAgreementGroup serviceLevelAgreement) {
    List<ServiceLevelAgreementActionConfiguration> actionConfigurations = new ArrayList<>();
    if (serviceLevelAgreement.getActionConfigurations() != null) {
        for (ServiceLevelAgreementActionUiConfigurationItem agreementActionUiConfigurationItem : serviceLevelAgreement.getActionConfigurations()) {
            try {
                ServiceLevelAgreementActionConfiguration actionConfiguration = ServiceLevelAgreementActionConfigTransformer.instance().fromUiModel(agreementActionUiConfigurationItem);
                actionConfigurations.add(actionConfiguration);
            } catch (PolicyTransformException e) {
                throw new RuntimeException(e);
            }
        }
    }
    return actionConfigurations;
}
Also used : ArrayList(java.util.ArrayList) PolicyTransformException(com.thinkbiganalytics.policy.PolicyTransformException) ServiceLevelAgreementActionConfiguration(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration)

Aggregations

ServiceLevelAgreementActionConfiguration (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration)6 ArrayList (java.util.ArrayList)4 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)2 Obligation (com.thinkbiganalytics.metadata.rest.model.sla.Obligation)2 ServiceLevelAgreement (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement)2 ServiceLevelAgreementActionValidation (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionValidation)2 ServiceLevelAgreementCheck (com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementCheck)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Lists (com.google.common.collect.Lists)1 ServicesApplicationStartupListener (com.thinkbiganalytics.app.ServicesApplicationStartupListener)1 VelocityTemplate (com.thinkbiganalytics.common.velocity.model.VelocityTemplate)1 VelocityTemplateProvider (com.thinkbiganalytics.common.velocity.service.VelocityTemplateProvider)1 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)1 FeedServicesAccessControl (com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl)1 FeedManagerFeedService (com.thinkbiganalytics.feedmgr.service.feed.FeedManagerFeedService)1 MetadataAccess (com.thinkbiganalytics.metadata.api.MetadataAccess)1 Feed (com.thinkbiganalytics.metadata.api.feed.Feed)1 FeedNotFoundException (com.thinkbiganalytics.metadata.api.feed.FeedNotFoundException)1 FeedProvider (com.thinkbiganalytics.metadata.api.feed.FeedProvider)1