public ProgressObject distribute(TargetImpl []hostTargets,
InputStream archiveIs,
DeploymentPlan plan)
throws IllegalStateException
{
ProgressObjectImpl progress;
if (hostTargets == null || hostTargets.length != 1) {
String msg = L.l("jsr88 can only support single-host deploy");
log.warning(msg);
progress = new ProgressObjectImpl(new TargetModuleID[0]);
progress.failed(msg);
return progress;
}
String hostName = hostTargets[0].getName();
String name = plan.getName();
String moduleID;
ArchiveDeployMXBean mxbean = null;
try {
if ("ear".equals(plan.getArchiveType())) {
moduleID = "resin:name=" + name + ",type=EApp,Host=" + hostName;
String jmxName = "resin:type=EarDeploy,Host=" + hostName + ",*";
mxbean = loadArchiveMXBean(jmxName);
}
else if ("war".equals(plan.getArchiveType())) {
moduleID = "resin:name=/" + name + ",type=WebApp,Host=" + hostName;
String jmxName = "resin:type=WebAppDeploy,Host=" + hostName + ",*";
mxbean = loadArchiveMXBean(jmxName);
}
else if ("rar".equals(plan.getArchiveType())) {
moduleID = "resin:name=" + name + ",type=Resource,Host=" + hostName;
String jmxName = "resin:type=ResourceDeploy,Host=" + hostName + ",*";
mxbean = loadArchiveMXBean(jmxName);
}
else
throw new UnsupportedOperationException(plan.getArchiveType());
} catch (Exception e) {
throw new RuntimeException(e);
}
boolean failed = false;
StringBuilder message = new StringBuilder();
Path archivePath = null;
Throwable exception = null;
TargetImpl childTarget = new TargetImpl(moduleID, "");
TargetModuleIDImpl childModuleID
= new TargetModuleIDImpl(childTarget, moduleID);
if (mxbean != null) {
try {
Path deployPath = Vfs.lookup(mxbean.getArchivePath(name));
deployPath.getParent().mkdirs();
if (archivePath == null) {
createArchive(deployPath, plan, archiveIs);
archivePath = deployPath;
}
else {
WriteStream deployStream = deployPath.openWrite();
try {
deployStream.writeFile(archivePath);
}
finally {
deployStream.close();
}
}
mxbean.update();
exception = mxbean.getConfigException(name);
}
catch (Exception e) {
if (log.isLoggable(Level.INFO))
log.log(Level.INFO, e.toString(), e);
exception = e;
}
if (exception != null) {
failed = true;
describe(message, childModuleID, false, getExceptionMessage(exception));
/*
if (mxbean != null) {
try {
mxbean.undeploy(moduleID);
}
catch (Throwable t) {
log.log(Level.FINE, t.toString(), t);
}
}
*/
}
else {
if ("ear".equals(plan.getArchiveType())) {
try {
EAppMXBean eApp = (EAppMXBean) Jmx.find(moduleID);
if (eApp != null)
childTarget.setClientRefs(eApp.getClientRefs());
} catch (Exception e) {
log.log(Level.FINEST, e.toString(), e);
}
}
describe(message, childModuleID, true);
}
}
else {
failed = true;
log.warning(L.l("jsr88 cannot deploy '{0}', can't find deployment resource (e.g. web-app-deploy, ear-deploy).", moduleID));
}
TargetModuleID []targetModuleIDs
= new TargetModuleID[] { childModuleID };
progress = new ProgressObjectImpl(targetModuleIDs);
if (failed)
progress.failed(message.toString());
else
progress.completed(message.toString());
return progress;
}