java/code/src/com/redhat/rhn/common/db/datasource/xml/Channel_queries.xml | 13 + java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml | 3 java/code/src/com/redhat/rhn/frontend/dto/ChannelFamilySystem.java | 18 ++ java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml | 6 java/code/src/com/redhat/rhn/manager/system/SystemManager.java | 33 ++- java/code/src/com/redhat/rhn/manager/system/VirtualizationEntitlementsManager.java | 52 +++++ java/code/webapp/WEB-INF/pages/systems/entitlements/flexguests.jsp | 4 java/code/webapp/WEB-INF/struts-config.xml | 5 schema/spacewalk/common/data/rhnException.sql | 5 schema/spacewalk/oracle/packages/rhn_channel.pkb | 90 ++++++++++ schema/spacewalk/oracle/packages/rhn_channel.pks | 4 schema/spacewalk/upgrade/spacewalk-schema-1.0-to-spacewalk-schema-1.1/012-rhnException_data.sql | 2 12 files changed, 211 insertions(+), 24 deletions(-)
New commits: commit 0a6d245a91faac638eeba8e835c05d43c4d18680 Author: Partha Aji paji@redhat.com Date: Thu Jun 17 12:05:50 2010 -0400
Added the convert to flex plsql operation
diff --git a/java/code/src/com/redhat/rhn/common/db/datasource/xml/Channel_queries.xml b/java/code/src/com/redhat/rhn/common/db/datasource/xml/Channel_queries.xml index de48dfa..a7a9f58 100644 --- a/java/code/src/com/redhat/rhn/common/db/datasource/xml/Channel_queries.xml +++ b/java/code/src/com/redhat/rhn/common/db/datasource/xml/Channel_queries.xml @@ -1234,6 +1234,19 @@ GROUP BY C.id, C.name </query> </mode>
+<callable-mode name="convert_to_flex"> + <query params="sid, cfid, uid"> +BEGIN + rhn_channel.convert_to_fve(:sid, :cfid); +END; + </query> +</callable-mode> + +<callable-mode name="can_convert_to_flex"> + <query params="result, sid, cfid"> + {:result = call rhn_channel.convert_to_fve(:sid, :cfid)} + </query> +</callable-mode>
</datasource_modes>
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 8f97a59..79e10de 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 @@ -1745,8 +1745,5 @@ DELETE FROM rhnSatelliteChannelFamily WHERE server_id = :sid ) </query> </mode> - - - </datasource_modes>
diff --git a/java/code/src/com/redhat/rhn/frontend/dto/ChannelFamilySystem.java b/java/code/src/com/redhat/rhn/frontend/dto/ChannelFamilySystem.java index 01d3674..a9a3c20 100644 --- a/java/code/src/com/redhat/rhn/frontend/dto/ChannelFamilySystem.java +++ b/java/code/src/com/redhat/rhn/frontend/dto/ChannelFamilySystem.java @@ -114,4 +114,22 @@ public class ChannelFamilySystem extends SelectableAdapter { public String getSelectionKey() { return group.getId() + "|" + id; } + + /** + * Returns the channel family Id + * @param selectionKey the selection key used for this + * @return the channel family id + */ + public static Long parseChannelFamilyId(String selectionKey) { + return Long.valueOf(selectionKey.split("\|")[0]); + } + + /** + * Returns the system Id + * @param selectionKey the selection key used for this + * @return the system id + */ + public static Long parseServerId(String selectionKey) { + return Long.valueOf(selectionKey.split("\|")[1]); + } } diff --git a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml index e97a9c3..205a90d 100644 --- a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml +++ b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml @@ -6219,7 +6219,13 @@ value for this entitlement, excluding the default organization's consumption.</s <trans-unit id="flexguest.jsp.no-systems"> <source>There are no systems consuming Flex Guest entitlements.</source> </trans-unit> + <trans-unit id="Make Flex"> + <source>Convert To Flex Guest Entitlement</source> + </trans-unit> + <trans-unit id="eligible.flexguest.systems.confirm.message"> + <source>Converted <strong>{0}</strong> system(s) to use Flex Guest Entitlement.</source> + </trans-unit> </group>
<!-- System search --> 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 be532f1..2b2e47c 100644 --- a/java/code/src/com/redhat/rhn/manager/system/SystemManager.java +++ b/java/code/src/com/redhat/rhn/manager/system/SystemManager.java @@ -891,21 +891,11 @@ public class SystemManager extends BaseManager { public static Server lookupByIdAndUser(Long sid, User userIn) { Server server = ServerFactory.lookupByIdAndOrg(sid, userIn.getOrg()); - - if (!isAvailableToUser(userIn, sid)) { - LocalizationService ls = LocalizationService.getInstance(); - LookupException e = new LookupException("Could not find server " + sid + - " for user " + userIn.getId()); - e.setLocalizedTitle(ls.getMessage("lookup.jsp.title.system")); - e.setLocalizedReason1(ls.getMessage("lookup.jsp.reason1.system")); - e.setLocalizedReason2(ls.getMessage("lookup.jsp.reason2.system")); - throw e; - } - else { - return server; - } + ensureAvailableToUser(userIn, sid); + return server; }
+ /** * Returns a List of hydrated server objects from server ids. * @param serverIds the list of server ids to hyrdrate @@ -2063,6 +2053,23 @@ public class SystemManager extends BaseManager { params.put("sid", sid); return m.execute(params).size() >= 1; } + + /** + * Checks if the user has permissions to see the Server + * @param user User being checked + * @param sid ID of the Server being checked + */ + public static void ensureAvailableToUser(User user, Long sid) { + if (!isAvailableToUser(user, sid)) { + LocalizationService ls = LocalizationService.getInstance(); + LookupException e = new LookupException("Could not find server " + sid + + " for user " + user.getId()); + e.setLocalizedTitle(ls.getMessage("lookup.jsp.title.system")); + e.setLocalizedReason1(ls.getMessage("lookup.jsp.reason1.system")); + e.setLocalizedReason2(ls.getMessage("lookup.jsp.reason2.system")); + throw e; + } + }
/** * Return systems in the current set without a base channel. diff --git a/java/code/src/com/redhat/rhn/manager/system/VirtualizationEntitlementsManager.java b/java/code/src/com/redhat/rhn/manager/system/VirtualizationEntitlementsManager.java index be95619..4f10446 100644 --- a/java/code/src/com/redhat/rhn/manager/system/VirtualizationEntitlementsManager.java +++ b/java/code/src/com/redhat/rhn/manager/system/VirtualizationEntitlementsManager.java @@ -14,14 +14,21 @@ */ package com.redhat.rhn.manager.system;
+import com.redhat.rhn.common.db.datasource.CallableMode; +import com.redhat.rhn.common.db.datasource.ModeFactory; import com.redhat.rhn.domain.org.Org; import com.redhat.rhn.domain.server.ServerFactory; import com.redhat.rhn.domain.server.VirtualInstanceFactory; import com.redhat.rhn.domain.user.User; import com.redhat.rhn.frontend.dto.ChannelFamilySystemGroup;
+import org.apache.commons.lang.BooleanUtils; + +import java.sql.Types; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map;
/** @@ -100,7 +107,7 @@ public class VirtualizationEntitlementsManager { public List<ChannelFamilySystemGroup> listFlexGuests(User user) { return VirtualInstanceFactory.getInstance().listFlexGuests(user);
- } + }
/** @@ -111,6 +118,45 @@ public class VirtualizationEntitlementsManager { public List<ChannelFamilySystemGroup> listEligibleFlexGuests(User user) { return VirtualInstanceFactory.getInstance().listEligibleFlexGuests(user);
- } - + } + + /** + * Converts a given server to flex entitlement + * @param systemId the server id + * @param channelFamilyId the channel family id + * @param user the user object + */ + public void convertToFlex(Long systemId, + Long channelFamilyId, + User user) { + SystemManager.ensureAvailableToUser(user, systemId); + Map in = new HashMap(); + in.put("sid", systemId); + in.put("cfid", channelFamilyId); + CallableMode m = ModeFactory.getCallableMode( + "Channel_queries", "convert_to_flex"); + m.execute(in, new HashMap()); + } + + + /** + * True if the passed in server can be converted to flex + * @param sid the server id + * @param cfid the channel family id + * @return true if the server can be converted to flex + */ + public boolean canConvertToFlex(Long sid, Long cfid) { + Map in = new HashMap(); + in.put("sid", sid); + in.put("cfid", cfid); + Map outParams = new HashMap(); + outParams.put("result", new Integer(Types.NUMERIC)); + + CallableMode m = ModeFactory.getCallableMode( + "Channel_queries", "can_convert_to_flex"); + + Map result = m.execute(in, outParams); + return BooleanUtils.toBoolean( + ((Long)result.get("result")).intValue()); + } } diff --git a/java/code/webapp/WEB-INF/pages/systems/entitlements/flexguests.jsp b/java/code/webapp/WEB-INF/pages/systems/entitlements/flexguests.jsp index cfc2d18..88f7024 100644 --- a/java/code/webapp/WEB-INF/pages/systems/entitlements/flexguests.jsp +++ b/java/code/webapp/WEB-INF/pages/systems/entitlements/flexguests.jsp @@ -10,7 +10,7 @@ <c:set var="headerkey" value="eligible.flexguest.jsp.header"/> <c:set var="messagekey" value="eligible.flexguest.jsp.message"/> <c:set var="namestyle" value="first-column"/> - <c:set var="empty_msg" value="eligible-flexguest.jsp.no-systems"/> + <c:set var="empty_msg" value="eligible.flexguest.jsp.no-systems"/> </c:when> <c:otherwise> <c:set var="headerkey" value="flexguest.jsp.header"/> @@ -109,7 +109,7 @@ </rl:list> rhn:submitted/
-<c:if test="${not empty requestScope.selectable}"> +<c:if test="${not empty requestScope.selectable && not empty requestScope.dataset}"> <div align="right">
<hr /> diff --git a/java/code/webapp/WEB-INF/struts-config.xml b/java/code/webapp/WEB-INF/struts-config.xml index 2eaaaa9..205b830 100644 --- a/java/code/webapp/WEB-INF/struts-config.xml +++ b/java/code/webapp/WEB-INF/struts-config.xml @@ -6358,7 +6358,7 @@ className="com.redhat.rhn.frontend.struts.RhnActionMapping"> <set-property property="acls" value="user_role(org_admin)"/> <forward name="default" path="/WEB-INF/pages/systems/entitlements/flexguests.jsp"/> - <forward name="success" path="/systems/entitlements/FlexGuests.do" redirect="true"/> + <forward name="success" path="/systems/entitlements/EligibleFlexGuests.do" redirect="true"/> </action>
<action path="/channels/manage/errata/Add" @@ -6367,8 +6367,7 @@ type="com.redhat.rhn.frontend.action.channel.manage.AddErrataAction" className="com.redhat.rhn.frontend.struts.RhnActionMapping"> <forward name="default" path="/WEB-INF/pages/channel/manage/add.jsp" /> - - </action> + </action>
<action path="/channels/manage/errata/ListRemove" scope="request" diff --git a/schema/spacewalk/common/data/rhnException.sql b/schema/spacewalk/common/data/rhnException.sql index 8112644..fd10137 100644 --- a/schema/spacewalk/common/data/rhnException.sql +++ b/schema/spacewalk/common/data/rhnException.sql @@ -114,6 +114,11 @@ insert into rhnException values (-20292, 'package_provider_not_found', 'The spec insert into rhnException values (-20293, 'package_key_type_not_found', 'The specified package key type could not be found.'); insert into rhnException values (-20294, 'not_enough_flex_entitlements_in_base_org', 'You do not have enough entitlements in the base org.');
+insert into rhnException values (-20295, 'server_cannot_convert_to_flex', 'The given server cannot be converted to a flex entitlement.'); + +insert into rhnException values (-20296, 'not_enough_flex_entitlements', 'You do not have enough entitlements in your org..'); + + commit;
-- diff --git a/schema/spacewalk/oracle/packages/rhn_channel.pkb b/schema/spacewalk/oracle/packages/rhn_channel.pkb index 84832fa..ef0b66a 100644 --- a/schema/spacewalk/oracle/packages/rhn_channel.pkb +++ b/schema/spacewalk/oracle/packages/rhn_channel.pkb @@ -227,6 +227,96 @@ IS END IF;
END subscribe_server; + + + + FUNCTION can_convert_to_fve(server_id_in IN NUMBER, channel_family_id_val IN NUMBER) + RETURN NUMBER + IS + CURSOR fve_convertible_entries IS + select 1 from + RhnVirtualInstance vi + inner join rhnServer s on vi.virtual_system_id = s.id + inner join rhnServerChannel sc on sc.server_id = s.id + inner join rhnChannelFamilyMembers cfm on cfm.channel_id = sc.channel_id + inner join rhnChannelFamily cf on cf.id = cfm.channel_family_id + inner join rhnPrivateChannelFamily pcf on pcf.channel_family_id = cf.id and pcf.org_id = s.org_id + where sc.is_fve = 'N' + AND sc.server_id = server_id_in + AND cf.id = channel_family_id_val + AND (vi.host_system_id is null OR + exists ( + select sg.id 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.org_id = s.org_id + and s2.id = vi.host_system_id + and sgt.label not in ('virtualization_host' ,'virtualization_host_platform') ) + ); + + BEGIN + FOR entry IN fve_convertible_entries LOOP + return 1; + END LOOP; + RETURN 0; + END can_convert_to_fve; + + + -- Converts server channel_family to use a flex entitlement + PROCEDURE convert_to_fve(server_id_in IN NUMBER, channel_family_id_val IN NUMBER) + IS + available_fve_subs NUMBER; + server_org_id_val NUMBER; + BEGIN + + -- + -- Use the org_id of the server only if the org_id of the channel = NULL. + -- This is required for subscribing to shared channels. + -- + SELECT org_id + INTO server_org_id_val + FROM rhnServer + WHERE id = server_id_in; + + begin + obtain_read_lock(channel_family_id_val, server_org_id_val); + exception + when no_data_found then + rhn_exception.raise_exception('channel_family_no_subscriptions'); + end; + IF (can_convert_to_fve(server_id_in, channel_family_id_val ) = 0) + THEN + rhn_exception.raise_exception('server_cannot_convert_to_flex'); + END IF; + + available_fve_subs := rhn_channel.available_fve_family_subs(channel_family_id_val, server_org_id_val); + + IF (available_fve_subs > 0) + THEN + + insert into rhnServerHistory (id,server_id,summary,details) ( + select rhn_event_id_seq.nextval, + server_id_in, + 'converted to flex entitlement' || SUBSTR(cf.label, 0, 99), + cf.label + from rhnChannelFamily cf + where cf.id = channel_family_id_val + ); + + UPDATE rhnServerChannel sc set sc.is_fve = 'Y' + where sc.server_id = server_id_in and + sc.channel_id in + (select cfm.channel_id from rhnChannelFamilyMembers cfm + where cfm.CHANNEL_FAMILY_ID = channel_family_id_val); + + rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val); + ELSE + rhn_exception.raise_exception('not_enough_flex_entitlements'); + END IF; + + END convert_to_fve;
function can_server_consume_virt_channl( server_id_in in number, diff --git a/schema/spacewalk/oracle/packages/rhn_channel.pks b/schema/spacewalk/oracle/packages/rhn_channel.pks index 05ba2ff..b21dcf8 100644 --- a/schema/spacewalk/oracle/packages/rhn_channel.pks +++ b/schema/spacewalk/oracle/packages/rhn_channel.pks @@ -54,6 +54,10 @@ IS deleting_server in number := 0, update_family_countsYN IN NUMBER := 1); PROCEDURE subscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, user_id_in number := null, recalcfamily_in number := 1); + + PROCEDURE convert_to_fve(server_id_in IN NUMBER, channel_family_id_val IN NUMBER); + + FUNCTION can_convert_to_fve(server_id_in IN NUMBER, channel_family_id_val IN NUMBER) RETURN NUMBER; function can_server_consume_virt_channl( server_id_in IN NUMBER, diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.0-to-spacewalk-schema-1.1/012-rhnException_data.sql b/schema/spacewalk/upgrade/spacewalk-schema-1.0-to-spacewalk-schema-1.1/012-rhnException_data.sql index 9d8e856..4e274a3 100644 --- a/schema/spacewalk/upgrade/spacewalk-schema-1.0-to-spacewalk-schema-1.1/012-rhnException_data.sql +++ b/schema/spacewalk/upgrade/spacewalk-schema-1.0-to-spacewalk-schema-1.1/012-rhnException_data.sql @@ -18,7 +18,9 @@ -- data for rhnException
insert into rhnException values (-20294, 'not_enough_flex_entitlements_in_base_org', 'You do not have enough entitlements in the base org.'); +insert into rhnException values (-20295, 'server_cannot_convert_to_flex', 'The given server cannot be converted to a flex entitlement.');
+insert into rhnException values (-20296, 'not_enough_flex_entitlements', 'You do not have enough entitlements in your org..'); commit;
spacewalk-commits@lists.fedorahosted.org