Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * ========================================================================
   *
   * Codehaus CARGO, copyright 2004-2011 Vincent Massol.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
  *   http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  * ========================================================================
  */
 package org.codehaus.cargo.tools.jboss;
 
 import java.io.File;
 
 
JBoss deployer implementation.

Version:
$Id: JBossDeployer.java 3795 2014-01-08 17:39:20Z alitokmen $
 
 public class JBossDeployer implements IJBossProfileManagerDeployer
 {

    
Container configuration.
 
     private Configuration configuration;

    

Parameters:
configuration Configuration of the container.
 
     public JBossDeployer(Configuration configuration)
     {
         this. = configuration;
     }

    
 
     public void deploy(File deploymentFileString deploymentNamethrows Exception
     {
         DeploymentManager deploymentManager = getDeploymentManager();
 
         deploymentManager.loadProfile(getProfile());
 
         DeploymentProgress distribute = deploymentManager.distribute(deploymentName,
             deploymentFile.toURI().toURL(), true);
         distribute.run();
         checkFailed(distribute);
 
         String[] repositoryNames = distribute.getDeploymentID().getRepositoryNames();
         DeploymentProgress start = deploymentManager.start(repositoryNames);
         start.run();
         checkFailed(start);
     }

    
 
     public void undeploy(String deploymentNamethrows Exception
     {
         DeploymentManager deploymentManager = getDeploymentManager();
 
         String[] deploymentNameArray = new String[1];
         deploymentNameArray[0] = deploymentName;
         deploymentManager.loadProfile(getProfile());
 
         String[] repositoryNames = deploymentManager.getRepositoryNames(deploymentNameArray);
         DeploymentProgress stop = deploymentManager.stop(repositoryNames);
         stop.run();
        checkFailed(stop);
        DeploymentProgress remove = deploymentManager.remove(repositoryNames);
        remove.run();
        checkFailed(remove);
    }

    
    private ProfileKey getProfile()
    {
        if (server == null || server.trim().length() == 0)
        {
            server = .;
        }
        boolean isClustered = Boolean.valueOf(this..getPropertyValue(
            .)).booleanValue();
        String name = isClustered ? "farm" : profile;
        if (name == null || name.trim().length() == 0)
        {
            name = .;
        }
        return new ProfileKey(.servername);
    }

    

Parameters:
progress DP to check for failure.
Throws:
java.lang.Exception If progress has failed.
    private void checkFailed(DeploymentProgress progressthrows Exception
    {
        final int timeout = 30;
        DeploymentStatus status = progress.getDeploymentStatus();
        for (int i = 0; i < 30; i++)
        {
            Thread.sleep(1000);
            if (status.isCompleted() || status.isFailed())
            {
                break;
            }
            if (i == timeout - 1)
            {
                throw new Exception("Operation timed out");
            }
        }
        if (status.isFailed())
        {
            Exception cause = status.getFailure();
            throw new Exception("Remote action failed: " + status.getMessage()
                + " (" + cause.getMessage() + ")"cause);
        }
    }

    

Returns:
The JBoss deployment manager.
Throws:
java.lang.Exception If anything fails.
    {
        StringBuilder providerURL = new StringBuilder();
        providerURL.append("jnp://");
        providerURL.append(':');
        Properties properties = new Properties();
        properties.setProperty(
            ."org.jnp.interfaces.NamingContextFactory");
        properties.setProperty(.providerURL.toString());
        properties.setProperty(."org.jboss.naming:org.jnp.interfaces");
        new LoginContext("jboss-jaas"null,
            new UsernamePasswordCallbackHandler(this.),
            new JaasConfiguration(new AppConfigurationEntry(
                "org.jboss.security.ClientLoginModule",
                .))).login();
        Context ctx = new InitialContext(properties);
        ProfileService ps = (ProfileServicectx.lookup("ProfileService");
        return ps.getDeploymentManager();
        // TODO: think about logout ?
    }
New to GrepCode? Check out our FAQ X