use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.
the class NotificationManager method getUserByName.
private PipelineUser getUserByName(final String username) {
final PipelineUser user = userManager.loadUserByName(username);
Assert.notNull(user, messageHelper.getMessage(MessageConstants.ERROR_USER_NAME_NOT_FOUND, username));
return user;
}
use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.
the class NotificationManager method notifyLongRunningTask.
/**
* Internal method for creating notification message that selecting appropriate email template from db,
* serialize PipelineRun to key-value object and save it to notification_queue table.
* @param run
* @param settings defines, if a long initialization or long running message template should be used
*/
@Transactional(propagation = Propagation.REQUIRED)
public void notifyLongRunningTask(PipelineRun run, NotificationSettings settings) {
LOGGER.debug(messageHelper.getMessage(MessageConstants.INFO_NOTIFICATION_SUBMITTED, run.getPodId()));
NotificationMessage notificationMessage = new NotificationMessage();
if (settings.isKeepInformedOwner()) {
PipelineUser pipelineOwner = userManager.loadUserByName(run.getOwner());
notificationMessage.setToUserId(pipelineOwner.getId());
}
List<Long> ccUserIds = getKeepInformedUserIds(settings);
if (settings.isKeepInformedAdmins()) {
ExtendedRole extendedRole = roleManager.loadRoleWithUsers(DefaultRoles.ROLE_ADMIN.getId());
ccUserIds.addAll(extendedRole.getUsers().stream().map(PipelineUser::getId).collect(Collectors.toList()));
}
notificationMessage.setCopyUserIds(ccUserIds);
notificationMessage.setTemplate(new NotificationTemplate(settings.getTemplateId()));
if (notificationMessage.getTemplate() == null) {
LOGGER.error(messageHelper.getMessage(MessageConstants.ERROR_NOTIFICATION_NOT_FOUND, settings.getTemplateId()));
}
notificationMessage.setTemplateParameters(PipelineRunMapper.map(run, settings.getThreshold()));
monitoringNotificationDao.createMonitoringNotification(notificationMessage);
}
use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.
the class NotificationManager method notifyIdleRuns.
/**
* Issues a notification of an idle Pipeline Run for multiple runs.
*
* @param pipelineCpuRatePairs a list of pairs of PipelineRun and Double cpu usage rate value
* @param notificationType a type of notification to be issued. Supported types are IDLE_RUN, IDLE_RUN_PAUSED,
* IDLE_RUN_STOPPED
* @throws IllegalArgumentException if notificationType is not from IDLE_RUN group
*/
@Transactional(propagation = Propagation.REQUIRED)
public void notifyIdleRuns(List<Pair<PipelineRun, Double>> pipelineCpuRatePairs, NotificationType notificationType) {
if (CollectionUtils.isEmpty(pipelineCpuRatePairs)) {
return;
}
Assert.isTrue(NotificationSettings.NotificationGroup.IDLE_RUN == notificationType.getGroup(), "Only IDLE_RUN group notification types are allowed");
NotificationSettings idleRunSettings = notificationSettingsManager.load(notificationType);
if (idleRunSettings == null || !idleRunSettings.isEnabled()) {
LOGGER.info("No template configured for idle pipeline run notifications or it was disabled!");
return;
}
List<Long> ccUserIds = getKeepInformedUserIds(idleRunSettings);
if (idleRunSettings.isKeepInformedAdmins()) {
ExtendedRole extendedRole = roleManager.loadRoleWithUsers(DefaultRoles.ROLE_ADMIN.getId());
ccUserIds.addAll(extendedRole.getUsers().stream().map(PipelineUser::getId).collect(Collectors.toList()));
}
double idleCpuLevel = preferenceManager.getPreference(SystemPreferences.SYSTEM_IDLE_CPU_THRESHOLD_PERCENT);
Map<String, PipelineUser> pipelineOwners = userManager.loadUsersByNames(pipelineCpuRatePairs.stream().map(p -> p.getLeft().getOwner()).collect(Collectors.toList())).stream().collect(Collectors.toMap(PipelineUser::getUserName, user -> user));
List<NotificationMessage> messages = pipelineCpuRatePairs.stream().map(pair -> {
NotificationMessage message = new NotificationMessage();
message.setTemplate(new NotificationTemplate(idleRunSettings.getTemplateId()));
message.setTemplateParameters(PipelineRunMapper.map(pair.getLeft(), null));
message.getTemplateParameters().put("idleCpuLevel", idleCpuLevel);
message.getTemplateParameters().put("cpuRate", pair.getRight() * PERCENT);
message.setToUserId(pipelineOwners.getOrDefault(pair.getLeft().getOwner(), new PipelineUser()).getId());
message.setCopyUserIds(ccUserIds);
return message;
}).collect(Collectors.toList());
monitoringNotificationDao.createMonitoringNotifications(messages);
}
use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.
the class PipelineRunManager method loadActiveServices.
/**
* Method that will return all active runs for which current users is owner or is listed in run sids - a list of
* identities (user names or groups) that have access to run
* @param filter - filter containing a page and page size
* @return list of active runs which available for current user
*/
@Transactional(propagation = Propagation.SUPPORTS)
public PagedResult<List<PipelineRun>> loadActiveServices(PagingRunFilterVO filter) {
Assert.isTrue(filter.getPage() > 0, messageHelper.getMessage(MessageConstants.ERROR_PAGE_INDEX));
Assert.isTrue(filter.getPageSize() > 0, messageHelper.getMessage(MessageConstants.ERROR_PAGE_SIZE));
PipelineUser user = authManager.getCurrentUser();
List<PipelineRun> runs = pipelineRunDao.loadActiveServices(filter, user);
int count = pipelineRunDao.countActiveServices(user);
return new PagedResult<>(runs, count);
}
use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.
the class SearchRequestBuilder method getQuery.
private QueryBuilder getQuery(final ElasticSearchRequest searchRequest) {
final BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery().must(getBasicQuery(searchRequest));
final PipelineUser pipelineUser = userManager.loadUserByName(authManager.getAuthorizedUser());
if (pipelineUser == null) {
throw new IllegalArgumentException("Failed to find currently authorized user");
}
// no check for admins
if (ListUtils.emptyIfNull(pipelineUser.getRoles()).stream().anyMatch(role -> role.getId().equals(DefaultRoles.ROLE_ADMIN.getId()))) {
return queryBuilder;
}
addAclFilters(queryBuilder, pipelineUser);
return queryBuilder;
}
Aggregations