Development of NETCONF RPCs for tr-069 adapter to
[oam/tr069-adapter.git] / netconf-server / src / main / java / org / commscope / tr069adapter / netconf / restapi / NetConfServerManagerRestApi.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.restapi;
20
21 import java.util.List;
22
23 import org.commscope.tr069adapter.mapper.model.NetConfServerDetails;
24 import org.commscope.tr069adapter.netconf.server.NetConfServerManagerImpl;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.web.bind.annotation.GetMapping;
29 import org.springframework.web.bind.annotation.PostMapping;
30 import org.springframework.web.bind.annotation.RequestMapping;
31 import org.springframework.web.bind.annotation.RequestParam;
32 import org.springframework.web.bind.annotation.RestController;
33
34 @RestController
35 @RequestMapping("/netConfServerManagerService")
36 public class NetConfServerManagerRestApi {
37
38   private static final Logger LOG = LoggerFactory.getLogger(NetConfServerManagerRestApi.class);
39   public static final String PATTERN = "[\n|\r|\t]";
40
41   @Autowired
42   NetConfServerManagerImpl manager;
43
44   @PostMapping("/createServer")
45   public NetConfServerDetails createNetConfServerInstance(@RequestParam String deviceId,
46       @RequestParam String enodeBName, @RequestParam String swVersion,
47       @RequestParam String hwVersion) {
48           deviceId = deviceId.replaceAll(PATTERN, "_");
49           enodeBName = enodeBName.replaceAll(PATTERN, "_");
50     LOG.info("Received Create NetConf Server request for deviceID: {}, enodeBName: {}, swversion: {}", deviceId,
51         enodeBName, swVersion);
52     NetConfServerDetails serverDetails =
53         manager.createServer(deviceId, enodeBName, swVersion, hwVersion);
54     LOG.info("Successfully processed NetConf Server wit server details : {}", serverDetails);
55     return serverDetails;
56   }
57
58   @PostMapping("/restartOnVersionChange")
59   public NetConfServerDetails restartOnVersionChange(@RequestParam String deviceId,
60       @RequestParam String enodeBName, @RequestParam String swVersion,
61       @RequestParam String hwVersion) {
62           deviceId = deviceId.replaceAll(PATTERN, "_");
63           enodeBName = enodeBName.replaceAll(PATTERN, "_");  
64     LOG.info("Received Create NetConf Server request for deviceID: {}, enodeBName: {}", deviceId,
65         enodeBName);
66     NetConfServerDetails serverDetails =
67         manager.restartOnVersionChange(deviceId, enodeBName, swVersion, hwVersion);
68     LOG.info("Successfully processed NetConf Server wit server details : {}", serverDetails);
69     return serverDetails;
70   }
71   
72   @GetMapping("/listServers")
73   public List<NetConfServerDetails> listNetConfServersInfo() {
74     LOG.info("Received request to list all NetConf Servers information");
75     List<NetConfServerDetails> serverDetails = manager.getServersInfo();
76     LOG.info("Successfully processed request to list all NetConf Servers information");
77     return serverDetails;
78   }
79
80   @PostMapping("/unregisterServer")
81   public String unregisterNetConfServerInstance(@RequestParam String deviceId,
82       @RequestParam String enodeBName) {
83           deviceId = deviceId.replaceAll(PATTERN, "_");
84           enodeBName = enodeBName.replaceAll(PATTERN, "_");  
85     LOG.info("Received request for Unregister NetConf Server for deviceID: {}, enodeBName: {} ",
86         deviceId, enodeBName);
87     String result = manager.unregister(deviceId, enodeBName);
88     LOG.info("Unregister request is processed. NetConf Server for deviceID: {} , unregisted= {}",
89         deviceId, result);
90     return result;
91   }
92
93 }