Package org.apache.tuscany.sca.workspace

Examples of org.apache.tuscany.sca.workspace.Workspace


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

        // Build the contribution dependencies
        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(contribution, workspace.getModelResolver());
                }
            }
        }
       
        // 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
View Full Code Here


    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
View Full Code Here

    public Entry<String, Item>[] getAll() {
        logger.fine("getAll");

        // Return all the contributions
        List<Entry<String, Item>> entries = new ArrayList<Entry<String, Item>>();
        Workspace workspace = readContributions(readWorkspace());
       
        for (Contribution contribution: workspace.getContributions()) {
            if (contribution.getURI().equals(DEPLOYMENT_CONTRIBUTION_URI)) {
                continue;
            }
            entries.add(entry(workspace, contribution));
        }
View Full Code Here

            throw new ServiceRuntimeException(ex);
        }     
  }
 
  public Workspace createWorkspace(){
        Workspace workspace = workspaceFactory.createWorkspace();
       
        workspace.setModelResolver(new ExtensibleModelResolver(workspace, getRegistry()));
       
        return workspace;     
  }
View Full Code Here

            urlStream = connection.getInputStream();
            XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream);
            reader.nextTag();
           
            // Read the workspace model
            Workspace workspace = (Workspace)staxProcessor.read(reader);
            if (workspace != null) {
                workspace.setURI(uri.toString());
            }

            return workspace;
           
        } catch (XMLStreamException e) {
View Full Code Here

           
        // Get the domain composite items
        Entry<String, Item>[] domainEntries = domainCompositeCollection.getAll();
       
        // Populate the domain composite
        Workspace workspace = workspaceFactory.createWorkspace();
        workspace.setModelResolver(new ExtensibleModelResolver(workspace, extensionPoints));
       
        Map<String, Contribution> contributionMap = new HashMap<String, Contribution>();
        for (Entry<String, Item> domainEntry: domainEntries) {
           
            // Load the required contributions
            String contributionURI = contributionURI(domainEntry.getKey());
            Contribution contribution = contributionMap.get(contributionURI);
            if (contribution == null) {
               
                // The contribution has not been loaded yet, load it with all its dependencies
                Entry<String, Item>[] entries = contributionCollection.query("alldependencies=" + contributionURI);
                for (Entry<String, Item> entry: entries) {
                    Item dependencyItem = entry.getData();
                    String dependencyURI = entry.getKey();
                   
                    if (!contributionMap.containsKey(dependencyURI)) {
                       
                        // Read the contribution
                        Contribution dependency;
                        try {
                            String dependencyLocation = dependencyItem.getAlternate();
                            dependency = contribution(workspace, dependencyURI, dependencyLocation);
                        } catch (Exception e) {
                            if (contributionURI.equals(dependencyURI)) {
                                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, getDescription(e));
                                return;
                            } else {
                                continue;
                            }
                        }
                        workspace.getContributions().add(dependency);
                        contributionMap.put(dependencyURI, dependency);
                       
                        if (contributionURI.equals(entry.getKey())) {
                            contribution = dependency;
                        }
View Full Code Here

       
        // Get the collection of cloud composites
        Entry<String, Item>[] cloudEntries = cloudCollection.getAll();
       
        // Load the cloud contributions
        Workspace workspace = workspaceFactory.createWorkspace();
        Map<String, Contribution> contributionMap = new HashMap<String, Contribution>();
        for (Entry<String, Item> cloudEntry: cloudEntries) {
            String key = cloudEntry.getKey();
            String contributionURI = contributionURI(key);

            // Load the contribution
            Contribution contribution = contributionMap.get(contributionURI);
            if (contribution == null) {
                Item contributionItem = contributionCollection.get(contributionURI);
               
                // Read the contribution
                try {
                    contribution = contribution(workspace, contributionURI, contributionItem.getAlternate());
                } catch (ContributionReadException e) {
                    continue;
                }
                workspace.getContributions().add(contribution);
                contributionMap.put(contributionURI, contribution);
               
            }

            // Include the cloud composite in the clouds composite
View Full Code Here

    public Item get(String key) throws NotFoundException {
        logger.fine("get " + key);

        // Returns the contribution with the given URI key
        Workspace workspace = readContributions(readWorkspace());
        for (Contribution contribution: workspace.getContributions()) {
            if (key.equals(contribution.getURI())) {
                return item(workspace, contribution);
            }
        }
        throw new NotFoundException(key);
View Full Code Here

   
    public String post(String key, Item item) {
        logger.fine("post " + key);
       
        // Adds a new contribution to the workspace
        Workspace workspace = readWorkspace();
        Contribution contribution = contributionFactory.createContribution();
        contribution.setURI(key);
        try {
            contribution.setLocation(locationURL(item.getLink()).toString());
        } catch (MalformedURLException e) {
            throw new ServiceRuntimeException(e);
        }
        workspace.getContributions().add(contribution);
       
        // Write the workspace
        writeWorkspace(workspace);
       
        return key;
View Full Code Here

    }

    public void put(String key, Item item) throws NotFoundException {
       
        // Update a contribution already in the workspace
        Workspace workspace = readWorkspace();
        Contribution newContribution = contributionFactory.createContribution();
        newContribution.setURI(key);
        try {
            newContribution.setLocation(locationURL(item.getLink()).toString());
        } catch (MalformedURLException e) {
            throw new ServiceRuntimeException(e);
        }
        List<Contribution> contributions = workspace.getContributions();
        for (int i = 0, n = contributions.size(); i < n; i++) {
            if (contributions.get(i).getURI().equals(key)) {
                contributions.set(i, newContribution);
               
                // Write the workspace
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.workspace.Workspace

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.