2 * Copyright (c) 2015 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.v3po.impl;
19 import com.google.common.base.Optional;
20 import com.google.common.collect.Maps;
21 import com.google.common.util.concurrent.CheckedFuture;
22 import com.google.common.util.concurrent.Futures;
24 import javax.annotation.Nonnull;
25 import javax.annotation.Nullable;
26 import javax.annotation.concurrent.NotThreadSafe;
27 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
28 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
29 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
30 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
31 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
32 import org.opendaylight.controller.md.sal.dom.api.DOMRpcAvailabilityListener;
33 import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
34 import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException;
35 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
36 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
37 import org.opendaylight.controller.sal.core.api.Broker;
38 import org.opendaylight.controller.sal.core.api.BrokerService;
39 import org.opendaylight.controller.sal.core.api.Consumer;
40 import org.opendaylight.controller.sal.core.api.Provider;
41 import org.opendaylight.controller.sal.core.api.model.SchemaService;
42 import org.opendaylight.controller.sal.core.api.mount.MountProvisionListener;
43 import org.opendaylight.yangtools.concepts.ListenerRegistration;
44 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
45 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
46 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
47 import org.osgi.framework.BundleContext;
50 * Implementation of dom broker to facade VPP pipeline for northbound APIs
52 public class NorthboundFacadeHoneycombDOMBroker implements AutoCloseable, Broker {
54 private static final BrokerService EMPTY_DOM_RPC_SERVICE = new EmptyDomRpcService();
55 private static final BrokerService EMPTY_DOM_MOUNT_SERVICE = new EmptyDomMountService();
57 private Map<Class<? extends BrokerService>, BrokerService> services;
59 public NorthboundFacadeHoneycombDOMBroker(@Nonnull final DOMDataBroker domDataBrokerDependency,
60 @Nonnull final SchemaService schemaBiService,
61 @Nonnull final DOMNotificationService domNotificatioNService) {
62 services = Maps.newHashMap();
63 services.put(DOMDataBroker.class, domDataBrokerDependency);
64 // All services below are required to be present by Restconf northbound
65 services.put(SchemaService.class, schemaBiService);
66 services.put(DOMRpcService.class, EMPTY_DOM_RPC_SERVICE);
67 services.put(DOMMountPointService.class, EMPTY_DOM_MOUNT_SERVICE);
68 services.put(DOMNotificationService.class, domNotificatioNService);
69 // TODO do both notification service types have to be registered ?
70 services.put(DOMNotificationPublishService.class, domNotificatioNService);
74 public void close() throws Exception {
79 public ConsumerSession registerConsumer(final Consumer consumer) {
80 final SimpleConsumerSession session = new SimpleConsumerSession(services);
81 consumer.onSessionInitiated(session);
87 public ConsumerSession registerConsumer(final Consumer consumer, final BundleContext bundleContext) {
88 throw new UnsupportedOperationException();
92 public ProviderSession registerProvider(final Provider provider) {
93 final SimpleProviderSession session = new SimpleProviderSession(services);
94 provider.onSessionInitiated(session);
99 public ProviderSession registerProvider(final Provider provider, final BundleContext bundleContext) {
100 throw new UnsupportedOperationException();
104 private static class SimpleConsumerSession implements ConsumerSession {
105 private boolean closed;
106 private final Map<Class<? extends BrokerService>, BrokerService> services;
108 private SimpleConsumerSession(final Map<Class<? extends BrokerService>, BrokerService> services) {
109 this.services = services;
113 public boolean isClosed() {
118 public <T extends BrokerService> T getService(final Class<T> aClass) {
119 return (T)services.get(aClass);
123 public void close() {
129 private static class SimpleProviderSession implements ProviderSession {
130 private boolean closed;
131 private final Map<Class<? extends BrokerService>, BrokerService> services;
133 private SimpleProviderSession(final Map<Class<? extends BrokerService>, BrokerService> services) {
134 this.services = services;
138 public boolean isClosed() {
143 public <T extends BrokerService> T getService(final Class<T> aClass) {
144 return (T)services.get(aClass);
148 public void close() {
153 private static class EmptyDomRpcService implements DOMRpcService {
156 public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(@Nonnull final SchemaPath schemaPath,
157 @Nullable final NormalizedNode<?, ?> normalizedNode) {
158 return Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(
159 new DOMRpcImplementationNotAvailableException("RPCs not supported"));
164 public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(@Nonnull final T t) {
165 return new ListenerRegistration<T>() {
167 public void close() {
172 public T getInstance() {
179 private static class EmptyDomMountService implements DOMMountPointService {
181 public Optional<DOMMountPoint> getMountPoint(final YangInstanceIdentifier yangInstanceIdentifier) {
182 return Optional.absent();
186 public DOMMountPointBuilder createMountPoint(final YangInstanceIdentifier yangInstanceIdentifier) {
187 throw new UnsupportedOperationException("No mountpoint support");
191 public ListenerRegistration<MountProvisionListener> registerProvisionListener(
192 final MountProvisionListener mountProvisionListener) {
193 return new ListenerRegistration<MountProvisionListener>() {
195 public void close() {
200 public MountProvisionListener getInstance() {
201 return mountProvisionListener;