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
11 * http://www.apache.org/licenses/LICENSE-2.0
\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
19 package org.commscope.tr069adapter.mapper.netconf;
\r
21 import org.commscope.tr069adapter.mapper.MapperConfigProperties;
\r
22 import org.commscope.tr069adapter.mapper.model.NetConfServerDetails;
\r
23 import org.slf4j.Logger;
\r
24 import org.slf4j.LoggerFactory;
\r
25 import org.springframework.beans.factory.annotation.Autowired;
\r
26 import org.springframework.http.HttpEntity;
\r
27 import org.springframework.http.HttpHeaders;
\r
28 import org.springframework.http.MediaType;
\r
29 import org.springframework.http.ResponseEntity;
\r
30 import org.springframework.stereotype.Component;
\r
31 import org.springframework.util.LinkedMultiValueMap;
\r
32 import org.springframework.util.MultiValueMap;
\r
33 import org.springframework.web.client.RestTemplate;
\r
36 public class NetConfServerManager {
\r
38 private static final Logger LOG = LoggerFactory.getLogger(NetConfServerManager.class);
\r
40 private static String createServerSVC = "createServer";
\r
43 MapperConfigProperties config;
\r
46 RestTemplate restTemplate;
\r
48 public NetConfServerDetails createNetconfServer(String deviceID, String enodeBName,
\r
49 String swVersion, String hwVersion) {
\r
51 NetConfServerDetails result = null;
\r
53 final String uri = getNetconfServerManagerRestUri() + "/" + createServerSVC;
\r
54 LOG.debug("Sending create netconf server request for device id {}", deviceID);
\r
56 MultiValueMap<String, String> uriParams = new LinkedMultiValueMap<>();
\r
57 uriParams.add("deviceId", deviceID);
\r
58 uriParams.add("enodeBName", enodeBName);
\r
59 uriParams.add("swVersion", swVersion);
\r
60 uriParams.add("hwVersion", hwVersion);
\r
61 HttpHeaders headers = new HttpHeaders();
\r
62 headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
\r
63 final HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(uriParams, headers);
\r
64 ResponseEntity<NetConfServerDetails> res =
\r
65 restTemplate.postForEntity(uri, entity, NetConfServerDetails.class);
\r
66 result = res.getBody();
\r
67 LOG.debug("Successfully created netconf server for device id. {} , response= {}", deviceID,
\r
69 } catch (Exception e) {
\r
70 LOG.error("Exception while creating netconf server request for device id {}", deviceID, e);
\r
75 private String getNetconfServerManagerRestUri() {
\r
76 return config.getNbiServerManagerUri();
\r