org.mule.tools.muleesb.ClusterDeployer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of muleesb-maven-plugin Show documentation
Show all versions of muleesb-maven-plugin Show documentation
Maven plugin that helps control Mule ESB servers, including CE, EE Standalone and HA deployments.
Main use is for running integration tests but can be used also for deploying an application to any environment after all tests were ran.
Some of the features are:
Download Mule Standalone from a Maven Repository and install it locally.
Start Mule Standalone server.
Deploy a Mule application to a server.
Undeploy a Mule appliction.
Stop a Mule Standalone server.
Restart a Mule Standalone server.
Assemble a Mule cluster and deploy applications.
The newest version!
/*
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
package org.mule.tools.muleesb;
import org.mule.tck.probe.PollingProber;
import org.mule.tck.probe.Prober;
import org.mule.test.infrastructure.process.AppDeploymentProbe;
import org.mule.test.infrastructure.process.MuleControllerException;
import org.mule.test.infrastructure.process.MuleProcessController;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;
import java.util.Scanner;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
public class ClusterDeployer
{
private List mules;
private File[] paths;
private Log log;
private List applications;
private Prober prober;
private long timeout;
private long pollingDelay;
private String[] arguments;
private ClusterConfigurator configurator;
public ClusterDeployer(File[] paths,
List mules,
Log log,
List oneAppList,
long timeout,
String[] arguments,
long pollingDelay,
ClusterConfigurator configurator)
{
this.mules = mules;
this.log = log;
this.applications = oneAppList;
this.timeout = timeout;
this.pollingDelay = pollingDelay;
this.arguments = arguments;
this.prober = new PollingProber(timeout, pollingDelay);
this.paths = paths;
this.configurator = configurator;
log.debug(toString());
}
public String toString()
{
return String.format("Deployer with [Controllers=%s, log=%s, applications=%s, timeout=%d, pollingDelay=%d ]",
mules, log, applications, timeout, pollingDelay
);
}
public void execute() throws MojoFailureException, MojoExecutionException
{
try
{
configurator.configureCluster(paths,mules);
startMulesIfStopped();
deployApplications();
waitForDeployments();
}
catch (MuleControllerException e)
{
throw new MojoFailureException("Error deploying applications: [" + applications + "]");
}
catch (RuntimeException e)
{
throw new MojoExecutionException("Unexpected error deploying applications: [" + applications
+ "]", e);
}
}
private void waitForDeployments() throws MojoFailureException
{
for (MuleProcessController m : mules)
{
for (File application : applications)
{
if (!application.exists())
{
throw new MojoFailureException("Application does not exists: " + application);
}
log.debug("Checking for application [" + application + "] to be deployed.");
String app = getApplicationName(application);
try
{
prober.check(AppDeploymentProbe.isDeployed(m, app));
}
catch (AssertionError e)
{
log.error("Couldn't deploy application [" + application + "] after [" + timeout
+ "] miliseconds. Check Mule ESB log");
throw new MojoFailureException("Application deployment timeout.");
}
}
}
}
private String getApplicationName(File application)
{
String name = application.getName();
int extensionBeginning = name.lastIndexOf('.');
return extensionBeginning == -1? name : name.substring(0, extensionBeginning);
}
private void deployApplications() throws MojoFailureException
{
for (MuleProcessController m : mules)
{
for (File application : applications)
{
if (!application.exists())
{
throw new MojoFailureException("Application does not exists: " + application.getAbsolutePath());
}
log.debug("Deploying application [" + application + "]");
try
{
m.deploy(application.getAbsolutePath());
}
catch (MuleControllerException e)
{
log.error("Couldn't deploy application: " + application + ". Check Mule ESB logs");
}
}
}
}
private void startMulesIfStopped()
{
for (MuleProcessController m : mules)
{
log.debug("Checking if Mule ESB is running.");
if (!m.isRunning())
{
try
{
log.debug("Starting Mule ESB");
if (arguments == null){
m.start();
} else {
m.start(arguments);
}
}
catch (MuleControllerException e)
{
log.error("Couldn't start Mule ESB. Check Mule ESB logs");
}
}
}
}
public ClusterDeployer addLibraries(List libs)
{
for (File file : libs)
{
for (MuleProcessController c : mules) c.addLibrary(file);
log.debug(String.format("Adding library %s...", file));
}
return this;
}
}