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%2FGetConfigOperation.java;h=d7c4e98a8bccdfcae07caedd3eab80428a19f4bc;hb=76744e810f35c84ecbd1d9998e361052466e9483;hp=4fd08e08f1b2fb037e8c624aacc212cb532393f1;hpb=ce4e2d38e3d42725f61c39dd172325d2def4bc44;p=oam%2Ftr069-adapter.git diff --git a/netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/GetConfigOperation.java b/netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/GetConfigOperation.java index 4fd08e0..d7c4e98 100644 --- a/netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/GetConfigOperation.java +++ b/netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/GetConfigOperation.java @@ -1,109 +1,109 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : tr-069-adapter - * ================================================================================================= - * Copyright (C) 2020 CommScope Inc Intellectual Property. - * ================================================================================================= - * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License, - * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You - * may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and - * limitations under the License. - * ===============LICENSE_END======================================================================= - */ - -package org.commscope.tr069adapter.netconf.rpc; - -import java.io.File; -import java.io.IOException; -import java.util.Optional; - -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.api.xml.XmlUtil; -import org.opendaylight.netconf.util.mapping.AbstractLastNetconfOperation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; - -public class GetConfigOperation extends AbstractLastNetconfOperation { - private static final Logger logger = LoggerFactory.getLogger(GetConfigOperation.class); - - private String deviceID; - private String swVersion; - private String hwVersion; - - public GetConfigOperation(final String netconfSessionIdForReporting, - final Optional initialConfigXMLFile, String deviceID, String swVersion, - String hwVersion) { - super(netconfSessionIdForReporting); - this.deviceID = deviceID; - this.swVersion = swVersion; - this.hwVersion = hwVersion; - if (initialConfigXMLFile.isPresent()) { - logger.info("File is present: {}", initialConfigXMLFile.get().getName()); - } - } - - @Override - protected Element handleWithNoSubsequentOperations(final Document document, - final XmlElement operationElement) throws DocumentedException { - final Element element = document.createElement(XmlNetconfConstants.DATA_KEY); - - String requestXml = XmlUtility.convertDocumentToString(operationElement); - logger.debug("netconf request recevied : {}", requestXml); - NetConfServerProperties config = - NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class); - - final String baseUrl = config.getMapperPath() + "/getConfig"; - NetConfResponse restResponse = - XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion); - - if (restResponse != null) { - ErrorCodeDetails errorCode = restResponse.getErrorCode(); - if (errorCode != null && errorCode.getFaultCode() != null - && !errorCode.getFaultCode().equalsIgnoreCase("0")) { - logger.error("Error received : {} ", errorCode); - throw new DocumentedException(errorCode.getErrorMessage(), - ErrorType.from(errorCode.getErrorType()), ErrorTag.from(errorCode.getErrorTag()), - ErrorSeverity.from(errorCode.getErrorSeverity())); - } else if (restResponse.getNetconfResponseXml() != null) { - Element element1 = null; - try { - logger.debug("Response received from mapper :{}", restResponse.getNetconfResponseXml()); - element1 = XmlUtil.readXmlToElement(restResponse.getNetconfResponseXml()); - XmlElement xmlElement = XmlElement.fromDomElement(element1); - Element domElement = xmlElement.getDomElement(); - element.appendChild(element.getOwnerDocument().importNode(domElement, true)); - } catch (SAXException | IOException e1) { - logger.error("Error while constructing the reponse {}", e1.toString()); - } - } - } else { - logger.error("received the null response from mapper "); - throw new DocumentedException("Unable to perform Operation", ErrorType.from("application"), - ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR")); - } - - return element; - } - - @Override - protected String getOperationName() { - return XmlNetconfConstants.GET_CONFIG; - } -} +/* + * ============LICENSE_START======================================================================== + * ONAP : tr-069-adapter + * ================================================================================================= + * Copyright (C) 2020 CommScope Inc Intellectual Property. + * ================================================================================================= + * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License, + * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You + * may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and + * limitations under the License. + * ===============LICENSE_END======================================================================= + */ + +package org.commscope.tr069adapter.netconf.rpc; + +import java.io.File; +import java.io.IOException; +import java.util.Optional; + +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.api.xml.XmlUtil; +import org.opendaylight.netconf.util.mapping.AbstractLastNetconfOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +public class GetConfigOperation extends AbstractLastNetconfOperation { + private static final Logger logger = LoggerFactory.getLogger(GetConfigOperation.class); + + private String deviceID; + private String swVersion; + private String hwVersion; + + public GetConfigOperation(final String netconfSessionIdForReporting, + final Optional initialConfigXMLFile, String deviceID, String swVersion, + String hwVersion) { + super(netconfSessionIdForReporting); + this.deviceID = deviceID; + this.swVersion = swVersion; + this.hwVersion = hwVersion; + if (initialConfigXMLFile.isPresent()) { + logger.info("File is present: {}", initialConfigXMLFile.get().getName()); + } + } + + @Override + protected Element handleWithNoSubsequentOperations(final Document document, + final XmlElement operationElement) throws DocumentedException { + final Element element = document.createElement(XmlNetconfConstants.DATA_KEY); + + String requestXml = XmlUtility.convertDocumentToString(operationElement); + logger.debug("netconf request recevied : {}", requestXml); + NetConfServerProperties config = + NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class); + + final String baseUrl = config.getMapperPath() + "/getConfig"; + NetConfResponse restResponse = + XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion); + + if (restResponse != null) { + ErrorCodeDetails errorCode = restResponse.getErrorCode(); + if (errorCode != null && errorCode.getFaultCode() != null + && !errorCode.getFaultCode().equalsIgnoreCase("0")) { + logger.error("Error received : {} ", errorCode); + throw new DocumentedException(errorCode.getErrorMessage(), + ErrorType.from(errorCode.getErrorType()), ErrorTag.from(errorCode.getErrorTag()), + ErrorSeverity.from(errorCode.getErrorSeverity())); + } else if (restResponse.getNetconfResponseXml() != null) { + Element element1 = null; + try { + logger.debug("Response received from mapper :{}", restResponse.getNetconfResponseXml()); + element1 = XmlUtil.readXmlToElement(restResponse.getNetconfResponseXml()); + XmlElement xmlElement = XmlElement.fromDomElement(element1); + Element domElement = xmlElement.getDomElement(); + element.appendChild(element.getOwnerDocument().importNode(domElement, true)); + } catch (SAXException | IOException e1) { + logger.error("Error while constructing the reponse {}", e1.toString()); + } + } + } else { + logger.error("received the null response from mapper "); + throw new DocumentedException("Unable to perform Operation", ErrorType.from("application"), + ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR")); + } + + return element; + } + + @Override + protected String getOperationName() { + return XmlNetconfConstants.GET_CONFIG; + } +}