1 23 24 42 43 package com.sun.enterprise.deployment.backend; 44 45 import java.io.*; 46 import java.util.logging.*; 47 import com.sun.enterprise.instance.ApplicationEnvironment; 48 import com.sun.enterprise.instance.InstanceEnvironment; 49 import com.sun.enterprise.util.io.FileSource; 50 import com.sun.enterprise.util.io.FileUtils; 51 import com.sun.enterprise.config.ConfigException; 52 import com.sun.enterprise.util.i18n.StringManager; 53 import com.sun.enterprise.util.diagnostics.Reminder; 54 import com.sun.enterprise.deployment.phasing.DeploymentServiceUtils; 55 56 public class AppReDeployer extends AppDeployer 57 { 58 62 AppReDeployer(DeploymentRequest r) throws IASDeploymentException 63 { 64 super(r); 65 } 66 67 71 75 public void cleanup_internal() 76 { 77 try 78 { 79 if(isArchive() && oldAppDir != null) 81 { 82 FileUtils.whack(oldAppDir); 83 84 if(oldAppDir.exists()) 85 logger.info("Unable to delete previous deployment directory: " + oldAppDir.getPath()); 86 else 87 logger.info("Deleted previous deployment directory: " + oldAppDir.getPath()); 88 } 89 } 90 catch(Exception e) 91 { 92 logger.info("Unable to delete previous deployment directory: " + oldAppDir.getPath()); 93 } 94 } 95 96 100 protected void begin() throws IASDeploymentException 101 { 102 105 super.begin(); 106 107 try 108 { 109 originalAppDir = new File(DeploymentServiceUtils.getLocation(getAppName(), request.getType())); 110 getManager().unregisterDescriptor(getAppName()); 111 removePolicy(); 112 } 113 catch(Exception e) 114 { 115 String msg = localStrings.getString( 116 "enterprise.deployment.backend.error_getting_app_location", 117 getAppName() ); 118 throw new IASDeploymentException( msg, e); 119 } 120 } 121 122 124 protected final void predeploy() throws IASDeploymentException 125 { 126 appWasUnregistered = true; 127 super.predeploy(); 128 setOldDirs(); 129 } 130 131 133 protected final File setAppDir() throws IASDeploymentException 134 { 135 File newAppDir = null; 136 137 if(isArchive()) 138 { 139 newAppDir = setAppDirArchive(); 140 } 141 else if(isDirectory()) 142 { 143 newAppDir = setAppDirDirectory(); 144 } 145 else 146 { 147 String msg = localStrings.getString( 148 "enterprise.deployment.backend.redeployment_not_dir_or_archive" ); 149 throw new IASDeploymentException( msg ); 150 } 151 152 newAppDir.mkdirs(); 153 return newAppDir; 154 } 155 156 158 protected final File getOldStubsDir() 159 { 160 return oldStubsDir; 163 } 164 165 167 protected final File getOldAppDir() 168 { 169 return oldAppDir; 172 } 173 174 176 protected void postDeploy() throws ConfigException, IASDeploymentException 177 { 178 super.postDeploy(); 179 180 if(FileUtils.safeIsDirectory(oldStubsDir)) 181 FileUtils.whack(oldStubsDir); 182 183 if(FileUtils.safeIsDirectory(oldJSPDir)) 184 FileUtils.whack(oldJSPDir); 185 186 if(FileUtils.safeIsDirectory(oldXMLDir)) 187 FileUtils.whack(oldXMLDir); 188 189 if(FileUtils.safeIsDirectory(oldJWSDir)) 190 FileUtils.whack(oldJWSDir); 191 } 192 193 195 196 protected final void rollback() 197 { 198 try 201 { 202 if(isArchive()) 203 rollbackArchive(); 204 else 205 rollbackDirectory(); 206 } 207 catch(Exception e) 208 { 209 logger.log( Level.WARNING, 211 "enterprise.deployment_rollback_error", e ); 212 } 213 } 214 216 protected String whatAreYou() 217 { 218 return "Redeployment"; 219 } 220 221 225 private final void rollbackArchive() throws IASDeploymentException, ConfigException 226 { 227 230 236 if(appdirWasRenamed) 237 { 238 DeleteOrKeepFailedStubs(getStubsDir()); 240 241 if(FileUtils.safeIsDirectory(getJSPDir())) 242 FileUtils.whack(getJSPDir()); 243 244 if(FileUtils.safeIsDirectory(getXMLDir())) 245 FileUtils.whack(getXMLDir()); 246 247 if(FileUtils.safeIsDirectory(getJWSDir())) 248 FileUtils.whack(getJWSDir()); 249 250 if(FileUtils.safeIsDirectory(oldStubsDir)) 252 oldStubsDir.renameTo(getStubsDir()); 253 254 if(FileUtils.safeIsDirectory(oldJSPDir)) 255 oldJSPDir.renameTo(getJSPDir()); 256 if(FileUtils.safeIsDirectory(oldXMLDir)) 257 oldXMLDir.renameTo(getXMLDir()); 258 259 if(FileUtils.safeIsDirectory(oldJWSDir)) 260 oldJWSDir.renameTo(getJWSDir()); 261 262 boolean success = false; 263 File appdir = getAppDir(); 264 265 if(FileUtils.safeIsDirectory(appdir) && FileUtils.safeIsDirectory(oldAppDir)) 266 { 267 FileUtils.whack(appdir); 268 success = oldAppDir.renameTo(appdir); 269 } 270 271 if(!success) 272 { 273 FileUtils.whack(oldAppDir); 274 logger.log( Level.SEVERE, "enterprise.deployment.backend.directoryRenameFailure", 275 new Object [] {oldAppDir.getAbsolutePath() , appdir.getAbsolutePath()}); 276 } 277 278 } 279 280 getManager().registerDescriptor(request.getName(), request.getDescriptor()); 281 282 } 283 284 286 private final void rollbackDirectory() { 288 292 request.setReRegisterOnFailure(false); 293 } 294 295 297 private final File setAppDirDirectory() throws IASDeploymentException 298 { 299 FileSource fileSource = request.getFileSource(); 300 301 if(!fileSource.exists()) 302 { 303 String msg = localStrings.getString("enterprise.deployment.backend.file_source_does_not_exist", fileSource ); 304 throw new IASDeploymentException( msg ); 305 } 306 307 assert fileSource.isDirectory(); 308 File appDirectory = fileSource.getFile(); 309 310 return appDirectory; 311 } 312 313 315 private final File setAppDirArchive() throws IASDeploymentException 316 { 317 assert originalAppDir != null; 318 File newAppDirectory = originalAppDir; 319 oldAppDir = new File(newAppDirectory.getAbsolutePath() + "_old"); 320 321 322 FileUtils.whack(oldAppDir); 324 325 appdirWasRenamed = FileUtils.renameFile(newAppDirectory, oldAppDir); 328 329 if(!appdirWasRenamed) 330 { 331 String msg = localStrings.getString("enterprise.deployment.backend.directory_rename_error", 332 newAppDirectory.getAbsolutePath(), oldAppDir.getAbsolutePath()); 333 throw new IASDeploymentException( msg ); 334 } 335 336 return newAppDirectory; 337 } 338 339 341 private final void setOldDirs() throws IASDeploymentException 342 { 343 File stubsDirectory = getStubsDir(); 344 File jspDirectory = getJSPDir(); 345 File xmlDirectory = getXMLDir(); 346 File jwsDirectory = getJWSDir(); 347 348 if(FileUtils.safeIsDirectory(stubsDirectory)) 349 { 350 oldStubsDir = new File(stubsDirectory.getPath() + "_old"); 351 352 if(oldStubsDir.exists()) 353 { 354 356 if(oldStubsDir.isDirectory()) 357 FileUtils.whack(oldStubsDir); 358 else 359 oldStubsDir.delete(); 360 } 361 362 if(!stubsDirectory.renameTo(oldStubsDir)) { 363 String msg = localStrings.getString( 364 "enterprise.deployment.backend.directory_rename_error", 365 stubsDirectory.getPath(), 366 oldStubsDir.getPath() ); 367 throw new IASDeploymentException( msg ); 368 } 369 } 370 371 if(FileUtils.safeIsDirectory(jspDirectory)) 374 { 375 oldJSPDir = new File(jspDirectory.getPath() + "_old"); 376 377 if(oldJSPDir.exists()) 378 { 379 381 if(FileUtils.safeIsDirectory(oldJSPDir)) 382 FileUtils.whack(oldJSPDir); 383 else 384 oldJSPDir.delete(); 385 } 386 387 if(!jspDirectory.renameTo(oldJSPDir)) { 388 String msg = localStrings.getString( 389 "enterprise.deployment.backend.directory_rename_error", 390 jspDirectory.getPath(), 391 oldJSPDir.getPath() ); 392 throw new IASDeploymentException( msg ); 393 } 394 } 395 if(FileUtils.safeIsDirectory(xmlDirectory)) 396 { 397 oldXMLDir = new File(xmlDirectory.getPath() + "_old"); 398 399 if(oldXMLDir.exists()) 400 { 401 403 if(FileUtils.safeIsDirectory(oldXMLDir)) 404 FileUtils.whack(oldXMLDir); 405 else 406 oldXMLDir.delete(); 407 } 408 409 if( ! FileUtils.renameFile(xmlDirectory, oldXMLDir)) { 410 String msg = localStrings.getString( 411 "enterprise.deployment.backend.directory_rename_error", 412 xmlDirectory.getPath(), 413 oldXMLDir.getPath() ); 414 throw new IASDeploymentException( msg ); 415 } 416 } 417 418 if (FileUtils.safeIsDirectory(jwsDirectory)) { 419 if (jwsDirectory.list().length > 0) { 420 DeploymentStatus jwsStatus = new DeploymentStatus( 422 request.getCurrentDeploymentStatus()); 423 jwsStatus.setStageStatus(DeploymentStatus.WARNING); 424 jwsStatus.setStageStatusMessage(localStrings.getString( 425 "enterprise.deployment.backend.jws_redeploy", 426 jwsDirectory.getPath())); 427 428 } 429 oldJWSDir = new File(jwsDirectory.getPath() + "_old"); 430 431 if(oldJWSDir.exists()) 432 { 433 435 if(FileUtils.safeIsDirectory(oldJWSDir)) { 436 FileUtils.whack(oldJWSDir); 437 } 438 else { 439 oldJWSDir.delete(); 440 } 441 } 442 443 if( ! FileUtils.renameFile(jwsDirectory, oldJWSDir)) { 444 String msg = localStrings.getString( 445 "enterprise.deployment.backend.directory_rename_error", 446 jwsDirectory.getPath(), 447 oldJWSDir.getPath() ); 448 throw new IASDeploymentException( msg ); 449 } 450 } 451 } 452 453 455 456 private String failureMessage = "\n*********************\n****Redeployment Failed -- rolled back redeployment"; 457 private String successMessage = "\n*********************\n****Redeployment Successful for "; 458 private File oldAppDir = null; 459 private File oldStubsDir = null; 460 private File oldJSPDir = null; 461 private File oldXMLDir = null; 462 private File oldJWSDir = null; 463 private File originalAppDir = null; 464 private boolean appdirWasRenamed = false; 466 private boolean appWasUnregistered = false; 467 private static StringManager localStrings = 468 StringManager.getManager( AppReDeployer.class ); 469 } 470 | Popular Tags |