diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-04-14 04:15:42 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-04-14 04:15:42 +0000 |
commit | d4743525775f0d49ab021887e7402967d12d32be (patch) | |
tree | 7fff56c2496760ad6bd25e324d577b6daee7288a /sca-java-2.x/trunk/modules | |
parent | 4c7135a02179116fa07dd11df28a7885f5369273 (diff) |
Add duplication check for SCA configurations
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@933854 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules')
5 files changed, 87 insertions, 26 deletions
diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java index ffd619a4c2..22bcb5af41 100644 --- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java +++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java @@ -478,8 +478,10 @@ public class EndpointIntrospector { .getNamespaceURI())) { for (Binding binding : sc.getBindings()) { if (bindingName.getLocalPart().equals(binding.getName())) { - bindingMap.put(bindingName, binding); - break; + // We need to check duplications + if (bindingMap.put(bindingName, binding) != null) { + throw new ServiceRuntimeException("Duplicate binding found: " + bindingName); + } } } } diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java index 56e17a5642..00eb45f3c1 100644 --- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java +++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java @@ -265,7 +265,14 @@ public class RemoteServiceAdminImpl implements RemoteServiceAdmin, ManagedServic if (bindings != null) { props.put("org.osgi.sca.bindings", bindings); } - } + Object config = ep.getProperties().get("org.osgi.sca.config.url"); + if (config != null) { + props.put("org.osgi.sca.config.url", config); + } + config = ep.getProperties().get("org.osgi.sca.config.xml"); + if (config != null) { + props.put("org.osgi.sca.config.xml", config); + } } props.put("timestamp", Long.valueOf(System.currentTimeMillis())); props.put("event", rsaEvent); return new Event(topic, props); diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java index 34c72933e9..0cbdda7b56 100644 --- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java +++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java @@ -80,9 +80,12 @@ public class DomainDiscoveryService extends AbstractDiscoveryService implements public void endpointAdded(Endpoint endpoint) { Implementation impl = endpoint.getComponent().getImplementation(); + + /* if (!(impl instanceof OSGiImplementation)) { return; } + */ BundleContext bundleContext = null; // Remote endpoint doesn't have a bundle diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java index 320443c399..dc9ae096dd 100644 --- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java +++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java @@ -34,12 +34,17 @@ import java.util.UUID; import java.util.Map.Entry; import java.util.logging.Level; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.deployment.Deployer; import org.apache.tuscany.sca.implementation.osgi.SCAConfig; import org.apache.tuscany.sca.implementation.osgi.ServiceDescription; import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions; import org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; import org.oasisopen.sca.ServiceRuntimeException; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -159,6 +164,7 @@ public class LocalDiscoveryService extends AbstractDiscoveryService implements B } // Add to the extenders before notifying the listeners (the endpoints may references to the config) + ExtenderConfiguration.validate(extenders, extender); this.extenders.add(extender); // Notify @@ -200,6 +206,50 @@ public class LocalDiscoveryService extends AbstractDiscoveryService implements B return scaConfigs; } + public static void validate(Collection<ExtenderConfiguration> configs, ExtenderConfiguration newConfig) { + Map<QName, Binding> bindings = new HashMap<QName, Binding>(); + Map<QName, Intent> intents = new HashMap<QName, Intent>(); + Map<QName, PolicySet> policySets = new HashMap<QName, PolicySet>(); + + for (ExtenderConfiguration config : configs) { + for (SCAConfig c : config.getSCAConfigs()) { + addBindings(bindings, c); + addIntents(intents, c); + addPolicySets(policySets, c); + } + } + for (SCAConfig c : newConfig.getSCAConfigs()) { + addBindings(bindings, c); + addIntents(intents, c); + addPolicySets(policySets, c); + } + } + + private static void addIntents(Map<QName, Intent> intents, SCAConfig c) { + for (Intent i: c.getIntents()) { + if (intents.put(i.getName(), i) != null) { + throw new ServiceRuntimeException("Duplicate intent: " + i.getName()); + } + } + } + + private static void addPolicySets(Map<QName, PolicySet> policySets, SCAConfig c) { + for (PolicySet ps: c.getPolicySets()) { + if (policySets.put(ps.getName(), ps) != null) { + throw new ServiceRuntimeException("Duplicate policySet: " + ps.getName()); + } + } + } + + private static void addBindings(Map<QName, Binding> bindings, SCAConfig c) { + for (Binding b : c.getBindings()) { + QName name = new QName(c.getTargetNamespace(), b.getName()); + if (bindings.put(name, b) != null) { + throw new ServiceRuntimeException("Duplicate binding: " + name); + } + } + } + } @Override diff --git a/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java index 36091bec6c..d9c3f0ca54 100644 --- a/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java +++ b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java @@ -46,7 +46,6 @@ import org.apache.tuscany.sca.core.invocation.ProxyFactory; 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.management.NodeManager; import org.apache.tuscany.sca.runtime.ActivationException; import org.apache.tuscany.sca.runtime.CompositeActivator; import org.apache.tuscany.sca.runtime.DomainRegistryFactory; @@ -69,19 +68,19 @@ public class NodeImpl implements Node { private CompositeContext compositeContext; private Composite domainComposite; private NodeConfiguration configuration; - private NodeFactoryImpl manager; + private NodeFactoryImpl nodeFactory; private List<Contribution> contributions; - private NodeManager mbean; + // private NodeManager mbean; /** * Create a node from the configuration * @param manager * @param configuration */ - public NodeImpl(NodeFactoryImpl manager, NodeConfiguration configuration) { + public NodeImpl(NodeFactoryImpl nodeFactory, NodeConfiguration configuration) { super(); this.configuration = configuration; - this.manager = manager; + this.nodeFactory = nodeFactory; } /** @@ -93,7 +92,7 @@ public class NodeImpl implements Node { public NodeImpl(NodeFactoryImpl manager, NodeConfiguration configuration, List<Contribution> contributions) { super(); this.configuration = configuration; - this.manager = manager; + this.nodeFactory = manager; this.contributions = new ArrayList<Contribution>(contributions); } @@ -104,41 +103,41 @@ public class NodeImpl implements Node { public Node start() { logger.log(Level.INFO, "Starting node: " + configuration.getURI() + " domain: " + configuration.getDomainURI()); - manager.init(); - manager.addNode(configuration, this); - this.proxyFactory = manager.proxyFactory; + nodeFactory.init(); + nodeFactory.addNode(configuration, this); + this.proxyFactory = nodeFactory.proxyFactory; - DomainRegistryFactory domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(manager.registry); + DomainRegistryFactory domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(nodeFactory.registry); EndpointRegistry endpointRegistry = domainRegistryFactory.getEndpointRegistry(configuration.getDomainRegistryURI(), configuration .getDomainURI()); - UtilityExtensionPoint utilities = manager.registry.getExtensionPoint(UtilityExtensionPoint.class); + UtilityExtensionPoint utilities = nodeFactory.registry.getExtensionPoint(UtilityExtensionPoint.class); this.compositeActivator = utilities.getUtility(CompositeActivator.class); try { - Monitor monitor = manager.monitorFactory.createMonitor(); + Monitor monitor = nodeFactory.monitorFactory.createMonitor(); ProcessorContext context = new ProcessorContext(monitor); // Set up the thead context monitor - Monitor tcm = manager.monitorFactory.setContextMonitor(monitor); + Monitor tcm = nodeFactory.monitorFactory.setContextMonitor(monitor); try { if (contributions == null) { - contributions = manager.loadContributions(configuration, context); + contributions = nodeFactory.loadContributions(configuration, context); } - domainComposite = manager.configureNode(configuration, contributions, context); + domainComposite = nodeFactory.configureNode(configuration, contributions, context); this.compositeContext = - new CompositeContext(manager.registry, + new CompositeContext(nodeFactory.registry, endpointRegistry, domainComposite, configuration.getDomainURI(), configuration.getURI(), - manager.getDeployer().getSystemDefinitions()); + nodeFactory.getDeployer().getSystemDefinitions()); CompositeContext.setThreadCompositeContext(compositeContext); } finally { // Reset the thread context monitor - manager.monitorFactory.setContextMonitor(tcm); + nodeFactory.monitorFactory.setContextMonitor(tcm); } // Activate the composite @@ -164,7 +163,7 @@ public class NodeImpl implements Node { */ } catch (Throwable e) { // Ignore the error for now - mbean = null; + // mbean = null; logger.log(Level.SEVERE, e.getMessage(), e); } @@ -207,7 +206,7 @@ public class NodeImpl implements Node { } // end if - manager.removeNode(configuration); + nodeFactory.removeNode(configuration); this.compositeActivator = null; this.proxyFactory = null; this.domainComposite = null; @@ -298,7 +297,7 @@ public class NodeImpl implements Node { } public ExtensionPointRegistry getExtensionPointRegistry() { - return manager.getExtensionPointRegistry(); + return nodeFactory.getExtensionPointRegistry(); } /** @@ -341,11 +340,11 @@ public class NodeImpl implements Node { private String writeComposite(Composite composite, StAXArtifactProcessor<Composite> compositeProcessor){ ByteArrayOutputStream bos = new ByteArrayOutputStream(); XMLOutputFactory outputFactory = - manager.getExtensionPointRegistry().getExtensionPoint(FactoryExtensionPoint.class) + nodeFactory.getExtensionPointRegistry().getExtensionPoint(FactoryExtensionPoint.class) .getFactory(XMLOutputFactory.class); try { - compositeProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), new ProcessorContext(manager.registry)); + compositeProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), new ProcessorContext(nodeFactory.registry)); } catch(Exception ex) { return ex.toString(); } |