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