blob: c79d42aea0d3841a62f56738ff27d8b6fec43e7e [file] [log] [blame]
Sithara Punnassery9306e6b2017-02-06 15:38:19 -08001/*
2 * Copyright 2016-present Open Networking Laboratory
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 */
16package org.onosproject.config.impl;
17
Sithara Punnassery06208792017-02-10 16:25:29 -080018import com.google.common.annotations.Beta;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080019import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
24import org.apache.felix.scr.annotations.Service;
25import org.onosproject.config.DynamicConfigEvent;
26import org.onosproject.config.DynamicConfigListener;
27import org.onosproject.config.DynamicConfigService;
28import org.onosproject.config.DynamicConfigStore;
29import org.onosproject.config.DynamicConfigStoreDelegate;
30import org.onosproject.config.FailedException;
31import org.onosproject.config.Filter;
32import org.onosproject.config.RpcCaller;
33import org.onosproject.config.RpcCommand;
34import org.onosproject.config.RpcHandler;
35import org.onosproject.config.RpcInput;
36import org.onosproject.config.RpcOutput;
Sithara Punnassery4b091dc2017-03-02 17:22:40 -080037import org.onosproject.yang.model.DataNode;
38import org.onosproject.yang.model.ResourceId;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080039import org.onosproject.event.AbstractListenerManager;
40import org.onosproject.event.EventDeliveryService;
41import org.slf4j.Logger;
42
Sithara Punnassery44e2a702017-03-06 15:38:10 -080043import java.util.Collection;
44
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080045import static org.slf4j.LoggerFactory.getLogger;
46
47/**
48 * Demo application to use the DynamicConfig Service and DynamicConfigStore.
49 *
50 */
Sithara Punnassery06208792017-02-10 16:25:29 -080051@Beta
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080052@Component(immediate = true)
53@Service
54public class DynamicConfigManager
55 extends AbstractListenerManager<DynamicConfigEvent, DynamicConfigListener>
56 implements DynamicConfigService {
57 private final Logger log = getLogger(getClass());
58 private final DynamicConfigStoreDelegate storeDelegate = new InternalStoreDelegate();
59 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
60 protected EventDeliveryService eventDispatcher;
61 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
62 protected DynamicConfigStore store;
63
64 @Activate
65 public void activate() {
66 store.setDelegate(storeDelegate);
67 log.info("DynamicConfigService Started");
68 }
69
70 @Deactivate
71 public void deactivate() {
72 store.unsetDelegate(storeDelegate);
73 log.info("DynamicConfigService Stopped");
74 }
75
76 @Override
77 public void createNode(ResourceId path, DataNode node) {
Sithara Punnassery4b091dc2017-03-02 17:22:40 -080078 throw new FailedException("Not yet implemented");
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080079 }
80
81 public void createNodeRecursive(ResourceId path, DataNode node) {
82 Boolean stat = false;
83 stat = this.store.addRecursive(path, node).join();
84 }
85
86 public DataNode readNode(ResourceId path, Filter filter) {
87 return store.readNode(path, filter).join();
88 }
89
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080090 public void updateNode(ResourceId path, DataNode node) {
91 throw new FailedException("Not yet implemented");
92 }
93
94 public void deleteNode(ResourceId path) {
95 throw new FailedException("Not yet implemented");
96 }
97
98 public void deleteNodeRecursive(ResourceId path) {
Sithara Punnassery4b091dc2017-03-02 17:22:40 -080099 store.deleteNodeRecursive(path).join();
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800100 }
101
102 public void updateNodeRecursive(ResourceId path, DataNode node) {
103 throw new FailedException("Not yet implemented");
104 }
105
106 public void replaceNode(ResourceId path, DataNode node) {
107 throw new FailedException("Not yet implemented");
108 }
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800109 public Integer getNumberOfChildren(ResourceId path, Filter filter) {
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800110 throw new FailedException("Not yet implemented");
111 }
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800112 public void addConfigListener(ResourceId path, DynamicConfigListener listener) {
113 store.addConfigListener(path, listener);
114 }
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800115
116 public void removeConfigListener(ResourceId path, DynamicConfigListener listener) {
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800117 store.removeConfigListener(path, listener);
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800118 }
119
120 public void registerHandler(RpcHandler handler, RpcCommand command) {
121 throw new FailedException("Not yet implemented");
122 }
123
124 public void unRegisterHandler(RpcHandler handler, RpcCommand command) {
125 //check obj1.getClass().equals(obj2.getClass())
126 throw new FailedException("Not yet implemented");
127 }
128
129 public void invokeRpc(RpcCaller caller, Integer msgId, RpcCommand command, RpcInput input) {
130 throw new FailedException("Not yet implemented");
131 }
132
133 public void rpcResponse(Integer msgId, RpcOutput output) {
134 throw new FailedException("Not yet implemented");
135 }
136 /**
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800137 * Auxiliary store delegate to receive notification about changes in the store.
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800138 */
139 private class InternalStoreDelegate implements DynamicConfigStoreDelegate {
140 public void notify(DynamicConfigEvent event) {
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800141 ResourceId path = event.subject();
142 Collection<? extends DynamicConfigListener> lstnrs = store.getConfigListener(path);
143 if (lstnrs != null) {
144 for (DynamicConfigListener l : lstnrs) {
145 l.event(event);
146 }
147 } else {
148 log.info("InternalStoreDelegate: no Listeners");
149 }
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800150 }
151 }
152}