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.acs.nbi.impl;
21 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.MAPPER_SERVICE_QUALILFIER;
22 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.TR069_NBI_REQUEST_Q;
24 import org.commscope.tr069adapter.acs.common.DeviceRPCRequest;
25 import org.commscope.tr069adapter.acs.common.OperationCode;
26 import org.commscope.tr069adapter.acs.common.exception.MapperServiceException;
27 import org.commscope.tr069adapter.acs.common.mapper.ACSServiceAPI;
28 import org.commscope.tr069adapter.acs.nbi.util.OperationIdGenerator;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.jms.core.JmsTemplate;
34 import org.springframework.stereotype.Component;
36 @Component(MAPPER_SERVICE_QUALILFIER)
37 public class ACSServiceAPIImpl implements ACSServiceAPI {
39 private static final Logger logger = LoggerFactory.getLogger(ACSServiceAPIImpl.class);
41 private static final String CLIENT_STR = "client";
44 private OperationIdGenerator opIdGenerator;
47 private JmsTemplate jmsTemplate;
52 * @see org.commscope.tr069adapter.acs.mapper.ACSServiceAPI#performDeviceOperation(org.commscope.
53 * tr069adapter.acs.DeviceRPCRequest)
56 public long performDeviceOperation(DeviceRPCRequest deviceRPCRequest)
57 throws MapperServiceException {
61 if (deviceRPCRequest != null && deviceRPCRequest.getDeviceDetails() != null) {
62 MDC.put(CLIENT_STR, deviceRPCRequest.getDeviceDetails().getDeviceId());
65 // validate the request and reject if not valid.
66 if (null == deviceRPCRequest) {
67 logger.error("Received null Mapper Request.");
68 throw new MapperServiceException("Received null Mapper Request.");
69 } else if (null == deviceRPCRequest.getOpDetails()) {
70 logger.error("Received null operation details.");
71 throw new MapperServiceException("Received null operation details.");
72 } else if (null == deviceRPCRequest.getOpDetails().getOpCode()) {
73 logger.error("Received null operation code.");
74 throw new MapperServiceException("Received null operation code.");
76 OperationCode opCode = deviceRPCRequest.getOpDetails().getOpCode();
77 logger.info("Received request to perform device operation. OperationCode: {}", opCode);
78 opId = opIdGenerator.generateOpId();
79 logger.debug("The operation ID generated for processing the Device RPC request is - {}",
81 // set opId and forward the request
82 deviceRPCRequest.setOperationId(opId);
83 jmsTemplate.convertAndSend(TR069_NBI_REQUEST_Q, deviceRPCRequest);
86 "Successfully posted the Mapper Request to Queue with OperationId : {} OperationCode : {}",
87 deviceRPCRequest.getOperationId(), deviceRPCRequest.getOpDetails().getOpCode());
88 } catch (Exception ex) {
89 MapperServiceException mapperEx =
90 new MapperServiceException("ACS Internal Error. Unknown Exception. Details :", ex);
91 logger.error(mapperEx.getMessage());
94 MDC.remove(CLIENT_STR);