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

Multiple repos for vendor channels2 #9481

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
64ad853
remove duplicate methods and simplify some constructs
mcalmer Nov 4, 2024
3785171
add equals and hashCode for SUSEProductsSCCRepository
mcalmer Nov 4, 2024
b94be94
split function and extract linkOrphanContentSource
mcalmer Nov 4, 2024
656597e
improve hibernate entities for SCCRepository
mcalmer Nov 4, 2024
a9f03a1
change testcase to use a repository which fully exists in the metadata
mcalmer Nov 4, 2024
b4192bb
speedup getAvailableChannels by providing static extension map
mcalmer Nov 4, 2024
8883ce4
improve hibernate handling
mcalmer Nov 4, 2024
c5758a1
change logging
mcalmer Nov 4, 2024
656cc99
add changelog
mcalmer Nov 6, 2024
62089ed
DB: rename suseProductSCCRepository into suseChannelTemplate
mcalmer Nov 15, 2024
4aff272
rename SUSEProductSCCRepository into ChannelTemplate
mcalmer Nov 7, 2024
7610505
DB schema: multiple reppositories for a channel template
mcalmer Nov 11, 2024
776905c
introduce nonoss flag for repositories
mcalmer Nov 11, 2024
9cb9d38
multiple repositories for channel templates
mcalmer Nov 11, 2024
886fa7e
workaround a query which get stuck from time to time
mcalmer Nov 11, 2024
25d2f8b
find contentsource by repo not only via url
mcalmer Nov 11, 2024
59dafad
find sccrepository from contentsource via url
mcalmer Nov 11, 2024
6d5fb40
change the way how the contentsource label is set
mcalmer Nov 11, 2024
23ec6b9
unit test for adding/removing restricted channels
mcalmer Oct 31, 2024
1044fe3
define some variable for product and repo ids for better understanding
mcalmer Nov 14, 2024
eba623e
run podman rootless
mcalmer Nov 15, 2024
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
4 changes: 2 additions & 2 deletions java/Makefile.docker
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ dockerrun_pg ::
$(EXECUTOR) run $(DOCKER_COMMON_OPTS) $(DOCKER_PG_PORTS) $(DOCKER_VOLUMES) $(DOCKER_ENV) $(DOCKER_REGISTRY)/$(DOCKER_CONTAINER_BASE)-pgsql-4eclipse

podmanpull ::
sudo podman pull $(DOCKER_REGISTRY)/$(DOCKER_CONTAINER_BASE)-pgsql-4eclipse
podman pull $(DOCKER_REGISTRY)/$(DOCKER_CONTAINER_BASE)-pgsql-4eclipse

podmanrun ::
cp buildconf/test/rhn.conf.postgresql-example buildconf/test/rhn.conf
sudo podman run $(DOCKER_COMMON_OPTS) $(DOCKER_PG_PORTS) $(DOCKER_VOLUMES) $(DOCKER_ENV) $(DOCKER_REGISTRY)/$(DOCKER_CONTAINER_BASE)-pgsql-4eclipse
podman run $(DOCKER_COMMON_OPTS) $(DOCKER_PG_PORTS) $(DOCKER_VOLUMES) $(DOCKER_ENV) $(DOCKER_REGISTRY)/$(DOCKER_CONTAINER_BASE)-pgsql-4eclipse
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,22 @@
WITH product_channels AS (
-- Extract all the mandatory channels for the given product ids
SELECT sp.id
, spr.channel_label AS label
, ct.channel_label AS label
FROM suseproducts sp
INNER JOIN suseproductsccrepository spr ON sp.id = spr.product_id
INNER JOIN suseChannelTemplate ct ON sp.id = ct.product_id
WHERE sp.product_id IN ( %s )
AND spr.mandatory = 'Y'
AND ct.mandatory = 'Y'
), custom_channels AS (
-- Extract all the custom channels
SELECT id, label
FROM rhnchannel
WHERE org_id IS NOT NULL
AND channel_product_id IS NULL
AND channel_product_id IS NULL
) -- Evaluate if the labels are conflicting
SELECT pc.id, cc.label
FROM product_channels pc
INNER JOIN custom_channels cc ON pc.label = cc.label
</query>
</mode>


</datasource_modes>
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import com.redhat.rhn.domain.image.ProfileCustomDataValue;
import com.redhat.rhn.domain.notification.NotificationMessage;
import com.redhat.rhn.domain.notification.UserNotification;
import com.redhat.rhn.domain.product.SUSEProductSCCRepository;
import com.redhat.rhn.domain.product.ChannelTemplate;
import com.redhat.rhn.domain.recurringactions.GroupRecurringAction;
import com.redhat.rhn.domain.recurringactions.MinionRecurringAction;
import com.redhat.rhn.domain.recurringactions.OrgRecurringAction;
Expand Down Expand Up @@ -136,7 +136,7 @@ private AnnotationRegistry() {
SCCRepository.class,
SCCSubscription.class,
SCCOrderItem.class,
SUSEProductSCCRepository.class,
ChannelTemplate.class,
SCCRepositoryAuth.class,
SCCRepositoryNoAuth.class,
SCCRepositoryBasicAuth.class,
Expand Down
18 changes: 4 additions & 14 deletions java/code/src/com/redhat/rhn/domain/channel/Channel.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -696,24 +696,14 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
<![CDATA[
SELECT DISTINCT {r.*}
FROM rhnChannel c
JOIN suseProductSCCRepository pr ON c.label = pr.channel_label
JOIN suseSCCRepository r ON pr.repo_id = r.id
JOIN suseChannelTemplate ct ON c.label = ct.channel_label
JOIN suseChannelTemplateRepository cr ON ct.id = cr.template_id
JOIN suseSCCRepository r ON cr.repo_id = r.id
WHERE c.org_id IS NULL
AND c.id = :cid
AND c.id = :cid
]]>
<return alias="r" class="com.redhat.rhn.domain.scc.SCCRepository" />
</sql-query>
<sql-query name="Channel.findOrphanVendorChannels">
<![CDATA[
SELECT {c.*}
FROM rhnChannel c
LEFT JOIN rhnChannelCloned c_1_ ON c.id = c_1_.id
left join rhnChannelContentSource ccs on c.id = ccs.channel_id
where c.org_id is NULL
and ccs.source_id IS NULL
]]>
<return alias="c" class="com.redhat.rhn.domain.channel.Channel" />
</sql-query>
<sql-query name="Channel.findModularChannels">
<![CDATA[
SELECT {c.*}
Expand Down
82 changes: 58 additions & 24 deletions java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.redhat.rhn.domain.common.ChecksumType;
import com.redhat.rhn.domain.kickstart.KickstartableTree;
import com.redhat.rhn.domain.org.Org;
import com.redhat.rhn.domain.product.ChannelTemplate;
import com.redhat.rhn.domain.rhnpackage.Package;
import com.redhat.rhn.domain.scc.SCCRepository;
import com.redhat.rhn.domain.server.Server;
Expand All @@ -36,7 +37,6 @@
import org.apache.logging.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;

Expand All @@ -48,7 +48,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

/**
Expand Down Expand Up @@ -144,15 +143,34 @@ public static List<ContentSource> lookupContentSources(Org org) {
* @return the ContentSource(s)
*/
public static List<ContentSource> lookupOrphanVendorContentSources() {
return singleton.listObjectsByNamedQuery("ContentSource.findOrphanVendorContentSources", Map.of());
return getSession().createNamedQuery("ContentSource.findOrphanVendorContentSources", ContentSource.class)
.list();
}

/**
* Lookup orphan vendor channels
* @return the Channels(s)
* Find all Vendor Channels which miss repositories comparing to SCC provided data
* @return list of channels which are incomplete
*/
public static List<Channel> lookupOrphanVendorChannels() {
return singleton.listObjectsByNamedQuery("Channel.findOrphanVendorChannels", Map.of());
public static List<Channel> findIncompleteVendorChannels() {
return getSession().createNativeQuery("""
SELECT X.*, 0 as clazz_ FROM (
SELECT c.*,
(SELECT COUNT(*)
FROM suseChannelTemplate ct
JOIN suseChannelTemplateRepository cr ON ct.id = cr.template_id
WHERE ct.channel_label = c.label) sccrepositorycount,
(SELECT COUNT(*)
FROM rhnChannelContentSource ccs
WHERE ccs.channel_id = c.id) contentsourcecount
FROM rhnChannel c
WHERE c.org_id IS NULL) X
WHERE X.sccrepositorycount > X.contentsourcecount;
""", Channel.class)
.addSynchronizedEntityClass(ChannelTemplate.class)
.addSynchronizedEntityClass(Channel.class)
.addSynchronizedEntityClass(SCCRepository.class)
.addSynchronizedEntityClass(ContentSource.class)
.getResultList();
}

/**
Expand All @@ -169,9 +187,11 @@ public static void cleanupOrphanVendorContentSource() {
* @param c the channel
* @return repository
*/
public static Optional<SCCRepository> findVendorRepositoryByChannel(Channel c) {
return Optional.ofNullable(singleton.lookupObjectByNamedQuery("Channel.findVendorRepositoryByChannelId",
Map.of("cid", c.getId())));
public static List<SCCRepository> findVendorRepositoryByChannel(Channel c) {
return getSession()
.createNamedQuery("Channel.findVendorRepositoryByChannelId", SCCRepository.class)
.setParameter("cid", c.getId())
.list();
}

/**
Expand Down Expand Up @@ -1240,26 +1260,40 @@ public static List<ContentSource> listVendorContentSources() {
/**
* Find a vendor content source (org is null) for a given repo URL.
* @param repoUrl url to match against
* @param label the content source label in case multiple repos match the URL
* @return vendor content source if it exists
*/
public static ContentSource findVendorContentSourceByRepo(String repoUrl) {
Criteria criteria = getSession().createCriteria(ContentSource.class);
criteria.add(Restrictions.isNull("org"));
if (repoUrl.contains("mirrorlist.centos.org") || repoUrl.contains("mirrors.rockylinux.org")) {
criteria.add(Restrictions.eq("sourceUrl", repoUrl));
public static ContentSource findVendorContentSourceByRepo(String repoUrl, String label) {
List<ContentSource> contentSources = null;
String [] parts = repoUrl.split("\\?");
String repoUrlPrefix = parts[0];

if (repoUrl.contains("mirrorlist.centos.org") || repoUrl.contains("mirrors.rockylinux.org") ||
parts.length == 1) {
contentSources = getSession()
.createQuery("SELECT cs FROM ContentSource cs WHERE org is null AND sourceUrl = :repoURL",
ContentSource.class)
.setParameter("repoURL", repoUrl)
.list();
}
else {
String [] parts = repoUrl.split("\\?");
String repoUrlPrefix = parts[0];
if (parts.length > 1) {
criteria.add(Restrictions.like("sourceUrl", repoUrlPrefix + '?',
MatchMode.START));
}
else {
criteria.add(Restrictions.eq("sourceUrl", repoUrlPrefix));
contentSources = getSession()
.createQuery("SELECT cs FROM ContentSource cs WHERE org is null AND sourceUrl like :repoURL",
ContentSource.class)
.setParameter("repoURL", repoUrl + "%")
.list();
}
if (contentSources.size() == 1) {
return contentSources.get(0);
}
else if (contentSources.size() > 1) {
for (ContentSource source : contentSources) {
if (source.getLabel().equals(label)) {
return source;
}
}
}
return (ContentSource) criteria.uniqueResult();
return lookupVendorContentSourceByLabel(label);
}

/**
Expand Down
Loading
Loading