blob: b9ea3a862d0ae8adfc5246ab5e90adbf60986572 [file] [log] [blame]
Bharat saraswalf53b29a2016-09-27 15:35:15 +05301/*
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
17package org.onosproject.yms.app.ymsm;
18
19import 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.core.ApplicationId;
26import org.onosproject.core.CoreService;
27import org.onosproject.core.IdGenerator;
sonu gupta1bb37b82016-11-11 16:51:18 +053028import org.onosproject.yms.app.ydt.DefaultYdtWalker;
29import org.onosproject.yms.app.ydt.YangRequestWorkBench;
Bharat saraswalf53b29a2016-09-27 15:35:15 +053030import org.onosproject.yms.app.ynh.YangNotificationExtendedService;
31import org.onosproject.yms.app.ysr.DefaultYangSchemaRegistry;
32import org.onosproject.yms.app.ysr.YangSchemaRegistry;
33import org.onosproject.yms.ych.YangCodecHandler;
34import org.onosproject.yms.ych.YangDataTreeCodec;
35import org.onosproject.yms.ych.YangProtocolEncodingFormat;
36import org.onosproject.yms.ydt.YdtBuilder;
37import org.onosproject.yms.ydt.YdtResponse;
38import org.onosproject.yms.ydt.YdtWalker;
39import org.onosproject.yms.ydt.YmsOperationType;
40import org.onosproject.yms.ymsm.YmsService;
41import org.onosproject.yms.ynh.YangNotificationService;
42import org.onosproject.yms.ysr.YangModuleIdentifier;
43import org.onosproject.yms.ysr.YangModuleLibrary;
44import org.slf4j.Logger;
45import org.slf4j.LoggerFactory;
46
47import java.util.List;
48import java.util.concurrent.ExecutorService;
49import java.util.concurrent.Executors;
50
51import static org.onlab.util.Tools.groupedThreads;
52
53/**
54 * Represents implementation of YANG management system manager.
55 */
56@Service
57@Component(immediate = true)
58public class YmsManager
59 implements YmsService {
60
61 private final Logger log = LoggerFactory.getLogger(getClass());
62
63 private static final String APP_ID = "org.onosproject.app.yms";
64 private static final String MODULE_ID = "module-id";
65 private ApplicationId appId;
66 private YangSchemaRegistry schemaRegistry;
67 //module id generator should be used to generate a new module id for
68 //each YSR instance. So YCH also should generate it.
69 private IdGenerator moduleIdGenerator;
70 private ExecutorService schemaRegistryExecutor;
71 private YangNotificationExtendedService ynhExtendedService;
72
73 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
74 protected CoreService coreService;
75
76 @Activate
77 public void activate() {
78 appId = coreService.registerApplication(APP_ID);
79 moduleIdGenerator = coreService.getIdGenerator(MODULE_ID);
80 schemaRegistry = new DefaultYangSchemaRegistry(String.valueOf(
81 moduleIdGenerator.getNewId()));
82 schemaRegistryExecutor =
83 Executors.newSingleThreadExecutor(groupedThreads(
84 "onos/apps/yang-management-system/schema-registry",
85 "schema-registry-handler", log));
86 log.info("Started");
87 }
88
89 @Deactivate
90 public void deactivate() {
91 ((DefaultYangSchemaRegistry) schemaRegistry).flushYsrData();
92 schemaRegistryExecutor.shutdown();
93
94 // TODO implementation for other components.
95 log.info("Stopped");
96 }
97
98 @Override
99 public YdtBuilder getYdtBuilder(String logicalRootName,
100 String rootNamespace,
101 YmsOperationType operationType) {
sonu gupta1bb37b82016-11-11 16:51:18 +0530102 return new YangRequestWorkBench(logicalRootName, rootNamespace,
103 operationType, schemaRegistry, true);
Bharat saraswalf53b29a2016-09-27 15:35:15 +0530104 }
105
106 @Override
107 public YdtBuilder getYdtBuilder(String logicalRootName,
108 String rootNamespace,
109 YmsOperationType operationType,
110 Object schemaRegistryForYdt) {
sonu gupta1bb37b82016-11-11 16:51:18 +0530111 if (schemaRegistryForYdt != null) {
112 return new YangRequestWorkBench(logicalRootName, rootNamespace,
113 operationType,
114 (YangSchemaRegistry)
115 schemaRegistryForYdt,
116 false);
117 }
118 return new YangRequestWorkBench(logicalRootName, rootNamespace,
119 operationType, schemaRegistry, true);
Bharat saraswalf53b29a2016-09-27 15:35:15 +0530120 }
121
122 @Override
123 public YdtWalker getYdtWalker() {
sonu gupta1bb37b82016-11-11 16:51:18 +0530124 return new DefaultYdtWalker();
Bharat saraswalf53b29a2016-09-27 15:35:15 +0530125 }
126
127 @Override
128 public YdtResponse executeOperation(YdtBuilder operationRequest) {
129 return null;
130 }
131
132 @Override
133 public YangNotificationService getYangNotificationService() {
134 return ynhExtendedService;
135 }
136
137 /**
138 * Returns YANG notification extended service.
139 *
140 * @return YANG notification extended service
141 */
142 private YangNotificationExtendedService getYnhExtendedService() {
143 return ynhExtendedService;
144 }
145
146 @Override
147 public YangModuleLibrary getYangModuleLibrary() {
148 return ((DefaultYangSchemaRegistry) schemaRegistry).getLibrary();
149 }
150
151 @Override
152 public String getYangFile(YangModuleIdentifier moduleIdentifier) {
153 return ((DefaultYangSchemaRegistry) schemaRegistry)
154 .getYangFile(moduleIdentifier);
155 }
156
157 @Override
158 public void registerDefaultCodec(YangDataTreeCodec defaultCodec,
159 YangProtocolEncodingFormat dataFormat) {
160
161 }
162
163 @Override
164 public void registerService(Object yangManager, Class<?> yangService,
165 List<String> supportedFeatureList) {
166
167 //perform registration of service
168 schemaRegistryExecutor.execute(() -> schemaRegistry
169 .registerApplication(yangManager, yangService,
170 getYnhExtendedService()));
171 }
172
173 @Override
174 public void unRegisterService(Object appManager, Class<?> yangService) {
175 schemaRegistry.unRegisterApplication(appManager, yangService);
176 }
177
178 @Override
179 public YangCodecHandler getYangCodecHandler() {
180 return null;
181 }
182
183 /**
184 * Returns schema registry.
185 *
186 * @return schema registry
187 */
188 public YangSchemaRegistry getSchemaRegistry() {
189 return schemaRegistry;
190 }
Bharat saraswalf53b29a2016-09-27 15:35:15 +0530191}