Search in sources :

Example 1 with ServiceLevelAgreement

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

the class ServiceLevelAgreementRestController method getAgreement.

@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets the specified SLA.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the SLA.", response = ServiceLevelAgreement.class), @ApiResponse(code = 404, message = "The SLA could not be found.", response = RestResponseStatus.class) })
public ServiceLevelAgreement getAgreement(@PathParam("id") String idValue) {
    log.debug("GET SLA by ID: {}", idValue);
    accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_SERVICE_LEVEL_AGREEMENTS);
    ServiceLevelAgreement serviceLevelAgreement = serviceLevelAgreementService.getServiceLevelAgreement(idValue);
    if (serviceLevelAgreement == null) {
        throw new WebApplicationException("No SLA with the given ID was found", Response.Status.NOT_FOUND);
    } else {
        return serviceLevelAgreement;
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ServiceLevelAgreement(com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreement) FeedServiceLevelAgreement(com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with ServiceLevelAgreement

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

the class ServiceLevelAgreementRestController method saveAndScheduleFeedSla.

/**
 * Save an SLA and attach the ref to the Feed
 */
@POST
@Path("/feed/{feedId}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Saves the SLA and attaches it to the specified feed.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the SLA.", response = ServiceLevelAgreementGroup.class), @ApiResponse(code = 400, message = "The feedId is not a valid UUID.", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "The SLA could not be saved.", response = RestResponseStatus.class) })
public Response saveAndScheduleFeedSla(@UUID @PathParam("feedId") String feedId, ServiceLevelAgreementGroup sla) {
    accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.EDIT_SERVICE_LEVEL_AGREEMENTS);
    ServiceLevelAgreement serviceLevelAgreement = serviceLevelAgreementService.saveAndScheduleFeedSla(sla, feedId);
    ServiceLevelAgreementMetricTransformerHelper helper = new ServiceLevelAgreementMetricTransformerHelper();
    ServiceLevelAgreementGroup serviceLevelAgreementGroup = helper.toServiceLevelAgreementGroup(serviceLevelAgreement);
    return Response.ok(serviceLevelAgreementGroup).build();
}
Also used : ServiceLevelAgreement(com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreement) FeedServiceLevelAgreement(com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement) ServiceLevelAgreementGroup(com.thinkbiganalytics.feedmgr.sla.ServiceLevelAgreementGroup) ServiceLevelAgreementMetricTransformerHelper(com.thinkbiganalytics.feedmgr.sla.ServiceLevelAgreementMetricTransformerHelper) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with ServiceLevelAgreement

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

the class DefaultServiceLevelAgreementService method getServiceLevelAgreement.

@Override
public ServiceLevelAgreement getServiceLevelAgreement(String slaId) {
    com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement systemSla = findFeedServiceLevelAgreementAsAdmin(slaId, false);
    // filter out if this SLA has feeds which the current user cannot access
    ServiceLevelAgreement serviceLevelAgreement = metadataAccess.read(() -> {
        FeedServiceLevelAgreement agreement = feedSlaProvider.findAgreement(slaProvider.resolve(slaId));
        if (agreement != null) {
            com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement entityAccessControlledSla = serviceLevelAgreementTransform.toModel(agreement, false);
            if (systemSla.getFeedsCount() == entityAccessControlledSla.getFeedsCount()) {
                return entityAccessControlledSla;
            }
        }
        return null;
    });
    return serviceLevelAgreement;
}
Also used : FeedServiceLevelAgreement(com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreement) ServiceLevelAgreement(com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreement) FeedServiceLevelAgreement(com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreement)

Example 4 with ServiceLevelAgreement

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

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

the class IntegrationTestBase method getSla.

protected ServiceLevelAgreement[] getSla() {
    LOG.info("Getting SLAs");
    Response response = given(ServiceLevelAgreementRestController.V1_FEEDMGR_SLA).when().get();
    response.then().statusCode(HTTP_OK);
    return response.as(ServiceLevelAgreement[].class);
}
Also used : Response(com.jayway.restassured.response.Response) ServiceLevelAgreement(com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreement)

Aggregations

ServiceLevelAgreement (com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreement)9 FeedServiceLevelAgreement (com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 Produces (javax.ws.rs.Produces)3 ServiceLevelAgreementGroup (com.thinkbiganalytics.feedmgr.sla.ServiceLevelAgreementGroup)2 ServiceLevelAgreementMetricTransformerHelper (com.thinkbiganalytics.feedmgr.sla.ServiceLevelAgreementMetricTransformerHelper)2 FeedServiceLevelAgreement (com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreement)2 Obligation (com.thinkbiganalytics.metadata.rest.model.sla.Obligation)2 Path (javax.ws.rs.Path)2 Lists (com.google.common.collect.Lists)1 Response (com.jayway.restassured.response.Response)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