java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml | 21
+++++
java/code/src/com/redhat/rhn/domain/channel/Channel.hbm.xml | 5
+
java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java | 23
+++++
java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemChannelsAction.java | 4
-
java/code/src/com/redhat/rhn/manager/channel/ChannelEntitlementCounter.java | 12
+++
java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java | 17
++++
java/code/src/com/redhat/rhn/manager/system/SystemManager.java | 39
++++++++--
7 files changed, 115 insertions(+), 6 deletions(-)
New commits:
commit 009afe5bf9fa73a050d3516c09437ba2d5f2c157
Author: Milan Zazrivec <mzazrivec(a)redhat.com>
Date: Thu Feb 24 14:34:07 2011 +0100
673394 - correct entitlement logic when altering channel subscriptions
This fix is to make sure that when altering channel subscriptions, we
first check number of available flex guest entitlements in applicable
scenarios, then (if needed) check number of available regular entitlements.
diff --git a/java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml
b/java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml
index baa5bd3..ffe9db3 100644
--- a/java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml
+++ b/java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml
@@ -1794,6 +1794,27 @@ SELECT 1
</query>
</mode>
+<mode name="is_server_fve_eligible">
+ <query params="sid">
+ select 1
+ from rhnVirtualInstance vi
+ inner join rhnServer s on vi.virtual_system_id = s.id
+ where s.id = :sid and (
+ vi.host_system_id is null or
+ not exists (
+ select 1
+ from rhnServerGroupMembers sgm
+ inner join rhnServerGroup sg on sgm.server_group_id = sg.id
+ inner join rhnServerGroupType sgt on sgt.id = sg.group_type
+ inner join rhnServer s2 on s2.id = sgm.server_id
+ where s2.id = vi.host_system_id
+ and sgt.label in
+ ('virtualization_host', 'virtualization_host_platform')
+ )
+ )
+ </query>
+</mode>
+
<write-mode name="delete_note">
<query params="id,server_id">
delete from rhnServerNotes where id = :id and server_id = :server_id
diff --git a/java/code/src/com/redhat/rhn/domain/channel/Channel.hbm.xml
b/java/code/src/com/redhat/rhn/domain/channel/Channel.hbm.xml
index d435ae2..02fa661 100644
--- a/java/code/src/com/redhat/rhn/domain/channel/Channel.hbm.xml
+++ b/java/code/src/com/redhat/rhn/domain/channel/Channel.hbm.xml
@@ -264,6 +264,11 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
<![CDATA[select rhn_channel.available_chan_subscriptions(:channel_id, :org_id)
as entitlements from dual]]>
</sql-query>
+ <sql-query name="Channel.availableFveEntitlements">
+ <return-scalar type="long" column="entitlements"/>
+ <![CDATA[select rhn_channel.available_fve_chan_subs(:channel_id, :org_id) as
entitlements from dual]]>
+ </sql-query>
+
<sql-query name="Channel.verifyLabel">
<return-scalar type="string" column="label"/>
<![CDATA[select label from rhnChannel where label = :label]]>
diff --git a/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java
b/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java
index 469847e..ebca149 100644
--- a/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java
+++ b/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java
@@ -544,6 +544,29 @@ public class ChannelFactory extends HibernateFactory {
}
/**
+ * Returns available flex entitlements for the org and the given channel.
+ * @param org Org (used <b>only</b> when channel's org is NULL)
+ * @param c Channel
+ * @return available flex entitlements for the org and the given channel.
+ */
+ public static Long getAvailableFveEntitlements(Org org, Channel c) {
+ //
+ // The channel's org is used when not NULL to support
+ // shared channels.
+ //
+ Org channelOrg = c.getOrg();
+ if (channelOrg != null) {
+ org = channelOrg;
+ }
+ Map params = new HashMap();
+ params.put("channel_id", c.getId());
+ params.put("org_id", org.getId());
+ return (Long) singleton.lookupObjectByNamedQuery(
+ "Channel.availableFveEntitlements", params);
+
+ }
+
+ /**
* Creates an empty Channel
* @return empty Channel
*/
diff --git
a/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemChannelsAction.java
b/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemChannelsAction.java
index b8d1314..3e7f04c 100644
--- a/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemChannelsAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemChannelsAction.java
@@ -105,8 +105,10 @@ public class SystemChannelsAction extends RhnLookupDispatchAction {
s.isSubscribed(child),
ChannelManager.isChannelFreeForSubscription(s, child),
child.isSubscribable(user.getOrg(), s));
+
childchannels[i].setAvailableSubscriptions(
- ChannelManager.getAvailableEntitlements(user.getOrg(), child));
+ SystemManager.availableSystemChannelSubscriptions(
+ s, child, user.getOrg()));
}
request.setAttribute(AVAIL_CHILD_CHANNELS, childchannels);
form.set(NEW_BASE_CHANNEL_ID, s.getBaseChannel().getId());
diff --git a/java/code/src/com/redhat/rhn/manager/channel/ChannelEntitlementCounter.java
b/java/code/src/com/redhat/rhn/manager/channel/ChannelEntitlementCounter.java
index d58f6fd..07d3f01 100644
--- a/java/code/src/com/redhat/rhn/manager/channel/ChannelEntitlementCounter.java
+++ b/java/code/src/com/redhat/rhn/manager/channel/ChannelEntitlementCounter.java
@@ -37,4 +37,16 @@ public class ChannelEntitlementCounter {
return retval;
}
+ /**
+ * Get the available flex guest entitlements for the passed in Org
+ * and Channel
+ * @param orgIn to check
+ * @param channelIn to check
+ * @return Long count, null if unlimited.
+ */
+ public Long getAvailableFveEntitlements(Org orgIn, Channel channelIn) {
+ Long retval = ChannelFactory.getAvailableFveEntitlements(orgIn, channelIn);
+ return retval;
+ }
+
}
diff --git a/java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java
b/java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java
index 8c6e73b..4c54913 100644
--- a/java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java
+++ b/java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java
@@ -1128,6 +1128,23 @@ public class ChannelManager extends BaseManager {
}
/**
+ * Returns available flex entitlements for the org and the given channel.
+ * @param org Org
+ * @param c Channel
+ * @return available flex entitlements for the org and the given channel.
+ */
+ public static Long getAvailableFveEntitlements(Org org, Channel c) {
+ ChannelEntitlementCounter counter =
+ (ChannelEntitlementCounter) MethodUtil.getClassFromConfig(
+ ChannelEntitlementCounter.class.getName());
+
+ Long retval = counter.getAvailableFveEntitlements(org, c);
+ log.debug("getAvailableFveEntitlements: " + c.getLabel() + " got:
" + retval);
+
+ return retval;
+ }
+
+ /**
* Returns the latest packages in the channel. This call will return more details
* about the channel than the API specific call
* {@link #latestPackagesInChannel(com.redhat.rhn.domain.channel.Channel)}.
diff --git a/java/code/src/com/redhat/rhn/manager/system/SystemManager.java
b/java/code/src/com/redhat/rhn/manager/system/SystemManager.java
index bca2708..07b02f0 100644
--- a/java/code/src/com/redhat/rhn/manager/system/SystemManager.java
+++ b/java/code/src/com/redhat/rhn/manager/system/SystemManager.java
@@ -2003,12 +2003,10 @@ public class SystemManager extends BaseManager {
return true;
}
- // Otherwise check available subs
- Long availableSubscriptions =
- ChannelManager.getAvailableEntitlements(orgIn, channelIn);
+ Long availableSubscriptions = availableSystemChannelSubscriptions(serverIn,
+ channelIn, orgIn);
- if (availableSubscriptions != null &&
- (availableSubscriptions.longValue() < 1)) {
+ if (availableSubscriptions != null && (availableSubscriptions.longValue()
< 1)) {
log.debug("avail subscriptions is to small : " +
availableSubscriptions);
return false;
}
@@ -2017,6 +2015,37 @@ public class SystemManager extends BaseManager {
}
/**
+ * For given Server, Channel and Org return number of available subscriptions
+ * @param serverIn Server to check
+ * @param channelIn Channel to check
+ * @param orgIn Org to check
+ * @return number of subscriptions available
+ */
+ public static Long availableSystemChannelSubscriptions(Server serverIn,
+ Channel channelIn, Org orgIn) {
+ SelectMode m = ModeFactory.getMode("System_queries",
"is_server_fve_eligible");
+ Map params = new HashMap();
+ params.put("sid", serverIn.getId());
+
+ Long availableSubscriptions = null;
+
+ /* If serverIn is fve eligible, check number of flex guest entitlements available
*/
+ if (m.execute(params).size() >= 1) {
+ availableSubscriptions = ChannelManager.getAvailableFveEntitlements(orgIn,
channelIn);
+ }
+
+ /* If the previous query did not result any data or the number of flex guest
+ * subscriptions is zero, check number of regular entitlements available
+ */
+ if ((availableSubscriptions == null) || (availableSubscriptions.longValue() <
1)) {
+ availableSubscriptions = ChannelManager.getAvailableEntitlements(orgIn,
+ channelIn);
+ }
+
+ return availableSubscriptions;
+ }
+
+ /**
* Checks if the user has permissions to see the Server
* @param user User being checked
* @param sid ID of the Server being checked