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

Allow switch channel to liberty #9192

Merged
14 changes: 7 additions & 7 deletions java/code/src/com/redhat/rhn/domain/common/ArchType.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.redhat.rhn.domain.rhnpackage.PackageFactory;
import com.redhat.rhn.domain.rhnpackage.PackageType;

import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.util.Objects;
Expand Down Expand Up @@ -98,19 +99,18 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

ArchType archType = (ArchType) o;
if (o instanceof ArchType) {
ArchType archType = (ArchType) o;

return Objects.equals(id, archType.id);
return Objects.equals(getLabel(), archType.getLabel());
}
return false;
}

/** {@inheritDoc} */
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
return new HashCodeBuilder().append(getLabel()).toHashCode();
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ public static Channel createBaseChannelForBaseProduct(SUSEProduct product, User
channel.setOrg(null);
channel = TestUtils.saveAndReload(channel);
SUSEProductTestUtils.createTestSUSEProductChannel(channel, product, true);
channel = TestUtils.saveAndReload(channel);
return channel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
<many-to-one
name="archType"
class="com.redhat.rhn.domain.common.ArchType"
column="arch_type_id"/>
column="arch_type_id"
lazy="false"/>
</class>

<query name="PackageArch.findById">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ public boolean equals(Object archIn) {

if (archIn instanceof PackageArch) {
PackageArch arch = (PackageArch) archIn;
return new EqualsBuilder().append(this.name, arch.getName()).append(getLabel(),
arch.getLabel()).append(getId(), arch.getId()).append(getArchType(),
arch.getArchType()).isEquals();
return new EqualsBuilder()
.append(this.name, arch.getName())
.append(getLabel(), arch.getLabel())
.append(getArchType(), arch.getArchType()).isEquals();
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ public static List<PackageArch> lookupPackageArch() {
public static List<Package> listPackagesByPackageName(PackageName pn) {
Session session = HibernateFactory.getSession();

return session.getNamedQuery("Package.findByPackageName").setParameter("packageName",
pn).list();

return session.createNamedQuery("Package.findByPackageName", Package.class)
.setParameter("packageName", pn)
.list();
}

/**
Expand Down
25 changes: 14 additions & 11 deletions java/code/src/com/redhat/rhn/domain/server/InstalledProduct.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
import com.redhat.rhn.domain.product.SUSEProductFactory;
import com.redhat.rhn.domain.rhnpackage.PackageArch;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.util.Objects;

/**
* Installed Product
*/
Expand Down Expand Up @@ -167,17 +168,19 @@ public void setBaseproduct(boolean isBaseproductIn) {
* {@inheritDoc}
*/
@Override
public boolean equals(final Object other) {
if (!(other instanceof InstalledProduct)) {
return false;
public boolean equals(final Object oIn) {
if (this == oIn) {
return true;
}
if (oIn instanceof InstalledProduct) {
InstalledProduct that = (InstalledProduct) oIn;
return isBaseproduct() == that.isBaseproduct() &&
Objects.equals(getName(), that.getName()) &&
Objects.equals(getVersion(), that.getVersion()) &&
Objects.equals(getArch(), that.getArch()) &&
Objects.equals(getRelease(), that.getRelease());
}
InstalledProduct castOther = (InstalledProduct) other;
return new EqualsBuilder().append(getName(), castOther.getVersion())
.append(getVersion(), castOther.getVersion())
.append(getArch(), castOther.getArch())
.append(getRelease(), castOther.getRelease())
.append(isBaseproduct(), castOther.isBaseproduct())
.isEquals();
return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

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

List<EssentialChannelDto> compatibles = ChannelManager.listCompatibleBaseChannelsForChannel(user, c);
Set<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 @@ -92,6 +92,7 @@ public class SPMigrationAction extends RhnAction {
private static final String UPDATESTACK_UPDATE_NEEDED = "updateStackUpdateNeeded";
private static final String IS_MINION = "isMinion";
private static final String IS_SUSE_MINION = "isSUSEMinion";
private static final String IS_REDHAT_MINION = "isRedHatMinion";
private static final String IS_SALT_UP_TO_DATE = "isSaltUpToDate";
private static final String SALT_PACKAGE = "saltPackage";

Expand Down Expand Up @@ -149,6 +150,11 @@ public ActionForward execute(ActionMapping actionMapping,
logger.debug("is a SUSE minion? {}", isSUSEMinion);
request.setAttribute(IS_SUSE_MINION, isSUSEMinion);

// Check if this is a RedHat system (for minions only)
boolean isRedHatMinion = isMinion && minion.get().getOsFamily().equals("RedHat");
logger.debug("is a RedHat minion? {}", isRedHatMinion);
request.setAttribute(IS_REDHAT_MINION, isRedHatMinion);

// Check if the salt package on the minion is up to date (for minions only)
String saltPackage = "salt";
if (PackageFactory.lookupByNameAndServer("venv-salt-minion", server) != null) {
Expand All @@ -162,7 +168,8 @@ public ActionForward execute(ActionMapping actionMapping,

// Check if this server supports distribution upgrades via capabilities
// (for traditional clients only)
boolean supported = isSUSEMinion || DistUpgradeManager.isUpgradeSupported(server, ctx.getCurrentUser());
boolean supported = isSUSEMinion || isRedHatMinion ||
DistUpgradeManager.isUpgradeSupported(server, ctx.getCurrentUser());
logger.debug("Upgrade supported for '{}'? {}", server.getName(), supported);
request.setAttribute(UPGRADE_SUPPORTED, supported);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
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 @@ -120,8 +121,7 @@ public ActionForward unspecified(ActionMapping mapping,
}


List<EssentialChannelDto> orgChannels = ChannelManager.listBaseChannelsForSystem(
user, s);
Set<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 @@ -723,8 +723,7 @@ public Object[] listSubscribableBaseChannels(User loggedInUser, Integer sid)
Channel baseChannel = server.getBaseChannel();
List<Map<String, Object>> returnList = new ArrayList<>();

List<EssentialChannelDto> list =
ChannelManager.listBaseChannelsForSystem(loggedInUser, server);
Set<EssentialChannelDto> list = ChannelManager.listBaseChannelsForSystem(loggedInUser, server);
for (EssentialChannelDto ch : list) {
Boolean currentBase = (baseChannel != null) &&
baseChannel.getId().equals(ch.getId());
Expand Down
105 changes: 91 additions & 14 deletions java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
import com.redhat.rhn.domain.product.SUSEProductExtension;
import com.redhat.rhn.domain.product.SUSEProductFactory;
import com.redhat.rhn.domain.rhnpackage.PackageEvr;
import com.redhat.rhn.domain.rhnpackage.PackageFactory;
import com.redhat.rhn.domain.role.RoleFactory;
import com.redhat.rhn.domain.server.InstalledProduct;
import com.redhat.rhn.domain.server.MinionServer;
import com.redhat.rhn.domain.server.Server;
import com.redhat.rhn.domain.server.ServerFactory;
Expand Down Expand Up @@ -126,6 +128,13 @@ public class ChannelManager extends BaseManager {
private static TaskomaticApi taskomaticApi = new TaskomaticApi();
private static Logger log = LogManager.getLogger(ChannelManager.class);

private static final Map<InstalledProduct, InstalledProduct> COMPATIBLE_PRODUCTS = new HashMap<>();
static {
COMPATIBLE_PRODUCTS.put(
new InstalledProduct("res", "7", PackageFactory.lookupPackageArchByLabel("x86_64"), null, true),
new InstalledProduct("res-ltss", "7", PackageFactory.lookupPackageArchByLabel("x86_64"), null, true)
);
}
public static final String QRY_ROLE_MANAGE = "manage";
public static final String QRY_ROLE_SUBSCRIBE = "subscribe";
public static final String RHEL7_EUS_VERSION = "7Server";
Expand Down Expand Up @@ -1678,12 +1687,11 @@ private static Channel getDefaultBaseChannel(Org org, String version, ChannelArc
*
* @param usr requesting list
* @param s Server to check against
* @return List of Channel objects that match
* @return Set of Channel objects that match
*/
public static List<EssentialChannelDto> listBaseChannelsForSystem(User usr,
Server s) {
public static Set<EssentialChannelDto> listBaseChannelsForSystem(User usr, Server s) {

List<EssentialChannelDto> channelDtos = new LinkedList<>();
Set<EssentialChannelDto> channelDtos = new HashSet<>();
PackageEvr releaseEvr = PackageManager.lookupReleasePackageEvrFor(s);
if (releaseEvr != null) {
String rhelVersion =
Expand All @@ -1709,6 +1717,7 @@ public static List<EssentialChannelDto> listBaseChannelsForSystem(User usr,
}

listPossibleSuseBaseChannelsForServer(s).ifPresent(channelDtos::addAll);
channelDtos.addAll(listCompatibleBaseChannelsForServer(s));

// Get all the possible base-channels owned by this Org
channelDtos.addAll(listCustomBaseChannelsForServer(s));
Expand All @@ -1720,25 +1729,92 @@ public static List<EssentialChannelDto> listBaseChannelsForSystem(User usr,
return channelDtos;
}

/**
* Support switching Channels. For a Server using a base channel find the right compatible base channel to switch to
* @param s the server to switch the base channel
* @return Optional List of possible base channels where this system can change to
*/
public static Set<EssentialChannelDto> listCompatibleBaseChannelsForServer(Server s) {
log.debug("listCompatibleChannels called");

Optional<InstalledProduct> installedBaseProduct = s.getInstalledProducts()
.stream()
.filter(InstalledProduct::isBaseproduct)
.findFirst();

return Opt.fold(installedBaseProduct,
() -> {
log.info("Server has no base product installed");
return Collections.emptySet();
},
bp -> {
if (COMPATIBLE_PRODUCTS.containsKey(bp)) {
SUSEProduct compatProduct = COMPATIBLE_PRODUCTS.get(bp).getSUSEProduct();
if (compatProduct != null) {
return compatProduct.getSuseProductChannels()
.stream()
.map(SUSEProductChannel::getChannel)
.filter(Channel::isBaseChannel)
.map(EssentialChannelDto::new)
.collect(Collectors.toSet());
}
}
return Collections.emptySet();
});
}

/**
* Support switching Channels. For a channel find the right compatible base channel to switch to
* @param baseChannelIn the base channel
* @return Set of possible base channels where a system which use current base channel can switch to
*/
public static Set<EssentialChannelDto> listCompatibleBaseChannelsForChannel(Channel baseChannelIn) {
Set<EssentialChannelDto> retval = new HashSet<>();
for (Map.Entry<InstalledProduct, InstalledProduct> compatProducts : COMPATIBLE_PRODUCTS.entrySet()) {
SUSEProduct sourceProduct = compatProducts.getKey().getSUSEProduct();
if (sourceProduct != null && sourceProduct
.getSuseProductChannels()
.stream()
.map(SUSEProductChannel::getChannel)
.filter(Channel::isBaseChannel)
.map(Channel::getLabel)
.anyMatch(l -> l.equals(baseChannelIn.getLabel()))) {
SUSEProduct targetProduct = compatProducts.getValue().getSUSEProduct();
if (targetProduct != null) {
targetProduct
.getSuseProductChannels()
.stream()
.map(SUSEProductChannel::getChannel)
.filter(Channel::isBaseChannel)
.map(EssentialChannelDto::new)
.forEach(retval::add);
}
}
}
return retval;
}

/**
* Given a base-channel, find all the base channels available to the specified user
* that a system with the specified channel may be re-subscribed to.
*
* @param u User of interest
* @param u User of interest
* @param inChan Base-channel of interest
* @return List of channels that a system subscribed to "c" could be re-subscribed to
* @return Set of channels that a system subscribed to "c" could be re-subscribed to
*/
public static List<EssentialChannelDto> listCompatibleBaseChannelsForChannel(User u, Channel inChan) {
public static Set<EssentialChannelDto> listCompatibleBaseChannelsForChannel(User u, Channel inChan) {
// Get all the custom-channels owned by this org and add them
List<EssentialChannelDto> retval = ChannelFactory.listCustomBaseChannelsForSSM(u, inChan).stream()
.map(c -> new EssentialChannelDto(c))
.collect(Collectors.toList());
Set<EssentialChannelDto> retval = ChannelFactory.listCustomBaseChannelsForSSM(u, inChan)
.stream()
.map(EssentialChannelDto::new)
.collect(Collectors.toSet());

retval.addAll(ChannelFactory.listCompatibleDcmForChannelSSMInNullOrg(u, inChan).stream()
.map(c -> new EssentialChannelDto(c))
.collect(Collectors.toList()));
ChannelFactory.listCompatibleDcmForChannelSSMInNullOrg(u, inChan)
.stream()
.map(EssentialChannelDto::new)
.forEach(retval::add);

List<EssentialChannelDto> eusBaseChans = new LinkedList<>();
Set<EssentialChannelDto> eusBaseChans = new HashSet<>();

ReleaseChannelMap rcm = lookupDefaultReleaseChannelMapForChannel(inChan);
if (rcm != null) {
Expand All @@ -1758,6 +1834,7 @@ public static List<EssentialChannelDto> listCompatibleBaseChannelsForChannel(Use
}
}
retval.addAll(eusBaseChans);
retval.addAll(listCompatibleBaseChannelsForChannel(inChan));

for (EssentialChannelDto dto : retval) {
if (dto.getId().longValue() == inChan.getId().longValue()) {
Expand Down
Loading