\r
## Mapper Configuration\r
config.mapperInformNotificationServiceURL=http://${MAPPER_REST_HOST}:${MAPPER_REST_PORT}/tr069MapperSBI/notification\r
-config.mapperDeviceRPCResponseNotificationServiceURL=http://${MAPPER_REST_HOST}:${MAPPER_REST_PORT}/tr069MapperSBI/opResult
\ No newline at end of file
+config.mapperDeviceRPCResponseNotificationServiceURL=http://${MAPPER_REST_HOST}:${MAPPER_REST_PORT}/tr069MapperSBI/opResult\r
+config.isDeviceAuthorizationEnabled=true
\ No newline at end of file
-/*\r
- * ============LICENSE_START========================================================================\r
- * ONAP : tr-069-adapter\r
- * =================================================================================================\r
- * Copyright (C) 2020 CommScope Inc Intellectual Property.\r
- * =================================================================================================\r
- * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,\r
- * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You\r
- * may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\r
- * either express or implied. See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ===============LICENSE_END=======================================================================\r
- */\r
-\r
-package org.commscope.tr069adapter.acs.nbi.util;\r
-\r
-import org.springframework.stereotype.Component;\r
-\r
-@Component\r
-public class OperationIdGenerator {\r
-\r
- public Long generateOpId() {\r
- return System.currentTimeMillis();\r
- }\r
-\r
-}\r
+/*
+ * ============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.acs.common.utils;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class OperationIdGenerator {
+
+ public Long generateOpId() {
+ return System.currentTimeMillis();
+ }
+
+}
while (pfxs.hasNext()) {
String pfx = pfxs.next();
String uri = env.getNamespaceURI(pfx);
- if (uri.startsWith("urn:dslforum-org:cwmp-")) {
+ if (CWMP.equalsIgnoreCase(pfx)) {
urnCWMP = uri;
}
}
List<String> parameters = new ArrayList<>();
parameters.add("InternetGatewayDevice.DeviceInfo.HardwareVersion");
parameters.add("InternetGatewayDevice.DeviceInfo.SoftwareVersion");
- parameters.add("InternetGatewayDevice.DeviceInfo.ProvisioningCode");
parameters.add("InternetGatewayDevice.ManagementServer.ConnectionRequestURL");
parameters.add("InternetGatewayDevice.ManagementServer.ParameterKey");
informParameter.put("InternetGatewayDevice", parameters);
\r
package org.commscope.tr069adapter.acs.cpe.handler;\r
\r
+\r
import java.nio.charset.StandardCharsets;\r
import java.util.Base64;\r
\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.beans.factory.annotation.Value;\r
import org.springframework.http.ResponseEntity;\r
import org.springframework.stereotype.Component;\r
import org.springframework.web.client.RestTemplate;\r
@Autowired\r
RestTemplate restTemplate;\r
\r
+ @Value("${config.isDeviceAuthorizationEnabled:true}")\r
+ private boolean isDeviceAuthorizationEnabled;\r
+\r
public void setFactorySrvcDependencyConfig(\r
FactorySrvcDependencyConfig factorySrvcDependencyConfig) {\r
this.factorySrvcDependencyConfig = factorySrvcDependencyConfig;\r
* @return\r
*/\r
public Boolean isDeviceAuthorized(Inform inform, String authorization) {\r
+ if(!isDeviceAuthorizationEnabled){\r
+ logger.debug("Device authentication is not needed here. Hence always authorizing.");\r
+ return true;\r
+ }\r
if (authorization == null) {\r
logger.debug("HTTP Challenge failed as Authorization header does not exist");\r
return false;\r
import org.commscope.tr069adapter.acs.common.OperationCode;
import org.commscope.tr069adapter.acs.common.exception.MapperServiceException;
import org.commscope.tr069adapter.acs.common.mapper.ACSServiceAPI;
-import org.commscope.tr069adapter.acs.nbi.util.OperationIdGenerator;
+import org.commscope.tr069adapter.acs.common.utils.OperationIdGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Profile;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;
@Component
+//@Profile(value="default")
public class TR069EventNotificationService {
private static final Logger logger = LoggerFactory.getLogger(TR069EventNotificationService.class);
String deviceId = deviceNotification.getDeviceDetails().getDeviceId();
try {
MDC.put(CLIENT_STR, deviceId);
+
TR069InformType notificationType = (TR069InformType) deviceNotification.getInformType();
logger.debug("Device Inform Event received: '{}'", notificationType.getNotificationCode());
if (null != deviceRPCResponse) {
return;
}
- } catch (DeviceOperationException | SessionManagerException deo) {
+ } catch (DeviceOperationException deo) {
logger.error(deo.getMessage());
deviceRPCResponse = tr069RequestProcessEngineUtility.buildAbortedOperationresult(
tr069DeviceDetails, deviceRPCRequest, AcsFaultCode.FAULT_CODE_8000);
}
private DeviceRPCResponse checkForDeviceAvailabilityRequest(DeviceRPCRequest deviceRPCRequest,
- TR069DeviceDetails tr069DeviceDetails) throws SessionManagerException {
+ TR069DeviceDetails tr069DeviceDetails) {
DeviceRPCResponse deviceRPCResponse = null;
if (!deviceRPCRequest.getOpDetails().getOpCode().equals(CustomOperationCode.CONNECT)) {
if (deviceVersion.getSwVersion().equalsIgnoreCase(profileVersion.getSwVersion())
|| deviceVersion.getSwVersion().matches(profileVersion.getSwVersion())) {
if (profileVersion.isHwRegex()) {
- if (deviceVersion.getHwVersion() != null) {
-
- if ("*".equalsIgnoreCase(profileVersion.getHwVersion())
- || deviceVersion.getHwVersion().equalsIgnoreCase(profileVersion.getHwVersion())
- || deviceVersion.getHwVersion().matches(profileVersion.getHwVersion())) {
+ if (deviceVersion.getHwVersion() != null && hwVersionCheck(deviceVersion, profileVersion)) {
return entry.getValue();
- }
}
} else {
// Check Strict match of Hardware
}
}
}
- } else if (profileVersion.isHwRegex()) {
- if (deviceVersion.getHwVersion() != null) {
- if ("*".equalsIgnoreCase(profileVersion.getHwVersion())
- || deviceVersion.getHwVersion().equalsIgnoreCase(profileVersion.getHwVersion())
- || deviceVersion.getHwVersion().matches(profileVersion.getHwVersion())) {
+ } else if (profileVersion.isHwRegex() && (deviceVersion.getHwVersion() != null && hwVersionCheck(deviceVersion, profileVersion)) ) {
// Add all software version which matching
if (profileVersion.getSwVersion()
.compareToIgnoreCase(deviceVersion.getSwVersion()) <= 0) {
mSoftwareList.add(profileVersion);
- }
- }
}
}
} else {
return null;
}
+
+ private boolean hwVersionCheck(DeviceVersion deviceVersion, DeviceVersion profileVersion) {
+ return "*".equalsIgnoreCase(profileVersion.getHwVersion()) || deviceVersion.getHwVersion()
+ .equalsIgnoreCase(profileVersion.getHwVersion()) || deviceVersion.getHwVersion()
+ .matches(profileVersion.getHwVersion());
+ }
}
private static final Logger logger = LoggerFactory.getLogger(NetConfNotificationQueue.class);\r
\r
@Autowired\r
- NetConfSessionUtil netConfSessionUtil;;\r
+ NetConfSessionUtil netConfSessionUtil;\r
\r
@JmsListener(destination = NetConfServerConstants.NETCONF_NOTIFICATION_Q,\r
containerFactory = NetConfServerConstants.NETCONF_NOTIFICATION_CF)\r
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;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
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 AddObjectOperation implements NetconfOperation {
+public class AddObjectOperation extends GenericOperation {
private static final Logger logger = LoggerFactory.getLogger(AddObjectOperation.class);
- public static final String OP_NAMESPACE = "urn:tr069rpc:1.0";
- public static final String OP_NAME = "add-object";
- private String deviceID;
- private String swVersion;
- private String hwVersion;
public AddObjectOperation(String deviceID, String swVersion, String hwVersion) {
this.deviceID = deviceID;
this.swVersion = swVersion;
this.hwVersion = hwVersion;
- }
-
- @Override
- public HandlingPriority canHandle(final Document message) throws DocumentedException {
- OperationNameAndNamespace operationNameAndNamespace = null;
- operationNameAndNamespace = new OperationNameAndNamespace(message);
- return canHandle(operationNameAndNamespace.getOperationName(),
- operationNameAndNamespace.getNamespace());
+ setOpString("addobject");
+ setOpNamespace("urn:tr069rpc:1.0");
+ setOpName("add-object");
}
@Override
NetConfServerProperties config =
NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
- final String baseUrl = config.getMapperPath() + "/addobject";
+ final String baseUrl = config.getMapperPath() + "/" + getOpString();
NetConfResponse restResponse =
XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
Document document = null;
builder = factory.newDocumentBuilder();
document =
builder.parse(new InputSource(new StringReader(restResponse.getNetconfResponseXml())));
- document.getDocumentElement().setAttribute("xmlns:ns1", getOperationNamespace());
+ document.getDocumentElement().setAttribute("xmlns:ns1", getOpNamespace());
document.getDocumentElement().setAttribute("xmlns",
XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
document.getDocumentElement().setAttribute(XmlNetconfConstants.MESSAGE_ID, msgId);
return document;
}
-
- protected HandlingPriority canHandle(final String operationName,
- final String operationNamespace) {
- return operationName.equals(getOperationName())
- && operationNamespace.equals(getOperationNamespace())
- ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
- : HandlingPriority.CANNOT_HANDLE;
- }
-
- public static final class OperationNameAndNamespace {
- private final String operationName;
- private final String namespace;
-
- private final XmlElement operationElement;
-
- public OperationNameAndNamespace(final Document message) throws DocumentedException {
- XmlElement requestElement = null;
- requestElement = getRequestElementWithCheck(message);
- operationElement = requestElement.getOnlyChildElement();
- operationName = operationElement.getName();
- namespace = operationElement.getNamespace();
- }
-
- public String getOperationName() {
- return operationName;
- }
-
- public String getNamespace() {
- return namespace;
- }
-
- public XmlElement getOperationElement() {
- return operationElement;
- }
-
- }
-
- protected static XmlElement getRequestElementWithCheck(final Document message)
- throws DocumentedException {
- return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
- XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
- }
-
- protected String getOperationNamespace() {
- return OP_NAMESPACE;
- }
-
- protected String getOperationName() {
- return OP_NAME;
- }
-
}
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;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
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 ConnectionStatus implements NetconfOperation {
+public class ConnectionStatus extends GenericOperation {
private static final Logger logger = LoggerFactory.getLogger(ConnectionStatus.class);
- public static final String OP_NAMESPACE = "urn:tr069rpc:1.0";
- public static final String OP_NAME = "connection-status";
-
- private String deviceID;
- private String swVersion;
- private String hwVersion;
public ConnectionStatus(String deviceID, String swVersion, String hwVersion) {
this.deviceID = deviceID;
this.swVersion = swVersion;
this.hwVersion = hwVersion;
- }
-
- @Override
- public HandlingPriority canHandle(final Document message) throws DocumentedException {
- OperationNameAndNamespace operationNameAndNamespace = null;
- operationNameAndNamespace = new OperationNameAndNamespace(message);
- return canHandle(operationNameAndNamespace.getOperationName(),
- operationNameAndNamespace.getNamespace());
+ setOpString("connectionstatus");
+ setOpNamespace("urn:tr069rpc:1.0");
+ setOpName("connection-status");
}
@Override
NetConfServerProperties config =
NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
- final String baseUrl = config.getMapperPath() + "/connectionstatus";
+ final String baseUrl = config.getMapperPath() + "/" + getOpString();
NetConfResponse restResponse =
XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
Document document = null;
builder = factory.newDocumentBuilder();
document =
builder.parse(new InputSource(new StringReader(restResponse.getNetconfResponseXml())));
- document.getDocumentElement().setAttribute("xmlns:ns1", getOperationNamespace());
+ document.getDocumentElement().setAttribute("xmlns:ns1", getOpNamespace());
document.getDocumentElement().setAttribute("xmlns",
XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
document.getDocumentElement().setAttribute(XmlNetconfConstants.MESSAGE_ID, msgId);
return document;
}
-
- protected HandlingPriority canHandle(final String operationName,
- final String operationNamespace) {
- return operationName.equals(getOperationName())
- && operationNamespace.equals(getOperationNamespace())
- ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
- : HandlingPriority.CANNOT_HANDLE;
- }
-
- public static final class OperationNameAndNamespace {
- private final String operationName;
- private final String namespace;
-
- private final XmlElement operationElement;
-
- public OperationNameAndNamespace(final Document message) throws DocumentedException {
- XmlElement requestElement = null;
- requestElement = getRequestElementWithCheck(message);
- operationElement = requestElement.getOnlyChildElement();
- operationName = operationElement.getName();
- namespace = operationElement.getNamespace();
- }
-
- public String getOperationName() {
- return operationName;
- }
-
- public String getNamespace() {
- return namespace;
- }
-
- public XmlElement getOperationElement() {
- return operationElement;
- }
-
- }
-
- protected static XmlElement getRequestElementWithCheck(final Document message)
- throws DocumentedException {
- return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
- XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
- }
-
- protected String getOperationNamespace() {
- return OP_NAMESPACE;
- }
-
- protected String getOperationName() {
- return OP_NAME;
- }
-
}
protected String getOperationNamespace() {
return "urn:ietf:params:xml:ns:netconf:notification:1.0";
}
+
+ public String getSwVersion() {
+ return swVersion;
+ }
+
+ public String getHwVersion() {
+ return hwVersion;
+ }
@Override
protected Element handleWithNoSubsequentOperations(final Document document,
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;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
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 DeleteObjectOperation implements NetconfOperation {
+public class DeleteObjectOperation extends GenericOperation {
private static final Logger logger = LoggerFactory.getLogger(DeleteObjectOperation.class);
- public static final String OP_NAMESPACE = "urn:tr069rpc:1.0";
- public static final String OP_NAME = "delete-object";
-
- private String deviceID;
- private String swVersion;
- private String hwVersion;
public DeleteObjectOperation(String deviceID, String swVersion, String hwVersion) {
this.deviceID = deviceID;
this.swVersion = swVersion;
this.hwVersion = hwVersion;
- }
-
- @Override
- public HandlingPriority canHandle(final Document message) throws DocumentedException {
- OperationNameAndNamespace operationNameAndNamespace = null;
- operationNameAndNamespace = new OperationNameAndNamespace(message);
- return canHandle(operationNameAndNamespace.getOperationName(),
- operationNameAndNamespace.getNamespace());
+ setOpString("deleteobject");
+ setOpNamespace("urn:tr069rpc:1.0");
+ setOpName("delete-object");
}
@Override
NetConfServerProperties config =
NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
- final String baseUrl = config.getMapperPath() + "/deleteobject";
+ final String baseUrl = config.getMapperPath() + "/" + getOpString();
NetConfResponse restResponse =
XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
Document document = null;
builder = factory.newDocumentBuilder();
document =
builder.parse(new InputSource(new StringReader(restResponse.getNetconfResponseXml())));
- document.getDocumentElement().setAttribute("xmlns:ns1", getOperationNamespace());
+ document.getDocumentElement().setAttribute("xmlns:ns1", getOpNamespace());
document.getDocumentElement().setAttribute("xmlns",
XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
document.getDocumentElement().setAttribute(XmlNetconfConstants.MESSAGE_ID, msgId);
return document;
}
-
- protected HandlingPriority canHandle(final String operationName,
- final String operationNamespace) {
- return operationName.equals(getOperationName())
- && operationNamespace.equals(getOperationNamespace())
- ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
- : HandlingPriority.CANNOT_HANDLE;
- }
-
- public static final class OperationNameAndNamespace {
- private final String operationName;
- private final String namespace;
-
- private final XmlElement operationElement;
-
- public OperationNameAndNamespace(final Document message) throws DocumentedException {
- XmlElement requestElement = null;
- requestElement = getRequestElementWithCheck(message);
- operationElement = requestElement.getOnlyChildElement();
- operationName = operationElement.getName();
- namespace = operationElement.getNamespace();
- }
-
- public String getOperationName() {
- return operationName;
- }
-
- public String getNamespace() {
- return namespace;
- }
-
- public XmlElement getOperationElement() {
- return operationElement;
- }
-
- }
-
- protected static XmlElement getRequestElementWithCheck(final Document message)
- throws DocumentedException {
- return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
- XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
- }
-
- protected String getOperationNamespace() {
- return OP_NAMESPACE;
- }
-
- protected String getOperationName() {
- return OP_NAME;
- }
-
}
package org.commscope.tr069adapter.netconf.rpc;
-import java.io.StringReader;
-
-import javax.xml.XMLConstants;
-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;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
-import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.xml.sax.InputSource;
-
-public class DownloadOperation implements NetconfOperation {
- private static final Logger logger = LoggerFactory.getLogger(DownloadOperation.class);
- public static final String OP_NAMESPACE = "urn:tr069rpc:1.0";
- public static final String OP_NAME = "download";
-
- private String deviceID;
- private String swVersion;
- private String hwVersion;
+public class DownloadOperation extends GenericOperation {
public DownloadOperation(String deviceID, String swVersion, String hwVersion) {
this.deviceID = deviceID;
this.swVersion = swVersion;
this.hwVersion = hwVersion;
+ setOpString("download");
+ setOpNamespace("urn:tr069rpc:1.0");
+ setOpName("download");
}
-
- @Override
- public HandlingPriority canHandle(final Document message) throws DocumentedException {
- OperationNameAndNamespace operationNameAndNamespace = null;
- operationNameAndNamespace = new OperationNameAndNamespace(message);
- return canHandle(operationNameAndNamespace.getOperationName(),
- operationNameAndNamespace.getNamespace());
- }
-
- @Override
- public Document handle(Document requestMessage,
- NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
- logger.debug("download rpc is received in netconfserver");
-
- final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
-
- final String msgId = requestElement.getAttribute(XmlNetconfConstants.MESSAGE_ID);
- final Element element =
- requestMessage.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
- XmlNetconfConstants.RPC_REPLY_KEY);
- element.setAttribute("xmlns:ns1", getOperationNamespace());
- element.setAttribute("message-id", msgId);
-
- String requestXml = XmlUtility.convertDocumentToString(requestElement);
- logger.debug("download rpc requestXml= {}", requestXml);
-
-
- NetConfServerProperties config =
- NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
-
- final String baseUrl = config.getMapperPath() + "/download";
- NetConfResponse restResponse =
- XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
- 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.getNetconfResponseXml() != null) {
- logger.debug("download rpc response received from mapper: {}",
- restResponse.getNetconfResponseXml());
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
- factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
- DocumentBuilder builder;
- try {
- Node child = requestMessage.createElement(XmlNetconfConstants.OK);
- element.appendChild(child);
- String xmlStr = XmlUtility.convertDocumentToString(element);
- try {
- builder = factory.newDocumentBuilder();
- document = builder.parse(new InputSource(new StringReader(xmlStr)));
- } catch (Exception e) {
- logger.error("Error while converting String to element: {}", e.getMessage());
- throw new DocumentedException("Operation Aborted", ErrorType.from("application"),
- ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR"));
- }
- } catch (Exception e) {
- logger.error("Error while contruscting the response: {}", e.getMessage());
- throw new DocumentedException("Operation Aborted", ErrorType.from("application"),
- ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR"));
- }
- }
-
- return document;
- }
-
- protected HandlingPriority canHandle(final String operationName,
- final String operationNamespace) {
- return operationName.equals(getOperationName())
- && operationNamespace.equals(getOperationNamespace())
- ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
- : HandlingPriority.CANNOT_HANDLE;
- }
-
- public static final class OperationNameAndNamespace {
- private final String operationName;
- private final String namespace;
-
- private final XmlElement operationElement;
-
- public OperationNameAndNamespace(final Document message) throws DocumentedException {
- XmlElement requestElement = null;
- requestElement = getRequestElementWithCheck(message);
- operationElement = requestElement.getOnlyChildElement();
- operationName = operationElement.getName();
- namespace = operationElement.getNamespace();
- }
-
- public String getOperationName() {
- return operationName;
- }
-
- public String getNamespace() {
- return namespace;
- }
-
- public XmlElement getOperationElement() {
- return operationElement;
- }
-
- }
-
- protected static XmlElement getRequestElementWithCheck(final Document message)
- throws DocumentedException {
- return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
- XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
- }
-
- protected String getOperationNamespace() {
- return OP_NAMESPACE;
- }
-
- protected String getOperationName() {
- return OP_NAME;
- }
-
}
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;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
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 GPAObjectOperation implements NetconfOperation {
+public class GPAObjectOperation extends GenericOperation {
private static final Logger logger = LoggerFactory.getLogger(GPAObjectOperation.class);
- public static final String OP_NAMESPACE = "urn:tr069rpc:1.0";
- public static final String OP_NAME = "get-parameter-attributes";
-
- private String deviceID;
- private String swVersion;
- private String hwVersion;
public GPAObjectOperation(String deviceID, String swVersion, String hwVersion) {
this.deviceID = deviceID;
this.swVersion = swVersion;
this.hwVersion = hwVersion;
- }
-
- @Override
- public HandlingPriority canHandle(final Document message) throws DocumentedException {
- OperationNameAndNamespace operationNameAndNamespace = null;
- operationNameAndNamespace = new OperationNameAndNamespace(message);
- return canHandle(operationNameAndNamespace.getOperationName(),
- operationNameAndNamespace.getNamespace());
+ setOpString("gpaobject");
+ setOpNamespace("urn:tr069rpc:1.0");
+ setOpName("get-parameter-attributes");
}
@Override
NetConfServerProperties config =
NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
- final String baseUrl = config.getMapperPath() + "/gpaobject";
+ final String baseUrl = config.getMapperPath() + "/" + getOpString();
NetConfResponse restResponse =
XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
Document document = null;
builder = factory.newDocumentBuilder();
document =
builder.parse(new InputSource(new StringReader(restResponse.getNetconfResponseXml())));
- document.getDocumentElement().setAttribute("xmlns:ns1", getOperationNamespace());
+ document.getDocumentElement().setAttribute("xmlns:ns1", getOpNamespace());
document.getDocumentElement().setAttribute("xmlns",
XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
document.getDocumentElement().setAttribute(XmlNetconfConstants.MESSAGE_ID, msgId);
return document;
}
- protected HandlingPriority canHandle(final String operationName,
- final String operationNamespace) {
- return operationName.equals(getOperationName())
- && operationNamespace.equals(getOperationNamespace())
- ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
- : HandlingPriority.CANNOT_HANDLE;
- }
-
- public static final class OperationNameAndNamespace {
- private final String operationName;
- private final String namespace;
-
- private final XmlElement operationElement;
-
- public OperationNameAndNamespace(final Document message) throws DocumentedException {
- XmlElement requestElement = null;
- requestElement = getRequestElementWithCheck(message);
- operationElement = requestElement.getOnlyChildElement();
- operationName = operationElement.getName();
- namespace = operationElement.getNamespace();
- }
-
- public String getOperationName() {
- return operationName;
- }
-
- public String getNamespace() {
- return namespace;
- }
-
- public XmlElement getOperationElement() {
- return operationElement;
- }
-
- }
-
- protected static XmlElement getRequestElementWithCheck(final Document message)
- throws DocumentedException {
- return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
- XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
- }
-
- protected String getOperationNamespace() {
- return OP_NAMESPACE;
- }
-
- protected String getOperationName() {
- return OP_NAME;
- }
-
}
--- /dev/null
+package org.commscope.tr069adapter.netconf.rpc;
+
+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.xml.XmlElement;
+import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
+import org.opendaylight.netconf.mapping.api.HandlingPriority;
+import org.opendaylight.netconf.mapping.api.NetconfOperation;
+import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.StringReader;
+
+
+public abstract class GenericOperation implements NetconfOperation {
+ private static final Logger logger = LoggerFactory.getLogger(GenericOperation.class);
+
+ private String opNamespace;
+ private String opName;
+ private String opString;
+
+ protected String deviceID;
+ protected String swVersion;
+ protected String hwVersion;
+
+ public HandlingPriority canHandle(final Document message) throws DocumentedException {
+ OperationNameAndNamespace operationNameAndNamespace = new OperationNameAndNamespace(message);
+ return canHandle(operationNameAndNamespace.getOperationName(),
+ operationNameAndNamespace.getNamespace());
+ }
+
+ protected HandlingPriority canHandle(final String operationName,
+ final String operationNamespace) {
+ return operationName.equals(getOpName())
+ && operationNamespace.equals(getOpNamespace())
+ ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
+ : HandlingPriority.CANNOT_HANDLE;
+ }
+
+ public Document handle(Document requestMessage,
+ NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
+ logger.debug("rpc is received in netconfserver");
+
+ final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
+
+ final String msgId = requestElement.getAttribute(XmlNetconfConstants.MESSAGE_ID);
+ final Element element =
+ requestMessage.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
+ XmlNetconfConstants.RPC_REPLY_KEY);
+ element.setAttribute("xmlns:ns1", getOpNamespace());
+ element.setAttribute("message-id", msgId);
+
+ String requestXml = XmlUtility.convertDocumentToString(requestElement);
+ logger.debug("rpc requestXml= {}", requestXml);
+
+ NetConfServerProperties config =
+ NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
+
+ final String baseUrl = config.getMapperPath() + "/" + getOpString();
+ NetConfResponse restResponse =
+ XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
+ 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(),
+ DocumentedException.ErrorType.from(errorCode.getErrorType()), DocumentedException.ErrorTag
+ .from(errorCode.getErrorTag()),
+ DocumentedException.ErrorSeverity.from(errorCode.getErrorSeverity()));
+ } else if (restResponse.getNetconfResponseXml() != null) {
+ logger.debug("rpc response received from mapper: {}",
+ restResponse.getNetconfResponseXml());
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+ factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
+ try {
+ Node child = requestMessage.createElement(XmlNetconfConstants.OK);
+ element.appendChild(child);
+ String xmlStr = XmlUtility.convertDocumentToString(element);
+ document = getDocumentDetails(factory, xmlStr);
+ } catch (Exception e) {
+ logger.error("Error while contruscting the response: {}", e.getMessage());
+ throw new DocumentedException("Operation Aborted", DocumentedException.ErrorType.from("application"),
+ DocumentedException.ErrorTag.from("operation-failed"), DocumentedException.ErrorSeverity
+ .from("ERROR"));
+ }
+ }
+ return document;
+ }
+
+ protected Document getDocumentDetails(DocumentBuilderFactory factory, String xmlStr)
+ throws DocumentedException {
+ DocumentBuilder builder;
+ Document document;
+ try {
+ builder = factory.newDocumentBuilder();
+ document = builder.parse(new InputSource(new StringReader(xmlStr)));
+ } catch (Exception e) {
+ logger.error("Error while converting String to element: {}", e.getMessage());
+ throw new DocumentedException("Operation Aborted", DocumentedException.ErrorType.from("application"),
+ DocumentedException.ErrorTag.from("operation-failed"), DocumentedException.ErrorSeverity.from("ERROR"));
+ }
+ return document;
+ }
+
+ public static final class OperationNameAndNamespace {
+ private final String operationName;
+ private final String namespace;
+
+ private final XmlElement operationElement;
+
+ public OperationNameAndNamespace(final Document message) throws DocumentedException {
+ XmlElement requestElement = null;
+ requestElement = getRequestElementWithCheck(message);
+ operationElement = requestElement.getOnlyChildElement();
+ operationName = operationElement.getName();
+ namespace = operationElement.getNamespace();
+ }
+
+ public String getOperationName() {
+ return operationName;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public XmlElement getOperationElement() {
+ return operationElement;
+ }
+
+ }
+
+ protected static XmlElement getRequestElementWithCheck(final Document message)
+ throws DocumentedException {
+ return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
+ XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+ }
+
+ public String getOpNamespace() {
+ return opNamespace;
+ }
+
+ public void setOpNamespace(String opNamespace) {
+ this.opNamespace = opNamespace;
+ }
+
+ public String getOpName() {
+ return opName;
+ }
+
+ public void setOpName(String opName) {
+ this.opName = opName;
+ }
+
+ public String getOpString() {
+ return opString;
+ }
+
+ public void setOpString(String opString) {
+ this.opString = opString;
+ }
+}
package org.commscope.tr069adapter.netconf.rpc;
-import java.io.StringReader;
-
-import javax.xml.XMLConstants;
-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;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
-import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.xml.sax.InputSource;
-
-public class RebootOperation implements NetconfOperation {
- private static final Logger logger = LoggerFactory.getLogger(RebootOperation.class);
- public static final String OP_NAMESPACE = "urn:tr069rpc:1.0";
- public static final String OP_NAME = "reboot";
-
- private String deviceID;
- private String swVersion;
- private String hwVersion;
+public class RebootOperation extends GenericOperation {
public RebootOperation(String deviceID, String swVersion, String hwVersion) {
this.deviceID = deviceID;
this.swVersion = swVersion;
this.hwVersion = hwVersion;
+ setOpString("reboot");
+ setOpNamespace("urn:tr069rpc:1.0");
+ setOpName("reboot");
}
- @Override
- public HandlingPriority canHandle(final Document message) throws DocumentedException {
- OperationNameAndNamespace operationNameAndNamespace = null;
- operationNameAndNamespace = new OperationNameAndNamespace(message);
- return canHandle(operationNameAndNamespace.getOperationName(),
- operationNameAndNamespace.getNamespace());
- }
-
- @Override
- public Document handle(Document requestMessage,
- NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
- logger.debug("Reboot rpc is received in netconfserver");
-
- final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
-
- final String msgId = requestElement.getAttribute(XmlNetconfConstants.MESSAGE_ID);
- final Element element =
- requestMessage.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
- XmlNetconfConstants.RPC_REPLY_KEY);
- element.setAttribute("xmlns:ns1", getOperationNamespace());
- element.setAttribute("message-id", msgId);
-
- String requestXml = XmlUtility.convertDocumentToString(requestElement);
- logger.debug("reboot rpc requestXml= {}", requestXml);
-
-
- NetConfServerProperties config =
- NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
-
- final String baseUrl = config.getMapperPath() + "/reboot";
- NetConfResponse restResponse =
- XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
- Document respDoc = 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 {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
- factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
- DocumentBuilder builder;
- try {
- Node child = requestMessage.createElement(XmlNetconfConstants.OK);
- element.appendChild(child);
- String xmlStr = XmlUtility.convertDocumentToString(element);
- try {
- builder = factory.newDocumentBuilder();
- respDoc = builder.parse(new InputSource(new StringReader(xmlStr)));
- } catch (Exception e) {
- logger.error("Error while converting String to element: {}", e.getMessage());
- throw new DocumentedException("Operation Aborted", ErrorType.from("application"),
- ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR"));
- }
- } catch (Exception e) {
- logger.error("Error while contruscting the response: {}", e.getMessage());
- throw new DocumentedException("Operation Aborted", ErrorType.from("application"),
- ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR"));
- }
- }
-
- return respDoc;
- }
-
- protected HandlingPriority canHandle(final String operationName,
- final String operationNamespace) {
- return operationName.equals(getOperationName())
- && operationNamespace.equals(getOperationNamespace())
- ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
- : HandlingPriority.CANNOT_HANDLE;
- }
-
- public static final class OperationNameAndNamespace {
- private final String operationName;
- private final String namespace;
-
- private final XmlElement operationElement;
-
- public OperationNameAndNamespace(final Document message) throws DocumentedException {
- XmlElement requestElement = null;
- requestElement = getRequestElementWithCheck(message);
- operationElement = requestElement.getOnlyChildElement();
- operationName = operationElement.getName();
- namespace = operationElement.getNamespace();
- }
-
- public String getOperationName() {
- return operationName;
- }
-
- public String getNamespace() {
- return namespace;
- }
-
- public XmlElement getOperationElement() {
- return operationElement;
- }
-
- }
-
- protected static XmlElement getRequestElementWithCheck(final Document message)
- throws DocumentedException {
- return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
- XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
- }
-
- protected String getOperationNamespace() {
- return OP_NAMESPACE;
- }
-
- protected String getOperationName() {
- return OP_NAME;
- }
}
package org.commscope.tr069adapter.netconf.rpc;
-import java.io.StringReader;
-
-import javax.xml.XMLConstants;
-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;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
-import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.xml.sax.InputSource;
-
-public class ResetOperation implements NetconfOperation {
- private static final Logger logger = LoggerFactory.getLogger(ResetOperation.class);
- public static final String OP_NAMESPACE = "urn:tr069rpc:1.0";
- public static final String OP_NAME = "reset";
-
- private String deviceID;
- private String swVersion;
- private String hwVersion;
+public class ResetOperation extends GenericOperation {
public ResetOperation(String deviceID, String swVersion, String hwVersion) {
this.deviceID = deviceID;
this.swVersion = swVersion;
this.hwVersion = hwVersion;
+ setOpString("reset");
+ setOpNamespace("urn:tr069rpc:1.0");
+ setOpName("reset");
}
-
- @Override
- public HandlingPriority canHandle(final Document message) throws DocumentedException {
- OperationNameAndNamespace operationNameAndNamespace = null;
- operationNameAndNamespace = new OperationNameAndNamespace(message);
- return canHandle(operationNameAndNamespace.getOperationName(),
- operationNameAndNamespace.getNamespace());
- }
-
- @Override
- public Document handle(Document requestMessage,
- NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
- logger.debug("Reset rpc is received in netconfserver");
-
- final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
-
- final String msgId = requestElement.getAttribute(XmlNetconfConstants.MESSAGE_ID);
- final Element element =
- requestMessage.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
- XmlNetconfConstants.RPC_REPLY_KEY);
- element.setAttribute("xmlns:ns1", getOperationNamespace());
- element.setAttribute("message-id", msgId);
-
- String requestXml = XmlUtility.convertDocumentToString(requestElement);
- logger.debug("reset rpc requestXml= {}", requestXml);
-
- NetConfServerProperties config =
- NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
-
- final String baseUrl = config.getMapperPath() + "/reset";
- NetConfResponse restResponse =
- XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
- Document respDoc = 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 {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
- factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
- DocumentBuilder builder;
- try {
- Node child = requestMessage.createElement(XmlNetconfConstants.OK);
- element.appendChild(child);
- String xmlStr = XmlUtility.convertDocumentToString(element);
- try {
- builder = factory.newDocumentBuilder();
- respDoc = builder.parse(new InputSource(new StringReader(xmlStr)));
- } catch (Exception e) {
- logger.error("Error while converting String to element: {}", e.getMessage());
- throw new DocumentedException("Operation Aborted", ErrorType.from("application"),
- ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR"));
- }
- } catch (Exception e) {
- logger.error("Error while contruscting the response: {}", e.getMessage());
- throw new DocumentedException("Operation Aborted", ErrorType.from("application"),
- ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR"));
- }
- }
-
- return respDoc;
- }
-
- protected HandlingPriority canHandle(final String operationName,
- final String operationNamespace) {
- return operationName.equals(getOperationName())
- && operationNamespace.equals(getOperationNamespace())
- ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
- : HandlingPriority.CANNOT_HANDLE;
- }
-
- public static final class OperationNameAndNamespace {
- private final String operationName;
- private final String namespace;
-
- private final XmlElement operationElement;
-
- public OperationNameAndNamespace(final Document message) throws DocumentedException {
- XmlElement requestElement = null;
- requestElement = getRequestElementWithCheck(message);
- operationElement = requestElement.getOnlyChildElement();
- operationName = operationElement.getName();
- namespace = operationElement.getNamespace();
- }
-
- public String getOperationName() {
- return operationName;
- }
-
- public String getNamespace() {
- return namespace;
- }
-
- public XmlElement getOperationElement() {
- return operationElement;
- }
-
- }
-
- protected static XmlElement getRequestElementWithCheck(final Document message)
- throws DocumentedException {
- return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
- XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
- }
-
- protected String getOperationNamespace() {
- return OP_NAMESPACE;
- }
-
- protected String getOperationName() {
- return OP_NAME;
- }
-
}
package org.commscope.tr069adapter.netconf.rpc;
-import java.io.StringReader;
-
-import javax.xml.XMLConstants;
-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;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
-import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.xml.sax.InputSource;
-
-public class SPAObjectOperation implements NetconfOperation {
- private static final Logger logger = LoggerFactory.getLogger(SPAObjectOperation.class);
- public static final String OP_NAMESPACE = "urn:tr069rpc:1.0";
- public static final String OP_NAME = "set-parameter-attributes";
-
- private String deviceID;
- private String swVersion;
- private String hwVersion;
+public class SPAObjectOperation extends GenericOperation {
public SPAObjectOperation(String deviceID, String swVersion, String hwVersion) {
this.deviceID = deviceID;
this.swVersion = swVersion;
this.hwVersion = hwVersion;
+ setOpString("spaobject");
+ setOpNamespace("urn:tr069rpc:1.0");
+ setOpName("set-parameter-attributes");
}
-
- @Override
- public HandlingPriority canHandle(final Document message) throws DocumentedException {
- OperationNameAndNamespace operationNameAndNamespace = null;
- operationNameAndNamespace = new OperationNameAndNamespace(message);
- return canHandle(operationNameAndNamespace.getOperationName(),
- operationNameAndNamespace.getNamespace());
- }
-
- @Override
- public Document handle(Document requestMessage,
- NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
- logger.debug("spaObject rpc is received in netconfserver");
-
- final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
-
- final String msgId = requestElement.getAttribute(XmlNetconfConstants.MESSAGE_ID);
- final Element element =
- requestMessage.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
- XmlNetconfConstants.RPC_REPLY_KEY);
- element.setAttribute("xmlns:ns1", getOperationNamespace());
- element.setAttribute("message-id", msgId);
-
- String requestXml = XmlUtility.convertDocumentToString(requestElement);
- logger.debug("spaObject rpc requestXml= {}", requestXml);
-
-
- NetConfServerProperties config =
- NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
-
- final String baseUrl = config.getMapperPath() + "/spaobject";
- NetConfResponse restResponse =
- XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
- 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.getNetconfResponseXml() != null) {
- logger.debug("spaobject rpc response received from mapper: {}",
- restResponse.getNetconfResponseXml());
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
- factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
- DocumentBuilder builder;
- try {
- Node child = requestMessage.createElement(XmlNetconfConstants.OK);
- element.appendChild(child);
- String xmlStr = XmlUtility.convertDocumentToString(element);
- try {
- builder = factory.newDocumentBuilder();
- document = builder.parse(new InputSource(new StringReader(xmlStr)));
- } catch (Exception e) {
- logger.error("Error while converting String to element: {}", e.getMessage());
- throw new DocumentedException("Operation Aborted", ErrorType.from("application"),
- ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR"));
- }
- } catch (Exception e) {
- logger.error("Error while contruscting the response: {}", e.getMessage());
- throw new DocumentedException("Operation Aborted", ErrorType.from("application"),
- ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR"));
- }
- }
-
- return document;
- }
-
- protected HandlingPriority canHandle(final String operationName,
- final String operationNamespace) {
- return operationName.equals(getOperationName())
- && operationNamespace.equals(getOperationNamespace())
- ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
- : HandlingPriority.CANNOT_HANDLE;
- }
-
- public static final class OperationNameAndNamespace {
- private final String operationName;
- private final String namespace;
-
- private final XmlElement operationElement;
-
- public OperationNameAndNamespace(final Document message) throws DocumentedException {
- XmlElement requestElement = null;
- requestElement = getRequestElementWithCheck(message);
- operationElement = requestElement.getOnlyChildElement();
- operationName = operationElement.getName();
- namespace = operationElement.getNamespace();
- }
-
- public String getOperationName() {
- return operationName;
- }
-
- public String getNamespace() {
- return namespace;
- }
-
- public XmlElement getOperationElement() {
- return operationElement;
- }
-
- }
-
- protected static XmlElement getRequestElementWithCheck(final Document message)
- throws DocumentedException {
- return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
- XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
- }
-
- protected String getOperationNamespace() {
- return OP_NAMESPACE;
- }
-
- protected String getOperationName() {
- return OP_NAME;
- }
-
}
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.xml.XmlElement;
-import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
-import org.opendaylight.netconf.mapping.api.HandlingPriority;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
-public class SoftwareActivateOperation implements NetconfOperation {
+public class SoftwareActivateOperation extends GenericOperation {
private static final Logger logger = LoggerFactory.getLogger(SoftwareActivateOperation.class);
- public static final String SOFT_MGMT_NAMESPACE = "urn:o-ran:software-management:1.0";
-
- private String deviceID;
- private String swVersion;
- private String hwVersion;
public SoftwareActivateOperation(String deviceID, String swVersion, String hwVersion) {
this.deviceID = deviceID;
this.swVersion = swVersion;
this.hwVersion = hwVersion;
- }
-
- @Override
- public HandlingPriority canHandle(final Document message) throws DocumentedException {
- OperationNameAndNamespace operationNameAndNamespace = null;
- operationNameAndNamespace = new OperationNameAndNamespace(message);
- return canHandle(operationNameAndNamespace.getOperationName(),
- operationNameAndNamespace.getNamespace());
+ setOpString("softwareActivate");
+ setOpName("software-activate");
+ setOpNamespace("urn:o-ran:software-management:1.0");
}
@Override
public Document handle(Document requestMessage,
- NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
+ NetconfOperationChainedExecution subsequentOperation) {
logger.debug("sw-activate rpc recevied in netconf server");
final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
NetConfServerProperties config =
NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
- final String baseUrl = config.getMapperPath() + "/softwareActivate";
+ final String baseUrl = config.getMapperPath() + "/" + getOpString();
XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
return null;
}
-
- protected HandlingPriority canHandle(final String operationName,
- final String operationNamespace) {
- return operationName.equals("software-activate")
- && operationNamespace.equals(SOFT_MGMT_NAMESPACE)
- ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
- : HandlingPriority.CANNOT_HANDLE;
- }
-
- public static final class OperationNameAndNamespace {
- private final String operationName;
- private final String namespace;
-
- private final XmlElement operationElement;
-
- public OperationNameAndNamespace(final Document message) throws DocumentedException {
- XmlElement requestElement = null;
- requestElement = getRequestElementWithCheck(message);
- operationElement = requestElement.getOnlyChildElement();
- operationName = operationElement.getName();
- namespace = operationElement.getNamespace();
- }
-
- public String getOperationName() {
- return operationName;
- }
-
- public String getNamespace() {
- return namespace;
- }
-
- public XmlElement getOperationElement() {
- return operationElement;
- }
- }
-
- protected static XmlElement getRequestElementWithCheck(final Document message)
- throws DocumentedException {
- return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
- XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
- }
}
ExecutorService executorService = Executors.newFixedThreadPool(10);
+ private static final String ENODEBNAME = "enodeBName";
+
+ private static final String FAIL_DEVICE_UNREGISTER = "Failed to unregister the device ";
+
public boolean loadSchemas() {
LOG.debug("Loading yang schema started");
List<ProfileDefinition> profiles = versionManager.getSupportedProfileDefinitions();
return false;
}
- try {
- FileUtils.copyDirectory(schemaDir, schemaVerDir);
- } catch (IOException e) {
- LOG.error("Failed to copy directory {} ", e.getMessage());
- }
+ copyDir(schemaDir, schemaVerDir);
boolean isSchemaLoaded = ncServerStarter.loadSchemas(schemaVerDir);
if (!isSchemaLoaded) {
LOG.debug("Failed to load schema for profile {}", profile.getProfileId());
return true;
}
+private void copyDir(File schemaDir, File schemaVerDir) {
+ try {
+ FileUtils.copyDirectory(schemaDir, schemaVerDir);
+ } catch (IOException e) {
+ LOG.error("Failed to copy directory {} ", e.getMessage());
+ }
+ }
+
public void restartServers() {
LOG.debug("Restarting all netconf servers during startup...");
Iterable<NetConfServerDetailsEntity> entities = netconfDAO.findAll();
} else {
LOG.error(
"Both deviceID and enodeBName are null. Hence failed to unregister the netconf server.");
- resultMsg = "Failed to unregister the device " + deviceId + ", enodeBName=" + enodeBName
- + ". Invalid deviceId/enodeBName specified.";
+ resultMsg = FAIL_DEVICE_UNREGISTER + deviceId + ", " + ENODEBNAME + "=" + enodeBName
+ + ". Invalid deviceId/enodeBName specified.";
+ LOG.info(resultMsg);
}
if (entity == null) {
- resultMsg = "Failed to unregister the device " + deviceId + ", enodeBName=" + enodeBName
- + ". Invalid deviceId/enodeBName specified.";
+ resultMsg = FAIL_DEVICE_UNREGISTER + deviceId + ", " + ENODEBNAME + "=" + enodeBName
+ + ". Invalid deviceId/enodeBName specified.";
LOG.info(resultMsg);
return resultMsg;
}
LOG.info(resultMsg);
delteHeartBeatTimer(deviceId);
} else {
- resultMsg = "Failed to unregister the device " + deviceId + ", enodeBName=" + enodeBName;
+ resultMsg = FAIL_DEVICE_UNREGISTER + deviceId + ", " + ENODEBNAME + "=" + enodeBName;
LOG.error(resultMsg);
}
.equalsIgnoreCase(VesAgentConstants.REMOVE_HEART_BEAT_TIMER_VAL))) {
return false;
}
- if (null != countDownTimer
- && !countDownTimer.equalsIgnoreCase(VesAgentConstants.COUNT_DOWN_TIMER_ZERO)) {
- if (null == heartBeatPeriod || heartBeatPeriod.equalsIgnoreCase(existingHeartBeatPeriod)) {
- String exceptionReason = "Can't change timer value if heartbeat value is same";
- throw new VesAgentException(VesAgentConstants.INVALID_PARAMETER_VALUE, exceptionReason);
- }
-
- }
+ validateTimers(heartBeatPeriod, countDownTimer, existingHeartBeatPeriod);
if (!VesAgentUtils.isNullOrEmpty(heartBeatPeriod)) {
attrJsonMap.put(VesAgentConstants.HEART_BEAT_PERIOD, heartBeatPeriod);
return true;
}
+ private void validateTimers(String heartBeatPeriod, String countDownTimer,
+ String existingHeartBeatPeriod) throws VesAgentException {
+ if (null != countDownTimer
+ && !countDownTimer.equalsIgnoreCase(VesAgentConstants.COUNT_DOWN_TIMER_ZERO)) {
+ validateHeartBeatPeriod(heartBeatPeriod, existingHeartBeatPeriod);
+
+ }
+ }
+
+ private void validateHeartBeatPeriod(String heartBeatPeriod, String existingHeartBeatPeriod)
+ throws VesAgentException {
+ if (null == heartBeatPeriod || heartBeatPeriod.equalsIgnoreCase(existingHeartBeatPeriod)) {
+ String exceptionReason = "Can't change timer value if heartbeat value is same";
+ throw new VesAgentException(VesAgentConstants.INVALID_PARAMETER_VALUE, exceptionReason);
+ }
+ }
+
public void processHeartBeatSetRequest(DeviceRPCRequest deviceRPCRequest, String heartBeatPeriod,
String countDownTimer) throws VesAgentException {