use of com.epam.pipeline.entity.notification.NotificationSettings.NotificationType 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.notification.NotificationSettings.NotificationType in project cloud-pipeline by epam.
the class NotificationSettingsManager method loadAll.
public List<NotificationSettings> loadAll() {
List<NotificationSettings> settings = notificationSettingsDao.loadAllNotificationsSettings();
Set<NotificationType> existingTemplateTypes = settings.stream().map(NotificationSettings::getType).collect(Collectors.toSet());
for (NotificationType type : NotificationType.values()) {
if (!existingTemplateTypes.contains(type)) {
NotificationSettings defaultSetting = NotificationSettings.getDefault(type);
settings.add(defaultSetting);
}
}
return settings;
}
use of com.epam.pipeline.entity.notification.NotificationSettings.NotificationType in project cloud-pipeline by epam.
the class NotificationTemplateManager method loadAll.
public List<NotificationTemplate> loadAll() {
List<NotificationTemplate> templates = notificationTemplateDao.loadAllNotificationTemplates();
Set<Long> existingTemplateTypes = templates.stream().map(NotificationTemplate::getId).collect(Collectors.toSet());
for (NotificationType type : NotificationType.values()) {
if (!existingTemplateTypes.contains(type.getId())) {
NotificationTemplate defaultTemplate = NotificationTemplate.getDefault(type);
templates.add(defaultTemplate);
}
}
return templates;
}
Aggregations