if (isModified && !isFirstInstall) {
for (ServiceUnitDesc sud : descriptor.getServiceAssembly().getServiceUnits()) {
File suRootDir = new File(saDir, sud.getIdentification().getName());
String componentName = sud.getTarget().getComponentName();
ComponentImpl component = deployer.getComponent(componentName);
ServiceUnitImpl su = deployer.createServiceUnit(sud, suRootDir, component);
try {
su.undeploy();
} catch (Exception e) {
LOGGER.warn("Problem undeploying SU " + su.getName());
}
}
}
// Wipe out the SA dir
if (isModified) {
FileUtil.deleteFile(saDir);
FileUtil.buildDirectory(saDir);
}
// Iterate each SU and deploy it
List<ServiceUnitImpl> sus = new ArrayList<ServiceUnitImpl>();
Exception failure = null;
for (ServiceUnitDesc sud : descriptor.getServiceAssembly().getServiceUnits()) {
// Create directory for this SU
File suRootDir = new File(saDir, sud.getIdentification().getName());
// Unpack it
if (isModified) {
String zip = sud.getTarget().getArtifactsZip();
URL zipUrl = bundle.getResource(zip);
FileUtil.unpackArchive(zipUrl, suRootDir);
}
// Find component
String componentName = sud.getTarget().getComponentName();
ComponentImpl component = deployer.getComponent(componentName);
// Create service unit object
ServiceUnitImpl su = deployer.createServiceUnit(sud, suRootDir, component);
try {
LOGGER.debug("Deploying SU " + su.getName());
if (isModified) {
su.deploy();
}
// Add it to the list
sus.add(su);
} catch (Throwable e) {
LOGGER.error("Error deploying SU " + su.getName(), e);
failure = new Exception("Error deploying SU " + su.getName(), e);
break;
}
}
// If failure, undeploy SU and exit
if (failure != null) {
for (ServiceUnitImpl su : sus) {
try {
LOGGER.debug("Undeploying SU " + su.getName());
su.undeploy();
} catch (Exception e) {
LOGGER.warn("Error undeploying SU " + su.getName(), e);
}
}
throw failure;
}
return sus;