public static void main(String[] args) throws Exception {
init();
// Create workspace model
Workspace workspace = workspaceFactory.createWorkspace();
workspace.setModelResolver(new ExtensibleModelResolver(workspace, modelResolvers, modelFactories));
// Read the sample store contribution
URI storeURI = URI.create("store");
URL storeURL = new File("./target/sample-domain-management-store.jar").toURI().toURL();
Contribution storeContribution = contributionProcessor.read(null, storeURI, storeURL);
workspace.getContributions().add(storeContribution);
// Read the sample assets contribution
URI assetsURI = URI.create("assets");
URL assetsURL = new File("./target/sample-domain-management-assets.jar").toURI().toURL();
Contribution assetsContribution = contributionProcessor.read(null, assetsURI, assetsURL);
workspace.getContributions().add(assetsContribution);
// Read the sample client contribution
URI clientURI = URI.create("client");
URL clientURL = new File("./target/sample-domain-management-client.jar").toURI().toURL();
Contribution clientContribution = contributionProcessor.read(null, clientURI, clientURL);
workspace.getContributions().add(clientContribution);
// Build the contribution dependencies
Map<Contribution, List<Contribution>> contributionDependencies = new HashMap<Contribution, List<Contribution>>();
Set<Contribution> resolved = new HashSet<Contribution>();
for (Contribution contribution: workspace.getContributions()) {
List<Contribution> dependencies = contributionDependencyBuilder.buildContributionDependencies(contribution, workspace);
// Resolve contributions
for (Contribution dependency: dependencies) {
if (!resolved.contains(dependency)) {
resolved.add(dependency);
contributionProcessor.resolve(dependency, workspace.getModelResolver());
}
}
contributionDependencies.put(contribution, dependencies);
}
// Create a set of nodes, and assign the sample deployables to them
Map<Component, List<Contribution>> nodeDependencies = new HashMap<Component, List<Contribution>>();
Composite cloudComposite = assemblyFactory.createComposite();
cloudComposite.setName(new QName("http://sample", "cloud"));
int nodeID = 8100;
for (Contribution contribution: workspace.getContributions()) {
for (Composite deployable: contribution.getDeployables()) {
// Create a node
Component node = assemblyFactory.createComponent();
node.setName("Node" + nodeID);
cloudComposite.getComponents().add(node);
// Add default binding configuration to the node, our samples use
// Atom bindings so here we're just creating default Atom binding
// configurations, but all the other binding types can be configured
// like that too
ComponentService nodeService = assemblyFactory.createComponentService();
Binding binding = atomBindingFactory.createAtomBinding();
binding.setURI("http://localhost:" + (8100 + nodeID));
nodeService.getBindings().add(binding);
node.getServices().add(nodeService);
// Assign a deployable to the node
NodeImplementation nodeImplementation = nodeFactory.createNodeImplementation();
nodeImplementation.setComposite(deployable);
node.setImplementation(nodeImplementation);
// Keep track of what contributions will be needed by the node
nodeDependencies.put(node, contributionDependencies.get(contribution));
nodeID++;
}
}
// Print the model describing the nodes that we just built
System.out.println("cloud.composite");
System.out.println(print(cloudComposite));
// Build the nodes, this will apply their default binding configuration to the
// composites assigned to them
nodeCompositeBuilder.build(cloudComposite);
// Create a composite model for the domain
Composite domainComposite = assemblyFactory.createComposite();
domainComposite.setName(new QName("http://sample", "domain"));
// Add all deployables to it, normally the domain administrator would select
// the deployables to include
domainComposite.getIncludes().addAll(workspace.getDeployables());
// Build the domain composite and wire the components included in it
domainCompositeBuilder.build(domainComposite);
// Print out the resulting domain composite