Honeynode test tool
[transportpce.git] / tests / honeynode / minimal-distribution-core / src / main / java / io / fd / honeycomb / infra / distro / data / HoneycombNotificationManagerProvider.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package io.fd.honeycomb.infra.distro.data;
18
19 import com.google.common.collect.Lists;
20 import com.google.inject.Inject;
21 import io.fd.honeycomb.binding.init.ProviderTrait;
22 import io.fd.honeycomb.notification.ManagedNotificationProducer;
23 import io.fd.honeycomb.notification.NotificationCollector;
24 import io.fd.honeycomb.notification.impl.HoneycombNotificationCollector;
25 import io.fd.honeycomb.notification.impl.NotificationProducerRegistry;
26 import io.fd.honeycomb.notification.impl.NotificationProducerTracker;
27 import java.util.HashSet;
28 import java.util.Set;
29 import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationPublishServiceAdapter;
30 import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec;
31 import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter;
32
33 public final class HoneycombNotificationManagerProvider extends ProviderTrait<NotificationCollector> {
34
35     @Inject
36     private DOMNotificationRouter notificationRouter;
37     @Inject(optional = true)
38     private Set<ManagedNotificationProducer> notificationProducers = new HashSet<>();
39     @Inject
40     private BindingToNormalizedNodeCodec codec;
41
42     @Override
43     protected HoneycombNotificationCollector create() {
44         // Create the registry to keep track of what'OPERATIONAL registered
45         NotificationProducerRegistry notificationProducerRegistry =
46                 new NotificationProducerRegistry(Lists.newArrayList(notificationProducers));
47
48         // Create BA version of notification service (implementation is free from ODL)
49         BindingDOMNotificationPublishServiceAdapter bindingDOMNotificationPublishServiceAdapter =
50                 new BindingDOMNotificationPublishServiceAdapter(codec, notificationRouter);
51
52         // Create Collector on top of BA notification service and registry
53         HoneycombNotificationCollector honeycombNotificationCollector =
54                 new HoneycombNotificationCollector(bindingDOMNotificationPublishServiceAdapter,
55                         notificationProducerRegistry);
56
57         // Create tracker, responsible for starting and stopping registered notification producers whenever necessary
58         NotificationProducerTracker notificationProducerTracker =
59                 new NotificationProducerTracker(notificationProducerRegistry, honeycombNotificationCollector,
60                         notificationRouter);
61
62         // DOMNotificationService is already provided by DOMBroker injected into RESTCONF, however RESTCONF
63         // only supports data-change notification, nothing else. So currently (Beryllium-SR2) honeycomb notifications
64         // won't be available over RESTCONF.
65
66         return honeycombNotificationCollector;
67     }
68 }