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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=======================================================================
19 package org.commscope.tr069adapter.netconf.rpc;
21 import org.commscope.tr069adapter.netconf.boot.NetConfServiceBooter;
22 import org.commscope.tr069adapter.netconf.config.NetConfServerProperties;
23 import org.opendaylight.netconf.api.DocumentedException;
24 import org.opendaylight.netconf.api.xml.XmlElement;
25 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
26 import org.opendaylight.netconf.mapping.api.HandlingPriority;
27 import org.opendaylight.netconf.mapping.api.NetconfOperation;
28 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.w3c.dom.Document;
33 public class SoftwareActivateOperation implements NetconfOperation {
34 private static final Logger logger = LoggerFactory.getLogger(SoftwareActivateOperation.class);
35 public static final String SOFT_MGMT_NAMESPACE = "urn:o-ran:software-management:1.0";
37 private String deviceID;
38 private String swVersion;
39 private String hwVersion;
41 public SoftwareActivateOperation(String deviceID, String swVersion, String hwVersion) {
42 this.deviceID = deviceID;
43 this.swVersion = swVersion;
44 this.hwVersion = hwVersion;
48 public HandlingPriority canHandle(final Document message) throws DocumentedException {
49 OperationNameAndNamespace operationNameAndNamespace = null;
50 operationNameAndNamespace = new OperationNameAndNamespace(message);
51 return canHandle(operationNameAndNamespace.getOperationName(),
52 operationNameAndNamespace.getNamespace());
56 public Document handle(Document requestMessage,
57 NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
59 logger.debug("sw-activate rpc recevied in netconf server");
60 final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
62 String requestXml = XmlUtility.convertDocumentToString(requestElement);
63 logger.debug("sw-activate rpc recevied requestXml = {}", requestXml);
64 NetConfServerProperties config =
65 NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
67 final String baseUrl = config.getMapperPath() + "/softwareActivate";
68 XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
72 protected HandlingPriority canHandle(final String operationName,
73 final String operationNamespace) {
74 return operationName.equals("software-activate")
75 && operationNamespace.equals(SOFT_MGMT_NAMESPACE)
76 ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
77 : HandlingPriority.CANNOT_HANDLE;
80 public static final class OperationNameAndNamespace {
81 private final String operationName;
82 private final String namespace;
84 private final XmlElement operationElement;
86 public OperationNameAndNamespace(final Document message) throws DocumentedException {
87 XmlElement requestElement = null;
88 requestElement = getRequestElementWithCheck(message);
89 operationElement = requestElement.getOnlyChildElement();
90 operationName = operationElement.getName();
91 namespace = operationElement.getNamespace();
94 public String getOperationName() {
98 public String getNamespace() {
102 public XmlElement getOperationElement() {
103 return operationElement;
107 protected static XmlElement getRequestElementWithCheck(final Document message)
108 throws DocumentedException {
109 return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
110 XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);