blob: 938734d3cebb73aa94da87389f567e2bd0ffe2fd [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;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080040import org.slf4j.Logger;
41
42import static org.slf4j.LoggerFactory.getLogger;
43
44/**
45 * Demo application to use the DynamicConfig Service and DynamicConfigStore.
46 *
47 */
Sithara Punnassery06208792017-02-10 16:25:29 -080048@Beta
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080049@Component(immediate = true)
50@Service
51public class DynamicConfigManager
52 extends AbstractListenerManager<DynamicConfigEvent, DynamicConfigListener>
53 implements DynamicConfigService {
54 private final Logger log = getLogger(getClass());
55 private final DynamicConfigStoreDelegate storeDelegate = new InternalStoreDelegate();
56 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080057 protected DynamicConfigStore store;
58
59 @Activate
60 public void activate() {
61 store.setDelegate(storeDelegate);
Sithara Punnassery43833e12017-03-14 16:29:19 -070062 eventDispatcher.addSink(DynamicConfigEvent.class, listenerRegistry);
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080063 log.info("DynamicConfigService Started");
64 }
65
66 @Deactivate
67 public void deactivate() {
68 store.unsetDelegate(storeDelegate);
Sithara Punnassery43833e12017-03-14 16:29:19 -070069 eventDispatcher.removeSink(DynamicConfigEvent.class);
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080070 log.info("DynamicConfigService Stopped");
71 }
72
73 @Override
74 public void createNode(ResourceId path, DataNode node) {
Sithara Punnassery4b091dc2017-03-02 17:22:40 -080075 throw new FailedException("Not yet implemented");
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080076 }
77
78 public void createNodeRecursive(ResourceId path, DataNode node) {
79 Boolean stat = false;
80 stat = this.store.addRecursive(path, node).join();
81 }
82
83 public DataNode readNode(ResourceId path, Filter filter) {
84 return store.readNode(path, filter).join();
85 }
86
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080087 public void updateNode(ResourceId path, DataNode node) {
88 throw new FailedException("Not yet implemented");
89 }
90
91 public void deleteNode(ResourceId path) {
92 throw new FailedException("Not yet implemented");
93 }
94
95 public void deleteNodeRecursive(ResourceId path) {
Sithara Punnassery4b091dc2017-03-02 17:22:40 -080096 store.deleteNodeRecursive(path).join();
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080097 }
98
99 public void updateNodeRecursive(ResourceId path, DataNode node) {
100 throw new FailedException("Not yet implemented");
101 }
102
103 public void replaceNode(ResourceId path, DataNode node) {
104 throw new FailedException("Not yet implemented");
105 }
Sithara Punnassery43833e12017-03-14 16:29:19 -0700106
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800107 public Integer getNumberOfChildren(ResourceId path, Filter filter) {
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800108 throw new FailedException("Not yet implemented");
109 }
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800110
111 public void registerHandler(RpcHandler handler, RpcCommand command) {
112 throw new FailedException("Not yet implemented");
113 }
114
115 public void unRegisterHandler(RpcHandler handler, RpcCommand command) {
116 //check obj1.getClass().equals(obj2.getClass())
117 throw new FailedException("Not yet implemented");
118 }
119
120 public void invokeRpc(RpcCaller caller, Integer msgId, RpcCommand command, RpcInput input) {
121 throw new FailedException("Not yet implemented");
122 }
123
124 public void rpcResponse(Integer msgId, RpcOutput output) {
125 throw new FailedException("Not yet implemented");
126 }
127 /**
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800128 * Auxiliary store delegate to receive notification about changes in the store.
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800129 */
130 private class InternalStoreDelegate implements DynamicConfigStoreDelegate {
131 public void notify(DynamicConfigEvent event) {
Sithara Punnassery43833e12017-03-14 16:29:19 -0700132 post(event);
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800133 }
134 }
135}