Changes to 'refs/tags/spacewalk-java-2.0.4-1'
by Grant Gainey
Tag 'spacewalk-java-2.0.4-1' created by Grant Gainey <ggainey(a)redhat.com> at 2013-07-26 13:59 +0000
Tagging package [spacewalk-java] version [2.0.4-1] in directory [java/].
Changes since spacewalk-java-2.0.3-1:
Grant Gainey (3):
987977 - Fix chaining of pkg-scheduling in SSM
987977 - Fix there-can-be-solaris issue and make Upgrade behave like everything else
Automatic commit of package [spacewalk-java] release [2.0.4-1].
---
java/code/src/com/redhat/rhn/common/db/datasource/xml/Action_queries.xml | 15 -
java/code/src/com/redhat/rhn/domain/action/script/ScriptAction.java | 4
java/code/src/com/redhat/rhn/frontend/action/schedule/PendingActionsDeleteConfirmAction.java | 40 +--
java/code/src/com/redhat/rhn/frontend/events/SsmInstallPackagesAction.java | 17 -
java/code/src/com/redhat/rhn/frontend/events/SsmPackagesAction.java | 90 ++++---
java/code/src/com/redhat/rhn/frontend/events/SsmUpgradePackagesAction.java | 10
java/code/src/com/redhat/rhn/frontend/taglibs/list/SelectableColumnTag.java | 23 ++
java/code/src/com/redhat/rhn/frontend/taglibs/rhn-list.tld | 113 +++++-----
java/code/webapp/WEB-INF/pages/common/fragments/scheduledactions/listdisplay-new.jspf | 28 +-
java/spacewalk-java.spec | 7
rel-eng/packages/spacewalk-java | 2
11 files changed, 198 insertions(+), 151 deletions(-)
---
10 years, 2 months
Branch 'SPACEWALK-2.0' - 3 commits - java/code java/spacewalk-java.spec rel-eng/packages
by Grant Gainey
java/code/src/com/redhat/rhn/common/db/datasource/xml/Action_queries.xml | 15 -
java/code/src/com/redhat/rhn/domain/action/script/ScriptAction.java | 4
java/code/src/com/redhat/rhn/frontend/action/schedule/PendingActionsDeleteConfirmAction.java | 40 +--
java/code/src/com/redhat/rhn/frontend/events/SsmInstallPackagesAction.java | 17 -
java/code/src/com/redhat/rhn/frontend/events/SsmPackagesAction.java | 90 ++++---
java/code/src/com/redhat/rhn/frontend/events/SsmUpgradePackagesAction.java | 10
java/code/src/com/redhat/rhn/frontend/taglibs/list/SelectableColumnTag.java | 23 ++
java/code/src/com/redhat/rhn/frontend/taglibs/rhn-list.tld | 113 +++++-----
java/code/webapp/WEB-INF/pages/common/fragments/scheduledactions/listdisplay-new.jspf | 28 +-
java/spacewalk-java.spec | 7
rel-eng/packages/spacewalk-java | 2
11 files changed, 198 insertions(+), 151 deletions(-)
New commits:
commit e0621785f7246afe006f3bf9a4462b3d407a4e93
Author: Grant Gainey <ggainey(a)redhat.com>
Date: Fri Jul 26 09:59:35 2013 -0400
Automatic commit of package [spacewalk-java] release [2.0.4-1].
diff --git a/java/spacewalk-java.spec b/java/spacewalk-java.spec
index 1963d16..109129b 100644
--- a/java/spacewalk-java.spec
+++ b/java/spacewalk-java.spec
@@ -28,7 +28,7 @@ Name: spacewalk-java
Summary: Spacewalk Java site packages
Group: Applications/Internet
License: GPLv2
-Version: 2.0.3
+Version: 2.0.4
Release: 1%{?dist}
URL: https://fedorahosted.org/spacewalk
Source0: https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar.gz
@@ -771,6 +771,11 @@ fi
%{jardir}/postgresql-jdbc.jar
%changelog
+* Fri Jul 26 2013 Grant Gainey <ggainey(a)redhat.com> 2.0.4-1
+- 987977 - Fix there-can-be-solaris issue and make Upgrade behave like
+ everything else
+- 987977 - Fix chaining of pkg-scheduling in SSM
+
* Fri Jul 26 2013 Tomas Kasparek <tkasparek(a)redhat.com> 2.0.3-1
- ISS: Return LookupException to getDefaultMaster() if there isn't one
- 986527 - removing extra semicolon
diff --git a/rel-eng/packages/spacewalk-java b/rel-eng/packages/spacewalk-java
index 06c6d1e..fc23e6e 100644
--- a/rel-eng/packages/spacewalk-java
+++ b/rel-eng/packages/spacewalk-java
@@ -1 +1 @@
-2.0.3-1 java/
+2.0.4-1 java/
commit c1527c5ff6d774e54d6a6c9cc904bd5ea2559906
Author: Grant Gainey <ggainey(a)redhat.com>
Date: Thu Jul 25 16:09:21 2013 -0400
987977 - Fix there-can-be-solaris issue and make Upgrade behave like everything else
diff --git a/java/code/src/com/redhat/rhn/frontend/events/SsmInstallPackagesAction.java b/java/code/src/com/redhat/rhn/frontend/events/SsmInstallPackagesAction.java
index 1369b99..afa4b68 100644
--- a/java/code/src/com/redhat/rhn/frontend/events/SsmInstallPackagesAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/events/SsmInstallPackagesAction.java
@@ -22,7 +22,6 @@ import java.util.Map;
import java.util.Set;
import com.redhat.rhn.domain.action.Action;
-import com.redhat.rhn.domain.server.Server;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.frontend.action.SetLabels;
import com.redhat.rhn.frontend.dto.EssentialServerDto;
@@ -75,24 +74,4 @@ public class SsmInstallPackagesAction extends SsmPackagesAction {
return pkgActions;
}
- protected Action doSchedule(SsmPackageEvent event, User user, Server s, Date earliest) {
- SsmInstallPackagesEvent sipe = (SsmInstallPackagesEvent) event;
-
- Set<String> data = sipe.getPackages();
- // Convert the package list to domain objects
- List<PackageListItem> pkgListItems = new ArrayList<PackageListItem>(data.size());
- for (String key : data) {
- pkgListItems.add(PackageListItem.parse(key));
- }
-
- // Convert to list of maps
- List<Map<String, Long>> packageListData = PackageListItem
- .toKeyMaps(pkgListItems);
-
- Action pkgAction = ActionManager.schedulePackageInstall(user, s,
- packageListData, earliest);
-
- return pkgAction;
- }
-
}
diff --git a/java/code/src/com/redhat/rhn/frontend/events/SsmPackagesAction.java b/java/code/src/com/redhat/rhn/frontend/events/SsmPackagesAction.java
index 70fc767..dc24937 100644
--- a/java/code/src/com/redhat/rhn/frontend/events/SsmPackagesAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/events/SsmPackagesAction.java
@@ -14,7 +14,6 @@
*/
package com.redhat.rhn.frontend.events;
-import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -25,7 +24,6 @@ import com.redhat.rhn.common.messaging.EventMessage;
import com.redhat.rhn.domain.action.Action;
import com.redhat.rhn.domain.action.script.ScriptActionDetails;
import com.redhat.rhn.domain.action.script.ScriptRunAction;
-import com.redhat.rhn.domain.server.Server;
import com.redhat.rhn.domain.server.ServerFactory;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.domain.user.UserFactory;
@@ -107,54 +105,65 @@ public abstract class SsmPackagesAction extends AbstractDatabaseAction {
log.debug("Scheduling package actions.");
Date earliest = event.getEarliest();
- List<Long> serverIds = getAffectedServers(event, user);
+ List<Long> sids = getAffectedServers(event, user);
+
log.debug("Scheduling actions.");
- // If we have a remote-cmd, have to correctly order it and the package action(s)
+ // If we have a remote-cmd, have to correctly order it and the package
+ // action(s)
if (event.getScriptDetails() != null) {
- for (Long sid : serverIds) {
- Server s = ServerFactory.lookupById(sid);
- List<Long> sidList = new ArrayList<Long>();
- sidList.add(sid);
- ScriptActionDetails sad = event.getScriptDetails();
- if (event.isBefore()) {
- log.debug("Scheduling remote-action BEFORE.");
-
- ScriptRunAction sra = ActionManager.scheduleScriptRun(user, sidList,
- null, sad, earliest);
- ActionManager.storeAction(sra);
+ // It's possible to have non-linux servers in the list, and different Actions
+ // are created for them. Get the separate lists
+ List<Long> rhelIds = ServerFactory.listLinuxSystems(sids);
+ List<Long> solarisIds = ServerFactory.listSolarisSystems(sids);
- Action pkgAction = doSchedule(event, user, s, earliest);
+ ScriptActionDetails sad = event.getScriptDetails();
+ List<Action> pkgActions = doSchedule(event, user, sids, earliest);
+ for (Action a : pkgActions) {
- Action prevAction = sra;
- pkgAction.setPrerequisite(prevAction);
- ActionManager.storeAction(pkgAction);
- prevAction = pkgAction;
+ if (event.isBefore()) {
+ log.debug("Scheduling remote-action BEFORE.");
+ if (!rhelIds.isEmpty()) {
+ ScriptRunAction sra = ActionManager.scheduleScriptRun(user,
+ rhelIds, null, sad, earliest);
+ ActionManager.storeAction(sra);
+ a.setPrerequisite(sra);
+ ActionManager.storeAction(a);
+ }
+
+ if (!solarisIds.isEmpty()) {
+ ScriptRunAction sra = ActionManager.scheduleScriptRun(user,
+ solarisIds, null, sad, earliest);
+ ActionManager.storeAction(sra);
+ a.setPrerequisite(sra);
+ ActionManager.storeAction(a);
+ }
}
else {
log.debug("Scheduling remote-action AFTER.");
- Action pkgAction = doSchedule(event, user, s, earliest);
- ScriptRunAction sra = ActionManager.scheduleScriptRun(user, sidList,
- null, sad, earliest);
-
- // Might be more than one action from schedPkgActions
- Action prevAction = null;
- if (prevAction != null) {
- pkgAction.setPrerequisite(prevAction);
- }
- ActionManager.storeAction(pkgAction);
- prevAction = pkgAction;
-
- sra.setPrerequisite(prevAction);
- ActionManager.storeAction(sra);
+ if (!rhelIds.isEmpty()) {
+ ScriptRunAction sra = ActionManager.scheduleScriptRun(user,
+ rhelIds, null, sad, earliest);
+ ActionManager.storeAction(a);
+ sra.setPrerequisite(a);
+ ActionManager.storeAction(sra);
+ }
+
+ if (!solarisIds.isEmpty()) {
+ ScriptRunAction sra = ActionManager.scheduleScriptRun(user,
+ solarisIds, null, sad, earliest);
+ ActionManager.storeAction(a);
+ sra.setPrerequisite(a);
+ ActionManager.storeAction(sra);
+ }
}
}
}
else { // No remote-script to schedule
- doSchedule(event, user, serverIds, earliest);
+ doSchedule(event, user, sids, earliest);
}
log.debug("Done scheduling package actions.");
@@ -164,10 +173,6 @@ public abstract class SsmPackagesAction extends AbstractDatabaseAction {
protected abstract List<Long> getAffectedServers(SsmPackageEvent event, User u);
- protected abstract Action doSchedule(SsmPackageEvent event,
- User user,
- Server s,
- Date earliest);
protected abstract List<Action> doSchedule(SsmPackageEvent event,
User user,
diff --git a/java/code/src/com/redhat/rhn/frontend/events/SsmRemovePackagesAction.java b/java/code/src/com/redhat/rhn/frontend/events/SsmRemovePackagesAction.java
index dcfdf92..c17526e 100644
--- a/java/code/src/com/redhat/rhn/frontend/events/SsmRemovePackagesAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/events/SsmRemovePackagesAction.java
@@ -24,7 +24,6 @@ import java.util.Set;
import org.apache.log4j.Logger;
import com.redhat.rhn.domain.action.Action;
-import com.redhat.rhn.domain.server.Server;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.frontend.dto.PackageListItem;
import com.redhat.rhn.manager.action.ActionManager;
@@ -117,36 +116,4 @@ public class SsmRemovePackagesAction extends SsmPackagesAction {
return actions;
}
- protected Action doSchedule(SsmPackageEvent event, User user, Server s, Date earliest) {
-
- SsmRemovePackagesEvent srpe = (SsmRemovePackagesEvent) event;
-
- List<Map> result = srpe.getResult();
-
- Set<PackageListItem> allPackages = new HashSet<PackageListItem>();
-
- for (Map data : result) {
-
- // Get the packages out of the elaborator
- List<Map> elabList = (List<Map>) data.get("elaborator0");
- if (elabList != null) {
- for (Map elabMap : elabList) {
- String idCombo = (String) elabMap.get("id_combo");
- PackageListItem item = PackageListItem.parse(idCombo);
- allPackages.add(item);
- }
- }
- }
-
- List<PackageListItem> allPackagesList = new ArrayList<PackageListItem>(allPackages);
- List<Map<String, Long>> packageListData = PackageListItem
- .toKeyMaps(allPackagesList);
-
- Action action = ActionManager.schedulePackageRemoval(user, s,
- packageListData, earliest);
-
- return action;
- }
-
-
}
diff --git a/java/code/src/com/redhat/rhn/frontend/events/SsmUpgradePackagesAction.java b/java/code/src/com/redhat/rhn/frontend/events/SsmUpgradePackagesAction.java
index 84b9491..36cbde5 100644
--- a/java/code/src/com/redhat/rhn/frontend/events/SsmUpgradePackagesAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/events/SsmUpgradePackagesAction.java
@@ -20,7 +20,6 @@ import java.util.List;
import java.util.Map;
import com.redhat.rhn.domain.action.Action;
-import com.redhat.rhn.domain.server.Server;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.manager.action.ActionManager;
@@ -49,16 +48,15 @@ public class SsmUpgradePackagesAction extends SsmPackagesAction {
SsmUpgradePackagesEvent supe = (SsmUpgradePackagesEvent) event;
Map<Long, List<Map<String, Long>>> packageListItems = supe.getSysPackageSet();
+ List<Map<String, Long>> pkgs = new ArrayList<Map<String, Long>>();
+ for (List<Map<String, Long>> pkgList : packageListItems.values()) {
+ for (Map<String, Long> pkg : pkgList) {
+ pkgs.add(pkg);
+ }
+ }
- return ActionManager.schedulePackageUpgrades(user, packageListItems, earliest);
+ return ActionManager.schedulePackageInstall(user, sids, pkgs, earliest);
}
- protected Action doSchedule(SsmPackageEvent event, User user, Server s, Date earliest) {
-
- SsmUpgradePackagesEvent supe = (SsmUpgradePackagesEvent) event;
- List<Map<String, Long>> packageListItems = supe.getSysPackageSet().get(s.getId());
-
- return ActionManager.schedulePackageUpgrade(user, s, packageListItems, earliest);
- }
}
commit 5ad0427f73f8a5b44af489ef7cb236555e4770a0
Author: Grant Gainey <ggainey(a)redhat.com>
Date: Wed Jul 24 11:24:55 2013 -0400
987977 - Fix chaining of pkg-scheduling in SSM
diff --git a/java/code/src/com/redhat/rhn/common/db/datasource/xml/Action_queries.xml b/java/code/src/com/redhat/rhn/common/db/datasource/xml/Action_queries.xml
index 2372097..4c51e03 100644
--- a/java/code/src/com/redhat/rhn/common/db/datasource/xml/Action_queries.xml
+++ b/java/code/src/com/redhat/rhn/common/db/datasource/xml/Action_queries.xml
@@ -19,7 +19,7 @@ SELECT EVENT_ID as ID,
NULL AS history_status,
NULL AS history_type,
NULL AS history_type_name,
- SH.details
+ SH.details
FROM rhnServerHistory SH
WHERE SH.server_id = :sid
UNION
@@ -31,7 +31,7 @@ SELECT EVENT_ID as ID,
AStat.name AS history_status,
AType.label AS history_type,
AType.name AS history_type_name,
- NULL AS details
+ NULL AS details
FROM rhnActionType AType,
rhnActionStatus AStat,
rhnAction A
@@ -94,6 +94,7 @@ order by id desc
<query params="user_id, org_id">
SELECT DISTINCT UAO.id AS ID,
UAO.earliest_action AS EARLIEST,
+ A.prerequisite AS PREREQUISITE,
UAO.type_name,
(CASE UAO.action_name WHEN NULL THEN UAO.type_name ELSE UAO.action_name END) AS ACTION_NAME,
UAO.scheduler,
@@ -102,11 +103,13 @@ SELECT DISTINCT UAO.id AS ID,
(SELECT COUNT(server_id) FROM rhnServerAction WHERE action_id = UAO.id AND status = 2) AS "COMPLETED_SYSTEMS",
(SELECT COUNT(server_id) FROM rhnServerAction WHERE action_id = UAO.id AND status = 3) AS "FAILED_SYSTEMS"
FROM rhnUserActionOverview UAO left join
- web_contact WC on UAO.scheduler = WC.id
+ web_contact WC on UAO.scheduler = WC.id,
+ rhnAction A
WHERE UAO.org_id = :org_id
AND UAO.user_id = :user_id
AND UAO.action_status_id IN (0,1)
AND UAO.archived = 0
+ AND UAO.id = A.id
ORDER BY EARLIEST DESC
</query>
<elaborator name="action_overview_elab" />
@@ -297,9 +300,9 @@ SELECT 1
<query params="parent_id, status_id, tries">
INSERT INTO rhnServerAction (server_id, action_id, status, REMAINING_TRIES)
select s.id as server_id, :parent_id as action_id,
- :status_id as status, :tries as REMAINING_TRIES
- from rhnServer s
- where s.id in (%s)
+ :status_id as status, :tries as REMAINING_TRIES
+ from rhnServer s
+ where s.id in (%s)
</query>
</write-mode>
<write-mode name="add_config_rev_to_action">
diff --git a/java/code/src/com/redhat/rhn/domain/action/script/ScriptAction.java b/java/code/src/com/redhat/rhn/domain/action/script/ScriptAction.java
index 071a5eb..a0e453f 100644
--- a/java/code/src/com/redhat/rhn/domain/action/script/ScriptAction.java
+++ b/java/code/src/com/redhat/rhn/domain/action/script/ScriptAction.java
@@ -35,7 +35,9 @@ public class ScriptAction extends Action {
* @param scriptActionDetailsIn The scriptActionDetails to set.
*/
public void setScriptActionDetails(ScriptActionDetails scriptActionDetailsIn) {
- scriptActionDetailsIn.setParentAction(this);
+ if (scriptActionDetailsIn != null) {
+ scriptActionDetailsIn.setParentAction(this);
+ }
scriptActionDetails = scriptActionDetailsIn;
}
diff --git a/java/code/src/com/redhat/rhn/frontend/action/schedule/PendingActionsDeleteConfirmAction.java b/java/code/src/com/redhat/rhn/frontend/action/schedule/PendingActionsDeleteConfirmAction.java
index 653f856..5547a5b 100644
--- a/java/code/src/com/redhat/rhn/frontend/action/schedule/PendingActionsDeleteConfirmAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/action/schedule/PendingActionsDeleteConfirmAction.java
@@ -14,7 +14,21 @@
*/
package com.redhat.rhn.frontend.action.schedule;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+
import com.redhat.rhn.common.localization.LocalizationService;
+import com.redhat.rhn.domain.action.Action;
+import com.redhat.rhn.domain.action.ActionFactory;
import com.redhat.rhn.domain.rhnset.RhnSet;
import com.redhat.rhn.domain.rhnset.RhnSetElement;
import com.redhat.rhn.domain.user.User;
@@ -28,18 +42,6 @@ import com.redhat.rhn.manager.action.ActionManager;
import com.redhat.rhn.manager.rhnset.RhnSetDecl;
import com.redhat.rhn.manager.rhnset.RhnSetManager;
-import org.apache.struts.action.ActionForm;
-import org.apache.struts.action.ActionForward;
-import org.apache.struts.action.ActionMapping;
-import org.apache.struts.action.ActionMessage;
-import org.apache.struts.action.ActionMessages;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
/**
* PendingActionsConfirmAction
* @version $Rev: 101893 $
@@ -65,9 +67,6 @@ public class PendingActionsDeleteConfirmAction extends RhnAction implements List
return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
}
-
-
-
/**
* {@inheritDoc}
*/
@@ -84,7 +83,6 @@ public class PendingActionsDeleteConfirmAction extends RhnAction implements List
getSetDecl().getLabel());
}
-
private ActionForward cancelActions(ActionMapping mapping, HttpServletRequest request) {
RequestContext requestContext = new RequestContext(request);
StrutsDelegate strutsDelegate = getStrutsDelegate();
@@ -93,14 +91,12 @@ public class PendingActionsDeleteConfirmAction extends RhnAction implements List
RhnSet set = getSetDecl().get(user);
- List actionsToCancel = new LinkedList();
+ List<Action> actionsToCancel = new LinkedList();
for (RhnSetElement element : set.getElements()) {
- actionsToCancel.add(element.getElement());
+ actionsToCancel.add(ActionFactory.lookupById(element.getElement()));
}
-
- ActionManager.removeActions(actionsToCancel);
-
+ ActionManager.cancelActions(user, actionsToCancel);
ActionMessages msgs = new ActionMessages();
// If there was only one action cancelled, display the "action" cancelled
@@ -122,8 +118,6 @@ public class PendingActionsDeleteConfirmAction extends RhnAction implements List
set.clear();
RhnSetManager.store(set);
-
return mapping.findForward("success");
-
}
}
diff --git a/java/code/src/com/redhat/rhn/frontend/events/SsmInstallPackagesAction.java b/java/code/src/com/redhat/rhn/frontend/events/SsmInstallPackagesAction.java
index 8f7ba0a..1369b99 100644
--- a/java/code/src/com/redhat/rhn/frontend/events/SsmInstallPackagesAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/events/SsmInstallPackagesAction.java
@@ -22,6 +22,7 @@ import java.util.Map;
import java.util.Set;
import com.redhat.rhn.domain.action.Action;
+import com.redhat.rhn.domain.server.Server;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.frontend.action.SetLabels;
import com.redhat.rhn.frontend.dto.EssentialServerDto;
@@ -43,7 +44,7 @@ public class SsmInstallPackagesAction extends SsmPackagesAction {
Long channelId = sipe.getChannelId();
List<EssentialServerDto> servers = SystemManager.systemsSubscribedToChannelInSet(
- channelId, u, SetLabels.SYSTEM_LIST);
+ channelId, u, SetLabels.SYSTEM_LIST);
// Create one action for all servers to which the packages are installed
List<Long> serverIds = new LinkedList<Long>();
@@ -53,28 +54,45 @@ public class SsmInstallPackagesAction extends SsmPackagesAction {
return serverIds;
}
- protected List<Action> doSchedule(SsmPackageEvent event,
- User user,
- List<Long> sids,
- Date earliest) {
+ protected List<Action> doSchedule(SsmPackageEvent event, User user, List<Long> sids,
+ Date earliest) {
SsmInstallPackagesEvent sipe = (SsmInstallPackagesEvent) event;
Set<String> data = sipe.getPackages();
// Convert the package list to domain objects
- List<PackageListItem> packageListItems =
- new ArrayList<PackageListItem>(data.size());
+ List<PackageListItem> pkgListItems = new ArrayList<PackageListItem>(data.size());
for (String key : data) {
- packageListItems.add(PackageListItem.parse(key));
+ pkgListItems.add(PackageListItem.parse(key));
}
// Convert to list of maps
List<Map<String, Long>> packageListData = PackageListItem
- .toKeyMaps(packageListItems);
+ .toKeyMaps(pkgListItems);
List<Action> pkgActions = ActionManager.schedulePackageInstall(user, sids,
- packageListData, earliest);
+ packageListData, earliest);
return pkgActions;
}
+ protected Action doSchedule(SsmPackageEvent event, User user, Server s, Date earliest) {
+ SsmInstallPackagesEvent sipe = (SsmInstallPackagesEvent) event;
+
+ Set<String> data = sipe.getPackages();
+ // Convert the package list to domain objects
+ List<PackageListItem> pkgListItems = new ArrayList<PackageListItem>(data.size());
+ for (String key : data) {
+ pkgListItems.add(PackageListItem.parse(key));
+ }
+
+ // Convert to list of maps
+ List<Map<String, Long>> packageListData = PackageListItem
+ .toKeyMaps(pkgListItems);
+
+ Action pkgAction = ActionManager.schedulePackageInstall(user, s,
+ packageListData, earliest);
+
+ return pkgAction;
+ }
+
}
diff --git a/java/code/src/com/redhat/rhn/frontend/events/SsmPackagesAction.java b/java/code/src/com/redhat/rhn/frontend/events/SsmPackagesAction.java
index 7bb4fa9..70fc767 100644
--- a/java/code/src/com/redhat/rhn/frontend/events/SsmPackagesAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/events/SsmPackagesAction.java
@@ -14,6 +14,7 @@
*/
package com.redhat.rhn.frontend.events;
+import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -24,6 +25,8 @@ import com.redhat.rhn.common.messaging.EventMessage;
import com.redhat.rhn.domain.action.Action;
import com.redhat.rhn.domain.action.script.ScriptActionDetails;
import com.redhat.rhn.domain.action.script.ScriptRunAction;
+import com.redhat.rhn.domain.server.Server;
+import com.redhat.rhn.domain.server.ServerFactory;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.domain.user.UserFactory;
import com.redhat.rhn.manager.action.ActionManager;
@@ -107,46 +110,47 @@ public abstract class SsmPackagesAction extends AbstractDatabaseAction {
List<Long> serverIds = getAffectedServers(event, user);
log.debug("Scheduling actions.");
+
// If we have a remote-cmd, have to correctly order it and the package action(s)
if (event.getScriptDetails() != null) {
- ScriptActionDetails sad = event.getScriptDetails();
- if (event.isBefore()) {
- log.debug("Scheduling remote-action BEFORE.");
-
- ScriptRunAction sra = ActionManager.scheduleScriptRun(user, serverIds,
- null, sad, earliest);
- ActionManager.storeAction(sra);
-
- List<Action> pkgActions = doSchedule(event, user, serverIds, earliest);
-
- // Might be more than one action from schedPkgActions
- Action prevAction = sra;
- for (Action a : pkgActions) {
- a.setPrerequisite(prevAction);
- ActionManager.storeAction(a);
- prevAction = a;
- }
+ for (Long sid : serverIds) {
+ Server s = ServerFactory.lookupById(sid);
+ List<Long> sidList = new ArrayList<Long>();
+ sidList.add(sid);
+ ScriptActionDetails sad = event.getScriptDetails();
+ if (event.isBefore()) {
+ log.debug("Scheduling remote-action BEFORE.");
- }
- else {
- log.debug("Scheduling remote-action AFTER.");
-
- List<Action> pkgActions = doSchedule(event, user, serverIds, earliest);
- ScriptRunAction sra = ActionManager.scheduleScriptRun(user, serverIds,
- null, sad, earliest);
-
- // Might be more than one action from schedPkgActions
- Action prevAction = null;
- for (Action a : pkgActions) {
- if (prevAction != null) {
- a.setPrerequisite(prevAction);
- }
- ActionManager.storeAction(a);
- prevAction = a;
- }
+ ScriptRunAction sra = ActionManager.scheduleScriptRun(user, sidList,
+ null, sad, earliest);
+ ActionManager.storeAction(sra);
+
+ Action pkgAction = doSchedule(event, user, s, earliest);
+
+ Action prevAction = sra;
+ pkgAction.setPrerequisite(prevAction);
+ ActionManager.storeAction(pkgAction);
+ prevAction = pkgAction;
- sra.setPrerequisite(prevAction);
- ActionManager.storeAction(sra);
+ }
+ else {
+ log.debug("Scheduling remote-action AFTER.");
+
+ Action pkgAction = doSchedule(event, user, s, earliest);
+ ScriptRunAction sra = ActionManager.scheduleScriptRun(user, sidList,
+ null, sad, earliest);
+
+ // Might be more than one action from schedPkgActions
+ Action prevAction = null;
+ if (prevAction != null) {
+ pkgAction.setPrerequisite(prevAction);
+ }
+ ActionManager.storeAction(pkgAction);
+ prevAction = pkgAction;
+
+ sra.setPrerequisite(prevAction);
+ ActionManager.storeAction(sra);
+ }
}
}
else { // No remote-script to schedule
@@ -160,9 +164,14 @@ public abstract class SsmPackagesAction extends AbstractDatabaseAction {
protected abstract List<Long> getAffectedServers(SsmPackageEvent event, User u);
- protected abstract List<Action> doSchedule(SsmPackageEvent event,
+ protected abstract Action doSchedule(SsmPackageEvent event,
User user,
- List<Long> sids,
+ Server s,
Date earliest);
+ protected abstract List<Action> doSchedule(SsmPackageEvent event,
+ User user,
+ List<Long> sid,
+ Date earliest);
+
}
diff --git a/java/code/src/com/redhat/rhn/frontend/events/SsmRemovePackagesAction.java b/java/code/src/com/redhat/rhn/frontend/events/SsmRemovePackagesAction.java
index c17526e..dcfdf92 100644
--- a/java/code/src/com/redhat/rhn/frontend/events/SsmRemovePackagesAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/events/SsmRemovePackagesAction.java
@@ -24,6 +24,7 @@ import java.util.Set;
import org.apache.log4j.Logger;
import com.redhat.rhn.domain.action.Action;
+import com.redhat.rhn.domain.server.Server;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.frontend.dto.PackageListItem;
import com.redhat.rhn.manager.action.ActionManager;
@@ -116,4 +117,36 @@ public class SsmRemovePackagesAction extends SsmPackagesAction {
return actions;
}
+ protected Action doSchedule(SsmPackageEvent event, User user, Server s, Date earliest) {
+
+ SsmRemovePackagesEvent srpe = (SsmRemovePackagesEvent) event;
+
+ List<Map> result = srpe.getResult();
+
+ Set<PackageListItem> allPackages = new HashSet<PackageListItem>();
+
+ for (Map data : result) {
+
+ // Get the packages out of the elaborator
+ List<Map> elabList = (List<Map>) data.get("elaborator0");
+ if (elabList != null) {
+ for (Map elabMap : elabList) {
+ String idCombo = (String) elabMap.get("id_combo");
+ PackageListItem item = PackageListItem.parse(idCombo);
+ allPackages.add(item);
+ }
+ }
+ }
+
+ List<PackageListItem> allPackagesList = new ArrayList<PackageListItem>(allPackages);
+ List<Map<String, Long>> packageListData = PackageListItem
+ .toKeyMaps(allPackagesList);
+
+ Action action = ActionManager.schedulePackageRemoval(user, s,
+ packageListData, earliest);
+
+ return action;
+ }
+
+
}
diff --git a/java/code/src/com/redhat/rhn/frontend/events/SsmUpgradePackagesAction.java b/java/code/src/com/redhat/rhn/frontend/events/SsmUpgradePackagesAction.java
index 5620c22..84b9491 100644
--- a/java/code/src/com/redhat/rhn/frontend/events/SsmUpgradePackagesAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/events/SsmUpgradePackagesAction.java
@@ -20,6 +20,7 @@ import java.util.List;
import java.util.Map;
import com.redhat.rhn.domain.action.Action;
+import com.redhat.rhn.domain.server.Server;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.manager.action.ActionManager;
@@ -53,4 +54,11 @@ public class SsmUpgradePackagesAction extends SsmPackagesAction {
}
+ protected Action doSchedule(SsmPackageEvent event, User user, Server s, Date earliest) {
+
+ SsmUpgradePackagesEvent supe = (SsmUpgradePackagesEvent) event;
+ List<Map<String, Long>> packageListItems = supe.getSysPackageSet().get(s.getId());
+
+ return ActionManager.schedulePackageUpgrade(user, s, packageListItems, earliest);
+ }
}
diff --git a/java/code/src/com/redhat/rhn/frontend/taglibs/list/SelectableColumnTag.java b/java/code/src/com/redhat/rhn/frontend/taglibs/list/SelectableColumnTag.java
index abfe836..cd0d989 100644
--- a/java/code/src/com/redhat/rhn/frontend/taglibs/list/SelectableColumnTag.java
+++ b/java/code/src/com/redhat/rhn/frontend/taglibs/list/SelectableColumnTag.java
@@ -53,6 +53,7 @@ public class SelectableColumnTag extends TagSupport {
private String headerKey;
private String listName;
private String rhnSet;
+ private String hideDisabled;
/**
* Sets the column width
@@ -111,6 +112,15 @@ public class SelectableColumnTag extends TagSupport {
}
/**
+ * Expression to determine if we should show disabled checkboxes
+ * @param expr "true" if we should hide disabled checkboxes, else we show them
+ */
+ public void setHideDisabled(String expr) {
+ hideDisabled = expr;
+ }
+
+
+ /**
* {@inheritDoc}
*/
public int doStartTag() throws JspException {
@@ -220,6 +230,11 @@ public class SelectableColumnTag extends TagSupport {
String id = ListTagHelper.getObjectId(getCurrent());
String checkboxId = makeCheckboxId(listName, id);
renderHiddenItem(id, value);
+
+ if (isHideDisabled() && isDisabled()) {
+ return;
+ }
+
ListTagUtil.write(pageContext, "<input type=\"checkbox\" ");
boolean selected = isSelected();
if (selected) {
@@ -399,6 +414,14 @@ public class SelectableColumnTag extends TagSupport {
}
return false;
}
+
+ private boolean isHideDisabled() {
+ if (hideDisabled != null && hideDisabled.equalsIgnoreCase("true")) {
+ return true;
+ }
+ return false;
+ }
+
protected void writeStartingTd() throws JspException {
writeStartingTd(pageContext, styleClass, width);
}
diff --git a/java/code/src/com/redhat/rhn/frontend/taglibs/rhn-list.tld b/java/code/src/com/redhat/rhn/frontend/taglibs/rhn-list.tld
index 3b99555..f145ee6 100644
--- a/java/code/src/com/redhat/rhn/frontend/taglibs/rhn-list.tld
+++ b/java/code/src/com/redhat/rhn/frontend/taglibs/rhn-list.tld
@@ -16,7 +16,7 @@
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
- <attribute>
+ <attribute>
<name>legend</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
@@ -82,40 +82,40 @@
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
- <name>hidepagenums</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
+ <name>hidepagenums</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
+ <attribute>
<name>parentiselement</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
- <attribute>
+ <attribute>
<name>searchparent</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
- <attribute>
+ <attribute>
<name>searchchild</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>reflink</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>reflinkkey</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>reflinkkeyarg0</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
+ </attribute>
+ <attribute>
+ <name>reflink</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
+ <attribute>
+ <name>reflinkkey</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
+ <attribute>
+ <name>reflinkkeyarg0</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
</tag>
<tag>
<name>decorator</name>
@@ -221,12 +221,12 @@
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
- <attribute>
+ <attribute>
<name>filterattr</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
- <attribute>
+ <attribute>
<name>filtermessage</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
@@ -251,7 +251,7 @@
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
- <attribute>
+ <attribute>
<name>headerkey</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
@@ -271,6 +271,11 @@
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
+ <attribute>
+ <name>hideDisabled</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
</tag>
<tag>
<name>radiocolumn</name>
@@ -291,7 +296,7 @@
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
- <attribute>
+ <attribute>
<name>headerkey</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
@@ -307,37 +312,37 @@
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
- <tag>
- <name>csv</name>
- <tag-class>com.redhat.rhn.frontend.taglibs.list.CSVTag</tag-class>
- <body-content>JSP</body-content>
- <attribute>
- <name>name</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>dataset</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>exportColumns</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>header</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- </tag>
+ <tag>
+ <name>csv</name>
+ <tag-class>com.redhat.rhn.frontend.taglibs.list.CSVTag</tag-class>
+ <body-content>JSP</body-content>
+ <attribute>
+ <name>name</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
+ <attribute>
+ <name>dataset</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
+ <attribute>
+ <name>exportColumns</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
+ <attribute>
+ <name>header</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
+ </tag>
<function>
<name>expandable</name>
<function-class>com.redhat.rhn.frontend.taglibs.RhnListTagFunctions</function-class>
<function-signature>boolean isExpandable(java.lang.Object)</function-signature>
</function>
- <function>
+ <function>
<name>countChildren</name>
<function-class>com.redhat.rhn.frontend.taglibs.RhnListTagFunctions</function-class>
<function-signature>int getChildrenCount(java.lang.Object)</function-signature>
diff --git a/java/code/webapp/WEB-INF/pages/common/fragments/scheduledactions/listdisplay-new.jspf b/java/code/webapp/WEB-INF/pages/common/fragments/scheduledactions/listdisplay-new.jspf
index a744fa3..c0e1a91 100644
--- a/java/code/webapp/WEB-INF/pages/common/fragments/scheduledactions/listdisplay-new.jspf
+++ b/java/code/webapp/WEB-INF/pages/common/fragments/scheduledactions/listdisplay-new.jspf
@@ -1,15 +1,15 @@
<rl:decorator name="PageSizeDecorator"/>
- <rl:decorator name="SelectableDecorator"/>
+ <rl:decorator name="SelectableDecorator"/>
<rl:decorator name="ElaborationDecorator"/>
-
- <rl:selectablecolumn value="${current.selectionKey}"
- selected="${current.selected}"
- disabled="${not current.selectable}"
- headerclass="first-column"/>
+ <rl:selectablecolumn value="${current.selectionKey}"
+ selected="${current.selected}"
+ disabled="${not current.selectable}"
+ hideDisabled="true"
+ headerclass="first-column"/>
<rl:column sortable="true"
bound="false"
@@ -20,7 +20,6 @@
<a href="/rhn/schedule/CompletedSystems.do?aid=${current.id}"><c:out value="${current.actionName}" /></a>
</rl:column>
-
<rl:column sortable="true"
bound="false"
headerkey="actions.jsp.earliest"
@@ -30,17 +29,16 @@
<c:out value="${current.earliest}" />
</rl:column>
-
<rl:column sortable="false"
bound="false"
headerkey="actions.jsp.succeeded"
styleclass="thin-column"
>
<c:if test="${current.completed != 0}">
- <a href="/rhn/schedule/CompletedSystems.do?aid=${current.id}">${current.completed}</a>
+ <a href="/rhn/schedule/CompletedSystems.do?aid=${current.id}">${current.completed}</a>
</c:if>
<c:if test="${current.completed == 0}">
- ${current.completed}
+ ${current.completed}
</c:if>
</rl:column>
@@ -51,10 +49,10 @@
styleclass="thin-column"
>
<c:if test="${current.failed != 0}">
- <a href="/rhn/schedule/FailedSystems.do?aid=${current.id}">${current.failed}</a>
+ <a href="/rhn/schedule/FailedSystems.do?aid=${current.id}">${current.failed}</a>
</c:if>
<c:if test="${current.failed == 0}">
- ${current.failed}
+ ${current.failed}
</c:if>
</rl:column>
@@ -66,10 +64,10 @@
styleclass="thin-column"
>
<c:if test="${current.inProgress != 0}">
- <a href="/rhn/schedule/InProgressSystems.do?aid=${current.id}">${current.inProgress}</a>
+ <a href="/rhn/schedule/InProgressSystems.do?aid=${current.id}">${current.inProgress}</a>
</c:if>
<c:if test="${current.inProgress == 0}">
- ${current.inProgress}
+ ${current.inProgress}
</c:if>
</rl:column>
@@ -78,6 +76,6 @@
bound="false"
headerkey="actions.jsp.total"
styleclass="thin-column">
- ${current.tally}
+ ${current.tally}
</rl:column>
10 years, 2 months
Changes to 'refs/tags/spacewalk-schema-2.1.4-1'
by Michael Mraka
Tag 'spacewalk-schema-2.1.4-1' created by Michael Mraka <michael.mraka(a)redhat.com> at 2013-07-26 11:16 +0000
Tagging package [spacewalk-schema] version [2.1.4-1] in directory [schema/spacewalk/].
Changes since spacewalk-java-2.1.7-1:
Michael Mraka (2):
fixed upgrade file names
Automatic commit of package [spacewalk-schema] release [2.1.4-1].
---
rel-eng/packages/spacewalk-schema | 2
schema/spacewalk/spacewalk-schema.spec | 5
schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.oracle | 1777 ---------
schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.postgresql | 1787 ----------
schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.sql.oracle | 1777 +++++++++
schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.sql.postgresql | 1787 ++++++++++
6 files changed, 3569 insertions(+), 3566 deletions(-)
---
10 years, 2 months
2 commits - rel-eng/packages schema/spacewalk
by Michael Mraka
rel-eng/packages/spacewalk-schema | 2
schema/spacewalk/spacewalk-schema.spec | 5
schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.oracle | 1777 ---------
schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.postgresql | 1787 ----------
schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.sql.oracle | 1777 +++++++++
schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.sql.postgresql | 1787 ++++++++++
6 files changed, 3569 insertions(+), 3566 deletions(-)
New commits:
commit ed830251484ab80ac26a62480e2f2edb41187eed
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Jul 26 13:16:45 2013 +0200
Automatic commit of package [spacewalk-schema] release [2.1.4-1].
diff --git a/rel-eng/packages/spacewalk-schema b/rel-eng/packages/spacewalk-schema
index c8b6565..4ffced2 100644
--- a/rel-eng/packages/spacewalk-schema
+++ b/rel-eng/packages/spacewalk-schema
@@ -1 +1 @@
-2.1.3-1 schema/spacewalk/
+2.1.4-1 schema/spacewalk/
diff --git a/schema/spacewalk/spacewalk-schema.spec b/schema/spacewalk/spacewalk-schema.spec
index 5d9bcb0..3c384c6 100644
--- a/schema/spacewalk/spacewalk-schema.spec
+++ b/schema/spacewalk/spacewalk-schema.spec
@@ -4,7 +4,7 @@ Name: spacewalk-schema
Group: Applications/Internet
Summary: Oracle SQL schema for Spacewalk server
-Version: 2.1.3
+Version: 2.1.4
Release: 1%{?dist}
Source0: %{name}-%{version}.tar.gz
@@ -71,6 +71,9 @@ rm -rf $RPM_BUILD_ROOT
%{_mandir}/man1/spacewalk-sql*
%changelog
+* Fri Jul 26 2013 Michael Mraka <michael.mraka(a)redhat.com> 2.1.4-1
+- fixed upgrade file names
+
* Thu Jul 25 2013 Tomas Lestach <tlestach(a)redhat.com> 2.1.3-1
- recreate logging triggers after we change the logging table column types
commit f539a8ee98a40e1791e027f9458bb758e2d6ff1f
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Jul 26 11:36:10 2013 +0200
fixed upgrade file names
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.oracle b/schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.oracle
deleted file mode 100644
index d694b34..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.oracle
+++ /dev/null
@@ -1,1777 +0,0 @@
---
--- Copyright (c) 2008--2012 Red Hat, Inc.
---
--- This software is licensed to you under the GNU General Public License,
--- version 2 (GPLv2). There is NO WARRANTY for this software, express or
--- implied, including the implied warranties of MERCHANTABILITY or FITNESS
--- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
--- along with this software; if not, see
--- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
---
--- Red Hat trademarks are not licensed under GPLv2. No permission is
--- granted to use or replicate Red Hat trademarks that are incorporated
--- in this software or its documentation.
---
---
---
---
-
-create or replace
-package body rhn_entitlements
-is
- body_version varchar2(100) := '';
-
- function find_compatible_sg (
- server_id_in in number,
- type_label_in in varchar2
- ) return number is
-
- cursor servergroups is
- select sg.id id
- from rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServer s,
- rhnServerServerGroupArchCompat ssgac
- where s.id = server_id_in
- and s.org_id = sg.org_id
- and sgt.label = type_label_in
- and sg.group_type = sgt.id
- and ssgac.server_group_type = sgt.id
- and ssgac.server_arch_id = s.server_arch_id
- and not exists (
- select 1
- from rhnServerGroupMembers sgm
- where sgm.server_group_id = sg.id
- and sgm.server_id = s.id);
-
-
- begin
- for servergroup in servergroups loop
- return servergroup.id;
- end loop;
-
- --no servergroup found
- return null;
- end find_compatible_sg;
-
-
- -- *******************************************************************
- -- PROCEDURE: remove_org_entitlements
- --
- -- Removes both system entitlements and channel subscriptions
- -- that are currently assigned to an org and re-assigns to the
- -- master org (org_id = 1).
- --
- -- When we call this we expect everything to already be unentitled
- -- which shoul be handled by delete_org.
- --
- -- Called by: delete_org
- -- *******************************************************************
- procedure remove_org_entitlements(
- org_id_in in number
- )
- is
-
- cursor system_ents is
- select sg.id, sg.max_members, sg.group_type
- from rhnServerGroup sg
- where group_type is not null
- and org_id = org_id_in;
-
- cursor channel_subs is
- select pcf.channel_family_id, pcf.max_members
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = org_id_in
- and pcf.channel_family_id = cf.id
- and cf.org_id is null;
-
- begin
-
- for system_ent in system_ents loop
- update rhnServerGroup
- set max_members = max_members + system_ent.max_members
- where org_id = 1
- and group_type = system_ent.group_type;
- end loop;
-
- update rhnServerGroup
- set max_members = 0
- where org_id = org_id_in;
-
- for channel_sub in channel_subs loop
- update rhnPrivateChannelFamily
- set max_members = max_members + channel_sub.max_members
- where org_id = 1
- and channel_family_id = channel_sub.channel_family_id;
- end loop;
-
- update rhnPrivateChannelFamily
- set max_members = 0
- where org_id = org_id_in;
-
- end remove_org_entitlements;
-
- function entitlement_grants_service (
- entitlement_in in varchar2,
- service_level_in in varchar2
- ) return number is
- begin
- if service_level_in = 'provisioning' then
- if entitlement_in = 'provisioning_entitled' then
- return 1;
- else
- return 0;
- end if;
- elsif service_level_in = 'management' then
- if entitlement_in = 'enterprise_entitled' then
- return 1;
- else
- return 0;
- end if;
- elsif service_level_in = 'monitoring' then
- if entitlement_in = 'monitoring_entitled' then
- return 1;
- end if;
- elsif service_level_in = 'updates' then
- return 1;
- else
- return 0;
- end if;
- end entitlement_grants_service;
-
- function lookup_entitlement_group (
- org_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- ) return number is
- cursor server_groups is
- select sg.id server_group_id
- from rhnServerGroup sg,
- rhnServerGroupType sgt
- where sgt.label = type_label_in
- and sgt.id = sg.group_type
- and sg.org_id = org_id_in;
- begin
- for sg in server_groups loop
- return sg.server_group_id;
- end loop;
- return rhn_entitlements.create_entitlement_group(
- org_id_in,
- type_label_in
- );
- end lookup_entitlement_group;
-
- function create_entitlement_group (
- org_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- ) return number is
- sg_id_val number;
- begin
- select rhn_server_group_id_seq.nextval
- into sg_id_val
- from dual;
-
- insert into rhnServerGroup (
- id, name, description, max_members, current_members,
- group_type, org_id
- ) (
- select sg_id_val, sgt.label, sgt.label,
- 0, 0, sgt.id, org_id_in
- from rhnServerGroupType sgt
- where sgt.label = type_label_in
- );
-
- return sg_id_val;
- end create_entitlement_group;
-
- function can_entitle_server (
- server_id_in in number,
- type_label_in in varchar2 )
- return number is
- cursor addon_servergroups (base_label_in in varchar2,
- addon_label_in in varchar2) is
- select
- addon_id
- from
- rhnSGTypeBaseAddonCompat
- where base_id = lookup_sg_type (base_label_in)
- and addon_id = lookup_sg_type (addon_label_in);
-
- previous_ent rhn_entitlements.ents_array;
- is_base_in char := 'N';
- is_base_current char := 'N';
- i number := 0;
- sgid number := 0;
-
- begin
-
- previous_ent := rhn_entitlements.ents_array();
- previous_ent := rhn_entitlements.get_server_entitlement(server_id_in);
-
- select distinct is_base
- into is_base_in
- from rhnServerGroupType
- where label = type_label_in;
-
- if previous_ent.count = 0 then
- sgid := find_compatible_sg (server_id_in, type_label_in);
- if (is_base_in = 'Y' and sgid is not null) then
- -- rhn_server.insert_into_servergroup (server_id_in, sgid);
- return 1;
- else
- -- rhn_exception.raise_exception ('invalid_base_entitlement');
- return 0;
- end if;
-
- -- there are previous ents, first make sure we're not trying to entitle a base ent
- elsif is_base_in = 'Y' then
- -- rhn_exception.raise_exception ('invalid_addon_entitlement');
- return 0;
-
- -- it must be an addon, so proceed with the entitlement
- else
-
- -- find the servers base ent
- is_base_current := 'N';
- i := 0;
- while is_base_current = 'N' and i <= previous_ent.count
- loop
- i := i + 1;
- select is_base
- into is_base_current
- from rhnServerGroupType
- where label = previous_ent(i);
- end loop;
-
- -- never found a base ent, that would be strange
- if is_base_current = 'N' then
- -- rhn_exception.raise_exception ('invalid_base_entitlement');
- return 0;
- end if;
-
- -- this for loop verifies the validity of the addon path
- for addon_servergroup in addon_servergroups (previous_ent(i), type_label_in) loop
- -- find an appropriate sgid for the addon and entitle the server
- sgid := find_compatible_sg (server_id_in, type_label_in);
- if sgid is not null then
- -- rhn_server.insert_into_servergroup (server_id_in, sgid);
- return 1;
- else
- -- rhn_exception.raise_exception ('invalid_addon_entitlement');
- return 0;
- end if;
- end loop;
-
- end if;
-
- return 0;
-
- end can_entitle_server;
-
- function can_switch_base (
- server_id_in in integer,
- type_label_in in varchar2
- ) return number is
-
- type_label_in_is_base char(1);
- sgid number;
-
- begin
-
- begin
- select is_base into type_label_in_is_base
- from rhnServerGroupType
- where label = type_label_in;
- exception
- when no_data_found then
- rhn_exception.raise_exception ( 'invalid_entitlement' );
- end;
-
- if type_label_in_is_base = 'N' then
- rhn_exception.raise_exception ( 'invalid_entitlement' );
- else
- sgid := find_compatible_sg ( server_id_in, type_label_in );
- if sgid is not null then
- return 1;
- else
- return 0;
- end if;
- end if;
-
- end can_switch_base;
-
-
- procedure entitle_server (
- server_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- ) is
- sgid number := 0;
- is_virt number := 0;
-
- begin
-
- begin
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
- exception
- when no_data_found then
- is_virt := 0;
- end;
-
- if is_virt = 0 and (type_label_in = 'virtualization_host' or
- type_label_in = 'virtualization_host_platform') then
-
- is_virt := 1;
- end if;
-
-
-
- if rhn_entitlements.can_entitle_server(server_id_in,
- type_label_in) = 1 then
- sgid := find_compatible_sg (server_id_in, type_label_in);
- if sgid is not null then
- insert into rhnServerHistory ( id, server_id, summary, details )
- values ( rhn_event_id_seq.nextval, server_id_in,
- 'added system entitlement ',
- case type_label_in
- when 'enterprise_entitled' then 'Management'
- when 'sw_mgr_entitled' then 'Update'
- when 'provisioning_entitled' then 'Provisioning'
- when 'monitoring_entitled' then 'Monitoring'
- when 'virtualization_host' then 'Virtualization'
- when 'virtualization_host_platform' then
- 'Virtualization Platform' end );
-
- rhn_server.insert_into_servergroup (server_id_in, sgid);
-
- if is_virt = 1 then
- rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
- end if;
-
- else
- rhn_exception.raise_exception ('no_available_server_group');
- end if;
- else
- rhn_exception.raise_exception ('invalid_entitlement');
- end if;
- end entitle_server;
-
- procedure remove_server_entitlement (
- server_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled',
- repoll_virt_guests in number := 1
- ) is
- group_id number;
- type_is_base char;
- is_virt number := 0;
- begin
- begin
-
-
- -- would be nice if there were a virt attribute of entitlement types, not have to specify 2 different ones...
- begin
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
- exception
- when no_data_found then
- is_virt := 0;
- end;
-
- select sg.id, sgt.is_base
- into group_id, type_is_base
- from rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServerGroupMembers sgm,
- rhnServer s
- where s.id = server_id_in
- and s.id = sgm.server_id
- and sgm.server_group_id = sg.id
- and sg.org_id = s.org_id
- and sgt.label = type_label_in
- and sgt.id = sg.group_type;
-
- if ( type_is_base = 'Y' ) then
- -- unentitle_server should handle everything, don't really need to do anything else special here
- unentitle_server ( server_id_in );
- else
-
- insert into rhnServerHistory ( id, server_id, summary, details )
- values ( rhn_event_id_seq.nextval, server_id_in,
- 'removed system entitlement ',
- case type_label_in
- when 'enterprise_entitled' then 'Management'
- when 'sw_mgr_entitled' then 'Update'
- when 'provisioning_entitled' then 'Provisioning'
- when 'monitoring_entitled' then 'Monitoring'
- when 'virtualization_host' then 'Virtualization'
- when 'virtualization_host_platform' then
- 'Virtualization Platforrm' end );
-
- rhn_server.delete_from_servergroup(server_id_in, group_id);
-
- if type_label_in = 'monitoring_entitled' then
- DELETE
- FROM rhn_probe
- WHERE recid IN (SELECT probe_id
- FROM rhn_check_probe
- WHERE host_id = server_id_in);
- end if;
-
- if is_virt = 1 and repoll_virt_guests = 1 then
- rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
- end if;
- end if;
-
- exception
- when no_data_found then
- rhn_exception.raise_exception('invalid_server_group_member');
- end;
-
- end remove_server_entitlement;
-
-
- procedure unentitle_server (server_id_in in number) is
-
- cursor servergroups is
- select distinct sgt.label, sg.id server_group_id
- from rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServer s,
- rhnServerGroupMembers sgm
- where s.id = server_id_in
- and s.org_id = sg.org_id
- and sg.group_type = sgt.id
- and sgm.server_group_id = sg.id
- and sgm.server_id = s.id;
-
- is_virt number := 0;
-
- begin
-
- begin
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
- exception
- when no_data_found then
- is_virt := 0;
- end;
-
- for servergroup in servergroups loop
-
- insert into rhnServerHistory ( id, server_id, summary, details )
- values ( rhn_event_id_seq.nextval, server_id_in,
- 'removed system entitlement ',
- case servergroup.label
- when 'enterprise_entitled' then 'Management'
- when 'sw_mgr_entitled' then 'Update'
- when 'provisioning_entitled' then 'Provisioning'
- when 'monitoring_entitled' then 'Monitoring'
- when 'virtualization_host' then 'Virtualization'
- when 'virtualization_host_platform' then
- 'Virtualization Platform' end );
-
- rhn_server.delete_from_servergroup(server_id_in,
- servergroup.server_group_id );
- end loop;
-
- if is_virt = 1 then
- rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
- end if;
-
- end unentitle_server;
-
-
- -- *******************************************************************
- -- PROCEDURE: repoll_virt_guest_entitlements
- --
- -- Whenever we add/remove a virtualization_host* entitlement from
- -- a host, we can call this procedure to update what type of slots
- -- the guests are consuming.
- --
- -- If you're removing the entitlement, it's
- -- possible the guests will become unentitled if you don't have enough
- -- physical slots to cover them.
- --
- -- If you're adding the entitlement, you end up freeing up physical
- -- slots for other systems.
- --
- -- *******************************************************************
- procedure repoll_virt_guest_entitlements(server_id_in in number)
- is
-
- -- All channel families associated with the guests of server_id_in
- cursor families is
- select distinct cfs.channel_family_id
- from
- rhnChannelFamilyServers cfs,
- rhnVirtualInstance vi
- where
- vi.host_system_id = server_id_in
- and vi.virtual_system_id = cfs.server_id;
-
- -- All of server group types associated with the guests of
- -- server_id_in
- cursor group_types is
- select distinct sg.group_type, sgt.label
- from
- rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServerGroupMembers sgm,
- rhnVirtualInstance vi
- where
- vi.host_system_id = server_id_in
- and vi.virtual_system_id = sgm.server_id
- and sgm.server_group_id = sg.id
- and sg.group_type = sgt.id;
-
- -- Virtual servers from a certain family belonging to a speicifc
- -- host that are consuming physical channel slots over the limit.
- cursor virt_servers_cfam(family_id_in in number, quantity_in in number) is
- select virtual_system_id
- from (
- select rownum, vi.virtual_system_id
- from
- rhnChannelFamilyMembers cfm,
- rhnServerChannel sc,
- rhnVirtualInstance vi
- where
- vi.host_system_id = server_id_in
- and vi.virtual_system_id = sc.server_id
- and sc.channel_id = cfm.channel_id
- and cfm.channel_family_id = family_id_in
- order by sc.modified desc
- )
- where rownum <= quantity_in;
-
- -- Virtual servers from a certain family belonging to a speicifc
- -- host that are consuming physical system slots over the limit.
- cursor virt_servers_sgt(group_type_in in number, quantity_in in number) is
- select virtual_system_id
- from (
- select rownum, vi.virtual_system_id
- from
- rhnServerGroup sg,
- rhnServerGroupMembers sgm,
- rhnVirtualInstance vi
- where
- vi.host_system_id = server_id_in
- and vi.virtual_system_id = sgm.server_id
- and sgm.server_group_id = sg.id
- and sg.group_type = group_type_in
- order by sgm.modified desc
- )
- where rownum <= quantity_in;
- -- Get the orgs of Virtual guests
- -- Since they may belong to different orgs
- cursor virt_guest_orgs is
- select distinct (s.org_id)
- from rhnServer s
- inner join rhnVirtualInstance vi on vi.virtual_system_id = s.id
- where
- vi.host_system_id = server_id_in
- and s.org_id <> (select s1.org_id from rhnServer s1 where s1.id = vi.host_system_id) ;
-
-
- org_id_val number;
- max_members_val number;
- max_flex_val number;
- current_members_calc number;
- sg_id number;
- is_virt number := 0;
- begin
- begin
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
- exception
- when no_data_found then
- is_virt := 0;
- end;
-
- select org_id
- into org_id_val
- from rhnServer
- where id = server_id_in;
-
- -- deal w/ channel entitlements first ...
- for family in families loop
- if is_virt = 0 then
- -- if the host_server does not have virt
- --- find all possible flex slots
- -- and set each of the flex eligible guests to Y
- UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
- where sc.server_id in (
- select virtual_system_id from (
- select rownum, vi.virtual_system_id, sfc.max_members - sfc.current_members as free_slots
- from rhnServerFveCapable sfc
- inner join rhnVirtualInstance vi on vi.virtual_system_id = sfc.server_id
- where vi.host_system_id = server_id_in
- and sfc.channel_family_id = family.channel_family_id
- order by vi.modified desc
- )
- where rownum <= free_slots
- );
- else
- -- if the host_server has virt
- -- set all its flex guests to N
- UPDATE rhnServerChannel sc set sc.is_fve = 'N'
- where
- sc.channel_id in (select cfm.channel_id from rhnChannelFamilyMembers cfm
- where cfm.CHANNEL_FAMILY_ID = family.channel_family_id)
- and sc.is_fve = 'Y'
- and sc.server_id in
- (select vi.virtual_system_id from rhnVirtualInstance vi
- where vi.host_system_id = server_id_in);
- end if;
-
- -- get the current (physical) members of the family
- current_members_calc :=
- rhn_channel.channel_family_current_members(family.channel_family_id,
- org_id_val); -- fixed transposed args
-
- begin
-
- -- get the max members of the family
- select max_members
- into max_members_val
- from rhnPrivateChannelFamily
- where channel_family_id = family.channel_family_id
- and org_id = org_id_val;
-
- select fve_max_members
- into max_flex_val
- from rhnPrivateChannelFamily
- where channel_family_id = family.channel_family_id
- and org_id = org_id_val;
-
- if current_members_calc > max_members_val then
- -- A virtualization_host* ent must have been removed, so we'll
- -- unsubscribe guests from the host first.
-
- -- hm, i don't think max_members - current_members_calc yielding a negative number
- -- will work w/ rownum, swaping 'em in the body of this if...
- for virt_server in virt_servers_cfam(family.channel_family_id,
- current_members_calc - max_members_val) loop
-
- rhn_channel.unsubscribe_server_from_family(
- virt_server.virtual_system_id,
- family.channel_family_id);
- end loop;
-
- -- if we're still over the limit, which would be odd,
- -- just prune the group to max_members
- --
- -- er... wouldn't we actually have to refresh the values of
- -- current_members_calc and max_members_val to actually ever
- -- *skip this??
- if current_members_calc > max_members_val then
- -- argh, transposed again?!
- set_family_count(org_id_val,
- family.channel_family_id,
- max_members_val, max_flex_val);
- --TODO calculate this correctly
- end if;
-
- end if;
-
- -- update current_members for the family. This will set the value
- -- to reflect adding/removing the entitlement.
- --
- -- what's the difference of doing this vs the unavoidable set_family_count above?
- rhn_channel.update_family_counts(family.channel_family_id,
- org_id_val);
-
- exception when no_data_found then null;
- end;
-
- -- It is possible that the guests belong to a different org than the host
- -- so we are going to update the family counts in the guests orgs also
- for org in virt_guest_orgs loop
- rhn_channel.update_family_counts(family.channel_family_id,
- org.org_id);
- end loop;
- end loop;
-
- for a_group_type in group_types loop
- -- get the current *physical* members of the system entitlement type for the org...
- --
- -- unlike channel families, it appears the standard rhnServerGroup.max_members represents
- -- *physical* slots, vs physical+virt ... boy that's confusing...
-
- select max_members, id
- into max_members_val, sg_id
- from rhnServerGroup
- where group_type = a_group_type.group_type
- and org_id = org_id_val;
-
-
- select count(sep.server_id) into current_members_calc
- from rhnServerEntitlementPhysical sep
- where sep.server_group_id = sg_id
- and sep.server_group_type_id = a_group_type.group_type;
-
- if current_members_calc > max_members_val then
- -- A virtualization_host* ent must have been removed, and we're over the limit, so unsubscribe guests
- for virt_server in virt_servers_sgt(a_group_type.group_type,
- current_members_calc - max_members_val) loop
- rhn_entitlements.remove_server_entitlement(virt_server.virtual_system_id, a_group_type.label);
-
- -- decrement current_members_calc, we'll use it to reset current_members for the group at the end...
- current_members_calc := current_members_calc - 1;
- end loop;
-
- end if;
-
- update rhnServerGroup set current_members = current_members_calc
- where org_id = org_id_val
- and group_type = a_group_type.group_type;
-
- -- I think that's all the house-keeping we have to do...
- end loop;
-
- end repoll_virt_guest_entitlements;
-
-
- function get_server_entitlement (
- server_id_in in number
- ) return ents_array is
-
- cursor server_groups is
- select sgt.label
- from rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServerGroupMembers sgm
- where 1=1
- and sgm.server_id = server_id_in
- and sg.id = sgm.server_group_id
- and sgt.id = sg.group_type
- and sgt.label in (
- 'sw_mgr_entitled','enterprise_entitled',
- 'provisioning_entitled', 'nonlinux_entitled',
- 'monitoring_entitled', 'virtualization_host',
- 'virtualization_host_platform'
- );
-
- ent_array ents_array;
-
- begin
-
- ent_array := ents_array();
-
- for sg in server_groups loop
- ent_array.extend;
- ent_array(ent_array.count) := sg.label;
- end loop;
-
- return ent_array;
-
- end get_server_entitlement;
-
-
- -- this desperately needs to be table driven.
- procedure modify_org_service (
- org_id_in in number,
- service_label_in in varchar2,
- enable_in in char
- ) is
- type roles_v is varray(10) of rhnUserGroupType.label%TYPE;
- roles_to_process roles_v;
- cursor roles(role_label_in in varchar2) is
- select label, id
- from rhnUserGroupType
- where label = role_label_in;
- cursor org_roles(role_label_in in varchar2) is
- select 1
- from rhnUserGroup ug,
- rhnUserGroupType ugt
- where ugt.label = role_label_in
- and ug.org_id = org_id_in
- and ugt.id = ug.group_type;
-
- type ents_v is varray(10) of rhnOrgEntitlementType.label%TYPE;
- ents_to_process ents_v;
- cursor ents(ent_label_in in varchar2) is
- select label, id
- from rhnOrgEntitlementType
- where label = ent_label_in;
- cursor org_ents(ent_label_in in varchar2) is
- select 1
- from rhnOrgEntitlements oe,
- rhnOrgEntitlementType oet
- where oet.label = ent_label_in
- and oe.org_id = org_id_in
- and oet.id = oe.entitlement_id;
- create_row char(1);
- begin
- ents_to_process := ents_v();
- roles_to_process := roles_v();
- -- a bit kludgy, but only for 3.4 really. Certainly no
- -- worse than the old code...
- if service_label_in = 'enterprise' or
- service_label_in = 'management' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'sw_mgr_enterprise';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'org_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'system_group_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'activation_key_admin';
- elsif service_label_in = 'provisioning' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_provisioning';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'system_group_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'activation_key_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'config_admin';
- -- another nasty special case...
- if enable_in = 'Y' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'sw_mgr_enterprise';
- end if;
- elsif service_label_in = 'monitoring' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_monitor';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'monitoring_admin';
- elsif service_label_in = 'virtualization' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_virtualization';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'config_admin';
- elsif service_label_in = 'virtualization_platform' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_virtualization_platform';
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'config_admin';
- elsif service_label_in = 'nonlinux' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_nonlinux';
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'config_admin';
- end if;
-
- if enable_in = 'Y' then
- for i in 1..ents_to_process.count loop
- for ent in ents(ents_to_process(i)) loop
- create_row := 'Y';
- for oe in org_ents(ent.label) loop
- create_row := 'N';
- end loop;
- if create_row = 'Y' then
- insert into rhnOrgEntitlements(org_id, entitlement_id)
- values (org_id_in, ent.id);
- end if;
- end loop;
- end loop;
- for i in 1..roles_to_process.count loop
- for role in roles(roles_to_process(i)) loop
- create_row := 'Y';
- for o_r in org_roles(role.label) loop
- create_row := 'N';
- end loop;
- if create_row = 'Y' then
- insert into rhnUserGroup(
- id, name, description, current_members,
- group_type, org_id
- ) (
- select rhn_user_group_id_seq.nextval,
- ugt.name || 's',
- ugt.name || 's for Org ' ||
- o.name || ' ('|| o.id ||')',
- 0, ugt.id, o.id
- from rhnUserGroupType ugt,
- web_customer o
- where o.id = org_id_in
- and ugt.id = role.id
- );
- end if;
- end loop;
- end loop;
- else
- for i in 1..ents_to_process.count loop
- for ent in ents(ents_to_process(i)) loop
- delete from rhnOrgEntitlements
- where org_id = org_id_in
- and entitlement_id = ent.id;
- end loop;
- end loop;
- end if;
- end modify_org_service;
-
- procedure set_customer_enterprise (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'enterprise', 'Y');
- end set_customer_enterprise;
-
- procedure set_customer_provisioning (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'provisioning', 'Y');
- end set_customer_provisioning;
-
- procedure set_customer_monitoring (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'monitoring', 'Y');
- end set_customer_monitoring;
-
- procedure set_customer_nonlinux (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'nonlinux', 'Y');
- end set_customer_nonlinux;
-
- procedure unset_customer_enterprise (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'enterprise', 'N');
- end unset_customer_enterprise;
-
- procedure unset_customer_provisioning (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'provisioning', 'N');
- end unset_customer_provisioning;
-
- procedure unset_customer_monitoring (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'monitoring', 'N');
- end unset_customer_monitoring;
-
- procedure unset_customer_nonlinux (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'nonlinux', 'N');
- end unset_customer_nonlinux;
-
- -- *******************************************************************
- -- PROCEDURE: prune_group
- -- Unsubscribes servers consuming physical slots that over the org's
- -- limit.
- -- Called by: set_server_group_count, repoll_virt_guest_entitlements
- -- *******************************************************************
- procedure prune_group (
- group_id_in in number,
- quantity_in in number,
- update_family_countsYN in number := 1
- ) is
- cursor servergroups is
- select server_id, server_group_id, sgt.id as group_type_id, sgt.label
- from rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServerGroupMembers sgm
- where 1=1
- and sgm.server_group_id = group_id_in
- and sgm.server_id in (
- select server_id
- from (
- select rownum row_number,
- server_id,
- time
- from (
- select sep.server_id,
- sep.modified time
- from
- rhnServerEntitlementPhysical sep
- where
- sep.server_group_id = group_id_in
- order by time asc
- )
- )
- where row_number > quantity_in
- )
- and sgm.server_group_id = sg.id
- and sg.group_type = sgt.id;
- type_is_base char;
- begin
- update rhnServerGroup
- set max_members = quantity_in
- where id = group_id_in;
-
- for sg in servergroups loop
- remove_server_entitlement(sg.server_id, sg.label);
-
- select is_base
- into type_is_base
- from rhnServerGroupType sgt
- where sgt.id = sg.group_type_id;
-
- -- if we're removing a base ent, then be sure to
- -- remove the server's channel subscriptions.
- if ( type_is_base = 'Y' ) then
- rhn_channel.clear_subscriptions(sg.server_id,
- update_family_countsYN => update_family_countsYN);
- end if;
-
- end loop;
- end prune_group;
-
- procedure set_server_group_count (
- customer_id_in in number,
- group_type_in in number,
- quantity_in in number,
- update_family_countsYN in number := 1
- ) is
- group_id number;
- quantity number;
- begin
- quantity := quantity_in;
- if quantity is not null and quantity < 0 then
- quantity := 0;
- end if;
-
- select rsg.id
- into group_id
- from rhnServerGroup rsg
- where 1=1
- and rsg.org_id = customer_id_in
- and rsg.group_type = group_type_in;
-
- rhn_entitlements.prune_group(
- group_id,
- quantity,
- update_family_countsYN
- );
- exception
- when no_data_found then
- insert into rhnServerGroup (
- id, name, description, max_members, current_members,
- group_type, org_id, created, modified
- ) (
- select rhn_server_group_id_seq.nextval, name, name,
- quantity, 0, id, customer_id_in,
- current_timestamp, current_timestamp
- from rhnServerGroupType
- where id = group_type_in
- );
- end set_server_group_count;
-
- -- *******************************************************************
- -- PROCEDURE: assign_system_entitlement
- --
- -- Moves system entitlements from from_org_id_in to to_org_id_in.
- -- Can raise not_enough_entitlements_in_base_org if from_org_id_in
- -- does not have enough entitlements to cover the move.
- -- Takes care of unentitling systems if necessary by calling
- -- set_server_group_count
- -- *******************************************************************
- procedure assign_system_entitlement(
- group_label_in in varchar2,
- from_org_id_in in number,
- to_org_id_in in number,
- quantity_in in number
- )
- is
- prev_ent_count number;
- to_org_prev_ent_count number;
- new_ent_count number;
- new_quantity number;
- group_type number;
- begin
-
- begin
- select max_members
- into prev_ent_count
- from rhnServerGroupType sgt,
- rhnServerGroup sg
- where sg.org_id = from_org_id_in
- and sg.group_type = sgt.id
- and sgt.label = group_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end;
-
- begin
- select max_members
- into to_org_prev_ent_count
- from rhnServerGroupType sgt,
- rhnServerGroup sg
- where sg.org_id = to_org_id_in
- and sg.group_type = sgt.id
- and sgt.label = group_label_in;
- exception
- when NO_DATA_FOUND then
- to_org_prev_ent_count := 0;
- end;
-
- begin
- select id
- into group_type
- from rhnServerGroupType
- where label = group_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'invalid_server_group');
- end;
-
- new_ent_count := prev_ent_count - quantity_in;
-
- if prev_ent_count > new_ent_count then
- new_quantity := to_org_prev_ent_count + quantity_in;
- end if;
-
- if new_ent_count < 0 then
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end if;
-
-
- set_server_group_count(from_org_id_in,
- group_type,
- new_ent_count);
-
- set_server_group_count(to_org_id_in,
- group_type,
- new_quantity);
-
- -- Create or delete the entries in rhnOrgEntitlementType
- if group_label_in = 'enterprise_entitled' then
- if new_quantity > 0 then
- set_customer_enterprise(to_org_id_in);
- else
- unset_customer_enterprise(to_org_id_in);
- end if;
- end if;
-
- if group_label_in = 'provisioning_entitled' then
- if new_quantity > 0 then
- set_customer_provisioning(to_org_id_in);
- else
- unset_customer_provisioning(to_org_id_in);
- end if;
- end if;
-
- if group_label_in = 'monitoring_entitled' then
- if new_quantity > 0 then
- set_customer_monitoring(to_org_id_in);
- else
- unset_customer_monitoring(to_org_id_in);
- end if;
- end if;
-
- end assign_system_entitlement;
-
- -- *******************************************************************
- -- PROCEDURE: assign_channel_entitlement
- --
- -- Moves channel entitlements from from_org_id_in to to_org_id_in.
- -- Can raise not_enough_entitlements_in_base_org if from_org_id_in
- -- does not have enough entitlements to cover the move.
- -- Takes care of unentitling systems if necessary by calling
- -- set_family_count
- -- *******************************************************************
- procedure assign_channel_entitlement(
- channel_family_label_in in varchar2,
- from_org_id_in in number,
- to_org_id_in in number,
- quantity_in in number,
- flex_in in number
- )
- is
- from_org_prev_ent_count number;
- from_org_prev_ent_count_flex number;
- new_ent_count number;
- new_ent_count_flex number;
- to_org_prev_ent_count number;
- to_org_prev_ent_count_flex number;
- new_quantity number;
- new_flex number;
- cfam_id number;
- begin
-
- begin
- select max_members
- into from_org_prev_ent_count
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = from_org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end;
-
- begin
- select max_members
- into to_org_prev_ent_count
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = to_org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- to_org_prev_ent_count := 0;
- end;
-
- begin
- select fve_max_members
- into from_org_prev_ent_count_flex
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = from_org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'not_enough_flex_entitlements_in_base_org');
- end;
-
- begin
- select fve_max_members
- into to_org_prev_ent_count_flex
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = to_org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- to_org_prev_ent_count_flex := 0;
- end;
-
- begin
- select id
- into cfam_id
- from rhnChannelFamily
- where label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'invalid_channel_family');
- end;
-
- new_ent_count := from_org_prev_ent_count - quantity_in;
- new_ent_count_flex := from_org_prev_ent_count_flex - flex_in;
-
- if from_org_prev_ent_count >= new_ent_count then
- new_quantity := to_org_prev_ent_count + quantity_in;
- end if;
-
- if from_org_prev_ent_count_flex >= new_ent_count_flex then
- new_flex := to_org_prev_ent_count_flex + flex_in;
- end if;
-
-
- if new_ent_count < 0 then
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end if;
-
- if new_ent_count_flex < 0 then
- rhn_exception.raise_exception(
- 'not_enough_flex_entitlements_in_base_org');
- end if;
-
-
-
- rhn_entitlements.set_family_count(from_org_id_in, cfam_id,
- new_ent_count, new_ent_count_flex);
-
- rhn_entitlements.set_family_count(to_org_id_in,
- cfam_id,
- new_quantity, new_flex);
-
- end assign_channel_entitlement;
-
- -- *******************************************************************
- -- PROCEDURE: activate_system_entitlement
- --
- -- Sets the values in rhnServerGroup for a given rhnServerGroupType.
- --
- -- Calls: set_server_group_count to update, prune, or create the group.
- -- Called by: the code that activates a satellite cert.
- --
- -- Raises not_enough_entitlements_in_base_org if all entitlements
- -- in the org are used so the free entitlements would not cover
- -- the difference when descreasing the number of entitlements.
- -- *******************************************************************
- procedure activate_system_entitlement(
- org_id_in in number,
- group_label_in in varchar2,
- quantity_in in number
- )
- is
- prev_ent_count number;
- prev_ent_count_sum number;
- group_type number;
- begin
-
- -- Fetch the current entitlement count for the org
- -- into prev_ent_count
- begin
- select current_members
- into prev_ent_count
- from rhnServerGroupType sgt,
- rhnServerGroup sg
- where sg.group_type = sgt.id
- and sgt.label = group_label_in
- and sg.org_id = org_id_in;
- exception
- when NO_DATA_FOUND then
- prev_ent_count := 0;
- end;
-
- begin
- select id
- into group_type
- from rhnServerGroupType
- where label = group_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'invalid_server_group');
- end;
-
- -- If we're setting the total entitlemnt count to a lower value,
- -- and that value is less than the allocated count in this org,
- -- we need to raise an exception.
- if quantity_in < prev_ent_count then
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- else
- -- don't update family counts after every server
- -- will do bulk update afterwards
- set_server_group_count(org_id_in,
- group_type,
- quantity_in,
- update_family_countsYN => 0);
- -- bulk update family counts
- rhn_channel.update_group_family_counts(group_label_in, org_id_in);
- end if;
-
-
- end activate_system_entitlement;
-
- -- *******************************************************************
- -- PROCEDURE: activate_channel_entitlement
- --
- -- Calls: set_family_count to update, prune, or create the family
- -- permission bucket.
- -- Called by: the code that activates a satellite cert.
- --
- -- Raises not_enough_entitlements_in_base_org if there are not enough
- -- entitlements in the org to cover the difference when you are
- -- descreasing the number of entitlements.
- --
- -- The backend code in Python is expected to do whatever arithmetics
- -- is needed.
- -- *******************************************************************
- procedure activate_channel_entitlement(
- org_id_in in number,
- channel_family_label_in in varchar2,
- quantity_in in number,
- flex_in in number
-
- )
- is
- prev_ent_count number;
- prev_flex_count number;
- prev_ent_count_sum number;
- cfam_id number;
- reduce_quantity number;
- total_flex_capable number;
- cursor to_convert_reg (channel_family_id_val in number, org_id_in in number, quantity in number)
- is
- select SC.server_id
- from rhnServerChannel SC inner join
- rhnServer S on S.id = SC.server_id
- where
- is_fve = 'Y'
- and S.org_id = org_id_in
- and SC.channel_id in
- (select cfm.channel_id from rhnChannelFamilyMembers cfm
- where cfm.CHANNEL_FAMILY_ID = channel_family_id_val)
- and rownum <= quantity;
- cursor to_convert_flex (channel_family_id_val in number, org_id_in in number, quantity in number)
- is
- select server_id
- from rhnServerFveCapable
- where SERVER_ORG_ID = org_id_in and
- channel_family_id = cfam_id and
- rownum <= quantity;
-
- begin
-
- -- Fetch the current entitlement count for the org
- -- into prev_ent_count
- begin
- select current_members
- into prev_ent_count
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- prev_ent_count := 0;
- end;
-
- begin
- select pcf.fve_current_members
- into prev_flex_count
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- prev_flex_count := 0;
- end;
-
-
- begin
- select id
- into cfam_id
- from rhnChannelFamily
- where label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'invalid_channel_family');
- end;
-
- -- if there are too few flex entitlements
- if flex_in < prev_flex_count then
- -- and if the extra we need is less than or equal to our extra regular entitlements
- if prev_flex_count - flex_in <= quantity_in - prev_ent_count then
- reduce_quantity := prev_flex_count - flex_in;
- -- We need to convert some systems from flex guest to regular
- for system in to_convert_reg(cfam_id, org_id_in, reduce_quantity) loop
- --rhn_channel.convert_to_regular(system.server_id, cfam_id);
- UPDATE rhnServerChannel sc set sc.is_fve = 'N'
- where sc.server_id = system.server_id
- and sc.channel_id in (select cfm.channel_id
- from rhnChannelFamilyMembers cfm
- where cfm.channel_family_id = cfam_id);
- end loop;
-
- --reset previous counts
- prev_ent_count := prev_ent_count + reduce_quantity;
- prev_flex_count := prev_flex_count - reduce_quantity;
- else
- rhn_exception.raise_exception(
- 'not_enough_flex_entitlements_in_base_org');
- end if;
- end if;
-
- -- if there are too few regular entitlements, and extra flex entitlements
- if quantity_in < prev_ent_count and prev_flex_count < flex_in then
- -- how many flex-capable systems (that aren't using flex) do we have
- select count(*)
- into total_flex_capable
- from rhnServerFveCapable
- where SERVER_ORG_ID = org_id_in and
- channel_family_id = cfam_id;
- -- if we have enough flex capable machines that is at least
- -- as many as what we are over on
- if total_flex_capable >= prev_ent_count - quantity_in then
- reduce_quantity := prev_ent_count - quantity_in;
- for system in to_convert_flex(cfam_id, org_id_in, reduce_quantity) loop
--- rhn_channel.convert_to_fve(system.server_id, cfam_id);
- UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
- where sc.server_id = system.server_id
- and sc.channel_id in (select cfm.channel_id
- from rhnChannelFamilyMembers cfm
- where cfm.channel_family_id = cfam_id);
- end loop;
- prev_ent_count := prev_ent_count - reduce_quantity;
- prev_flex_count := prev_flex_count + reduce_quantity;
- end if;
- end if;
-
-
-
-
- -- If we're setting the total entitlemnt count to a lower value,
- -- and that value is less than the count in that one org,
- -- we need to raise an exception.
- if quantity_in < prev_ent_count then
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- else
- -- even if we've manually converted systems to/from flex above
- -- set_family_count should call update_family_counts, to reset
- -- current used slots
- rhn_entitlements.set_family_count(org_id_in, cfam_id,
- quantity_in, flex_in);
- end if;
-
- end activate_channel_entitlement;
-
-
- -- *******************************************************************
- -- PROCEDURE: prune_family
- -- Unsubscribes servers consuming physical slots from the channel family
- -- that are over the org's limit.
- -- Called by: set_family_count
- -- *******************************************************************
- procedure prune_family (
- customer_id_in in number,
- channel_family_id_in in number,
- quantity_in in number,
- flex_in in number
- ) is
- cursor serverchannels(tmp_quantity number, is_fve_in char) is
- select sc.server_id,
- sc.channel_id
- from rhnServerChannel sc,
- rhnChannelFamilyMembers cfm
- where 1=1
- and cfm.channel_family_id = channel_family_id_in
- and cfm.channel_id = sc.channel_id
- and server_id in (
- select server_id
- from (
- select server_id, time, rownum row_number
- from (
- select rs.id server_id, rcfm.modified time
- from rhnServerChannel rsc,
- rhnChannelFamilyMembers rcfm,
- rhnServer rs
- where 1=1
- and rs.org_id = customer_id_in
- and rs.id = rsc.server_id
- and rsc.channel_id = rcfm.channel_id
- and rcfm.channel_family_id = channel_family_id_in
- and rsc.is_fve = is_fve_in
- -- we only want to grab servers consuming
- -- physical slots.
- and exists (
- select 1
- from rhnChannelFamilyServerPhysical cfsp
- where cfsp.server_id = rs.id
- and cfsp.channel_family_id =
- channel_family_id_in
- )
- order by time asc
- )
- )
- where row_number > tmp_quantity
- );
- begin
- -- if we get a null customer_id, this is completely bogus.
- if customer_id_in is null then
- return;
- end if;
-
- for sc in serverchannels(quantity_in, 'N') loop
- rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1,
- update_family_countsYN => 0);
- end loop;
-
- for sc in serverchannels(flex_in, 'Y') loop
- rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1,
- update_family_countsYN => 0);
- end loop;
-
- rhn_channel.update_family_counts(channel_family_id_in, customer_id_in);
- end prune_family;
-
- procedure set_family_count (
- customer_id_in in number,
- channel_family_id_in in number,
- quantity_in in number,
- flex_in in number
- ) is
- cursor privperms is
- select 1
- from rhnPrivateChannelFamily
- where org_id = customer_id_in
- and channel_family_id = channel_family_id_in;
- cursor pubperms is
- select o.id org_id
- from web_customer o,
- rhnPublicChannelFamily pcf
- where pcf.channel_family_id = channel_family_id_in;
- quantity number;
- done number := 0;
- flex number;
- begin
- quantity := quantity_in;
- if quantity is not null and quantity < 0 then
- quantity := 0;
- end if;
- flex := flex_in;
- if flex is not null and flex < 0 then
- flex := 0;
- end if;
-
-
- if customer_id_in is not null then
- for perm in privperms loop
- rhn_entitlements.prune_family(customer_id_in, channel_family_id_in,
- quantity, flex);
-
- if quantity is null and flex is null then
- delete from rhnPrivateChannelFamily
- where org_id = customer_id_in
- and channel_family_id = channel_family_id_in;
- else
- update rhnPrivateChannelFamily
- set max_members = quantity
- where org_id = customer_id_in
- and channel_family_id = channel_family_id_in;
-
- update rhnPrivateChannelFamily
- set fve_max_members = flex
- where org_id = customer_id_in
- and channel_family_id = channel_family_id_in;
- end if;
- return;
- end loop;
-
- insert into rhnPrivateChannelFamily (
- channel_family_id, org_id, max_members, current_members, fve_max_members, fve_current_members
- ) values (
- channel_family_id_in, customer_id_in, quantity, 0, flex, 0 );
- return;
- end if;
-
- for perm in pubperms loop
- if quantity = 0 then
- rhn_entitlements.prune_family(
- perm.org_id,
- channel_family_id_in,
- quantity,
- flex
- );
- if done = 0 then
- delete from rhnPublicChannelFamily
- where channel_family_id = channel_family_id_in;
- end if;
- end if;
- done := 1;
- end loop;
- -- if done's not 1, then we don't have any entitlements
- if done != 1 then
- insert into rhnPublicChannelFamily (
- channel_family_id
- ) values (
- channel_family_id_in
- );
- end if;
- end set_family_count;
-
- -- this expects quantity_in to be the number of available slots, not the
- -- max_members of the server group. If you give it too many, it'll fail
- -- and raise servergroup_max_members.
- -- We should NEVER run this unless we're SURE that we won't
- -- be violating the max.
- procedure entitle_last_modified_servers (
- customer_id_in in number,
- type_label_in in varchar2,
- quantity_in in number
- ) is
- -- find the servers that aren't currently in slots
- cursor servers(cid_in in number, quant_in in number) is
- select server_id
- from (
- select rownum row_number,
- server_id
- from (
- select rs.id server_iD
- from rhnServer rs
- where 1=1
- and rs.org_id = cid_in
- and not exists (
- select 1
- from rhnServerGroup sg,
- rhnServerGroupMembers rsgm
- where rsgm.server_id = rs.id
- and rsgm.server_group_id = sg.id
- and sg.group_type is not null
- )
- and not exists (
- select 1
- from rhnVirtualInstance vi
- where vi.virtual_system_id =
- rs.id
- ) order by modified desc
- )
- )
- where row_number <= quant_in;
- begin
- for server in servers(customer_id_in, quantity_in) loop
- rhn_entitlements.entitle_server(server.server_id, type_label_in);
- end loop;
- end entitle_last_modified_servers;
-
- procedure subscribe_newest_servers (
- customer_id_in in number
- ) is
- -- find servers without base channels
- cursor servers(cid_in in number) is
- select s.id
- from rhnServer s
- where 1=1
- and s.org_id = cid_in
- and not exists (
- select 1
- from rhnChannel c,
- rhnServerChannel sc
- where sc.server_id = s.id
- and sc.channel_id = c.id
- and c.parent_channel is null
- )
- and not exists (
- select 1
- from rhnVirtualInstance vi
- where vi.virtual_system_id = s.id
- )
- order by s.modified desc;
- channel_id number;
- begin
- for server in servers(customer_id_in) loop
- channel_id := rhn_channel.guess_server_base(server.id);
- if channel_id is not null then
- begin
- rhn_channel.subscribe_server(server.id, channel_id);
- commit;
- -- exception is really channel_family_no_subscriptions
- exception
- when others then
- null;
- end;
- end if;
- end loop;
- end subscribe_newest_servers;
-end rhn_entitlements;
-/
-show errors
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.postgresql b/schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.postgresql
deleted file mode 100644
index 1ec95e3..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.postgresql
+++ /dev/null
@@ -1,1787 +0,0 @@
--- oracle equivalent source sha1 49a42a42768d83a188a939412c353bf6de4013ab
---
--- Copyright (c) 2008--2012 Red Hat, Inc.
---
--- This software is licensed to you under the GNU General Public License,
--- version 2 (GPLv2). There is NO WARRANTY for this software, express or
--- implied, including the implied warranties of MERCHANTABILITY or FITNESS
--- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
--- along with this software; if not, see
--- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
---
--- Red Hat trademarks are not licensed under GPLv2. No permission is
--- granted to use or replicate Red Hat trademarks that are incorporated
--- in this software or its documentation.
---
-
--- create schema rhn_entitlements;
-
--- setup search_path so that these functions are created in appropriate schema.
-update pg_settings set setting = 'rhn_entitlements,' || setting where name = 'search_path';
-
- create or replace function find_compatible_sg (
- server_id_in in numeric,
- type_label_in in varchar
- )
- returns numeric
-as $$
- declare
- servergroups cursor for
- select sg.id
- from rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServer s,
- rhnServerServerGroupArchCompat ssgac
- where s.id = server_id_in
- and s.org_id = sg.org_id
- and sgt.label = type_label_in
- and sg.group_type = sgt.id
- and ssgac.server_group_type = sgt.id
- and ssgac.server_arch_id = s.server_arch_id
- and not exists (
- select 1
- from rhnServerGroupMembers sgm
- where sgm.server_group_id = sg.id
- and sgm.server_id = s.id);
-
-
- begin
- for servergroup in servergroups loop
- return servergroup.id;
- end loop;
-
- --no servergroup found
- return NULL;
- end$$
-language plpgsql;
-
- -- *******************************************************************
- -- PROCEDURE: remove_org_entitlements
- --
- -- Removes both system entitlements and channel subscriptions
- -- that are currently assigned to an org and re-assigns to the
- -- master org (org_id = 1).
- --
- -- When we call this we expect everything to already be unentitled
- -- which shoul be handled by delete_org.
- --
- -- Called by: delete_org
- -- *******************************************************************
- create or replace function remove_org_entitlements (
- org_id_in numeric
- ) returns void
-as $$
- declare
- system_ents cursor for
- select sg.id, sg.max_members, sg.group_type
- from rhnServerGroup sg
- where group_type is not null
- and org_id = org_id_in;
-
- channel_subs cursor for
- select pcf.channel_family_id, pcf.max_members
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = org_id_in
- and pcf.channel_family_id = cf.id
- and cf.org_id is null;
-
- begin
-
- for system_ent in system_ents loop
- update rhnServerGroup
- set max_members = max_members + system_ent.max_members
- where org_id = 1
- and group_type = system_ent.group_type;
- end loop;
-
- update rhnServerGroup
- set max_members = 0
- where org_id = org_id_in;
-
- for channel_sub in channel_subs loop
- update rhnPrivateChannelFamily
- set max_members = max_members + channel_sub.max_members
- where org_id = 1
- and channel_family_id = channel_sub.channel_family_id;
- end loop;
-
- update rhnPrivateChannelFamily
- set max_members = 0
- where org_id = org_id_in;
-
- end$$
-language plpgsql;
-
- create or replace function entitlement_grants_service (
- entitlement_in in varchar,
- service_level_in in varchar
- ) returns numeric
-as $$
- begin
- if service_level_in = 'provisioning' then
- if entitlement_in = 'provisioning_entitled' then
- return 1;
- else
- return 0;
- end if;
- elsif service_level_in = 'management' then
- if entitlement_in = 'enterprise_entitled' then
- return 1;
- else
- return 0;
- end if;
- elsif service_level_in = 'monitoring' then
- if entitlement_in = 'monitoring_entitled' then
- return 1;
- end if;
- elsif service_level_in = 'updates' then
- return 1;
- else
- return 0;
- end if;
- end$$
-language plpgsql;
-
- create or replace function lookup_entitlement_group (
- org_id_in in numeric,
- type_label_in in varchar default 'sw_mgr_entitled'
- ) returns numeric
-as $$
- declare
- server_groups cursor for
- select sg.id server_group_id
- from rhnServerGroup sg,
- rhnServerGroupType sgt
- where sgt.label = type_label_in
- and sgt.id = sg.group_type
- and sg.org_id = org_id_in;
- begin
- for sg in server_groups loop
- return sg.server_group_id;
- end loop;
- return rhn_entitlements.create_entitlement_group(
- org_id_in,
- type_label_in
- );
- end$$
-language plpgsql;
-
- create or replace function create_entitlement_group (
- org_id_in in numeric,
- type_label_in in varchar default 'sw_mgr_entitled'
- ) returns numeric
-as $$
- declare
- sg_id_val numeric;
- begin
- select nextval('rhn_server_group_id_seq')
- into sg_id_val;
-
- insert into rhnServerGroup (
- id, name, description, max_members, current_members,
- group_type, org_id
- ) (
- select sg_id_val, sgt.label, sgt.label,
- 0, 0, sgt.id, org_id_in
- from rhnServerGroupType sgt
- where sgt.label = type_label_in
- );
-
- return sg_id_val;
- end$$
-language plpgsql;
-
- create or replace function can_entitle_server (
- server_id_in in numeric,
- type_label_in in varchar
- )
- returns numeric
-as $$
- declare
- addon_servergroups cursor (base_label_in varchar,
- addon_label_in varchar) for
- select
- addon_id
- from
- rhnSGTypeBaseAddonCompat
- where base_id = lookup_sg_type (base_label_in)
- and addon_id = lookup_sg_type (addon_label_in);
-
- previous_ent varchar[];
- is_base_in char := 'N';
- is_base_current char := 'N';
- i numeric := 0;
- sgid numeric := 0;
-
- begin
-
- previous_ent := rhn_entitlements.get_server_entitlement(server_id_in);
-
- select distinct is_base
- into is_base_in
- from rhnServerGroupType
- where label = type_label_in;
-
- if array_upper(previous_ent, 1) is null or array_upper(previous_ent, 1) = 0 then
- if is_base_in = 'Y' then
- sgid := rhn_entitlements.find_compatible_sg (server_id_in, type_label_in);
- if sgid is not null then
- -- rhn_server.insert_into_servergroup (server_id_in, sgid);
- return 1;
- else
- -- rhn_exception.raise_exception ('invalid_base_entitlement');
- return 0;
- end if;
- else
- -- rhn_exception.raise_exception ('invalid_base_entitlement');
- return 0;
- end if;
-
- -- there are previous ents, first make sure we're not trying to entitle a base ent
- elsif is_base_in = 'Y' then
- -- rhn_exception.raise_exception ('invalid_addon_entitlement');
- return 0;
-
- -- it must be an addon, so proceed with the entitlement
- else
-
- -- find the servers base ent
- is_base_current := 'N';
- i := 0;
- while is_base_current = 'N' and i < array_upper(previous_ent, 1)
- loop
- i := i + 1;
- select is_base
- into is_base_current
- from rhnServerGroupType
- where label = previous_ent[i];
- end loop;
-
- -- never found a base ent, that would be strange
- if is_base_current = 'N' then
- -- rhn_exception.raise_exception ('invalid_base_entitlement');
- return 0;
- end if;
-
- -- this for loop verifies the validity of the addon path
- for addon_servergroup in addon_servergroups (previous_ent[i], type_label_in) loop
- -- find an appropriate sgid for the addon and entitle the server
- sgid := rhn_entitlements.find_compatible_sg (server_id_in, type_label_in);
- if sgid is not null then
- -- rhn_server.insert_into_servergroup (server_id_in, sgid);
- return 1;
- else
- -- rhn_exception.raise_exception ('invalid_addon_entitlement');
- return 0;
- end if;
- end loop;
-
- end if;
-
- return 0;
-
- end$$
-language plpgsql;
-
- create or replace function can_switch_base (
- server_id_in in integer,
- type_label_in in varchar
- )
- returns numeric
-as $$
- declare
- type_label_in_is_base char(1);
- sgid numeric;
-
- begin
-
- select is_base into type_label_in_is_base
- from rhnServerGroupType
- where label = type_label_in;
-
- if not found then
- perform rhn_exception.raise_exception ( 'invalid_entitlement' );
- end if;
-
- if type_label_in_is_base = 'N' then
- perform rhn_exception.raise_exception ( 'invalid_entitlement' );
- else
- sgid := rhn_entitlements.find_compatible_sg ( server_id_in,
- type_label_in );
- if sgid is not null then
- return 1;
- else
- return 0;
- end if;
- end if;
-
- end$$
-language plpgsql;
-
- create or replace function entitle_server (
- server_id_in in numeric,
- type_label_in in varchar default 'sw_mgr_entitled'
- ) returns void
-as $$
- declare
- sgid numeric := 0;
- is_virt numeric := 0;
-
- begin
-
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
-
- if not found then
- is_virt := 0;
- end if;
-
- if is_virt = 0 and (type_label_in = 'virtualization_host' or
- type_label_in = 'virtualization_host_platform') then
-
- is_virt := 1;
- end if;
-
- if rhn_entitlements.can_entitle_server(server_id_in,
- type_label_in) = 1 then
- sgid := rhn_entitlements.find_compatible_sg (server_id_in,
- type_label_in);
- if sgid is not null then
- insert into rhnServerHistory ( id, server_id, summary, details )
- values ( nextval('rhn_event_id_seq'), server_id_in,
- 'added system entitlement ',
- case type_label_in
- when 'enterprise_entitled' then 'Management'
- when 'sw_mgr_entitled' then 'Update'
- when 'provisioning_entitled' then 'Provisioning'
- when 'monitoring_entitled' then 'Monitoring'
- when 'virtualization_host' then 'Virtualization'
- when 'virtualization_host_platform' then
- 'Virtualization Platform' end );
-
- perform rhn_server.insert_into_servergroup (server_id_in, sgid);
-
- if is_virt = 1 then
- perform rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
- end if;
-
- else
- perform rhn_exception.raise_exception ('no_available_server_group');
- end if;
- else
- perform rhn_exception.raise_exception ('invalid_entitlement');
- end if;
- end$$
-language plpgsql;
-
- create or replace function remove_server_entitlement (
- server_id_in in numeric,
- type_label_in in varchar default 'sw_mgr_entitled',
- repoll_virt_guests in numeric default 1
- ) returns void
-as $$
- declare
- group_id numeric;
- type_is_base char;
- is_virt numeric := 0;
- begin
- -- would be nice if there were a virt attribute of entitlement types, not have to specify 2 different ones...
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
- if not found then
- is_virt := 0;
- end if;
-
- select sg.id, sgt.is_base
- into group_id, type_is_base
- from rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServerGroupMembers sgm,
- rhnServer s
- where s.id = server_id_in
- and s.id = sgm.server_id
- and sgm.server_group_id = sg.id
- and sg.org_id = s.org_id
- and sgt.label = type_label_in
- and sgt.id = sg.group_type;
-
- if not found then
- perform rhn_exception.raise_exception('invalid_server_group_member');
- end if;
-
- if ( type_is_base = 'Y' ) then
- -- unentitle_server should handle everything, don't really need to do anything else special here
- perform rhn_entitlements.unentitle_server ( server_id_in );
- else
-
- insert into rhnServerHistory ( id, server_id, summary, details )
- values ( nextval('rhn_event_id_seq'), server_id_in,
- 'removed system entitlement ',
- case type_label_in
- when 'enterprise_entitled' then 'Management'
- when 'sw_mgr_entitled' then 'Update'
- when 'provisioning_entitled' then 'Provisioning'
- when 'monitoring_entitled' then 'Monitoring'
- when 'virtualization_host' then 'Virtualization'
- when 'virtualization_host_platform' then
- 'Virtualization Platforrm' end );
-
- perform rhn_server.delete_from_servergroup(server_id_in, group_id);
-
- if type_label_in = 'monitoring_entitled' then
- DELETE
- FROM rhn_probe
- WHERE recid IN (SELECT probe_id
- FROM rhn_check_probe
- WHERE host_id = server_id_in);
- end if;
-
- if is_virt = 1 and repoll_virt_guests = 1 then
- perform rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
- end if;
- end if;
-
- end$$
-language plpgsql;
-
- create or replace function unentitle_server (
- server_id_in in numeric
- ) returns void
-as $$
- declare
- servergroups cursor for
- select distinct sgt.label, sg.id server_group_id
- from rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServer s,
- rhnServerGroupMembers sgm
- where s.id = server_id_in
- and s.org_id = sg.org_id
- and sg.group_type = sgt.id
- and sgm.server_group_id = sg.id
- and sgm.server_id = s.id;
-
- is_virt numeric := 0;
-
- begin
-
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
-
- if not found then
- is_virt := 0;
- end if;
-
- for servergroup in servergroups loop
-
- insert into rhnServerHistory ( id, server_id, summary, details )
- values ( nextval('rhn_event_id_seq'), server_id_in,
- 'removed system entitlement ',
- case servergroup.label
- when 'enterprise_entitled' then 'Management'
- when 'sw_mgr_entitled' then 'Update'
- when 'provisioning_entitled' then 'Provisioning'
- when 'monitoring_entitled' then 'Monitoring'
- when 'virtualization_host' then 'Virtualization'
- when 'virtualization_host_platform' then
- 'Virtualization Platform' end );
-
- perform rhn_server.delete_from_servergroup(server_id_in,
- servergroup.server_group_id );
- end loop;
-
- if is_virt = 1 then
- perform rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
- end if;
-
- end$$
-language plpgsql;
-
-
- -- *******************************************************************
- -- PROCEDURE: repoll_virt_guest_entitlements
- --
- -- Whenever we add/remove a virtualization_host* entitlement from
- -- a host, we can call this procedure to update what type of slots
- -- the guests are consuming.
- --
- -- If you're removing the entitlement, it's
- -- possible the guests will become unentitled if you don't have enough
- -- physical slots to cover them.
- --
- -- If you're adding the entitlement, you end up freeing up physical
- -- slots for other systems.
- --
- -- *******************************************************************
- create or replace function repoll_virt_guest_entitlements(
- server_id_in in numeric
- ) returns void
-as $$
- declare
- -- All channel families associated with the guests of server_id_in
- families cursor for
- select distinct cfs.channel_family_id
- from
- rhnChannelFamilyServers cfs,
- rhnVirtualInstance vi
- where
- vi.host_system_id = server_id_in
- and vi.virtual_system_id = cfs.server_id;
-
- -- All of server group types associated with the guests of
- -- server_id_in
- group_types cursor for
- select distinct sg.group_type, sgt.label
- from
- rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServerGroupMembers sgm,
- rhnVirtualInstance vi
- where
- vi.host_system_id = server_id_in
- and vi.virtual_system_id = sgm.server_id
- and sgm.server_group_id = sg.id
- and sg.group_type = sgt.id;
-
- -- Virtual servers from a certain family belonging to a specific
- -- host that are consuming physical channel slots over the limit.
- virt_servers_cfam cursor(family_id_in numeric, quantity_in numeric) for
- select vi.virtual_system_id
- from
- rhnChannelFamilyMembers cfm,
- rhnServerChannel sc,
- rhnVirtualInstance vi
- where
- vi.host_system_id = server_id_in
- and vi.virtual_system_id = sc.server_id
- and sc.channel_id = cfm.channel_id
- and cfm.channel_family_id = family_id_in
- order by sc.modified desc
- limit quantity_in;
-
- -- Virtual servers from a certain family belonging to a specific
- -- host that are consuming physical system slots over the limit.
- virt_servers_sgt cursor(group_type_in numeric, quantity_in numeric) for
- select vi.virtual_system_id
- from
- rhnServerGroup sg,
- rhnServerGroupMembers sgm,
- rhnVirtualInstance vi
- where
- vi.host_system_id = server_id_in
- and vi.virtual_system_id = sgm.server_id
- and sgm.server_group_id = sg.id
- and sg.group_type = group_type_in
- order by sgm.modified desc
- limit quantity_in;
-
- -- Get the orgs of Virtual guests
- -- Since they may belong to different orgs
- virt_guest_orgs cursor for
- select distinct (s.org_id)
- from rhnServer s
- inner join rhnVirtualInstance vi on vi.virtual_system_id = s.id
- where
- vi.host_system_id = server_id_in
- and s.org_id <> (select s1.org_id from rhnServer s1 where s1.id = vi.host_system_id) ;
-
- org_id_val numeric;
- max_members_val numeric;
- max_flex_val numeric;
- current_members_calc numeric;
- sg_id numeric;
- is_virt numeric := 0;
- free_slots numeric := 0;
- begin
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
-
- if not found then
- is_virt := 0;
- end if;
-
- select org_id
- into org_id_val
- from rhnServer
- where id = server_id_in;
-
- -- deal w/ channel entitlements first ...
- for family in families loop
- if is_virt = 0 then
- -- if the host_server does not have virt
- --- find all possible flex slots
- -- and set each of the flex eligible guests to Y
- select sfc.max_members - sfc.current_members
- into free_slots
- from rhnServerFveCapable sfc
- where sfc.channel_family_id = family.channel_family_id;
- UPDATE rhnServerChannel sc set is_fve = 'Y'
- where sc.server_id in (
- select vi.virtual_system_id
- from rhnServerFveCapable sfc
- inner join rhnVirtualInstance vi on vi.virtual_system_id = sfc.server_id
- where vi.host_system_id = server_id_in
- and sfc.channel_family_id = family.channel_family_id
- order by vi.modified desc
- limit free_slots
- );
- else
- -- if the host_server has virt
- -- set all its flex guests to N
- UPDATE rhnServerChannel sc set is_fve = 'N'
- where
- sc.channel_id in (select cfm.channel_id from rhnChannelFamilyMembers cfm
- where cfm.CHANNEL_FAMILY_ID = family.channel_family_id)
- and sc.is_fve = 'Y'
- and sc.server_id in
- (select vi.virtual_system_id from rhnVirtualInstance vi
- where vi.host_system_id = server_id_in);
- end if;
-
- -- get the current (physical) members of the family
- current_members_calc :=
- rhn_channel.channel_family_current_members(family.channel_family_id,
- org_id_val); -- fixed transposed args
-
- -- get the max members of the family
- select max_members
- into max_members_val
- from rhnPrivateChannelFamily
- where channel_family_id = family.channel_family_id
- and org_id = org_id_val;
-
- select fve_max_members
- into max_flex_val
- from rhnPrivateChannelFamily
- where channel_family_id = family.channel_family_id
- and org_id = org_id_val;
-
- if current_members_calc > max_members_val then
- -- A virtualization_host* ent must have been removed, so we'll
- -- unsubscribe guests from the host first.
-
- -- hm, i don't think max_members - current_members_calc yielding a negative number
- -- will work w/ rownum, swaping 'em in the body of this if...
- for virt_server in virt_servers_cfam(family.channel_family_id,
- current_members_calc - max_members_val) loop
-
- perform rhn_channel.unsubscribe_server_from_family(
- virt_server.virtual_system_id,
- family.channel_family_id);
- end loop;
-
- -- if we're still over the limit, which would be odd,
- -- just prune the group to max_members
- --
- -- er... wouldn't we actually have to refresh the values of
- -- current_members_calc and max_members_val to actually ever
- -- *skip this??
- if current_members_calc > max_members_val then
- -- argh, transposed again?!
- perform rhn_entitlements.set_family_count(org_id_val,
- family.channel_family_id,
- max_members_val, max_flex_val);
- --TODO calculate this correctly
- end if;
-
- end if;
-
- -- update current_members for the family. This will set the value
- -- to reflect adding/removing the entitlement.
- --
- -- what's the difference of doing this vs the unavoidable set_family_count above?
- perform rhn_channel.update_family_counts(family.channel_family_id,
- org_id_val);
-
- -- It is possible that the guests belong to a different org than the host
- -- so we are going to update the family counts in the guests orgs also
- for org in virt_guest_orgs loop
- perform rhn_channel.update_family_counts(family.channel_family_id,
- org.org_id);
- end loop;
- end loop;
-
- for a_group_type in group_types loop
- -- get the current *physical* members of the system entitlement type for the org...
- --
- -- unlike channel families, it appears the standard rhnServerGroup.max_members represents
- -- *physical* slots, vs physical+virt ... boy that's confusing...
-
- select max_members, id
- into max_members_val, sg_id
- from rhnServerGroup
- where group_type = a_group_type.group_type
- and org_id = org_id_val;
-
-
- select count(sep.server_id) into current_members_calc
- from rhnServerEntitlementPhysical sep
- where sep.server_group_id = sg_id
- and sep.server_group_type_id = a_group_type.group_type;
-
- if current_members_calc > max_members_val then
- -- A virtualization_host* ent must have been removed, and we're over the limit, so unsubscribe guests
- for virt_server in virt_servers_sgt(a_group_type.group_type,
- current_members_calc - max_members_val) loop
- perform rhn_entitlements.remove_server_entitlement(virt_server.virtual_system_id, a_group_type.label);
-
- -- decrement current_members_calc, we'll use it to reset current_members for the group at the end...
- current_members_calc := current_members_calc - 1;
- end loop;
-
- end if;
-
- update rhnServerGroup set current_members = current_members_calc
- where org_id = org_id_val
- and group_type = a_group_type.group_type;
-
- -- I think that's all the house-keeping we have to do...
- end loop;
-
- end$$
-language plpgsql;
-
- create or replace function get_server_entitlement (
- server_id_in in numeric
- ) returns varchar[]
-as $$
- declare
- server_groups cursor for
- select sgt.label
- from rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServerGroupMembers sgm
- where 1=1
- and sgm.server_id = server_id_in
- and sg.id = sgm.server_group_id
- and sgt.id = sg.group_type
- and sgt.label in (
- 'sw_mgr_entitled','enterprise_entitled',
- 'provisioning_entitled', 'nonlinux_entitled',
- 'monitoring_entitled', 'virtualization_host',
- 'virtualization_host_platform'
- );
-
- ent_array varchar[];
-
- begin
-
- ent_array := '{}';
-
- for sg in server_groups loop
- ent_array := ent_array || sg.label;
- end loop;
-
- return ent_array;
-
- end$$
-language plpgsql;
-
- -- this desperately needs to be table driven.
- create or replace function modify_org_service (
- org_id_in in numeric,
- service_label_in in varchar,
- enable_in in char
- ) returns void
-as $$
- declare
- roles_to_process varchar[];
- roles cursor(role_label_in varchar) for
- select label, id
- from rhnUserGroupType
- where label = role_label_in;
- org_roles cursor(role_label_in varchar) for
- select 1
- from rhnUserGroup ug,
- rhnUserGroupType ugt
- where ugt.label = role_label_in
- and ug.org_id = org_id_in
- and ugt.id = ug.group_type;
-
- ents_to_process varchar[];
- ents cursor(ent_label_in varchar) for
- select label, id
- from rhnOrgEntitlementType
- where label = ent_label_in;
- org_ents cursor(ent_label_in varchar) for
- select 1
- from rhnOrgEntitlements oe,
- rhnOrgEntitlementType oet
- where oet.label = ent_label_in
- and oe.org_id = org_id_in
- and oet.id = oe.entitlement_id;
- create_row char(1);
- begin
- ents_to_process := '{}';
- roles_to_process := '{}';
- -- a bit kludgy, but only for 3.4 really. Certainly no
- -- worse than the old code...
- if service_label_in = 'enterprise' or
- service_label_in = 'management' then
- ents_to_process := array_append(ents_to_process, 'sw_mgr_enterprise');
-
- roles_to_process := array_append(roles_to_process, 'org_admin');
-
- roles_to_process := array_append(roles_to_process, 'system_group_admin');
-
- roles_to_process := array_append(roles_to_process, 'activation_key_admin');
- elsif service_label_in = 'provisioning' then
- ents_to_process := array_append(ents_to_process, 'rhn_provisioning');
-
- roles_to_process := array_append(roles_to_process, 'system_group_admin');
-
- roles_to_process := array_append(roles_to_process, 'activation_key_admin');
-
- roles_to_process := array_append(roles_to_process, 'config_admin');
- -- another nasty special case...
- if enable_in = 'Y' then
- ents_to_process := array_append(ents_to_process, 'sw_mgr_enterprise');
- end if;
- elsif service_label_in = 'monitoring' then
- ents_to_process := array_append(ents_to_process, 'rhn_monitor');
-
- roles_to_process := array_append(roles_to_process, 'monitoring_admin');
- elsif service_label_in = 'virtualization' then
- ents_to_process := array_append(ents_to_process, 'rhn_virtualization');
-
- roles_to_process := array_append(roles_to_process, 'config_admin');
- elsif service_label_in = 'virtualization_platform' then
- ents_to_process := array_append(ents_to_process, 'rhn_virtualization_platform');
- roles_to_process := array_append(roles_to_process, 'config_admin');
- elsif service_label_in = 'nonlinux' then
- ents_to_process := array_append(ents_to_process, 'rhn_nonlinux');
- roles_to_process := array_append(roles_to_process, 'config_admin');
- end if;
-
- if enable_in = 'Y' then
- for i in 1..array_upper(ents_to_process, 1) loop
- for ent in ents(ents_to_process[i]) loop
- create_row := 'Y';
- for oe in org_ents(ent.label) loop
- create_row := 'N';
- end loop;
- if create_row = 'Y' then
- insert into rhnOrgEntitlements(org_id, entitlement_id)
- values (org_id_in, ent.id);
- end if;
- end loop;
- end loop;
- for i in 1..array_upper(roles_to_process, 1) loop
- for role in roles(roles_to_process[i]) loop
- create_row := 'Y';
- for o_r in org_roles(role.label) loop
- create_row := 'N';
- end loop;
- if create_row = 'Y' then
- insert into rhnUserGroup(
- id, name, description, current_members,
- group_type, org_id
- ) (
- select nextval('rhn_user_group_id_seq'),
- ugt.name || 's',
- ugt.name || 's for Org ' ||
- o.name || ' ('|| o.id ||')',
- 0, ugt.id, o.id
- from rhnUserGroupType ugt,
- web_customer o
- where o.id = org_id_in
- and ugt.id = role.id
- );
- end if;
- end loop;
- end loop;
- else
- for i in 1..coalesce(array_upper(ents_to_process, 1), 0) loop
- for ent in ents(ents_to_process[i]) loop
- delete from rhnOrgEntitlements
- where org_id = org_id_in
- and entitlement_id = ent.id;
- end loop;
- end loop;
- end if;
- end$$
-language plpgsql;
-
- create or replace function set_customer_enterprise (
- customer_id_in in numeric
- ) returns void
-as $$
- begin
- perform rhn_entitlements.modify_org_service(customer_id_in, 'enterprise', 'Y');
- end$$
-language plpgsql;
-
- create or replace function set_customer_provisioning (
- customer_id_in in numeric
- ) returns void
-as $$
- begin
- perform rhn_entitlements.modify_org_service(customer_id_in, 'provisioning', 'Y');
- end$$
-language plpgsql;
-
- create or replace function set_customer_monitoring (
- customer_id_in in numeric
- ) returns void
-as $$
- begin
- perform rhn_entitlements.modify_org_service(customer_id_in, 'monitoring', 'Y');
- end$$
-language plpgsql;
-
- create or replace function set_customer_nonlinux (
- customer_id_in in numeric
- ) returns void
-as $$
- begin
- perform rhn_entitlements.modify_org_service(customer_id_in, 'nonlinux', 'Y');
- end$$
-language plpgsql;
-
- create or replace function unset_customer_enterprise (
- customer_id_in in numeric
- ) returns void
-as $$
- begin
- perform rhn_entitlements.modify_org_service(customer_id_in, 'enterprise', 'N');
- end$$
-language plpgsql;
-
- create or replace function unset_customer_provisioning (
- customer_id_in in numeric
- ) returns void
-as $$
- begin
- perform rhn_entitlements.modify_org_service(customer_id_in, 'provisioning', 'N');
- end$$
-language plpgsql;
-
- create or replace function unset_customer_monitoring (
- customer_id_in in numeric
- ) returns void
-as $$
- begin
- perform rhn_entitlements.modify_org_service(customer_id_in, 'monitoring', 'N');
- end$$
-language plpgsql;
-
- create or replace function unset_customer_nonlinux (
- customer_id_in in numeric
- ) returns void
-as $$
- begin
- perform rhn_entitlements.modify_org_service(customer_id_in, 'nonlinux', 'N');
- end$$
-language plpgsql;
-
- -- *******************************************************************
- -- PROCEDURE: prune_group
- -- Unsubscribes servers consuming physical slots that over the org's
- -- limit.
- -- Called by: set_server_group_count, repoll_virt_guest_entitlements
- -- *******************************************************************
- create or replace function prune_group (
- group_id_in in numeric,
- quantity_in in numeric,
- update_family_countsYN in numeric default 1
- ) returns void
-as $$
- declare
- sgrecord record;
- type_is_base char;
- begin
- update rhnServerGroup
- set max_members = quantity_in
- where id = group_id_in;
-
- for sgrecord in (
- select server_id, server_group_id, sgt.id as group_type_id, sgt.label
- from rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServerGroupMembers sgm
- where 1=1
- and sgm.server_group_id = group_id_in
- and sgm.server_id in (
- select sep.server_id
- from
- rhnServerEntitlementPhysical sep
- where
- sep.server_group_id = group_id_in
- order by sep.modified asc
- offset quantity_in
- )
- and sgm.server_group_id = sg.id
- and sg.group_type = sgt.id
- ) loop
- perform rhn_entitlements.remove_server_entitlement(sgrecord.server_id, sgrecord.label);
-
- select is_base
- into type_is_base
- from rhnServerGroupType sgt
- where sgt.id = sgrecord.group_type_id;
-
- -- if we're removing a base ent, then be sure to
- -- remove the server's channel subscriptions.
- if ( type_is_base = 'Y' ) then
- perform rhn_channel.clear_subscriptions(sgrecord.server_id, 0, update_family_countsYN);
- end if;
-
- end loop;
- end$$
-language plpgsql;
-
- -- *******************************************************************
- -- PROCEDURE: assign_system_entitlement
- --
- -- Moves system entitlements from from_org_id_in to to_org_id_in.
- -- Can raise not_enough_entitlements_in_base_org if from_org_id_in
- -- does not have enough entitlements to cover the move.
- -- Takes care of unentitling systems if necessary by calling
- -- set_server_group_count
- -- *******************************************************************
- create or replace function assign_system_entitlement(
- group_label_in in varchar,
- from_org_id_in in numeric,
- to_org_id_in in numeric,
- quantity_in in numeric
- ) returns void
-as $$
- declare
- prev_ent_count numeric;
- to_org_prev_ent_count numeric;
- new_ent_count numeric;
- new_quantity numeric;
- group_type numeric;
- begin
-
- select max_members
- into prev_ent_count
- from rhnServerGroupType sgt,
- rhnServerGroup sg
- where sg.org_id = from_org_id_in
- and sg.group_type = sgt.id
- and sgt.label = group_label_in;
-
- if not found then
- perform rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end if;
-
- select max_members
- into to_org_prev_ent_count
- from rhnServerGroupType sgt,
- rhnServerGroup sg
- where sg.org_id = to_org_id_in
- and sg.group_type = sgt.id
- and sgt.label = group_label_in;
-
- if not found then
- to_org_prev_ent_count := 0;
- end if;
-
- select id
- into group_type
- from rhnServerGroupType
- where label = group_label_in;
-
- if not found then
- perform rhn_exception.raise_exception(
- 'invalid_server_group');
- end if;
-
- new_ent_count := prev_ent_count - quantity_in;
-
- if prev_ent_count > new_ent_count then
- new_quantity := to_org_prev_ent_count + quantity_in;
- end if;
-
- if new_ent_count < 0 then
- perform rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end if;
-
-
- perform rhn_entitlements.set_server_group_count(from_org_id_in,
- group_type,
- new_ent_count);
-
- perform rhn_entitlements.set_server_group_count(to_org_id_in,
- group_type,
- new_quantity);
-
- -- Create or delete the entries in rhnOrgEntitlementType
- if group_label_in = 'enterprise_entitled' then
- if new_quantity > 0 then
- perform rhn_entitlements.set_customer_enterprise(to_org_id_in);
- else
- perform rhn_entitlements.unset_customer_enterprise(to_org_id_in);
- end if;
- end if;
-
- if group_label_in = 'provisioning_entitled' then
- if new_quantity > 0 then
- perform rhn_entitlements.set_customer_provisioning(to_org_id_in);
- else
- perform rhn_entitlements.unset_customer_provisioning(to_org_id_in);
- end if;
- end if;
-
- if group_label_in = 'monitoring_entitled' then
- if new_quantity > 0 then
- perform rhn_entitlements.set_customer_monitoring(to_org_id_in);
- else
- perform rhn_entitlements.unset_customer_monitoring(to_org_id_in);
- end if;
- end if;
-
- end$$
-language plpgsql;
-
- -- *******************************************************************
- -- PROCEDURE: assign_channel_entitlement
- --
- -- Moves channel entitlements from from_org_id_in to to_org_id_in.
- -- Can raise not_enough_entitlements_in_base_org if from_org_id_in
- -- does not have enough entitlements to cover the move.
- -- Takes care of unentitling systems if necessary by calling
- -- set_family_count
- -- *******************************************************************
- create or replace function assign_channel_entitlement(
- channel_family_label_in in varchar,
- from_org_id_in in numeric,
- to_org_id_in in numeric,
- quantity_in in numeric,
- flex_in in numeric
- ) returns void
-as $$
- declare
- from_org_prev_ent_count numeric;
- from_org_prev_ent_count_flex numeric;
- new_ent_count numeric;
- new_ent_count_flex numeric;
- to_org_prev_ent_count numeric;
- to_org_prev_ent_count_flex numeric;
- new_quantity numeric;
- new_flex numeric;
- cfam_id numeric;
- begin
-
- select max_members
- into from_org_prev_ent_count
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = from_org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
-
- if not found then
- perform rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end if;
-
- select max_members
- into to_org_prev_ent_count
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = to_org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
-
- if not found then
- to_org_prev_ent_count := 0;
- end if;
-
- select fve_max_members
- into from_org_prev_ent_count_flex
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = from_org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
-
- if not found then
- perform rhn_exception.raise_exception(
- 'not_enough_flex_entitlements_in_base_org');
- end if;
-
- select fve_max_members
- into to_org_prev_ent_count_flex
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = to_org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
-
- if not found then
- to_org_prev_ent_count_flex := 0;
- end if;
-
- select id
- into cfam_id
- from rhnChannelFamily
- where label = channel_family_label_in;
-
- if not found then
- perform rhn_exception.raise_exception(
- 'invalid_channel_family');
- end if;
-
- new_ent_count := from_org_prev_ent_count - quantity_in;
- new_ent_count_flex := from_org_prev_ent_count_flex - flex_in;
-
- if from_org_prev_ent_count >= new_ent_count then
- new_quantity := to_org_prev_ent_count + quantity_in;
- end if;
-
- if from_org_prev_ent_count_flex >= new_ent_count_flex then
- new_flex := to_org_prev_ent_count_flex + flex_in;
- end if;
-
- if new_ent_count < 0 then
- perform rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end if;
-
- if new_ent_count_flex < 0 then
- perform rhn_exception.raise_exception(
- 'not_enough_flex_entitlements_in_base_org');
- end if;
-
-
-
- perform rhn_entitlements.set_family_count(from_org_id_in,
- cfam_id,
- new_ent_count,
- new_ent_count_flex);
-
- perform rhn_entitlements.set_family_count(to_org_id_in,
- cfam_id,
- new_quantity,
- new_flex);
-
- end$$
-language plpgsql;
-
- -- *******************************************************************
- -- PROCEDURE: activate_system_entitlement
- --
- -- Sets the values in rhnServerGroup for a given rhnServerGroupType.
- --
- -- Calls: set_server_group_count to update, prune, or create the group.
- -- Called by: the code that activates a satellite cert.
- --
- -- Raises not_enough_entitlements_in_base_org if all entitlements
- -- in the org are used so the free entitlements would not cover
- -- the difference when descreasing the number of entitlements.
- -- *******************************************************************
- create or replace function activate_system_entitlement(
- org_id_in in numeric,
- group_label_in in varchar,
- quantity_in in numeric
- ) returns void
-as $$
- declare
- prev_ent_count numeric;
- prev_ent_count_sum numeric;
- group_type numeric;
- begin
-
- -- Fetch the current entitlement count for the org
- -- into prev_ent_count
-
- select current_members
- into prev_ent_count
- from rhnServerGroupType sgt,
- rhnServerGroup sg
- where sg.group_type = sgt.id
- and sgt.label = group_label_in
- and sg.org_id = org_id_in;
-
- if not found then
- prev_ent_count := 0;
- end if;
-
- select id
- into group_type
- from rhnServerGroupType
- where label = group_label_in;
-
- if not found then
- perform rhn_exception.raise_exception(
- 'invalid_server_group');
- end if;
-
- -- If we're setting the total entitlemnt count to a lower value,
- -- and that value is less than the allocated count in this org,
- -- we need to raise an exception.
- if quantity_in < prev_ent_count then
- perform rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- else
- -- don't update family counts after every server
- -- will do bulk update afterwards
- perform rhn_entitlements.set_server_group_count(org_id_in,
- group_type,
- quantity_in,
- 0);
- -- bulk update family counts
- perform rhn_channel.update_group_family_counts(group_label_in, org_id_in);
- end if;
-
- end$$
-language plpgsql;
-
- -- *******************************************************************
- -- PROCEDURE: activate_channel_entitlement
- --
- -- Calls: set_family_count to update, prune, or create the family
- -- permission bucket.
- -- Called by: the code that activates a satellite cert.
- --
- -- Raises not_enough_entitlements_in_base_org if there are not enough
- -- entitlements in the org to cover the difference when you are
- -- descreasing the number of entitlements.
- --
- -- The backend code in Python is expected to do whatever arithmetics
- -- is needed.
- -- *******************************************************************
- create or replace function activate_channel_entitlement(
- org_id_in in numeric,
- channel_family_label_in in varchar,
- quantity_in in numeric,
- flex_in in numeric
- ) returns void
-as $$
- declare
- prev_ent_count numeric;
- prev_flex_count numeric;
- prev_ent_count_sum numeric;
- cfam_id numeric;
- reduce_quantity numeric;
- total_flex_capable numeric;
- to_convert_reg cursor (channel_family_id_val numeric, org_id_in numeric, quantity numeric) for
- select SC.server_id
- from rhnServerChannel SC inner join
- rhnServer S on S.id = SC.server_id
- where
- is_fve = 'Y'
- and S.org_id = org_id_in
- and SC.channel_id in
- (select cfm.channel_id from rhnChannelFamilyMembers cfm
- where cfm.CHANNEL_FAMILY_ID = channel_family_id_val)
- limit quantity;
- to_convert_flex cursor (channel_family_id_val numeric, org_id_in numeric, quantity numeric) for
- select server_id
- from rhnServerFveCapable
- where SERVER_ORG_ID = org_id_in and
- channel_family_id = cfam_id
- limit quantity;
-
- begin
-
- -- Fetch the current entitlement count for the org
- -- into prev_ent_count
- select current_members
- into prev_ent_count
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
-
- if not found then
- prev_ent_count := 0;
- end if;
-
- select pcf.fve_current_members
- into prev_flex_count
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
-
- if not found then
- prev_flex_count := 0;
- end if;
-
- select id
- into cfam_id
- from rhnChannelFamily
- where label = channel_family_label_in;
-
- if not found then
- perform rhn_exception.raise_exception(
- 'invalid_channel_family');
- end if;
-
- -- if there are too few flex entitlements
- if flex_in < prev_flex_count then
- -- and if the extra we need is less than or equal to our extra regular entitlements
- if prev_flex_count - flex_in <= quantity_in - prev_ent_count then
- reduce_quantity := prev_flex_count - flex_in;
- -- We need to convert some systems from flex guest to regular
- for system in to_convert_reg(cfam_id, org_id_in, reduce_quantity) loop
- --rhn_channel.convert_to_regular(system.server_id, cfam_id);
- UPDATE rhnServerChannel sc set is_fve = 'N'
- where sc.server_id = system.server_id
- and sc.channel_id in (select cfm.channel_id
- from rhnChannelFamilyMembers cfm
- where cfm.channel_family_id = cfam_id);
- end loop;
-
- --reset previous counts
- prev_ent_count := prev_ent_count + reduce_quantity;
- prev_flex_count := prev_flex_count - reduce_quantity;
- else
- perform rhn_exception.raise_exception(
- 'not_enough_flex_entitlements_in_base_org');
- end if;
- end if;
-
- -- if there are too few regular entitlements, and extra flex entitlements
- if quantity_in < prev_ent_count and prev_flex_count < flex_in then
- -- how many flex-capable systems (that aren't using flex) do we have
- select count(*)
- into total_flex_capable
- from rhnServerFveCapable
- where SERVER_ORG_ID = org_id_in and
- channel_family_id = cfam_id;
- -- if we have enough flex capable machines that is at least
- -- as many as what we are over on
- if total_flex_capable >= prev_ent_count - quantity_in then
- reduce_quantity := prev_ent_count - quantity_in;
- for system in to_convert_flex(cfam_id, org_id_in, reduce_quantity) loop
--- rhn_channel.convert_to_fve(system.server_id, cfam_id);
- UPDATE rhnServerChannel sc set is_fve = 'Y'
- where sc.server_id = system.server_id
- and sc.channel_id in (select cfm.channel_id
- from rhnChannelFamilyMembers cfm
- where cfm.channel_family_id = cfam_id);
- end loop;
- prev_ent_count := prev_ent_count - reduce_quantity;
- prev_flex_count := prev_flex_count + reduce_quantity;
- end if;
- end if;
-
- -- If we're setting the total entitlemnt count to a lower value,
- -- and that value is less than the count in that one org,
- -- we need to raise an exception.
- if quantity_in < prev_ent_count then
- perform rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- else
- -- even if we've manually converted systems to/from flex above
- -- set_family_count should call update_family_counts, to reset
- -- current used slots
- perform rhn_entitlements.set_family_count(org_id_in, cfam_id,
- quantity_in, flex_in);
- end if;
-
- end$$
-language plpgsql;
-
- create or replace function set_server_group_count (
- customer_id_in in numeric, -- customer_id
- group_type_in in numeric, -- rhn[User|Server]GroupType.id
- quantity_in in numeric, -- quantity
- update_family_countsYN in numeric default 1
- ) returns void
-as $$
- declare
- group_id numeric;
- quantity numeric;
- wasfound boolean;
- begin
- quantity := quantity_in;
- if quantity is not null and quantity < 0 then
- quantity := 0;
- end if;
-
- select rsg.id
- into group_id
- from rhnServerGroup rsg
- where 1=1
- and rsg.org_id = customer_id_in
- and rsg.group_type = group_type_in;
-
- -- preserve the not found status across the rhn_entitlements.prune_group invocation
- wasfound := true;
- if not found then
- wasfound := false;
- end if;
-
- perform rhn_entitlements.prune_group(
- group_id,
- quantity,
- update_family_countsYN
- );
-
- if not wasfound then
- insert into rhnServerGroup (
- id, name, description, max_members, current_members,
- group_type, org_id, created, modified
- ) (
- select nextval('rhn_server_group_id_seq'), name, name,
- quantity, 0, id, customer_id_in,
- current_timestamp, current_timestamp
- from rhnServerGroupType
- where id = group_type_in
- );
- end if;
-
- end$$
-language plpgsql;
-
- -- *******************************************************************
- -- PROCEDURE: prune_family
- -- Unsubscribes servers consuming physical slots from the channel family
- -- that are over the org's limit.
- -- Called by: set_family_count
- -- *******************************************************************
- create or replace function prune_family (
- customer_id_in in numeric,
- channel_family_id_in in numeric,
- quantity_in in numeric,
- flex_in in numeric
- ) returns void
-as $$
- declare
- serverchannels cursor(tmp_quantity numeric, is_fve_in char) for
- select sc.server_id,
- sc.channel_id
- from rhnServerChannel sc,
- rhnChannelFamilyMembers cfm
- where 1=1
- and cfm.channel_family_id = channel_family_id_in
- and cfm.channel_id = sc.channel_id
- and server_id in (
- select rs.id as server_id
- from
- rhnServerChannel rsc,
- rhnChannelFamilyMembers rcfm,
- rhnServer rs
- where 1=1
- and rs.org_id = customer_id_in
- and rs.id = rsc.server_id
- and rsc.channel_id = rcfm.channel_id
- and rcfm.channel_family_id = channel_family_id_in
- and rsc.is_fve = is_fve_in
- -- we only want to grab servers consuming
- -- physical slots.
- and exists (
- select 1
- from rhnChannelFamilyServerPhysical cfsp
- where cfsp.server_id = rs.id
- and cfsp.channel_family_id =
- channel_family_id_in
- )
- order by rcfm.modified asc
- offset quantity_in
- );
- begin
- -- if we get a null customer_id, this is completely bogus.
- if customer_id_in is null then
- return;
- end if;
-
- for sc in serverchannels(quantity_in, 'N') loop
- perform rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id,
- 1, 1, 0, 0);
- end loop;
-
- for sc in serverchannels(flex_in, 'Y') loop
- perform rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id,
- 1, 1, 0, 0);
- end loop;
-
- perform rhn_channel.update_family_counts(channel_family_id_in, customer_id_in);
- end$$
-language plpgsql;
-
- create or replace function set_family_count (
- customer_id_in in numeric, -- customer_id
- channel_family_id_in in numeric, -- 246
- quantity_in in numeric, -- 3
- flex_in in numeric
- ) returns void
-as $$
- declare
- privperms cursor for
- select 1
- from rhnPrivateChannelFamily
- where org_id = customer_id_in
- and channel_family_id = channel_family_id_in;
- pubperms cursor for
- select o.id org_id
- from web_customer o,
- rhnPublicChannelFamily pcf
- where pcf.channel_family_id = channel_family_id_in;
- quantity numeric;
- done numeric := 0;
- flex numeric;
- begin
- quantity := quantity_in;
- if quantity is not null and quantity < 0 then
- quantity := 0;
- end if;
- flex := flex_in;
- if flex is not null and flex < 0 then
- flex := 0;
- end if;
-
- if customer_id_in is not null then
- for perm in privperms loop
- perform rhn_entitlements.prune_family(
- customer_id_in,
- channel_family_id_in,
- quantity,
- flex
- );
-
- if quantity is null and flex is null then
- delete from rhnPrivateChannelFamily
- where org_id = customer_id_in
- and channel_family_id = channel_family_id_in;
- else
- update rhnPrivateChannelFamily
- set max_members = quantity
- where org_id = customer_id_in
- and channel_family_id = channel_family_id_in;
-
- update rhnPrivateChannelFamily
- set fve_max_members = flex
- where org_id = customer_id_in
- and channel_family_id = channel_family_id_in;
- end if;
- return;
- end loop;
-
- insert into rhnPrivateChannelFamily (
- channel_family_id, org_id, max_members, current_members, fve_max_members, fve_current_members
- ) values (
- channel_family_id_in, customer_id_in, quantity, 0, flex, 0 );
- return;
- end if;
-
- for perm in pubperms loop
- if quantity = 0 then
- perform rhn_entitlements.prune_family(
- perm.org_id,
- channel_family_id_in,
- quantity,
- flex
- );
- if done = 0 then
- delete from rhnPublicChannelFamily
- where channel_family_id = channel_family_id_in;
- end if;
- end if;
- done := 1;
- end loop;
- -- if done's not 1, then we don't have any entitlements
- if done != 1 then
- insert into rhnPublicChannelFamily (
- channel_family_id
- ) values (
- channel_family_id_in
- );
- end if;
- end$$
-language plpgsql;
-
- -- this expects quantity_in to be the number of available slots, not the
- -- max_members of the server group. If you give it too many, it'll fail
- -- and raise servergroup_max_members.
- -- We should NEVER run this unless we're SURE that we won't
- -- be violating the max.
- create or replace function entitle_last_modified_servers (
- customer_id_in in numeric, -- customer_id
- type_label_in in varchar, -- 'enterprise_entitled'
- quantity_in in numeric -- 3
- ) returns void
-as $$
- declare
- -- find the servers that aren't currently in slots
- servers cursor(cid_in numeric, quant_in numeric) for
- select rs.id as server_id
- from rhnServer rs
- where 1=1
- and rs.org_id = cid_in
- and not exists (
- select 1
- from rhnServerGroup sg,
- rhnServerGroupMembers rsgm
- where rsgm.server_id = rs.id
- and rsgm.server_group_id = sg.id
- and sg.group_type is not null
- )
- and not exists (
- select 1
- from rhnVirtualInstance vi
- where vi.virtual_system_id =
- rs.id
- )
- order by modified desc
- limit quant_in;
- begin
- for server in servers(customer_id_in, quantity_in) loop
- perform rhn_entitlements.entitle_server(server.server_id, type_label_in);
- end loop;
- end$$
-language plpgsql;
-
- create or replace function subscribe_newest_servers (
- customer_id_in in numeric
- ) returns void
-as $$
- declare
- -- find servers without base channels
- servers cursor(cid_in numeric) for
- select s.id
- from rhnServer s
- where 1=1
- and s.org_id = cid_in
- and not exists (
- select 1
- from rhnChannel c,
- rhnServerChannel sc
- where sc.server_id = s.id
- and sc.channel_id = c.id
- and c.parent_channel is null
- )
- and not exists (
- select 1
- from rhnVirtualInstance vi
- where vi.virtual_system_id = s.id
- )
- order by s.modified desc;
- channel_id numeric;
- begin
- for server in servers(customer_id_in) loop
- channel_id := rhn_channel.guess_server_base(server.id);
- if channel_id is not null then
- begin
- perform rhn_channel.subscribe_server(server.id, channel_id);
- -- exception is really channel_family_no_subscriptions
- exception
- when others then
- null;
- end;
- end if;
- end loop;
- end$$
-language plpgsql;
-
-
--- restore the original setting
-update pg_settings set setting = overlay( setting placing '' from 1 for (length('rhn_entitlements')+1) ) where name = 'search_path';
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.sql.oracle
new file mode 100644
index 0000000..d694b34
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.sql.oracle
@@ -0,0 +1,1777 @@
+--
+-- Copyright (c) 2008--2012 Red Hat, Inc.
+--
+-- This software is licensed to you under the GNU General Public License,
+-- version 2 (GPLv2). There is NO WARRANTY for this software, express or
+-- implied, including the implied warranties of MERCHANTABILITY or FITNESS
+-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+-- along with this software; if not, see
+-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+--
+-- Red Hat trademarks are not licensed under GPLv2. No permission is
+-- granted to use or replicate Red Hat trademarks that are incorporated
+-- in this software or its documentation.
+--
+--
+--
+--
+
+create or replace
+package body rhn_entitlements
+is
+ body_version varchar2(100) := '';
+
+ function find_compatible_sg (
+ server_id_in in number,
+ type_label_in in varchar2
+ ) return number is
+
+ cursor servergroups is
+ select sg.id id
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServer s,
+ rhnServerServerGroupArchCompat ssgac
+ where s.id = server_id_in
+ and s.org_id = sg.org_id
+ and sgt.label = type_label_in
+ and sg.group_type = sgt.id
+ and ssgac.server_group_type = sgt.id
+ and ssgac.server_arch_id = s.server_arch_id
+ and not exists (
+ select 1
+ from rhnServerGroupMembers sgm
+ where sgm.server_group_id = sg.id
+ and sgm.server_id = s.id);
+
+
+ begin
+ for servergroup in servergroups loop
+ return servergroup.id;
+ end loop;
+
+ --no servergroup found
+ return null;
+ end find_compatible_sg;
+
+
+ -- *******************************************************************
+ -- PROCEDURE: remove_org_entitlements
+ --
+ -- Removes both system entitlements and channel subscriptions
+ -- that are currently assigned to an org and re-assigns to the
+ -- master org (org_id = 1).
+ --
+ -- When we call this we expect everything to already be unentitled
+ -- which shoul be handled by delete_org.
+ --
+ -- Called by: delete_org
+ -- *******************************************************************
+ procedure remove_org_entitlements(
+ org_id_in in number
+ )
+ is
+
+ cursor system_ents is
+ select sg.id, sg.max_members, sg.group_type
+ from rhnServerGroup sg
+ where group_type is not null
+ and org_id = org_id_in;
+
+ cursor channel_subs is
+ select pcf.channel_family_id, pcf.max_members
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.org_id is null;
+
+ begin
+
+ for system_ent in system_ents loop
+ update rhnServerGroup
+ set max_members = max_members + system_ent.max_members
+ where org_id = 1
+ and group_type = system_ent.group_type;
+ end loop;
+
+ update rhnServerGroup
+ set max_members = 0
+ where org_id = org_id_in;
+
+ for channel_sub in channel_subs loop
+ update rhnPrivateChannelFamily
+ set max_members = max_members + channel_sub.max_members
+ where org_id = 1
+ and channel_family_id = channel_sub.channel_family_id;
+ end loop;
+
+ update rhnPrivateChannelFamily
+ set max_members = 0
+ where org_id = org_id_in;
+
+ end remove_org_entitlements;
+
+ function entitlement_grants_service (
+ entitlement_in in varchar2,
+ service_level_in in varchar2
+ ) return number is
+ begin
+ if service_level_in = 'provisioning' then
+ if entitlement_in = 'provisioning_entitled' then
+ return 1;
+ else
+ return 0;
+ end if;
+ elsif service_level_in = 'management' then
+ if entitlement_in = 'enterprise_entitled' then
+ return 1;
+ else
+ return 0;
+ end if;
+ elsif service_level_in = 'monitoring' then
+ if entitlement_in = 'monitoring_entitled' then
+ return 1;
+ end if;
+ elsif service_level_in = 'updates' then
+ return 1;
+ else
+ return 0;
+ end if;
+ end entitlement_grants_service;
+
+ function lookup_entitlement_group (
+ org_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ ) return number is
+ cursor server_groups is
+ select sg.id server_group_id
+ from rhnServerGroup sg,
+ rhnServerGroupType sgt
+ where sgt.label = type_label_in
+ and sgt.id = sg.group_type
+ and sg.org_id = org_id_in;
+ begin
+ for sg in server_groups loop
+ return sg.server_group_id;
+ end loop;
+ return rhn_entitlements.create_entitlement_group(
+ org_id_in,
+ type_label_in
+ );
+ end lookup_entitlement_group;
+
+ function create_entitlement_group (
+ org_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ ) return number is
+ sg_id_val number;
+ begin
+ select rhn_server_group_id_seq.nextval
+ into sg_id_val
+ from dual;
+
+ insert into rhnServerGroup (
+ id, name, description, max_members, current_members,
+ group_type, org_id
+ ) (
+ select sg_id_val, sgt.label, sgt.label,
+ 0, 0, sgt.id, org_id_in
+ from rhnServerGroupType sgt
+ where sgt.label = type_label_in
+ );
+
+ return sg_id_val;
+ end create_entitlement_group;
+
+ function can_entitle_server (
+ server_id_in in number,
+ type_label_in in varchar2 )
+ return number is
+ cursor addon_servergroups (base_label_in in varchar2,
+ addon_label_in in varchar2) is
+ select
+ addon_id
+ from
+ rhnSGTypeBaseAddonCompat
+ where base_id = lookup_sg_type (base_label_in)
+ and addon_id = lookup_sg_type (addon_label_in);
+
+ previous_ent rhn_entitlements.ents_array;
+ is_base_in char := 'N';
+ is_base_current char := 'N';
+ i number := 0;
+ sgid number := 0;
+
+ begin
+
+ previous_ent := rhn_entitlements.ents_array();
+ previous_ent := rhn_entitlements.get_server_entitlement(server_id_in);
+
+ select distinct is_base
+ into is_base_in
+ from rhnServerGroupType
+ where label = type_label_in;
+
+ if previous_ent.count = 0 then
+ sgid := find_compatible_sg (server_id_in, type_label_in);
+ if (is_base_in = 'Y' and sgid is not null) then
+ -- rhn_server.insert_into_servergroup (server_id_in, sgid);
+ return 1;
+ else
+ -- rhn_exception.raise_exception ('invalid_base_entitlement');
+ return 0;
+ end if;
+
+ -- there are previous ents, first make sure we're not trying to entitle a base ent
+ elsif is_base_in = 'Y' then
+ -- rhn_exception.raise_exception ('invalid_addon_entitlement');
+ return 0;
+
+ -- it must be an addon, so proceed with the entitlement
+ else
+
+ -- find the servers base ent
+ is_base_current := 'N';
+ i := 0;
+ while is_base_current = 'N' and i <= previous_ent.count
+ loop
+ i := i + 1;
+ select is_base
+ into is_base_current
+ from rhnServerGroupType
+ where label = previous_ent(i);
+ end loop;
+
+ -- never found a base ent, that would be strange
+ if is_base_current = 'N' then
+ -- rhn_exception.raise_exception ('invalid_base_entitlement');
+ return 0;
+ end if;
+
+ -- this for loop verifies the validity of the addon path
+ for addon_servergroup in addon_servergroups (previous_ent(i), type_label_in) loop
+ -- find an appropriate sgid for the addon and entitle the server
+ sgid := find_compatible_sg (server_id_in, type_label_in);
+ if sgid is not null then
+ -- rhn_server.insert_into_servergroup (server_id_in, sgid);
+ return 1;
+ else
+ -- rhn_exception.raise_exception ('invalid_addon_entitlement');
+ return 0;
+ end if;
+ end loop;
+
+ end if;
+
+ return 0;
+
+ end can_entitle_server;
+
+ function can_switch_base (
+ server_id_in in integer,
+ type_label_in in varchar2
+ ) return number is
+
+ type_label_in_is_base char(1);
+ sgid number;
+
+ begin
+
+ begin
+ select is_base into type_label_in_is_base
+ from rhnServerGroupType
+ where label = type_label_in;
+ exception
+ when no_data_found then
+ rhn_exception.raise_exception ( 'invalid_entitlement' );
+ end;
+
+ if type_label_in_is_base = 'N' then
+ rhn_exception.raise_exception ( 'invalid_entitlement' );
+ else
+ sgid := find_compatible_sg ( server_id_in, type_label_in );
+ if sgid is not null then
+ return 1;
+ else
+ return 0;
+ end if;
+ end if;
+
+ end can_switch_base;
+
+
+ procedure entitle_server (
+ server_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ ) is
+ sgid number := 0;
+ is_virt number := 0;
+
+ begin
+
+ begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+ exception
+ when no_data_found then
+ is_virt := 0;
+ end;
+
+ if is_virt = 0 and (type_label_in = 'virtualization_host' or
+ type_label_in = 'virtualization_host_platform') then
+
+ is_virt := 1;
+ end if;
+
+
+
+ if rhn_entitlements.can_entitle_server(server_id_in,
+ type_label_in) = 1 then
+ sgid := find_compatible_sg (server_id_in, type_label_in);
+ if sgid is not null then
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( rhn_event_id_seq.nextval, server_id_in,
+ 'added system entitlement ',
+ case type_label_in
+ when 'enterprise_entitled' then 'Management'
+ when 'sw_mgr_entitled' then 'Update'
+ when 'provisioning_entitled' then 'Provisioning'
+ when 'monitoring_entitled' then 'Monitoring'
+ when 'virtualization_host' then 'Virtualization'
+ when 'virtualization_host_platform' then
+ 'Virtualization Platform' end );
+
+ rhn_server.insert_into_servergroup (server_id_in, sgid);
+
+ if is_virt = 1 then
+ rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+
+ else
+ rhn_exception.raise_exception ('no_available_server_group');
+ end if;
+ else
+ rhn_exception.raise_exception ('invalid_entitlement');
+ end if;
+ end entitle_server;
+
+ procedure remove_server_entitlement (
+ server_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled',
+ repoll_virt_guests in number := 1
+ ) is
+ group_id number;
+ type_is_base char;
+ is_virt number := 0;
+ begin
+ begin
+
+
+ -- would be nice if there were a virt attribute of entitlement types, not have to specify 2 different ones...
+ begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+ exception
+ when no_data_found then
+ is_virt := 0;
+ end;
+
+ select sg.id, sgt.is_base
+ into group_id, type_is_base
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm,
+ rhnServer s
+ where s.id = server_id_in
+ and s.id = sgm.server_id
+ and sgm.server_group_id = sg.id
+ and sg.org_id = s.org_id
+ and sgt.label = type_label_in
+ and sgt.id = sg.group_type;
+
+ if ( type_is_base = 'Y' ) then
+ -- unentitle_server should handle everything, don't really need to do anything else special here
+ unentitle_server ( server_id_in );
+ else
+
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( rhn_event_id_seq.nextval, server_id_in,
+ 'removed system entitlement ',
+ case type_label_in
+ when 'enterprise_entitled' then 'Management'
+ when 'sw_mgr_entitled' then 'Update'
+ when 'provisioning_entitled' then 'Provisioning'
+ when 'monitoring_entitled' then 'Monitoring'
+ when 'virtualization_host' then 'Virtualization'
+ when 'virtualization_host_platform' then
+ 'Virtualization Platforrm' end );
+
+ rhn_server.delete_from_servergroup(server_id_in, group_id);
+
+ if type_label_in = 'monitoring_entitled' then
+ DELETE
+ FROM rhn_probe
+ WHERE recid IN (SELECT probe_id
+ FROM rhn_check_probe
+ WHERE host_id = server_id_in);
+ end if;
+
+ if is_virt = 1 and repoll_virt_guests = 1 then
+ rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+ end if;
+
+ exception
+ when no_data_found then
+ rhn_exception.raise_exception('invalid_server_group_member');
+ end;
+
+ end remove_server_entitlement;
+
+
+ procedure unentitle_server (server_id_in in number) is
+
+ cursor servergroups is
+ select distinct sgt.label, sg.id server_group_id
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServer s,
+ rhnServerGroupMembers sgm
+ where s.id = server_id_in
+ and s.org_id = sg.org_id
+ and sg.group_type = sgt.id
+ and sgm.server_group_id = sg.id
+ and sgm.server_id = s.id;
+
+ is_virt number := 0;
+
+ begin
+
+ begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+ exception
+ when no_data_found then
+ is_virt := 0;
+ end;
+
+ for servergroup in servergroups loop
+
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( rhn_event_id_seq.nextval, server_id_in,
+ 'removed system entitlement ',
+ case servergroup.label
+ when 'enterprise_entitled' then 'Management'
+ when 'sw_mgr_entitled' then 'Update'
+ when 'provisioning_entitled' then 'Provisioning'
+ when 'monitoring_entitled' then 'Monitoring'
+ when 'virtualization_host' then 'Virtualization'
+ when 'virtualization_host_platform' then
+ 'Virtualization Platform' end );
+
+ rhn_server.delete_from_servergroup(server_id_in,
+ servergroup.server_group_id );
+ end loop;
+
+ if is_virt = 1 then
+ rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+
+ end unentitle_server;
+
+
+ -- *******************************************************************
+ -- PROCEDURE: repoll_virt_guest_entitlements
+ --
+ -- Whenever we add/remove a virtualization_host* entitlement from
+ -- a host, we can call this procedure to update what type of slots
+ -- the guests are consuming.
+ --
+ -- If you're removing the entitlement, it's
+ -- possible the guests will become unentitled if you don't have enough
+ -- physical slots to cover them.
+ --
+ -- If you're adding the entitlement, you end up freeing up physical
+ -- slots for other systems.
+ --
+ -- *******************************************************************
+ procedure repoll_virt_guest_entitlements(server_id_in in number)
+ is
+
+ -- All channel families associated with the guests of server_id_in
+ cursor families is
+ select distinct cfs.channel_family_id
+ from
+ rhnChannelFamilyServers cfs,
+ rhnVirtualInstance vi
+ where
+ vi.host_system_id = server_id_in
+ and vi.virtual_system_id = cfs.server_id;
+
+ -- All of server group types associated with the guests of
+ -- server_id_in
+ cursor group_types is
+ select distinct sg.group_type, sgt.label
+ from
+ rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm,
+ rhnVirtualInstance vi
+ where
+ vi.host_system_id = server_id_in
+ and vi.virtual_system_id = sgm.server_id
+ and sgm.server_group_id = sg.id
+ and sg.group_type = sgt.id;
+
+ -- Virtual servers from a certain family belonging to a speicifc
+ -- host that are consuming physical channel slots over the limit.
+ cursor virt_servers_cfam(family_id_in in number, quantity_in in number) is
+ select virtual_system_id
+ from (
+ select rownum, vi.virtual_system_id
+ from
+ rhnChannelFamilyMembers cfm,
+ rhnServerChannel sc,
+ rhnVirtualInstance vi
+ where
+ vi.host_system_id = server_id_in
+ and vi.virtual_system_id = sc.server_id
+ and sc.channel_id = cfm.channel_id
+ and cfm.channel_family_id = family_id_in
+ order by sc.modified desc
+ )
+ where rownum <= quantity_in;
+
+ -- Virtual servers from a certain family belonging to a speicifc
+ -- host that are consuming physical system slots over the limit.
+ cursor virt_servers_sgt(group_type_in in number, quantity_in in number) is
+ select virtual_system_id
+ from (
+ select rownum, vi.virtual_system_id
+ from
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm,
+ rhnVirtualInstance vi
+ where
+ vi.host_system_id = server_id_in
+ and vi.virtual_system_id = sgm.server_id
+ and sgm.server_group_id = sg.id
+ and sg.group_type = group_type_in
+ order by sgm.modified desc
+ )
+ where rownum <= quantity_in;
+ -- Get the orgs of Virtual guests
+ -- Since they may belong to different orgs
+ cursor virt_guest_orgs is
+ select distinct (s.org_id)
+ from rhnServer s
+ inner join rhnVirtualInstance vi on vi.virtual_system_id = s.id
+ where
+ vi.host_system_id = server_id_in
+ and s.org_id <> (select s1.org_id from rhnServer s1 where s1.id = vi.host_system_id) ;
+
+
+ org_id_val number;
+ max_members_val number;
+ max_flex_val number;
+ current_members_calc number;
+ sg_id number;
+ is_virt number := 0;
+ begin
+ begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+ exception
+ when no_data_found then
+ is_virt := 0;
+ end;
+
+ select org_id
+ into org_id_val
+ from rhnServer
+ where id = server_id_in;
+
+ -- deal w/ channel entitlements first ...
+ for family in families loop
+ if is_virt = 0 then
+ -- if the host_server does not have virt
+ --- find all possible flex slots
+ -- and set each of the flex eligible guests to Y
+ UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
+ where sc.server_id in (
+ select virtual_system_id from (
+ select rownum, vi.virtual_system_id, sfc.max_members - sfc.current_members as free_slots
+ from rhnServerFveCapable sfc
+ inner join rhnVirtualInstance vi on vi.virtual_system_id = sfc.server_id
+ where vi.host_system_id = server_id_in
+ and sfc.channel_family_id = family.channel_family_id
+ order by vi.modified desc
+ )
+ where rownum <= free_slots
+ );
+ else
+ -- if the host_server has virt
+ -- set all its flex guests to N
+ UPDATE rhnServerChannel sc set sc.is_fve = 'N'
+ where
+ sc.channel_id in (select cfm.channel_id from rhnChannelFamilyMembers cfm
+ where cfm.CHANNEL_FAMILY_ID = family.channel_family_id)
+ and sc.is_fve = 'Y'
+ and sc.server_id in
+ (select vi.virtual_system_id from rhnVirtualInstance vi
+ where vi.host_system_id = server_id_in);
+ end if;
+
+ -- get the current (physical) members of the family
+ current_members_calc :=
+ rhn_channel.channel_family_current_members(family.channel_family_id,
+ org_id_val); -- fixed transposed args
+
+ begin
+
+ -- get the max members of the family
+ select max_members
+ into max_members_val
+ from rhnPrivateChannelFamily
+ where channel_family_id = family.channel_family_id
+ and org_id = org_id_val;
+
+ select fve_max_members
+ into max_flex_val
+ from rhnPrivateChannelFamily
+ where channel_family_id = family.channel_family_id
+ and org_id = org_id_val;
+
+ if current_members_calc > max_members_val then
+ -- A virtualization_host* ent must have been removed, so we'll
+ -- unsubscribe guests from the host first.
+
+ -- hm, i don't think max_members - current_members_calc yielding a negative number
+ -- will work w/ rownum, swaping 'em in the body of this if...
+ for virt_server in virt_servers_cfam(family.channel_family_id,
+ current_members_calc - max_members_val) loop
+
+ rhn_channel.unsubscribe_server_from_family(
+ virt_server.virtual_system_id,
+ family.channel_family_id);
+ end loop;
+
+ -- if we're still over the limit, which would be odd,
+ -- just prune the group to max_members
+ --
+ -- er... wouldn't we actually have to refresh the values of
+ -- current_members_calc and max_members_val to actually ever
+ -- *skip this??
+ if current_members_calc > max_members_val then
+ -- argh, transposed again?!
+ set_family_count(org_id_val,
+ family.channel_family_id,
+ max_members_val, max_flex_val);
+ --TODO calculate this correctly
+ end if;
+
+ end if;
+
+ -- update current_members for the family. This will set the value
+ -- to reflect adding/removing the entitlement.
+ --
+ -- what's the difference of doing this vs the unavoidable set_family_count above?
+ rhn_channel.update_family_counts(family.channel_family_id,
+ org_id_val);
+
+ exception when no_data_found then null;
+ end;
+
+ -- It is possible that the guests belong to a different org than the host
+ -- so we are going to update the family counts in the guests orgs also
+ for org in virt_guest_orgs loop
+ rhn_channel.update_family_counts(family.channel_family_id,
+ org.org_id);
+ end loop;
+ end loop;
+
+ for a_group_type in group_types loop
+ -- get the current *physical* members of the system entitlement type for the org...
+ --
+ -- unlike channel families, it appears the standard rhnServerGroup.max_members represents
+ -- *physical* slots, vs physical+virt ... boy that's confusing...
+
+ select max_members, id
+ into max_members_val, sg_id
+ from rhnServerGroup
+ where group_type = a_group_type.group_type
+ and org_id = org_id_val;
+
+
+ select count(sep.server_id) into current_members_calc
+ from rhnServerEntitlementPhysical sep
+ where sep.server_group_id = sg_id
+ and sep.server_group_type_id = a_group_type.group_type;
+
+ if current_members_calc > max_members_val then
+ -- A virtualization_host* ent must have been removed, and we're over the limit, so unsubscribe guests
+ for virt_server in virt_servers_sgt(a_group_type.group_type,
+ current_members_calc - max_members_val) loop
+ rhn_entitlements.remove_server_entitlement(virt_server.virtual_system_id, a_group_type.label);
+
+ -- decrement current_members_calc, we'll use it to reset current_members for the group at the end...
+ current_members_calc := current_members_calc - 1;
+ end loop;
+
+ end if;
+
+ update rhnServerGroup set current_members = current_members_calc
+ where org_id = org_id_val
+ and group_type = a_group_type.group_type;
+
+ -- I think that's all the house-keeping we have to do...
+ end loop;
+
+ end repoll_virt_guest_entitlements;
+
+
+ function get_server_entitlement (
+ server_id_in in number
+ ) return ents_array is
+
+ cursor server_groups is
+ select sgt.label
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm
+ where 1=1
+ and sgm.server_id = server_id_in
+ and sg.id = sgm.server_group_id
+ and sgt.id = sg.group_type
+ and sgt.label in (
+ 'sw_mgr_entitled','enterprise_entitled',
+ 'provisioning_entitled', 'nonlinux_entitled',
+ 'monitoring_entitled', 'virtualization_host',
+ 'virtualization_host_platform'
+ );
+
+ ent_array ents_array;
+
+ begin
+
+ ent_array := ents_array();
+
+ for sg in server_groups loop
+ ent_array.extend;
+ ent_array(ent_array.count) := sg.label;
+ end loop;
+
+ return ent_array;
+
+ end get_server_entitlement;
+
+
+ -- this desperately needs to be table driven.
+ procedure modify_org_service (
+ org_id_in in number,
+ service_label_in in varchar2,
+ enable_in in char
+ ) is
+ type roles_v is varray(10) of rhnUserGroupType.label%TYPE;
+ roles_to_process roles_v;
+ cursor roles(role_label_in in varchar2) is
+ select label, id
+ from rhnUserGroupType
+ where label = role_label_in;
+ cursor org_roles(role_label_in in varchar2) is
+ select 1
+ from rhnUserGroup ug,
+ rhnUserGroupType ugt
+ where ugt.label = role_label_in
+ and ug.org_id = org_id_in
+ and ugt.id = ug.group_type;
+
+ type ents_v is varray(10) of rhnOrgEntitlementType.label%TYPE;
+ ents_to_process ents_v;
+ cursor ents(ent_label_in in varchar2) is
+ select label, id
+ from rhnOrgEntitlementType
+ where label = ent_label_in;
+ cursor org_ents(ent_label_in in varchar2) is
+ select 1
+ from rhnOrgEntitlements oe,
+ rhnOrgEntitlementType oet
+ where oet.label = ent_label_in
+ and oe.org_id = org_id_in
+ and oet.id = oe.entitlement_id;
+ create_row char(1);
+ begin
+ ents_to_process := ents_v();
+ roles_to_process := roles_v();
+ -- a bit kludgy, but only for 3.4 really. Certainly no
+ -- worse than the old code...
+ if service_label_in = 'enterprise' or
+ service_label_in = 'management' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'sw_mgr_enterprise';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'org_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'system_group_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'activation_key_admin';
+ elsif service_label_in = 'provisioning' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_provisioning';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'system_group_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'activation_key_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'config_admin';
+ -- another nasty special case...
+ if enable_in = 'Y' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'sw_mgr_enterprise';
+ end if;
+ elsif service_label_in = 'monitoring' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_monitor';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'monitoring_admin';
+ elsif service_label_in = 'virtualization' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_virtualization';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'config_admin';
+ elsif service_label_in = 'virtualization_platform' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_virtualization_platform';
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'config_admin';
+ elsif service_label_in = 'nonlinux' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_nonlinux';
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'config_admin';
+ end if;
+
+ if enable_in = 'Y' then
+ for i in 1..ents_to_process.count loop
+ for ent in ents(ents_to_process(i)) loop
+ create_row := 'Y';
+ for oe in org_ents(ent.label) loop
+ create_row := 'N';
+ end loop;
+ if create_row = 'Y' then
+ insert into rhnOrgEntitlements(org_id, entitlement_id)
+ values (org_id_in, ent.id);
+ end if;
+ end loop;
+ end loop;
+ for i in 1..roles_to_process.count loop
+ for role in roles(roles_to_process(i)) loop
+ create_row := 'Y';
+ for o_r in org_roles(role.label) loop
+ create_row := 'N';
+ end loop;
+ if create_row = 'Y' then
+ insert into rhnUserGroup(
+ id, name, description, current_members,
+ group_type, org_id
+ ) (
+ select rhn_user_group_id_seq.nextval,
+ ugt.name || 's',
+ ugt.name || 's for Org ' ||
+ o.name || ' ('|| o.id ||')',
+ 0, ugt.id, o.id
+ from rhnUserGroupType ugt,
+ web_customer o
+ where o.id = org_id_in
+ and ugt.id = role.id
+ );
+ end if;
+ end loop;
+ end loop;
+ else
+ for i in 1..ents_to_process.count loop
+ for ent in ents(ents_to_process(i)) loop
+ delete from rhnOrgEntitlements
+ where org_id = org_id_in
+ and entitlement_id = ent.id;
+ end loop;
+ end loop;
+ end if;
+ end modify_org_service;
+
+ procedure set_customer_enterprise (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'enterprise', 'Y');
+ end set_customer_enterprise;
+
+ procedure set_customer_provisioning (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'provisioning', 'Y');
+ end set_customer_provisioning;
+
+ procedure set_customer_monitoring (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'monitoring', 'Y');
+ end set_customer_monitoring;
+
+ procedure set_customer_nonlinux (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'nonlinux', 'Y');
+ end set_customer_nonlinux;
+
+ procedure unset_customer_enterprise (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'enterprise', 'N');
+ end unset_customer_enterprise;
+
+ procedure unset_customer_provisioning (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'provisioning', 'N');
+ end unset_customer_provisioning;
+
+ procedure unset_customer_monitoring (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'monitoring', 'N');
+ end unset_customer_monitoring;
+
+ procedure unset_customer_nonlinux (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'nonlinux', 'N');
+ end unset_customer_nonlinux;
+
+ -- *******************************************************************
+ -- PROCEDURE: prune_group
+ -- Unsubscribes servers consuming physical slots that over the org's
+ -- limit.
+ -- Called by: set_server_group_count, repoll_virt_guest_entitlements
+ -- *******************************************************************
+ procedure prune_group (
+ group_id_in in number,
+ quantity_in in number,
+ update_family_countsYN in number := 1
+ ) is
+ cursor servergroups is
+ select server_id, server_group_id, sgt.id as group_type_id, sgt.label
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm
+ where 1=1
+ and sgm.server_group_id = group_id_in
+ and sgm.server_id in (
+ select server_id
+ from (
+ select rownum row_number,
+ server_id,
+ time
+ from (
+ select sep.server_id,
+ sep.modified time
+ from
+ rhnServerEntitlementPhysical sep
+ where
+ sep.server_group_id = group_id_in
+ order by time asc
+ )
+ )
+ where row_number > quantity_in
+ )
+ and sgm.server_group_id = sg.id
+ and sg.group_type = sgt.id;
+ type_is_base char;
+ begin
+ update rhnServerGroup
+ set max_members = quantity_in
+ where id = group_id_in;
+
+ for sg in servergroups loop
+ remove_server_entitlement(sg.server_id, sg.label);
+
+ select is_base
+ into type_is_base
+ from rhnServerGroupType sgt
+ where sgt.id = sg.group_type_id;
+
+ -- if we're removing a base ent, then be sure to
+ -- remove the server's channel subscriptions.
+ if ( type_is_base = 'Y' ) then
+ rhn_channel.clear_subscriptions(sg.server_id,
+ update_family_countsYN => update_family_countsYN);
+ end if;
+
+ end loop;
+ end prune_group;
+
+ procedure set_server_group_count (
+ customer_id_in in number,
+ group_type_in in number,
+ quantity_in in number,
+ update_family_countsYN in number := 1
+ ) is
+ group_id number;
+ quantity number;
+ begin
+ quantity := quantity_in;
+ if quantity is not null and quantity < 0 then
+ quantity := 0;
+ end if;
+
+ select rsg.id
+ into group_id
+ from rhnServerGroup rsg
+ where 1=1
+ and rsg.org_id = customer_id_in
+ and rsg.group_type = group_type_in;
+
+ rhn_entitlements.prune_group(
+ group_id,
+ quantity,
+ update_family_countsYN
+ );
+ exception
+ when no_data_found then
+ insert into rhnServerGroup (
+ id, name, description, max_members, current_members,
+ group_type, org_id, created, modified
+ ) (
+ select rhn_server_group_id_seq.nextval, name, name,
+ quantity, 0, id, customer_id_in,
+ current_timestamp, current_timestamp
+ from rhnServerGroupType
+ where id = group_type_in
+ );
+ end set_server_group_count;
+
+ -- *******************************************************************
+ -- PROCEDURE: assign_system_entitlement
+ --
+ -- Moves system entitlements from from_org_id_in to to_org_id_in.
+ -- Can raise not_enough_entitlements_in_base_org if from_org_id_in
+ -- does not have enough entitlements to cover the move.
+ -- Takes care of unentitling systems if necessary by calling
+ -- set_server_group_count
+ -- *******************************************************************
+ procedure assign_system_entitlement(
+ group_label_in in varchar2,
+ from_org_id_in in number,
+ to_org_id_in in number,
+ quantity_in in number
+ )
+ is
+ prev_ent_count number;
+ to_org_prev_ent_count number;
+ new_ent_count number;
+ new_quantity number;
+ group_type number;
+ begin
+
+ begin
+ select max_members
+ into prev_ent_count
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg
+ where sg.org_id = from_org_id_in
+ and sg.group_type = sgt.id
+ and sgt.label = group_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end;
+
+ begin
+ select max_members
+ into to_org_prev_ent_count
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg
+ where sg.org_id = to_org_id_in
+ and sg.group_type = sgt.id
+ and sgt.label = group_label_in;
+ exception
+ when NO_DATA_FOUND then
+ to_org_prev_ent_count := 0;
+ end;
+
+ begin
+ select id
+ into group_type
+ from rhnServerGroupType
+ where label = group_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'invalid_server_group');
+ end;
+
+ new_ent_count := prev_ent_count - quantity_in;
+
+ if prev_ent_count > new_ent_count then
+ new_quantity := to_org_prev_ent_count + quantity_in;
+ end if;
+
+ if new_ent_count < 0 then
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end if;
+
+
+ set_server_group_count(from_org_id_in,
+ group_type,
+ new_ent_count);
+
+ set_server_group_count(to_org_id_in,
+ group_type,
+ new_quantity);
+
+ -- Create or delete the entries in rhnOrgEntitlementType
+ if group_label_in = 'enterprise_entitled' then
+ if new_quantity > 0 then
+ set_customer_enterprise(to_org_id_in);
+ else
+ unset_customer_enterprise(to_org_id_in);
+ end if;
+ end if;
+
+ if group_label_in = 'provisioning_entitled' then
+ if new_quantity > 0 then
+ set_customer_provisioning(to_org_id_in);
+ else
+ unset_customer_provisioning(to_org_id_in);
+ end if;
+ end if;
+
+ if group_label_in = 'monitoring_entitled' then
+ if new_quantity > 0 then
+ set_customer_monitoring(to_org_id_in);
+ else
+ unset_customer_monitoring(to_org_id_in);
+ end if;
+ end if;
+
+ end assign_system_entitlement;
+
+ -- *******************************************************************
+ -- PROCEDURE: assign_channel_entitlement
+ --
+ -- Moves channel entitlements from from_org_id_in to to_org_id_in.
+ -- Can raise not_enough_entitlements_in_base_org if from_org_id_in
+ -- does not have enough entitlements to cover the move.
+ -- Takes care of unentitling systems if necessary by calling
+ -- set_family_count
+ -- *******************************************************************
+ procedure assign_channel_entitlement(
+ channel_family_label_in in varchar2,
+ from_org_id_in in number,
+ to_org_id_in in number,
+ quantity_in in number,
+ flex_in in number
+ )
+ is
+ from_org_prev_ent_count number;
+ from_org_prev_ent_count_flex number;
+ new_ent_count number;
+ new_ent_count_flex number;
+ to_org_prev_ent_count number;
+ to_org_prev_ent_count_flex number;
+ new_quantity number;
+ new_flex number;
+ cfam_id number;
+ begin
+
+ begin
+ select max_members
+ into from_org_prev_ent_count
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = from_org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end;
+
+ begin
+ select max_members
+ into to_org_prev_ent_count
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = to_org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ to_org_prev_ent_count := 0;
+ end;
+
+ begin
+ select fve_max_members
+ into from_org_prev_ent_count_flex
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = from_org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'not_enough_flex_entitlements_in_base_org');
+ end;
+
+ begin
+ select fve_max_members
+ into to_org_prev_ent_count_flex
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = to_org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ to_org_prev_ent_count_flex := 0;
+ end;
+
+ begin
+ select id
+ into cfam_id
+ from rhnChannelFamily
+ where label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'invalid_channel_family');
+ end;
+
+ new_ent_count := from_org_prev_ent_count - quantity_in;
+ new_ent_count_flex := from_org_prev_ent_count_flex - flex_in;
+
+ if from_org_prev_ent_count >= new_ent_count then
+ new_quantity := to_org_prev_ent_count + quantity_in;
+ end if;
+
+ if from_org_prev_ent_count_flex >= new_ent_count_flex then
+ new_flex := to_org_prev_ent_count_flex + flex_in;
+ end if;
+
+
+ if new_ent_count < 0 then
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end if;
+
+ if new_ent_count_flex < 0 then
+ rhn_exception.raise_exception(
+ 'not_enough_flex_entitlements_in_base_org');
+ end if;
+
+
+
+ rhn_entitlements.set_family_count(from_org_id_in, cfam_id,
+ new_ent_count, new_ent_count_flex);
+
+ rhn_entitlements.set_family_count(to_org_id_in,
+ cfam_id,
+ new_quantity, new_flex);
+
+ end assign_channel_entitlement;
+
+ -- *******************************************************************
+ -- PROCEDURE: activate_system_entitlement
+ --
+ -- Sets the values in rhnServerGroup for a given rhnServerGroupType.
+ --
+ -- Calls: set_server_group_count to update, prune, or create the group.
+ -- Called by: the code that activates a satellite cert.
+ --
+ -- Raises not_enough_entitlements_in_base_org if all entitlements
+ -- in the org are used so the free entitlements would not cover
+ -- the difference when descreasing the number of entitlements.
+ -- *******************************************************************
+ procedure activate_system_entitlement(
+ org_id_in in number,
+ group_label_in in varchar2,
+ quantity_in in number
+ )
+ is
+ prev_ent_count number;
+ prev_ent_count_sum number;
+ group_type number;
+ begin
+
+ -- Fetch the current entitlement count for the org
+ -- into prev_ent_count
+ begin
+ select current_members
+ into prev_ent_count
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg
+ where sg.group_type = sgt.id
+ and sgt.label = group_label_in
+ and sg.org_id = org_id_in;
+ exception
+ when NO_DATA_FOUND then
+ prev_ent_count := 0;
+ end;
+
+ begin
+ select id
+ into group_type
+ from rhnServerGroupType
+ where label = group_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'invalid_server_group');
+ end;
+
+ -- If we're setting the total entitlemnt count to a lower value,
+ -- and that value is less than the allocated count in this org,
+ -- we need to raise an exception.
+ if quantity_in < prev_ent_count then
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ else
+ -- don't update family counts after every server
+ -- will do bulk update afterwards
+ set_server_group_count(org_id_in,
+ group_type,
+ quantity_in,
+ update_family_countsYN => 0);
+ -- bulk update family counts
+ rhn_channel.update_group_family_counts(group_label_in, org_id_in);
+ end if;
+
+
+ end activate_system_entitlement;
+
+ -- *******************************************************************
+ -- PROCEDURE: activate_channel_entitlement
+ --
+ -- Calls: set_family_count to update, prune, or create the family
+ -- permission bucket.
+ -- Called by: the code that activates a satellite cert.
+ --
+ -- Raises not_enough_entitlements_in_base_org if there are not enough
+ -- entitlements in the org to cover the difference when you are
+ -- descreasing the number of entitlements.
+ --
+ -- The backend code in Python is expected to do whatever arithmetics
+ -- is needed.
+ -- *******************************************************************
+ procedure activate_channel_entitlement(
+ org_id_in in number,
+ channel_family_label_in in varchar2,
+ quantity_in in number,
+ flex_in in number
+
+ )
+ is
+ prev_ent_count number;
+ prev_flex_count number;
+ prev_ent_count_sum number;
+ cfam_id number;
+ reduce_quantity number;
+ total_flex_capable number;
+ cursor to_convert_reg (channel_family_id_val in number, org_id_in in number, quantity in number)
+ is
+ select SC.server_id
+ from rhnServerChannel SC inner join
+ rhnServer S on S.id = SC.server_id
+ where
+ is_fve = 'Y'
+ and S.org_id = org_id_in
+ and SC.channel_id in
+ (select cfm.channel_id from rhnChannelFamilyMembers cfm
+ where cfm.CHANNEL_FAMILY_ID = channel_family_id_val)
+ and rownum <= quantity;
+ cursor to_convert_flex (channel_family_id_val in number, org_id_in in number, quantity in number)
+ is
+ select server_id
+ from rhnServerFveCapable
+ where SERVER_ORG_ID = org_id_in and
+ channel_family_id = cfam_id and
+ rownum <= quantity;
+
+ begin
+
+ -- Fetch the current entitlement count for the org
+ -- into prev_ent_count
+ begin
+ select current_members
+ into prev_ent_count
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ prev_ent_count := 0;
+ end;
+
+ begin
+ select pcf.fve_current_members
+ into prev_flex_count
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ prev_flex_count := 0;
+ end;
+
+
+ begin
+ select id
+ into cfam_id
+ from rhnChannelFamily
+ where label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'invalid_channel_family');
+ end;
+
+ -- if there are too few flex entitlements
+ if flex_in < prev_flex_count then
+ -- and if the extra we need is less than or equal to our extra regular entitlements
+ if prev_flex_count - flex_in <= quantity_in - prev_ent_count then
+ reduce_quantity := prev_flex_count - flex_in;
+ -- We need to convert some systems from flex guest to regular
+ for system in to_convert_reg(cfam_id, org_id_in, reduce_quantity) loop
+ --rhn_channel.convert_to_regular(system.server_id, cfam_id);
+ UPDATE rhnServerChannel sc set sc.is_fve = 'N'
+ where sc.server_id = system.server_id
+ and sc.channel_id in (select cfm.channel_id
+ from rhnChannelFamilyMembers cfm
+ where cfm.channel_family_id = cfam_id);
+ end loop;
+
+ --reset previous counts
+ prev_ent_count := prev_ent_count + reduce_quantity;
+ prev_flex_count := prev_flex_count - reduce_quantity;
+ else
+ rhn_exception.raise_exception(
+ 'not_enough_flex_entitlements_in_base_org');
+ end if;
+ end if;
+
+ -- if there are too few regular entitlements, and extra flex entitlements
+ if quantity_in < prev_ent_count and prev_flex_count < flex_in then
+ -- how many flex-capable systems (that aren't using flex) do we have
+ select count(*)
+ into total_flex_capable
+ from rhnServerFveCapable
+ where SERVER_ORG_ID = org_id_in and
+ channel_family_id = cfam_id;
+ -- if we have enough flex capable machines that is at least
+ -- as many as what we are over on
+ if total_flex_capable >= prev_ent_count - quantity_in then
+ reduce_quantity := prev_ent_count - quantity_in;
+ for system in to_convert_flex(cfam_id, org_id_in, reduce_quantity) loop
+-- rhn_channel.convert_to_fve(system.server_id, cfam_id);
+ UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
+ where sc.server_id = system.server_id
+ and sc.channel_id in (select cfm.channel_id
+ from rhnChannelFamilyMembers cfm
+ where cfm.channel_family_id = cfam_id);
+ end loop;
+ prev_ent_count := prev_ent_count - reduce_quantity;
+ prev_flex_count := prev_flex_count + reduce_quantity;
+ end if;
+ end if;
+
+
+
+
+ -- If we're setting the total entitlemnt count to a lower value,
+ -- and that value is less than the count in that one org,
+ -- we need to raise an exception.
+ if quantity_in < prev_ent_count then
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ else
+ -- even if we've manually converted systems to/from flex above
+ -- set_family_count should call update_family_counts, to reset
+ -- current used slots
+ rhn_entitlements.set_family_count(org_id_in, cfam_id,
+ quantity_in, flex_in);
+ end if;
+
+ end activate_channel_entitlement;
+
+
+ -- *******************************************************************
+ -- PROCEDURE: prune_family
+ -- Unsubscribes servers consuming physical slots from the channel family
+ -- that are over the org's limit.
+ -- Called by: set_family_count
+ -- *******************************************************************
+ procedure prune_family (
+ customer_id_in in number,
+ channel_family_id_in in number,
+ quantity_in in number,
+ flex_in in number
+ ) is
+ cursor serverchannels(tmp_quantity number, is_fve_in char) is
+ select sc.server_id,
+ sc.channel_id
+ from rhnServerChannel sc,
+ rhnChannelFamilyMembers cfm
+ where 1=1
+ and cfm.channel_family_id = channel_family_id_in
+ and cfm.channel_id = sc.channel_id
+ and server_id in (
+ select server_id
+ from (
+ select server_id, time, rownum row_number
+ from (
+ select rs.id server_id, rcfm.modified time
+ from rhnServerChannel rsc,
+ rhnChannelFamilyMembers rcfm,
+ rhnServer rs
+ where 1=1
+ and rs.org_id = customer_id_in
+ and rs.id = rsc.server_id
+ and rsc.channel_id = rcfm.channel_id
+ and rcfm.channel_family_id = channel_family_id_in
+ and rsc.is_fve = is_fve_in
+ -- we only want to grab servers consuming
+ -- physical slots.
+ and exists (
+ select 1
+ from rhnChannelFamilyServerPhysical cfsp
+ where cfsp.server_id = rs.id
+ and cfsp.channel_family_id =
+ channel_family_id_in
+ )
+ order by time asc
+ )
+ )
+ where row_number > tmp_quantity
+ );
+ begin
+ -- if we get a null customer_id, this is completely bogus.
+ if customer_id_in is null then
+ return;
+ end if;
+
+ for sc in serverchannels(quantity_in, 'N') loop
+ rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1,
+ update_family_countsYN => 0);
+ end loop;
+
+ for sc in serverchannels(flex_in, 'Y') loop
+ rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1,
+ update_family_countsYN => 0);
+ end loop;
+
+ rhn_channel.update_family_counts(channel_family_id_in, customer_id_in);
+ end prune_family;
+
+ procedure set_family_count (
+ customer_id_in in number,
+ channel_family_id_in in number,
+ quantity_in in number,
+ flex_in in number
+ ) is
+ cursor privperms is
+ select 1
+ from rhnPrivateChannelFamily
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+ cursor pubperms is
+ select o.id org_id
+ from web_customer o,
+ rhnPublicChannelFamily pcf
+ where pcf.channel_family_id = channel_family_id_in;
+ quantity number;
+ done number := 0;
+ flex number;
+ begin
+ quantity := quantity_in;
+ if quantity is not null and quantity < 0 then
+ quantity := 0;
+ end if;
+ flex := flex_in;
+ if flex is not null and flex < 0 then
+ flex := 0;
+ end if;
+
+
+ if customer_id_in is not null then
+ for perm in privperms loop
+ rhn_entitlements.prune_family(customer_id_in, channel_family_id_in,
+ quantity, flex);
+
+ if quantity is null and flex is null then
+ delete from rhnPrivateChannelFamily
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+ else
+ update rhnPrivateChannelFamily
+ set max_members = quantity
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+
+ update rhnPrivateChannelFamily
+ set fve_max_members = flex
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+ end if;
+ return;
+ end loop;
+
+ insert into rhnPrivateChannelFamily (
+ channel_family_id, org_id, max_members, current_members, fve_max_members, fve_current_members
+ ) values (
+ channel_family_id_in, customer_id_in, quantity, 0, flex, 0 );
+ return;
+ end if;
+
+ for perm in pubperms loop
+ if quantity = 0 then
+ rhn_entitlements.prune_family(
+ perm.org_id,
+ channel_family_id_in,
+ quantity,
+ flex
+ );
+ if done = 0 then
+ delete from rhnPublicChannelFamily
+ where channel_family_id = channel_family_id_in;
+ end if;
+ end if;
+ done := 1;
+ end loop;
+ -- if done's not 1, then we don't have any entitlements
+ if done != 1 then
+ insert into rhnPublicChannelFamily (
+ channel_family_id
+ ) values (
+ channel_family_id_in
+ );
+ end if;
+ end set_family_count;
+
+ -- this expects quantity_in to be the number of available slots, not the
+ -- max_members of the server group. If you give it too many, it'll fail
+ -- and raise servergroup_max_members.
+ -- We should NEVER run this unless we're SURE that we won't
+ -- be violating the max.
+ procedure entitle_last_modified_servers (
+ customer_id_in in number,
+ type_label_in in varchar2,
+ quantity_in in number
+ ) is
+ -- find the servers that aren't currently in slots
+ cursor servers(cid_in in number, quant_in in number) is
+ select server_id
+ from (
+ select rownum row_number,
+ server_id
+ from (
+ select rs.id server_iD
+ from rhnServer rs
+ where 1=1
+ and rs.org_id = cid_in
+ and not exists (
+ select 1
+ from rhnServerGroup sg,
+ rhnServerGroupMembers rsgm
+ where rsgm.server_id = rs.id
+ and rsgm.server_group_id = sg.id
+ and sg.group_type is not null
+ )
+ and not exists (
+ select 1
+ from rhnVirtualInstance vi
+ where vi.virtual_system_id =
+ rs.id
+ ) order by modified desc
+ )
+ )
+ where row_number <= quant_in;
+ begin
+ for server in servers(customer_id_in, quantity_in) loop
+ rhn_entitlements.entitle_server(server.server_id, type_label_in);
+ end loop;
+ end entitle_last_modified_servers;
+
+ procedure subscribe_newest_servers (
+ customer_id_in in number
+ ) is
+ -- find servers without base channels
+ cursor servers(cid_in in number) is
+ select s.id
+ from rhnServer s
+ where 1=1
+ and s.org_id = cid_in
+ and not exists (
+ select 1
+ from rhnChannel c,
+ rhnServerChannel sc
+ where sc.server_id = s.id
+ and sc.channel_id = c.id
+ and c.parent_channel is null
+ )
+ and not exists (
+ select 1
+ from rhnVirtualInstance vi
+ where vi.virtual_system_id = s.id
+ )
+ order by s.modified desc;
+ channel_id number;
+ begin
+ for server in servers(customer_id_in) loop
+ channel_id := rhn_channel.guess_server_base(server.id);
+ if channel_id is not null then
+ begin
+ rhn_channel.subscribe_server(server.id, channel_id);
+ commit;
+ -- exception is really channel_family_no_subscriptions
+ exception
+ when others then
+ null;
+ end;
+ end if;
+ end loop;
+ end subscribe_newest_servers;
+end rhn_entitlements;
+/
+show errors
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.sql.postgresql b/schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.sql.postgresql
new file mode 100644
index 0000000..1ec95e3
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-2.0-to-spacewalk-schema-2.1/010-rhn_entitlements.pkb.sql.postgresql
@@ -0,0 +1,1787 @@
+-- oracle equivalent source sha1 49a42a42768d83a188a939412c353bf6de4013ab
+--
+-- Copyright (c) 2008--2012 Red Hat, Inc.
+--
+-- This software is licensed to you under the GNU General Public License,
+-- version 2 (GPLv2). There is NO WARRANTY for this software, express or
+-- implied, including the implied warranties of MERCHANTABILITY or FITNESS
+-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+-- along with this software; if not, see
+-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+--
+-- Red Hat trademarks are not licensed under GPLv2. No permission is
+-- granted to use or replicate Red Hat trademarks that are incorporated
+-- in this software or its documentation.
+--
+
+-- create schema rhn_entitlements;
+
+-- setup search_path so that these functions are created in appropriate schema.
+update pg_settings set setting = 'rhn_entitlements,' || setting where name = 'search_path';
+
+ create or replace function find_compatible_sg (
+ server_id_in in numeric,
+ type_label_in in varchar
+ )
+ returns numeric
+as $$
+ declare
+ servergroups cursor for
+ select sg.id
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServer s,
+ rhnServerServerGroupArchCompat ssgac
+ where s.id = server_id_in
+ and s.org_id = sg.org_id
+ and sgt.label = type_label_in
+ and sg.group_type = sgt.id
+ and ssgac.server_group_type = sgt.id
+ and ssgac.server_arch_id = s.server_arch_id
+ and not exists (
+ select 1
+ from rhnServerGroupMembers sgm
+ where sgm.server_group_id = sg.id
+ and sgm.server_id = s.id);
+
+
+ begin
+ for servergroup in servergroups loop
+ return servergroup.id;
+ end loop;
+
+ --no servergroup found
+ return NULL;
+ end$$
+language plpgsql;
+
+ -- *******************************************************************
+ -- PROCEDURE: remove_org_entitlements
+ --
+ -- Removes both system entitlements and channel subscriptions
+ -- that are currently assigned to an org and re-assigns to the
+ -- master org (org_id = 1).
+ --
+ -- When we call this we expect everything to already be unentitled
+ -- which shoul be handled by delete_org.
+ --
+ -- Called by: delete_org
+ -- *******************************************************************
+ create or replace function remove_org_entitlements (
+ org_id_in numeric
+ ) returns void
+as $$
+ declare
+ system_ents cursor for
+ select sg.id, sg.max_members, sg.group_type
+ from rhnServerGroup sg
+ where group_type is not null
+ and org_id = org_id_in;
+
+ channel_subs cursor for
+ select pcf.channel_family_id, pcf.max_members
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.org_id is null;
+
+ begin
+
+ for system_ent in system_ents loop
+ update rhnServerGroup
+ set max_members = max_members + system_ent.max_members
+ where org_id = 1
+ and group_type = system_ent.group_type;
+ end loop;
+
+ update rhnServerGroup
+ set max_members = 0
+ where org_id = org_id_in;
+
+ for channel_sub in channel_subs loop
+ update rhnPrivateChannelFamily
+ set max_members = max_members + channel_sub.max_members
+ where org_id = 1
+ and channel_family_id = channel_sub.channel_family_id;
+ end loop;
+
+ update rhnPrivateChannelFamily
+ set max_members = 0
+ where org_id = org_id_in;
+
+ end$$
+language plpgsql;
+
+ create or replace function entitlement_grants_service (
+ entitlement_in in varchar,
+ service_level_in in varchar
+ ) returns numeric
+as $$
+ begin
+ if service_level_in = 'provisioning' then
+ if entitlement_in = 'provisioning_entitled' then
+ return 1;
+ else
+ return 0;
+ end if;
+ elsif service_level_in = 'management' then
+ if entitlement_in = 'enterprise_entitled' then
+ return 1;
+ else
+ return 0;
+ end if;
+ elsif service_level_in = 'monitoring' then
+ if entitlement_in = 'monitoring_entitled' then
+ return 1;
+ end if;
+ elsif service_level_in = 'updates' then
+ return 1;
+ else
+ return 0;
+ end if;
+ end$$
+language plpgsql;
+
+ create or replace function lookup_entitlement_group (
+ org_id_in in numeric,
+ type_label_in in varchar default 'sw_mgr_entitled'
+ ) returns numeric
+as $$
+ declare
+ server_groups cursor for
+ select sg.id server_group_id
+ from rhnServerGroup sg,
+ rhnServerGroupType sgt
+ where sgt.label = type_label_in
+ and sgt.id = sg.group_type
+ and sg.org_id = org_id_in;
+ begin
+ for sg in server_groups loop
+ return sg.server_group_id;
+ end loop;
+ return rhn_entitlements.create_entitlement_group(
+ org_id_in,
+ type_label_in
+ );
+ end$$
+language plpgsql;
+
+ create or replace function create_entitlement_group (
+ org_id_in in numeric,
+ type_label_in in varchar default 'sw_mgr_entitled'
+ ) returns numeric
+as $$
+ declare
+ sg_id_val numeric;
+ begin
+ select nextval('rhn_server_group_id_seq')
+ into sg_id_val;
+
+ insert into rhnServerGroup (
+ id, name, description, max_members, current_members,
+ group_type, org_id
+ ) (
+ select sg_id_val, sgt.label, sgt.label,
+ 0, 0, sgt.id, org_id_in
+ from rhnServerGroupType sgt
+ where sgt.label = type_label_in
+ );
+
+ return sg_id_val;
+ end$$
+language plpgsql;
+
+ create or replace function can_entitle_server (
+ server_id_in in numeric,
+ type_label_in in varchar
+ )
+ returns numeric
+as $$
+ declare
+ addon_servergroups cursor (base_label_in varchar,
+ addon_label_in varchar) for
+ select
+ addon_id
+ from
+ rhnSGTypeBaseAddonCompat
+ where base_id = lookup_sg_type (base_label_in)
+ and addon_id = lookup_sg_type (addon_label_in);
+
+ previous_ent varchar[];
+ is_base_in char := 'N';
+ is_base_current char := 'N';
+ i numeric := 0;
+ sgid numeric := 0;
+
+ begin
+
+ previous_ent := rhn_entitlements.get_server_entitlement(server_id_in);
+
+ select distinct is_base
+ into is_base_in
+ from rhnServerGroupType
+ where label = type_label_in;
+
+ if array_upper(previous_ent, 1) is null or array_upper(previous_ent, 1) = 0 then
+ if is_base_in = 'Y' then
+ sgid := rhn_entitlements.find_compatible_sg (server_id_in, type_label_in);
+ if sgid is not null then
+ -- rhn_server.insert_into_servergroup (server_id_in, sgid);
+ return 1;
+ else
+ -- rhn_exception.raise_exception ('invalid_base_entitlement');
+ return 0;
+ end if;
+ else
+ -- rhn_exception.raise_exception ('invalid_base_entitlement');
+ return 0;
+ end if;
+
+ -- there are previous ents, first make sure we're not trying to entitle a base ent
+ elsif is_base_in = 'Y' then
+ -- rhn_exception.raise_exception ('invalid_addon_entitlement');
+ return 0;
+
+ -- it must be an addon, so proceed with the entitlement
+ else
+
+ -- find the servers base ent
+ is_base_current := 'N';
+ i := 0;
+ while is_base_current = 'N' and i < array_upper(previous_ent, 1)
+ loop
+ i := i + 1;
+ select is_base
+ into is_base_current
+ from rhnServerGroupType
+ where label = previous_ent[i];
+ end loop;
+
+ -- never found a base ent, that would be strange
+ if is_base_current = 'N' then
+ -- rhn_exception.raise_exception ('invalid_base_entitlement');
+ return 0;
+ end if;
+
+ -- this for loop verifies the validity of the addon path
+ for addon_servergroup in addon_servergroups (previous_ent[i], type_label_in) loop
+ -- find an appropriate sgid for the addon and entitle the server
+ sgid := rhn_entitlements.find_compatible_sg (server_id_in, type_label_in);
+ if sgid is not null then
+ -- rhn_server.insert_into_servergroup (server_id_in, sgid);
+ return 1;
+ else
+ -- rhn_exception.raise_exception ('invalid_addon_entitlement');
+ return 0;
+ end if;
+ end loop;
+
+ end if;
+
+ return 0;
+
+ end$$
+language plpgsql;
+
+ create or replace function can_switch_base (
+ server_id_in in integer,
+ type_label_in in varchar
+ )
+ returns numeric
+as $$
+ declare
+ type_label_in_is_base char(1);
+ sgid numeric;
+
+ begin
+
+ select is_base into type_label_in_is_base
+ from rhnServerGroupType
+ where label = type_label_in;
+
+ if not found then
+ perform rhn_exception.raise_exception ( 'invalid_entitlement' );
+ end if;
+
+ if type_label_in_is_base = 'N' then
+ perform rhn_exception.raise_exception ( 'invalid_entitlement' );
+ else
+ sgid := rhn_entitlements.find_compatible_sg ( server_id_in,
+ type_label_in );
+ if sgid is not null then
+ return 1;
+ else
+ return 0;
+ end if;
+ end if;
+
+ end$$
+language plpgsql;
+
+ create or replace function entitle_server (
+ server_id_in in numeric,
+ type_label_in in varchar default 'sw_mgr_entitled'
+ ) returns void
+as $$
+ declare
+ sgid numeric := 0;
+ is_virt numeric := 0;
+
+ begin
+
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+
+ if not found then
+ is_virt := 0;
+ end if;
+
+ if is_virt = 0 and (type_label_in = 'virtualization_host' or
+ type_label_in = 'virtualization_host_platform') then
+
+ is_virt := 1;
+ end if;
+
+ if rhn_entitlements.can_entitle_server(server_id_in,
+ type_label_in) = 1 then
+ sgid := rhn_entitlements.find_compatible_sg (server_id_in,
+ type_label_in);
+ if sgid is not null then
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( nextval('rhn_event_id_seq'), server_id_in,
+ 'added system entitlement ',
+ case type_label_in
+ when 'enterprise_entitled' then 'Management'
+ when 'sw_mgr_entitled' then 'Update'
+ when 'provisioning_entitled' then 'Provisioning'
+ when 'monitoring_entitled' then 'Monitoring'
+ when 'virtualization_host' then 'Virtualization'
+ when 'virtualization_host_platform' then
+ 'Virtualization Platform' end );
+
+ perform rhn_server.insert_into_servergroup (server_id_in, sgid);
+
+ if is_virt = 1 then
+ perform rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+
+ else
+ perform rhn_exception.raise_exception ('no_available_server_group');
+ end if;
+ else
+ perform rhn_exception.raise_exception ('invalid_entitlement');
+ end if;
+ end$$
+language plpgsql;
+
+ create or replace function remove_server_entitlement (
+ server_id_in in numeric,
+ type_label_in in varchar default 'sw_mgr_entitled',
+ repoll_virt_guests in numeric default 1
+ ) returns void
+as $$
+ declare
+ group_id numeric;
+ type_is_base char;
+ is_virt numeric := 0;
+ begin
+ -- would be nice if there were a virt attribute of entitlement types, not have to specify 2 different ones...
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+ if not found then
+ is_virt := 0;
+ end if;
+
+ select sg.id, sgt.is_base
+ into group_id, type_is_base
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm,
+ rhnServer s
+ where s.id = server_id_in
+ and s.id = sgm.server_id
+ and sgm.server_group_id = sg.id
+ and sg.org_id = s.org_id
+ and sgt.label = type_label_in
+ and sgt.id = sg.group_type;
+
+ if not found then
+ perform rhn_exception.raise_exception('invalid_server_group_member');
+ end if;
+
+ if ( type_is_base = 'Y' ) then
+ -- unentitle_server should handle everything, don't really need to do anything else special here
+ perform rhn_entitlements.unentitle_server ( server_id_in );
+ else
+
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( nextval('rhn_event_id_seq'), server_id_in,
+ 'removed system entitlement ',
+ case type_label_in
+ when 'enterprise_entitled' then 'Management'
+ when 'sw_mgr_entitled' then 'Update'
+ when 'provisioning_entitled' then 'Provisioning'
+ when 'monitoring_entitled' then 'Monitoring'
+ when 'virtualization_host' then 'Virtualization'
+ when 'virtualization_host_platform' then
+ 'Virtualization Platforrm' end );
+
+ perform rhn_server.delete_from_servergroup(server_id_in, group_id);
+
+ if type_label_in = 'monitoring_entitled' then
+ DELETE
+ FROM rhn_probe
+ WHERE recid IN (SELECT probe_id
+ FROM rhn_check_probe
+ WHERE host_id = server_id_in);
+ end if;
+
+ if is_virt = 1 and repoll_virt_guests = 1 then
+ perform rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+ end if;
+
+ end$$
+language plpgsql;
+
+ create or replace function unentitle_server (
+ server_id_in in numeric
+ ) returns void
+as $$
+ declare
+ servergroups cursor for
+ select distinct sgt.label, sg.id server_group_id
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServer s,
+ rhnServerGroupMembers sgm
+ where s.id = server_id_in
+ and s.org_id = sg.org_id
+ and sg.group_type = sgt.id
+ and sgm.server_group_id = sg.id
+ and sgm.server_id = s.id;
+
+ is_virt numeric := 0;
+
+ begin
+
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+
+ if not found then
+ is_virt := 0;
+ end if;
+
+ for servergroup in servergroups loop
+
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( nextval('rhn_event_id_seq'), server_id_in,
+ 'removed system entitlement ',
+ case servergroup.label
+ when 'enterprise_entitled' then 'Management'
+ when 'sw_mgr_entitled' then 'Update'
+ when 'provisioning_entitled' then 'Provisioning'
+ when 'monitoring_entitled' then 'Monitoring'
+ when 'virtualization_host' then 'Virtualization'
+ when 'virtualization_host_platform' then
+ 'Virtualization Platform' end );
+
+ perform rhn_server.delete_from_servergroup(server_id_in,
+ servergroup.server_group_id );
+ end loop;
+
+ if is_virt = 1 then
+ perform rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+
+ end$$
+language plpgsql;
+
+
+ -- *******************************************************************
+ -- PROCEDURE: repoll_virt_guest_entitlements
+ --
+ -- Whenever we add/remove a virtualization_host* entitlement from
+ -- a host, we can call this procedure to update what type of slots
+ -- the guests are consuming.
+ --
+ -- If you're removing the entitlement, it's
+ -- possible the guests will become unentitled if you don't have enough
+ -- physical slots to cover them.
+ --
+ -- If you're adding the entitlement, you end up freeing up physical
+ -- slots for other systems.
+ --
+ -- *******************************************************************
+ create or replace function repoll_virt_guest_entitlements(
+ server_id_in in numeric
+ ) returns void
+as $$
+ declare
+ -- All channel families associated with the guests of server_id_in
+ families cursor for
+ select distinct cfs.channel_family_id
+ from
+ rhnChannelFamilyServers cfs,
+ rhnVirtualInstance vi
+ where
+ vi.host_system_id = server_id_in
+ and vi.virtual_system_id = cfs.server_id;
+
+ -- All of server group types associated with the guests of
+ -- server_id_in
+ group_types cursor for
+ select distinct sg.group_type, sgt.label
+ from
+ rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm,
+ rhnVirtualInstance vi
+ where
+ vi.host_system_id = server_id_in
+ and vi.virtual_system_id = sgm.server_id
+ and sgm.server_group_id = sg.id
+ and sg.group_type = sgt.id;
+
+ -- Virtual servers from a certain family belonging to a specific
+ -- host that are consuming physical channel slots over the limit.
+ virt_servers_cfam cursor(family_id_in numeric, quantity_in numeric) for
+ select vi.virtual_system_id
+ from
+ rhnChannelFamilyMembers cfm,
+ rhnServerChannel sc,
+ rhnVirtualInstance vi
+ where
+ vi.host_system_id = server_id_in
+ and vi.virtual_system_id = sc.server_id
+ and sc.channel_id = cfm.channel_id
+ and cfm.channel_family_id = family_id_in
+ order by sc.modified desc
+ limit quantity_in;
+
+ -- Virtual servers from a certain family belonging to a specific
+ -- host that are consuming physical system slots over the limit.
+ virt_servers_sgt cursor(group_type_in numeric, quantity_in numeric) for
+ select vi.virtual_system_id
+ from
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm,
+ rhnVirtualInstance vi
+ where
+ vi.host_system_id = server_id_in
+ and vi.virtual_system_id = sgm.server_id
+ and sgm.server_group_id = sg.id
+ and sg.group_type = group_type_in
+ order by sgm.modified desc
+ limit quantity_in;
+
+ -- Get the orgs of Virtual guests
+ -- Since they may belong to different orgs
+ virt_guest_orgs cursor for
+ select distinct (s.org_id)
+ from rhnServer s
+ inner join rhnVirtualInstance vi on vi.virtual_system_id = s.id
+ where
+ vi.host_system_id = server_id_in
+ and s.org_id <> (select s1.org_id from rhnServer s1 where s1.id = vi.host_system_id) ;
+
+ org_id_val numeric;
+ max_members_val numeric;
+ max_flex_val numeric;
+ current_members_calc numeric;
+ sg_id numeric;
+ is_virt numeric := 0;
+ free_slots numeric := 0;
+ begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+
+ if not found then
+ is_virt := 0;
+ end if;
+
+ select org_id
+ into org_id_val
+ from rhnServer
+ where id = server_id_in;
+
+ -- deal w/ channel entitlements first ...
+ for family in families loop
+ if is_virt = 0 then
+ -- if the host_server does not have virt
+ --- find all possible flex slots
+ -- and set each of the flex eligible guests to Y
+ select sfc.max_members - sfc.current_members
+ into free_slots
+ from rhnServerFveCapable sfc
+ where sfc.channel_family_id = family.channel_family_id;
+ UPDATE rhnServerChannel sc set is_fve = 'Y'
+ where sc.server_id in (
+ select vi.virtual_system_id
+ from rhnServerFveCapable sfc
+ inner join rhnVirtualInstance vi on vi.virtual_system_id = sfc.server_id
+ where vi.host_system_id = server_id_in
+ and sfc.channel_family_id = family.channel_family_id
+ order by vi.modified desc
+ limit free_slots
+ );
+ else
+ -- if the host_server has virt
+ -- set all its flex guests to N
+ UPDATE rhnServerChannel sc set is_fve = 'N'
+ where
+ sc.channel_id in (select cfm.channel_id from rhnChannelFamilyMembers cfm
+ where cfm.CHANNEL_FAMILY_ID = family.channel_family_id)
+ and sc.is_fve = 'Y'
+ and sc.server_id in
+ (select vi.virtual_system_id from rhnVirtualInstance vi
+ where vi.host_system_id = server_id_in);
+ end if;
+
+ -- get the current (physical) members of the family
+ current_members_calc :=
+ rhn_channel.channel_family_current_members(family.channel_family_id,
+ org_id_val); -- fixed transposed args
+
+ -- get the max members of the family
+ select max_members
+ into max_members_val
+ from rhnPrivateChannelFamily
+ where channel_family_id = family.channel_family_id
+ and org_id = org_id_val;
+
+ select fve_max_members
+ into max_flex_val
+ from rhnPrivateChannelFamily
+ where channel_family_id = family.channel_family_id
+ and org_id = org_id_val;
+
+ if current_members_calc > max_members_val then
+ -- A virtualization_host* ent must have been removed, so we'll
+ -- unsubscribe guests from the host first.
+
+ -- hm, i don't think max_members - current_members_calc yielding a negative number
+ -- will work w/ rownum, swaping 'em in the body of this if...
+ for virt_server in virt_servers_cfam(family.channel_family_id,
+ current_members_calc - max_members_val) loop
+
+ perform rhn_channel.unsubscribe_server_from_family(
+ virt_server.virtual_system_id,
+ family.channel_family_id);
+ end loop;
+
+ -- if we're still over the limit, which would be odd,
+ -- just prune the group to max_members
+ --
+ -- er... wouldn't we actually have to refresh the values of
+ -- current_members_calc and max_members_val to actually ever
+ -- *skip this??
+ if current_members_calc > max_members_val then
+ -- argh, transposed again?!
+ perform rhn_entitlements.set_family_count(org_id_val,
+ family.channel_family_id,
+ max_members_val, max_flex_val);
+ --TODO calculate this correctly
+ end if;
+
+ end if;
+
+ -- update current_members for the family. This will set the value
+ -- to reflect adding/removing the entitlement.
+ --
+ -- what's the difference of doing this vs the unavoidable set_family_count above?
+ perform rhn_channel.update_family_counts(family.channel_family_id,
+ org_id_val);
+
+ -- It is possible that the guests belong to a different org than the host
+ -- so we are going to update the family counts in the guests orgs also
+ for org in virt_guest_orgs loop
+ perform rhn_channel.update_family_counts(family.channel_family_id,
+ org.org_id);
+ end loop;
+ end loop;
+
+ for a_group_type in group_types loop
+ -- get the current *physical* members of the system entitlement type for the org...
+ --
+ -- unlike channel families, it appears the standard rhnServerGroup.max_members represents
+ -- *physical* slots, vs physical+virt ... boy that's confusing...
+
+ select max_members, id
+ into max_members_val, sg_id
+ from rhnServerGroup
+ where group_type = a_group_type.group_type
+ and org_id = org_id_val;
+
+
+ select count(sep.server_id) into current_members_calc
+ from rhnServerEntitlementPhysical sep
+ where sep.server_group_id = sg_id
+ and sep.server_group_type_id = a_group_type.group_type;
+
+ if current_members_calc > max_members_val then
+ -- A virtualization_host* ent must have been removed, and we're over the limit, so unsubscribe guests
+ for virt_server in virt_servers_sgt(a_group_type.group_type,
+ current_members_calc - max_members_val) loop
+ perform rhn_entitlements.remove_server_entitlement(virt_server.virtual_system_id, a_group_type.label);
+
+ -- decrement current_members_calc, we'll use it to reset current_members for the group at the end...
+ current_members_calc := current_members_calc - 1;
+ end loop;
+
+ end if;
+
+ update rhnServerGroup set current_members = current_members_calc
+ where org_id = org_id_val
+ and group_type = a_group_type.group_type;
+
+ -- I think that's all the house-keeping we have to do...
+ end loop;
+
+ end$$
+language plpgsql;
+
+ create or replace function get_server_entitlement (
+ server_id_in in numeric
+ ) returns varchar[]
+as $$
+ declare
+ server_groups cursor for
+ select sgt.label
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm
+ where 1=1
+ and sgm.server_id = server_id_in
+ and sg.id = sgm.server_group_id
+ and sgt.id = sg.group_type
+ and sgt.label in (
+ 'sw_mgr_entitled','enterprise_entitled',
+ 'provisioning_entitled', 'nonlinux_entitled',
+ 'monitoring_entitled', 'virtualization_host',
+ 'virtualization_host_platform'
+ );
+
+ ent_array varchar[];
+
+ begin
+
+ ent_array := '{}';
+
+ for sg in server_groups loop
+ ent_array := ent_array || sg.label;
+ end loop;
+
+ return ent_array;
+
+ end$$
+language plpgsql;
+
+ -- this desperately needs to be table driven.
+ create or replace function modify_org_service (
+ org_id_in in numeric,
+ service_label_in in varchar,
+ enable_in in char
+ ) returns void
+as $$
+ declare
+ roles_to_process varchar[];
+ roles cursor(role_label_in varchar) for
+ select label, id
+ from rhnUserGroupType
+ where label = role_label_in;
+ org_roles cursor(role_label_in varchar) for
+ select 1
+ from rhnUserGroup ug,
+ rhnUserGroupType ugt
+ where ugt.label = role_label_in
+ and ug.org_id = org_id_in
+ and ugt.id = ug.group_type;
+
+ ents_to_process varchar[];
+ ents cursor(ent_label_in varchar) for
+ select label, id
+ from rhnOrgEntitlementType
+ where label = ent_label_in;
+ org_ents cursor(ent_label_in varchar) for
+ select 1
+ from rhnOrgEntitlements oe,
+ rhnOrgEntitlementType oet
+ where oet.label = ent_label_in
+ and oe.org_id = org_id_in
+ and oet.id = oe.entitlement_id;
+ create_row char(1);
+ begin
+ ents_to_process := '{}';
+ roles_to_process := '{}';
+ -- a bit kludgy, but only for 3.4 really. Certainly no
+ -- worse than the old code...
+ if service_label_in = 'enterprise' or
+ service_label_in = 'management' then
+ ents_to_process := array_append(ents_to_process, 'sw_mgr_enterprise');
+
+ roles_to_process := array_append(roles_to_process, 'org_admin');
+
+ roles_to_process := array_append(roles_to_process, 'system_group_admin');
+
+ roles_to_process := array_append(roles_to_process, 'activation_key_admin');
+ elsif service_label_in = 'provisioning' then
+ ents_to_process := array_append(ents_to_process, 'rhn_provisioning');
+
+ roles_to_process := array_append(roles_to_process, 'system_group_admin');
+
+ roles_to_process := array_append(roles_to_process, 'activation_key_admin');
+
+ roles_to_process := array_append(roles_to_process, 'config_admin');
+ -- another nasty special case...
+ if enable_in = 'Y' then
+ ents_to_process := array_append(ents_to_process, 'sw_mgr_enterprise');
+ end if;
+ elsif service_label_in = 'monitoring' then
+ ents_to_process := array_append(ents_to_process, 'rhn_monitor');
+
+ roles_to_process := array_append(roles_to_process, 'monitoring_admin');
+ elsif service_label_in = 'virtualization' then
+ ents_to_process := array_append(ents_to_process, 'rhn_virtualization');
+
+ roles_to_process := array_append(roles_to_process, 'config_admin');
+ elsif service_label_in = 'virtualization_platform' then
+ ents_to_process := array_append(ents_to_process, 'rhn_virtualization_platform');
+ roles_to_process := array_append(roles_to_process, 'config_admin');
+ elsif service_label_in = 'nonlinux' then
+ ents_to_process := array_append(ents_to_process, 'rhn_nonlinux');
+ roles_to_process := array_append(roles_to_process, 'config_admin');
+ end if;
+
+ if enable_in = 'Y' then
+ for i in 1..array_upper(ents_to_process, 1) loop
+ for ent in ents(ents_to_process[i]) loop
+ create_row := 'Y';
+ for oe in org_ents(ent.label) loop
+ create_row := 'N';
+ end loop;
+ if create_row = 'Y' then
+ insert into rhnOrgEntitlements(org_id, entitlement_id)
+ values (org_id_in, ent.id);
+ end if;
+ end loop;
+ end loop;
+ for i in 1..array_upper(roles_to_process, 1) loop
+ for role in roles(roles_to_process[i]) loop
+ create_row := 'Y';
+ for o_r in org_roles(role.label) loop
+ create_row := 'N';
+ end loop;
+ if create_row = 'Y' then
+ insert into rhnUserGroup(
+ id, name, description, current_members,
+ group_type, org_id
+ ) (
+ select nextval('rhn_user_group_id_seq'),
+ ugt.name || 's',
+ ugt.name || 's for Org ' ||
+ o.name || ' ('|| o.id ||')',
+ 0, ugt.id, o.id
+ from rhnUserGroupType ugt,
+ web_customer o
+ where o.id = org_id_in
+ and ugt.id = role.id
+ );
+ end if;
+ end loop;
+ end loop;
+ else
+ for i in 1..coalesce(array_upper(ents_to_process, 1), 0) loop
+ for ent in ents(ents_to_process[i]) loop
+ delete from rhnOrgEntitlements
+ where org_id = org_id_in
+ and entitlement_id = ent.id;
+ end loop;
+ end loop;
+ end if;
+ end$$
+language plpgsql;
+
+ create or replace function set_customer_enterprise (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ begin
+ perform rhn_entitlements.modify_org_service(customer_id_in, 'enterprise', 'Y');
+ end$$
+language plpgsql;
+
+ create or replace function set_customer_provisioning (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ begin
+ perform rhn_entitlements.modify_org_service(customer_id_in, 'provisioning', 'Y');
+ end$$
+language plpgsql;
+
+ create or replace function set_customer_monitoring (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ begin
+ perform rhn_entitlements.modify_org_service(customer_id_in, 'monitoring', 'Y');
+ end$$
+language plpgsql;
+
+ create or replace function set_customer_nonlinux (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ begin
+ perform rhn_entitlements.modify_org_service(customer_id_in, 'nonlinux', 'Y');
+ end$$
+language plpgsql;
+
+ create or replace function unset_customer_enterprise (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ begin
+ perform rhn_entitlements.modify_org_service(customer_id_in, 'enterprise', 'N');
+ end$$
+language plpgsql;
+
+ create or replace function unset_customer_provisioning (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ begin
+ perform rhn_entitlements.modify_org_service(customer_id_in, 'provisioning', 'N');
+ end$$
+language plpgsql;
+
+ create or replace function unset_customer_monitoring (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ begin
+ perform rhn_entitlements.modify_org_service(customer_id_in, 'monitoring', 'N');
+ end$$
+language plpgsql;
+
+ create or replace function unset_customer_nonlinux (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ begin
+ perform rhn_entitlements.modify_org_service(customer_id_in, 'nonlinux', 'N');
+ end$$
+language plpgsql;
+
+ -- *******************************************************************
+ -- PROCEDURE: prune_group
+ -- Unsubscribes servers consuming physical slots that over the org's
+ -- limit.
+ -- Called by: set_server_group_count, repoll_virt_guest_entitlements
+ -- *******************************************************************
+ create or replace function prune_group (
+ group_id_in in numeric,
+ quantity_in in numeric,
+ update_family_countsYN in numeric default 1
+ ) returns void
+as $$
+ declare
+ sgrecord record;
+ type_is_base char;
+ begin
+ update rhnServerGroup
+ set max_members = quantity_in
+ where id = group_id_in;
+
+ for sgrecord in (
+ select server_id, server_group_id, sgt.id as group_type_id, sgt.label
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm
+ where 1=1
+ and sgm.server_group_id = group_id_in
+ and sgm.server_id in (
+ select sep.server_id
+ from
+ rhnServerEntitlementPhysical sep
+ where
+ sep.server_group_id = group_id_in
+ order by sep.modified asc
+ offset quantity_in
+ )
+ and sgm.server_group_id = sg.id
+ and sg.group_type = sgt.id
+ ) loop
+ perform rhn_entitlements.remove_server_entitlement(sgrecord.server_id, sgrecord.label);
+
+ select is_base
+ into type_is_base
+ from rhnServerGroupType sgt
+ where sgt.id = sgrecord.group_type_id;
+
+ -- if we're removing a base ent, then be sure to
+ -- remove the server's channel subscriptions.
+ if ( type_is_base = 'Y' ) then
+ perform rhn_channel.clear_subscriptions(sgrecord.server_id, 0, update_family_countsYN);
+ end if;
+
+ end loop;
+ end$$
+language plpgsql;
+
+ -- *******************************************************************
+ -- PROCEDURE: assign_system_entitlement
+ --
+ -- Moves system entitlements from from_org_id_in to to_org_id_in.
+ -- Can raise not_enough_entitlements_in_base_org if from_org_id_in
+ -- does not have enough entitlements to cover the move.
+ -- Takes care of unentitling systems if necessary by calling
+ -- set_server_group_count
+ -- *******************************************************************
+ create or replace function assign_system_entitlement(
+ group_label_in in varchar,
+ from_org_id_in in numeric,
+ to_org_id_in in numeric,
+ quantity_in in numeric
+ ) returns void
+as $$
+ declare
+ prev_ent_count numeric;
+ to_org_prev_ent_count numeric;
+ new_ent_count numeric;
+ new_quantity numeric;
+ group_type numeric;
+ begin
+
+ select max_members
+ into prev_ent_count
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg
+ where sg.org_id = from_org_id_in
+ and sg.group_type = sgt.id
+ and sgt.label = group_label_in;
+
+ if not found then
+ perform rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end if;
+
+ select max_members
+ into to_org_prev_ent_count
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg
+ where sg.org_id = to_org_id_in
+ and sg.group_type = sgt.id
+ and sgt.label = group_label_in;
+
+ if not found then
+ to_org_prev_ent_count := 0;
+ end if;
+
+ select id
+ into group_type
+ from rhnServerGroupType
+ where label = group_label_in;
+
+ if not found then
+ perform rhn_exception.raise_exception(
+ 'invalid_server_group');
+ end if;
+
+ new_ent_count := prev_ent_count - quantity_in;
+
+ if prev_ent_count > new_ent_count then
+ new_quantity := to_org_prev_ent_count + quantity_in;
+ end if;
+
+ if new_ent_count < 0 then
+ perform rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end if;
+
+
+ perform rhn_entitlements.set_server_group_count(from_org_id_in,
+ group_type,
+ new_ent_count);
+
+ perform rhn_entitlements.set_server_group_count(to_org_id_in,
+ group_type,
+ new_quantity);
+
+ -- Create or delete the entries in rhnOrgEntitlementType
+ if group_label_in = 'enterprise_entitled' then
+ if new_quantity > 0 then
+ perform rhn_entitlements.set_customer_enterprise(to_org_id_in);
+ else
+ perform rhn_entitlements.unset_customer_enterprise(to_org_id_in);
+ end if;
+ end if;
+
+ if group_label_in = 'provisioning_entitled' then
+ if new_quantity > 0 then
+ perform rhn_entitlements.set_customer_provisioning(to_org_id_in);
+ else
+ perform rhn_entitlements.unset_customer_provisioning(to_org_id_in);
+ end if;
+ end if;
+
+ if group_label_in = 'monitoring_entitled' then
+ if new_quantity > 0 then
+ perform rhn_entitlements.set_customer_monitoring(to_org_id_in);
+ else
+ perform rhn_entitlements.unset_customer_monitoring(to_org_id_in);
+ end if;
+ end if;
+
+ end$$
+language plpgsql;
+
+ -- *******************************************************************
+ -- PROCEDURE: assign_channel_entitlement
+ --
+ -- Moves channel entitlements from from_org_id_in to to_org_id_in.
+ -- Can raise not_enough_entitlements_in_base_org if from_org_id_in
+ -- does not have enough entitlements to cover the move.
+ -- Takes care of unentitling systems if necessary by calling
+ -- set_family_count
+ -- *******************************************************************
+ create or replace function assign_channel_entitlement(
+ channel_family_label_in in varchar,
+ from_org_id_in in numeric,
+ to_org_id_in in numeric,
+ quantity_in in numeric,
+ flex_in in numeric
+ ) returns void
+as $$
+ declare
+ from_org_prev_ent_count numeric;
+ from_org_prev_ent_count_flex numeric;
+ new_ent_count numeric;
+ new_ent_count_flex numeric;
+ to_org_prev_ent_count numeric;
+ to_org_prev_ent_count_flex numeric;
+ new_quantity numeric;
+ new_flex numeric;
+ cfam_id numeric;
+ begin
+
+ select max_members
+ into from_org_prev_ent_count
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = from_org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+
+ if not found then
+ perform rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end if;
+
+ select max_members
+ into to_org_prev_ent_count
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = to_org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+
+ if not found then
+ to_org_prev_ent_count := 0;
+ end if;
+
+ select fve_max_members
+ into from_org_prev_ent_count_flex
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = from_org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+
+ if not found then
+ perform rhn_exception.raise_exception(
+ 'not_enough_flex_entitlements_in_base_org');
+ end if;
+
+ select fve_max_members
+ into to_org_prev_ent_count_flex
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = to_org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+
+ if not found then
+ to_org_prev_ent_count_flex := 0;
+ end if;
+
+ select id
+ into cfam_id
+ from rhnChannelFamily
+ where label = channel_family_label_in;
+
+ if not found then
+ perform rhn_exception.raise_exception(
+ 'invalid_channel_family');
+ end if;
+
+ new_ent_count := from_org_prev_ent_count - quantity_in;
+ new_ent_count_flex := from_org_prev_ent_count_flex - flex_in;
+
+ if from_org_prev_ent_count >= new_ent_count then
+ new_quantity := to_org_prev_ent_count + quantity_in;
+ end if;
+
+ if from_org_prev_ent_count_flex >= new_ent_count_flex then
+ new_flex := to_org_prev_ent_count_flex + flex_in;
+ end if;
+
+ if new_ent_count < 0 then
+ perform rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end if;
+
+ if new_ent_count_flex < 0 then
+ perform rhn_exception.raise_exception(
+ 'not_enough_flex_entitlements_in_base_org');
+ end if;
+
+
+
+ perform rhn_entitlements.set_family_count(from_org_id_in,
+ cfam_id,
+ new_ent_count,
+ new_ent_count_flex);
+
+ perform rhn_entitlements.set_family_count(to_org_id_in,
+ cfam_id,
+ new_quantity,
+ new_flex);
+
+ end$$
+language plpgsql;
+
+ -- *******************************************************************
+ -- PROCEDURE: activate_system_entitlement
+ --
+ -- Sets the values in rhnServerGroup for a given rhnServerGroupType.
+ --
+ -- Calls: set_server_group_count to update, prune, or create the group.
+ -- Called by: the code that activates a satellite cert.
+ --
+ -- Raises not_enough_entitlements_in_base_org if all entitlements
+ -- in the org are used so the free entitlements would not cover
+ -- the difference when descreasing the number of entitlements.
+ -- *******************************************************************
+ create or replace function activate_system_entitlement(
+ org_id_in in numeric,
+ group_label_in in varchar,
+ quantity_in in numeric
+ ) returns void
+as $$
+ declare
+ prev_ent_count numeric;
+ prev_ent_count_sum numeric;
+ group_type numeric;
+ begin
+
+ -- Fetch the current entitlement count for the org
+ -- into prev_ent_count
+
+ select current_members
+ into prev_ent_count
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg
+ where sg.group_type = sgt.id
+ and sgt.label = group_label_in
+ and sg.org_id = org_id_in;
+
+ if not found then
+ prev_ent_count := 0;
+ end if;
+
+ select id
+ into group_type
+ from rhnServerGroupType
+ where label = group_label_in;
+
+ if not found then
+ perform rhn_exception.raise_exception(
+ 'invalid_server_group');
+ end if;
+
+ -- If we're setting the total entitlemnt count to a lower value,
+ -- and that value is less than the allocated count in this org,
+ -- we need to raise an exception.
+ if quantity_in < prev_ent_count then
+ perform rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ else
+ -- don't update family counts after every server
+ -- will do bulk update afterwards
+ perform rhn_entitlements.set_server_group_count(org_id_in,
+ group_type,
+ quantity_in,
+ 0);
+ -- bulk update family counts
+ perform rhn_channel.update_group_family_counts(group_label_in, org_id_in);
+ end if;
+
+ end$$
+language plpgsql;
+
+ -- *******************************************************************
+ -- PROCEDURE: activate_channel_entitlement
+ --
+ -- Calls: set_family_count to update, prune, or create the family
+ -- permission bucket.
+ -- Called by: the code that activates a satellite cert.
+ --
+ -- Raises not_enough_entitlements_in_base_org if there are not enough
+ -- entitlements in the org to cover the difference when you are
+ -- descreasing the number of entitlements.
+ --
+ -- The backend code in Python is expected to do whatever arithmetics
+ -- is needed.
+ -- *******************************************************************
+ create or replace function activate_channel_entitlement(
+ org_id_in in numeric,
+ channel_family_label_in in varchar,
+ quantity_in in numeric,
+ flex_in in numeric
+ ) returns void
+as $$
+ declare
+ prev_ent_count numeric;
+ prev_flex_count numeric;
+ prev_ent_count_sum numeric;
+ cfam_id numeric;
+ reduce_quantity numeric;
+ total_flex_capable numeric;
+ to_convert_reg cursor (channel_family_id_val numeric, org_id_in numeric, quantity numeric) for
+ select SC.server_id
+ from rhnServerChannel SC inner join
+ rhnServer S on S.id = SC.server_id
+ where
+ is_fve = 'Y'
+ and S.org_id = org_id_in
+ and SC.channel_id in
+ (select cfm.channel_id from rhnChannelFamilyMembers cfm
+ where cfm.CHANNEL_FAMILY_ID = channel_family_id_val)
+ limit quantity;
+ to_convert_flex cursor (channel_family_id_val numeric, org_id_in numeric, quantity numeric) for
+ select server_id
+ from rhnServerFveCapable
+ where SERVER_ORG_ID = org_id_in and
+ channel_family_id = cfam_id
+ limit quantity;
+
+ begin
+
+ -- Fetch the current entitlement count for the org
+ -- into prev_ent_count
+ select current_members
+ into prev_ent_count
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+
+ if not found then
+ prev_ent_count := 0;
+ end if;
+
+ select pcf.fve_current_members
+ into prev_flex_count
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+
+ if not found then
+ prev_flex_count := 0;
+ end if;
+
+ select id
+ into cfam_id
+ from rhnChannelFamily
+ where label = channel_family_label_in;
+
+ if not found then
+ perform rhn_exception.raise_exception(
+ 'invalid_channel_family');
+ end if;
+
+ -- if there are too few flex entitlements
+ if flex_in < prev_flex_count then
+ -- and if the extra we need is less than or equal to our extra regular entitlements
+ if prev_flex_count - flex_in <= quantity_in - prev_ent_count then
+ reduce_quantity := prev_flex_count - flex_in;
+ -- We need to convert some systems from flex guest to regular
+ for system in to_convert_reg(cfam_id, org_id_in, reduce_quantity) loop
+ --rhn_channel.convert_to_regular(system.server_id, cfam_id);
+ UPDATE rhnServerChannel sc set is_fve = 'N'
+ where sc.server_id = system.server_id
+ and sc.channel_id in (select cfm.channel_id
+ from rhnChannelFamilyMembers cfm
+ where cfm.channel_family_id = cfam_id);
+ end loop;
+
+ --reset previous counts
+ prev_ent_count := prev_ent_count + reduce_quantity;
+ prev_flex_count := prev_flex_count - reduce_quantity;
+ else
+ perform rhn_exception.raise_exception(
+ 'not_enough_flex_entitlements_in_base_org');
+ end if;
+ end if;
+
+ -- if there are too few regular entitlements, and extra flex entitlements
+ if quantity_in < prev_ent_count and prev_flex_count < flex_in then
+ -- how many flex-capable systems (that aren't using flex) do we have
+ select count(*)
+ into total_flex_capable
+ from rhnServerFveCapable
+ where SERVER_ORG_ID = org_id_in and
+ channel_family_id = cfam_id;
+ -- if we have enough flex capable machines that is at least
+ -- as many as what we are over on
+ if total_flex_capable >= prev_ent_count - quantity_in then
+ reduce_quantity := prev_ent_count - quantity_in;
+ for system in to_convert_flex(cfam_id, org_id_in, reduce_quantity) loop
+-- rhn_channel.convert_to_fve(system.server_id, cfam_id);
+ UPDATE rhnServerChannel sc set is_fve = 'Y'
+ where sc.server_id = system.server_id
+ and sc.channel_id in (select cfm.channel_id
+ from rhnChannelFamilyMembers cfm
+ where cfm.channel_family_id = cfam_id);
+ end loop;
+ prev_ent_count := prev_ent_count - reduce_quantity;
+ prev_flex_count := prev_flex_count + reduce_quantity;
+ end if;
+ end if;
+
+ -- If we're setting the total entitlemnt count to a lower value,
+ -- and that value is less than the count in that one org,
+ -- we need to raise an exception.
+ if quantity_in < prev_ent_count then
+ perform rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ else
+ -- even if we've manually converted systems to/from flex above
+ -- set_family_count should call update_family_counts, to reset
+ -- current used slots
+ perform rhn_entitlements.set_family_count(org_id_in, cfam_id,
+ quantity_in, flex_in);
+ end if;
+
+ end$$
+language plpgsql;
+
+ create or replace function set_server_group_count (
+ customer_id_in in numeric, -- customer_id
+ group_type_in in numeric, -- rhn[User|Server]GroupType.id
+ quantity_in in numeric, -- quantity
+ update_family_countsYN in numeric default 1
+ ) returns void
+as $$
+ declare
+ group_id numeric;
+ quantity numeric;
+ wasfound boolean;
+ begin
+ quantity := quantity_in;
+ if quantity is not null and quantity < 0 then
+ quantity := 0;
+ end if;
+
+ select rsg.id
+ into group_id
+ from rhnServerGroup rsg
+ where 1=1
+ and rsg.org_id = customer_id_in
+ and rsg.group_type = group_type_in;
+
+ -- preserve the not found status across the rhn_entitlements.prune_group invocation
+ wasfound := true;
+ if not found then
+ wasfound := false;
+ end if;
+
+ perform rhn_entitlements.prune_group(
+ group_id,
+ quantity,
+ update_family_countsYN
+ );
+
+ if not wasfound then
+ insert into rhnServerGroup (
+ id, name, description, max_members, current_members,
+ group_type, org_id, created, modified
+ ) (
+ select nextval('rhn_server_group_id_seq'), name, name,
+ quantity, 0, id, customer_id_in,
+ current_timestamp, current_timestamp
+ from rhnServerGroupType
+ where id = group_type_in
+ );
+ end if;
+
+ end$$
+language plpgsql;
+
+ -- *******************************************************************
+ -- PROCEDURE: prune_family
+ -- Unsubscribes servers consuming physical slots from the channel family
+ -- that are over the org's limit.
+ -- Called by: set_family_count
+ -- *******************************************************************
+ create or replace function prune_family (
+ customer_id_in in numeric,
+ channel_family_id_in in numeric,
+ quantity_in in numeric,
+ flex_in in numeric
+ ) returns void
+as $$
+ declare
+ serverchannels cursor(tmp_quantity numeric, is_fve_in char) for
+ select sc.server_id,
+ sc.channel_id
+ from rhnServerChannel sc,
+ rhnChannelFamilyMembers cfm
+ where 1=1
+ and cfm.channel_family_id = channel_family_id_in
+ and cfm.channel_id = sc.channel_id
+ and server_id in (
+ select rs.id as server_id
+ from
+ rhnServerChannel rsc,
+ rhnChannelFamilyMembers rcfm,
+ rhnServer rs
+ where 1=1
+ and rs.org_id = customer_id_in
+ and rs.id = rsc.server_id
+ and rsc.channel_id = rcfm.channel_id
+ and rcfm.channel_family_id = channel_family_id_in
+ and rsc.is_fve = is_fve_in
+ -- we only want to grab servers consuming
+ -- physical slots.
+ and exists (
+ select 1
+ from rhnChannelFamilyServerPhysical cfsp
+ where cfsp.server_id = rs.id
+ and cfsp.channel_family_id =
+ channel_family_id_in
+ )
+ order by rcfm.modified asc
+ offset quantity_in
+ );
+ begin
+ -- if we get a null customer_id, this is completely bogus.
+ if customer_id_in is null then
+ return;
+ end if;
+
+ for sc in serverchannels(quantity_in, 'N') loop
+ perform rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id,
+ 1, 1, 0, 0);
+ end loop;
+
+ for sc in serverchannels(flex_in, 'Y') loop
+ perform rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id,
+ 1, 1, 0, 0);
+ end loop;
+
+ perform rhn_channel.update_family_counts(channel_family_id_in, customer_id_in);
+ end$$
+language plpgsql;
+
+ create or replace function set_family_count (
+ customer_id_in in numeric, -- customer_id
+ channel_family_id_in in numeric, -- 246
+ quantity_in in numeric, -- 3
+ flex_in in numeric
+ ) returns void
+as $$
+ declare
+ privperms cursor for
+ select 1
+ from rhnPrivateChannelFamily
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+ pubperms cursor for
+ select o.id org_id
+ from web_customer o,
+ rhnPublicChannelFamily pcf
+ where pcf.channel_family_id = channel_family_id_in;
+ quantity numeric;
+ done numeric := 0;
+ flex numeric;
+ begin
+ quantity := quantity_in;
+ if quantity is not null and quantity < 0 then
+ quantity := 0;
+ end if;
+ flex := flex_in;
+ if flex is not null and flex < 0 then
+ flex := 0;
+ end if;
+
+ if customer_id_in is not null then
+ for perm in privperms loop
+ perform rhn_entitlements.prune_family(
+ customer_id_in,
+ channel_family_id_in,
+ quantity,
+ flex
+ );
+
+ if quantity is null and flex is null then
+ delete from rhnPrivateChannelFamily
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+ else
+ update rhnPrivateChannelFamily
+ set max_members = quantity
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+
+ update rhnPrivateChannelFamily
+ set fve_max_members = flex
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+ end if;
+ return;
+ end loop;
+
+ insert into rhnPrivateChannelFamily (
+ channel_family_id, org_id, max_members, current_members, fve_max_members, fve_current_members
+ ) values (
+ channel_family_id_in, customer_id_in, quantity, 0, flex, 0 );
+ return;
+ end if;
+
+ for perm in pubperms loop
+ if quantity = 0 then
+ perform rhn_entitlements.prune_family(
+ perm.org_id,
+ channel_family_id_in,
+ quantity,
+ flex
+ );
+ if done = 0 then
+ delete from rhnPublicChannelFamily
+ where channel_family_id = channel_family_id_in;
+ end if;
+ end if;
+ done := 1;
+ end loop;
+ -- if done's not 1, then we don't have any entitlements
+ if done != 1 then
+ insert into rhnPublicChannelFamily (
+ channel_family_id
+ ) values (
+ channel_family_id_in
+ );
+ end if;
+ end$$
+language plpgsql;
+
+ -- this expects quantity_in to be the number of available slots, not the
+ -- max_members of the server group. If you give it too many, it'll fail
+ -- and raise servergroup_max_members.
+ -- We should NEVER run this unless we're SURE that we won't
+ -- be violating the max.
+ create or replace function entitle_last_modified_servers (
+ customer_id_in in numeric, -- customer_id
+ type_label_in in varchar, -- 'enterprise_entitled'
+ quantity_in in numeric -- 3
+ ) returns void
+as $$
+ declare
+ -- find the servers that aren't currently in slots
+ servers cursor(cid_in numeric, quant_in numeric) for
+ select rs.id as server_id
+ from rhnServer rs
+ where 1=1
+ and rs.org_id = cid_in
+ and not exists (
+ select 1
+ from rhnServerGroup sg,
+ rhnServerGroupMembers rsgm
+ where rsgm.server_id = rs.id
+ and rsgm.server_group_id = sg.id
+ and sg.group_type is not null
+ )
+ and not exists (
+ select 1
+ from rhnVirtualInstance vi
+ where vi.virtual_system_id =
+ rs.id
+ )
+ order by modified desc
+ limit quant_in;
+ begin
+ for server in servers(customer_id_in, quantity_in) loop
+ perform rhn_entitlements.entitle_server(server.server_id, type_label_in);
+ end loop;
+ end$$
+language plpgsql;
+
+ create or replace function subscribe_newest_servers (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ declare
+ -- find servers without base channels
+ servers cursor(cid_in numeric) for
+ select s.id
+ from rhnServer s
+ where 1=1
+ and s.org_id = cid_in
+ and not exists (
+ select 1
+ from rhnChannel c,
+ rhnServerChannel sc
+ where sc.server_id = s.id
+ and sc.channel_id = c.id
+ and c.parent_channel is null
+ )
+ and not exists (
+ select 1
+ from rhnVirtualInstance vi
+ where vi.virtual_system_id = s.id
+ )
+ order by s.modified desc;
+ channel_id numeric;
+ begin
+ for server in servers(customer_id_in) loop
+ channel_id := rhn_channel.guess_server_base(server.id);
+ if channel_id is not null then
+ begin
+ perform rhn_channel.subscribe_server(server.id, channel_id);
+ -- exception is really channel_family_no_subscriptions
+ exception
+ when others then
+ null;
+ end;
+ end if;
+ end loop;
+ end$$
+language plpgsql;
+
+
+-- restore the original setting
+update pg_settings set setting = overlay( setting placing '' from 1 for (length('rhn_entitlements')+1) ) where name = 'search_path';
10 years, 2 months
Changes to 'refs/tags/spacewalk-java-2.0.3-1'
by Tomáš Kašpárek
Tag 'spacewalk-java-2.0.3-1' created by Tomas Kasparek <tkasparek(a)redhat.com> at 2013-07-26 08:45 +0000
Tagging package [spacewalk-java] version [2.0.3-1] in directory [java/].
Changes since spacewalk-repo-2.0-3:
Grant Gainey (1):
ISS: Return LookupException to getDefaultMaster() if there isn't one
Miroslav Suchý (1):
spacewalk-web has been retired
Tomas Kasparek (1):
Automatic commit of package [spacewalk-java] release [2.0.3-1].
Tomas Lestach (1):
986527 - removing extra semicolon
---
java/code/src/com/redhat/rhn/common/db/datasource/xml/Channel_queries.xml | 2 +-
java/code/src/com/redhat/rhn/frontend/xmlrpc/sync/master/MasterHandler.java | 4 +++-
java/spacewalk-java.spec | 6 +++++-
rel-eng/packages/spacewalk-java | 2 +-
rel-eng/push-packages-to-fedora.sh | 2 +-
5 files changed, 11 insertions(+), 5 deletions(-)
---
10 years, 2 months
Branch 'SPACEWALK-2.0' - java/spacewalk-java.spec rel-eng/packages
by Tomáš Kašpárek
java/spacewalk-java.spec | 6 +++++-
rel-eng/packages/spacewalk-java | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
New commits:
commit 3f07342397dd022a189e14c0e727f6002d1c2529
Author: Tomas Kasparek <tkasparek(a)redhat.com>
Date: Fri Jul 26 10:45:38 2013 +0200
Automatic commit of package [spacewalk-java] release [2.0.3-1].
diff --git a/java/spacewalk-java.spec b/java/spacewalk-java.spec
index 6db412c..1963d16 100644
--- a/java/spacewalk-java.spec
+++ b/java/spacewalk-java.spec
@@ -28,7 +28,7 @@ Name: spacewalk-java
Summary: Spacewalk Java site packages
Group: Applications/Internet
License: GPLv2
-Version: 2.0.2
+Version: 2.0.3
Release: 1%{?dist}
URL: https://fedorahosted.org/spacewalk
Source0: https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar.gz
@@ -771,6 +771,10 @@ fi
%{jardir}/postgresql-jdbc.jar
%changelog
+* Fri Jul 26 2013 Tomas Kasparek <tkasparek(a)redhat.com> 2.0.3-1
+- ISS: Return LookupException to getDefaultMaster() if there isn't one
+- 986527 - removing extra semicolon
+
* Thu Jul 18 2013 Tomas Lestach <tlestach(a)redhat.com> 2.0.2-1
- 855845 - escaping system name on /rhn/systems/customdata/UpdateCustomKey.do
- 865595 - specify custom info searchability more precisely
diff --git a/rel-eng/packages/spacewalk-java b/rel-eng/packages/spacewalk-java
index 612658a..06c6d1e 100644
--- a/rel-eng/packages/spacewalk-java
+++ b/rel-eng/packages/spacewalk-java
@@ -1 +1 @@
-2.0.2-1 java/
+2.0.3-1 java/
10 years, 2 months
Branch 'SPACEWALK-2.0' - 2 commits - java/code
by Tomáš Kašpárek
java/code/src/com/redhat/rhn/common/db/datasource/xml/Channel_queries.xml | 2 +-
java/code/src/com/redhat/rhn/frontend/xmlrpc/sync/master/MasterHandler.java | 4 +++-
2 files changed, 4 insertions(+), 2 deletions(-)
New commits:
commit a17484ef0eee16a2770561cf235a6ffda6ddb5ec
Author: Grant Gainey <ggainey(a)redhat.com>
Date: Fri Jul 19 09:45:55 2013 -0400
ISS: Return LookupException to getDefaultMaster() if there isn't one
(cherry picked from commit 5308e5f069f40449acd6f4d764389aa01f9adb36)
diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/sync/master/MasterHandler.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/sync/master/MasterHandler.java
index d1438a1..7be457c 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/sync/master/MasterHandler.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/sync/master/MasterHandler.java
@@ -152,7 +152,9 @@ public class MasterHandler extends BaseHandler {
*/
public IssMaster getDefaultMaster(String sessionKey) {
ensureSatAdmin(getLoggedInUser(sessionKey));
- return IssFactory.getCurrentMaster();
+ IssMaster dflt = IssFactory.getCurrentMaster();
+ validateExists(dflt, "Default Master");
+ return dflt;
}
/**
commit d0be308bea3ed625d18cf10ee3b8f61f5671675c
Author: Tomas Lestach <tlestach(a)redhat.com>
Date: Mon Jul 22 09:48:07 2013 +0200
986527 - removing extra semicolon
(cherry picked from commit 5bb687cedfd93cdfecb596ba89072d83e6ec3297)
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 e57af31..f5c9de9 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
@@ -200,7 +200,7 @@ ORDER BY UPPER(C.name)
SELECT u.id
FROM web_contact u
WHERE u.org_id = :org_id
- AND rhn_channel.user_role_check(:channel_id, u.id, 'manage')= 1;
+ AND rhn_channel.user_role_check(:channel_id, u.id, 'manage') = 1
</query>
</mode>
10 years, 2 months
Changes to 'refs/tags/spacewalk-java-2.1.7-1'
by Grant Gainey
Tag 'spacewalk-java-2.1.7-1' created by Grant Gainey <ggainey(a)redhat.com> at 2013-07-25 20:09 +0000
Tagging package [spacewalk-java] version [2.1.7-1] in directory [java/].
Changes since spacewalk-schema-2.1.3-1:
Grant Gainey (2):
987977 - Fix there-can-be-solaris issue and make Upgrade behave like everything else
Automatic commit of package [spacewalk-java] release [2.1.7-1].
---
java/code/src/com/redhat/rhn/frontend/events/SsmInstallPackagesAction.java | 21 --
java/code/src/com/redhat/rhn/frontend/events/SsmPackagesAction.java | 83 +++++-----
java/code/src/com/redhat/rhn/frontend/events/SsmRemovePackagesAction.java | 33 ---
java/code/src/com/redhat/rhn/frontend/events/SsmUpgradePackagesAction.java | 16 -
java/spacewalk-java.spec | 6
rel-eng/packages/spacewalk-java | 2
6 files changed, 57 insertions(+), 104 deletions(-)
---
10 years, 2 months
java/spacewalk-java.spec rel-eng/packages
by Grant Gainey
java/spacewalk-java.spec | 6 +++++-
rel-eng/packages/spacewalk-java | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
New commits:
commit 46de52a1e9b365f6d9f02d442058c37b698cb0bf
Author: Grant Gainey <ggainey(a)redhat.com>
Date: Thu Jul 25 16:09:55 2013 -0400
Automatic commit of package [spacewalk-java] release [2.1.7-1].
diff --git a/java/spacewalk-java.spec b/java/spacewalk-java.spec
index a399da3..f91b564 100644
--- a/java/spacewalk-java.spec
+++ b/java/spacewalk-java.spec
@@ -28,7 +28,7 @@ Name: spacewalk-java
Summary: Spacewalk Java site packages
Group: Applications/Internet
License: GPLv2
-Version: 2.1.6
+Version: 2.1.7
Release: 1%{?dist}
URL: https://fedorahosted.org/spacewalk
Source0: https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar.gz
@@ -771,6 +771,10 @@ fi
%{jardir}/postgresql-jdbc.jar
%changelog
+* Thu Jul 25 2013 Grant Gainey <ggainey(a)redhat.com> 2.1.7-1
+- 987977 - Fix there-can-be-solaris issue and make Upgrade behave like
+ everything else
+
* Wed Jul 24 2013 Grant Gainey <ggainey(a)redhat.com> 2.1.6-1
- Make checkstyle happy
- 987977 - Fix chaining of pkg-scheduling in SSM
diff --git a/rel-eng/packages/spacewalk-java b/rel-eng/packages/spacewalk-java
index 8cb278d..cf5150a 100644
--- a/rel-eng/packages/spacewalk-java
+++ b/rel-eng/packages/spacewalk-java
@@ -1 +1 @@
-2.1.6-1 java/
+2.1.7-1 java/
10 years, 2 months
java/code
by Grant Gainey
java/code/src/com/redhat/rhn/frontend/events/SsmInstallPackagesAction.java | 21 --
java/code/src/com/redhat/rhn/frontend/events/SsmPackagesAction.java | 83 +++++-----
java/code/src/com/redhat/rhn/frontend/events/SsmRemovePackagesAction.java | 33 ---
java/code/src/com/redhat/rhn/frontend/events/SsmUpgradePackagesAction.java | 16 -
4 files changed, 51 insertions(+), 102 deletions(-)
New commits:
commit caac301bfbef1353df6fb8e4b0f7d71bb9fac7b4
Author: Grant Gainey <ggainey(a)redhat.com>
Date: Thu Jul 25 16:09:21 2013 -0400
987977 - Fix there-can-be-solaris issue and make Upgrade behave like everything else
diff --git a/java/code/src/com/redhat/rhn/frontend/events/SsmInstallPackagesAction.java b/java/code/src/com/redhat/rhn/frontend/events/SsmInstallPackagesAction.java
index 1369b99..afa4b68 100644
--- a/java/code/src/com/redhat/rhn/frontend/events/SsmInstallPackagesAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/events/SsmInstallPackagesAction.java
@@ -22,7 +22,6 @@ import java.util.Map;
import java.util.Set;
import com.redhat.rhn.domain.action.Action;
-import com.redhat.rhn.domain.server.Server;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.frontend.action.SetLabels;
import com.redhat.rhn.frontend.dto.EssentialServerDto;
@@ -75,24 +74,4 @@ public class SsmInstallPackagesAction extends SsmPackagesAction {
return pkgActions;
}
- protected Action doSchedule(SsmPackageEvent event, User user, Server s, Date earliest) {
- SsmInstallPackagesEvent sipe = (SsmInstallPackagesEvent) event;
-
- Set<String> data = sipe.getPackages();
- // Convert the package list to domain objects
- List<PackageListItem> pkgListItems = new ArrayList<PackageListItem>(data.size());
- for (String key : data) {
- pkgListItems.add(PackageListItem.parse(key));
- }
-
- // Convert to list of maps
- List<Map<String, Long>> packageListData = PackageListItem
- .toKeyMaps(pkgListItems);
-
- Action pkgAction = ActionManager.schedulePackageInstall(user, s,
- packageListData, earliest);
-
- return pkgAction;
- }
-
}
diff --git a/java/code/src/com/redhat/rhn/frontend/events/SsmPackagesAction.java b/java/code/src/com/redhat/rhn/frontend/events/SsmPackagesAction.java
index 70fc767..dc24937 100644
--- a/java/code/src/com/redhat/rhn/frontend/events/SsmPackagesAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/events/SsmPackagesAction.java
@@ -14,7 +14,6 @@
*/
package com.redhat.rhn.frontend.events;
-import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -25,7 +24,6 @@ import com.redhat.rhn.common.messaging.EventMessage;
import com.redhat.rhn.domain.action.Action;
import com.redhat.rhn.domain.action.script.ScriptActionDetails;
import com.redhat.rhn.domain.action.script.ScriptRunAction;
-import com.redhat.rhn.domain.server.Server;
import com.redhat.rhn.domain.server.ServerFactory;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.domain.user.UserFactory;
@@ -107,54 +105,65 @@ public abstract class SsmPackagesAction extends AbstractDatabaseAction {
log.debug("Scheduling package actions.");
Date earliest = event.getEarliest();
- List<Long> serverIds = getAffectedServers(event, user);
+ List<Long> sids = getAffectedServers(event, user);
+
log.debug("Scheduling actions.");
- // If we have a remote-cmd, have to correctly order it and the package action(s)
+ // If we have a remote-cmd, have to correctly order it and the package
+ // action(s)
if (event.getScriptDetails() != null) {
- for (Long sid : serverIds) {
- Server s = ServerFactory.lookupById(sid);
- List<Long> sidList = new ArrayList<Long>();
- sidList.add(sid);
- ScriptActionDetails sad = event.getScriptDetails();
- if (event.isBefore()) {
- log.debug("Scheduling remote-action BEFORE.");
-
- ScriptRunAction sra = ActionManager.scheduleScriptRun(user, sidList,
- null, sad, earliest);
- ActionManager.storeAction(sra);
+ // It's possible to have non-linux servers in the list, and different Actions
+ // are created for them. Get the separate lists
+ List<Long> rhelIds = ServerFactory.listLinuxSystems(sids);
+ List<Long> solarisIds = ServerFactory.listSolarisSystems(sids);
- Action pkgAction = doSchedule(event, user, s, earliest);
+ ScriptActionDetails sad = event.getScriptDetails();
+ List<Action> pkgActions = doSchedule(event, user, sids, earliest);
+ for (Action a : pkgActions) {
- Action prevAction = sra;
- pkgAction.setPrerequisite(prevAction);
- ActionManager.storeAction(pkgAction);
- prevAction = pkgAction;
+ if (event.isBefore()) {
+ log.debug("Scheduling remote-action BEFORE.");
+ if (!rhelIds.isEmpty()) {
+ ScriptRunAction sra = ActionManager.scheduleScriptRun(user,
+ rhelIds, null, sad, earliest);
+ ActionManager.storeAction(sra);
+ a.setPrerequisite(sra);
+ ActionManager.storeAction(a);
+ }
+
+ if (!solarisIds.isEmpty()) {
+ ScriptRunAction sra = ActionManager.scheduleScriptRun(user,
+ solarisIds, null, sad, earliest);
+ ActionManager.storeAction(sra);
+ a.setPrerequisite(sra);
+ ActionManager.storeAction(a);
+ }
}
else {
log.debug("Scheduling remote-action AFTER.");
- Action pkgAction = doSchedule(event, user, s, earliest);
- ScriptRunAction sra = ActionManager.scheduleScriptRun(user, sidList,
- null, sad, earliest);
-
- // Might be more than one action from schedPkgActions
- Action prevAction = null;
- if (prevAction != null) {
- pkgAction.setPrerequisite(prevAction);
- }
- ActionManager.storeAction(pkgAction);
- prevAction = pkgAction;
-
- sra.setPrerequisite(prevAction);
- ActionManager.storeAction(sra);
+ if (!rhelIds.isEmpty()) {
+ ScriptRunAction sra = ActionManager.scheduleScriptRun(user,
+ rhelIds, null, sad, earliest);
+ ActionManager.storeAction(a);
+ sra.setPrerequisite(a);
+ ActionManager.storeAction(sra);
+ }
+
+ if (!solarisIds.isEmpty()) {
+ ScriptRunAction sra = ActionManager.scheduleScriptRun(user,
+ solarisIds, null, sad, earliest);
+ ActionManager.storeAction(a);
+ sra.setPrerequisite(a);
+ ActionManager.storeAction(sra);
+ }
}
}
}
else { // No remote-script to schedule
- doSchedule(event, user, serverIds, earliest);
+ doSchedule(event, user, sids, earliest);
}
log.debug("Done scheduling package actions.");
@@ -164,10 +173,6 @@ public abstract class SsmPackagesAction extends AbstractDatabaseAction {
protected abstract List<Long> getAffectedServers(SsmPackageEvent event, User u);
- protected abstract Action doSchedule(SsmPackageEvent event,
- User user,
- Server s,
- Date earliest);
protected abstract List<Action> doSchedule(SsmPackageEvent event,
User user,
diff --git a/java/code/src/com/redhat/rhn/frontend/events/SsmRemovePackagesAction.java b/java/code/src/com/redhat/rhn/frontend/events/SsmRemovePackagesAction.java
index dcfdf92..c17526e 100644
--- a/java/code/src/com/redhat/rhn/frontend/events/SsmRemovePackagesAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/events/SsmRemovePackagesAction.java
@@ -24,7 +24,6 @@ import java.util.Set;
import org.apache.log4j.Logger;
import com.redhat.rhn.domain.action.Action;
-import com.redhat.rhn.domain.server.Server;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.frontend.dto.PackageListItem;
import com.redhat.rhn.manager.action.ActionManager;
@@ -117,36 +116,4 @@ public class SsmRemovePackagesAction extends SsmPackagesAction {
return actions;
}
- protected Action doSchedule(SsmPackageEvent event, User user, Server s, Date earliest) {
-
- SsmRemovePackagesEvent srpe = (SsmRemovePackagesEvent) event;
-
- List<Map> result = srpe.getResult();
-
- Set<PackageListItem> allPackages = new HashSet<PackageListItem>();
-
- for (Map data : result) {
-
- // Get the packages out of the elaborator
- List<Map> elabList = (List<Map>) data.get("elaborator0");
- if (elabList != null) {
- for (Map elabMap : elabList) {
- String idCombo = (String) elabMap.get("id_combo");
- PackageListItem item = PackageListItem.parse(idCombo);
- allPackages.add(item);
- }
- }
- }
-
- List<PackageListItem> allPackagesList = new ArrayList<PackageListItem>(allPackages);
- List<Map<String, Long>> packageListData = PackageListItem
- .toKeyMaps(allPackagesList);
-
- Action action = ActionManager.schedulePackageRemoval(user, s,
- packageListData, earliest);
-
- return action;
- }
-
-
}
diff --git a/java/code/src/com/redhat/rhn/frontend/events/SsmUpgradePackagesAction.java b/java/code/src/com/redhat/rhn/frontend/events/SsmUpgradePackagesAction.java
index 84b9491..36cbde5 100644
--- a/java/code/src/com/redhat/rhn/frontend/events/SsmUpgradePackagesAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/events/SsmUpgradePackagesAction.java
@@ -20,7 +20,6 @@ import java.util.List;
import java.util.Map;
import com.redhat.rhn.domain.action.Action;
-import com.redhat.rhn.domain.server.Server;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.manager.action.ActionManager;
@@ -49,16 +48,15 @@ public class SsmUpgradePackagesAction extends SsmPackagesAction {
SsmUpgradePackagesEvent supe = (SsmUpgradePackagesEvent) event;
Map<Long, List<Map<String, Long>>> packageListItems = supe.getSysPackageSet();
+ List<Map<String, Long>> pkgs = new ArrayList<Map<String, Long>>();
+ for (List<Map<String, Long>> pkgList : packageListItems.values()) {
+ for (Map<String, Long> pkg : pkgList) {
+ pkgs.add(pkg);
+ }
+ }
- return ActionManager.schedulePackageUpgrades(user, packageListItems, earliest);
+ return ActionManager.schedulePackageInstall(user, sids, pkgs, earliest);
}
- protected Action doSchedule(SsmPackageEvent event, User user, Server s, Date earliest) {
-
- SsmUpgradePackagesEvent supe = (SsmUpgradePackagesEvent) event;
- List<Map<String, Long>> packageListItems = supe.getSysPackageSet().get(s.getId());
-
- return ActionManager.schedulePackageUpgrade(user, s, packageListItems, earliest);
- }
}
10 years, 2 months