Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.config.impl; |
| 17 | |
Sithara Punnassery | 0620879 | 2017-02-10 16:25:29 -0800 | [diff] [blame] | 18 | import com.google.common.annotations.Beta; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 24 | import org.apache.felix.scr.annotations.Service; |
| 25 | import org.onosproject.config.DynamicConfigEvent; |
| 26 | import org.onosproject.config.DynamicConfigListener; |
| 27 | import org.onosproject.config.DynamicConfigService; |
| 28 | import org.onosproject.config.DynamicConfigStore; |
| 29 | import org.onosproject.config.DynamicConfigStoreDelegate; |
| 30 | import org.onosproject.config.FailedException; |
| 31 | import org.onosproject.config.Filter; |
| 32 | import org.onosproject.config.RpcCaller; |
| 33 | import org.onosproject.config.RpcCommand; |
| 34 | import org.onosproject.config.RpcHandler; |
| 35 | import org.onosproject.config.RpcInput; |
| 36 | import org.onosproject.config.RpcOutput; |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 37 | import org.onosproject.yang.model.DataNode; |
| 38 | import org.onosproject.yang.model.ResourceId; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 39 | import org.onosproject.event.AbstractListenerManager; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 40 | import org.slf4j.Logger; |
| 41 | |
| 42 | import static org.slf4j.LoggerFactory.getLogger; |
| 43 | |
| 44 | /** |
| 45 | * Demo application to use the DynamicConfig Service and DynamicConfigStore. |
| 46 | * |
| 47 | */ |
Sithara Punnassery | 0620879 | 2017-02-10 16:25:29 -0800 | [diff] [blame] | 48 | @Beta |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 49 | @Component(immediate = true) |
| 50 | @Service |
| 51 | public 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 Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 57 | protected DynamicConfigStore store; |
| 58 | |
| 59 | @Activate |
| 60 | public void activate() { |
| 61 | store.setDelegate(storeDelegate); |
Sithara Punnassery | 43833e1 | 2017-03-14 16:29:19 -0700 | [diff] [blame] | 62 | eventDispatcher.addSink(DynamicConfigEvent.class, listenerRegistry); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 63 | log.info("DynamicConfigService Started"); |
| 64 | } |
| 65 | |
| 66 | @Deactivate |
| 67 | public void deactivate() { |
| 68 | store.unsetDelegate(storeDelegate); |
Sithara Punnassery | 43833e1 | 2017-03-14 16:29:19 -0700 | [diff] [blame] | 69 | eventDispatcher.removeSink(DynamicConfigEvent.class); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 70 | log.info("DynamicConfigService Stopped"); |
| 71 | } |
| 72 | |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 73 | public void createNodeRecursive(ResourceId path, DataNode node) { |
| 74 | Boolean stat = false; |
Sithara Punnassery | 4cd2ced | 2017-03-17 17:36:43 -0700 | [diff] [blame] | 75 | stat = this.store.addNode(path, node).join(); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | public DataNode readNode(ResourceId path, Filter filter) { |
| 79 | return store.readNode(path, filter).join(); |
| 80 | } |
| 81 | |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 82 | public void updateNode(ResourceId path, DataNode node) { |
| 83 | throw new FailedException("Not yet implemented"); |
| 84 | } |
| 85 | |
| 86 | public void deleteNode(ResourceId path) { |
| 87 | throw new FailedException("Not yet implemented"); |
| 88 | } |
| 89 | |
| 90 | public void deleteNodeRecursive(ResourceId path) { |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 91 | store.deleteNodeRecursive(path).join(); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | public void updateNodeRecursive(ResourceId path, DataNode node) { |
| 95 | throw new FailedException("Not yet implemented"); |
| 96 | } |
| 97 | |
| 98 | public void replaceNode(ResourceId path, DataNode node) { |
| 99 | throw new FailedException("Not yet implemented"); |
| 100 | } |
Sithara Punnassery | 43833e1 | 2017-03-14 16:29:19 -0700 | [diff] [blame] | 101 | |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 102 | public Integer getNumberOfChildren(ResourceId path, Filter filter) { |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 103 | throw new FailedException("Not yet implemented"); |
| 104 | } |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 105 | |
| 106 | public void registerHandler(RpcHandler handler, RpcCommand command) { |
| 107 | throw new FailedException("Not yet implemented"); |
| 108 | } |
| 109 | |
| 110 | public void unRegisterHandler(RpcHandler handler, RpcCommand command) { |
| 111 | //check obj1.getClass().equals(obj2.getClass()) |
| 112 | throw new FailedException("Not yet implemented"); |
| 113 | } |
| 114 | |
| 115 | public void invokeRpc(RpcCaller caller, Integer msgId, RpcCommand command, RpcInput input) { |
| 116 | throw new FailedException("Not yet implemented"); |
| 117 | } |
| 118 | |
| 119 | public void rpcResponse(Integer msgId, RpcOutput output) { |
| 120 | throw new FailedException("Not yet implemented"); |
| 121 | } |
| 122 | /** |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 123 | * Auxiliary store delegate to receive notification about changes in the store. |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 124 | */ |
| 125 | private class InternalStoreDelegate implements DynamicConfigStoreDelegate { |
| 126 | public void notify(DynamicConfigEvent event) { |
Sithara Punnassery | 43833e1 | 2017-03-14 16:29:19 -0700 | [diff] [blame] | 127 | post(event); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | } |