* @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
LOGGER.debug("Moving {} to {}", tmpDir.getAbsolutePath(), 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) {
checkSus(saDirectory, sus);
}
// Everything seems ok, so deploy all SUs
int nbFailures = 0;
List<Element> componentResults = new ArrayList<Element>();
List<String> suKeys = new ArrayList<String>();
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);
LOGGER.debug("Unpack service unit archive {} to {}", artifactFile, targetDir);
FileUtil.unpackArchive(artifactFile, targetDir);
} catch (IOException e) {
nbFailures++;
componentResults.add(ManagementSupport.createComponentFailure(