* @return result/status of the deployment in xml format
* @throws Exception in xml format
*/
protected String deployServiceAssembly(File tmpDir, ServiceAssembly sa) throws Exception {
String assemblyName = sa.getIdentification().getName();
ServiceAssemblyEnvironment env = environmentContext.getNewServiceAssemblyEnvironment(assemblyName);
File saDirectory = env.getInstallDir();
// move the assembly to a well-named holding area
if (log.isDebugEnabled()) {
log.debug("Moving " + tmpDir.getAbsolutePath() + " to " + saDirectory.getAbsolutePath());
}
saDirectory.getParentFile().mkdirs();
if (!tmpDir.renameTo(saDirectory)) {
throw ManagementSupport.failure("deploy", "Failed to rename " + tmpDir + " to " + saDirectory);
}
// Check all SUs requirements
ServiceUnit[] sus = sa.getServiceUnits();
if (sus != null) {
for (int i = 0; i < sus.length; i++) {
String suName = sus[i].getIdentification().getName();
String artifact = sus[i].getTarget().getArtifactsZip();
String componentName = sus[i].getTarget().getComponentName();
File artifactFile = new File(saDirectory, artifact);
if (!artifactFile.exists()) {
throw ManagementSupport.failure("deploy", "Artifact " + artifact + " not found for service unit " + suName);
}
ComponentMBeanImpl lcc = container.getComponent(componentName);
if (lcc == null) {
throw ManagementSupport.failure("deploy", "Target component " + componentName + " for service unit " + suName + " is not installed");
}
if (!lcc.isStarted()) {
throw ManagementSupport.failure("deploy", "Target component " + componentName + " for service unit " + suName + " is not started");
}
if (lcc.getServiceUnitManager() == null) {
throw ManagementSupport.failure("deploy", "Target component " + componentName + " for service unit " + suName + " does not accept deployments");
}
// TODO: check duplicates here ?
if (isDeployedServiceUnit(componentName, suName)) {
throw ManagementSupport.failure("deploy", "Service unit " + suName + " is already deployed on component " + componentName);
}
}
}
// Everything seems ok, so deploy all SUs
int nbSuccess = 0;
int nbFailures = 0;
List componentResults = new ArrayList();
List suKeys = new ArrayList();
if (sus != null) {
for (int i = 0; i < sus.length; i++) {
File targetDir = null;
String suName = sus[i].getIdentification().getName();
String artifact = sus[i].getTarget().getArtifactsZip();
String componentName = sus[i].getTarget().getComponentName();
// TODO: skip duplicates
// Unpack SU
try {
File artifactFile = new File(saDirectory, artifact);
targetDir = env.getServiceUnitDirectory(componentName, suName);
if (log.isDebugEnabled()) {
log.debug("Unpack service unit archive " + artifactFile + " to " + targetDir);
}
FileUtil.unpackArchive(artifactFile, targetDir);
} catch (IOException e) {