diff --git a/java/code/src/com/redhat/rhn/manager/action/ActionChainManager.java b/java/code/src/com/redhat/rhn/manager/action/ActionChainManager.java index 6f6461a3390..2a45a40b1ff 100644 --- a/java/code/src/com/redhat/rhn/manager/action/ActionChainManager.java +++ b/java/code/src/com/redhat/rhn/manager/action/ActionChainManager.java @@ -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 schedulePackageUpgrades(User user, Map>> packageMaps, Date earliestAction, @@ -149,9 +149,10 @@ public static List schedulePackageUpgrades(User user, if (actionChain != null) { List actions = new ArrayList<>(); int sortOrder = ActionChainFactory.getNextSortOrderValue(actionChain); - for (Long sid : packageMaps.keySet()) { + for (Map.Entry>> 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)); } @@ -188,7 +189,7 @@ public static List 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> packages, Date earliest, ActionChain actionChain) @@ -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> packages, Date earliest, ActionChain actionChain) @@ -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> packages, ActionType type, Date earliest, ActionChain actionChain, Integer sortOrder, @@ -246,15 +247,15 @@ private static Action schedulePackageAction(User user, List> 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 schedulePackageActions(User user, List> packages, ActionType type, Date earliestAction, @@ -318,7 +319,7 @@ 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 scheduleScriptRuns(User user, List sids, String name, ScriptActionDetails script, Date earliest, ActionChain actionChain) @@ -326,8 +327,7 @@ public static Set scheduleScriptRuns(User user, List sids, String ActionManager.checkScriptingOnServers(sids); - Set sidSet = new HashSet<>(); - sidSet.addAll(sids); + Set sidSet = new HashSet<>(sids); Set result = createActions(user, ActionFactory.TYPE_SCRIPT_RUN, name, earliest, actionChain, null, sidSet); @@ -357,14 +357,12 @@ public static Set scheduleApplyStates(User user, List 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 sidSet = new HashSet<>(); - sidSet.addAll(sids); + Set sidSet = new HashSet<>(sids); String summary = "Apply highstate" + (test.isPresent() && test.get() ? " in test-mode" : ""); Set result = createActions(user, ActionFactory.TYPE_APPLY_STATES, summary, @@ -604,7 +602,7 @@ public static List scheduleErrataUpdate(User user, List 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 schedulePackageInstalls(User user, Collection serverIds, List> packages, Date earliest, @@ -624,7 +622,7 @@ public static List 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 schedulePackageRemovals(User user, Collection serverIds, List> packages, Date earliest, @@ -643,7 +641,6 @@ public static List 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 createActions(User user, ActionType type, String name, Date earliest, ActionChain actionChain, Integer sortOrder, Set serverIds) { @@ -700,10 +697,9 @@ private static void taskoScheduleActions(Set 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); }); @@ -749,8 +745,7 @@ private static List schedulePackageActionsByOs(User user, throws TaskomaticApiException { List result = new LinkedList<>(); - Set rhelServers = new HashSet<>(); - rhelServers.addAll(ServerFactory.listLinuxSystems(serverIds)); + Set rhelServers = new HashSet<>(ServerFactory.listLinuxSystems(serverIds)); if (!rhelServers.isEmpty()) { result.addAll(schedulePackageActions(user, packages, linuxActionType, earliest,