FileDocCategorySizeDatePackage
DeployHelper.javaAPI DocGlassfish v2 API10932Fri May 04 22:23:28 BST 2007com.sun.enterprise.management.helper

DeployHelper

public final class DeployHelper extends com.sun.appserv.management.helper.Helper
Helper class for simplifying deployment.
since
AppServer 9.0

Fields Summary
private com.sun.appserv.management.helper.DeployNotificationListener
mListener
private final com.sun.appserv.management.deploy.DeploymentMgr
mDeploymentMgr
private boolean
mDidAssociate
Constructors Summary
public DeployHelper(com.sun.appserv.management.deploy.DeploymentMgr deploymentMgr)

		super( deploymentMgr.getDomainRoot() );
		
		mDeploymentMgr   = deploymentMgr;
		mListener        = null;
		mDidAssociate    = false;
	
Methods Summary
public java.util.SetcreateReferences(java.lang.String[] targets, java.util.Map refOptions)
Associate the specified targets with the deployed application by creating {@link DeployedItemRefConfig} configuration within the targets. Call only after deployment has finished, and call it only once.

param
targets names (eg getName()) of {@link StandaloneServerConfig} or {@link ClusterConfig}
param
refOptions options to be passed when creating {@link DeployedItemRefConfig} (may be null)

	    if ( targets == null || targets.length == 0 )
	    {
	        throw new IllegalArgumentException();
	    }

	    if ( mListener == null || ! mListener.isCompleted() )
	    {
	        throw new IllegalStateException();
	    }
	    
	    final DeploymentStatus  status  = mListener.getDeploymentStatus();
	    
	    if ( status == null || status.getStageStatus() == STATUS_CODE_FAILURE )
	    {
	        throw new IllegalStateException();
	    }
	    
	    if ( mDidAssociate )
	    {
	        throw new IllegalStateException();
	    }
	    
	    // OK, go ahead
		final Map<String,Serializable>    additionalStatus = status.getAdditionalStatus();
		final String moduleID	= (String)additionalStatus.get( MODULE_ID_KEY );
	
	    final Set<DeployedItemRefConfig>   refs = new HashSet<DeployedItemRefConfig>();
	    final Set<DeployedItemRefConfigCR>  proxies = getTargetProxies( getDomainRoot(), targets );
	    for( final DeployedItemRefConfigCR cr : proxies )
	    {   
	        final DeployedItemRefConfig ref =
	            cr.createDeployedItemRefConfig( moduleID, refOptions );
	        refs.add( ref );
	    }
	    
	    return refs;
	
public voiddeploy(java.io.File archive, java.util.Map deployOptions)
Deploy the archive. Subsequent progress and status should be obtained from the listener returned from {@link #getDeployNotificationListener}.

For most errors, an Exception is not thrown; the returned DeploymentStatus should be checked for errors using {@link DeploymentStatus#getStageStatus}, verifing that {@link DeploymentStatus#STATUS_CODE_SUCCESS} was received.

If no targets are specified, then the app is deployed, but not associated with any server or cluster.

param
archive the archive to deploy
param
deployOptions optional deployment options as defined by {@link DeploymentMgr}
see
DeploymentStatus
see
DeploymentProgress

	    if ( archive == null )
	    {
	        throw new IllegalArgumentException();
	    }

	    final Object uploadID   = Misc.uploadFile(
	        getDomainRoot().getUploadDownloadMgr(),
	        archive );
	    
		final Object	deployID	= mDeploymentMgr.initDeploy( );
	    mListener   = new DeployNotificationListener( mDeploymentMgr, deployID );
		
		try
		{
			final String	archiveName	= archive.getName();
			
			final Map<String,String>   actualOptions   = new HashMap<String,String>();
			if ( deployOptions != null )
			{
			    actualOptions.putAll( deployOptions );
			}
			if ( ! actualOptions.containsKey( DEPLOY_OPTION_NAME_KEY ) )
			{
			    final String    appName = getDefaultAppName( archiveName );
			    actualOptions.put( DEPLOY_OPTION_NAME_KEY, appName );
			}
			
			mDeploymentMgr.startDeploy( deployID, uploadID, null, actualOptions );
		}
		finally
		{
			// remove right away; not all failures notify the listener
		    mListener.cleanup();
		}
	
public com.sun.appserv.management.deploy.DeploymentStatusdeploy(java.io.File archive, java.util.Map deployOptions, java.lang.String[] targets, java.util.Map refOptions)
Deploy the archive and associate it with all specified targets. Calls {@link #deploy}, {@link #waitTillDone}, and {@link #createReferences}.

param
archive the archive to deploy
param
deployOptions optional deployment options as defined by {@link DeploymentMgr}
param
targets names (eg getName()) of {@link StandaloneServerConfig} or {@link ClusterConfig}
param
refOptions options for creating references, see {@link DeployedItemRefConfigCR}
return
final status

	    deploy( archive, deployOptions );
	    
	    final DeploymentStatus  status  = waitTillDone( 50 );
	    
	    if ( targets != null && targets.length != 0 )
	    {
	        createReferences( targets, refOptions );
	    }
	    
	    return status;
	
public com.sun.appserv.management.deploy.DeploymentStatusdeploy(java.io.File archive, java.lang.String[] targets)
Perform default deployment. Calls deploy( archive, null, targets, null );

param
archive
param
targets
return
final status

	    return deploy( archive, null, targets, null );
	
public static final java.lang.StringgetDefaultAppName(java.lang.String archiveName)

		String	result	= archiveName;
		
		final int	idx	= archiveName.lastIndexOf( "." );
		if ( idx > 1 )
		{
			result	= archiveName.substring( 0, idx );
		}
		
		return( result );
	
public com.sun.appserv.management.helper.DeployNotificationListenergetDeployNotificationListener()
To monitor progress or check on final status, use the listener.

see
DeployNotificationListener

	    return mListener;
	
public static java.util.SetgetTargetProxies(com.sun.appserv.management.DomainRoot domainRoot, java.lang.String[] names)
Get a Set of all {@link StandaloneServerConfig} and {@link ClusterConfig} corresponding to the target names.

param
domainRoot
param
names names (eg getName()) of {@link StandaloneServerConfig} or {@link ClusterConfig}

	    final DomainConfig  domainConfig = domainRoot.getDomainConfig();
	    
	    final Set<DeployedItemRefConfigCR>  result  = new HashSet<DeployedItemRefConfigCR>();
	    
	    final Map<String,StandaloneServerConfig> serverConfigs = 
	        domainConfig.getStandaloneServerConfigMap();
	        
	    final Map<String,ClusterConfig> clusterConfigs =
	        domainConfig.getClusterConfigMap();
	        
	    for( final String name : names )
	    {
	        if ( serverConfigs.containsKey( name ) )
	        {
	            result.add( serverConfigs.get( name ) );
	        }
	        else if ( clusterConfigs.containsKey( name ) )
	        {
	            result.add( clusterConfigs.get( name ) );
	        }
	    }
	    
	    return result;
	
public com.sun.appserv.management.deploy.DeploymentStatuswaitTillDone(long pollMillis)
Wait for deployment to finish, then return status.

return
final status

	    // sanity check
	    if ( pollMillis > 5 * 1000 )
	    {
	        throw new IllegalArgumentException();
	    }
	    
	    // a more sophisticated solution would be to have
	    // the DeploymentNotificationListener wake us up...
	    while ( ! mListener.isCompleted() )
	    {
	        Util.sleep( pollMillis );
	    }
	    
	    final DeploymentStatus  status  = mListener.getDeploymentStatus();
	    
	    return status;