Search in sources :

Example 1 with ServiceLevelAgreementCheck

use of com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreementCheck 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 2 with ServiceLevelAgreementCheck

use of com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreementCheck in project kylo by Teradata.

the class ServiceLevelAgreementModelTransform method toModel.

public static com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreement toModel(ServiceLevelAgreement domain, boolean deep) {
    com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreement sla = new com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreement(domain.getId().toString(), domain.getName(), domain.getDescription());
    if (domain.getSlaChecks() != null) {
        List<ServiceLevelAgreementCheck> checks = new ArrayList<>();
        sla.setSlaChecks(checks);
        for (com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementCheck check : domain.getSlaChecks()) {
            ServiceLevelAgreementCheck restModel = new ServiceLevelAgreementCheck();
            restModel.setCronSchedule(check.getCronSchedule());
            if (deep) {
                try {
                    restModel.setActionConfigurations(check.getActionConfigurations());
                } catch (Exception e) {
                    if (ExceptionUtils.getRootCause(e) instanceof ClassNotFoundException) {
                        String msg = ExceptionUtils.getRootCauseMessage(e);
                        // get just the simpleClassName stripping the package info
                        msg = StringUtils.substringAfterLast(msg, ".");
                        sla.addSlaCheckError("Unable to find the SLA Action Configurations of type: " + msg + ". Check with an administrator to ensure the correct plugin is installed with this SLA configuration. ");
                    } else {
                        throw new RuntimeException(e);
                    }
                }
            }
            checks.add(restModel);
        }
    }
    if (deep) {
        if (domain.getObligationGroups().size() == 1 && domain.getObligationGroups().get(0).getCondition() == ObligationGroup.Condition.REQUIRED) {
            for (Obligation domainOb : domain.getObligations()) {
                com.thinkbiganalytics.metadata.rest.model.sla.Obligation ob = toModel(domainOb, true);
                sla.addObligation(ob);
            }
        } else {
            for (ObligationGroup domainGroup : domain.getObligationGroups()) {
                // Force it to be required
                // TODO Rework once the SLA page allows for Sufficient/Required settings
                // TODO use the domainGroup.condition instead
                com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup group = new com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup(ObligationGroup.Condition.REQUIRED.name());
                for (Obligation domainOb : domainGroup.getObligations()) {
                    com.thinkbiganalytics.metadata.rest.model.sla.Obligation ob = toModel(domainOb, true);
                    group.addObligation(ob);
                }
                sla.addGroup(group);
            }
        }
    }
    return sla;
}
Also used : Obligation(com.thinkbiganalytics.metadata.sla.api.Obligation) ServiceLevelAgreementCheck(com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreementCheck) ArrayList(java.util.ArrayList) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) FeedServiceLevelAgreement(com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement) ObligationGroup(com.thinkbiganalytics.metadata.sla.api.ObligationGroup)

Aggregations

ServiceLevelAgreementCheck (com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreementCheck)2 ArrayList (java.util.ArrayList)2 FeedServiceLevelAgreement (com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement)1 Obligation (com.thinkbiganalytics.metadata.rest.model.sla.Obligation)1 ObligationGroup (com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup)1 Metric (com.thinkbiganalytics.metadata.sla.api.Metric)1 Obligation (com.thinkbiganalytics.metadata.sla.api.Obligation)1 ObligationGroup (com.thinkbiganalytics.metadata.sla.api.ObligationGroup)1 ServiceLevelAgreement (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement)1 ServiceLevelAgreementActionConfiguration (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration)1