FileDocCategorySizeDatePackage
DeploymentStatus.javaAPI DocGlassfish v2 API16758Fri May 04 22:34:32 BST 2007com.sun.enterprise.deployment.backend

DeploymentStatus

public class DeploymentStatus extends Object implements com.sun.appserv.management.base.MapCapable, Serializable
This class encapsulates all status related to backend deployment Backend deployement can consist of several stages. Those stages are organized in a parent/children relationship where the children are the sub stages of a parent stage. For instance, deployment stage consist of j2eec stage and application loading stage. For a stage to be sucessful, its status and all its children's status must be warning or success
author
Jerome Dochez

Fields Summary
static final long
serialVersionUID
public static final int
FAILURE
Possible status for a stage or overall deployment status
public static final int
WARNING
public static final int
SUCCESS
public static final int
NOTINITIALIZED
public static final String
CONTEXT_ROOT
public static final String
KEY_SEPARATOR
public static final String
MODULE_ID
public static final String
MODULE_TYPE
public static final String
SUBMODULE_COUNT
public static final String
WSDL_PUBLISH_URL
public static final String
WSDL_LOCATION
public static final String
WSDL_DIRECTORY
public static final String
WSDL_FILE_ENTRIES
public static final String
COUNT
private String
stageDescription
instance information : - information about this stage - information about sub stages
private int
stageStatus
private String
stageStatusMessage
private Throwable
stageException
private List
subStages
private DeploymentStatus
parent
private Map
additionalStatus
backend deployment can transfer some information back to the client process through these properties.
private Properties
props
Constructors Summary
public DeploymentStatus()
Creates a new uninitialized DeploymentStatus instance

        
	
	       	 
	  
	
public DeploymentStatus(DeploymentStatus parent)
Creates a new uninitialized DeploymentStatus instance as a sub stage deployment status of the passed DeploymentStatus

param
parent DeploymentStatus

		if (parent==null) {
			throw new IllegalArgumentException("parent deployment status cannot be null");
		}
		parent.addSubStage(this);
	
Methods Summary
public voidaddProperty(java.lang.String propertyName, java.lang.String propertyValue)
Add a new property to this status object

            additionalStatus.put(propertyName, propertyValue);

            // the name-value pair is also stored in props 
            // for backward compatibility
            if (props==null) {
                props = new Properties();
            }
            props.put(propertyName, propertyValue);
        
public voidaddSubStage(com.sun.enterprise.deployment.backend.DeploymentStatus subStage)
Add a sub stage to this deployment status

param
the sub stage deployment status

		subStages.add(subStage);
                subStage.setParent(this);
	
public java.util.MapasMap()
Implement the MapCapable interface so DeploymentStatus can be converted back and forth with CompositeData

            HashMap m = new HashMap();
            m.put(MapCapable.MAP_CAPABLE_CLASS_NAME_KEY, com.sun.appserv.management.deploy.DeploymentStatus.DEPLOYMENT_STATUS_CLASS_NAME );
            m.put(com.sun.appserv.management.deploy.DeploymentStatus.STAGE_STATUS_KEY, new Integer(stageStatus));
            m.put(com.sun.appserv.management.deploy.DeploymentStatus.STAGE_STATUS_MESSAGE_KEY, stageStatusMessage);
            m.put(com.sun.appserv.management.deploy.DeploymentStatus.STAGE_DESCRIPTION_KEY, stageDescription);
            m.put(com.sun.appserv.management.deploy.DeploymentStatus.SUB_STAGES_KEY, subStagesToMapList());
            m.put(com.sun.appserv.management.deploy.DeploymentStatus.STAGE_THROWABLE_KEY, stageException);
            m.put(com.sun.appserv.management.deploy.DeploymentStatus.ADDITIONAL_STATUS_KEY, additionalStatus);
            return( m );

        
public java.util.MapgetAdditionalStatus()

return
the additional status map

            return additionalStatus;
        
public static java.util.IteratorgetAllStageStatusForLevel(com.sun.enterprise.deployment.backend.DeploymentStatus status, int level)
Get all stages with this deployment status level

param
parent status it needs to iterate through
param
status level it's looking for
return
an iterator for the stages with the level

            List stages = new ArrayList();
            if (status.getStageStatus() == level) {
                stages.add(status);
            }
            // need to iterate through the rest of status hierarchy
            for (Iterator itr = status.getSubStages();itr.hasNext();) {
                DeploymentStatus subStage = (DeploymentStatus) itr.next();
                if (subStage.getStageStatus() == level) {
                    stages.add(subStage);
                }
                for (Iterator itr2 = subStage.getSubStages();itr2.hasNext();) {
                    DeploymentStatus subStage2 = (DeploymentStatus) itr2.next();
                    if (subStage2.getStageStatus() == level) {
                        stages.add(subStage2);
                    }

                    for (Iterator itr3 = subStage2.getSubStages();
                        itr3.hasNext();) {
                        DeploymentStatus subStage3 = 
                            (DeploymentStatus) itr3.next();
                        if (subStage3.getStageStatus() == level) {
                            stages.add(subStage3);
                        }
                    }
                }
            }
            return stages.iterator();
        
public com.sun.enterprise.deployment.backend.DeploymentStatusgetMainStatus()

return
the main status for this deployment operation, which is the parent of all status in this hierarchy

            if (parent!=null) {
                return parent.getMainStatus();
            }
            return this;
        
public java.lang.StringgetMapClassName()
Return the interface that this Map represents (the Java classname).

	    return com.sun.appserv.management.deploy.DeploymentStatus.DEPLOYMENT_STATUS_CLASS_NAME;
	
public com.sun.enterprise.deployment.backend.DeploymentStatusgetParent()

return
the parent status for this status if any

            return parent;
        
public java.lang.StringgetProperty(java.lang.String propertyName)

return
the value of for property name

            if (additionalStatus.get(propertyName) != null) {
                return (String)additionalStatus.get(propertyName);
            } else {
            // we also try to retrieve from props 
            // for backward compatibility
                if (props==null) {
                    return null;
                }
                return props.getProperty(propertyName);
            }
        
public java.lang.StringgetStageDescription()

return
a meaningful i18ned stage description

                return stageDescription;
        
public java.lang.ThrowablegetStageException()

return
the exception if an exception was thrown during the execution of the stage

		return stageException;
	
public java.lang.StringgetStageIdentifier()

return
a meaningful i18ned stage description

		return stageDescription;
	
public intgetStageStatus()

return
the status for this stage (ignoring sub stages status)

		return stageStatus;
	
public com.sun.enterprise.deployment.backend.DeploymentStatusgetStageStatusForLevel(int level)

return
the current deployment status or one of the sub stage deployment status with a status equal to the provided level.

            if (stageStatus == level) {
                return this;
            } else {
                for (Iterator itr = subStages.iterator();itr.hasNext();) {
                    DeploymentStatus subStage = (DeploymentStatus) itr.next();
                    if (subStage.getStatus()==level) {
                        return subStage;
                    }
                }
            }
            return null;
        
public java.lang.StringgetStageStatusMessage()

return
a meaningful i18ned reason for failure or warning

		return stageStatusMessage;
	
public intgetStatus()

return
the combined status for the stage and its children, it will return the lowest status as defined in the constants

		
		int currentStatus = stageStatus;
		
		// iterate over all sub stages to get their status
		for (Iterator stageItr = subStages.iterator();stageItr.hasNext();) {
			DeploymentStatus subStage = (DeploymentStatus) stageItr.next();
			int subStageStatus= subStage.getStatus();
			// if the sub stage status is a lower number than our current, something
			// went horribly wrong in the substage, update ours
			if (subStageStatus<currentStatus) {
				currentStatus = subStageStatus;
			}
		}
		return currentStatus;
	
public java.util.IteratorgetSubStages()
Get the list of sub stages for this deployment status

return
an Iterator for the sub stages

		return subStages.iterator();
	
public static voidparseDeploymentStatus(com.sun.enterprise.deployment.backend.DeploymentStatus status, java.io.PrintWriter pw)
Traverse through the DeploymenStatus hierarchy and write failure/warning msgs to the print writer

            if (status != null) {
                
                // if it's falure case, print all exceptions
                if (status.getStatus() == DeploymentStatus.FAILURE) {
                    for (Iterator itr = getAllStageStatusForLevel(status, DeploymentStatus.FAILURE); itr.hasNext();) {
                        DeploymentStatus stage = (DeploymentStatus) itr.next();
                        printFailure(pw, stage);
                    }
                } 

                // if it's warning case, print all warnings
                else if (status.getStatus() == DeploymentStatus.WARNING) {
                    for (Iterator itr = getAllStageStatusForLevel(status, DeploymentStatus.WARNING); itr.hasNext();) {
                        DeploymentStatus stage = (DeploymentStatus) itr.next();
                        String msg = stage.getStageStatusMessage();
                        if (msg != null) {
                            pw.println(msg);
                        }
                    }
                }
                pw.flush();
            }
        
private static voidprintFailure(java.io.PrintWriter pw, com.sun.enterprise.deployment.backend.DeploymentStatus status)
Prints the status string and/or status exception

param
pw PrintWriter to which info is printed.
param
status DeploymentStatus
param
t Throwable to print

            String msg = status.getStageStatusMessage();
            Throwable t = status.getStageException();
            if (msg != null && msg.trim().length() > 0) {
                pw.println(msg);
                // only print the exception if it's not the same as the 
                // the status message 
                if (t != null && t.getMessage() != null && 
                    !t.getMessage().equals(msg)) {
                    pw.println(t.getLocalizedMessage());
                }
            } else {
                if (t != null) {
                    pw.println(t.getLocalizedMessage());
                }
            }
        
public voidsetAdditionalStatus(java.util.Map additionalStatus)
Set the additional status for this status

            this.additionalStatus = additionalStatus;
        
public voidsetParent(com.sun.enterprise.deployment.backend.DeploymentStatus parent)
Setthe parent status for this status

            this.parent = parent;
        
public voidsetStageDescription(java.lang.String string)

param
string for a meaningful i18ned stage description

		stageDescription = string;
	
public voidsetStageException(java.lang.Throwable throwable)
When the stage throws an exception, it should store it here in the assiciated deployment status

param
throwable

            stageException = new Throwable(throwable.getMessage());
            stageException.setStackTrace(throwable.getStackTrace());
	
public voidsetStageStatus(int status)
Set the status for this stage

param
the status as defined in the constants

		stageStatus = status;
	
public voidsetStageStatusMessage(java.lang.String string)

param
string for a meaningful i18ned reason for stage warning or failure

		stageStatusMessage = string;
	
java.util.ListsubStagesToMapList()
DeploymentStatus class may not be available on the client side. Converts the list of DeploymentStatus objects to list of Maps. Iterates through the substages list and calls asMap().

            final List l = new ArrayList(subStages.size());
            final Iterator it = subStages.iterator();
            while (it.hasNext()) {
                final MapCapable mc = (MapCapable)it.next();
                l.add(mc.asMap());
            }
            return l;
        
public java.lang.StringtoString()

return
a meaningful string about mysefl

            return "Status " + stageStatus + " message " + stageStatusMessage 
                + " \nException " + stageException;