FileDocCategorySizeDatePackage
DeployCommand.javaAPI DocGlassfish v2 API15966Fri May 04 22:25:08 BST 2007com.sun.enterprise.cli.commands

DeployCommand

public class DeployCommand extends S1ASCommand
This is the Deploy command
version
$Revision: 1.11 $

Fields Summary
private static final String
TARGET_OPTION
private static final String
CONTEXT_ROOT_OPTION
private static final String
FORCE_OPTION
private static final String
PRECOMPILE_JSP_OPTION
private static final String
VERIFY_OPTION
private static final String
UPLOAD_OPTION
private static final String
ENABLED_OPTION
private static final String
COMPONENT_NAME
private static final String
RETRIEVE_DIR
private static final String
VIRTUALSERVERS_OPTION
private static final String
DB_VENDOR_NAME_OPTION
private static final String
CREATE_TABLES_OPTION
private static final String
DROP_AND_CREATE_TABLES_OPTION
private static final String
UNIQUE_TABLENAMES_OPTION
private static final String
DEPLOYMENTPLAN_OPTION
private static final String
AVAILABILITY_ENABLED_OPTION
private static final String
GENERATE_RMI_STUBS_OPTION
private static final String
LIBRARIES_OPTION
private String
filePath
private String
componentName
com.sun.enterprise.deployment.client.DeploymentFacility
df
Constructors Summary
Methods Summary
private com.sun.enterprise.deployment.client.JESProgressObjectcallDeploy()

        df = DeploymentFacilityFactory.getDeploymentFacility();       
        ServerConnectionIdentifier conn = createServerConnectionIdentifier(
            getHost(), getPort(), getUser(), getPassword());
        df.connect(conn);

        //prepare data
        final String targetName = getOption(TARGET_OPTION);                
        
        final String deploymentPlan = getOption(DEPLOYMENTPLAN_OPTION);
        JESProgressObject progressObject = null;
        try {
            AbstractArchive arch = (new ArchiveFactory()).openArchive(filespecToJarURI(filePath));
            AbstractArchive plan = null;
            if (deploymentPlan != null) {
                plan = (new ArchiveFactory()).openArchive(filespecToJarURI(deploymentPlan));
            }
            //value of the map is String only
            Map deployOptions = createDeploymentProperties();

            if (df.isConnected()) 
            {
                Target[] targets = df.createTargets(new String[]{targetName});
                if (targets == null)
                {
                    //CLILogger.getInstance().printError(getLocalizedString("InvalidTarget"));
                    throw new CommandException(getLocalizedString("InvalidTarget", new Object[] {targetName}));
                }

                progressObject = df.deploy(targets, arch, plan, deployOptions);
            } else 
            {
                CLILogger.getInstance().printError(
                                   getLocalizedString("CouldNotConnectToDAS"));
            }
        }
        catch (Exception e)
        {
            //e.printStackTrace();
            if (e.getLocalizedMessage() != null)
                CLILogger.getInstance().printDetailMessage(
                    e.getLocalizedMessage());

            throw new CommandException(getLocalizedString(
                "CommandUnSuccessful", new Object[] {name} ), e);
        }
        return progressObject;
    
private voidcheckDeployStatus(com.sun.enterprise.deployment.backend.DeploymentStatus status, java.lang.String statusString)
Check the deployment status returned from the backend deployment. This method will iterate through the stages of the DeploymentStatus. If the first stage fails then it's a j2eec phase failure. CommandException will be thrown if j2eec phase failed. The next stages are the associate, start phases. If the j2eec phase passed but start phase failed then the deployment was successfull but not loaded. The backend message will be displayed.

param
status - DeploymentStatus returned from the backend deployment.
throws
CommandException if j2eec phase failed.

        if (status != null && status.getStatus() == DeploymentStatus.FAILURE) {
            throw new CommandException(getLocalizedString(
                "CommandUnSuccessfulWithMsg", new Object[] {name,
                statusString} ));
        }            
    
private java.util.MapcreateDeploymentProperties()
creates the DeployProperties which is used as a parameter to the deploy operation.

return
Properties

        final String virtualServers = getOption(VIRTUALSERVERS_OPTION);
        final String contextRoot = getContextRoot();
        final String dbVendorName = getOption(DB_VENDOR_NAME_OPTION);
        final String createTable = getOption(CREATE_TABLES_OPTION);
        final String dropCreateTable = getOption(DROP_AND_CREATE_TABLES_OPTION);
        final String uniqueTableNames = getOption(UNIQUE_TABLENAMES_OPTION);
        final String target = getOption(TARGET_OPTION);  
        final String libraries = getOption(LIBRARIES_OPTION);
        final String upload = getOption(UPLOAD_OPTION);
        
        Properties props = new Properties();

        if (target != null) 
            props.put(DeploymentProperties.TARGET, target);
        
        if(filePath != null)
            props.put(DeploymentProperties.ARCHIVE_NAME, filePath);


        if(contextRoot != null)
            props.put(DeploymentProperties.CONTEXT_ROOT, contextRoot);

        if(virtualServers != null)
            props.put(DeploymentProperties.VIRTUAL_SERVERS, 
                              virtualServers);

        if(dbVendorName != null)
            props.put(Constants.CMP_DB_VENDOR_NAME, dbVendorName);

        if(createTable != null)
            props.put(Constants.CMP_CREATE_TABLES, createTable);
        
        if(dropCreateTable != null)
            props.put(Constants.CMP_DROP_AND_CREATE_TABLES, dropCreateTable);

        if(uniqueTableNames != null)
            props.put(Constants.CMP_UNIQUE_TABLE_NAMES, uniqueTableNames);

        if(libraries != null)
            props.put(DeploymentProperties.DEPLOY_OPTION_LIBRARIES_KEY, libraries);

        if(upload != null)
            props.put(DeploymentProperties.UPLOAD, upload);


            //the following properties is either a required option/operand
            //or it contains a default value in the CLIDescriptors.xml
            //so do not neet to check for "null"
        props.put(DeploymentProperties.NAME, componentName);

        props.put(DeploymentProperties.VERIFY, 
                          getOption(VERIFY_OPTION));

        props.put(DeploymentProperties.PRECOMPILE_JSP, 
                          getOption(PRECOMPILE_JSP_OPTION));

        props.put(DeploymentProperties.ENABLE, 
                          getOption(ENABLED_OPTION));
		
        props.put(DeploymentProperties.FORCE, 
                          getOption(FORCE_OPTION));
        
        props.put(DeploymentProperties.AVAILABILITY_ENABLED, 
                          getOption(AVAILABILITY_ENABLED_OPTION));
        
        props.put(DeploymentProperties.GENERATE_RMI_STUBS, 
                          getOption(GENERATE_RMI_STUBS_OPTION));
        
        final String retrievePath = getOption(RETRIEVE_DIR);
        if (retrievePath != null){
            props.put(DeploymentProperties.CLIENTJARREQUESTED,  "true");
        };

        return props;

    
private java.net.URIfilespecToJarURI(java.lang.String fileSpec)
Convert a file spec into a jar URI.

param
filePath to be converted into a URI
return
URI with scheme=jar for the file

        File archiveFile = new File(fileSpec);
        String prefix = (archiveFile.isDirectory()) ? "file" : "jar";
        URI archiveFileURI = archiveFile.toURI();
        URI archiveJarURI = new URI(prefix, "" /* authority */, archiveFileURI.getSchemeSpecificPart(), null, null);
        return archiveJarURI;
    
private java.lang.StringgetComponentName()
get the component name. if component name is null then get it from the file path in the operand

throws
CommandValidationException if could not get component name

        String name = getOption(COMPONENT_NAME);
        if (name == null)
        {
            name = getNameFromFilePath();
        }
            //if name is still null or empty then throw an exception
        if ((name == null) || (name.equals("")))
            throw new CommandValidationException(getLocalizedString("ComponentNameNull"));
        return name;
    
private java.lang.StringgetContextRoot()
get the context root from command option. If context root is null then it will get from the filepath in the operand.

param
returns context root

        String contextRoot = getOption(CONTEXT_ROOT_OPTION);
        return contextRoot;
    
private java.lang.StringgetNameFromFilePath()
get the file name from the filepath

return
file name

        final File file = new File(filePath);
        final String fileName = file.getName();
        
        if (file.isFile()) {
            int toIndex = fileName.lastIndexOf('.");
            if (toIndex > 1)
            {
                return fileName.substring(0, toIndex);
            }
        }
        return fileName;
    
public voidrunCommand()
An abstract method that Executes the command

throws
CommandException


                    
       
          
       
        System.setProperty(DefaultConfiguration.REDIRECTION, "false");
        validateOptions();
        JESProgressObject progressObject = callDeploy();
        DeploymentStatus status = df.waitFor(progressObject);
        String statusString = status.getStageStatusMessage();

        if (statusString.indexOf("302")>-1) {
            setOption(SECURE, "true");
            progressObject = this.callDeploy();
            status = df.waitFor(progressObject);
            statusString = status.getStageStatusMessage();
        }

        if (status != null && status.getStatus() == DeploymentStatus.FAILURE) {
            checkDeployStatus(status, statusString);
        }

        final String retrievePath = getOption(RETRIEVE_DIR);
        if (retrievePath != null){
            try {
                CLILogger.getInstance().printDebugMessage("componentName = " + componentName + 
                                                  " retrievePath = " + retrievePath);
                final String fileName = df.downloadFile(new File(retrievePath), componentName, null);
                CLILogger.getInstance().printDebugMessage("downloaded stubs to  : " + fileName );
	    }
	    catch(Exception e){
	        throw new CommandException((getLocalizedString(
                    "InvalidValueInOption", new Object[] {RETRIEVE_DIR,
                    retrievePath})) + "\n"+ e.getLocalizedMessage());
	    }
	}

        if (status != null && status.getStatus() == DeploymentStatus.WARNING) {
            CLILogger.getInstance().printDetailMessage(getLocalizedString(
                "CommandSuccessfulWithMsg",
                new Object[] {name, statusString}));
        } else {
            CLILogger.getInstance().printDetailMessage(getLocalizedString(
                                                       "CommandSuccessful",
                                                       new Object[] {name} ) );
        }
    
public booleanvalidateOptions()
An abstract method that validates the options on the specification in the xml properties file This method verifies for the correctness of number of operands and if all the required options are supplied by the client.

return
boolean returns true if success else returns false

        super.validateOptions();
        if (getOption(CREATE_TABLES_OPTION) !=null &&
            getOption(DROP_AND_CREATE_TABLES_OPTION) != null)
            throw new CommandValidationException(getLocalizedString(
                                                     "MutuallyExclusiveOption",
                                                     new Object[] {CREATE_TABLES_OPTION,
                                                     DROP_AND_CREATE_TABLES_OPTION
                                                     }));

        filePath = (String) getOperands().get(0);
        componentName = getComponentName();
        return true;