/* (non-Javadoc)
* @see org.mule.jbi.registry.Assembly#deploy()
*/
public synchronized String deploy() throws RegistryException {
if (!getCurrentState().equals(UNKNOWN)) {
throw new RegistryException("Illegal status: " + getCurrentState());
}
try {
Jbi jbi = (Jbi)getDescriptor().getConfiguration();
// Deploy service units
ServiceUnit[] sua = jbi.getServiceAssembly().getServiceUnitArray();
this.units = new ArrayList();
for (int i = 0; i < sua.length; i++) {
String suName = sua[i].getIdentification().getName();
String artifactName = sua[i].getTarget().getArtifactsZip();
String componentName = sua[i].getTarget().getComponentName();
File artifact = new File(getInstallRoot(), artifactName);
File installDir = new File(getInstallRoot(), componentName + File.separator + suName);
// Check that artifact exists
if (!artifact.isFile()) {
throw new JBIException("Artifact file not found: " + sua[i].getTarget().getArtifactsZip());
}
// Check that component exists
RegistryComponent component = getRegistry().getComponent(componentName);
if (component == null) {
throw new JBIException("Service assembly requires a missing component: " + componentName);
}
// Check component is fully installed
if (!component.getCurrentState().equals(RUNNING)) {
throw new JBIException("Component is not started: " + componentName);
}
// Check that we can deploy onto it
ServiceUnitManager mgr = ((Component)component.getComponent()).getServiceUnitManager();
if (mgr == null) {
throw new JBIException("Component does not accept deployments: " + componentName);
}
// Check for duplicate SU
Unit[] compUnits = component.getUnits();
for (int j = 0; j < compUnits.length; j++) {
if (compUnits[i].getName().equals(suName)) {
throw new JBIException("Service unit already installed on component: " + suName);
}
}
// Unzip artifact
Utility.unzip(artifact, installDir);
// Create Unit
Unit unit = registry.createUnit(suName);
unit.setAssembly(this);
unit.setRegistryComponent(component);
unit.setInstallRoot(installDir.getAbsolutePath());
// Deploy this unit
String result = unit.deploy();
// TODO: analyse result
}
// Deploy connections
if (jbi.getServiceAssembly().isSetConnections()) {
Connections connections = jbi.getServiceAssembly().getConnections();
Connection[] cns = connections.getConnectionArray();
for (int i = 0; i < cns.length; i++) {
QName consItf = cns[i].getConsumer().getInterfaceName();
QName consSer = cns[i].getConsumer().getServiceName();
String consEP = cns[i].getConsumer().getEndpointName().getStringValue();
QName provSer = cns[i].getProvider().getServiceName();
String provEP = cns[i].getProvider().getEndpointName().getStringValue();
// TODO: deploy connection info
}
}
// Finish
setCurrentState(SHUTDOWN);
// TODO return info
return null;
} catch (Exception e) {
// If we failed, undeploy
undeploy();
if (e instanceof RegistryException) {
throw (RegistryException) e;
} else {
throw new RegistryException("Could not deploy assembly", e);
}
}
}