diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2012-06-18 10:16:09 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2012-06-18 10:16:09 +0000 |
commit | 745ef23338dfce805135fc98845ae070342fe990 (patch) | |
tree | 14a47fa651aa36b135bcc070dfab34ae2e2b85b6 /sca-java-2.x/tags/2.0-RC2/modules/node-impl | |
parent | 2fc08b2a6dfd93293a81f0dc298014dc37c8c00f (diff) |
Tag for 2.0 RC2
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1351268 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/tags/2.0-RC2/modules/node-impl')
29 files changed, 2873 insertions, 0 deletions
diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/LICENSE b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + + + diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/META-INF/MANIFEST.MF b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..0f8eebd936 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/META-INF/MANIFEST.MF @@ -0,0 +1,43 @@ +Manifest-Version: 1.0
+Export-Package: org.apache.tuscany.sca.node.impl;version="2.0.0"
+SCA-Version: 1.1
+Bundle-Name: Apache Tuscany SCA Node Implementation
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0.0
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany SCA Node Implementation
+Import-Package: javax.management;resolution:=optional,
+ javax.xml.namespace,
+ javax.xml.stream,
+ org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.assembly.builder;version="2.0.0",
+ org.apache.tuscany.sca.common.java.io;version="2.0.0",
+ org.apache.tuscany.sca.common.xml.stax;version="2.0.0",
+ org.apache.tuscany.sca.context;version="2.0.0",
+ org.apache.tuscany.sca.contribution;version="2.0.0",
+ org.apache.tuscany.sca.contribution.processor;version="2.0.0",
+ org.apache.tuscany.sca.contribution.resolver;version="2.0.0",
+ org.apache.tuscany.sca.core;version="2.0.0",
+ org.apache.tuscany.sca.core.assembly;version="2.0.0",
+ org.apache.tuscany.sca.core.invocation;version="2.0.0",
+ org.apache.tuscany.sca.definitions;version="2.0.0",
+ org.apache.tuscany.sca.definitions.util;version="2.0.0",
+ org.apache.tuscany.sca.definitions.xml;version="2.0.0",
+ org.apache.tuscany.sca.deployment;version="2.0.0",
+ org.apache.tuscany.sca.extensibility;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.java;version="2.0.0",
+ org.apache.tuscany.sca.management;version="2.0.0",
+ org.apache.tuscany.sca.monitor;version="2.0.0",
+ org.apache.tuscany.sca.node;version="2.0.0",
+ org.apache.tuscany.sca.node.configuration;version="2.0.0",
+ org.apache.tuscany.sca.node.extensibility,
+ org.apache.tuscany.sca.node.impl;version="2.0.0",
+ org.apache.tuscany.sca.runtime;version="2.0.0",
+ org.apache.tuscany.sca.work;version="2.0.0",
+ org.oasisopen.sca;version="2.0.0",
+ org.oasisopen.sca.annotation;version="2.0.0";resolution:=optional
+Bundle-SymbolicName: org.apache.tuscany.sca.node.impl
+Bundle-DocURL: http://www.apache.org/
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/NOTICE b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/NOTICE new file mode 100644 index 0000000000..b01801136b --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2012 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/pom.xml b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/pom.xml new file mode 100644 index 0000000000..0dd85b3d9e --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/pom.xml @@ -0,0 +1,115 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<project> + + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-modules</artifactId> + <version>2.0</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>tuscany-node-impl</artifactId> + <name>Apache Tuscany SCA Node Implementation</name> + + <dependencies> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly</artifactId> + <version>2.0</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-contribution</artifactId> + <version>2.0</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-node-api</artifactId> + <version>2.0</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-core</artifactId> + <version>2.0</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly-xml</artifactId> + <version>2.0</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-deployment</artifactId> + <version>2.0</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-builder</artifactId> + <version>2.0</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-sca-runtime</artifactId> + <version>2.0</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-core-databinding</artifactId> + <version>2.0</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly-xsd</artifactId> + <version>2.0</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-java-runtime</artifactId> + <version>2.0</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-ws-wsdlgen</artifactId> + <version>2.0</version> + <scope>test</scope> + </dependency> + + </dependencies> + +</project> diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationATOMProcessor.java b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationATOMProcessor.java new file mode 100644 index 0000000000..d11eb317cf --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationATOMProcessor.java @@ -0,0 +1,160 @@ +/* + * 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.node.configuration.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.node.configuration.ContributionConfiguration; +import org.apache.tuscany.sca.node.configuration.NodeConfiguration; +import org.apache.tuscany.sca.node.configuration.NodeConfigurationFactory; + +/** + * Implements a StAX artifact processor for configured node implementations. + * + * @version $Rev$ $Date$ + */ +public class NodeConfigurationATOMProcessor extends BaseStAXArtifactProcessor implements + StAXArtifactProcessor<NodeConfiguration> { + + private static final String ATOM_NS = "http://www.w3.org/2005/Atom"; + private static final QName FEED_QNAME = new QName(ATOM_NS, "feed"); + private static final QName ENTRY_QNAME = new QName(ATOM_NS, "entry"); + private static final QName ID_QNAME = new QName(ATOM_NS, "id"); + private static final QName LINK_QNAME = new QName(ATOM_NS, "link"); + private static final QName CONTENT_QNAME = new QName(ATOM_NS, "content"); + private static final String HREF = "href"; + + private NodeConfigurationFactory factory; + + public NodeConfigurationATOMProcessor(FactoryExtensionPoint modelFactories) { + this.factory = modelFactories.getFactory(NodeConfigurationFactory.class); + } + + public QName getArtifactType() { + return null; + } + + public Class<NodeConfiguration> getModelType() { + // Returns the type of model processed by this processor + return NodeConfiguration.class; + } + + public NodeConfiguration read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + + NodeConfiguration config = factory.createNodeConfiguration(); + + // Read a feed containing links to the composite and the contributions assigned to + // the node + ContributionConfiguration contribution = null; + boolean id = false; + QName name = null; + + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + + case START_ELEMENT: + name = reader.getName(); + + if (ENTRY_QNAME.equals(name)) { + + // Read an <entry> + contribution = factory.createContributionConfiguration(); + } else if (ID_QNAME.equals(name)) { + + // Read an <id> + id = true; + + } else if (LINK_QNAME.equals(name)) { + + // Read a <link> + String href = getString(reader, HREF); + + if (contribution != null) { + contribution.setLocation(href); + } + } else if (CONTENT_QNAME.equals(name)) { + // Read a <content> + } else if (FEED_QNAME.equals(name)) { + // Read a <feed> + } + break; + + case XMLStreamConstants.CHARACTERS: + + // Read characters inside an <id> element + if (id) { + if (contribution != null) { + contribution.setURI(reader.getText()); + } + } + break; + + case END_ELEMENT: + name = reader.getName(); + + // Clear current state when reading reaching end element + if (ENTRY_QNAME.equals(name)) { + if (contribution != null) { + config.getContributions().add(contribution); + } + + contribution = null; + + } else if (ID_QNAME.equals(name)) { + id = false; + + } else if (FEED_QNAME.equals(name)) { + + // We've reached the end of the feed + return config; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + return config; + } + + public void resolve(NodeConfiguration implementation, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + } + + public void write(NodeConfiguration implementation, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, + XMLStreamException { + } +} diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessor.java b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessor.java new file mode 100644 index 0000000000..48d76225fb --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessor.java @@ -0,0 +1,258 @@ +/* + * 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.node.configuration.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; + +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Arrays; +import java.util.StringTokenizer; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.common.xml.stax.StAXHelper; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.node.configuration.BindingConfiguration; +import org.apache.tuscany.sca.node.configuration.ContributionConfiguration; +import org.apache.tuscany.sca.node.configuration.DeploymentComposite; +import org.apache.tuscany.sca.node.configuration.NodeConfiguration; +import org.apache.tuscany.sca.node.configuration.NodeConfigurationFactory; + +/** + * Implements a StAX artifact processor for node implementations. + * + * @version $Rev$ $Date$ + */ +public class NodeConfigurationProcessor extends BaseStAXArtifactProcessor implements + StAXArtifactProcessor<NodeConfiguration> { + private static final String SCA11_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; + private static final QName NODE = new QName(SCA11_TUSCANY_NS, "node"); + private static final QName CONTRIBUTION = new QName(SCA11_TUSCANY_NS, "contribution"); + private static final QName BINDING = new QName(SCA11_TUSCANY_NS, "binding"); + private static final QName BASE_URI = new QName(SCA11_TUSCANY_NS, "baseURI"); + private static final QName DEPLOYMENT_COMPOSITE = new QName(SCA11_TUSCANY_NS, "deploymentComposite"); + + private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200912"; + private static final QName COMPOSITE = new QName(SCA11_NS, "composite"); + + private StAXArtifactProcessor processor; + private NodeConfigurationFactory nodeConfigurationFactory; + private StAXHelper helper; + + public NodeConfigurationProcessor(ExtensionPointRegistry registry, + StAXArtifactProcessor processor) { + FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); + this.nodeConfigurationFactory = modelFactories.getFactory(NodeConfigurationFactory.class); + this.processor = processor; + this.helper = StAXHelper.getInstance(registry); + } + + public QName getArtifactType() { + // Returns the QName of the XML element processed by this processor + return NODE; + } + + public Class<NodeConfiguration> getModelType() { + // Returns the type of model processed by this processor + return NodeConfiguration.class; + } + + public NodeConfiguration read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + + NodeConfiguration node = null; + ContributionConfiguration contribution = null; + DeploymentComposite composite = null; + BindingConfiguration binding = null; + + // Skip to end element + while (true) { + int event = reader.getEventType(); + switch (event) { + case XMLStreamConstants.START_ELEMENT: + QName name = reader.getName(); + if (NODE.equals(name)) { + node = nodeConfigurationFactory.createNodeConfiguration(); + node.setURI(reader.getAttributeValue(null, "uri")); + node.setDomainURI(reader.getAttributeValue(null, "domain")); + node.setDomainRegistryURI(reader.getAttributeValue(null, "domainRegistry")); + } else if (CONTRIBUTION.equals(name)) { + contribution = nodeConfigurationFactory.createContributionConfiguration(); + contribution.setURI(reader.getAttributeValue(null, "uri")); + contribution.setLocation(reader.getAttributeValue(null, "location")); + contribution.setMetaDataURL(reader.getAttributeValue(null, "metaDataURL")); + String startDeployables = reader.getAttributeValue(null, "startDeployables"); + if (startDeployables != null) { + contribution.setStartDeployables(Boolean.parseBoolean(startDeployables)); + } + String dependentURIs = reader.getAttributeValue(null, "dependentURIs"); + if (dependentURIs != null) { + contribution.setDependentContributionURIs(Arrays.asList(dependentURIs.split(","))); + } + node.getContributions().add(contribution); + } else if (BINDING.equals(name)) { + binding = nodeConfigurationFactory.createBindingConfiguration(); + binding.setBindingType(getQName(reader, "name")); + String baseURIs = reader.getAttributeValue(null, "baseURIs"); + if (baseURIs != null) { + StringTokenizer tokenizer = new StringTokenizer(baseURIs); + while (tokenizer.hasMoreTokens()) { + binding.getBaseURIs().add(tokenizer.nextToken()); + } + } + node.getBindings().add(binding); + } else if (DEPLOYMENT_COMPOSITE.equals(name)) { + composite = nodeConfigurationFactory.createDeploymentComposite(); + composite.setLocation(reader.getAttributeValue(null, "location")); + if (contribution != null) { + contribution.getDeploymentComposites().add(composite); + } + } else if(BASE_URI.equals(name)) { + // We also support <baseURI> element + String baseURI = reader.getElementText(); + if (baseURI != null && binding != null) { + baseURI = baseURI.trim(); + binding.addBaseURI(baseURI); + } + // getElementText() moves the event to END_ELEMENT + continue; + } else if (COMPOSITE.equals(name)) { + /* + Object model = processor.read(reader); + if (model instanceof Composite) { + // FIXME: We need to capture the text here + // composite.setComposite((Composite)model); + } + */ + StringWriter sw = new StringWriter(); + XMLStreamWriter writer = helper.createXMLStreamWriter(sw); + helper.save(reader, writer); + composite.setContent(sw.toString()); + } else { + Object ext = processor.read(reader, context); + if (ext instanceof Endpoint) { + node.getEndpointDescriptions().add((Endpoint)ext); + } else { + node.getExtensions().add(ext); + } + } + break; + + case END_ELEMENT: + name = reader.getName(); + if (NODE.equals(name)) { + return node; + } else if (CONTRIBUTION.equals(name)) { + contribution = null; + } else if (DEPLOYMENT_COMPOSITE.equals(name)) { + composite = null; + } else if (BINDING.equals(name)) { + binding = null; + } + } + if (reader.hasNext()) { + reader.next(); + } else { + break; + } + } + + return node; + } + + public void resolve(NodeConfiguration node, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + } + + public void write(NodeConfiguration node, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, + XMLStreamException { + + writeStart(writer, + NODE.getNamespaceURI(), + NODE.getLocalPart(), + new XAttr("uri", node.getURI()), + new XAttr("domainRegistry", node.getDomainRegistryURI()), + new XAttr("domain", node.getDomainURI())); + + for (ContributionConfiguration c : node.getContributions()) { + writeStart(writer, + CONTRIBUTION.getNamespaceURI(), + CONTRIBUTION.getLocalPart(), + new XAttr("uri", c.getURI()), + new XAttr("location", c.getLocation())); + for (DeploymentComposite dc : c.getDeploymentComposites()) { + writeStart(writer, + DEPLOYMENT_COMPOSITE.getNamespaceURI(), + DEPLOYMENT_COMPOSITE.getLocalPart(), + new XAttr("location", dc.getLocation()), + new XAttr("contribution", dc.getContributionURI())); + if (dc.getContent() != null) { + XMLStreamReader reader = helper.createXMLStreamReader(new StringReader(dc.getContent())); + reader.nextTag(); // Move to the first element + helper.save(reader, writer); + reader.close(); + } + writeEnd(writer); + } + writeEnd(writer); + } + + for (BindingConfiguration b : node.getBindings()) { + StringBuffer uris = new StringBuffer(); + for (String uri : b.getBaseURIs()) { + uris.append(uri).append(' '); + } + if (uris.length() > 0) { + uris.deleteCharAt(uris.length() - 1); // Remove the trailing space + } else { + uris = null; + } + String baseURIs = (uris == null) ? null : uris.toString(); + writeStart(writer, + BINDING.getNamespaceURI(), + BINDING.getLocalPart(), + new XAttr("name", b.getBindingType()), + new XAttr("baseURIs", baseURIs)); + writeEnd(writer); + } + + // FIXME: The composite processor assumes that composite is root element +// for (Endpoint o : node.getEndpointDescriptions()) { +// processor.write(o, writer, context); +// } + + for(Object o: node.getExtensions()) { + processor.write(o, writer, context); + } + + writeEnd(writer); + } +} diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/extensibility/impl/DefaultNodeActivatorExtensionPoint.java b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/extensibility/impl/DefaultNodeActivatorExtensionPoint.java new file mode 100644 index 0000000000..8226b12078 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/extensibility/impl/DefaultNodeActivatorExtensionPoint.java @@ -0,0 +1,132 @@ +/* + * 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.node.extensibility.impl; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceHelper; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.extensibility.NodeActivator; +import org.apache.tuscany.sca.node.extensibility.NodeActivatorExtensionPoint; + +public class DefaultNodeActivatorExtensionPoint implements NodeActivatorExtensionPoint { + private final static Logger logger = Logger.getLogger(DefaultNodeActivatorExtensionPoint.class.getName()); + private List<NodeActivator> activators = new ArrayList<NodeActivator>(); + private ExtensionPointRegistry registry; + private boolean loadedActivators; + + public DefaultNodeActivatorExtensionPoint(ExtensionPointRegistry registry) { + this.registry = registry; + } + + public void addNodeActivator(NodeActivator activator) { + this.activators.add(activator); + } + + @Override + public void removeNodeActivator(NodeActivator activator) { + this.activators.remove(activator); + } + + @Override + public List<NodeActivator> getNodeActivators() { + loadModuleActivators(); + return activators; + } + + @Override + public void nodeStarted(Node node) { + for(NodeActivator activator : activators) { + activator.nodeStarted(node); + } + } + + @Override + public void nodeStopped(Node node) { + for(NodeActivator activator : activators) { + activator.nodeStopped(node); + } + } + + + + /** + * Dynamically load node activators declared under META-INF/services + */ + private synchronized void loadModuleActivators() { + if (loadedActivators) + return; + + // Get the activator service declarations + Collection<ServiceDeclaration> activatorDeclarations; + try { + // Load the module activators by ranking + activatorDeclarations = registry.getServiceDiscovery().getServiceDeclarations(NodeActivator.class.getName(), true); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + // Load and instantiate module activators + for (ServiceDeclaration activatorDeclaration : activatorDeclarations) { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Loading " + activatorDeclaration.getClassName()); + } + NodeActivator activator = null; + try { + Class<NodeActivator> activatorClass = (Class<NodeActivator>)activatorDeclaration.loadClass(); + try { + activator = ServiceHelper.newInstance(activatorClass, ExtensionPointRegistry.class, registry); + } catch (NoSuchMethodException e) { + try { + activator = + ServiceHelper.newInstance(activatorClass, + new Class<?>[] {ExtensionPointRegistry.class, Map.class}, + registry, + activatorDeclaration.getAttributes()); + + } catch (NoSuchMethodException e1) { + activator = ServiceHelper.newInstance(activatorClass); + + } + } + } catch (Throwable e) { + String optional = activatorDeclaration.getAttributes().get("optional"); + if ("true".equalsIgnoreCase(optional)) { + // If the optional flag is true, just log the error + logger.log(Level.SEVERE, e.getMessage(), e); + continue; + } else { + throw new IllegalArgumentException(e); + } + } + addNodeActivator(activator); + } + + loadedActivators = true; + } +} diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java new file mode 100644 index 0000000000..a97f40e943 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java @@ -0,0 +1,504 @@ +/* + * 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.node.impl; + +import static java.lang.System.currentTimeMillis; +import static org.apache.tuscany.sca.common.java.io.IOHelper.createURI; +import static org.apache.tuscany.sca.common.java.io.IOHelper.openStream; + +import java.io.File; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; +import java.net.URI; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.common.java.io.IOHelper; +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.ValidationSchemaExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +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.core.invocation.ExtensibleProxyFactory; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.deployment.Deployer; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; +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.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.apache.tuscany.sca.node.configuration.BindingConfiguration; +import org.apache.tuscany.sca.node.configuration.ContributionConfiguration; +import org.apache.tuscany.sca.node.configuration.DefaultNodeConfigurationFactory; +import org.apache.tuscany.sca.node.configuration.DeploymentComposite; +import org.apache.tuscany.sca.node.configuration.NodeConfiguration; +import org.apache.tuscany.sca.node.configuration.NodeConfigurationFactory; +import org.apache.tuscany.sca.node.extensibility.NodeExtension; +import org.apache.tuscany.sca.runtime.DomainRegistryFactory; +import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory; +import org.apache.tuscany.sca.runtime.RuntimeProperties; +import org.apache.tuscany.sca.work.WorkScheduler; +import org.oasisopen.sca.ServiceRuntimeException; + +/** + * This class provides a node factory that can create multiple nodes that share the same + * extension point registry + */ +public class NodeFactoryImpl extends NodeFactory { + protected static final Logger logger = Logger.getLogger(NodeImpl.class.getName()); + + protected boolean inited; + protected Map<Object, Node> nodes = new ConcurrentHashMap<Object, Node>(); + + protected Deployer deployer; + protected ExtensionPointRegistry registry; + protected ProxyFactory proxyFactory; + protected MonitorFactory monitorFactory; + + /** + * Automatically destroy the factory when last node is stopped. Subclasses + * can set this flag. + */ + protected boolean autoDestroy = true; + + boolean quietLogging; + + @Override + public Node createNode(NodeConfiguration configuration) { + if (configuration.getURI() == null) { + // Make sure a unique node URI is created for the same node factory + configuration.setURI(generateNodeURI()); + } + return new NodeImpl(this, configuration); + } + + protected Node removeNode(NodeConfiguration configuration) { + Node node = nodes.remove(getNodeKey(configuration)); + if (autoDestroy && nodes.isEmpty()) { + destroy(); + } + return node; + } + + @SuppressWarnings("unchecked") + @Override + public Node createNode(List<?> contributions) { + NodeConfigurationFactory nodeConfigurationFactory = new DefaultNodeConfigurationFactory(); + return new NodeImpl(this, nodeConfigurationFactory.createNodeConfiguration(), new ArrayList<Contribution>((List<Contribution>)contributions)); + } + + protected void addNode(NodeConfiguration configuration, Node node) { + nodes.put(getNodeKey(configuration), node); + } + + @Override + public NodeConfiguration loadConfiguration(InputStream xml, URL base) { + try { + init(); + InputStreamReader reader = new InputStreamReader(xml, "UTF-8"); + ProcessorContext context = deployer.createProcessorContext(); + NodeConfiguration config = deployer.loadXMLDocument(reader, context.getMonitor()); + if (base != null && config != null) { + // Resolve the contribution location against the node.xml + for (ContributionConfiguration c : config.getContributions()) { + String location = c.getLocation(); + if (location != null) { + URL url = new URL(base, location); + url = IOHelper.normalize(url); + c.setLocation(url.toString()); + } + } + } + return config; + } catch (Throwable e) { + throw new ServiceRuntimeException(e); + } + } + + public Map<Object, Node> getNodes() { + return nodes; + } + + public List<Node> getNodesInDomain(String domainName) { + List<Node> domainNodes = new ArrayList<Node>(); + if (nodes != null) { + for (Node n : nodes.values()) { + if (domainName.equals(((NodeImpl)n).getConfiguration().getDomainURI())) { + domainNodes.add(n); + } + } + } + return domainNodes; + } + + protected Object getNodeKey(NodeConfiguration configuration) { + return new NodeKey(configuration); + } + + public synchronized void destroy() { + if (inited) { + for (Node node : nodes.values()) { + node.stop(); + } + nodes.clear(); + deployer.stop(); + registry.stop(); + super.destroy(); + inited = false; + } + } + + /** + * Analyze problems reported by the artifact processors and builders. + * + * @throws Exception + */ + private 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(); + } + } + + private boolean attachDeploymentComposite(Contribution contribution, Reader xml, String location, boolean attached, ProcessorContext context) + throws XMLStreamException, ContributionReadException { + + // Read the composite model + Composite composite = deployer.loadXMLDocument(xml, context.getMonitor()); + + // Replace the deployable composites with the deployment composites + // Clear the deployable composites if it's the first deployment composite + deployer.attachDeploymentComposite(contribution, composite, attached); + if (!attached) { + attached = true; + } + return attached; + } + + public ExtensionPointRegistry getExtensionPointRegistry() { + if (registry == null) { + // Create extension point registry + registry = createExtensionPointRegistry(); + registry.start(); + } + return registry; + } + + public synchronized void init() { + if (inited) { + return; + } + long start = currentTimeMillis(); + + getExtensionPointRegistry(); + + UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); + monitorFactory = utilities.getUtility(MonitorFactory.class); + + utilities.getUtility(RuntimeProperties.class).setProperties(properties); + quietLogging = Boolean.parseBoolean(properties.getProperty(RuntimeProperties.QUIET_LOGGING)); + + // Use the runtime-enabled assembly factory + FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = new RuntimeAssemblyFactory(registry); + modelFactories.addFactory(assemblyFactory); + + // Load the Deployer + deployer = utilities.getUtility(Deployer.class); + + // Enable schema validation only of the logger level is FINE or higher + deployer.setSchemaValidationEnabled(isSchemaValidationEnabled()); + + // Initialize the Tuscany module activators + // The module activators will be started + registry.getExtensionPoint(ModuleActivatorExtensionPoint.class); + + // Initialize runtime + + // Get proxy factory + proxyFactory = ExtensibleProxyFactory.getInstance(registry); + + utilities.getUtility(WorkScheduler.class); + + inited = true; + + if (logger.isLoggable(Level.FINE)) { + long end = currentTimeMillis(); + logger.fine("The tuscany runtime started in " + (end - start) + " ms."); + } + } + + public void start() { + init(); + DomainRegistryFactory domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(registry); + domainRegistryFactory.getEndpointRegistry(properties.getProperty("reguri"), properties.getProperty("defaultDomainName")); + } + + protected ExtensionPointRegistry createExtensionPointRegistry() { + return new DefaultExtensionPointRegistry(); + } + + protected boolean isSchemaValidationEnabled() { + String enabled = getSystemProperty(ValidationSchemaExtensionPoint.class.getName() + ".enabled"); + if (enabled == null) { + enabled = "true"; + } + boolean debug = logger.isLoggable(Level.FINE); + return "true".equals(enabled) || debug; + } + + protected Composite configureNode(NodeConfiguration configuration, List<Contribution> contributions, ProcessorContext context) + throws Throwable { + if (contributions == null) { + // Load contributions + contributions = loadContributions(configuration, context); + } + + Monitor monitor = context.getMonitor(); + Map<QName, List<String>> bindingBaseURIs = new HashMap<QName, List<String>>(); + for (BindingConfiguration config : configuration.getBindings()) { + bindingBaseURIs.put(config.getBindingType(), config.getBaseURIs()); + } + List<Contribution> allContributions = getAllContributions(configuration.getDomainURI()); + + Composite domainComposite = deployer.build(contributions, allContributions, bindingBaseURIs, monitor); + analyzeProblems(monitor); + + // postBuildEndpointReferenceMatching(domainComposite); + + return domainComposite; + } + + private List<Contribution> getAllContributions(String domainName) { + List<Contribution> contributions = new ArrayList<Contribution>(); + for (NodeFactory f : getNodeFactories()) { + for (Node node : ((NodeFactoryImpl)f).getNodesInDomain(domainName)) { + contributions.addAll(((NodeImpl)node).getContributions()); + } + } + return contributions; + } + + protected List<Contribution> loadContributions(NodeConfiguration configuration, ProcessorContext context) throws Throwable { + List<Contribution> contributions = new ArrayList<Contribution>(); + + // Load the specified contributions + for (ContributionConfiguration contrib : configuration.getContributions()) { + URI contributionURI = createURI(contrib.getURI()); + + URI uri = createURI(contrib.getLocation()); + if (uri != null && uri.getScheme() == null) { + uri = new File(contrib.getLocation()).toURI(); + } + URL contributionURL = null; + if (uri != null) { + contributionURL = uri.toURL(); + } + + // Load the contribution + logger.log(quietLogging? Level.FINE : Level.INFO, "Loading contribution: " + contributionURL); + Contribution contribution = deployer.loadContribution(contributionURI, contributionURL, context.getMonitor()); + contributions.add(contribution); + + boolean attached = false; + for (DeploymentComposite dc : contrib.getDeploymentComposites()) { + if (dc.getContent() != null) { + Reader xml = new StringReader(dc.getContent()); + attached = attachDeploymentComposite(contribution, xml, null, attached, context); + } else if (dc.getLocation() != null) { + URI dcURI = createURI(dc.getLocation()); + if (!dcURI.isAbsolute()) { + Composite composite = null; + // The location is pointing to an artifact within the contribution + for (Artifact a : contribution.getArtifacts()) { + if (dcURI.toString().equals(a.getURI())) { + composite = (Composite)a.getModel(); + if (!attached) { + contribution.getDeployables().clear(); + attached = true; + } + contribution.getDeployables().add(composite); + break; + } + } + if (composite == null) { + // Not found + throw new ServiceRuntimeException("Deployment composite " + dcURI + + " cannot be found within contribution " + + contribution.getLocation()); + } + } else { + URL url = dcURI.toURL(); + InputStream is = openStream(url); + Reader xml = new InputStreamReader(is, "UTF-8"); + attached = attachDeploymentComposite(contribution, xml, url.toString(), attached, context); + } + } + } + analyzeProblems(context.getMonitor()); + } + return contributions; + } + + protected static String getSystemProperty(final String name) { + return AccessController.doPrivileged(new PrivilegedAction<String>() { + public String run() { + return System.getProperty(name); + } + }); + } + + protected static class NodeKey { + private String domainURI; + private String nodeURI; + + public NodeKey(NodeConfiguration configuration) { + this.domainURI = configuration.getDomainURI(); + this.nodeURI = configuration.getURI(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((domainURI == null) ? 0 : domainURI.hashCode()); + result = prime * result + ((nodeURI == null) ? 0 : nodeURI.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + NodeKey other = (NodeKey)obj; + if (domainURI == null) { + if (other.domainURI != null) + return false; + } else if (!domainURI.equals(other.domainURI)) + return false; + if (nodeURI == null) { + if (other.nodeURI != null) + return false; + } else if (!nodeURI.equals(other.nodeURI)) + return false; + return true; + } + + public String toString() { + StringBuffer buf = new StringBuffer(); + if (domainURI != null) { + buf.append("{").append(domainURI).append("}"); + } + if (nodeURI != null) { + buf.append(nodeURI); + } + return buf.toString(); + } + } + + @Override + public void configure(Map<String, Map<String, String>> attributes) { + ServiceDiscovery discovery = getExtensionPointRegistry().getServiceDiscovery(); + for (Map.Entry<String, Map<String, String>> e : attributes.entrySet()) { + discovery.setAttribute(e.getKey(), e.getValue()); + } + for (Object o : properties.keySet()) { + String p = (String) o; + if (p.indexOf('.') > -1) { + String serviceType = p.substring(0, p.lastIndexOf('.')); + String attribute = p.substring(p.lastIndexOf('.')+1); + discovery.setAttribute(serviceType, attribute, properties.getProperty(p)); + } + } + quietLogging = Boolean.parseBoolean(properties.getProperty(RuntimeProperties.QUIET_LOGGING)); + super.configure(attributes); + } + + /** + * Added to allow the node access to the deployer in order to get + * to the systemContribution and hence set up the CompositeContext so that + * the runtime epr matching algorithm can get at the binding types + * @return + */ + public Deployer getDeployer() { + return deployer; + } + + @Override + public void setAutoDestroy(boolean b) { + autoDestroy = b; + } + + /** + * Create and load a node + * @param configuration + * @return The node + */ + public NodeExtension loadNode(NodeConfiguration configuration) { + Node node = createNode(configuration); + + try { + NodeImpl nodeImpl = ((NodeImpl) node); + nodeImpl.load(); + return nodeImpl; + } catch (Throwable e) { + throw new ServiceRuntimeException(e); + } + } + + +} diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java new file mode 100644 index 0000000000..453b4fb486 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java @@ -0,0 +1,443 @@ +/* + * 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.node.impl; + +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.context.CompositeContext; +import org.apache.tuscany.sca.context.ThreadMessageContext; +import org.apache.tuscany.sca.contribution.Contribution; +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.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.configuration.NodeConfiguration; +import org.apache.tuscany.sca.node.extensibility.NodeActivator; +import org.apache.tuscany.sca.node.extensibility.NodeActivatorExtensionPoint; +import org.apache.tuscany.sca.node.extensibility.NodeExtension; +import org.apache.tuscany.sca.runtime.ActivationException; +import org.apache.tuscany.sca.runtime.CompositeActivator; +import org.apache.tuscany.sca.runtime.DomainRegistry; +import org.apache.tuscany.sca.runtime.DomainRegistryFactory; +import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.oasisopen.sca.ServiceReference; +import org.oasisopen.sca.ServiceRuntimeException; +import org.oasisopen.sca.ServiceUnavailableException; + +/** + * An SCA Node that is managed by the NodeManager + */ +public class NodeImpl implements Node, NodeExtension { + private static final Logger logger = Logger.getLogger(NodeImpl.class.getName()); + private ProxyFactory proxyFactory; + private CompositeActivator compositeActivator; + private CompositeContext compositeContext; + private Composite domainComposite; + private NodeConfiguration configuration; + private NodeFactoryImpl nodeFactory; + private List<Contribution> contributions; + private NodeActivatorExtensionPoint nodeActivators; + // private NodeManager mbean; + + /** + * Create a node from the configuration + * @param manager + * @param configuration + */ + public NodeImpl(NodeFactoryImpl nodeFactory, NodeConfiguration configuration) { + super(); + this.configuration = configuration; + this.nodeFactory = nodeFactory; + this.nodeActivators = nodeFactory.getExtensionPointRegistry().getExtensionPoint(NodeActivatorExtensionPoint.class); + } + + /** + * Create a node from the configuration and loaded contributions + * @param manager + * @param configuration + * @param contributions + */ + public NodeImpl(NodeFactoryImpl manager, NodeConfiguration configuration, List<Contribution> contributions) { + super(); + this.configuration = configuration; + this.nodeFactory = manager; + this.nodeActivators = nodeFactory.getExtensionPointRegistry().getExtensionPoint(NodeActivatorExtensionPoint.class); + this.contributions = new ArrayList<Contribution>(contributions); + } + + public String getURI() { + return getConfiguration().getURI(); + } + + public String getDomainURI() { + return getConfiguration().getDomainURI(); + } + + public Node start() { + logger.log(nodeFactory.quietLogging? Level.FINE : Level.INFO, "Starting node: " + configuration.getURI() + " domain: " + configuration.getDomainURI()); + + try { + load(); + + this.proxyFactory = nodeFactory.proxyFactory; + + // Set up the node context + UtilityExtensionPoint utilities = nodeFactory.registry.getExtensionPoint(UtilityExtensionPoint.class); + this.compositeActivator = utilities.getUtility(CompositeActivator.class); + + DomainRegistryFactory domainRegistryFactory = + ExtensibleDomainRegistryFactory.getInstance(nodeFactory.registry); + DomainRegistry domainRegistry = + domainRegistryFactory.getEndpointRegistry(configuration.getDomainRegistryURI(), + configuration.getDomainURI()); + + this.compositeContext = + new CompositeContext(nodeFactory.registry, domainRegistry, domainComposite, + configuration.getDomainURI(), configuration.getURI(), nodeFactory + .getDeployer().getSystemDefinitions()); + // Pass down the context attributes + compositeContext.getAttributes().putAll(configuration.getAttributes()); + + // Add endpoint descriptions from the node configuration if the domain registry is local + if (!domainRegistry.isDistributed()) { + for (Endpoint e : configuration.getEndpointDescriptions()) { + domainRegistry.addEndpoint(e); + } + } + // Activate the composite + compositeActivator.activate(compositeContext, domainComposite); + + // Start the composite + compositeActivator.start(compositeContext, domainComposite); + + // FIXME: [rfeng] We should turn the management capability into a system utility. + // In certain environment such as Google App Engine, the JMX API is not allowed + try { + /* + MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); + mbean = new NodeManager(this); + mBeanServer.registerMBean(mbean, mbean.getName()); + */ + /* + LocateRegistry.createRegistry(9999); + JMXServiceURL url = + new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/server"); + JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mBeanServer); + connectorServer.start(); + */ + } catch (Throwable e) { + // Ignore the error for now + // mbean = null; + logger.log(Level.SEVERE, e.getMessage(), e); + } + + for(NodeActivator activator : nodeActivators.getNodeActivators()) { + activator.nodeStarted(this); + } + return this; + + } catch (Throwable e) { + throw new IllegalStateException(e); + } + + } + + public void load() throws Throwable { + nodeFactory.init(); + + nodeFactory.addNode(configuration, this); + + Monitor monitor = nodeFactory.monitorFactory.createMonitor(); + ProcessorContext context = new ProcessorContext(monitor); + + // Set up the thead context monitor + Monitor tcm = nodeFactory.monitorFactory.setContextMonitor(monitor); + try { + // Use the lack of the contributions collection as an indicator for when the node + // is being started for the first time. If it is the first time do all the work + // to read the contributions and create the domain composite + if (contributions == null) { + contributions = nodeFactory.loadContributions(configuration, context); + } + + if (domainComposite == null) { + domainComposite = nodeFactory.configureNode(configuration, contributions, context); + } + + + } finally { + // Reset the thread context monitor + nodeFactory.monitorFactory.setContextMonitor(tcm); + } + } + + public void stop() { + logger.log(nodeFactory.quietLogging? Level.FINE : Level.INFO, "Stopping node: " + configuration.getURI()); + + try { + if (compositeActivator == null) { + return; + } + + /* + if (mbean != null) { + try { + MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); + mBeanServer.unregisterMBean(mbean.getName()); + } catch (Throwable e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } finally { + mbean = null; + } + } + */ + + if( domainComposite != null ) { + + // Stop the composite + compositeActivator.stop(compositeContext, domainComposite); + + // Deactivate the composite + compositeActivator.deactivate(domainComposite); + + } // end if + + // Remove the external endpoint descriptions from node.xml + DomainRegistry domainRegistry = compositeContext.getEndpointRegistry(); + if (!domainRegistry.isDistributed()) { + for (Endpoint e : configuration.getEndpointDescriptions()) { + domainRegistry.removeEndpoint(e); + } + } + + nodeFactory.removeNode(configuration); +/* + this.compositeActivator = null; + this.proxyFactory = null; + this.domainComposite = null; + this.compositeContext = null; +*/ + + for(NodeActivator activator : nodeActivators.getNodeActivators()) { + activator.nodeStopped(this); + } + + ThreadMessageContext.removeMessageContext(); + + } catch (ActivationException e) { + throw new IllegalStateException(e); + } + + } + + @SuppressWarnings("unchecked") + public <B, R extends ServiceReference<B>> R cast(B target) throws IllegalArgumentException { + return (R)proxyFactory.cast(target); + } + + public <B> B getService(Class<B> businessInterface, String serviceName) { + + ServiceReference<B> serviceReference = getServiceReference(businessInterface, serviceName); + if (serviceReference == null) { + throw new ServiceRuntimeException("Service not found: " + serviceName); + } + return serviceReference.getService(); + } + + public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String name) { + + // Extract the component name + String componentName = null; + String serviceName = null; + if (name != null) { + int i = name.indexOf('/'); + if (i != -1) { + componentName = name.substring(0, i); + serviceName = name.substring(i + 1); + + } else { + componentName = name; + serviceName = null; + } + } + + // Lookup the component + Component component = null; + + for (Component compositeComponent : domainComposite.getComponents()) { + if (componentName == null) { + for (ComponentService service : compositeComponent.getServices()) { + Interface intf = service.getInterfaceContract().getInterface(); + if (intf instanceof JavaInterface) { + JavaInterface ji = (JavaInterface)intf; + if (ji.getJavaClass() == businessInterface) { + return ((RuntimeComponent)compositeComponent).getComponentContext() + .createSelfReference(businessInterface, service); + } + } + } + } + if (compositeComponent.getName().equals(componentName)) { + component = compositeComponent; + break; + } + } + + if (component == null) { + throw new ServiceUnavailableException("The service " + name + " has not been contributed to the domain"); + } + + return ((RuntimeComponent)component).getServiceReference(businessInterface, serviceName); + } + + public NodeConfiguration getConfiguration() { + return configuration; + } + + public ExtensionPointRegistry getExtensionPointRegistry() { + return nodeFactory.getExtensionPointRegistry(); + } + + /** + * Get the service endpoints in this Node + * TODO: needs review, works for the very simple testcase but i expect there are + * other endpoints to be included + */ + public List<Endpoint> getServiceEndpoints() { + List<Endpoint> endpoints = new ArrayList<Endpoint>(); + if (compositeActivator != null) { + if (domainComposite != null) { + for (Component component : domainComposite.getComponents()) { + for (Service service : component.getServices()) { + // MJE 28/05/2009 - changed to RuntimeComponentService from RuntimeComponentServiceImpl + // - no need to access the Impl directly here + if (service instanceof RuntimeComponentService) { + endpoints.addAll(((RuntimeComponentService)service).getEndpoints()); + } + } + } + } + } + return endpoints; + } + + public Composite getDomainComposite() { + return domainComposite; + } + + public String dumpDomainComposite() { + + StAXArtifactProcessorExtensionPoint xmlProcessors = + getExtensionPointRegistry().getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + StAXArtifactProcessor<Composite> compositeProcessor = + xmlProcessors.getProcessor(Composite.class); + + return writeComposite(getDomainComposite(), compositeProcessor); + } + + private String writeComposite(Composite composite, StAXArtifactProcessor<Composite> compositeProcessor){ + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + XMLOutputFactory outputFactory = + nodeFactory.getExtensionPointRegistry().getExtensionPoint(FactoryExtensionPoint.class) + .getFactory(XMLOutputFactory.class); + + try { + XMLStreamWriter xmlStreamWriter = outputFactory.createXMLStreamWriter(bos); + compositeProcessor.write(composite, xmlStreamWriter, new ProcessorContext(nodeFactory.registry)); + xmlStreamWriter.flush(); + } catch(Exception ex) { + return ex.toString(); + } + + + String result = bos.toString(); + + // write out and nested composites + for (Component component : composite.getComponents()) { + if (component.getImplementation() instanceof Composite) { + result += "\n<!-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -->\n" + + writeComposite((Composite)component.getImplementation(), + compositeProcessor); + } + } + + return result; + } + + public List<Contribution> getContributions() { + return contributions; + } + + @Override + public String getEndpointAddress(String serviceBindingName) { + if (serviceBindingName == null) { + throw new IllegalArgumentException("Service binding name cannot be null"); + } + + // Calculate the names for compoment/service/binding + String[] parts = serviceBindingName.split("/"); + String componentName = parts[0]; + String serviceName = parts.length >= 2 ? parts[1] : null; + String bindingName = parts.length >= 3 ? parts[2] : serviceName; + + if (domainComposite != null) { + for (Component component : domainComposite.getComponents()) { + if (!component.getName().equals(componentName)) { + continue; + } + for (Service service : component.getServices()) { + if (serviceName != null && !service.getName().equals(serviceName)) { + continue; + } + if (service instanceof RuntimeComponentService) { + for (Endpoint ep : ((RuntimeComponentService)service).getEndpoints()) { + if (bindingName == null || bindingName.equals(ep.getBinding().getName())) { + return ep.getDeployedURI(); + } + } + } + } + } + } + return null; + } + +} diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java new file mode 100644 index 0000000000..4da41442f5 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java @@ -0,0 +1,43 @@ +/* + * 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.node.impl; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; + +/** + * NodeUtil + * + * @version $Rev$ $Date$ + */ +public class NodeUtil { + + private NodeUtil() { + } + + static Contribution contribution(ContributionFactory contributionFactory, org.apache.tuscany.sca.node.Contribution c) { + Contribution contribution = contributionFactory.createContribution(); + contribution.setURI(c.getURI()); + contribution.setLocation(c.getLocation()); + contribution.setUnresolved(true); + return contribution; + } + +} diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/management/NodeManager.java b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/management/NodeManager.java new file mode 100644 index 0000000000..12704a3ee5 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/management/NodeManager.java @@ -0,0 +1,65 @@ +/* + * 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.node.management; + +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; + +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.impl.NodeImpl; + +/** + * MBean implementation for the node + */ +public class NodeManager implements NodeManagerMBean { + private NodeImpl node; + private ObjectName name; + + public NodeManager(NodeImpl node) { + this.node = node; + try { + this.name = getName(node); + } catch (MalformedObjectNameException e) { + // Ignore + } + } + + public String getURI() { + return node.getURI(); + } + + public String getDomainURI() { + return node.getConfiguration().getDomainURI(); + } + + public ObjectName getName() { + return name; + } + + private static ObjectName getName(NodeImpl node) throws MalformedObjectNameException { + String name = + Node.class.getPackage().getName() + ":type=" + + Node.class.getSimpleName() + + ",uri=" + + ObjectName.quote(node.getURI()); + return ObjectName.getInstance(name); + + } +} diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/management/NodeManagerMBean.java b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/management/NodeManagerMBean.java new file mode 100644 index 0000000000..3133142c2b --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/management/NodeManagerMBean.java @@ -0,0 +1,30 @@ +/* + * 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.node.management; + + + +/** + * MBean for NodeImpl + */ +public interface NodeManagerMBean { + String getURI(); + String getDomainURI(); +} diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..a9d0f5ef52 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,18 @@ +# 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. +org.apache.tuscany.sca.node.configuration.xml.NodeConfigurationProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#node,model=org.apache.tuscany.sca.node.configuration.NodeConfiguration +
diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.NodeFactory b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.NodeFactory new file mode 100644 index 0000000000..a349dd7c26 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.NodeFactory @@ -0,0 +1,18 @@ +# 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.
+org.apache.tuscany.sca.node.impl.NodeFactoryImpl
+
diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.configuration.NodeConfigurationFactory b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.configuration.NodeConfigurationFactory new file mode 100644 index 0000000000..9b26d0c7c1 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.configuration.NodeConfigurationFactory @@ -0,0 +1,18 @@ +# 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.
+org.apache.tuscany.sca.node.configuration.DefaultNodeConfigurationFactory
+
diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.extensibility.NodeActivatorExtensionPoint b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.extensibility.NodeActivatorExtensionPoint new file mode 100644 index 0000000000..3c83b6f38e --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.extensibility.NodeActivatorExtensionPoint @@ -0,0 +1,19 @@ +# 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. + +org.apache.tuscany.sca.node.extensibility.impl.DefaultNodeActivatorExtensionPoint + diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/resources/org/apache/tuscany/sca/node/impl/node-impl-validation-messages.properties b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/resources/org/apache/tuscany/sca/node/impl/node-impl-validation-messages.properties new file mode 100644 index 0000000000..0c07a3a30f --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/main/resources/org/apache/tuscany/sca/node/impl/node-impl-validation-messages.properties @@ -0,0 +1,22 @@ +# +# +# 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. +# +# + +UnresolvedImport = Unresolved import: Import = {0} diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/hello/HelloWorld.java b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/hello/HelloWorld.java new file mode 100644 index 0000000000..df5c246241 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/hello/HelloWorld.java @@ -0,0 +1,37 @@ +/* + * 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 hello; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * HelloWorld interface + */ +@Remotable +public interface HelloWorld { + String hello(String name); + + Message echo(Message msg); + + public class Message { + public String name; + public String message; + } +} diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/hello/HelloWorldImpl.java b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/hello/HelloWorldImpl.java new file mode 100644 index 0000000000..3285ab12db --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/hello/HelloWorldImpl.java @@ -0,0 +1,38 @@ +/* + * 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 hello; + +import org.oasisopen.sca.annotation.AllowsPassByReference; + +/** + * HelloWorldImpl + */ +public class HelloWorldImpl implements HelloWorld { + public String hello(String name) { + System.out.println("Hello: " + name); + return "Hello, " + name; + } + + @Override + @AllowsPassByReference + public Message echo(Message msg) { + return msg; + } +} diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessorTestCase.java b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessorTestCase.java new file mode 100644 index 0000000000..27c56dc6ec --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessorTestCase.java @@ -0,0 +1,86 @@ +/* + * 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.node.configuration.xml; + +import java.io.InputStream; +import java.io.StringWriter; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +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.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.DefaultFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.node.configuration.NodeConfiguration; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + */ +public class NodeConfigurationProcessorTestCase { + private static FactoryExtensionPoint factories; + private static StAXArtifactProcessor processor; + + private static ProcessorContext context; + + @BeforeClass + public static void setUp() throws Exception { + ExtensionPointRegistry registry = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(registry); + + factories = new DefaultFactoryExtensionPoint(registry); + StAXArtifactProcessorExtensionPoint processors = + registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + processor = processors.getProcessor(NodeConfiguration.class); + } + + @Test + public void testRead() throws Exception { + InputStream is = getClass().getResourceAsStream("/org/apache/tuscany/sca/node/configuration/node1.xml"); + XMLInputFactory xmlInputFactory = factories.getFactory(XMLInputFactory.class); + XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(is); + reader.nextTag(); + NodeConfiguration config = (NodeConfiguration) processor.read(reader, context); + is.close(); + StringWriter sw = new StringWriter(); + XMLOutputFactory xmlOutputFactory = factories.getFactory(XMLOutputFactory.class); + xmlOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); + XMLStreamWriter writer = xmlOutputFactory.createXMLStreamWriter(sw); + processor.write(config, writer, context); + writer.flush(); + System.out.println(sw.toString()); + } + + /** + * @throws java.lang.Exception + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + +} diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java new file mode 100644 index 0000000000..86a85034ae --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java @@ -0,0 +1,251 @@ +/* + * 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.node.impl; + +import hello.HelloWorld; + +import java.io.File; +import java.io.StringReader; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.extensibility.ServiceDeclarationParser; +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.apache.tuscany.sca.runtime.DomainRegistryFactoryExtensionPoint; +import org.apache.tuscany.sca.runtime.RuntimeProperties; +import org.junit.Assert; +import org.junit.Test; + +/** + * Test case for NodeImpl + */ +public class NodeImplTestCase { + private static String composite = + "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\"" + " xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.1\"" + + " targetNamespace=\"http://sample/composite\"" + + " xmlns:sc=\"http://sample/composite\"" + + " name=\"HelloWorld2\">" + + " <component name=\"HelloWorld2\">" + + " <implementation.java class=\"hello.HelloWorldImpl\"/>" + + " </component>" + + " </composite>"; + + @Test + public void testNodeWithCompositeContent() { + NodeFactory factory = new NodeFactoryImpl(); + Contribution contribution = new Contribution("c1", new File("target/test-classes").toURI().toString()); + Node node = factory.createNode(new StringReader(composite), contribution); + testNode2(node); + } + + @Test + public void testNodeWithRelativeCompositeURI() { + NodeFactory factory = new NodeFactoryImpl(); + Contribution contribution = new Contribution("c1", new File("target/test-classes").toURI().toString()); + String compositeURI = "HelloWorld.composite"; + Node node = factory.createNode(compositeURI, contribution); + testNode(node); + } + + @SuppressWarnings("deprecation") + @Test + public void testNodeWithAbsoluteCompositeURI() throws MalformedURLException { + NodeFactory factory = new NodeFactoryImpl(); + Contribution contribution = new Contribution("c1", new File("target/test-classes").toURL().toString()); + String compositeURI = new File("target/test-classes/HelloWorld.composite").toURL().toString(); + Node node = factory.createNode(compositeURI, contribution); + testNode(node); + } + + @Test + public void testDefaultNode() { + testNode(new NodeFactoryImpl().createNode()); + } + + @Test + public void testNodeWithURI() { + testNode(new NodeFactoryImpl().createNode(URI.create("foo"),"target/test-classes")); + } + @Test + public void testNodeWithURIandComposite() throws MalformedURLException { + String compositeURI = new File("target/test-classes/HelloWorld.composite").toURI().toString(); + testNode(new NodeFactoryImpl().createNode(URI.create("foo"), compositeURI, new String[]{"target/test-classes"})); + } + + @Test + public void testGetServiceEndpoints() { + NodeFactory factory = new NodeFactoryImpl(); + Contribution contribution = new Contribution("c1", new File("target/test-classes").toURI().toString()); + NodeImpl node = (NodeImpl)factory.createNode(new StringReader(composite), contribution); + node.start(); + List<Endpoint> es = node.getServiceEndpoints(); + Assert.assertEquals(1, es.size()); + Assert.assertEquals("HelloWorld2", es.get(0).getComponent().getName()); + node.stop(); + } + + private void testNode(Node node) { + node.start(); + HelloWorld hw = node.getService(HelloWorld.class, "HelloWorld"); + Assert.assertEquals("Hello, Node", hw.hello("Node")); + hw = node.getService(HelloWorld.class, null); + Assert.assertEquals("Hello, Node", hw.hello("Node")); + String address = node.getEndpointAddress("HelloWorld"); + Assert.assertNotNull(address); + address = node.getEndpointAddress("HelloWorld/HelloWorld"); + Assert.assertNotNull(address); + address = node.getEndpointAddress("HelloWorld/HelloWorld/HelloWorld"); + Assert.assertNotNull(address); + address = node.getEndpointAddress("HelloWorld/HelloWorld1"); + Assert.assertNull(address); + + HelloWorld.Message msg = new HelloWorld.Message(); + msg.name = "John"; + msg.message = "Hi"; + Assert.assertSame(msg, hw.echo(msg)); + node.stop(); + } + + private void testNode2(Node node) { + node.start(); + HelloWorld hw = node.getService(HelloWorld.class, "HelloWorld2"); + Assert.assertEquals("Hello, Node", hw.hello("Node")); + node.stop(); + } + + @Test + public void testNodeFactoryAttributes() { + Map<String, Map<String, String>> attrs = new HashMap<String, Map<String, String>>(); + Map<String, String> map = new HashMap<String, String>(); + map.put("enabled", "false"); + attrs.put(ValidationSchemaExtensionPoint.class.getName(), map); + + Map<String, String> map2 = new HashMap<String, String>(); + map2.put("urn:MyDomain", "multicast://200.0.0.100:50000/MyDomain"); + attrs.put(DomainRegistryFactoryExtensionPoint.class.getName(), map2); + + NodeFactoryImpl factory = (NodeFactoryImpl)NodeFactory.newInstance(attrs); + Assert.assertFalse(factory.getExtensionPointRegistry().getExtensionPoint(ValidationSchemaExtensionPoint.class) + .isEnabled()); + + DomainRegistryFactoryExtensionPoint domainRegistryFactoryExtensionPoint = + factory.getExtensionPointRegistry().getExtensionPoint(DomainRegistryFactoryExtensionPoint.class); + Map<String, String> mapping = domainRegistryFactoryExtensionPoint.getDomainRegistryMapping(); + Assert.assertEquals(1, mapping.size()); + Assert.assertEquals("multicast://200.0.0.100:50000/MyDomain", mapping.get("urn:MyDomain")); + } + + @Test + public void testNodeFactoryProperties() throws Exception { + NodeFactoryImpl factory = (NodeFactoryImpl)NodeFactory.newInstance(); + factory.init(); + UtilityExtensionPoint utilities = factory.getExtensionPointRegistry().getExtensionPoint(UtilityExtensionPoint.class); + Properties ps = utilities.getUtility(RuntimeProperties.class).getProperties(); + Assert.assertEquals(0, ps.size()); + + Properties properties = new Properties(); + properties.setProperty("defaultScheme", "vm"); + properties.setProperty("foo.bla", "some value"); + factory = (NodeFactoryImpl)NodeFactory.newInstance(properties); + factory.init(); + utilities = factory.getExtensionPointRegistry().getExtensionPoint(UtilityExtensionPoint.class); + ps = utilities.getUtility(RuntimeProperties.class).getProperties(); + Assert.assertEquals(2, ps.size()); + Assert.assertEquals("some value", ps.getProperty("foo.bla")); + + factory = (NodeFactoryImpl)NodeFactory.newInstance("properties:test.properties"); + factory.init(); + utilities = factory.getExtensionPointRegistry().getExtensionPoint(UtilityExtensionPoint.class); + ps = utilities.getUtility(RuntimeProperties.class).getProperties(); + Assert.assertEquals(2, ps.size()); + Assert.assertEquals("xyz", ps.getProperty("foo.bla")); + + factory = (NodeFactoryImpl)NodeFactory.newInstance("uri:foo?k1=v1&k2=v2&defaultScheme=vm"); + factory.init(); + utilities = factory.getExtensionPointRegistry().getExtensionPoint(UtilityExtensionPoint.class); + ps = utilities.getUtility(RuntimeProperties.class).getProperties(); + Assert.assertEquals(4, ps.size()); + Assert.assertEquals("vm", ps.getProperty("defaultScheme")); + Assert.assertEquals("foo", ps.getProperty("defaultDomainName")); + Assert.assertEquals("v1", ps.getProperty("k1")); + Assert.assertEquals("v2", ps.getProperty("k2")); + + factory = (NodeFactoryImpl)NodeFactory.newInstance("uri:"); + factory.init(); + utilities = factory.getExtensionPointRegistry().getExtensionPoint(UtilityExtensionPoint.class); + ps = utilities.getUtility(RuntimeProperties.class).getProperties(); + Assert.assertEquals(1, ps.size()); + Assert.assertEquals("", ps.getProperty("defaultDomainName")); + + factory = (NodeFactoryImpl)NodeFactory.newInstance("uri:?"); + factory.init(); + utilities = factory.getExtensionPointRegistry().getExtensionPoint(UtilityExtensionPoint.class); + ps = utilities.getUtility(RuntimeProperties.class).getProperties(); + Assert.assertEquals(1, ps.size()); + Assert.assertEquals("default", ps.getProperty("defaultDomainName")); + + factory = (NodeFactoryImpl)NodeFactory.newInstance("uri:?foo"); + factory.init(); + utilities = factory.getExtensionPointRegistry().getExtensionPoint(UtilityExtensionPoint.class); + ps = utilities.getUtility(RuntimeProperties.class).getProperties(); + Assert.assertEquals(2, ps.size()); + Assert.assertEquals("default", ps.getProperty("defaultDomainName")); + Assert.assertEquals("", ps.getProperty("foo")); + } + + @Test + public void testLoadNodeFactoryProperties() throws Exception { + URL url = getClass().getResource("/org/apache/tuscany/sca/node/configuration/test-node-factory.config"); + Collection<Map<String, String>> items = ServiceDeclarationParser.load(url, false); + for (Map<String, String> attrs : items) { + System.out.println(attrs); + } + } + + @Test + public void testAutoDestroy() throws Exception { + NodeFactory nf = NodeFactory.newInstance(); + Node node = nf.createNode(); + node.start(); + Assert.assertTrue(((NodeFactoryImpl)nf).inited); + node.stop(); + Assert.assertFalse(((NodeFactoryImpl)nf).inited); + + nf = NodeFactory.newInstance(); + nf.setAutoDestroy(false); + node = nf.createNode(); + node.start(); + Assert.assertTrue(((NodeFactoryImpl)nf).inited); + node.stop(); + Assert.assertTrue(((NodeFactoryImpl)nf).inited); + + } +} diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeUtilTestCase.java b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeUtilTestCase.java new file mode 100644 index 0000000000..4b9dda4a71 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeUtilTestCase.java @@ -0,0 +1,48 @@ +/* + * 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.node.impl; + +import java.net.URI; + +import org.apache.tuscany.sca.common.java.io.IOHelper; +import org.junit.Assert; +import org.junit.Test; + + +/** + * + */ +public class NodeUtilTestCase { + @Test + public void testCreateURI() { + Assert.assertEquals("/a/b", IOHelper.createURI("/a/b").toString()); + Assert.assertEquals("/a%20b", IOHelper.createURI("/a b").toString()); + Assert.assertEquals("file:/a/b", IOHelper.createURI("file:/a/b").toString()); + Assert.assertEquals("file:/a%20b", IOHelper.createURI("file:/a b").toString()); + Assert.assertEquals("file:/a%20b", IOHelper.createURI("file:/a%20b").toString()); + } + + @Test + public void testDomainURI() { + Assert.assertEquals("foo", NodeFactoryImpl.getDomainURI(URI.create("tuscany:foo"))); + Assert.assertEquals("foo", NodeFactoryImpl.getDomainURI(URI.create("vm:foo"))); + Assert.assertEquals("foo", NodeFactoryImpl.getDomainURI(URI.create("bla://foo"))); + } +} diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/PerflTest.java b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/PerflTest.java new file mode 100644 index 0000000000..80bd3b2ca1 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/PerflTest.java @@ -0,0 +1,81 @@ +/* + * 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.node.impl; + +import hello.HelloWorld; + +import java.io.File; +import java.io.IOException; +import java.io.StringReader; +import java.util.Properties; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.apache.tuscany.sca.runtime.RuntimeProperties; +import org.junit.Assert; +import org.junit.Test; + +/** + * Test case for NodeImpl + */ +public class PerflTest { + private static String composite = + "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\"" + " xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.1\"" + + " targetNamespace=\"http://sample/composite\"" + + " xmlns:sc=\"http://sample/composite\"" + + " name=\"HelloWorld2\">" + + " <component name=\"HelloWorld2\">" + + " <implementation.java class=\"hello.HelloWorldImpl\"/>" + + " </component>" + + " </composite>"; + + @Test + public void testNodeWithCompositeContent() throws IOException { + Properties config = new Properties(); + config.setProperty(RuntimeProperties.QUIET_LOGGING, "true"); + NodeFactory factory = NodeFactory.newInstance(config); + factory.setAutoDestroy(false); + Contribution contribution = new Contribution("c1", new File("target/test-classes").toURI().toString()); + Node node = factory.createNode(new StringReader(composite), contribution); + testNode2(node); + + node.stop(); + + int count = 3000; + long start = System.currentTimeMillis(); + for (int i=0; i<count; i++) { + node.start(); + node.stop(); + } + long total = System.currentTimeMillis() - start; + System.out.println(count + " = " + total + " = " + total / (double)count); + + // test it still works + testNode2(node); + } + + private void testNode2(Node node) { + node.start(); + HelloWorld hw = node.getService(HelloWorld.class, "HelloWorld2"); + Assert.assertEquals("Hello, Node", hw.hello("Node")); + node.stop(); + } +} diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/QuietLoggingTestCase.java b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/QuietLoggingTestCase.java new file mode 100644 index 0000000000..2d3b4f7c2f --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/QuietLoggingTestCase.java @@ -0,0 +1,71 @@ +/* + * 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.node.impl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.logging.Handler; +import java.util.logging.LogManager; +import java.util.logging.LogRecord; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.apache.tuscany.sca.runtime.RuntimeProperties; +import org.junit.Assert; +import org.junit.Test; + +/** + * Test case for NodeImpl + */ +public class QuietLoggingTestCase { + + @Test + public void testQuietLogging() throws Exception { + + final List<LogRecord> logRecords = new ArrayList<LogRecord>(); + LogManager logManager = LogManager.getLogManager(); + logManager.reset(); + Handler handler = new Handler() { + @Override + public void publish(LogRecord record) { + logRecords.add(record); + } + @Override + public void flush() { + } + @Override + public void close() throws SecurityException { + } + }; + Logger.getLogger("").addHandler(handler); + + Properties props = new Properties(); + props.setProperty(RuntimeProperties.QUIET_LOGGING, "true"); + NodeFactory nf = NodeFactory.newInstance(props); + Node node = nf.createNode(); + node.start(); + node.stop(); + + Assert.assertEquals(0 , logRecords.size()); + } + +} diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/resources/HelloWorld.composite b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/resources/HelloWorld.composite new file mode 100644 index 0000000000..ca3c3eda7c --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/resources/HelloWorld.composite @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" + targetNamespace="http://sample/composite" + xmlns:sc="http://sample/composite" + name="HelloWorld"> + + <component name="HelloWorld"> + <implementation.java class="hello.HelloWorldImpl"/> + </component> + +</composite> diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/resources/META-INF/sca-contribution.xml b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..20627c3d2c --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/resources/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +* 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. +--> + +<contribution xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:sc="http://sample/composite"> + <deployable composite="sc:HelloWorld" /> +</contribution> diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/resources/org/apache/tuscany/sca/node/configuration/node1.xml b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/resources/org/apache/tuscany/sca/node/configuration/node1.xml new file mode 100644 index 0000000000..0e574e61fe --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/resources/org/apache/tuscany/sca/node/configuration/node1.xml @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<node xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns="http://tuscany.apache.org/xmlns/sca/1.1" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" + uri="http://sample/nodes/TestNode1" + domainRegistry = "vm://localhost" + domain="http://domain1"> + + <!-- Configure the base URIs for a given binding --> + <!-- Each base URI is for a protocol supported by the binding --> + <binding name="sca:binding.ws" baseURIs="http://localhost:8080/ws https://localhost:8081/ws"/> + <binding name="tuscany:binding.rmi" baseURIs="rmi://localhost:8080/rmi"/> + <binding name="tuscany:binding.jsonrpc"> + <baseURI>http://localhost:8080/jsonrpc</baseURI> + </binding> + + <!-- Configure a list of contributions --> + <contribution uri="http://c1" location="file:///a.jar"/> + <contribution uri="http://c2" location="http://locahost/repo/b.jar"> + <!-- The deployment composite is optional --> + <!-- The deployment composite can be defined inline or referenced using a URI --> + <!-- Can we have more than one deployment composites --> + <deploymentComposite> + <sca:composite> + <sca:component name="Component1"> <!-- first component --> + <sca:implementation.java class="a.b.Component1Impl"/> + <sca:reference name="ref1"> + <tuscany:binding.rmi/> + </sca:reference> + </sca:component> + </sca:composite> + </deploymentComposite> + </contribution> + <contribution uri="http://c3" location="http://locahost/repo/c.jar"> + <deploymentComposite location="test/Test.composite"> + </deploymentComposite> + </contribution> + <option name="debug" value="true"/> + <option name="validation">true</option> + <endpoint> + <sca:composite name="endpoint"> + <sca:component name="Component1"> <!-- first component --> + <sca:service name="Service1"> + <tuscany:binding.rest uri="http://localhost:8080/services/myResource" /> + </sca:service> + </sca:component> + </sca:composite> + </endpoint> +</node>
\ No newline at end of file diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/resources/org/apache/tuscany/sca/node/configuration/test-node-factory.config b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/resources/org/apache/tuscany/sca/node/configuration/test-node-factory.config new file mode 100644 index 0000000000..ec87f6a3e0 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/resources/org/apache/tuscany/sca/node/configuration/test-node-factory.config @@ -0,0 +1,19 @@ +# 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.
+# Configuration properties for NodeFactory
+org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint;enabled=true,attr="value"
+org.apache.tuscany.sca.runtime.DomainRegistryFactoryExtensionPoint;urn:MyDomain="multicast://200.0.0.100:50000/MyDomain"
\ No newline at end of file diff --git a/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/resources/test.properties b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/resources/test.properties new file mode 100644 index 0000000000..df9d47b4eb --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC2/modules/node-impl/src/test/resources/test.properties @@ -0,0 +1,22 @@ +#
+# 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.
+#
+defaultScheme = vm
+foo.bla = xyz
+
+
|