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.
    Note: if isCopyContent is true, a zipped file is expected. Copying a directory is currently not supported.
  • start - starts the application on the server
  • stop - stops the application on the server
  • remove - removes the deployment

 

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.