Search in sources :

Example 36 with ServiceLevelAgreement

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

the class ServiceLevelAgreementModelTransform method toModel.

/**
 * Transforms the specified domain objects to REST objects.
 *
 * @param domain the SLA domain object
 * @param feeds  the feed domain objects
 * @param deep   {@code true} to include action configurations
 * @return the SLA REST object
 */
public FeedServiceLevelAgreement toModel(ServiceLevelAgreement domain, Set<com.thinkbiganalytics.metadata.api.feed.Feed> feeds, boolean deep) {
    com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreement slaModel = toModel(domain, deep);
    FeedServiceLevelAgreement feedServiceLevelAgreement = new FeedServiceLevelAgreement(slaModel);
    boolean canEdit = false;
    boolean canView = true;
    if (feeds != null && !feeds.isEmpty()) {
        final Set<Feed> feedModels = feeds.stream().filter(feed -> feed != null).map(model::domainToFeed).collect(Collectors.toSet());
        feedServiceLevelAgreement.setFeeds(feedModels);
        if (accessController.isEntityAccessControlled()) {
            // set the flag on the sla edit to true only if the user has access to edit the feeds assigned to this sla
            canEdit = feeds.stream().allMatch(feed -> feed.getAllowedActions().hasPermission(FeedAccessControl.EDIT_DETAILS));
            // can view
            canView = feeds.stream().allMatch(feed -> feed.getAllowedActions().hasPermission(FeedAccessControl.ACCESS_FEED));
        } else {
            canEdit = this.accessController.hasPermission(AccessController.SERVICES, FeedServicesAccessControl.EDIT_SERVICE_LEVEL_AGREEMENTS);
        }
    } else {
        canEdit = this.accessController.hasPermission(AccessController.SERVICES, FeedServicesAccessControl.EDIT_SERVICE_LEVEL_AGREEMENTS);
    }
    slaModel.setCanEdit(canEdit);
    if (feedServiceLevelAgreement.getFeeds() == null) {
        feedServiceLevelAgreement.setFeeds(new HashSet<>());
    }
    feedServiceLevelAgreement.setCanEdit(canEdit);
    return feedServiceLevelAgreement;
}
Also used : Collections2(com.google.common.collect.Collections2) Obligation(com.thinkbiganalytics.metadata.sla.api.Obligation) ServiceLevelAgreementBuilder(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementBuilder) StringUtils(org.apache.commons.lang3.StringUtils) Model(com.thinkbiganalytics.feedmgr.rest.Model) 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) FeedAccessControl(com.thinkbiganalytics.metadata.api.feed.security.FeedAccessControl) AccessController(com.thinkbiganalytics.security.AccessController) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) MetricAssessment(com.thinkbiganalytics.metadata.sla.api.MetricAssessment) ObligationGroup(com.thinkbiganalytics.metadata.sla.api.ObligationGroup) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) Nonnull(javax.annotation.Nonnull) Function(com.google.common.base.Function) Collection(java.util.Collection) Set(java.util.Set) ServiceLevelAgreementProvider(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementProvider) ServiceLevelAgreementCheck(com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreementCheck) Collectors(java.util.stream.Collectors) Feed(com.thinkbiganalytics.metadata.rest.model.feed.Feed) ObligationAssessment(com.thinkbiganalytics.metadata.sla.api.ObligationAssessment) FeedServiceLevelAgreement(com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement) List(java.util.List) ServiceLevelAssessment(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment) ObligationBuilder(com.thinkbiganalytics.metadata.sla.spi.ObligationBuilder) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) FeedServiceLevelAgreement(com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement) Feed(com.thinkbiganalytics.metadata.rest.model.feed.Feed)

Example 37 with ServiceLevelAgreement

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

the class DefaultServiceLevelAgreementScheduler method enableServiceLevelAgreement.

/**
 * Used to enable the schedule of the SLA, so that once again executes after a being disabled
 *
 * @param sla The SLA to enable
 */
public void enableServiceLevelAgreement(ServiceLevelAgreement sla) {
    ServiceLevelAgreement.ID slaId = sla.getId();
    JobIdentifier scheduledJobId = null;
    if (scheduledJobNames.containsKey(slaId)) {
        scheduledJobId = jobIdentifierForName(scheduledJobNames.get(slaId));
    } else {
        scheduledJobId = jobIdentifierForName(sla.getName());
    }
    QuartzScheduler scheduler = (QuartzScheduler) jobScheduler;
    if (scheduledJobId != null && scheduler.jobExists(scheduledJobId)) {
        try {
            jobScheduler.resumeTriggersOnJob(scheduledJobId);
        } catch (JobSchedulerException e) {
            log.error("Unable to resume the schedule for the SLA {} ", sla.getName());
        }
    } else {
        log.info("Unable to resume the SLA job {} .  The Job does not exist", sla.getName());
    }
}
Also used : JobSchedulerException(com.thinkbiganalytics.scheduler.JobSchedulerException) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) JcrServiceLevelAgreement(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreement) QuartzScheduler(com.thinkbiganalytics.scheduler.QuartzScheduler) JobIdentifier(com.thinkbiganalytics.scheduler.JobIdentifier) DefaultJobIdentifier(com.thinkbiganalytics.scheduler.model.DefaultJobIdentifier)

Example 38 with ServiceLevelAgreement

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

the class DefaultServiceLevelAgreementScheduler method run.

/**
 * Called on startup as part of the PostMetadataConfigAction.
 */
@Override
public void run() {
    log.info("PostMetadataConfigAction called for DefaultServiceLevelAgreementScheduler.  About to schedule the SLA's ");
    metadataAccess.read(() -> {
        List<? extends ServiceLevelAgreement> agreements = slaProvider.getAgreements();
        if (agreements != null) {
            log.info("About to schedule {} SLA's", agreements.size());
            for (ServiceLevelAgreement agreement : agreements) {
                JobIdentifier jobIdentifier = slaJobName(agreement);
                QuartzScheduler scheduler = (QuartzScheduler) jobScheduler;
                if (!scheduler.jobExists(jobIdentifier)) {
                    scheduleServiceLevelAgreement(agreement);
                } else {
                    scheduledJobNames.put(agreement.getId(), jobIdentifier.getName());
                }
            }
        } else {
            log.info("No SLA's found to schedule.");
        }
        return null;
    }, MetadataAccess.SERVICE);
}
Also used : ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) JcrServiceLevelAgreement(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreement) QuartzScheduler(com.thinkbiganalytics.scheduler.QuartzScheduler) JobIdentifier(com.thinkbiganalytics.scheduler.JobIdentifier) DefaultJobIdentifier(com.thinkbiganalytics.scheduler.model.DefaultJobIdentifier)

Example 39 with ServiceLevelAgreement

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

the class DefaultServiceLevelAgreementScheduler method disableServiceLevelAgreement.

/**
 * Used to disable the schedule of the SLA, so that it no longer executes until subsequently re-enabled
 *
 * @param sla The SLA to disable
 */
public void disableServiceLevelAgreement(ServiceLevelAgreement sla) {
    ServiceLevelAgreement.ID slaId = sla.getId();
    JobIdentifier scheduledJobId = null;
    if (scheduledJobNames.containsKey(slaId)) {
        scheduledJobId = jobIdentifierForName(scheduledJobNames.get(slaId));
    } else {
        scheduledJobId = jobIdentifierForName(sla.getName());
    }
    QuartzScheduler scheduler = (QuartzScheduler) jobScheduler;
    if (scheduledJobId != null && scheduler.jobExists(scheduledJobId)) {
        try {
            jobScheduler.pauseTriggersOnJob(scheduledJobId);
        } catch (JobSchedulerException e) {
            log.error("Unable to pause the schedule for the disabled SLA {} ", sla.getName());
        }
    } else {
        log.info("Unable to pause the SLA job {} .  The Job does not exist", sla.getName());
    }
}
Also used : JobSchedulerException(com.thinkbiganalytics.scheduler.JobSchedulerException) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) JcrServiceLevelAgreement(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreement) QuartzScheduler(com.thinkbiganalytics.scheduler.QuartzScheduler) JobIdentifier(com.thinkbiganalytics.scheduler.JobIdentifier) DefaultJobIdentifier(com.thinkbiganalytics.scheduler.model.DefaultJobIdentifier)

Example 40 with ServiceLevelAgreement

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

the class DefaultServiceLevelAgreementScheduler method scheduleServiceLevelAgreement.

/**
 * Schedules an SLA to be run
 *
 * @param sla The SLA to schedule
 */
public void scheduleServiceLevelAgreement(ServiceLevelAgreement sla) {
    if (scheduledJobNames.containsKey(sla.getId())) {
        unscheduleServiceLevelAgreement(sla);
    }
    JobIdentifier jobIdentifier = slaJobName(sla);
    ServiceLevelAgreement.ID slaId = sla.getId();
    // schedule the job
    scheduleSlaJob(jobIdentifier, slaId);
    log.info("Schedule sla job " + jobIdentifier.getName());
    scheduledJobNames.put(sla.getId(), jobIdentifier.getName());
    // notify the other schedulers in the cluster of the scheduled job name
    if (clusterService.isClustered()) {
        clusterService.sendMessageToOthers(QTZ_JOB_SCHEDULED_MESSAGE_TYPE, new ScheduledServiceLevelAgreementClusterMessage(slaId, jobIdentifier));
    }
    if (!sla.isEnabled()) {
        disableServiceLevelAgreement(sla);
    }
}
Also used : ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) JcrServiceLevelAgreement(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreement) JobIdentifier(com.thinkbiganalytics.scheduler.JobIdentifier) DefaultJobIdentifier(com.thinkbiganalytics.scheduler.model.DefaultJobIdentifier)

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