Skip to content

Commit bfab440

Browse files
committed
Add SSM AppStreams API methods
1 parent 0a6f6a2 commit bfab440

File tree

4 files changed

+155
-0
lines changed

4 files changed

+155
-0
lines changed

java/code/src/com/redhat/rhn/frontend/xmlrpc/system/appstreams/SystemAppStreamHandler.java

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import com.suse.manager.api.ReadOnly;
3030
import com.suse.manager.webui.controllers.appstreams.response.ChannelAppStreamsResponse;
31+
import com.suse.manager.webui.controllers.appstreams.response.SsmAppStreamModuleResponse;
3132

3233
import org.apache.logging.log4j.LogManager;
3334
import org.apache.logging.log4j.Logger;
@@ -195,4 +196,96 @@ public List<ChannelAppStreamsResponse> listModuleStreams(User loggedInUser, Inte
195196
throw new NoSuchSystemException();
196197
}
197198
}
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+
}
198291
}

schema/spacewalk/common/data/endpoint.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3621,6 +3621,14 @@ INSERT INTO access.endpoint (class_method, endpoint, http_method, scope, auth_re
36213621
INSERT INTO access.endpoint (class_method, endpoint, http_method, scope, auth_required)
36223622
VALUES ('', '/rhn/manager/api/ssm/appstreams/save', 'POST', 'W', True)
36233623
ON CONFLICT (endpoint, http_method) DO NOTHING;
3624+
INSERT INTO access.endpoint (class_method, endpoint, http_method, scope, auth_required)
3625+
VALUES ('com.redhat.rhn.frontend.xmlrpc.system.appstreams.SystemAppStreamHandler.ssmEnable',
3626+
'/rhn/manager/api/system/appstreams/ssmEnable', 'POST', 'A', True)
3627+
ON CONFLICT (endpoint, http_method) DO NOTHING;
3628+
INSERT INTO access.endpoint (class_method, endpoint, http_method, scope, auth_required)
3629+
VALUES ('com.redhat.rhn.frontend.xmlrpc.system.appstreams.SystemAppStreamHandler.ssmDisable',
3630+
'/rhn/manager/api/system/appstreams/ssmDisable', 'POST', 'A', True)
3631+
ON CONFLICT (endpoint, http_method) DO NOTHING;
36243632

36253633
INSERT INTO access.endpoint (class_method, endpoint, http_method, scope, auth_required)
36263634
VALUES ('com.redhat.rhn.frontend.xmlrpc.access.AccessHandler.createRole', '/manager/api/access/createRole', 'POST', 'A', True)

schema/spacewalk/common/data/endpointNamespace.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5240,6 +5240,18 @@ INSERT INTO access.endpointNamespace (namespace_id, endpoint_id)
52405240
WHERE ns.namespace = 'systems.appstreams' AND ns.access_mode = 'W'
52415241
AND ep.endpoint = '/rhn/manager/api/ssm/appstreams/save' AND ep.http_method = 'POST'
52425242
ON CONFLICT (endpoint_id, namespace_id) DO NOTHING;
5243+
INSERT INTO access.endpointNamespace (namespace_id, endpoint_id)
5244+
SELECT ns.id, ep.id
5245+
FROM access.namespace ns, access.endpoint ep
5246+
WHERE ns.namespace = 'system.appstreams' AND ns.access_mode = 'W'
5247+
AND ep.endpoint = '/rhn/manager/system/api/appstreams/ssmEnable' AND ep.http_method = 'POST'
5248+
ON CONFLICT (endpoint_id, namespace_id) DO NOTHING;
5249+
INSERT INTO access.endpointNamespace (namespace_id, endpoint_id)
5250+
SELECT ns.id, ep.id
5251+
FROM access.namespace ns, access.endpoint ep
5252+
WHERE ns.namespace = 'system.appstreams' AND ns.access_mode = 'W'
5253+
AND ep.endpoint = '/rhn/manager/api/system/appstreams/ssmDisable' AND ep.http_method = 'POST'
5254+
ON CONFLICT (endpoint_id, namespace_id) DO NOTHING;
52435255

52445256
INSERT INTO access.endpointNamespace (namespace_id, endpoint_id)
52455257
SELECT ns.id, ep.id FROM access.namespace ns, access.endpoint ep

schema/spacewalk/upgrade/susemanager-schema-5.2.1-to-susemanager-schema-5.2.2/100-ssm-appstreams-rbac.sql

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@ WHERE NOT EXISTS (
2626
WHERE endpoint = '/rhn/manager/api/ssm/appstreams/save' AND http_method = 'POST'
2727
);
2828

29+
INSERT INTO access.endpoint (class_method, endpoint, http_method, scope, auth_required)
30+
SELECT
31+
'com.redhat.rhn.frontend.xmlrpc.system.appstreams.SystemAppStreamHandler.ssmEnable',
32+
'/rhn/manager/api/system/appstreams/ssmEnable',
33+
'POST', 'A', True
34+
WHERE NOT EXISTS (
35+
SELECT 1 FROM access.endpoint
36+
WHERE endpoint = '/rhn/manager/api/system/appstreams/ssmEnable' AND http_method = 'POST'
37+
);
38+
39+
INSERT INTO access.endpoint (class_method, endpoint, http_method, scope, auth_required)
40+
SELECT
41+
'com.redhat.rhn.frontend.xmlrpc.system.appstreams.SystemAppStreamHandler.ssmDisable',
42+
'/rhn/manager/api/system/appstreams/ssmDisable',
43+
'POST', 'A', True
44+
WHERE NOT EXISTS (
45+
SELECT 1 FROM access.endpoint
46+
WHERE endpoint = '/rhn/manager/api/appstreams/ssmDisable' AND http_method = 'POST'
47+
);
48+
2949
INSERT INTO access.endpointNamespace (namespace_id, endpoint_id)
3050
SELECT ns.id, ep.id
3151
FROM access.namespace ns, access.endpoint ep
@@ -58,3 +78,25 @@ AND NOT EXISTS (
5878
SELECT 1 FROM access.endpointNamespace en
5979
WHERE en.namespace_id = ns.id AND en.endpoint_id = ep.id
6080
);
81+
82+
INSERT INTO access.endpointNamespace (namespace_id, endpoint_id)
83+
SELECT ns.id, ep.id
84+
FROM access.namespace ns, access.endpoint ep
85+
WHERE
86+
ns.namespace = 'system.appstreams' AND ns.access_mode = 'W'
87+
AND ep.endpoint = '/rhn/manager/system/api/appstreams/ssmEnable' AND ep.http_method = 'POST'
88+
AND NOT EXISTS (
89+
SELECT 1 FROM access.endpointNamespace en
90+
WHERE en.namespace_id = ns.id AND en.endpoint_id = ep.id
91+
);
92+
93+
INSERT INTO access.endpointNamespace (namespace_id, endpoint_id)
94+
SELECT ns.id, ep.id
95+
FROM access.namespace ns, access.endpoint ep
96+
WHERE
97+
ns.namespace = 'system.appstreams' AND ns.access_mode = 'W'
98+
AND ep.endpoint = '/rhn/manager/api/system/appstreams/ssmDisable' AND ep.http_method = 'POST'
99+
AND NOT EXISTS (
100+
SELECT 1 FROM access.endpointNamespace en
101+
WHERE en.namespace_id = ns.id AND en.endpoint_id = ep.id
102+
);

0 commit comments

Comments
 (0)