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()));