X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=netconf-server%2Fsrc%2Fmain%2Fjava%2Forg%2Fcommscope%2Ftr069adapter%2Fnetconf%2Frpc%2FSoftwareDownloadOperation.java;fp=netconf-server%2Fsrc%2Fmain%2Fjava%2Forg%2Fcommscope%2Ftr069adapter%2Fnetconf%2Frpc%2FSoftwareDownloadOperation.java;h=00bf175dd0d8861a703ef5d288061548d15546e4;hb=641a6c47b4ee74412e9386b3c95693adda3cafc9;hp=b6f4dc97b781ffde8d34e5d528897b9f2480ae91;hpb=8c7432b8380a355e89df05f070e7d88e599912fd;p=oam%2Ftr069-adapter.git diff --git a/netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/SoftwareDownloadOperation.java b/netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/SoftwareDownloadOperation.java index b6f4dc9..00bf175 100644 --- a/netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/SoftwareDownloadOperation.java +++ b/netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/SoftwareDownloadOperation.java @@ -18,9 +18,19 @@ package org.commscope.tr069adapter.netconf.rpc; +import java.io.StringReader; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.commscope.tr069adapter.mapper.model.ErrorCodeDetails; +import org.commscope.tr069adapter.mapper.model.NetConfResponse; import org.commscope.tr069adapter.netconf.boot.NetConfServiceBooter; import org.commscope.tr069adapter.netconf.config.NetConfServerProperties; import org.opendaylight.netconf.api.DocumentedException; +import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity; +import org.opendaylight.netconf.api.DocumentedException.ErrorTag; +import org.opendaylight.netconf.api.DocumentedException.ErrorType; import org.opendaylight.netconf.api.xml.XmlElement; import org.opendaylight.netconf.api.xml.XmlNetconfConstants; import org.opendaylight.netconf.mapping.api.HandlingPriority; @@ -29,6 +39,7 @@ import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; +import org.xml.sax.InputSource; public class SoftwareDownloadOperation implements NetconfOperation { private static final Logger logger = LoggerFactory.getLogger(SoftwareDownloadOperation.class); @@ -52,18 +63,48 @@ public class SoftwareDownloadOperation implements NetconfOperation { public Document handle(Document requestMessage, NetconfOperationChainedExecution subsequentOperation) throws DocumentedException { - logger.debug("sw-download rpc recevied in netconf server"); + logger.debug("soft-ware download rpc is received in netconfserver"); + final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage); + final String msgId = requestElement.getAttribute(XmlNetconfConstants.MESSAGE_ID); String requestXml = XmlUtility.convertDocumentToString(requestElement); - logger.debug("sw-download rpc recevied requestXml = {}", requestXml); + logger.debug("soft-ware download rpc requestXml=" + requestXml); + NetConfServerProperties config = NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class); final String baseUrl = config.getMapperPath() + "/softwareDowload"; - XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID); + NetConfResponse restResponse = XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID); + + Document document = null; + + ErrorCodeDetails errorCode = restResponse.getErrorCode(); + if (errorCode != null && errorCode.getFaultCode() != null + && !errorCode.getFaultCode().equalsIgnoreCase("0")) { + logger.error("Error recevied : " + errorCode); + throw new DocumentedException(errorCode.getErrorMessage(), + ErrorType.from(errorCode.getErrorType()), ErrorTag.from(errorCode.getErrorTag()), + ErrorSeverity.from(errorCode.getErrorSeverity())); + } else if (restResponse != null && restResponse.getNetconfResponseXml() != null) { + logger.debug("soft-ware download rpc response received from mapper " + + restResponse.getNetconfResponseXml()); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder; + try { + builder = factory.newDocumentBuilder(); + document = + builder.parse(new InputSource(new StringReader(restResponse.getNetconfResponseXml()))); + document.getDocumentElement().setAttribute("xmlns:ns1", getOperationNamespace()); + document.getDocumentElement().setAttribute("xmlns", + XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); + document.getDocumentElement().setAttribute(XmlNetconfConstants.MESSAGE_ID, msgId); + } catch (Exception e) { + logger.error("while contruscting the response; ", e.toString()); + } + } - return null; + return document; } protected HandlingPriority canHandle(final String operationName, @@ -107,4 +148,12 @@ public class SoftwareDownloadOperation implements NetconfOperation { return XmlElement.fromDomElementWithExpected(message.getDocumentElement(), XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); } + + protected String getOperationNamespace() { + return "urn:o-ran:software-management:1.0"; + } + + protected String getOperationName() { + return "software-download"; + } }