public void addToDomainLevelComposite(QName compositeQName, String nodeURI) throws DomainException {
try {
// check to see if this composite has already been added
if (domainModel.getDeployedComposites().containsKey(compositeQName) ){
throw new DomainException("Composite " + compositeQName.toString() +
" had already been added to the domain level composite");
}
// find the contribution that has this composite
ContributionModel contributionModel = findContributionFromComposite(compositeQName);
if (contributionModel == null){
throw new DomainException("Can't find contribution for composite " + compositeQName.toString());
}
// find the composite object from the contribution
CompositeModel compositeModel = contributionModel.getComposites().get(compositeQName);
if (compositeModel == null){
throw new DomainException("Can't find composite model " + compositeQName.toString() +
" in contribution " + contributionModel.getContributionURI());
}
// build the contribution to create the services and references
domainModel.getDeployedComposites().put(compositeQName, compositeModel);
domainManagementRuntime.getCompositeBuilder().build(compositeModel.getComposite());
domainModel.getDomainLevelComposite().getIncludes().add(compositeModel.getComposite());
NodeModel node = null;
// find the node for the composite to run on
if (nodeURI != null) {
// find the named node
node = domainModel.getNodes().get(nodeURI);
if (node == null){
throw new DomainException("Node " + nodeURI + " not found in domain");
}
} else {
// noddy algorithm to find a free node
// TODO - do something better
for(NodeModel tmpNode : domainModel.getNodes().values()) {
if (tmpNode.getLifecycleState() == LifecyleState.AVAILABLE){
node = tmpNode;
}
}
if (node == null){
throw new DomainException("No free node available to run composite " + compositeQName.toString());
}
}
// find all the composites that the node must know about
List<Contribution> dependentContributions = new ArrayList<Contribution>();
findDependentContributions(contributionModel.getContribution(), dependentContributions);
// assign the set of contributions to the node model
for (Contribution tmpContribution : dependentContributions){
node.getContributions().put(tmpContribution.getURI(),
domainModel.getContributions().get(tmpContribution.getURI()));
}
// assign the composite to the node model
node.getDeployedComposites().put(compositeQName, compositeModel);
node.setLifecycleState(LifecyleState.DEPLOYED);
// now pass this information over to the real node
// add contributions. Use the dependent contribution list here rather than the
// one built up in the node model to ensure that contributions are added in the correct order
// I.e. the top most in the dependency tree last.
for (Contribution tmpContribution : dependentContributions){
((NodeModelImpl)node).getSCANodeManagerService().addContribution(tmpContribution.getURI(),
domainModel.getContributions().get(tmpContribution.getURI()).getContributionURL());
}
// deploy composite
((NodeModelImpl)node).getSCANodeManagerService().addToDomainLevelComposite(compositeQName.toString());
// spray all of the service endpoints from this composite out to interested nodes
notifyDomainChange();
} catch (DomainException ex) {
throw ex;
} catch (Exception ex) {
throw new DomainException(ex);
}
}