java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemChannelsAction.java | 10
+
java/code/src/com/redhat/rhn/frontend/dto/ChildChannelDto.java | 16
++
java/code/src/com/redhat/rhn/manager/system/SystemManager.java | 77
+++-------
java/code/webapp/WEB-INF/pages/systems/sdc/channels.jsp | 26
++-
4 files changed, 73 insertions(+), 56 deletions(-)
New commits:
commit 30f6fe90f434d41d888283166205016b835da4f5
Author: Milan Zazrivec <mzazrivec(a)redhat.com>
Date: Mon May 2 18:26:21 2011 +0200
673392 - alter channel subscriptions: display flex consumption
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 3e7f04c..dbde178 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
@@ -76,6 +76,7 @@ public class SystemChannelsAction extends RhnLookupDispatchAction {
public static final String CURRENT_BASE_CHANNEL = "current_base_channel";
public static final String CURRENT_BASE_CHANNEL_ID =
"current_base_channel_id";
public static final String NEW_BASE_CHANNEL = "new_base_channel";
+ public static final String SERVER_FVE_ELIGIBLE = "server_fve_eligible";
/** {@inheritDoc} */
@@ -91,6 +92,7 @@ public class SystemChannelsAction extends RhnLookupDispatchAction {
// Setup request attributes
request.setAttribute(RequestContext.SYSTEM, s);
+ request.setAttribute(SERVER_FVE_ELIGIBLE, SystemManager.isServerFveEligible(s));
if (s.getBaseChannel() != null) {
Channel baseChannel = s.getBaseChannel();
List channels = baseChannel.getAccessibleChildrenFor(user);
@@ -107,8 +109,12 @@ public class SystemChannelsAction extends RhnLookupDispatchAction {
child.isSubscribable(user.getOrg(), s));
childchannels[i].setAvailableSubscriptions(
- SystemManager.availableSystemChannelSubscriptions(
- s, child, user.getOrg()));
+ ChannelManager.getAvailableEntitlements(
+ user.getOrg(), child));
+
+ childchannels[i].setAvailableFveSubscriptions(
+ ChannelManager.getAvailableFveEntitlements(
+ user.getOrg(), child));
}
request.setAttribute(AVAIL_CHILD_CHANNELS, childchannels);
form.set(NEW_BASE_CHANNEL_ID, s.getBaseChannel().getId());
diff --git a/java/code/src/com/redhat/rhn/frontend/dto/ChildChannelDto.java
b/java/code/src/com/redhat/rhn/frontend/dto/ChildChannelDto.java
index 1cc9c2e..6e47971 100644
--- a/java/code/src/com/redhat/rhn/frontend/dto/ChildChannelDto.java
+++ b/java/code/src/com/redhat/rhn/frontend/dto/ChildChannelDto.java
@@ -28,6 +28,7 @@ public class ChildChannelDto {
private boolean isFreeForGuests;
private boolean isSubscribable;
private Long availableSubscriptions;
+ private Long availableFveSubscriptions;
private Long systemCount;
/**
@@ -148,6 +149,21 @@ public class ChildChannelDto {
this.availableSubscriptions = availableSubscriptionsIn;
}
+ /**
+ * @return Returns the availableFveSubscriptions.
+ */
+ public Long getAvailableFveSubscriptions() {
+ return availableFveSubscriptions;
+ }
+
+
+ /**
+ * @param availableFveSubscriptionsIn The availableFveSubscriptions to set.
+ */
+ public void setAvailableFveSubscriptions(Long availableFveSubscriptionsIn) {
+ this.availableFveSubscriptions = availableFveSubscriptionsIn;
+ }
+
/**
* @return Returns the isSubscribable.
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 0513f61..358d5c1 100644
--- a/java/code/src/com/redhat/rhn/manager/system/SystemManager.java
+++ b/java/code/src/com/redhat/rhn/manager/system/SystemManager.java
@@ -1992,6 +1992,25 @@ public class SystemManager extends BaseManager {
}
}
+
+ /**
+ * Check if a given Server is FVE eligible
+ * @param serverIn to check
+ * @return true if Server is FVE eligible, false otherwise
+ */
+ public static boolean isServerFveEligible(Server serverIn) {
+ SelectMode m = ModeFactory.getMode("System_queries",
"is_server_fve_eligible");
+ Map params = new HashMap();
+ params.put("sid", serverIn.getId());
+
+ if (m.execute(params).size() >= 1) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+
/**
* Check to see if an attempt to subscribe the passed in server to the
* passed in channel will succeed. Checks available slots, if the channel is
@@ -2004,64 +2023,28 @@ public class SystemManager extends BaseManager {
*/
public static boolean canServerSubscribeToChannel(Org orgIn, Server serverIn,
Channel channelIn) {
-
if (serverIn.isSubscribed(channelIn)) {
- log.debug("already subscribed. return true");
return true;
}
// If channel is free for this guest, dont check avail subs
if (ChannelManager.isChannelFreeForSubscription(serverIn, channelIn)) {
- log.debug("its a free channel for this server, returning true");
return true;
}
- Long availableSubscriptions = availableSystemChannelSubscriptions(serverIn,
- channelIn, orgIn);
-
- if (availableSubscriptions != null && (availableSubscriptions.longValue()
< 1)) {
- log.debug("avail subscriptions is to small : " +
availableSubscriptions);
- return false;
- }
- log.debug("canServerSubscribeToChannel true!");
- return true;
- }
-
- /**
- * 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;
-
- /* Check if the channel is consumable for free */
- if (ChannelManager.isChannelFreeForSubscription(serverIn, channelIn)) {
- return availableSubscriptions;
- }
-
- /* 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);
+ // Not free. Check to see if we're a guest, and there are FVEs available.
+ // Note that for FVEs, NULL == NOT FOUND
+ if (isServerFveEligible(serverIn)) {
+ Long availableFVEs = ChannelManager.getAvailableFveEntitlements(orgIn,
channelIn);
+ if (availableFVEs != null && (availableFVEs.longValue() > 0)) {
+ return true;
+ }
}
- return availableSubscriptions;
+ // Finally, check available physical subs
+ // Note that for PHYS SUBS, NULL == UNLIMITED
+ Long availableSubs = ChannelManager.getAvailableEntitlements(orgIn, channelIn);
+ return ((availableSubs == null) || (availableSubs.longValue() > 0));
}
/**
diff --git a/java/code/webapp/WEB-INF/pages/systems/sdc/channels.jsp
b/java/code/webapp/WEB-INF/pages/systems/sdc/channels.jsp
index 6ed6023..45426a2 100644
--- a/java/code/webapp/WEB-INF/pages/systems/sdc/channels.jsp
+++ b/java/code/webapp/WEB-INF/pages/systems/sdc/channels.jsp
@@ -44,15 +44,27 @@
<c:if test="${not channel.subscribed}">
<input ${disabledChannel} name="child_channel"
value="${channel.id}" type="checkbox" id="unchecked">
</c:if>
- <c:if test="${not channel.freeForGuests &&
system.virtualGuest && channel.availableSubscriptions != null}">
- <span class="asterisk">* </span>
- </c:if>
<a
href="/rhn/channels/ChannelDetail.do?cid=${channel.id}">${channel.name}</a>
- <c:if test="${channel.availableSubscriptions !=
null}">
- (<strong>${channel.availableSubscriptions}</strong>
<bean:message key="sdc.channels.edit.available"/>)
+ <c:if test="${system.virtualGuest}">
+ <c:if test="${not channel.freeForGuests}">
+ <span class="asterisk">* </span>
+ </c:if>
+ <c:choose>
+ <c:when test="${channel.freeForGuests &&
system.virtualInstance.hostSystem != null}">
+ (<bean:message
key="sdc.channels.edit.unlimited"/>)
+ </c:when>
+
+ <c:when test="${server_fve_eligible &&
channel.availableFveSubscriptions > 0}">
+
(<strong>${channel.availableFveSubscriptions}</strong> flex <bean:message
key="sdc.channels.edit.available"/>)
+ </c:when>
+
+ <c:otherwise>
+ (<strong>${channel.availableSubscriptions}</strong>
<bean:message key="sdc.channels.edit.available"/>)
+ </c:otherwise>
+ </c:choose>
</c:if>
- <c:if test="${channel.availableSubscriptions ==
null}">
- (<bean:message
key="sdc.channels.edit.unlimited"/>)
+ <c:if test="${not system.virtualGuest}">
+ (<strong>${channel.availableSubscriptions}</strong>
<bean:message key="sdc.channels.edit.available"/>)
</c:if>
</li>
</c:forEach>