1 23 24 29 30 package com.sun.enterprise.deployment.backend; 31 32 import java.io.File ; 33 import java.io.IOException ; 34 import java.util.logging.*; 35 import java.security.AccessController ; 36 import java.security.PrivilegedAction ; 37 38 import com.sun.enterprise.config.ConfigException; 39 import com.sun.enterprise.deployment.Application; 40 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 41 import com.sun.enterprise.deployment.archivist.ApplicationArchivist; 42 import com.sun.enterprise.instance.ApplicationEnvironment; 43 import com.sun.enterprise.instance.AppsManager; 44 import com.sun.enterprise.instance.BaseManager; 45 import com.sun.enterprise.instance.InstanceEnvironment; 46 import com.sun.enterprise.util.io.FileSource; 47 import com.sun.enterprise.util.io.FileUtils; 48 import com.sun.enterprise.util.zip.ZipFileException; 49 import com.sun.enterprise.util.i18n.StringManager; 50 import com.sun.enterprise.util.diagnostics.Reminder; 51 import com.sun.enterprise.deployment.phasing.DeploymentServiceUtils; 52 53 58 59 public class AppUnDeployer extends AppDeployerBase 60 { 61 AppUnDeployer(DeploymentRequest r) throws IASDeploymentException 62 { 63 super(r); 64 } 65 66 68 public void doRequest() throws IASDeploymentException 69 { 70 doRequestPrepare(); 71 doRequestFinish(); 72 } 73 74 76 public void doRequestPrepare() throws IASDeploymentException 77 { 78 try 79 { 80 begin(); 81 } 82 catch(IASDeploymentException e) 83 { 84 throw e; 85 } 86 catch(Exception e) 87 { 88 String msg = localStrings.getString( 89 "enterprise.deployment.backend.dorequest_exception"); 90 logger.log(Level.WARNING, msg, e); 91 throw new IASDeploymentException(msg, e); 92 } 93 } 94 95 97 public void doRequestFinish() throws IASDeploymentException 98 { 99 try 100 { 101 predeploy(); 102 localBegin(); undeploy(); 104 removePolicy(); 105 } 106 catch(IASDeploymentException e) 107 { 108 throw e; 109 } 110 catch(Exception e) 111 { 112 String msg = localStrings.getString( 113 "enterprise.deployment.backend.dorequest_exception"); 114 logger.log(Level.WARNING, msg, e); 115 throw new IASDeploymentException(msg, e); 116 } 117 finally 118 { 119 finish(); 120 } 121 } 122 123 127 public void cleanup_internal() { 128 try { 129 if(isMaybeCMPDropTables) 130 dropTables(); 131 132 liquidate(); 133 } 134 catch(Exception e) { 135 logger.warning("Caught an Exception in cleanup_internal: " + e); 136 } 137 } 138 139 141 protected final File setAppDir() throws IASDeploymentException { 142 try { 143 return new File (DeploymentServiceUtils.getLocation(getAppName(), 144 request.getType())); 145 } 146 catch(Exception e) { 147 String msg = localStrings.getString( 148 "enterprise.deployment.backend.error_getting_app_directory", 149 e); 150 throw new IASDeploymentException(msg, e); 151 } 152 } 153 154 156 private void undeploy() throws IASDeploymentException { 157 try { 158 getManager().unregisterDescriptor(getAppName()); 159 addToSummary(successMessage + getAppName()); 160 } 161 catch(Exception e) { 162 if(e instanceof IASDeploymentException) 163 throw (IASDeploymentException)e; 164 else 165 throw new IASDeploymentException(e); 166 } 167 } 168 169 171 private void liquidate() throws IASDeploymentException, ConfigException 172 { 173 174 File aDir = getAppDir(); 175 File sDir = getStubsDir(); 176 File jDir = getJSPDir(); 177 File xDir = getXMLDir(); 178 File jwsDir = getJWSDir(); 179 assert aDir != null && sDir != null && jDir != null; 180 181 if (! (DeploymentServiceUtils.isDirectoryDeployed(getAppName(), 183 request.getType()) || request.isReload()) ) 184 { 185 if(FileUtils.safeIsDirectory(aDir)) { 186 FileUtils.whack(aDir); 187 logger.fine("Deleted Application Directory: " + aDir.getPath()); 188 } 189 else { 190 logger.warning("Can't delete Application Directory -- it isn't a directory: " 191 + aDir.getPath()); 192 } 193 } 194 else { 195 logger.fine("Did NOT delete Application Directory (Directory-Deployment): " + aDir); 196 } 197 198 if(FileUtils.safeIsDirectory(sDir)) { 199 FileUtils.whack(sDir); 200 } 201 else { 202 logger.finest("Can't delete Stubs Directory -- it isn't a directory: " 203 + FileUtils.safeGetCanonicalPath(sDir)); 204 } 205 206 if(FileUtils.safeIsDirectory(jDir)) { 207 FileUtils.whack(jDir); 208 } 209 else { 210 logger.finest("Can't delete JSP Directory -- it isn't a directory: " 211 + FileUtils.safeGetCanonicalPath(jDir)); 212 } 213 214 if(FileUtils.safeIsDirectory(xDir)) { 215 FileUtils.whack(xDir); 216 } 217 else { 218 logger.finest("Can't delete XML Directory -- it isn't a directory: " 219 + FileUtils.safeGetCanonicalPath(xDir)); 220 } 221 222 if(FileUtils.safeIsDirectory(jwsDir)) { 223 FileUtils.whack(jwsDir); 224 } 225 else { 226 logger.finest("Can't delete JWS Directory -- it isn't a directory: " 227 + FileUtils.safeGetCanonicalPath(jwsDir)); 228 } 229 230 } 231 232 238 private void localBegin() { 239 246 try { 247 if(getRequest().isMaybeCMPDropTables()) { 248 isMaybeCMPDropTables = true; 249 250 if (FileUtils.safeIsDirectory(getXMLDir())) { 251 applicationDD = 252 DeploymentUtils.getAppDescriptor(getXMLDir().getAbsolutePath()); 253 FileArchive archive = new FileArchive(); 254 archive.open(getAppDir().getAbsolutePath()); 255 try { 256 ApplicationArchivist. 257 readPersistenceDeploymentDescriptorsRecursively( 258 archive, applicationDD); 259 } finally { 260 archive.close(); 261 } 262 } else { 263 applicationDD = 264 DeploymentUtils.getAppDescriptor(getAppDir().getAbsolutePath()); 265 } 266 267 applicationDD.setRegistrationName(getAppName()); 268 } 269 } 270 catch(Exception e) { 271 logger.warning("Caught an Exception in localBegin: " + e); 272 } 273 } 274 275 283 private void dropTables() { 284 assert isMaybeCMPDropTables; 286 try { 287 DeploymentEventInfo info = new DeploymentEventInfo(getAppDir(), 288 getStubsDir(), applicationDD, getRequest()); 289 DeploymentEvent ev = new DeploymentEvent(DeploymentEventType.PRE_UNDEPLOY, info); 290 DeploymentEventManager.notifyDeploymentEvent(ev); 291 } 292 catch(Throwable t) { 293 logger.warning("Caught a Throwable in dropTables: " + t); 294 } 295 } 296 297 299 private String failureMessage = "Undeployment Failed -- rolled back undeployment"; 300 private String successMessage = "Undeployment Successful for "; 301 private boolean isMaybeCMPDropTables = false; 302 private Application applicationDD = null; 303 private static StringManager localStrings = StringManager.getManager( AppUnDeployer.class ); 304 } 305 | Popular Tags |