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;
}
}
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();
}
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;
}
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;
}
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);
}
Aggregations