5ad9dfd9d2fe07475b8263eaa2b164ea8b793768
[oam/tr069-adapter.git] / netconf-server / src / main / java / org / commscope / tr069adapter / netconf / operations / CustomOperationsCreator.java
1 /*\r
2  * ============LICENSE_START========================================================================\r
3  * ONAP : tr-069-adapter\r
4  * =================================================================================================\r
5  * Copyright (C) 2020 CommScope Inc Intellectual Property.\r
6  * =================================================================================================\r
7  * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,\r
8  * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You\r
9  * may obtain a copy of the License at\r
10  *\r
11  * http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\r
14  * either express or implied. See the License for the specific language governing permissions and\r
15  * limitations under the License.\r
16  * ===============LICENSE_END=======================================================================\r
17  */\r
18 \r
19 package org.commscope.tr069adapter.netconf.operations;\r
20 \r
21 import com.google.common.collect.Sets;\r
22 \r
23 import java.util.Optional;\r
24 import java.util.Set;\r
25 \r
26 import org.commscope.tr069adapter.netconf.rpc.CreateSubscription;\r
27 import org.commscope.tr069adapter.netconf.rpc.DeleteConfigOperation;\r
28 import org.commscope.tr069adapter.netconf.rpc.GetConfigOperation;\r
29 import org.commscope.tr069adapter.netconf.rpc.GetOperation;\r
30 import org.commscope.tr069adapter.netconf.rpc.OperationCommit;\r
31 import org.commscope.tr069adapter.netconf.rpc.OperationLock;\r
32 import org.commscope.tr069adapter.netconf.rpc.OperationUnLock;\r
33 import org.commscope.tr069adapter.netconf.rpc.SetConfigOperation;\r
34 import org.commscope.tr069adapter.netconf.rpc.SoftwareActivateOperation;\r
35 import org.commscope.tr069adapter.netconf.rpc.SoftwareDownloadOperation;\r
36 import org.opendaylight.netconf.api.capability.Capability;\r
37 import org.opendaylight.netconf.impl.SessionIdProvider;\r
38 import org.opendaylight.netconf.mapping.api.NetconfOperation;\r
39 import org.opendaylight.netconf.mapping.api.NetconfOperationService;\r
40 import org.opendaylight.netconf.test.tool.operations.OperationsCreator;\r
41 import org.opendaylight.netconf.test.tool.rpc.DataList;\r
42 import org.slf4j.Logger;\r
43 import org.slf4j.LoggerFactory;\r
44 \r
45 public final class CustomOperationsCreator implements OperationsCreator {\r
46   private static final Logger logger = LoggerFactory.getLogger(CustomOperationsCreator.class);\r
47 \r
48   private String macID = null;\r
49 \r
50   private String swVersion;\r
51 \r
52   private String hwVersion;\r
53 \r
54   private OperationService operationService;\r
55 \r
56   public CustomOperationsCreator(String macID, String swVersion, String hwVersion) {\r
57     this.macID = macID;\r
58     this.swVersion = swVersion;\r
59     this.hwVersion = hwVersion;\r
60   }\r
61 \r
62   @Override\r
63   public NetconfOperationService getNetconfOperationService(final Set<Capability> caps,\r
64       final SessionIdProvider idProvider, final String netconfSessionIdForReporting) {\r
65     if (null == operationService) {\r
66       operationService =\r
67           new OperationService(idProvider.getCurrentSessionId(), macID, swVersion, hwVersion);\r
68     }\r
69     return operationService;\r
70   }\r
71 \r
72   static class OperationService implements NetconfOperationService {\r
73 \r
74     private final long currentSessionId;\r
75     private String macID;\r
76     private String swVersion;\r
77     private String hwVersion;\r
78 \r
79     OperationService(final long currentSessionId, String macID, String swVersion,\r
80         String hwVersion) {\r
81       this.currentSessionId = currentSessionId;\r
82       this.macID = macID;\r
83       this.swVersion = swVersion;\r
84       this.hwVersion = hwVersion;\r
85     }\r
86 \r
87     @Override\r
88     public Set<NetconfOperation> getNetconfOperations() {\r
89       final DataList storage = new DataList();\r
90       final GetOperation oGet =\r
91           new GetOperation(String.valueOf(currentSessionId), storage, macID, swVersion, hwVersion);\r
92       final GetConfigOperation oGetConfig = new GetConfigOperation(String.valueOf(currentSessionId),\r
93           Optional.empty(), macID, swVersion, hwVersion);\r
94       final SetConfigOperation oSetConfig =\r
95           new SetConfigOperation(String.valueOf(currentSessionId), macID, swVersion, hwVersion);\r
96       final DeleteConfigOperation oDelConfig = new DeleteConfigOperation(\r
97           String.valueOf(currentSessionId), storage, macID, swVersion, hwVersion);\r
98       final OperationCommit oCommit = new OperationCommit(String.valueOf(currentSessionId));\r
99       final OperationLock oLock = new OperationLock(String.valueOf(currentSessionId));\r
100       final OperationUnLock oUnlock = new OperationUnLock(String.valueOf(currentSessionId));\r
101       final CreateSubscription sCreateSubs = new CreateSubscription(\r
102           String.valueOf(currentSessionId), Optional.empty(), macID, swVersion, hwVersion);\r
103       SoftwareDownloadOperation swDownloadOperation =\r
104           new SoftwareDownloadOperation(macID, swVersion, hwVersion);\r
105       SoftwareActivateOperation swActivateOperation =\r
106           new SoftwareActivateOperation(macID, swVersion, hwVersion);\r
107       return Sets.newHashSet(oGet, oGetConfig, oSetConfig, oDelConfig, oCommit, oLock, oUnlock,\r
108           sCreateSubs, swDownloadOperation, swActivateOperation);\r
109     }\r
110 \r
111     @Override\r
112     public void close() {\r
113       logger.debug("close called on CustomOperationsCreator");\r
114     }\r
115 \r
116   }\r
117 }\r