1 23 24 package com.sun.enterprise.deployment.backend; 25 26 import java.util.List ; 27 import java.util.ArrayList ; 28 import java.util.Iterator ; 29 import java.util.Properties ; 30 import java.util.Map ; 31 import java.util.HashMap ; 32 import java.io.PrintWriter ; 33 import java.io.ByteArrayOutputStream ; 34 35 import com.sun.appserv.management.base.MapCapable; 36 37 38 50 public class DeploymentStatus implements java.io.Serializable , MapCapable { 51 52 static final long serialVersionUID = -6130876961172599515L; 57 58 61 public static final int FAILURE = 0; 62 public static final int WARNING = 1; 63 public static final int SUCCESS=2; 64 public static final int NOTINITIALIZED = 3; 65 66 67 70 public static final String CONTEXT_ROOT = "ContextRoot"; 71 public static final String KEY_SEPARATOR = "_"; 72 public static final String MODULE_ID = "moduleid"; 73 public static final String MODULE_TYPE = "ModuleType"; 74 public static final String SUBMODULE_COUNT = "NumberOfSubModules"; 75 public static final String WSDL_PUBLISH_URL = "ClientPublishURL"; 76 public static final String WSDL_LOCATION = "WsdlFileLocation"; 77 public static final String WSDL_DIRECTORY = "WsdlDirectory"; 78 public static final String WSDL_FILE_ENTRIES = "WsdlFileEntries"; 79 public static final String COUNT = "NumberOfEntries"; 80 81 86 private String stageDescription; 87 private int stageStatus = NOTINITIALIZED; 88 private String stageStatusMessage = ""; 89 private Throwable stageException; 90 91 private List subStages = new ArrayList (); 92 private DeploymentStatus parent = null; 93 94 98 private Map additionalStatus = new Properties (); 99 100 private Properties props=null; 102 103 104 107 public DeploymentStatus() { 108 } 109 110 115 public DeploymentStatus(DeploymentStatus parent) { 116 if (parent==null) { 117 throw new IllegalArgumentException ("parent deployment status cannot be null"); 118 } 119 parent.addSubStage(this); 120 } 121 122 126 public int getStatus() { 127 128 int currentStatus = stageStatus; 129 130 for (Iterator stageItr = subStages.iterator();stageItr.hasNext();) { 132 DeploymentStatus subStage = (DeploymentStatus) stageItr.next(); 133 int subStageStatus= subStage.getStatus(); 134 if (subStageStatus<currentStatus) { 137 currentStatus = subStageStatus; 138 } 139 } 140 return currentStatus; 141 } 142 143 147 public void addSubStage(DeploymentStatus subStage) { 148 subStages.add(subStage); 149 subStage.setParent(this); 150 } 151 152 156 public Iterator getSubStages() { 157 return subStages.iterator(); 158 } 159 160 164 public void setStageStatus(int status) { 165 stageStatus = status; 166 } 167 168 171 public int getStageStatus() { 172 return stageStatus; 173 } 174 175 179 public Throwable getStageException() { 180 return stageException; 181 } 182 183 186 public String getStageIdentifier() { 187 return stageDescription; 188 } 189 190 193 public String getStageDescription() { 194 return stageDescription; 195 } 196 197 198 201 public String getStageStatusMessage() { 202 return stageStatusMessage; 203 } 204 205 210 public void setStageException(Throwable throwable) { 211 stageException = new Throwable (throwable.getMessage()); 212 stageException.setStackTrace(throwable.getStackTrace()); 213 } 214 215 218 public void setStageDescription(String string) { 219 stageDescription = string; 220 } 221 222 226 public void setStageStatusMessage(String string) { 227 stageStatusMessage = string; 228 } 229 230 234 public DeploymentStatus getStageStatusForLevel(int level) { 235 if (stageStatus == level) { 236 return this; 237 } else { 238 for (Iterator itr = subStages.iterator();itr.hasNext();) { 239 DeploymentStatus subStage = (DeploymentStatus) itr.next(); 240 if (subStage.getStatus()==level) { 241 return subStage; 242 } 243 } 244 } 245 return null; 246 } 247 248 251 public DeploymentStatus getParent() { 252 return parent; 253 } 254 255 258 public void setParent(DeploymentStatus parent) { 259 this.parent = parent; 260 } 261 262 266 public DeploymentStatus getMainStatus() { 267 if (parent!=null) { 268 return parent.getMainStatus(); 269 } 270 return this; 271 } 272 273 276 public void addProperty(String propertyName, String propertyValue) { 277 additionalStatus.put(propertyName, propertyValue); 278 279 if (props==null) { 282 props = new Properties (); 283 } 284 props.put(propertyName, propertyValue); 285 } 286 287 290 public String getProperty(String propertyName) { 291 if (additionalStatus.get(propertyName) != null) { 292 return (String )additionalStatus.get(propertyName); 293 } else { 294 if (props==null) { 297 return null; 298 } 299 return props.getProperty(propertyName); 300 } 301 } 302 303 306 public Map getAdditionalStatus() { 307 return additionalStatus; 308 } 309 310 313 public void setAdditionalStatus(Map additionalStatus) { 314 this.additionalStatus = additionalStatus; 315 } 316 317 320 public String toString() { 321 return "Status " + stageStatus + " message " + stageStatusMessage 322 + " \nException " + stageException; 323 } 324 325 331 public static Iterator getAllStageStatusForLevel( 332 DeploymentStatus status, 333 int level) { 334 List stages = new ArrayList (); 335 if (status.getStageStatus() == level) { 336 stages.add(status); 337 } 338 for (Iterator itr = status.getSubStages();itr.hasNext();) { 340 DeploymentStatus subStage = (DeploymentStatus) itr.next(); 341 if (subStage.getStageStatus() == level) { 342 stages.add(subStage); 343 } 344 for (Iterator itr2 = subStage.getSubStages();itr2.hasNext();) { 345 DeploymentStatus subStage2 = (DeploymentStatus) itr2.next(); 346 if (subStage2.getStageStatus() == level) { 347 stages.add(subStage2); 348 } 349 350 for (Iterator itr3 = subStage2.getSubStages(); 351 itr3.hasNext();) { 352 DeploymentStatus subStage3 = 353 (DeploymentStatus) itr3.next(); 354 if (subStage3.getStageStatus() == level) { 355 stages.add(subStage3); 356 } 357 } 358 } 359 } 360 return stages.iterator(); 361 } 362 363 367 public Map asMap() { 368 HashMap m = new HashMap (); 369 m.put(MapCapable.MAP_CAPABLE_CLASS_NAME_KEY, com.sun.appserv.management.deploy.DeploymentStatus.DEPLOYMENT_STATUS_CLASS_NAME ); 370 m.put(com.sun.appserv.management.deploy.DeploymentStatus.STAGE_STATUS_KEY, new Integer (stageStatus)); 371 m.put(com.sun.appserv.management.deploy.DeploymentStatus.STAGE_STATUS_MESSAGE_KEY, stageStatusMessage); 372 m.put(com.sun.appserv.management.deploy.DeploymentStatus.STAGE_DESCRIPTION_KEY, stageDescription); 373 m.put(com.sun.appserv.management.deploy.DeploymentStatus.SUB_STAGES_KEY, subStagesToMapList()); 374 m.put(com.sun.appserv.management.deploy.DeploymentStatus.STAGE_THROWABLE_KEY, stageException); 375 m.put(com.sun.appserv.management.deploy.DeploymentStatus.ADDITIONAL_STATUS_KEY, additionalStatus); 376 return( m ); 377 378 } 379 380 386 List subStagesToMapList() { 387 final List l = new ArrayList (subStages.size()); 388 final Iterator it = subStages.iterator(); 389 while (it.hasNext()) { 390 final MapCapable mc = (MapCapable)it.next(); 391 l.add(mc.asMap()); 392 } 393 return l; 394 } 395 396 400 public String getMapClassName() { 401 return com.sun.appserv.management.deploy.DeploymentStatus.DEPLOYMENT_STATUS_CLASS_NAME; 402 } 403 404 405 409 public static void parseDeploymentStatus(DeploymentStatus status, 410 PrintWriter pw) { 411 if (status != null) { 412 413 if (status.getStatus() == DeploymentStatus.FAILURE) { 415 for (Iterator itr = getAllStageStatusForLevel(status, DeploymentStatus.FAILURE); itr.hasNext();) { 416 DeploymentStatus stage = (DeploymentStatus) itr.next(); 417 printFailure(pw, stage); 418 } 419 } 420 421 else if (status.getStatus() == DeploymentStatus.WARNING) { 423 for (Iterator itr = getAllStageStatusForLevel(status, DeploymentStatus.WARNING); itr.hasNext();) { 424 DeploymentStatus stage = (DeploymentStatus) itr.next(); 425 String msg = stage.getStageStatusMessage(); 426 if (msg != null) { 427 pw.println(msg); 428 } 429 } 430 } 431 pw.flush(); 432 } 433 } 434 435 441 private static void printFailure(PrintWriter pw, 442 DeploymentStatus status) { 443 String msg = status.getStageStatusMessage(); 444 Throwable t = status.getStageException(); 445 if (msg != null && msg.trim().length() > 0) { 446 pw.println(msg); 447 if (t != null && t.getMessage() != null && 450 !t.getMessage().equals(msg)) { 451 pw.println(t); 452 } 453 } else { 454 if (t != null) { 455 pw.println(t); 456 } 457 } 458 } 459 460 } 461 | Popular Tags |