protected List deploySUs()

in jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java [164:230]


    protected List<ServiceUnitImpl> deploySUs() throws Exception {
        // Create the SA directory
        File saDir = new File(installRoot.getParent(), "sus");
        // Quickly undeploy the SA if it has changed
        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;
    }