|
28 | 28 |
|
29 | 29 | import com.suse.manager.api.ReadOnly; |
30 | 30 | import com.suse.manager.webui.controllers.appstreams.response.ChannelAppStreamsResponse; |
| 31 | +import com.suse.manager.webui.controllers.appstreams.response.SsmAppStreamModuleResponse; |
31 | 32 |
|
32 | 33 | import org.apache.logging.log4j.LogManager; |
33 | 34 | import org.apache.logging.log4j.Logger; |
@@ -195,4 +196,96 @@ public List<ChannelAppStreamsResponse> listModuleStreams(User loggedInUser, Inte |
195 | 196 | throw new NoSuchSystemException(); |
196 | 197 | } |
197 | 198 | } |
| 199 | + |
| 200 | + /** |
| 201 | + * Schedule module stream enable for the SSM (System Set Manager) systems subscribed to a given modular channel. |
| 202 | + * |
| 203 | + * @param loggedInUser The current user |
| 204 | + * @param channelId ID of the channel containing the streams |
| 205 | + * @param moduleStreams struct containing module and stream |
| 206 | + * @param earliestOccurrence Earliest occurrence of the module enable |
| 207 | + * @return appstreams changes action id |
| 208 | + * @apidoc.doc Schedule enabling of module streams from a given modular channel for the SSM (System Set Manager) |
| 209 | + * systems. Invalid modules will be filtered out. If all provided modules are invalid the request will fail. |
| 210 | + * @apidoc.param #session_key() |
| 211 | + * @apidoc.param #param("int", "channelId") |
| 212 | + * @apidoc.param #array_begin("moduleStreams") |
| 213 | + * #struct_begin("Module Stream") |
| 214 | + * #prop("string", "module") |
| 215 | + * #prop("string", "stream") |
| 216 | + * #struct_end() |
| 217 | + * #array_end() |
| 218 | + * @apidoc.param #param("$date", "earliestOccurrence") |
| 219 | + * @apidoc.returntype #param_desc("int", "actionId", "The action id of the scheduled action") |
| 220 | + */ |
| 221 | + public int ssmEnable(User loggedInUser, Integer channelId, List<Map<String, String>> moduleStreams, |
| 222 | + Date earliestOccurrence) { |
| 223 | + var validStreams = new HashSet<String>(); |
| 224 | + var availableAppStreams = AppStreamsManager.listSsmChannelAppStreams(channelId.longValue(), loggedInUser) |
| 225 | + .stream() |
| 226 | + .map(s -> s.getName() + ":" + s.getStream()) |
| 227 | + .collect(Collectors.toSet()); |
| 228 | + moduleStreams.forEach(moduleStream -> { |
| 229 | + String appStream = moduleStream.get("module") + ":" + moduleStream.get("stream"); |
| 230 | + if (availableAppStreams.contains(appStream)) { |
| 231 | + validStreams.add(appStream); |
| 232 | + } |
| 233 | + else { |
| 234 | + log.warn("Invalid appstream: {} {}. Skipping ...", appStream, channelId); |
| 235 | + } |
| 236 | + }); |
| 237 | + return ssmSchedule(loggedInUser, channelId, validStreams, new HashSet<>(), earliestOccurrence); |
| 238 | + } |
| 239 | + |
| 240 | + /** |
| 241 | + * Schedule module stream disable for the SSM (System Set Manager) systems subscribed to a given modular channel. |
| 242 | + * |
| 243 | + * @param loggedInUser The current user |
| 244 | + * @param channelId ID of the channel containing the streams |
| 245 | + * @param moduleNames list of module names do be disabled |
| 246 | + * @param earliestOccurrence Earliest occurrence of the module disable |
| 247 | + * @return appstreams changes action id |
| 248 | + * @apidoc.doc Schedule disabling of module streams from a given modular channel for the SSM (System Set Manager) |
| 249 | + * systems. Invalid modules will be filtered out. If all provided modules are invalid the request will fail. |
| 250 | + * @apidoc.param #session_key() |
| 251 | + * @apidoc.param #param("int", "channelId") |
| 252 | + * @apidoc.param #array_begin("moduleNames") |
| 253 | + * #param("string", "moduleName") |
| 254 | + * #array_end() |
| 255 | + * @apidoc.param #param("$date", "earliestOccurrence") |
| 256 | + * @apidoc.returntype #param_desc("int", "actionId", "The action id of the scheduled action") |
| 257 | + */ |
| 258 | + public int ssmDisable(User loggedInUser, Integer channelId, List<String> moduleNames, Date earliestOccurrence) { |
| 259 | + var availableModules = AppStreamsManager |
| 260 | + .listSsmChannelAppStreams(channelId.longValue(), loggedInUser) |
| 261 | + .stream() |
| 262 | + .map(SsmAppStreamModuleResponse::getName) |
| 263 | + .collect(Collectors.toSet()); |
| 264 | + var validModules = moduleNames.stream().filter(availableModules::contains).collect(Collectors.toSet()); |
| 265 | + return ssmSchedule(loggedInUser, channelId, new HashSet<>(), validModules, earliestOccurrence); |
| 266 | + } |
| 267 | + |
| 268 | + /** |
| 269 | + * Private helper to schedule SSM AppStream changes. |
| 270 | + */ |
| 271 | + private int ssmSchedule(User loggedInUser, Integer channelId, Set<String> toEnable, Set<String> toDisable, |
| 272 | + Date earliestOccurrence) { |
| 273 | + if (toEnable.isEmpty() && toDisable.isEmpty()) { |
| 274 | + throw new NoSuchAppStreamException("No valid AppStreams provided for SSM from channel " + channelId); |
| 275 | + } |
| 276 | + try { |
| 277 | + Long actionId = AppStreamsManager.scheduleSsmAppStreamsChanges( |
| 278 | + channelId.longValue(), |
| 279 | + toEnable, |
| 280 | + toDisable, |
| 281 | + loggedInUser, |
| 282 | + Optional.empty(), |
| 283 | + earliestOccurrence |
| 284 | + ); |
| 285 | + return actionId.intValue(); |
| 286 | + } |
| 287 | + catch (com.redhat.rhn.taskomatic.TaskomaticApiException e) { |
| 288 | + throw new TaskomaticApiException(e.getMessage()); |
| 289 | + } |
| 290 | + } |
198 | 291 | } |
0 commit comments