summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-05-22 06:49:50 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-05-22 06:49:50 +0000
commit7250f4158b1bdfa9f82760cebf0269a40ad21acd (patch)
tree1ed38f22e8f58bdc5ae808cef35d2cd5b13ade84
parent263ea309c7e5ca7d7e17e84b5186bfab3fbc90df (diff)
Update with code to deploy composites, add getInstalledContributions and getDeployedComposites. Refactor code to have a separate DeployedComposite class
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@947252 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/Section10.java23
-rw-r--r--sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/DeployedComposite.java158
-rw-r--r--sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Helper.java57
-rw-r--r--sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/InstalledContribution.java5
-rw-r--r--sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java172
-rw-r--r--sca-java-2.x/contrib/modules/section10/src/test/java/org/apache/tuscany/sca/something/Section102TestCase.java168
-rw-r--r--sca-java-2.x/contrib/modules/section10/src/test/java/org/apache/tuscany/sca/something/Section10TestCase.java70
7 files changed, 491 insertions, 162 deletions
diff --git a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/Section10.java b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/Section10.java
index d351426c13..dcdc8f71ab 100644
--- a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/Section10.java
+++ b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/Section10.java
@@ -20,13 +20,13 @@
package org.apache.tuscany.sca.something;
import java.io.Reader;
-import java.net.MalformedURLException;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.runtime.ActivationException;
import org.oasisopen.sca.NoSuchServiceException;
public interface Section10 {
@@ -56,17 +56,17 @@ public interface Section10 {
* 4598 this list to be generated by tooling. *
* @param uri
* @param contributionURL
- * @throws MalformedURLException
* @throws ContributionReadException
+ * @throws ActivationException
*/
- void installContribution(String uri, String contributionURL, List<String> dependentContributionURIs) throws ContributionReadException, MalformedURLException;
+ void installContribution(String uri, String contributionURL, List<String> dependentContributionURIs) throws ContributionReadException, ActivationException;
/* and i'd expect short forms of that for when you don't care or have the others:*/
- String installContribution(String contributionURL) throws ContributionReadException, MalformedURLException;
- void installContribution(String uri, String contributionURL) throws ContributionReadException, MalformedURLException;
+ String installContribution(String contributionURL) throws ContributionReadException, ActivationException;
+ void installContribution(String uri, String contributionURL) throws ContributionReadException, ActivationException;
/* autoDeploy indicates whether or not to automatically deploy the deployables defined in sca-contribution.xml */
- String installContribution(String contributionURL, boolean autoDeploy) throws ContributionReadException, MalformedURLException;
- void installContribution(String uri, String contributionURL, List<String> dependentContributionURIs, boolean autoDeploy) throws ContributionReadException, MalformedURLException;
+ String installContribution(String contributionURL, boolean autoDeploy) throws ContributionReadException, ActivationException;
+ void installContribution(String uri, String contributionURL, List<String> dependentContributionURIs, boolean autoDeploy) throws ContributionReadException, ActivationException;
/**
* 4577 10.5.1 install Contribution & update Contribution
@@ -148,8 +148,9 @@ public interface Section10 {
* 4612 Removes the deployed contribution identified by a supplied contribution URI.
*
* @param contributionURI
+ * @throws ActivationException
*/
- void removeContribution(String contributionURI);
+ void removeContribution(String contributionURI) throws ActivationException;
/**
* 4677 10.7.1 add To Domain-Level Composite
@@ -163,8 +164,9 @@ public interface Section10 {
* 4686 outside the domain composite, the usual idea of promotion has no utility.
*
* @param compositeURI
+ * @throws ActivationException
*/
- void addToDomainLevelComposite(String compositeURI);
+ void addToDomainLevelComposite(String compositeURI) throws ActivationException;
/**
* 4687 10.7.2 remove From Domain-Level Composite
@@ -172,8 +174,9 @@ public interface Section10 {
* 4689 supplied composite URI. This means that the removal of the components, wires, services and references
* 4690 originally added to the domain level composite by the identified composite. *
* @param compositeURI
+ * @throws ActivationException
*/
- void removeFromDomainLevelComposite(String compositeURI);
+ void removeFromDomainLevelComposite(String compositeURI) throws ActivationException;
/**
* 10.7.3 get Domain-Level Composite
diff --git a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/DeployedComposite.java b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/DeployedComposite.java
new file mode 100644
index 0000000000..226d3c2b87
--- /dev/null
+++ b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/DeployedComposite.java
@@ -0,0 +1,158 @@
+/*
+ * 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.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.context.CompositeContext;
+import org.apache.tuscany.sca.contribution.Artifact;
+import org.apache.tuscany.sca.contribution.Contribution;
+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.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.apache.tuscany.sca.runtime.ActivationException;
+import org.apache.tuscany.sca.runtime.CompositeActivator;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
+import org.oasisopen.sca.ServiceRuntimeException;
+
+public class DeployedComposite {
+
+ private Composite c;
+ private InstalledContribution ic;
+ private List<Contribution> dependentContributions;
+ private String uri;
+
+ private CompositeActivator compositeActivator;
+ private CompositeContext compositeContext;
+ private Composite domainComposite; // TODO: this is a misleadingly named
+ private Deployer deployer;
+ private MonitorFactory monitorFactory;
+ private EndpointRegistry endpointRegistry;
+ private ExtensionPointRegistry extensionPointRegistry;
+
+ public DeployedComposite(Composite c,
+ InstalledContribution ic,
+ List<Contribution> dependentContributions,
+ Deployer deployer,
+ CompositeActivator compositeActivator,
+ MonitorFactory monitorFactory,
+ EndpointRegistry endpointRegistry,
+ ExtensionPointRegistry extensionPointRegistry) throws ActivationException {
+ this.c = c;
+ this.ic = ic;
+ this.dependentContributions = dependentContributions;
+ this.deployer = deployer;
+ this.compositeActivator = compositeActivator;
+ this.monitorFactory = monitorFactory;
+ this.endpointRegistry = endpointRegistry;
+ this.extensionPointRegistry = extensionPointRegistry;
+ try {
+ init();
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected void init() throws Throwable {
+
+ List<Contribution> contributions = new ArrayList<Contribution>();
+ contributions.add(ic.getContribution());
+ contributions.get(0).getDeployables().clear();
+ contributions.get(0).getDeployables().add(c);
+
+ Monitor monitor = monitorFactory.createMonitor();
+ Monitor tcm = monitorFactory.setContextMonitor(monitor);
+ try {
+
+ domainComposite = deployer.build(contributions, dependentContributions, new HashMap<QName, List<String>>(), monitor);
+ analyzeProblems(monitor);
+
+ } finally {
+ monitorFactory.setContextMonitor(tcm);
+ }
+
+ compositeContext = new CompositeContext(extensionPointRegistry,
+ endpointRegistry,
+ domainComposite,
+ null, // nothing appears to use the domain name in CompositeContext
+ null, // don't need node uri
+ deployer.getSystemDefinitions());
+
+ CompositeContext.setThreadCompositeContext(compositeContext); // TODO: what is this doing?
+
+ compositeActivator.activate(compositeContext, domainComposite);
+ compositeActivator.start(compositeContext, domainComposite);
+
+ this.uri = getCompositeURI(c, ic);
+ }
+
+
+ public void unDeploy() throws ActivationException {
+ compositeActivator.stop(compositeContext, domainComposite);
+ compositeActivator.deactivate(domainComposite);
+ }
+
+ public String getURI() {
+ return uri;
+ }
+
+ /**
+ * Deployable composites don't have the uri set so get it from the artifact in the contribution
+ */
+ protected String getCompositeURI(Composite c, InstalledContribution ic) {
+ for (Artifact a : ic.getContribution().getArtifacts()) {
+ if (a.getModel() != null) {
+ if (a.getModel() instanceof Composite) {
+ Composite cm = a.getModel();
+ if (c.getName().equals(cm.getName())) {
+ return cm.getURI();
+ }
+ }
+ }
+ }
+ // shouldn't ever happen
+ throw new IllegalStateException("can't determine composte uri");
+ }
+
+ protected void analyzeProblems(Monitor monitor) throws Throwable {
+ try {
+ for (Problem problem : monitor.getProblems()) {
+ if ((problem.getSeverity() == Severity.ERROR)) {
+ if (problem.getCause() != null) {
+ throw problem.getCause();
+ } else {
+ throw new ServiceRuntimeException(problem.toString());
+ }
+ }
+ }
+ } finally {
+ // FIXME: Clear problems so that the monitor is clean again
+ monitor.reset();
+ }
+ }
+}
diff --git a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Helper.java b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Helper.java
new file mode 100644
index 0000000000..a8a06ed00b
--- /dev/null
+++ b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Helper.java
@@ -0,0 +1,57 @@
+/*
+ * 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.impl;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.node.impl.NodeFactoryImpl;
+import org.apache.tuscany.sca.runtime.ActivationException;
+import org.apache.tuscany.sca.runtime.CompositeActivator;
+import org.apache.tuscany.sca.runtime.DomainRegistryFactory;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
+import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory;
+
+public class Helper {
+
+ public static DeployedComposite createDeployedComposite(Composite composite,
+ InstalledContribution ic,
+ List<Contribution> dependentContributions,
+ String domainName,
+ NodeFactoryImpl nodeFactory) throws ActivationException {
+
+ // TODO: have this code as a separate static method for now to keep the impl class clean while its worked out what it needs
+
+ UtilityExtensionPoint utilities = nodeFactory.getExtensionPointRegistry().getExtensionPoint(UtilityExtensionPoint.class);
+ CompositeActivator compositeActivator = utilities.getUtility(CompositeActivator.class);
+ MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
+
+ DomainRegistryFactory domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(nodeFactory.getExtensionPointRegistry());
+ EndpointRegistry endpointRegistry = domainRegistryFactory.getEndpointRegistry("default", domainName);
+
+ return new DeployedComposite(composite, ic, dependentContributions, nodeFactory.getDeployer(),
+ compositeActivator, monitorFactory, endpointRegistry,
+ nodeFactory.getExtensionPointRegistry());
+ }
+
+}
diff --git a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/InstalledContribution.java b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/InstalledContribution.java
index 90f81724cf..3fbad6091c 100644
--- a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/InstalledContribution.java
+++ b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/InstalledContribution.java
@@ -22,7 +22,6 @@ package org.apache.tuscany.sca.something.impl;
import java.util.ArrayList;
import java.util.List;
-import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.contribution.Contribution;
public class InstalledContribution {
@@ -32,7 +31,7 @@ public class InstalledContribution {
private String uri;
private String url;
private Contribution contribution;
- private List<Composite> deployedComposites = new ArrayList<Composite>();
+ private List<DeployedComposite> deployedComposites = new ArrayList<DeployedComposite>();
public InstalledContribution(String uri, String url, Contribution contribution) {
this.uri = uri;
@@ -51,7 +50,7 @@ public class InstalledContribution {
public String getURL() {
return url;
}
- public List<Composite> getDeployedComposites() {
+ public List<DeployedComposite> getDeployedComposites() {
return deployedComposites;
}
diff --git a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java
index 4130af2a94..608a131505 100644
--- a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java
+++ b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java
@@ -19,7 +19,6 @@
package org.apache.tuscany.sca.something.impl;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.Reader;
import java.net.MalformedURLException;
@@ -32,33 +31,19 @@ import java.util.Map;
import java.util.Properties;
import javax.xml.namespace.QName;
-import javax.xml.stream.XMLOutputFactory;
-import org.apache.tuscany.sca.assembly.Component;
import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.common.java.io.IOHelper;
-import org.apache.tuscany.sca.context.CompositeContext;
import org.apache.tuscany.sca.contribution.Artifact;
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
-import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
-import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
-import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.core.UtilityExtensionPoint;
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.Problem;
import org.apache.tuscany.sca.monitor.Problem.Severity;
import org.apache.tuscany.sca.node.NodeFactory;
-import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
import org.apache.tuscany.sca.node.impl.NodeFactoryImpl;
-import org.apache.tuscany.sca.runtime.CompositeActivator;
-import org.apache.tuscany.sca.runtime.DomainRegistryFactory;
-import org.apache.tuscany.sca.runtime.EndpointRegistry;
-import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory;
+import org.apache.tuscany.sca.runtime.ActivationException;
import org.apache.tuscany.sca.something.Section10;
import org.oasisopen.sca.NoSuchDomainException;
import org.oasisopen.sca.NoSuchServiceException;
@@ -75,25 +60,25 @@ public class Section10Impl implements Section10 {
((NodeFactoryImpl)nodeFactory).start();
}
- public String installContribution(String contributionURL) throws ContributionReadException, MalformedURLException {
+ public String installContribution(String contributionURL) throws ContributionReadException, ActivationException {
installContribution(contributionURL, contributionURL, null, true);
return contributionURL;
}
- public String installContribution(String contributionURL, boolean autoDeploy) throws ContributionReadException, MalformedURLException {
+ public String installContribution(String contributionURL, boolean autoDeploy) throws ContributionReadException, ActivationException {
installContribution(contributionURL, contributionURL, null, autoDeploy);
return contributionURL;
}
- public void installContribution(String uri, String contributionURL) throws ContributionReadException, MalformedURLException {
+ public void installContribution(String uri, String contributionURL) throws ContributionReadException, ActivationException {
installContribution(uri, contributionURL, null, true);
}
- public void installContribution(String uri, String contributionURL, List<String> dependentContributionURIs) throws ContributionReadException, MalformedURLException {
+ public void installContribution(String uri, String contributionURL, List<String> dependentContributionURIs) throws ContributionReadException, ActivationException {
installContribution(uri, contributionURL, dependentContributionURIs, true);
}
- public void installContribution(String uri, String contributionURL, List<String> dependentContributionURIs, boolean autoDeploy) throws ContributionReadException, MalformedURLException {
+ public void installContribution(String uri, String contributionURL, List<String> dependentContributionURIs, boolean autoDeploy) throws ContributionReadException, ActivationException {
Deployer deployer = nodeFactory.getDeployer();
Monitor monitor = deployer.createMonitor();
URL url = getLocationAsURL(contributionURL);
@@ -102,12 +87,7 @@ public class Section10Impl implements Section10 {
installedContributions.put(uri, ic);
if (autoDeploy) {
for (Composite c : contribution.getDeployables()) {
- try {
- deployComposite(c, ic);
- } catch (Throwable e) {
- // TODO tidy up the exceptions
- throw new RuntimeException(e);
- }
+ deployComposite(c, ic);
}
}
}
@@ -122,7 +102,7 @@ public class Section10Impl implements Section10 {
return null;
}
- public void addToDomainLevelComposite(String compositeURI) {
+ public void addToDomainLevelComposite(String compositeURI) throws ActivationException {
String contributionURI = getContributionUriForArtifact(compositeURI);
InstalledContribution ic = installedContributions.get(contributionURI);
if (ic == null) {
@@ -132,25 +112,22 @@ public class Section10Impl implements Section10 {
for (Artifact a : ic.getContribution().getArtifacts()) {
if (a.getURI().equals(relativeURI)) {
Composite c = (Composite) a.getModel();
- try {
- deployComposite(c, ic);
- } catch (Throwable e) {
- // TODO tidy up the exceptions
- throw new RuntimeException(e);
- }
+ deployComposite(c, ic);
return;
}
}
throw new IllegalArgumentException("composite not found: " + compositeURI);
}
- public void removeFromDomainLevelComposite(String compositeURI) {
+ public void removeFromDomainLevelComposite(String compositeURI) throws ActivationException {
String contributionURI = getContributionUriForArtifact(compositeURI);
InstalledContribution ic = installedContributions.get(contributionURI);
String relativeURI = compositeURI.substring(contributionURI.length()+1);
- for (Composite c : ic.getDeployedComposites()) {
- if (relativeURI.equals(c.getURI())) {
- undeployComposite(c, ic);
+ for (DeployedComposite dc : ic.getDeployedComposites()) {
+ if (relativeURI.equals(dc.getURI())) {
+// undeployComposite(dc, ic);
+ ic.getDeployedComposites().remove(dc);
+ dc.unDeploy();
return;
}
}
@@ -163,9 +140,8 @@ public class Section10Impl implements Section10 {
}
public String getDomainLevelCompositeAsString() {
- StAXArtifactProcessorExtensionPoint xmlProcessors = getExtensionRegistry().getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- StAXArtifactProcessor<Composite> compositeProcessor = xmlProcessors.getProcessor(Composite.class);
- return writeComposite(getDomainLevelComposite(), compositeProcessor);
+ // TODO Auto-generated method stub
+ return null;
}
public Object getQNameDefinition(String contributionURI, QName definition, QName symbolSpace) {
@@ -173,15 +149,17 @@ public class Section10Impl implements Section10 {
return null;
}
- public void removeContribution(String contributionURI) {
+ public void removeContribution(String contributionURI) throws ActivationException {
// TODO: what about dependent contributions
InstalledContribution ic = installedContributions.remove(contributionURI);
if (ic == null) {
throw new IllegalArgumentException("Contribution not installed: " + contributionURI);
}
- for (Composite c : ic.getDeployedComposites()) {
- undeployComposite(c, ic);
+ for (DeployedComposite dc : ic.getDeployedComposites()) {
+// undeployComposite(dc, ic);
+ dc.unDeploy();
}
+ ic.getDeployedComposites().clear();
}
public void updateContribution(String uri, String contributionURL) {
@@ -220,13 +198,17 @@ public class Section10Impl implements Section10 {
}
public List<String> getDeployedCompostes(String contributionURI) {
- // TODO Auto-generated method stub
- return null;
+ ArrayList<String> compositeURIs = new ArrayList<String>();
+ for (InstalledContribution ic : installedContributions.values()) {
+ for (DeployedComposite dc : ic.getDeployedComposites()) {
+ compositeURIs.add(ic.getURI() + "/" + dc.getURI());
+ }
+ }
+ return compositeURIs;
}
- public List<String> getInstalledContributions(String contributionURI) {
- // TODO Auto-generated method stub
- return null;
+ public List<String> getInstalledContributions() {
+ return new ArrayList<String>(installedContributions.keySet());
}
protected String getContributionUriForArtifact(String artifactURI) {
@@ -243,95 +225,27 @@ public class Section10Impl implements Section10 {
return contributionURI;
}
- protected void deployComposite(Composite c, InstalledContribution ic) throws Throwable {
- // TODO Auto-generated method stub
-
- UtilityExtensionPoint utilities = getExtensionRegistry().getExtensionPoint(UtilityExtensionPoint.class);
- CompositeActivator compositeActivator = utilities.getUtility(CompositeActivator.class);
- MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
-
- DomainRegistryFactory domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(getExtensionRegistry());
- EndpointRegistry endpointRegistry = domainRegistryFactory.getEndpointRegistry("default", getDomainName());
-
- Monitor monitor = monitorFactory.createMonitor();
- ProcessorContext context = new ProcessorContext(monitor);
-
- Composite domainComposite;
- CompositeContext compositeContext;
- Monitor tcm = monitorFactory.setContextMonitor(monitor);
- try {
-
- NodeConfiguration configuration;
- List<Contribution> allContributions = new ArrayList<Contribution>();
- for (InstalledContribution ics : installedContributions.values()) {
- allContributions.add(ics.getContribution());
- }
-
- List<Contribution> contributions = new ArrayList<Contribution>();
- contributions.add(ic.getContribution());
- contributions.get(0).getDeployables().clear();
- contributions.get(0).getDeployables().add(c);
- domainComposite = nodeFactory.getDeployer().build(contributions, allContributions, new HashMap<QName, List<String>>(), monitor);
- analyzeProblems(monitor);
+ protected void deployComposite(Composite c, InstalledContribution ic) throws ActivationException {
- compositeContext = new CompositeContext(getExtensionRegistry(),
- endpointRegistry,
- domainComposite,
- getDomainName(),
- "whatIsThisURIfor",
- nodeFactory.getDeployer().getSystemDefinitions());
-
- CompositeContext.setThreadCompositeContext(compositeContext);
- } finally {
- monitorFactory.setContextMonitor(tcm);
+ List<Contribution> dependentContributions = new ArrayList<Contribution>();
+ for (InstalledContribution ics : installedContributions.values()) {
+ dependentContributions.add(ics.getContribution());
}
-
- compositeActivator.activate(compositeContext, domainComposite);
- compositeActivator.start(compositeContext, domainComposite);
-
- ic.getDeployedComposites().add(c);
- }
-
- protected void undeployComposite(Composite c, InstalledContribution ic) {
- ic.getDeployedComposites().remove(c);
- // TODO Auto-generated method stub
- }
-
- protected ExtensionPointRegistry getExtensionRegistry() {
- ExtensionPointRegistry reg = nodeFactory.getExtensionPointRegistry();
- return reg;
- }
- protected String writeComposite(Composite composite, StAXArtifactProcessor<Composite> compositeProcessor){
- XMLOutputFactory outputFactory = getExtensionRegistry().getExtensionPoint(FactoryExtensionPoint.class).getFactory(XMLOutputFactory.class);
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- try {
- compositeProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), new ProcessorContext(getExtensionRegistry()));
- } catch(Exception e) {
- throw new RuntimeException(e);
- }
-
- String result = bos.toString();
-
- // write out and nested composites
- for (Component component : composite.getComponents()) {
- if (component.getImplementation() instanceof Composite) {
- result += "\n<!-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -->\n";
- result += writeComposite((Composite)component.getImplementation(), compositeProcessor);
- }
- }
-
- return result;
+ DeployedComposite dc = Helper.createDeployedComposite(c, ic, dependentContributions, getDomainName(), nodeFactory);
+ ic.getDeployedComposites().add(dc);
}
- protected URL getLocationAsURL(String location) throws MalformedURLException {
+ protected URL getLocationAsURL(String location) throws ContributionReadException {
URI uri = IOHelper.createURI(location);
if (uri.getScheme() == null) {
uri = new File(location).toURI();
}
- URL url = uri.toURL();
- return url;
+ try {
+ return uri.toURL();
+ } catch (MalformedURLException e) {
+ throw new ContributionReadException(e);
+ }
}
protected void analyzeProblems(Monitor monitor) throws Throwable {
diff --git a/sca-java-2.x/contrib/modules/section10/src/test/java/org/apache/tuscany/sca/something/Section102TestCase.java b/sca-java-2.x/contrib/modules/section10/src/test/java/org/apache/tuscany/sca/something/Section102TestCase.java
new file mode 100644
index 0000000000..15176b5d83
--- /dev/null
+++ b/sca-java-2.x/contrib/modules/section10/src/test/java/org/apache/tuscany/sca/something/Section102TestCase.java
@@ -0,0 +1,168 @@
+/*
+ * 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.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.MemoryPoolMXBean;
+import java.net.MalformedURLException;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.runtime.ActivationException;
+import org.junit.Test;
+import org.oasisopen.sca.NoSuchDomainException;
+import org.oasisopen.sca.NoSuchServiceException;
+
+public class Section102TestCase {
+
+// @Test
+// public void testInstallDeployable() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, MalformedURLException {
+// Section10 section10 = Section10Factory.createSection10();
+// section10.installContribution("src/test/resources/sample-helloworld.jar");
+//
+//// Helloworld helloworldService = section10.getService(Helloworld.class, "HelloworldComponent");
+//// Assert.assertEquals("Hello petra", helloworldService.sayHello("petra"));
+// }
+//
+// @Test
+// public void testInstallWithDependent() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, MalformedURLException {
+// Section10 section10 = Section10Factory.createSection10();
+// section10.installContribution("/Tuscany/svn/2.x-trunk/itest/T3558/src/test/resources/sample-store.jar");
+// section10.installContribution("/Tuscany/svn/2.x-trunk/itest/T3558/src/test/resources/sample-store-client.jar");
+//
+//// Helloworld helloworldService = section10.getService(Helloworld.class, "HelloworldComponent");
+//// Assert.assertEquals("Hello petra", helloworldService.sayHello("petra"));
+// }
+
+// Doesnt work yet as addToDomainLevelComposite doesn't work
+// @Test
+ public void testInstallNoDeployable() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, MalformedURLException, ActivationException {
+ Section10 section10 = Section10Factory.createSection10();
+ String contributionURI = section10.installContribution("src/test/resources/sample-helloworld-nodeployable.jar");
+
+// SCAClientFactory scaClientFactory = section10.getSCAClientFactory();
+// try {
+// scaClientFactory.getService(Helloworld.class, "HelloworldComponent");
+// Assert.fail();
+// } catch (NoSuchServiceException e) {
+// // expected as there is no deployables
+// }
+
+ section10.addToDomainLevelComposite(contributionURI + "/helloworld.composite");
+// Helloworld helloworldService = scaClientFactory.getService(Helloworld.class, "HelloworldComponent");
+// Assert.assertEquals("Hello petra", helloworldService.sayHello("petra"));
+ }
+
+// @Test
+ public void testGetInstalledContributions() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, MalformedURLException, ActivationException {
+ Section10 section10 = Section10Factory.createSection10();
+ section10.installContribution("foo", "src/test/resources/sample-helloworld-nodeployable.jar");
+ List<String> ics = section10.getInstalledContributions();
+ Assert.assertEquals(1, ics.size());
+ Assert.assertEquals("foo", ics.get(0));
+ }
+
+// @Test
+ public void testGetDeployedCompostes() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, MalformedURLException, ActivationException {
+ Section10 section10 = Section10Factory.createSection10();
+ section10.installContribution("foo", "src/test/resources/sample-helloworld.jar");
+ List<String> dcs = section10.getDeployedCompostes("foo");
+ Assert.assertEquals(1, dcs.size());
+ Assert.assertEquals("foo/helloworld.composite", dcs.get(0));
+ }
+
+ // @Test
+ public void testRemoveComposte() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, MalformedURLException, ActivationException {
+ Section10 section10 = Section10Factory.createSection10();
+ section10.installContribution("foo", "src/test/resources/sample-helloworld.jar");
+ section10.removeFromDomainLevelComposite("foo/helloworld.composite");
+ List<String> dcs = section10.getDeployedCompostes("foo");
+ Assert.assertEquals(0, dcs.size());
+ }
+
+ @Test
+ public void testLots() throws NoSuchServiceException, ContributionReadException, MalformedURLException, ActivationException, InterruptedException {
+ Section10 section10 = Section10Factory.createSection10();
+ for (int i=0; i<40000; i++) {
+ String uri = section10.installContribution("src/test/resources/sample-helloworld.jar");
+ section10.removeContribution(uri);
+ }
+ Thread.sleep(100000);
+ dumpMemoryInfo();
+ section10.shutdown();
+ }
+ public static void main(String[] args) throws ContributionReadException, MalformedURLException, NoSuchServiceException, ActivationException, InterruptedException {
+ new Section102TestCase().testLots();
+ }
+
+ public static void dumpMemoryInfo()
+ {
+ try
+ {
+ System.out.println( "\nDUMPING MEMORY INFO\n" );
+ // Read MemoryMXBean
+ MemoryMXBean memorymbean = ManagementFactory.getMemoryMXBean();
+ System.out.println( "Heap Memory Usage: " + memorymbean.getHeapMemoryUsage() );
+ System.out.println( "Non-Heap Memory Usage: " + memorymbean.getNonHeapMemoryUsage() );
+
+ // Read Garbage Collection information
+ List<GarbageCollectorMXBean> gcmbeans = ManagementFactory.getGarbageCollectorMXBeans();
+ for( GarbageCollectorMXBean gcmbean : gcmbeans )
+ {
+ System.out.println( "\nName: " + gcmbean.getName() );
+ System.out.println( "Collection count: " + gcmbean.getCollectionCount() );
+ System.out.println( "Collection time: " + gcmbean.getCollectionTime() );
+ System.out.println( "Memory Pools: " );
+ String[] memoryPoolNames = gcmbean.getMemoryPoolNames();
+ for( int i=0; i<memoryPoolNames.length; i++ )
+ {
+ System.out.println( "\t" + memoryPoolNames[ i ] );
+ }
+ }
+
+ // Read Memory Pool Information
+ System.out.println( "Memory Pools Info" );
+ List<MemoryPoolMXBean> mempoolsmbeans = ManagementFactory.getMemoryPoolMXBeans();
+ for( MemoryPoolMXBean mempoolmbean : mempoolsmbeans )
+ {
+ System.out.println( "\nName: " + mempoolmbean.getName() );
+ System.out.println( "Usage: " + mempoolmbean.getUsage() );
+ System.out.println( "Collection Usage: " + mempoolmbean.getCollectionUsage() );
+ System.out.println( "Peak Usage: " + mempoolmbean.getPeakUsage() );
+ System.out.println( "Type: " + mempoolmbean.getType() );
+ System.out.println( "Memory Manager Names: " ) ;
+ String[] memManagerNames = mempoolmbean.getMemoryManagerNames();
+ for( int i=0; i<memManagerNames.length; i++ )
+ {
+ System.out.println( "\t" + memManagerNames[ i ] );
+ }
+ System.out.println( "\n" );
+ }
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/sca-java-2.x/contrib/modules/section10/src/test/java/org/apache/tuscany/sca/something/Section10TestCase.java b/sca-java-2.x/contrib/modules/section10/src/test/java/org/apache/tuscany/sca/something/Section10TestCase.java
index 76bc7c066d..4fee3a07a4 100644
--- a/sca-java-2.x/contrib/modules/section10/src/test/java/org/apache/tuscany/sca/something/Section10TestCase.java
+++ b/sca-java-2.x/contrib/modules/section10/src/test/java/org/apache/tuscany/sca/something/Section10TestCase.java
@@ -19,36 +19,39 @@
package org.apache.tuscany.sca.something;
import java.net.MalformedURLException;
+import java.util.List;
+
+import junit.framework.Assert;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.runtime.ActivationException;
import org.junit.Test;
import org.oasisopen.sca.NoSuchDomainException;
import org.oasisopen.sca.NoSuchServiceException;
public class Section10TestCase {
-// @Test
-// public void testInstallDeployable() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, MalformedURLException {
-// Section10 section10 = Section10Factory.createSection10();
-// section10.installContribution("src/test/resources/sample-helloworld.jar");
-//
-//// Helloworld helloworldService = section10.getService(Helloworld.class, "HelloworldComponent");
-//// Assert.assertEquals("Hello petra", helloworldService.sayHello("petra"));
-// }
-//
-// @Test
-// public void testInstallWithDependent() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, MalformedURLException {
-// Section10 section10 = Section10Factory.createSection10();
-// section10.installContribution("/Tuscany/svn/2.x-trunk/itest/T3558/src/test/resources/sample-store.jar");
-// section10.installContribution("/Tuscany/svn/2.x-trunk/itest/T3558/src/test/resources/sample-store-client.jar");
-//
-//// Helloworld helloworldService = section10.getService(Helloworld.class, "HelloworldComponent");
-//// Assert.assertEquals("Hello petra", helloworldService.sayHello("petra"));
-// }
+ @Test
+ public void testInstallDeployable() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException {
+ Section10 section10 = Section10Factory.createSection10();
+ section10.installContribution("src/test/resources/sample-helloworld.jar");
+
+// Helloworld helloworldService = section10.getService(Helloworld.class, "HelloworldComponent");
+// Assert.assertEquals("Hello petra", helloworldService.sayHello("petra"));
+ }
+
+ @Test
+ public void testInstallWithDependent() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException {
+ Section10 section10 = Section10Factory.createSection10();
+ section10.installContribution("/Tuscany/svn/2.x-trunk/itest/T3558/src/test/resources/sample-store.jar");
+ section10.installContribution("/Tuscany/svn/2.x-trunk/itest/T3558/src/test/resources/sample-store-client.jar");
+
+// Helloworld helloworldService = section10.getService(Helloworld.class, "HelloworldComponent");
+// Assert.assertEquals("Hello petra", helloworldService.sayHello("petra"));
+ }
-// Doesnt work yet as addToDomainLevelComposite doesn't work
@Test
- public void testInstallNoDeployable() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, MalformedURLException {
+ public void testInstallNoDeployable() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException {
Section10 section10 = Section10Factory.createSection10();
String contributionURI = section10.installContribution("src/test/resources/sample-helloworld-nodeployable.jar");
@@ -65,4 +68,31 @@ public class Section10TestCase {
// Assert.assertEquals("Hello petra", helloworldService.sayHello("petra"));
}
+ @Test
+ public void testGetInstalledContributions() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException {
+ Section10 section10 = Section10Factory.createSection10();
+ section10.installContribution("foo", "src/test/resources/sample-helloworld-nodeployable.jar");
+ List<String> ics = section10.getInstalledContributions();
+ Assert.assertEquals(1, ics.size());
+ Assert.assertEquals("foo", ics.get(0));
+ }
+
+ @Test
+ public void testGetDeployedCompostes() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, MalformedURLException, ActivationException {
+ Section10 section10 = Section10Factory.createSection10();
+ section10.installContribution("foo", "src/test/resources/sample-helloworld.jar");
+ List<String> dcs = section10.getDeployedCompostes("foo");
+ Assert.assertEquals(1, dcs.size());
+ Assert.assertEquals("foo/helloworld.composite", dcs.get(0));
+ }
+
+ // @Test
+ public void testRemoveComposte() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, MalformedURLException, ActivationException {
+ Section10 section10 = Section10Factory.createSection10();
+ section10.installContribution("foo", "src/test/resources/sample-helloworld.jar");
+ section10.removeFromDomainLevelComposite("foo/helloworld.composite");
+ List<String> dcs = section10.getDeployedCompostes("foo");
+ Assert.assertEquals(0, dcs.size());
+ }
+
}