1 25 26 package org.objectweb.jonas.webapp.jonasadmin.deploy; 27 28 import java.io.IOException ; 29 import java.util.ArrayList ; 30 import java.util.HashMap ; 31 import java.util.Map ; 32 33 import javax.management.ObjectName ; 34 import javax.servlet.ServletException ; 35 import javax.servlet.http.HttpServletRequest ; 36 import javax.servlet.http.HttpServletResponse ; 37 38 import org.apache.struts.action.ActionForm; 39 import org.apache.struts.action.ActionForward; 40 import org.apache.struts.action.ActionMapping; 41 import org.objectweb.jonas.jmx.JonasManagementRepr; 42 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx; 43 44 48 public class ApplyDomainDeployConfirmAction extends BaseDeployAction { 49 50 52 private ArrayList servers; 53 54 56 public ActionForward executeAction(ActionMapping p_Mapping, 57 ActionForm p_Form, HttpServletRequest p_Request, 58 HttpServletResponse p_Response) throws IOException , 59 ServletException { 60 61 DomainDeployForm oForm = (DomainDeployForm) p_Form; 62 63 66 if (!oForm.getDeploymentInProgress() && !oForm.getDeploymentComplete()) { 70 71 oForm.setDeploymentInProgress(true); 72 73 new DeployThread(p_Mapping, p_Form, p_Request, p_Response) { 76 77 public void run() { 78 DomainDeployForm oForm = (DomainDeployForm) p_Form; 80 81 try { 82 servers = oForm.getListTargetServers(); 84 ArrayList alApps = oForm.getListDeploy(); 86 Map reportList = oForm.getReports(); 88 89 String selectedAction = oForm.getSelectedAction(); 90 boolean replaceExisting = oForm.getReplacementOption(); 91 92 for (int i = 0; i < alApps.size(); i++) { 93 String current = (String ) alApps.get(i); 94 95 if (selectedAction.equals(DomainDeployForm.DEPLOY)) { 100 if (doDeployOperation(current)) { 101 reportList.put(current, getReport()); 102 resetProgress(); 103 } 104 else { 105 createException("Another domain deployment operation is running on this server."); 106 } 107 } else if (selectedAction.equals(DomainDeployForm.UPLOAD)) { 108 if (doUploadOperation(current, replaceExisting)) { 109 reportList.put(current, getReport()); 110 resetProgress(); 111 } 112 else { 113 createException("Another domain deployment operation is running on this server."); 114 } 115 } else if (selectedAction.equals(DomainDeployForm.UPLOADDEPLOY)) { 116 if (doUploadDeployOperation(current, replaceExisting)) { 117 reportList.put(current, getReport()); 118 resetProgress(); 119 } 120 else { 121 createException("Another domain deployment operation is running on this server."); 122 } 123 } 124 } 125 126 oForm.setDeploymentInProgress(false); 128 oForm.setDeploymentComplete(true); 130 } catch (Throwable t) { 131 oForm.setException(true); 132 addGlobalError(t); 133 saveErrors(p_Request, m_Errors); 134 } 135 } 136 }.start(); 137 } 138 139 return (p_Mapping.findForward("Domain Deploy Progress")); 141 } 142 143 private void createException(String message) throws OperationInProgressException { 144 throw new OperationInProgressException(message); 145 } 146 147 153 private boolean doDeployOperation(String appName) { 154 ObjectName on = JonasAdminJmx.getJ2eeDomainObjectName(); 155 156 String [] serverArray = new String [servers.size()]; 158 for (int i = 0; i < servers.size(); i++) { 159 serverArray[i] = (String ) servers.get(i); 160 } 161 162 Object [] params = new Object [] {serverArray, appName}; 164 String [] sig = new String [] {"[Ljava.lang.String;", "java.lang.String"}; 165 166 return ((Boolean ) JonasManagementRepr.invoke(on, 167 getDomainDeploymentMethodName(), params, sig)).booleanValue(); 168 } 169 170 177 private boolean doUploadOperation(String appName, boolean replaceExisting) { 178 ObjectName on = JonasAdminJmx.getJ2eeDomainObjectName(); 179 180 String [] serverArray = new String [servers.size()]; 182 for (int i = 0; i < servers.size(); i++) { 183 serverArray[i] = (String ) servers.get(i); 184 } 185 186 String opName = "uploadFile"; 188 Object [] params = new Object [] {serverArray, appName, Boolean.valueOf(replaceExisting)}; 189 String [] sig = new String [] {"[Ljava.lang.String;", "java.lang.String", "boolean"}; 190 191 return ((Boolean ) JonasManagementRepr.invoke(on, 192 opName, params, sig)).booleanValue(); 193 } 194 195 202 private boolean doUploadDeployOperation(String appName, boolean replaceExisting) { 203 ObjectName on = JonasAdminJmx.getJ2eeDomainObjectName(); 204 205 String [] serverArray = new String [servers.size()]; 207 for (int i = 0; i < servers.size(); i++) { 208 serverArray[i] = (String ) servers.get(i); 209 } 210 211 String opName = getDomainUploadDeployMethodName(); 213 Object [] params = new Object [] {serverArray, appName, Boolean.valueOf(replaceExisting)}; 214 String [] sig = new String [] {"[Ljava.lang.String;", "java.lang.String", "boolean"}; 215 216 return ((Boolean ) JonasManagementRepr.invoke(on, 217 opName, params, sig)).booleanValue(); 218 } 219 220 223 private void resetProgress() { 224 ObjectName on = JonasAdminJmx.getJ2eeDomainObjectName(); 225 Object [] params = new Object [] {}; 226 String [] sig = new String [] {}; 227 228 JonasManagementRepr.invoke(on, "resetProgress", params, sig); 229 } 230 231 236 private HashMap getReport() { 237 ObjectName on = JonasAdminJmx.getJ2eeDomainObjectName(); 238 HashMap report = (HashMap ) JonasManagementRepr.getAttribute(on, 239 "progressReport"); 240 241 return report; 242 } 243 244 247 protected class DeployThread extends Thread { 248 249 protected ActionMapping p_Mapping; 250 251 protected ActionForm p_Form; 252 253 protected HttpServletRequest p_Request; 254 255 protected HttpServletResponse p_Response; 256 257 public DeployThread(ActionMapping p_Mapping, ActionForm p_Form, 258 HttpServletRequest p_Request, HttpServletResponse p_Response) { 259 this.p_Mapping = p_Mapping; 260 this.p_Form = p_Form; 261 this.p_Request = p_Request; 262 this.p_Response = p_Response; 263 } 264 265 } 266 267 268 } 269 | Popular Tags |