ProfileService DeploymentManager in 5.x

    Overview

    The DeploymentManager is a client-side plugin for distributing and controlling deployments in a profile.

     

    Compared to the DeploymentManager in 5.0.x there are some differences:

    • The DeploymentPhase has been removed.

    • The usage is now symmetric independent of the boolean isCopyContent flag.

    • loadProfile(ProfileKey key) is not required to be able use the DeploymentManager.

      Not loading a profile will copy the deployment to the default location specified in deploy/profileservice-jboss-beans.xml

    In general loadProfile specifies the target profile. A set of profiles which support deployment actions can be obtained using deployMgr.getProfiles(). Not loading a profile or deployMgr.loadProfile(new ProfileKey(ProfileKey.DEFAULT)); is recommended.

    Example Usage
    import java.net.URL;
    
    import javax.naming.InitialContext;
    
    import org.jboss.deployers.spi.management.deploy.DeploymentManager;
    import org.jboss.deployers.spi.management.deploy.DeploymentProgress;
    import org.jboss.deployers.spi.management.deploy.DeploymentStatus;
    import org.jboss.profileservice.spi.ProfileService;
    
    public class DeploymentTest
    {
        
        public void deployAndUndeploy(String deploymentName, URL deploymentURL) throws Exception
        {
            DeploymentManager deployMgr = getDeploymentManager();
            if(deployMgr == null)
                throw new IllegalStateException("Null deployment manager.");
    
            String[] repositoryNames = null;
            // Distribute a zipped file
            DeploymentProgress distribute = deployMgr.distribute(deploymentName, deploymentURL, true);
            // Run
            distribute.run();
            // Check if the deploy failed
            checkFailed(distribute);
            
            // Get the deployed names
            repositoryNames = distribute.getDeploymentID().getRepositoryNames();
            
            // Start the deployment
            DeploymentProgress start = deployMgr.start(repositoryNames);
            // Run
            start.run();
            //
            checkFailed(start);
            
            // Stop the deployment
            DeploymentProgress stop = deployMgr.stop(repositoryNames);
            // Run
            stop.run();
            // 
            checkFailed(stop);            
            
            // Remove the deployment
            DeploymentProgress remove = deployMgr.remove(repositoryNames);
            // Run
            remove.run();
            // 
            checkFailed(remove);
        }
        
        void checkFailed(DeploymentProgress progress) throws Exception
        {
            DeploymentStatus status = progress.getDeploymentStatus();
            if(status.isFailed())
                throw new RuntimeException("Failed to deploy", status.getFailure());
        }
        
        DeploymentManager getDeploymentManager() throws Exception
        {
            ProfileService ps = getProfileService();
            return ps.getDeploymentManager();
        }
        
        ProfileService getProfileService() throws Exception
        {
            InitialContext ctx = getInitialContext();
            return (ProfileService) ctx.lookup("ProfileService");
        }
        
        InitialContext getInitialContext() throws Exception
        {
            return new InitialContext();
        }
    }
    

     

    The main operations basically are:

    • distribute - distribute a deployment.
      The boolean flag isCopyContent indicates if the content should be copied in the applications directory.
      copyContent=false will just deploy the absolute url without touching the deployment.
      Additionally the distribute action will 'lock' the deployment, so it won't get deployed by the hot-deployment scanner.
      Note: if isCopyContent is true, a zipped file is expected. Copying a directory is currently not supported.

    • start
      starts the application on the server and enables hot-deployment checking for this deployment.

    • redeploy
      stops and starts the application without modifying any of the deployment contents.

    • stop
      only stops the application on the server, without deleting the file.

    • remove
      removes the deployment from the file system if it was distributed with copyContent=true
      In case copyContent was false, it won't delete the deployment.

     

    For starting a deployment distribute() and start() need to be called, as distribute just adds content and start actually deploys the application. To fully remove a deployment stop() and remove() have to be called, as e.g. just calling remove() would only remove the actual deployment - but the deployment could still exist in the temp.

     

    Note that DeploymentProgress.run() does not throw server side Exceptions. Errors during the deployment progress are passed to the DeploymentStatus and should be checked after each operation.