java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemMigrateAction.java
| 197 ++++++++++
java/code/src/com/redhat/rhn/frontend/action/systems/sdc/validation/systemMigrateForm.xsd
| 17
java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml
| 46 ++
java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml
| 35 +
java/code/webapp/WEB-INF/nav/system_detail.xml
| 1
java/code/webapp/WEB-INF/pages/systems/sdc/migrate.jsp
| 37 +
java/code/webapp/WEB-INF/struts-config.xml
| 20 +
web/html/nav/system_detail.xml
| 1
8 files changed, 354 insertions(+)
New commits:
commit 5d5de065ad0b5d080b43acbdbaa74aef56cf0e5f
Author: Colin Coe <colin.coe(a)gmail.com>
Date: Thu Jul 22 21:38:56 2010 +0800
Add system migration to webUI
diff --git
a/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemMigrateAction.java
b/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemMigrateAction.java
new file mode 100644
index 0000000..a9e0ce7
--- /dev/null
+++ b/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemMigrateAction.java
@@ -0,0 +1,197 @@
+/**
+ * Copyright (c) 2009--2010 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.
+ */
+package com.redhat.rhn.frontend.action.systems.sdc;
+
+import com.redhat.rhn.common.validator.ValidatorError;
+import
com.redhat.rhn.domain.org.Org;
+import com.redhat.rhn.domain.org.OrgFactory;
+import com.redhat.rhn.domain.role.RoleFactory;
+import com.redhat.rhn.domain.server.Server;
+import com.redhat.rhn.domain.user.User;
+import com.redhat.rhn.frontend.struts.RequestContext;
+import com.redhat.rhn.frontend.struts.RhnAction;
+import com.redhat.rhn.frontend.struts.RhnValidationHelper;
+import com.redhat.rhn.frontend.xmlrpc.org.trusts.OrgTrustHandler;
+import com.redhat.rhn.manager.org.MigrationManager;
+import com.redhat.rhn.manager.system.SystemManager;
+
+import org.apache.log4j.Logger;
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.DynaActionForm;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * SystemDetailsEditAction
+ * @version $Rev$
+ */
+public class SystemMigrateAction extends RhnAction {
+
+ private static Logger log = Logger.getLogger(SystemMigrateAction.class);
+
+ public static final String SID = "sid";
+ public static final String ORG = "to_org";
+
+ private OrgTrustHandler handler = new OrgTrustHandler();
+
+
+ /** {@inheritDoc} */
+ public ActionForward execute(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ RequestContext rctx = new RequestContext(request);
+ DynaActionForm daForm = (DynaActionForm) form;
+ User user = rctx.getLoggedInUser();
+ String forwardName = "default";
+ Integer trustedOrgCount = user.getOrg().getTrustedOrgs().size();
+
+ if (isSubmitted(daForm)) {
+ ActionErrors errors = RhnValidationHelper.validateDynaActionForm(this,
daForm);
+
+ Server s = SystemManager.lookupByIdAndUser(
+ rctx.getRequiredParam(RequestContext.SID), user);
+ // As a pre-requisite to performing the actual migration, verify that each
+ // server that is planned for migration passes the criteria that follows.
+ // If any of the servers fails that criteria, none will be migrated.
+
+ Org toOrg = OrgFactory.lookupByName(daForm.getString(ORG));
+ Long sid = s.getId(); // Required because if the migration goes ahead
we
+ String name = s.getName(); // can't lookup the servers ID
+
+ // Don't attempt migration to organisation "None"
+ if (toOrg == null) {
+ ValidatorError err = new
ValidatorError("system.migrate.no_org_specified");
+ getStrutsDelegate().saveMessages(request,
+ RhnValidationHelper.validatorErrorToActionErrors(err));
+ }
+ else {
+ forwardName = "success";
+
+ // unless the user is a satellite admin, they are not permitted to
migrate
+ // systems from an org that they do not belong to
+ if ((!user.hasRole(RoleFactory.SAT_ADMIN)) &&
+ (!user.getOrg().equals(s.getOrg()))) {
+ ValidatorError err = new
ValidatorError("system.migrate.user_no_perms");
+ getStrutsDelegate().saveMessages(request,
+ RhnValidationHelper.validatorErrorToActionErrors(err));
+ forwardName = "error";
+ }
+
+ // do not allow the user to migrate systems to/from the same org. doing
so
+ // would essentially remove entitlements, channels...etc from the
systems
+ // being migrated.
+ if (toOrg.equals(s.getOrg())) {
+ ValidatorError err = new
ValidatorError("system.migrate.same_org");
+ getStrutsDelegate().saveMessages(request,
+ RhnValidationHelper.validatorErrorToActionErrors(err));
+ forwardName = "error";
+ }
+
+ // if the originating org is not defined within the destination org's
trust
+ // the migration should not be permitted.
+ if (!toOrg.getTrustedOrgs().contains(s.getOrg())) {
+ ValidatorError err = new ValidatorError(
+ "system.migrate.org_not_trusted");
+ getStrutsDelegate().saveMessages(request,
+ RhnValidationHelper.validatorErrorToActionErrors(err));
+ forwardName = "error";
+ }
+
+ if (trustedOrgCount == 0) {
+ ValidatorError err = new ValidatorError(
+ "system.migrate.no_trusted_orgs");
+ getStrutsDelegate().saveMessages(request,
+ RhnValidationHelper.validatorErrorToActionErrors(err));
+ forwardName = "error";
+ }
+ }
+
+ if (errors.isEmpty() && forwardName.equals("success")) {
+ if (processSubmission(request, daForm, user, s, toOrg)) {
+ createSuccessMessage(request,
+ "sdc.details.migrate.success", name);
+
+ return mapping.findForward(forwardName);
+ }
+ else {
+ forwardName = "error";
+ }
+
+ }
+ else {
+ forwardName = "error";
+ getStrutsDelegate().saveMessages(request, errors);
+ }
+ }
+
+ if (forwardName.equals("default")) {
+ Server s = SystemManager.lookupByIdAndUser(
+ rctx.getRequiredParam(RequestContext.SID), user);
+ Org fromOrg = s.getOrg();
+ setupPageAndFormValues(rctx.getRequest(), daForm, user, s, fromOrg,
+ trustedOrgCount);
+ }
+
+ return mapping.findForward(forwardName);
+ }
+
+ /**
+ * Proccesses the system details edit form
+ * @param request to add messages to.
+ * @param daForm DynaActionForm to be processed
+ * @param user User submitting the form
+ * @param s Server whose details are being update
+ * @return true if the submission process didnot produce any errors.
+ */
+ private boolean processSubmission(HttpServletRequest request,
+ DynaActionForm daForm, User user, Server s, Org toOrg) {
+
+ boolean success = true;
+ boolean failure = false;
+
+ List<Server> serverList = new ArrayList<Server>();
+ serverList.add(s);
+
+ List<Long> serversMigrated = MigrationManager.migrateServers(user, toOrg,
serverList);
+
+ Iterator it = serversMigrated.iterator();
+ Long value = (Long)it.next();
+
+ if (value != null) {
+ return success;
+ }
+ return failure;
+ }
+
+ protected void setupPageAndFormValues(HttpServletRequest request,
+ DynaActionForm daForm, User user, Server s, Org o, Integer trustedOrgCount)
{
+
+ List orgList = new ArrayList(user.getOrg().getTrustedOrgs());
+
+ request.setAttribute("trustedOrgCount", trustedOrgCount);
+ request.setAttribute("system", s);
+ request.setAttribute("orgs", orgList);
+ request.setAttribute("org", o);
+ }
+
+}
diff --git
a/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/validation/systemMigrateForm.xsd
b/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/validation/systemMigrateForm.xsd
new file mode 100644
index 0000000..8533d28
--- /dev/null
+++
b/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/validation/systemMigrateForm.xsd
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+
+<schema targetNamespace="http://rhn.redhat.com"
+
xmlns="http://www.w3.org/1999/XMLSchema"
xmlns:rhn="http://rhn.redhat.com">
+ <attribute name="sid">
+ <simpleType baseType="long">
+ <minLength value="10"/>
+ <maxLength value="10"/>
+ <isRequired value="true"/>
+ </simpleType>
+ </attribute>
+ <attribute name="to_org">
+ <simpleType baseType="string">
+ <isRequired value="true"/>
+ </simpleType>
+ </attribute>
+</schema>
diff --git a/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml
b/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml
index d54f6f4..ef867e0 100644
--- a/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml
+++ b/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml
@@ -692,6 +692,12 @@
http://www.oasis-open.org/committees/xliff/documents/xliff-core-1.1.xsd&q...
<context context-type="sourcefile">Navigation
Menu</context>
</context-group>
</trans-unit>
+ <trans-unit id="Migrate">
+<source>Migrate</source>
+ <context-group name="ctx">
+ <context context-type="sourcefile">Navigation
Menu</context>
+ </context-group>
+ </trans-unit>
<trans-unit id="Packages">
<source>Packages</source>
<context-group name="ctx">
@@ -1516,6 +1522,18 @@
http://www.oasis-open.org/committees/xliff/documents/xliff-core-1.1.xsd&q...
</context-group>
</trans-unit>
<trans-unit id="message.perms_updated">
+ <trans-unit id="sid">
+<source>System ID</source>
+ <context-group name="ctx">
+ <context
context-type="sourcefile">/rhn/systems/details/SystemMigrate</context>
+ </context-group>
+ </trans-unit>
+ <trans-unit id="to_org">
+<source>Destination Organisation</source>
+ <context-group name="ctx">
+ <context
context-type="sourcefile">/rhn/systems/details/SystemMigrate</context>
+ </context-group>
+ </trans-unit>
<source>Permissions Updated</source>
<context-group name="ctx">
<context
context-type="sourcefile">/rhn/users/AssignedSystemGroups</context>
@@ -7771,6 +7789,34 @@ Follow this url to see the full list of inactive systems:
</context-group>
</trans-unit>
+ <trans-unit id="system.migrate.user_no_perms">
+<source>This user lacks the required permissions to migrate this
system.</source>
+ <context-group name="ctx">
+ <context
context-type="sourcefile">/rhn/systems/details/SystemMigrate.do</context>
+ </context-group>
+ </trans-unit>
+
+ <trans-unit id="system.migrate.org_not_trusted">
+<source>Systems can only be migrated between trusted organisations.</source>
+ <context-group name="ctx">
+ <context
context-type="sourcefile">/rhn/systems/details/SystemMigrate.do</context>
+ </context-group>
+ </trans-unit>
+
+ <trans-unit id="system.migrate.no_trusted_orgs">
+<source>This organisation has no trusts defined with other organisations, or no
other organisations are defined.</source>
+ <context-group name="ctx">
+ <context
context-type="sourcefile">/rhn/systems/details/SystemMigrate.do</context>
+ </context-group>
+ </trans-unit>
+
+ <trans-unit id="system.migrate.no_org_specified">
+<source>An organisation must be specified</source>
+ <context-group name="ctx">
+ <context
context-type="sourcefile">/rhn/systems/details/SystemMigrate.do</context>
+ </context-group>
+ </trans-unit>
+
<trans-unit id="system.entitle.invalid_addon_entitlement">
<source>Invalid add-on entitlement [{0}] provided.No such entitlement
exists.</source>
<context-group name="ctx">
diff --git a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml
b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml
index 85638b7..3cd7f72 100644
--- a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml
+++ b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml
@@ -18791,6 +18791,41 @@ performing a kickstart or creating a new kickstart
distribution.</strong>
</context-group>
</trans-unit>
+ <trans-unit id="sdc.details.migrate.header">
+ <source>Migrate System Between Organisations</source>
+ <context-group name="ctx">
+ <context
context-type="sourcefile">/systems/details/SystemMigrate.do</context>
+ </context-group>
+ </trans-unit>
+
+ <trans-unit id="sdc.details.migrate.org">
+ <source>Organisation Name</source>
+ <context-group name="ctx">
+ <context
context-type="sourcefile">/systems/details/SystemMigrate.do</context>
+ </context-group>
+ </trans-unit>
+
+ <trans-unit id="sdc.details.migrate.notrustedorgs">
+ <source>No trusted oranisations</source>
+ <context-group name="ctx">
+ <context
context-type="sourcefile">/systems/details/SystemMigrate.do</context>
+ </context-group>
+ </trans-unit>
+
+ <trans-unit id="sdc.details.migrate.migrate">
+ <source>Migrate System</source>
+ <context-group name="ctx">
+ <context
context-type="sourcefile">/systems/details/SystemMigrate.do</context>
+ </context-group>
+ </trans-unit>
+
+ <trans-unit id="sdc.details.migrate.success">
+ <source>System successfully migrated</source>
+ <context-group name="ctx">
+ <context
context-type="sourcefile">/systems/details/SystemMigrate.do</context>
+ </context-group>
+ </trans-unit>
+
<!-- SDC Details Edit Page strings -->
<trans-unit id="sdc.details.edit.header">
<source>Edit System Details</source>
diff --git a/java/code/webapp/WEB-INF/nav/system_detail.xml
b/java/code/webapp/WEB-INF/nav/system_detail.xml
index eeb0c48..60e4e99 100644
--- a/java/code/webapp/WEB-INF/nav/system_detail.xml
+++ b/java/code/webapp/WEB-INF/nav/system_detail.xml
@@ -17,6 +17,7 @@
<rhn-tab-url>/network/systems/details/hardware.pxt</rhn-tab-url>
<rhn-tab-url>/network/systems/hardware_list_refresh_confirm.pxt</rhn-tab-url>
</rhn-tab>
+ <rhn-tab name="Migrate" acl="user_role(org_admin)"
url="/rhn/systems/details/SystemMigrate.do" />
<rhn-tab name="Notes">
<rhn-tab-url>/network/systems/details/notes/notes_list.pxt</rhn-tab-url>
<rhn-tab-url>/network/systems/details/notes/edit.pxt</rhn-tab-url>
diff --git a/java/code/webapp/WEB-INF/pages/systems/sdc/migrate.jsp
b/java/code/webapp/WEB-INF/pages/systems/sdc/migrate.jsp
new file mode 100644
index 0000000..ed32738
--- /dev/null
+++ b/java/code/webapp/WEB-INF/pages/systems/sdc/migrate.jsp
@@ -0,0 +1,37 @@
+<%@ taglib
uri="http://java.sun.com/jsp/jstl/core" prefix="c"
%>
+<%@ taglib
uri="http://rhn.redhat.com/rhn" prefix="rhn" %>
+<%@ taglib
uri="http://jakarta.apache.org/struts/tags-bean"
prefix="bean" %>
+<%@ taglib
uri="http://jakarta.apache.org/struts/tags-html"
prefix="html" %>
+
+<html:html xhtml="true">
+ <body>
+ <%@ include
file="/WEB-INF/pages/common/fragments/systems/system-header.jspf" %>
+ <h2><bean:message
key="sdc.details.migrate.header"/></h2>
+
+ <html:form method="post"
action="/systems/details/SystemMigrate.do?sid=${system.id}">
+ <html:hidden property="submitted" value="true"/>
+ <table class="details">
+ <tr>
+ <th>
+ <bean:message key="sdc.details.migrate.org"/>
+ </th>
+ <td>
+ <html:select property="to_org">
+ <html:option value="">-- None --</html:option>
+ <c:forEach var="org" items="${orgs}">
+ <html:option
value="${org.name}">${org.name}</html:option>
+ </c:forEach>
+ </html:select>
+ </td>
+ </tr>
+ </table>
+
+ <hr/>
+ <div align="right">
+ <html:submit>
+ <bean:message key="sdc.details.migrate.migrate"/>
+ </html:submit>
+ </div>
+ </html:form>
+ </body>
+</html:html>
diff --git a/java/code/webapp/WEB-INF/struts-config.xml
b/java/code/webapp/WEB-INF/struts-config.xml
index 789b869..e6002c8 100644
--- a/java/code/webapp/WEB-INF/struts-config.xml
+++ b/java/code/webapp/WEB-INF/struts-config.xml
@@ -976,6 +976,12 @@
<form-property name="submitted"
type="java.lang.Boolean"/>
</form-bean>
+ <form-bean name="systemMigrateForm"
+ type="com.redhat.rhn.frontend.struts.ScrubbingDynaActionForm"
>
+ <form-property name="sid" type="java.lang.Long"/>
+ <form-property name="to_org" type="java.lang.String"/>
+ <form-property name="submitted"
type="java.lang.Boolean"/>
+ </form-bean>
<form-bean name="targetSystemsForm"
type="com.redhat.rhn.frontend.struts.ScrubbingDynaActionForm" >
@@ -3018,6 +3024,20 @@
path="/WEB-INF/pages/systems/sdc/details.jsp" />
</action>
+ <action path="/systems/details/SystemMigrate"
+ name="systemMigrateForm"
+ scope="request"
+ parameter="dispatch"
+ validate="false"
+ input="/WEB-INF/pages/systems/sdc/migrate.jsp"
+
type="com.redhat.rhn.frontend.action.systems.sdc.SystemMigrateAction">
+ <forward name="default"
+ path="/WEB-INF/pages/systems/sdc/migrate.jsp" />
+ <forward name="success"
+ path="/systems/SystemList.do" redirect="true"
/>
+ <forward name="error"
+ path="/systems/details/Overview.do" />
+ </action>
<action path="/systems/details/SystemChannels"
name="systemChannelsForm"
diff --git a/web/html/nav/system_detail.xml b/web/html/nav/system_detail.xml
index 216426c..43a5306 100644
--- a/web/html/nav/system_detail.xml
+++ b/web/html/nav/system_detail.xml
@@ -17,6 +17,7 @@
<rhn-tab-url>/network/systems/details/hardware.pxt</rhn-tab-url>
<rhn-tab-url>/network/systems/hardware_list_refresh_confirm.pxt</rhn-tab-url>
</rhn-tab>
+ <rhn-tab name="Migrate" acl="user_role(org_admin)"
url="/rhn/systems/details/SystemMigrate.do" />
<rhn-tab name="Notes">
<rhn-tab-url>/network/systems/details/notes/notes_list.pxt</rhn-tab-url>
<rhn-tab-url>/network/systems/details/notes/edit.pxt</rhn-tab-url>