From 5f2d26d1844bb1da514f43a04ee8b012e9f6a709 Mon Sep 17 00:00:00 2001 From: antelder Date: Fri, 4 Jun 2010 13:41:38 +0000 Subject: Add methods to install/update using Deployer artifacts and associated simplify use of monitors git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@951409 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tuscany/sca/something/Section10.java | 9 +++- .../tuscany/sca/something/Section10Factory.java | 5 +- .../sca/something/impl/DeployedComposite.java | 17 +++--- .../tuscany/sca/something/impl/Section10Impl.java | 42 ++++++++++----- .../tuscany/sca/something/DeployerTestCase.java | 63 ++++++++++++++++++++++ 5 files changed, 109 insertions(+), 27 deletions(-) create mode 100644 sca-java-2.x/trunk/modules/domain/src/test/java/org/apache/tuscany/sca/something/DeployerTestCase.java diff --git a/sca-java-2.x/trunk/modules/domain/src/main/java/org/apache/tuscany/sca/something/Section10.java b/sca-java-2.x/trunk/modules/domain/src/main/java/org/apache/tuscany/sca/something/Section10.java index 0704de8f35..02bba46567 100644 --- a/sca-java-2.x/trunk/modules/domain/src/main/java/org/apache/tuscany/sca/something/Section10.java +++ b/sca-java-2.x/trunk/modules/domain/src/main/java/org/apache/tuscany/sca/something/Section10.java @@ -26,7 +26,9 @@ import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.deployment.Deployer; import org.apache.tuscany.sca.monitor.ValidationException; import org.apache.tuscany.sca.runtime.ActivationException; import org.oasisopen.sca.NoSuchServiceException; @@ -70,6 +72,7 @@ public interface Section10 { /* autoDeploy indicates whether or not to automatically deploy the deployables defined in sca-contribution.xml */ String installContribution(String contributionURL, boolean autoDeploy) throws ContributionReadException, ActivationException, ValidationException; void installContribution(String uri, String contributionURL, List dependentContributionURIs, boolean autoDeploy) throws ContributionReadException, ActivationException, ValidationException; + void installContribution(Contribution contribution, List dependentContributionURIs, boolean autoDeploy) throws ContributionReadException, ActivationException, ValidationException; /** * 4577 10.5.1 install Contribution & update Contribution @@ -99,6 +102,7 @@ public interface Section10 { * @param contributionURL */ void updateContribution(String uri, String contributionURL); + void updateContribution(Contribution contribution); /** * 4599 10.5.2 add Deployment Composite & update Deployment Composite @@ -122,7 +126,8 @@ public interface Section10 { * @throws ActivationException * @throws ValidationException */ - String addDeploymentComposite(String contriubutionURI, Reader compositeXML) throws ContributionReadException, XMLStreamException, ActivationException, ValidationException; + String addDeploymentComposite(String contributionURI, Reader compositeXML) throws ContributionReadException, XMLStreamException, ActivationException, ValidationException; + String addDeploymentComposite(String contributionURI, Composite composite) throws ActivationException; /** * 4599 10.5.2 add Deployment Composite & update Deployment Composite @@ -143,6 +148,7 @@ public interface Section10 { * @return */ String updateDeploymentComposite(String uri, Reader compositeXML); + String updateDeploymentComposite(String uri, Composite composite); /** * 4611 11.4.310.5.3 remove Contribution @@ -226,4 +232,5 @@ public interface Section10 { List getDeployedCompostes(String contributionURI); List getInstalledContributions(); + Deployer getDeployer(); } diff --git a/sca-java-2.x/trunk/modules/domain/src/main/java/org/apache/tuscany/sca/something/Section10Factory.java b/sca-java-2.x/trunk/modules/domain/src/main/java/org/apache/tuscany/sca/something/Section10Factory.java index 190524a40d..8822af178e 100644 --- a/sca-java-2.x/trunk/modules/domain/src/main/java/org/apache/tuscany/sca/something/Section10Factory.java +++ b/sca-java-2.x/trunk/modules/domain/src/main/java/org/apache/tuscany/sca/something/Section10Factory.java @@ -29,7 +29,6 @@ import org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; import org.apache.tuscany.sca.deployment.Deployer; -import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.runtime.CompositeActivator; import org.apache.tuscany.sca.runtime.EndpointRegistry; import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory; @@ -41,7 +40,6 @@ public class Section10Factory { private Deployer deployer; private ExtensionPointRegistry extensionPointRegistry; - private MonitorFactory monitorFactory; private CompositeActivator compositeActivator; private ExtensibleDomainRegistryFactory domainRegistryFactory; @@ -60,7 +58,7 @@ public class Section10Factory { public Section10 createSection10(String domainName) { EndpointRegistry endpointRegistry = domainRegistryFactory.getEndpointRegistry("default", domainName); - return new Section10Impl(domainName, deployer, monitorFactory, compositeActivator, endpointRegistry, extensionPointRegistry); + return new Section10Impl(domainName, deployer, compositeActivator, endpointRegistry, extensionPointRegistry); } public void shutdown() { @@ -82,7 +80,6 @@ public class Section10Factory { modelFactories.addFactory(assemblyFactory); UtilityExtensionPoint utilities = extensionPointRegistry.getExtensionPoint(UtilityExtensionPoint.class); - this.monitorFactory = utilities.getUtility(MonitorFactory.class); this.compositeActivator = utilities.getUtility(CompositeActivator.class); this.deployer = utilities.getUtility(Deployer.class); utilities.getUtility(RuntimeProperties.class).setProperties(config); diff --git a/sca-java-2.x/trunk/modules/domain/src/main/java/org/apache/tuscany/sca/something/impl/DeployedComposite.java b/sca-java-2.x/trunk/modules/domain/src/main/java/org/apache/tuscany/sca/something/impl/DeployedComposite.java index 0ac3162122..dfd4c9b9ba 100644 --- a/sca-java-2.x/trunk/modules/domain/src/main/java/org/apache/tuscany/sca/something/impl/DeployedComposite.java +++ b/sca-java-2.x/trunk/modules/domain/src/main/java/org/apache/tuscany/sca/something/impl/DeployedComposite.java @@ -34,7 +34,6 @@ import org.apache.tuscany.sca.contribution.processor.ContributionResolveExceptio import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.deployment.Deployer; import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.monitor.ValidationException; import org.apache.tuscany.sca.runtime.ActivationException; import org.apache.tuscany.sca.runtime.CompositeActivator; @@ -51,7 +50,6 @@ public class DeployedComposite { private CompositeActivator compositeActivator; private CompositeContext compositeContext; private Deployer deployer; - private MonitorFactory monitorFactory; private EndpointRegistry endpointRegistry; private ExtensionPointRegistry extensionPointRegistry; @@ -60,7 +58,6 @@ public class DeployedComposite { List dependedOnContributions, Deployer deployer, CompositeActivator compositeActivator, - MonitorFactory monitorFactory, EndpointRegistry endpointRegistry, ExtensionPointRegistry extensionPointRegistry) throws ActivationException { this.composite = composite; @@ -68,7 +65,6 @@ public class DeployedComposite { this.dependedOnContributions = dependedOnContributions; this.deployer = deployer; this.compositeActivator = compositeActivator; - this.monitorFactory = monitorFactory; this.endpointRegistry = endpointRegistry; this.extensionPointRegistry = extensionPointRegistry; try { @@ -85,16 +81,17 @@ public class DeployedComposite { contribution.get(0).getDeployables().clear(); contribution.get(0).getDeployables().add(composite); - Monitor monitor = monitorFactory.createMonitor(); - Monitor tcm = monitorFactory.setContextMonitor(monitor); - try { + Monitor monitor = deployer.createMonitor(); +// TODO: is the ContextMonitor neccessary here? +// Monitor tcm = monitorFactory.setContextMonitor(monitor); +// try { domainComposite = deployer.build(contribution, dependedOnContributions, new HashMap>(), monitor); monitor.analyzeProblems(); - } finally { - monitorFactory.setContextMonitor(tcm); - } +// } finally { +// monitorFactory.setContextMonitor(tcm); +// } compositeContext = new CompositeContext(extensionPointRegistry, endpointRegistry, diff --git a/sca-java-2.x/trunk/modules/domain/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java b/sca-java-2.x/trunk/modules/domain/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java index 60b44588bf..f87bf4c6ad 100644 --- a/sca-java-2.x/trunk/modules/domain/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java +++ b/sca-java-2.x/trunk/modules/domain/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java @@ -40,7 +40,6 @@ import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.deployment.Deployer; import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.monitor.ValidationException; import org.apache.tuscany.sca.runtime.ActivationException; import org.apache.tuscany.sca.runtime.CompositeActivator; @@ -55,15 +54,13 @@ public class Section10Impl implements Section10 { private String domainName; private Deployer deployer; private Map installedContributions = new HashMap(); - private MonitorFactory monitorFactory; private CompositeActivator compositeActivator; private EndpointRegistry endpointRegistry; private ExtensionPointRegistry extensionPointRegistry; - public Section10Impl(String domainName, Deployer deployer, MonitorFactory monitorFactory, CompositeActivator compositeActivator, EndpointRegistry endpointRegistry, ExtensionPointRegistry extensionPointRegistry) { + public Section10Impl(String domainName, Deployer deployer, CompositeActivator compositeActivator, EndpointRegistry endpointRegistry, ExtensionPointRegistry extensionPointRegistry) { this.domainName = domainName; this.deployer = deployer; - this.monitorFactory = monitorFactory; this.compositeActivator = compositeActivator; this.endpointRegistry = endpointRegistry; this.extensionPointRegistry = extensionPointRegistry; @@ -92,8 +89,13 @@ public class Section10Impl implements Section10 { Monitor monitor = deployer.createMonitor(); Contribution contribution = deployer.loadContribution(URI.create(uri), url, monitor); monitor.analyzeProblems(); - InstalledContribution ic = new InstalledContribution(uri, url.toString(), contribution); - installedContributions.put(uri, ic); + installContribution(contribution, dependentContributionURIs, autoDeploy); + } + + public void installContribution(Contribution contribution, List dependentContributionURIs, boolean autoDeploy) throws ContributionReadException, ActivationException, ValidationException { + // TODO: dependentContributionURIs + InstalledContribution ic = new InstalledContribution(contribution.getURI(), contribution.getLocation(), contribution); + installedContributions.put(contribution.getURI(), ic); if (autoDeploy) { for (Composite c : ic.getDefaultDeployables()) { deployComposite(c, ic); @@ -102,15 +104,17 @@ public class Section10Impl implements Section10 { } public String addDeploymentComposite(String contributionURI, Reader compositeXML) throws ContributionReadException, XMLStreamException, ActivationException, ValidationException { + Monitor monitor = deployer.createMonitor(); + Composite composite = deployer.loadXMLDocument(compositeXML, monitor); + monitor.analyzeProblems(); + return addDeploymentComposite(contributionURI, composite); + } + + public String addDeploymentComposite(String contributionURI, Composite composite) throws ActivationException { InstalledContribution ic = installedContributions.get(contributionURI); if (ic == null) { throw new IllegalArgumentException("contribution not installed: " + contributionURI); } - - Monitor monitor = monitorFactory.createMonitor(); - Composite composite = deployer.loadXMLDocument(compositeXML, monitor); - monitor.analyzeProblems(); - String compositeArtifcatURI = deployer.attachDeploymentComposite(ic.getContribution(), composite, true); deployComposite(composite, ic); return compositeArtifcatURI; @@ -242,7 +246,7 @@ public class Section10Impl implements Section10 { dependentContributions.add(ics.getContribution()); } - DeployedComposite dc = new DeployedComposite(c, ic, dependentContributions, deployer, compositeActivator, monitorFactory, endpointRegistry, extensionPointRegistry); + DeployedComposite dc = new DeployedComposite(c, ic, dependentContributions, deployer, compositeActivator, endpointRegistry, extensionPointRegistry); ic.getDeployedComposites().add(dc); } @@ -262,4 +266,18 @@ public class Section10Impl implements Section10 { } return dependentContributionURIs; } + + public Deployer getDeployer() { + return deployer; + } + + public void updateContribution(Contribution contribution) { + // TODO Auto-generated method stub + + } + + public String updateDeploymentComposite(String uri, Composite composite) { + // TODO Auto-generated method stub + return null; + } } diff --git a/sca-java-2.x/trunk/modules/domain/src/test/java/org/apache/tuscany/sca/something/DeployerTestCase.java b/sca-java-2.x/trunk/modules/domain/src/test/java/org/apache/tuscany/sca/something/DeployerTestCase.java new file mode 100644 index 0000000000..33e999b0b4 --- /dev/null +++ b/sca-java-2.x/trunk/modules/domain/src/test/java/org/apache/tuscany/sca/something/DeployerTestCase.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.something; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URI; +import java.util.List; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.deployment.Deployer; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.ValidationException; +import org.apache.tuscany.sca.runtime.ActivationException; +import org.junit.Test; +import org.oasisopen.sca.NoSuchDomainException; +import org.oasisopen.sca.NoSuchServiceException; + +public class DeployerTestCase { + + @Test + public void testInstalledContribution() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, MalformedURLException { + Section10 section10 = Section10Factory.createSection10(); + + Deployer deployer = section10.getDeployer(); + Monitor monitor = deployer.createMonitor(); + Contribution contribution = deployer.loadContribution(URI.create("foo"), new File("src/test/resources/sample-helloworld-nodeployable.jar").toURI().toURL(), monitor); + monitor.analyzeProblems(); + + section10.installContribution(contribution, null, true); + List ics = section10.getInstalledContributions(); + Assert.assertEquals(1, ics.size()); + Assert.assertEquals("foo", ics.get(0)); + } + + @Test + public void testAddDeploymentComposite() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, MalformedURLException { + Section10 section10 = Section10Factory.createSection10(); + + Deployer deployer = section10.getDeployer(); + Monitor monitor = deployer.createMonitor(); + } + +} -- cgit v1.2.3