Return-Path: Delivered-To: apmail-tuscany-commits-archive@www.apache.org Received: (qmail 78117 invoked from network); 21 May 2010 14:50:22 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 21 May 2010 14:50:22 -0000 Received: (qmail 31646 invoked by uid 500); 21 May 2010 14:50:22 -0000 Delivered-To: apmail-tuscany-commits-archive@tuscany.apache.org Received: (qmail 31624 invoked by uid 500); 21 May 2010 14:50:22 -0000 Mailing-List: contact commits-help@tuscany.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tuscany.apache.org Delivered-To: mailing list commits@tuscany.apache.org Received: (qmail 31617 invoked by uid 99); 21 May 2010 14:50:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 May 2010 14:50:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 May 2010 14:50:18 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 25BBF23888E4; Fri, 21 May 2010 14:49:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r947031 - in /tuscany/sca-java-2.x/contrib/modules/section10/src: main/java/org/apache/tuscany/sca/something/impl/ test/java/org/apache/tuscany/sca/something/ Date: Fri, 21 May 2010 14:49:56 -0000 To: commits@tuscany.apache.org From: antelder@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100521144956.25BBF23888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: antelder Date: Fri May 21 14:49:55 2010 New Revision: 947031 URL: http://svn.apache.org/viewvc?rev=947031&view=rev Log: Update for Section10 interface updates and start to try to get it to work more as the spec describes so without nodes and to have installed contributions and deploying/undeploying composites. (The tests getService methods no longer work as the scaclient factory impl expects Nodes to have been created) Added: tuscany/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/InstalledContribution.java Modified: tuscany/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java tuscany/sca-java-2.x/contrib/modules/section10/src/test/java/org/apache/tuscany/sca/something/Section10TestCase.java Added: tuscany/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/InstalledContribution.java URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/InstalledContribution.java?rev=947031&view=auto ============================================================================== --- tuscany/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/InstalledContribution.java (added) +++ tuscany/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/InstalledContribution.java Fri May 21 14:49:55 2010 @@ -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.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; + +public class InstalledContribution { + private String uri; + private String url; + private Contribution contribution; + private List deployedComposites = new ArrayList(); + + public InstalledContribution(String uri, String url, Contribution contribution) { + this.uri = uri; + this.url = url; + this.contribution = contribution; + } + public Contribution getContribution() { + return contribution; + } + public void setContribution(Contribution contribution) { + this.contribution = contribution; + } + public String getURI() { + return uri; + } + public String getURL() { + return url; + } + public List getDeployedComposites() { + return deployedComposites; + } + + // TODO: there likely needs to be ways to get at depending/dependent contributions + +} Modified: tuscany/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java?rev=947031&r1=947030&r2=947031&view=diff ============================================================================== --- tuscany/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java (original) +++ tuscany/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java Fri May 21 14:49:55 2010 @@ -19,36 +19,99 @@ package org.apache.tuscany.sca.something.impl; +import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.Reader; +import java.net.MalformedURLException; import java.net.URI; -import java.util.Collections; +import java.net.URL; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; import javax.xml.namespace.QName; +import javax.xml.stream.XMLOutputFactory; -import org.apache.tuscany.sca.node.Node; +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.node.impl.NodeImpl; +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.something.Section10; import org.oasisopen.sca.NoSuchDomainException; +import org.oasisopen.sca.NoSuchServiceException; +import org.oasisopen.sca.ServiceRuntimeException; import org.oasisopen.sca.client.SCAClientFactory; -import org.w3c.dom.Document; public class Section10Impl implements Section10 { - private NodeFactory nodeFactory; - private Map installedContributions = new HashMap(); + protected NodeFactoryImpl nodeFactory; + protected Map installedContributions = new HashMap(); public Section10Impl(Properties config) { - this.nodeFactory = NodeFactory.newInstance(config); + this.nodeFactory = (NodeFactoryImpl)NodeFactory.newInstance(config); ((NodeFactoryImpl)nodeFactory).start(); } + public String installContribution(String contributionURL) throws ContributionReadException, MalformedURLException { + installContribution(contributionURL, contributionURL, null, true); + return contributionURL; + } + + public String installContribution(String contributionURL, boolean autoDeploy) throws ContributionReadException, MalformedURLException { + installContribution(contributionURL, contributionURL, null, autoDeploy); + return contributionURL; + } + + public void installContribution(String uri, String contributionURL) throws ContributionReadException, MalformedURLException { + installContribution(uri, contributionURL, null, true); + } + + public void installContribution(String uri, String contributionURL, List dependentContributionURIs) throws ContributionReadException, MalformedURLException { + installContribution(uri, contributionURL, dependentContributionURIs, true); + } + + public void installContribution(String uri, String contributionURL, List dependentContributionURIs, boolean autoDeploy) throws ContributionReadException, MalformedURLException { + Deployer deployer = nodeFactory.getDeployer(); + Monitor monitor = deployer.createMonitor(); + URL url = getLocationAsURL(contributionURL); + Contribution contribution = deployer.loadContribution(URI.create(uri), url, monitor); + InstalledContribution ic = new InstalledContribution(uri, url.toString(), contribution); + 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); + } + } + } + } + public String addDeploymentComposite(String contriubutionURI, String compositeXML) { // TODO Auto-generated method stub return null; @@ -60,132 +123,221 @@ public class Section10Impl implements Se } public void addToDomainLevelComposite(String compositeURI) { - String contributionURI = getContributionUriFromArtifactUri(compositeURI); - String artifactURI = compositeURI.substring(contributionURI.length()+1); - // TODO: now what? there doesn't appear to be any way yet to do this with the exsiting Node API + String contributionURI = getContributionUriForArtifact(compositeURI); + InstalledContribution ic = installedContributions.get(contributionURI); + if (ic == null) { + throw new IllegalArgumentException("Contribution not installed: " + contributionURI); + } + String relativeURI = compositeURI.substring(contributionURI.length()+1); + 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); + } + return; + } + } + throw new IllegalArgumentException("composite not found: " + compositeURI); } - protected String getContributionUriFromArtifactUri(String artifactURI) { - String contributionURI = null; - for (String uri : installedContributions.keySet()) { - if (artifactURI.startsWith(uri)) { - contributionURI = uri; - break; + public void removeFromDomainLevelComposite(String compositeURI) { + 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); + return; } } - if (contributionURI == null) { - throw new IllegalArgumentException("no contribution found for: " + artifactURI); - } - return contributionURI; + throw new IllegalStateException("composite not deployed: " + compositeURI); } - public void deployContribution(String contributionURI) { + public Composite getDomainLevelComposite() { // TODO Auto-generated method stub + return null; + } + + public String getDomainLevelCompositeAsString() { + StAXArtifactProcessorExtensionPoint xmlProcessors = getExtensionRegistry().getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + StAXArtifactProcessor compositeProcessor = xmlProcessors.getProcessor(Composite.class); + return writeComposite(getDomainLevelComposite(), compositeProcessor); } - public Document getDomainLevelComposite() { + public Object getQNameDefinition(String contributionURI, QName definition, QName symbolSpace) { // TODO Auto-generated method stub return null; } - public String getDomainLevelCompositeAsString() { + public void removeContribution(String contributionURI) { + // 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); + } + } + + public void updateContribution(String uri, String contributionURL) { + // TODO Auto-generated method stub + // is this just removeContribution/installContribution? + } + + public String updateDeploymentComposite(String uri, String compositeXML) { // TODO Auto-generated method stub + // is this removeFromDomainLevelComposite/addDeploymentComposite return null; } - public Object getQNameDefinition(String contributionURI, QName definition, QName symbolSpace) { + public String updateDeploymentComposite(String uri, Reader compositeXML) { // TODO Auto-generated method stub + // is this removeFromDomainLevelComposite/addDeploymentComposite return null; } - public SCAClientFactory getSCAClientFactory() { + public void shutdown() { + nodeFactory.destroy(); + } + + public T getService(Class interfaze, String serviceURI) throws NoSuchServiceException { try { - return SCAClientFactory.newInstance(URI.create(getDomainName())); + return SCAClientFactory.newInstance(URI.create(getDomainName())).getService(interfaze, serviceURI); } catch (NoSuchDomainException e) { + // shouldn't ever happen as we know this is the domain so it must exist throw new IllegalStateException(e); } } - - private String getDomainName() { + + public String getDomainName() { // TODO Auto-generated method stub return "default"; } - public void installContribution(String uri, String contributionURL, List dependentContributionURIs) { - if (dependentContributionURIs == null) { - dependentContributionURIs = Collections.emptyList(); - } - String[] cs = new String[dependentContributionURIs.size()+1]; - cs[0] = contributionURL; - for (int i=1; i allContributions = new ArrayList(); + for (InstalledContribution ics : installedContributions.values()) { + allContributions.add(ics.getContribution()); + } + + List contributions = new ArrayList(); + contributions.add(ic.getContribution()); + contributions.get(0).getDeployables().clear(); + contributions.get(0).getDeployables().add(c); + domainComposite = nodeFactory.getDeployer().build(contributions, allContributions, new HashMap>(), monitor); + analyzeProblems(monitor); + + compositeContext = new CompositeContext(getExtensionRegistry(), + endpointRegistry, + domainComposite, + getDomainName(), + "whatIsThisURIfor", + nodeFactory.getDeployer().getSystemDefinitions()); + + CompositeContext.setThreadCompositeContext(compositeContext); + } finally { + monitorFactory.setContextMonitor(tcm); + } + compositeActivator.activate(compositeContext, domainComposite); + compositeActivator.start(compositeContext, domainComposite); + + ic.getDeployedComposites().add(c); } - public void stopComponent(String componentURI) { + protected void undeployComposite(Composite c, InstalledContribution ic) { + ic.getDeployedComposites().remove(c); // TODO Auto-generated method stub - } - public void undeployContribution(String contributionURI) { - // TODO Auto-generated method stub - + protected ExtensionPointRegistry getExtensionRegistry() { + ExtensionPointRegistry reg = nodeFactory.getExtensionPointRegistry(); + return reg; } - public void updateContribution(String uri, String contributionURL) { - // TODO Auto-generated method stub + protected String writeComposite(Composite composite, StAXArtifactProcessor 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\n"; + result += writeComposite((Composite)component.getImplementation(), compositeProcessor); + } + } + return result; } - public String updateDeploymentComposite(String uri, String compositeXML) { - // TODO Auto-generated method stub - return null; + protected URL getLocationAsURL(String location) throws MalformedURLException { + URI uri = IOHelper.createURI(location); + if (uri.getScheme() == null) { + uri = new File(location).toURI(); + } + URL url = uri.toURL(); + return url; } - - public String updateDeploymentComposite(String uri, Reader compositeXML) { - // TODO Auto-generated method stub - return null; + + 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(); + } } - } Modified: tuscany/sca-java-2.x/contrib/modules/section10/src/test/java/org/apache/tuscany/sca/something/Section10TestCase.java URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/contrib/modules/section10/src/test/java/org/apache/tuscany/sca/something/Section10TestCase.java?rev=947031&r1=947030&r2=947031&view=diff ============================================================================== --- tuscany/sca-java-2.x/contrib/modules/section10/src/test/java/org/apache/tuscany/sca/something/Section10TestCase.java (original) +++ tuscany/sca-java-2.x/contrib/modules/section10/src/test/java/org/apache/tuscany/sca/something/Section10TestCase.java Fri May 21 14:49:55 2010 @@ -18,44 +18,40 @@ */ package org.apache.tuscany.sca.something; -import junit.framework.Assert; +import java.net.MalformedURLException; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.junit.Test; import org.oasisopen.sca.NoSuchDomainException; import org.oasisopen.sca.NoSuchServiceException; -import org.oasisopen.sca.client.SCAClientFactory; - -import sample.Helloworld; public class Section10TestCase { - @Test - public void testInstallDeployable() throws NoSuchServiceException, NoSuchDomainException { - Section10 section10 = Section10Factory.createSection10(); - section10.installContribution("src/test/resources/sample-helloworld.jar"); - - SCAClientFactory scaClientFactory = section10.getSCAClientFactory(); - Helloworld helloworldService = scaClientFactory.getService(Helloworld.class, "HelloworldComponent"); - Assert.assertEquals("Hello petra", helloworldService.sayHello("petra")); - } +// @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 testInstallWithDependent() throws NoSuchServiceException, NoSuchDomainException { + public void testInstallNoDeployable() 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"); - - SCAClientFactory scaClientFactory = section10.getSCAClientFactory(); - Helloworld helloworldService = scaClientFactory.getService(Helloworld.class, "HelloworldComponent"); - Assert.assertEquals("Hello petra", helloworldService.sayHello("petra")); - } + String contributionURI = section10.installContribution("src/test/resources/sample-helloworld-nodeployable.jar"); -// Doesnt work yet as addToDomainLevelComposite doesn't work -// @Test -// public void testInstallNoDeployable() throws NoSuchServiceException, NoSuchDomainException { -// 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"); @@ -63,10 +59,10 @@ public class Section10TestCase { // } catch (NoSuchServiceException e) { // // expected as there is no deployables // } -// -// section10.addToDomainLevelComposite(contributionURI + "/helloworld.composite"); + + section10.addToDomainLevelComposite(contributionURI + "/helloworld.composite"); // Helloworld helloworldService = scaClientFactory.getService(Helloworld.class, "HelloworldComponent"); // Assert.assertEquals("Hello petra", helloworldService.sayHello("petra")); -// } + } }