From: Tony Tkacik Date: Fri, 5 Apr 2013 11:11:04 +0000 (+0200) Subject: Added support for binding-independent RPCs X-Git-Tag: releasepom-0.1.0~594 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=1d01212bc66db4193eb67007267b105fc02cbd71 Added support for binding-independent RPCs Implemented the support for binding-independent RPCs directly into BrokerImpl, and removed unused placeholders for functionality. Cleanup: - Moved Session Implementations directly into BrokerImpl as private inner classes, because they are BrokerImpl specific. - Removed unnecessary packages. - Extracted RPC utils from sal-broker-impl to sal-common-utils to be reusable for other components without introducing dependency on sal-broker-impl. Signed-off-by: Tony Tkacik --- diff --git a/opendaylight/sal/yang-prototype/sal/pom.xml b/opendaylight/sal/yang-prototype/sal/pom.xml index 1b633b4a25..9f77613b89 100644 --- a/opendaylight/sal/yang-prototype/sal/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/pom.xml @@ -7,15 +7,15 @@ pom + sal-common + sal-common-util sal-core-api sal-data-api sal-binding-api sal-binding-spi sal-binding-broker-impl sal-schema-repository-api - sal-common sal-core-spi - ../yang sal-broker-impl sal-core-demo @@ -33,6 +33,11 @@ slf4j-api 1.7.2 + + junit + junit + 4.10 + @@ -40,7 +45,6 @@ junit junit - 4.10 test true diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/pom.xml index d81c6ac2ff..c195fe4ae2 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/pom.xml @@ -13,6 +13,11 @@ sal-core-api 1.0-SNAPSHOT + + org.opendaylight.controller + sal-common-util + 1.0-SNAPSHOT + org.opendaylight.controller sal-core-spi diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/BrokerImpl.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/BrokerImpl.java index 84bc056950..b8a0b97eab 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/BrokerImpl.java +++ b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/BrokerImpl.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -8,46 +7,55 @@ */ package org.opendaylight.controller.sal.core.impl; +import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; - import org.opendaylight.controller.sal.core.api.Broker; import org.opendaylight.controller.sal.core.api.BrokerService; import org.opendaylight.controller.sal.core.api.Consumer; import org.opendaylight.controller.sal.core.api.Provider; +import org.opendaylight.controller.sal.core.api.RpcImplementation; import org.opendaylight.controller.sal.core.spi.BrokerModule; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.common.RpcResult; -import org.opendaylight.controller.yang.data.api.CompositeNode; +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.common.RpcResult; +import org.opendaylight.controller.yang.data.api.CompositeNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class BrokerImpl implements Broker { private static Logger log = LoggerFactory.getLogger(BrokerImpl.class); - private Set sessions = new HashSet(); - private Set providerSessions = new HashSet(); - // private ExecutorService executor; - private Set modules = new HashSet(); + // Broker Generic Context + private Set sessions = Collections + .synchronizedSet(new HashSet()); + private Set providerSessions = Collections + .synchronizedSet(new HashSet()); + private Set modules = Collections + .synchronizedSet(new HashSet()); + private Map, BrokerModule> serviceProviders = Collections + .synchronizedMap(new HashMap, BrokerModule>()); + + // RPC Context + private Map rpcImpls = Collections + .synchronizedMap(new HashMap()); - private Map, BrokerModule> serviceProviders = new HashMap, BrokerModule>(); + // Implementation specific + private ExecutorService executor; @Override public ConsumerSession registerConsumer(Consumer consumer) { checkPredicates(consumer); log.info("Registering consumer " + consumer); - ConsumerSessionImpl session = newSessionFor(consumer); consumer.onSessionInitiated(session); - sessions.add(session); - return session; - } @Override @@ -56,11 +64,26 @@ public class BrokerImpl implements Broker { ProviderSessionImpl session = newSessionFor(provider); provider.onSessionInitiated(session); - providerSessions.add(session); return session; } + public void addModule(BrokerModule module) { + log.info("Registering broker module " + module); + if (modules.contains(module)) { + log.error("Module already registered"); + throw new IllegalArgumentException("Module already exists."); + } + + Set> provServices = module + .getProvidedServices(); + for (Class serviceType : provServices) { + log.info(" Registering session service implementation: " + + serviceType.getCanonicalName()); + serviceProviders.put(serviceType, module); + } + } + public T serviceFor(Class service, ConsumerSessionImpl session) { BrokerModule prov = serviceProviders.get(service); @@ -71,11 +94,43 @@ public class BrokerImpl implements Broker { return prov.getServiceForSession(service, session); } - public Future> invokeRpc(QName rpc, + // RPC Functionality + + private void addRpcImplementation(QName rpcType, + RpcImplementation implementation) { + synchronized (rpcImpls) { + if (rpcImpls.get(rpcType) != null) { + throw new IllegalStateException("Implementation for rpc " + + rpcType + " is already registered."); + } + rpcImpls.put(rpcType, implementation); + } + // TODO Add notification for availability of Rpc Implementation + } + + private void removeRpcImplementation(QName rpcType, + RpcImplementation implToRemove) { + synchronized (rpcImpls) { + if (implToRemove == rpcImpls.get(rpcType)) { + rpcImpls.remove(rpcType); + } + } + // TODO Add notification for removal of Rpc Implementation + } + + private Future> invokeRpc(QName rpc, CompositeNode input) { - // TODO Implement this method - throw new UnsupportedOperationException("Not implemented"); + RpcImplementation impl = rpcImpls.get(rpc); + // if() + + Callable> call = callableFor(impl, + rpc, input); + Future> result = executor.submit(call); + + return result; } + + // Validation private void checkPredicates(Provider prov) { if (prov == null) @@ -96,34 +151,130 @@ public class BrokerImpl implements Broker { } } + // Private Factory methods + private ConsumerSessionImpl newSessionFor(Consumer cons) { - return new ConsumerSessionImpl(this, cons); + return new ConsumerSessionImpl(cons); } private ProviderSessionImpl newSessionFor(Provider provider) { - return new ProviderSessionImpl(this, provider); + return new ProviderSessionImpl(provider); } - public void addModule(BrokerModule module) { - log.info("Registering broker module " + module); - if (modules.contains(module)) { - log.error("Module already registered"); - throw new IllegalArgumentException("Module already exists."); + private void consumerSessionClosed(ConsumerSessionImpl consumerSessionImpl) { + sessions.remove(consumerSessionImpl); + providerSessions.remove(consumerSessionImpl); + } + + private static Callable> callableFor( + final RpcImplementation implemenation, final QName rpc, + final CompositeNode input) { + + return new Callable>() { + + @Override + public RpcResult call() throws Exception { + return implemenation.invokeRpc(rpc, input); + } + }; + } + + private class ConsumerSessionImpl implements ConsumerSession { + + private final Consumer consumer; + + private Map, BrokerService> instantiatedServices = Collections + .synchronizedMap(new HashMap, BrokerService>()); + private boolean closed = false; + + public Consumer getConsumer() { + return consumer; } - Set> provServices = module - .getProvidedServices(); - for (Class serviceType : provServices) { - log.info(" Registering session service implementation: " - + serviceType.getCanonicalName()); - serviceProviders.put(serviceType, module); + public ConsumerSessionImpl(Consumer consumer) { + this.consumer = consumer; + } + + @Override + public Future> rpc(QName rpc, + CompositeNode input) { + return BrokerImpl.this.invokeRpc(rpc, input); + } + + @Override + public T getService(Class service) { + BrokerService potential = instantiatedServices.get(service); + if (potential != null) { + @SuppressWarnings("unchecked") + T ret = (T) potential; + return ret; + } + T ret = BrokerImpl.this.serviceFor(service, this); + if (ret != null) { + instantiatedServices.put(service, ret); + } + return ret; + } + + @Override + public void close() { + Collection toStop = instantiatedServices.values(); + this.closed = true; + for (BrokerService brokerService : toStop) { + brokerService.closeSession(); + } + BrokerImpl.this.consumerSessionClosed(this); + } + + @Override + public boolean isClosed() { + return closed; } - } - public void consumerSessionClosed(ConsumerSessionImpl consumerSessionImpl) { - sessions.remove(consumerSessionImpl); - providerSessions.remove(consumerSessionImpl); } + private class ProviderSessionImpl extends ConsumerSessionImpl implements + ProviderSession { + + private Provider provider; + private Map sessionRpcImpls = Collections.synchronizedMap(new HashMap()); + + public ProviderSessionImpl(Provider provider) { + super(null); + this.provider = provider; + } + + @Override + public void addRpcImplementation(QName rpcType, + RpcImplementation implementation) + throws IllegalArgumentException { + if (rpcType == null) { + throw new IllegalArgumentException("rpcType must not be null"); + } + if (implementation == null) { + throw new IllegalArgumentException( + "Implementation must not be null"); + } + BrokerImpl.this.addRpcImplementation(rpcType, implementation); + sessionRpcImpls.put(rpcType, implementation); + } + + @Override + public void removeRpcImplementation(QName rpcType, + RpcImplementation implToRemove) throws IllegalArgumentException { + RpcImplementation localImpl = rpcImpls.get(rpcType); + if (localImpl != implToRemove) { + throw new IllegalStateException( + "Implementation was not registered in this session"); + } + + BrokerImpl.this.removeRpcImplementation(rpcType, implToRemove); + sessionRpcImpls.remove(rpcType); + } + + public Provider getProvider() { + return this.provider; + } + + } } - diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/BrokerServiceImpl.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/BrokerServiceImpl.java deleted file mode 100644 index 4f254430bb..0000000000 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/BrokerServiceImpl.java +++ /dev/null @@ -1,16 +0,0 @@ - -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.sal.core.impl; - -import org.opendaylight.controller.sal.core.api.BrokerService; - -abstract public class BrokerServiceImpl implements BrokerService { - - ConsumerSessionImpl session; -} diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/ConsumerSessionImpl.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/ConsumerSessionImpl.java deleted file mode 100644 index 032dd22e3c..0000000000 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/ConsumerSessionImpl.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.sal.core.impl; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.Future; - -import org.opendaylight.controller.sal.core.api.BrokerService; -import org.opendaylight.controller.sal.core.api.Consumer; -import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.common.RpcResult; -import org.opendaylight.controller.yang.data.api.CompositeNode; - - -public class ConsumerSessionImpl implements ConsumerSession { - - private final BrokerImpl broker; - private final Consumer consumer; - - private Map, BrokerService> instantiatedServices = new HashMap, BrokerService>(); - private boolean closed = false; - - public Consumer getConsumer() { - return consumer; - } - - public ConsumerSessionImpl(BrokerImpl broker, Consumer consumer) { - this.broker = broker; - this.consumer = consumer; - } - - @Override - public Future> rpc(QName rpc, CompositeNode input) { - return broker.invokeRpc(rpc, input); - } - - @Override - public T getService(Class service) { - BrokerService potential = instantiatedServices.get(service); - if (potential != null) { - @SuppressWarnings("unchecked") - T ret = (T) potential; - return ret; - } - T ret = this.broker.serviceFor(service, this); - if (ret != null) { - instantiatedServices.put(service, ret); - } - return ret; - } - - @Override - public void close() { - Collection toStop = instantiatedServices.values(); - this.closed = true; - for (BrokerService brokerService : toStop) { - brokerService.closeSession(); - } - broker.consumerSessionClosed(this); - } - - @Override - public boolean isClosed() { - return closed; - } - -} diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/data/DataBrokerModule.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/DataBrokerModule.java similarity index 86% rename from opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/data/DataBrokerModule.java rename to opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/DataBrokerModule.java index 7b93e5f08f..852f6b6e87 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/data/DataBrokerModule.java +++ b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/DataBrokerModule.java @@ -5,7 +5,7 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.controller.sal.core.impl.data; +package org.opendaylight.controller.sal.core.impl; import java.util.ArrayList; import java.util.Collections; @@ -13,9 +13,11 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import org.opendaylight.controller.sal.common.DataStoreIdentifier; +import org.opendaylight.controller.sal.common.util.Rpcs; import org.opendaylight.controller.sal.core.api.BrokerService; import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession; import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; @@ -27,7 +29,6 @@ import org.opendaylight.controller.sal.core.api.data.DataProviderService; import org.opendaylight.controller.sal.core.api.data.DataValidator; import org.opendaylight.controller.sal.core.api.data.DataCommitHandler.CommitTransaction; import org.opendaylight.controller.sal.core.api.data.DataProviderService.DataRefresher; -import org.opendaylight.controller.sal.core.impl.RpcUtils; import org.opendaylight.controller.sal.core.spi.BrokerModule; import org.opendaylight.controller.yang.common.RpcError; import org.opendaylight.controller.yang.common.RpcResult; @@ -36,33 +37,40 @@ import org.opendaylight.controller.yang.data.api.CompositeNodeModification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.collect.ImmutableSet; public class DataBrokerModule implements BrokerModule { private static final Logger log = LoggerFactory .getLogger(DataBrokerModule.class); + private static final Set> SUPPORTED_PROVIDER_FUNCTIONALITY = ImmutableSet + .of((Class) DataValidator.class, + DataRefresher.class, DataCommitHandler.class); + + private static final Set> PROVIDED_SESSION_SERVICES = ImmutableSet + .of((Class) DataBrokerService.class, + DataProviderService.class); + private Map storeContext; + private ExecutorService executor; + private SequentialCommitHandlerCoordinator coordinator = new SequentialCommitHandlerCoordinator(); @Override public Set> getProvidedServices() { - // FIXME: Refactor - Set> ret = new HashSet>(); - ret.add(DataBrokerService.class); - ret.add(DataProviderService.class); - return ret; + return PROVIDED_SESSION_SERVICES; } @Override public Set> getSupportedProviderFunctionality() { - // FIXME Refactor - Set> ret = new HashSet>(); - ret.add(DataValidator.class); - ret.add(DataCommitHandler.class); - ret.add(DataRefresher.class); - return ret; + return SUPPORTED_PROVIDER_FUNCTIONALITY; + } + + @Override + public Set> getSupportedConsumerFunctionality() { + return Collections.emptySet(); } @Override @@ -85,25 +93,24 @@ public class DataBrokerModule implements BrokerModule { } private DataProviderService newDataProviderService(ConsumerSession session) { - // TODO Implement this method - throw new UnsupportedOperationException("Not implemented"); + return new DataProviderSession(); } private DataBrokerService newDataConsumerService(ConsumerSession session) { - // TODO Implement this method - throw new UnsupportedOperationException("Not implemented"); + return new DataConsumerSession(); } - @Override - public Set> getSupportedConsumerFunctionality() { - // TODO Implement this method - throw new UnsupportedOperationException("Not implemented"); + private StoreContext context(DataStoreIdentifier store) { + return storeContext.get(store); } private static class StoreContext { - private Set commitHandlers = new HashSet(); - private Set validators = new HashSet(); - private Set refreshers = new HashSet(); + private Set commitHandlers = Collections + .synchronizedSet(new HashSet()); + private Set validators = Collections + .synchronizedSet(new HashSet()); + private Set refreshers = Collections + .synchronizedSet(new HashSet()); } private class DataConsumerSession implements DataBrokerService { @@ -153,10 +160,12 @@ public class DataBrokerModule implements BrokerModule { throw new UnsupportedOperationException("Not implemented"); } - } + @Override + public Set getDataStores() { + // TODO Auto-generated method stub + return null; + } - private StoreContext context(DataStoreIdentifier store) { - return storeContext.get(store); } private class DataProviderSession extends DataConsumerSession implements @@ -265,7 +274,7 @@ public class DataBrokerModule implements BrokerModule { } CommitTransaction transaction = new SequentialCommitTransaction( store, transactions); - return RpcUtils.getRpcResult(successful, transaction, errors); + return Rpcs.getRpcResult(successful, transaction, errors); } @Override @@ -306,7 +315,7 @@ public class DataBrokerModule implements BrokerModule { break; } - return RpcUtils.getRpcResult(successful, null, errors); + return Rpcs.getRpcResult(successful, null, errors); } @Override @@ -330,7 +339,7 @@ public class DataBrokerModule implements BrokerModule { break; } - return RpcUtils.getRpcResult(successful, null, errors); + return Rpcs.getRpcResult(successful, null, errors); } @Override @@ -374,7 +383,7 @@ public class DataBrokerModule implements BrokerModule { break; } - return RpcUtils.getRpcResult(successful, null, errors); + return Rpcs.getRpcResult(successful, null, errors); } @Override @@ -408,4 +417,3 @@ public class DataBrokerModule implements BrokerModule { } } } - diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/notify/NotificationModule.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/NotificationModule.java similarity index 86% rename from opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/notify/NotificationModule.java rename to opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/NotificationModule.java index 8f9632be9e..e5077967d7 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/notify/NotificationModule.java +++ b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/NotificationModule.java @@ -22,7 +22,6 @@ import org.opendaylight.controller.sal.core.api.Provider.ProviderFunctionality; import org.opendaylight.controller.sal.core.api.notify.NotificationListener; import org.opendaylight.controller.sal.core.api.notify.NotificationProviderService; import org.opendaylight.controller.sal.core.api.notify.NotificationService; -import org.opendaylight.controller.sal.core.impl.BrokerServiceImpl; import org.opendaylight.controller.sal.core.spi.BrokerModule; import org.opendaylight.controller.yang.common.QName; import org.opendaylight.controller.yang.data.api.CompositeNode; @@ -40,21 +39,25 @@ public class NotificationModule implements BrokerModule { private Multimap listeners = HashMultimap .create(); - private static final Set> providedServices = ImmutableSet + private static final Set> PROVIDED_SERVICE_TYPE = ImmutableSet .of((Class) NotificationService.class, NotificationProviderService.class); + private static final Set> SUPPORTED_CONSUMER_FUNCTIONALITY = ImmutableSet + .of((Class) NotificationListener.class, + NotificationListener.class); // Workaround: if we use the + // version of method with only + // one argument, the generics + // inference will not work + @Override public Set> getProvidedServices() { - return providedServices; + return PROVIDED_SERVICE_TYPE; } @Override public Set> getSupportedConsumerFunctionality() { - // FIXME Refactor - Set> ret = new HashSet>(); - ret.add(NotificationListener.class); - return ret; + return SUPPORTED_CONSUMER_FUNCTIONALITY; } @Override @@ -107,8 +110,8 @@ public class NotificationModule implements BrokerModule { return new NotificationProviderSessionImpl(); } - private class NotificationConsumerSessionImpl extends BrokerServiceImpl - implements NotificationService { + private class NotificationConsumerSessionImpl implements + NotificationService { private Multimap consumerListeners = HashMultimap .create(); diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/ProviderSessionImpl.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/ProviderSessionImpl.java deleted file mode 100644 index e87b8bbbb1..0000000000 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/ProviderSessionImpl.java +++ /dev/null @@ -1,48 +0,0 @@ - -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.sal.core.impl; - -import java.util.Set; - -import org.opendaylight.controller.sal.core.api.Provider; -import org.opendaylight.controller.sal.core.api.RpcImplementation; -import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; -import org.opendaylight.controller.yang.common.QName; - - -public class ProviderSessionImpl extends ConsumerSessionImpl implements - ProviderSession { - - private Provider provider; - - public ProviderSessionImpl(BrokerImpl broker, Provider provider) { - super(broker, null); - this.provider = provider; - } - - @Override - public void addRpcImplementation(QName rpcType, - RpcImplementation implementation) throws IllegalArgumentException { - // TODO Implement this method - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public void removeRpcImplementation(QName rpcType, - RpcImplementation implementation) throws IllegalArgumentException { - // TODO Implement this method - throw new UnsupportedOperationException("Not implemented"); - } - - public Provider getProvider() { - return this.provider; - } - -} - diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/data/package-info.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/data/package-info.java deleted file mode 100644 index 34fa5e4658..0000000000 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/data/package-info.java +++ /dev/null @@ -1,10 +0,0 @@ - -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.core.impl.data; \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/notify/package-info.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/notify/package-info.java deleted file mode 100644 index c068196bde..0000000000 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/notify/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.core.impl.notify; \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/rpc/RpcModule.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/rpc/RpcModule.java deleted file mode 100644 index 58ceb5f51b..0000000000 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/rpc/RpcModule.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.opendaylight.controller.sal.core.impl.rpc; - -public interface RpcModule { - -} diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/rpc/package-info.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/rpc/package-info.java deleted file mode 100644 index 41e9bcbd27..0000000000 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/rpc/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.sal.core.impl.rpc; \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-common-util/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-common-util/pom.xml new file mode 100644 index 0000000000..b8be514c02 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-common-util/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + org.opendaylight.controller + sal + 1.0-SNAPSHOT + + sal-common-util + + + + org.opendaylight.controller + yang-common + 1.0 + + + org.opendaylight.controller + sal-common + 1.0-SNAPSHOT + + + + \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/RpcUtils.java b/opendaylight/sal/yang-prototype/sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/Rpcs.java similarity index 60% rename from opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/RpcUtils.java rename to opendaylight/sal/yang-prototype/sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/Rpcs.java index 6edb981219..d397bff0d6 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/RpcUtils.java +++ b/opendaylight/sal/yang-prototype/sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/Rpcs.java @@ -5,38 +5,17 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.controller.sal.core.impl; +package org.opendaylight.controller.sal.common.util; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.List; -import java.util.concurrent.Callable; - -import org.opendaylight.controller.sal.core.api.RpcImplementation; -import org.opendaylight.controller.yang.common.QName; import org.opendaylight.controller.yang.common.RpcError; import org.opendaylight.controller.yang.common.RpcResult; -import org.opendaylight.controller.yang.data.api.CompositeNode; - - -public class RpcUtils { - - Callable> callableFor( - final RpcImplementation implemenation, final QName rpc, - final CompositeNode input) { - - return new Callable>() { - - @Override - public RpcResult call() throws Exception { - return implemenation.invokeRpc(rpc, input); - } - }; - } +public class Rpcs { public static RpcResult getRpcResult(boolean successful, T result, - List errors) { + Collection errors) { RpcResult ret = new RpcResultTO(successful, result, errors); return ret; } @@ -47,7 +26,8 @@ public class RpcUtils { private final T result; private final boolean successful; - public RpcResultTO(boolean successful, T result, List errors) { + public RpcResultTO(boolean successful, T result, + Collection errors) { this.successful = successful; this.result = result; this.errors = Collections.unmodifiableList(new ArrayList( @@ -71,4 +51,3 @@ public class RpcUtils { } } - diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-core-api/pom.xml index abdd3ad656..7ced1746fc 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/pom.xml @@ -1,27 +1,29 @@ - - 4.0.0 - - org.opendaylight.controller - sal - 1.0-SNAPSHOT - - sal-core-api - - - - org.opendaylight.controller - sal-common - 1.0-SNAPSHOT - - - org.opendaylight.controller - yang-data-api - 1.0 - - - org.opendaylight.controller - yang-model-api - 1.0 - - + + 4.0.0 + + org.opendaylight.controller + sal + 1.0-SNAPSHOT + + sal-core-api + + + + org.opendaylight.controller + sal-common + 1.0-SNAPSHOT + + + + org.opendaylight.controller + yang-data-api + 1.0 + + + org.opendaylight.controller + yang-model-api + 1.0 + + \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataBrokerService.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataBrokerService.java index f5f393852e..d74a7d146d 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataBrokerService.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataBrokerService.java @@ -7,6 +7,7 @@ */ package org.opendaylight.controller.sal.core.api.data; +import java.util.Set; import java.util.concurrent.Future; import org.opendaylight.controller.sal.common.DataStoreIdentifier; @@ -29,6 +30,9 @@ import org.opendaylight.controller.yang.data.api.Node; */ public interface DataBrokerService extends BrokerService { + + Set getDataStores(); + /** * Returns a data from specified Data Store. * diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/model/SchemaService.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/model/SchemaService.java new file mode 100644 index 0000000000..22abdc2a00 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/model/SchemaService.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.sal.core.api.model; + +import org.opendaylight.controller.sal.core.api.BrokerService; +import org.opendaylight.controller.yang.model.api.Module; +import org.opendaylight.controller.yang.model.api.SchemaContext; + +public interface SchemaService extends BrokerService { + + /** + * Registers a YANG module to session and global context + * + * @param module + */ + void addModule(Module module); + + /** + * Unregisters a YANG module from session context + * + * @param module + */ + void removeModule(Module module); + + /** + * Returns session specific YANG schema context + * @return + */ + SchemaContext getSessionContext(); + + /** + * Returns global schema context + * + * @return + */ + SchemaContext getGlobalContext(); +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-demo/src/main/java/org/opendaylight/controller/sal/demo/SALDemo.java b/opendaylight/sal/yang-prototype/sal/sal-core-demo/src/main/java/org/opendaylight/controller/sal/demo/SALDemo.java index b582349f54..fa0ea393ab 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-demo/src/main/java/org/opendaylight/controller/sal/demo/SALDemo.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-demo/src/main/java/org/opendaylight/controller/sal/demo/SALDemo.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.io.InputStreamReader; import org.opendaylight.controller.sal.core.impl.BrokerImpl; -import org.opendaylight.controller.sal.core.impl.notify.NotificationModule; +import org.opendaylight.controller.sal.core.impl.NotificationModule; public class SALDemo {