Skip to content

Commit

Permalink
apply sonarlint suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalmer committed Oct 18, 2024
1 parent 479fa29 commit 6e741dd
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 deletions java/code/src/com/redhat/rhn/manager/action/ActionChainManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static PackageAction schedulePackageRemoval(User user, Server server,
* @return scheduled actions
* @throws TaskomaticApiException if there was a Taskomatic error
* (typically: Taskomatic is down)
* @see ActionManager#addPackageActionDetails(Action, List) for "package map"
* @see ActionManager#addPackageActionDetails(Collection, List) for "package map"
*/
public static List<Action> schedulePackageUpgrades(User user,
Map<Long, List<Map<String, Long>>> packageMaps, Date earliestAction,
Expand All @@ -149,9 +149,10 @@ public static List<Action> schedulePackageUpgrades(User user,
if (actionChain != null) {
List<Action> actions = new ArrayList<>();
int sortOrder = ActionChainFactory.getNextSortOrderValue(actionChain);
for (Long sid : packageMaps.keySet()) {
for (Map.Entry<Long, List<Map<String, Long>>> entry : packageMaps.entrySet()) {
Long sid = entry.getKey();
Server server = SystemManager.lookupByIdAndUser(sid, user);
actions.add(schedulePackageActionByOs(user, server, packageMaps.get(sid),
actions.add(schedulePackageActionByOs(user, server, entry.getValue(),
earliestAction, actionChain, sortOrder,
ActionFactory.TYPE_PACKAGES_UPDATE));
}
Expand Down Expand Up @@ -188,7 +189,7 @@ public static List<Action> schedulePackageUpgrades(User user,
* @return scheduled action
* @throws TaskomaticApiException if there was a Taskomatic error
* (typically: Taskomatic is down)
* @see ActionManager#addPackageActionDetails(Action, List) for "package map"
* @see ActionManager#addPackageActionDetails(Collection, List) for "package map"
*/
public static PackageAction schedulePackageUpgrade(User user, Server server,
List<Map<String, Long>> packages, Date earliest, ActionChain actionChain)
Expand All @@ -207,7 +208,7 @@ public static PackageAction schedulePackageUpgrade(User user, Server server,
* @throws TaskomaticApiException if there was a Taskomatic error
* (typically: Taskomatic is down)
* @see com.redhat.rhn.manager.action.ActionManager#schedulePackageVerify
* @see ActionManager#addPackageActionDetails(Action, List) for "package map"
* @see ActionManager#addPackageActionDetails(Collection, List) for "package map"
*/
public static PackageAction schedulePackageVerify(User user, Server server,
List<Map<String, Long>> packages, Date earliest, ActionChain actionChain)
Expand All @@ -228,8 +229,8 @@ public static PackageAction schedulePackageVerify(User user, Server server,
* @return scheduled action
* @throws TaskomaticApiException if there was a Taskomatic error
* (typically: Taskomatic is down)
* @see com.redhat.rhn.manager.action.ActionManager#schedulePackageAction
* @see ActionManager#addPackageActionDetails(Action, List) for "package map"
* @see ActionManager#schedulePackageAction(User, List, ActionType, Date, Server...)
* @see ActionManager#addPackageActionDetails(Collection, List) for "package map"
*/
private static Action schedulePackageAction(User user, List<Map<String, Long>> packages,
ActionType type, Date earliest, ActionChain actionChain, Integer sortOrder,
Expand All @@ -246,15 +247,15 @@ private static Action schedulePackageAction(User user, List<Map<String, Long>> p
* @param user the user scheduling actions
* @param packages a list of "package maps"
* @param type the type
* @param earliest the earliest execution date
* @param earliestAction the earliest execution date
* @param actionChain the action chain or null
* @param sortOrder the sort order or null
* @param servers the servers involved
* @param serverIds the ids of servers involved
* @return scheduled actions
* @throws TaskomaticApiException if there was a Taskomatic error
* (typically: Taskomatic is down)
* @see com.redhat.rhn.manager.action.ActionManager#schedulePackageAction
* @see ActionManager#addPackageActionDetails(Action, List) for "package map"
* @see ActionManager#schedulePackageAction(User, List, ActionType, Date, Server...)
* @see ActionManager#addPackageActionDetails(Collection, List) for "package map"
*/
private static Set<Action> schedulePackageActions(User user,
List<Map<String, Long>> packages, ActionType type, Date earliestAction,
Expand Down Expand Up @@ -318,16 +319,15 @@ user, ActionFactory.TYPE_APPSTREAM_CONFIGURE, name, earliest, actionChain, null,
* @throws com.redhat.rhn.manager.MissingEntitlementException if any server
* in the list is missing Provisioning schedule fails
* @see com.redhat.rhn.manager.action.ActionManager#scheduleScriptRun
* @see ActionManager#addPackageActionDetails(Action, List) for "package map"
* @see ActionManager#addPackageActionDetails(Collection, List) for "package map"
*/
public static Set<Action> scheduleScriptRuns(User user, List<Long> sids, String name,
ScriptActionDetails script, Date earliest, ActionChain actionChain)
throws TaskomaticApiException {

ActionManager.checkScriptingOnServers(sids);

Set<Long> sidSet = new HashSet<>();
sidSet.addAll(sids);
Set<Long> sidSet = new HashSet<>(sids);

Set<Action> result = createActions(user, ActionFactory.TYPE_SCRIPT_RUN, name,
earliest, actionChain, null, sidSet);
Expand Down Expand Up @@ -357,14 +357,12 @@ public static Set<Action> scheduleApplyStates(User user, List<Long> sids, Option
Date earliest, ActionChain actionChain)
throws TaskomaticApiException {

if (!sids.stream().map(ServerFactory::lookupById)
.filter(server -> !MinionServerUtils.isMinionServer(server))
.toList().isEmpty()) {
if (sids.stream().map(ServerFactory::lookupById)
.anyMatch(server -> !MinionServerUtils.isMinionServer(server))) {
throw new IllegalArgumentException("Server ids include non minion servers.");
}

Set<Long> sidSet = new HashSet<>();
sidSet.addAll(sids);
Set<Long> sidSet = new HashSet<>(sids);

String summary = "Apply highstate" + (test.isPresent() && test.get() ? " in test-mode" : "");
Set<Action> result = createActions(user, ActionFactory.TYPE_APPLY_STATES, summary,
Expand Down Expand Up @@ -604,7 +602,7 @@ public static List<Long> scheduleErrataUpdate(User user, List<Server> servers, L
* @return scheduled actions
* @throws TaskomaticApiException if there was a Taskomatic error
* (typically: Taskomatic is down)
* @see ActionManager#addPackageActionDetails(Action, List) for "package map"
* @see ActionManager#addPackageActionDetails(Collection, List) for "package map"
*/
public static List<Action> schedulePackageInstalls(User user,
Collection<Long> serverIds, List<Map<String, Long>> packages, Date earliest,
Expand All @@ -624,7 +622,7 @@ public static List<Action> schedulePackageInstalls(User user,
* @return scheduled actions
* @throws TaskomaticApiException if there was a Taskomatic error
* (typically: Taskomatic is down)
* @see ActionManager#addPackageActionDetails(Action, List) for "package map"
* @see ActionManager#addPackageActionDetails(Collection, List) for "package map"
*/
public static List<Action> schedulePackageRemovals(User user,
Collection<Long> serverIds, List<Map<String, Long>> packages, Date earliest,
Expand All @@ -643,7 +641,6 @@ public static List<Action> schedulePackageRemovals(User user,
* @param sortOrder the sort order or null
* @param serverIds the affected servers' IDs
* @return created actions
* @see com.redhat.rhn.manager.action.ActionManager#scheduleAction
*/
private static Set<Action> createActions(User user, ActionType type, String name,
Date earliest, ActionChain actionChain, Integer sortOrder, Set<Long> serverIds) {
Expand Down Expand Up @@ -700,10 +697,9 @@ private static void taskoScheduleActions(Set<Action> actions, User user, ActionC
catch (TaskomaticApiException e) {
String cancellationMessage = "Taskomatic error, please check log files";
// do not leave actions queued forever
actions.stream().map(a -> HibernateFactory.reload(a)).forEach(a -> {
a.getServerActions().stream().forEach(sa -> {
ActionManager.failSystemAction(user, sa.getServerId(), a.getId(), cancellationMessage);
});
actions.stream().map(HibernateFactory::reload).forEach(a -> {
a.getServerActions().forEach(sa ->
ActionManager.failSystemAction(user, sa.getServerId(), a.getId(), cancellationMessage));
ActionFactory.save(a);
});

Expand Down Expand Up @@ -749,8 +745,7 @@ private static List<Action> schedulePackageActionsByOs(User user,
throws TaskomaticApiException {

List<Action> result = new LinkedList<>();
Set<Long> rhelServers = new HashSet<>();
rhelServers.addAll(ServerFactory.listLinuxSystems(serverIds));
Set<Long> rhelServers = new HashSet<>(ServerFactory.listLinuxSystems(serverIds));

if (!rhelServers.isEmpty()) {
result.addAll(schedulePackageActions(user, packages, linuxActionType, earliest,
Expand Down

0 comments on commit 6e741dd

Please sign in to comment.