Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure channel lists are reliably sorted by name (bsc#1233724) #9564

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -464,7 +463,7 @@ protected List<SystemsPerChannelDto> setupList(User user, HttpServletRequest req
// change the systems base channel
Channel c = ChannelFactory.lookupById(spc.getId());

Set<EssentialChannelDto> compatibles = ChannelManager.listCompatibleBaseChannelsForChannel(user, c);
List<EssentialChannelDto> compatibles = ChannelManager.listCompatibleBaseChannelsForChannel(user, c);
log.debug("Sorting channels: {}", compatibles.size());
List<EssentialChannelDto> rhn = new ArrayList<>();
List<EssentialChannelDto> custom = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -121,7 +120,7 @@ public ActionForward unspecified(ActionMapping mapping,
}


Set<EssentialChannelDto> orgChannels = ChannelManager.listBaseChannelsForSystem(user, s);
List<EssentialChannelDto> orgChannels = ChannelManager.listBaseChannelsForSystem(user, s);

List<EssentialChannelDto> rhnChannels = new LinkedList<>();
List<EssentialChannelDto> customChannels = new LinkedList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ public Object[] listSubscribableBaseChannels(User loggedInUser, Integer sid)
Channel baseChannel = server.getBaseChannel();
List<Map<String, Object>> returnList = new ArrayList<>();

Set<EssentialChannelDto> list = ChannelManager.listBaseChannelsForSystem(loggedInUser, server);
List<EssentialChannelDto> list = ChannelManager.listBaseChannelsForSystem(loggedInUser, server);
for (EssentialChannelDto ch : list) {
Boolean currentBase = (baseChannel != null) &&
baseChannel.getId().equals(ch.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package com.redhat.rhn.manager.channel;

import static java.util.Comparator.comparing;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static java.util.Optional.ofNullable;
Expand Down Expand Up @@ -1687,9 +1688,9 @@ private static Channel getDefaultBaseChannel(Org org, String version, ChannelArc
*
* @param usr requesting list
* @param s Server to check against
* @return Set of Channel objects that match
* @return List of Channel objects that match
*/
public static Set<EssentialChannelDto> listBaseChannelsForSystem(User usr, Server s) {
public static List<EssentialChannelDto> listBaseChannelsForSystem(User usr, Server s) {

Set<EssentialChannelDto> channelDtos = new HashSet<>();
PackageEvr releaseEvr = PackageManager.lookupReleasePackageEvrFor(s);
Expand Down Expand Up @@ -1726,7 +1727,7 @@ public static Set<EssentialChannelDto> listBaseChannelsForSystem(User usr, Serve
channelDtos.add(new EssentialChannelDto(dcm.getChannel()));
}

return channelDtos;
return channelDtos.stream().sorted(comparing(EssentialChannelDto::getName)).toList();
}

/**
Expand Down Expand Up @@ -1800,9 +1801,10 @@ public static Set<EssentialChannelDto> listCompatibleBaseChannelsForChannel(Chan
*
* @param u User of interest
* @param inChan Base-channel of interest
* @return Set of channels that a system subscribed to "c" could be re-subscribed to
* @return List of channels that a system subscribed to "c" could be re-subscribed to
*/
public static Set<EssentialChannelDto> listCompatibleBaseChannelsForChannel(User u, Channel inChan) {
public static List<EssentialChannelDto> listCompatibleBaseChannelsForChannel(User u, Channel inChan) {

// Get all the custom-channels owned by this org and add them
Set<EssentialChannelDto> retval = ChannelFactory.listCustomBaseChannelsForSSM(u, inChan)
.stream()
Expand Down Expand Up @@ -1843,7 +1845,7 @@ public static Set<EssentialChannelDto> listCompatibleBaseChannelsForChannel(User
}
}

return retval;
return retval.stream().sorted(comparing(EssentialChannelDto::getName)).toList();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,31 @@ public void testBaseChannelsForSystem() throws Exception {

ChannelTestUtils.createTestChannel(user);
ChannelTestUtils.createTestChannel(user);
Set<EssentialChannelDto> channels = ChannelManager.listBaseChannelsForSystem(user, s);
List<EssentialChannelDto> channels = ChannelManager.listBaseChannelsForSystem(user, s);

assertTrue(channels.size() >= 2);
}

@Test
public void testBaseChannelsForSystemSorted() throws Exception {
Server s = ServerTestUtils.createTestSystem(user);

Channel c = ChannelTestUtils.createTestChannel(user);
c.setName("A Channel");
TestUtils.saveAndReload(c);
c = ChannelTestUtils.createTestChannel(user);
c.setName("C Channel");
TestUtils.saveAndReload(c);
c = ChannelTestUtils.createTestChannel(user);
c.setName("B Channel");
TestUtils.saveAndReload(c);

List<String> channelNames = ChannelManager.listBaseChannelsForSystem(user, s).stream()
.map(EssentialChannelDto::getName).toList();

assertTrue(channelNames.indexOf("A Channel") < channelNames.indexOf("B Channel"));
assertTrue(channelNames.indexOf("B Channel") < channelNames.indexOf("C Channel"));
}

@Test
public void testBaseChannelsForLiberty() throws Exception {
Expand All @@ -464,7 +484,7 @@ public void testBaseChannelsForLiberty() throws Exception {
// Test: list base channels for Liberty 7
SUSEProductTestUtils.installSUSEProductOnServer(resProduct, s);

Set<EssentialChannelDto> channels = ChannelManager.listBaseChannelsForSystem(user, s);
List<EssentialChannelDto> channels = ChannelManager.listBaseChannelsForSystem(user, s);

assertEquals(2, channels.size());
List<String> expectedNames = new ArrayList<>(List.of(
Expand Down Expand Up @@ -525,7 +545,7 @@ public void testBaseChannelsForSystemIncludesEus() throws Exception {
ChannelManager.RHEL_PRODUCT_NAME, version, release3);
HibernateFactory.getSession().flush();

Set<EssentialChannelDto> channels = ChannelManager.listBaseChannelsForSystem(user, s);
List<EssentialChannelDto> channels = ChannelManager.listBaseChannelsForSystem(user, s);
assertTrue(channels.size() >= 2);
}

Expand Down Expand Up @@ -813,7 +833,7 @@ public void testListCompatibleBaseChannels() throws Exception {
commitHappened();

// Ask for channels compatible with the new server's base
Set<EssentialChannelDto> compatibles = ChannelManager.listCompatibleBaseChannelsForChannel(user, c);
List<EssentialChannelDto> compatibles = ChannelManager.listCompatibleBaseChannelsForChannel(user, c);

// There should be two - we now list ALL custom-channelsl
assertNotNull(compatibles);
Expand Down
6 changes: 3 additions & 3 deletions java/code/src/com/redhat/rhn/manager/ssm/SsmManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private static ChannelSelectionResult handleExplicitBaseChannelChange(Date earli
boolean newBaseIsCompatible = true;
if (baseChange) {
if (currentBase.isPresent()) {
Set<EssentialChannelDto> compatibleBaseChannels = ChannelManager
List<EssentialChannelDto> compatibleBaseChannels = ChannelManager
.listCompatibleBaseChannelsForChannel(user, currentBase.get());
newBaseIsCompatible =
// new base is in the compatible channels list
Expand All @@ -305,7 +305,7 @@ private static ChannelSelectionResult handleExplicitBaseChannelChange(Date earli
}
else {
// system doesn't have a base
Set<EssentialChannelDto> availableBaseChannels = ChannelManager.listBaseChannelsForSystem(user, srv);
List<EssentialChannelDto> availableBaseChannels = ChannelManager.listBaseChannelsForSystem(user, srv);
newBaseIsCompatible = availableBaseChannels.stream()
.anyMatch(abc -> abc.getId().equals(srvChange.getNewBaseId().orElse(null)));
}
Expand Down Expand Up @@ -496,7 +496,7 @@ public static List<SsmAllowedChildChannelsDto> computeAllowedChannelChanges(SsmB
}
else if (change.getNewBaseId() > 0) {
// explicit base channel change
Set<EssentialChannelDto> compatibleBases = ChannelManager
List<EssentialChannelDto> compatibleBases = ChannelManager
.listCompatibleBaseChannelsForChannel(user, currentBase);
Channel newBase = compatibleBases.stream()
.filter(cb -> cb.getId() == change.getNewBaseId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

import spark.Request;
Expand Down Expand Up @@ -107,7 +106,7 @@ public static String getBaseChannels(Request request, Response response, User us
SsmAllowedBaseChannelsJson allowedBaseJson = new SsmAllowedBaseChannelsJson();
allowedBaseJson.setBase(new SsmChannelDto(c.getId(), c.getName(), c.isCustom()));

Set<EssentialChannelDto> compatibles = ChannelManager.listCompatibleBaseChannelsForChannel(user, c);
List<EssentialChannelDto> compatibles = ChannelManager.listCompatibleBaseChannelsForChannel(user, c);

allowedBaseJson.setAllowedBaseChannels(
compatibles.stream().map(cc ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ public String getChannels(Request request, Response response, User user) {
*/
public String getAvailableBaseChannels(Request request, Response response, User user) {
return withServer(request, response, user, server -> {
Set<EssentialChannelDto> orgChannels = ChannelManager.listBaseChannelsForSystem(user, server);
List<EssentialChannelDto> orgChannels = ChannelManager.listBaseChannelsForSystem(user, server);
List<ChannelsJson.ChannelJson> baseChannels =
orgChannels.stream().map(c -> new ChannelsJson.ChannelJson(c.getId(),
c.getLabel(),
Expand Down
1 change: 1 addition & 0 deletions java/spacewalk-java.changes.cbbayburt.bsc1233724
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Ensure channel lists are reliably sorted by name (bsc#1233724)
Loading