X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ves-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Fcommscope%2Ftr069adapter%2Fvesagent%2Fasync%2FAsyncRequestHandler.java;h=beb30197bb3d18877314ca17cc0be3b607d4dbff;hb=76744e810f35c84ecbd1d9998e361052466e9483;hp=aeb8c03cf09abafc64150acd5c4677a7283907e1;hpb=ce4e2d38e3d42725f61c39dd172325d2def4bc44;p=oam%2Ftr069-adapter.git diff --git a/ves-agent/src/main/java/org/commscope/tr069adapter/vesagent/async/AsyncRequestHandler.java b/ves-agent/src/main/java/org/commscope/tr069adapter/vesagent/async/AsyncRequestHandler.java index aeb8c03..beb3019 100644 --- a/ves-agent/src/main/java/org/commscope/tr069adapter/vesagent/async/AsyncRequestHandler.java +++ b/ves-agent/src/main/java/org/commscope/tr069adapter/vesagent/async/AsyncRequestHandler.java @@ -16,147 +16,138 @@ * ===============LICENSE_END======================================================================= */ -package org.commscope.tr069adapter.vesagent.async; - -import java.util.concurrent.Future; - -import org.commscope.tr069adapter.acs.common.DeviceDetails; -import org.commscope.tr069adapter.acs.common.DeviceRPCRequest; -import org.commscope.tr069adapter.acs.common.DeviceRPCResponse; -import org.commscope.tr069adapter.acs.common.OperationCode; -import org.commscope.tr069adapter.acs.common.OperationOptions; -import org.commscope.tr069adapter.acs.common.dto.CustomOperationCode; -import org.commscope.tr069adapter.acs.common.dto.TR069OperationDetails; -import org.commscope.tr069adapter.vesagent.VesConfiguration; -import org.commscope.tr069adapter.vesagent.controller.HeartBeatMessageHandler; -import org.commscope.tr069adapter.vesagent.entity.DeviceDataEntity; -import org.commscope.tr069adapter.vesagent.mapper.MapperRequestSender; -import org.commscope.tr069adapter.vesagent.util.VesAgentConstants; -import org.commscope.tr069adapter.vesagent.util.VesAgentUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Component; - -/** - * - * @version 1.0 - * @since June 12, 2020 - * @author Prashant Kumar - */ -@Component -public class AsyncRequestHandler { - - private static final Logger LOG = LoggerFactory.getLogger(AsyncRequestHandler.class); - - @Autowired - MapperRequestSender mapperRequestSender; - - @Autowired - WaitForNotifications waitForNotifications; - - @Autowired - HeartBeatMessageHandler heartBeatMessageHandler; - - @Autowired - VesConfiguration config; - - public DeviceRPCResponse performDeviceOperation(DeviceRPCRequest deviceRPCRequest) { - LOG.info("Initiating device connectivity request to ACS for device {}", - deviceRPCRequest.getDeviceDetails().getDeviceId()); - - Future futureResponse = mapperRequestSender.sendRequest(deviceRPCRequest); - if (null == futureResponse) { - LOG.error("Request could not be sent. response is null"); - return null; - } - - boolean isSuccess = false; - DeviceRPCResponse response = null; - - OperationCode opCode = deviceRPCRequest.getOpDetails().getOpCode(); - String deviceId = deviceRPCRequest.getDeviceDetails().getDeviceId(); - long timeOut = getOperationTimeOut(deviceRPCRequest.getOptions().getExecutionTimeout()); - - try { - waitForNotifications.waitForResult(deviceId, opCode, futureResponse, timeOut); - response = waitForNotifications.getOperationResult(deviceId, opCode); - - if (null == response) { - LOG.error("Request got timed out."); - } else { - LOG.debug("Received operation result for device : {}, operation = {} as {}", deviceId, - opCode, response); - } - waitForNotifications.stopOperation(deviceId, opCode); - - // if(isSuccess) { - // response = waitForNotifications.getOperationResult(deviceId, opCode); - // LOG.debug("Received operation result for device : {}, operation = {} as {}",deviceId, - // opCode,response); - // - // waitForNotifications.stopOperation(deviceId, opCode); - // }else { - // LOG.error("Request got timed out."); - // } - } catch (InterruptedException e) { - LOG.debug( - "InterruptedException while waiting for mapper operation result for device : {}, operation : {} request.", - deviceId, opCode); - } - - return response; - } - - private long getOperationTimeOut(long timeOut) { - if (timeOut > 0) { - return timeOut; - } - - if (null != config.getRequestTimeout()) { - timeOut = Long.valueOf(config.getRequestTimeout()); - } - - return timeOut; - } - - @Async("threadPoolTaskExecutor1") +package org.commscope.tr069adapter.vesagent.async; + +import java.util.concurrent.Future; + +import org.commscope.tr069adapter.acs.common.DeviceDetails; +import org.commscope.tr069adapter.acs.common.DeviceRPCRequest; +import org.commscope.tr069adapter.acs.common.DeviceRPCResponse; +import org.commscope.tr069adapter.acs.common.OperationCode; +import org.commscope.tr069adapter.acs.common.OperationOptions; +import org.commscope.tr069adapter.acs.common.dto.CustomOperationCode; +import org.commscope.tr069adapter.acs.common.dto.TR069OperationDetails; +import org.commscope.tr069adapter.vesagent.VesConfiguration; +import org.commscope.tr069adapter.vesagent.controller.HeartBeatMessageHandler; +import org.commscope.tr069adapter.vesagent.entity.DeviceDataEntity; +import org.commscope.tr069adapter.vesagent.mapper.MapperRequestSender; +import org.commscope.tr069adapter.vesagent.util.VesAgentConstants; +import org.commscope.tr069adapter.vesagent.util.VesAgentUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +/** + * + * @version 1.0 + * @since June 12, 2020 + * @author Prashant Kumar + */ +@Component +public class AsyncRequestHandler { + + private static final Logger LOG = LoggerFactory.getLogger(AsyncRequestHandler.class); + + @Autowired + MapperRequestSender mapperRequestSender; + + @Autowired + WaitForNotifications waitForNotifications; + + @Autowired + HeartBeatMessageHandler heartBeatMessageHandler; + + @Autowired + VesConfiguration config; + + public DeviceRPCResponse performDeviceOperation(DeviceRPCRequest deviceRPCRequest) { + LOG.info("Initiating device connectivity request to ACS for device {}", + deviceRPCRequest.getDeviceDetails().getDeviceId()); + + Future futureResponse = mapperRequestSender.sendRequest(deviceRPCRequest); + if (null == futureResponse) { + LOG.error("Request could not be sent. response is null"); + return null; + } + + DeviceRPCResponse response = null; + + OperationCode opCode = deviceRPCRequest.getOpDetails().getOpCode(); + String deviceId = deviceRPCRequest.getDeviceDetails().getDeviceId(); + long timeOut = getOperationTimeOut(deviceRPCRequest.getOptions().getExecutionTimeout()); + + try { + waitForNotifications.waitForResult(deviceId, opCode, futureResponse, timeOut); + response = waitForNotifications.getOperationResult(deviceId, opCode); + + if (null == response) { + LOG.error("Request got timed out."); + } else { + LOG.debug("Received operation result for device : {}, operation = {} as {}", deviceId, + opCode, response); + } + waitForNotifications.stopOperation(deviceId, opCode); + + } catch (InterruptedException e) { + LOG.debug( + "InterruptedException while waiting for mapper operation result for device : {}, operation : {} request.", + deviceId, opCode); + Thread.currentThread().interrupt(); + } + + return response; + } + + private long getOperationTimeOut(long timeOut) { + if (timeOut > 0) { + return timeOut; + } + + if (null != config.getRequestTimeout()) { + timeOut = Long.valueOf(config.getRequestTimeout()); + } + + return timeOut; + } + + @Async("threadPoolTaskExecutor1") public void initiateDeviceReachabilityCheck(DeviceDataEntity deviceDataEntity) { - deviceDataEntity.setStartEpochMicrosec(VesAgentUtils.getStartEpochTime()*1000); - DeviceDetails deviceDetails = new DeviceDetails(); - deviceDetails.setDeviceId(deviceDataEntity.getDeviceId()); - deviceDetails.setOui(deviceDataEntity.getOui()); - deviceDetails.setProductClass(deviceDataEntity.getProductClass()); - - TR069OperationDetails operationDetails = new TR069OperationDetails(); - operationDetails.setOpCode(CustomOperationCode.CONNECT); - - DeviceRPCRequest deviceRPCRequest = new DeviceRPCRequest(); - - deviceRPCRequest.setDeviceDetails(deviceDetails); - deviceRPCRequest.setOpDetails(operationDetails); - - OperationOptions options = new OperationOptions(); - if (null != config.getRequestTimeout()) { - options.setExecutionTimeout(Integer.valueOf(config.getRequestTimeout())); - } - - deviceRPCRequest.setOptions(options); - - DeviceRPCResponse deviceRPCResponse = performDeviceOperation(deviceRPCRequest); - - if (VesAgentUtils.isDeviceReachable(deviceRPCResponse)) { - LOG.debug("Device {} is reachable.", deviceDataEntity.getDeviceId()); - try { - LOG.debug("Sending heatbeat event for device {}.", deviceDataEntity.getDeviceId()); - heartBeatMessageHandler.sendHeartBeatEvent(deviceDataEntity, Integer.parseInt( - deviceDataEntity.getAttributesMap().get(VesAgentConstants.HEART_BEAT_PERIOD))); - } catch (NumberFormatException e) { - LOG.error("heartBeatPeriod doesn't have numeric value. ErrorMsg: {}", e.getMessage()); - } catch (Exception e) { - LOG.error("Error while sending heart beat ves event. ErrorMsg: {}", e.getMessage()); - } - } - } -} + deviceDataEntity.setStartEpochMicrosec(VesAgentUtils.getStartEpochTime() * 1000); + DeviceDetails deviceDetails = new DeviceDetails(); + deviceDetails.setDeviceId(deviceDataEntity.getDeviceId()); + deviceDetails.setOui(deviceDataEntity.getOui()); + deviceDetails.setProductClass(deviceDataEntity.getProductClass()); + + TR069OperationDetails operationDetails = new TR069OperationDetails(); + operationDetails.setOpCode(CustomOperationCode.CONNECT); + + DeviceRPCRequest deviceRPCRequest = new DeviceRPCRequest(); + + deviceRPCRequest.setDeviceDetails(deviceDetails); + deviceRPCRequest.setOpDetails(operationDetails); + + OperationOptions options = new OperationOptions(); + if (null != config.getRequestTimeout()) { + options.setExecutionTimeout(Integer.valueOf(config.getRequestTimeout())); + } + + deviceRPCRequest.setOptions(options); + + DeviceRPCResponse deviceRPCResponse = performDeviceOperation(deviceRPCRequest); + + if (VesAgentUtils.isDeviceReachable(deviceRPCResponse)) { + LOG.debug("Device {} is reachable.", deviceDataEntity.getDeviceId()); + try { + LOG.debug("Sending heatbeat event for device {}.", deviceDataEntity.getDeviceId()); + heartBeatMessageHandler.sendHeartBeatEvent(deviceDataEntity, Integer.parseInt( + deviceDataEntity.getAttributesMap().get(VesAgentConstants.HEART_BEAT_PERIOD))); + } catch (NumberFormatException e) { + LOG.error("heartBeatPeriod doesn't have numeric value. ErrorMsg: {}", e.getMessage()); + } catch (Exception e) { + LOG.error("Error while sending heart beat ves event. ErrorMsg: {}", e.getMessage()); + } + } + } +}