Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async function validateBasicAuth(request, scopes, schema) {
function loggingErrorHandler(err, req, res, next) {
const statusCode = err.status || 500;
const errorBody = {
code : statusCode,
code: statusCode,
message: err.message,
errors: err.errors,
}
Expand All @@ -102,7 +102,9 @@ function loggingErrorHandler(err, req, res, next) {
const traceIndicator = req.headers['trace-indicator'];
const user = req.headers.user;
const originator = req.headers.originator;
executionAndTraceService.recordServiceRequest(xCorrelator, traceIndicator, user, originator, req.url, statusCode, req.body, errorBody);
if (!(originator == "ExecutionAndTraceLog" && req.url == "/v1/record-service-request")) {
executionAndTraceService.recordServiceRequest(xCorrelator, traceIndicator, user, originator, req.url, statusCode, req.body, errorBody);
}
}
}
console.log(`loggingErrorHandler - caught error, returning response with status code "${statusCode}" and body ${JSON.stringify(errorBody)}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ const tcpClientInterface = require('./TcpClientInterface');
const onfPaths = require('../../constants/OnfPaths');
const onfAttributes = require('../../constants/OnfAttributes');
const fileOperation = require('../../../databaseDriver/JSONDriver');
global.operationKeyNotificationChannel = [];
global.notificationChannelSubscriber = [];
global.isNotificationChannelON = false;
const operationKeyUpdateNotificationService = require('../../services/OperationKeyUpdateNotificationService');
/**
* @extends LayerProtocol
*/
Expand Down Expand Up @@ -217,7 +215,7 @@ class OperationClientInterface extends LayerProtocol {
false);
}
if (isOperationKeySet == true || oldoperationKey == operationKey) {
this.addOperationKeyUpdateToNotificationChannel(operationClientUuid);
operationKeyUpdateNotificationService.addOperationKeyUpdateToNotificationChannel(operationClientUuid);
}
return isOperationKeySet;
}
Expand Down Expand Up @@ -298,93 +296,7 @@ class OperationClientInterface extends LayerProtocol {
const layerProtocol = ltp[onfAttributes.LOGICAL_TERMINATION_POINT.LAYER_PROTOCOL][0];
const layerProtocolName = layerProtocol[onfAttributes.LAYER_PROTOCOL.LAYER_PROTOCOL_NAME];
return LayerProtocol.layerProtocolNameEnum.OPERATION_CLIENT === layerProtocolName;
}

/**
* @param {HRTime} timeStampIdentifier an identifier the process that turns ON the notification channel
* @return {boolean} result whether the notificationChannel is turned ON or not
*/
static turnONNotificationChannel(timeStampIdentifier) {
try {
if (!global.notificationChannelSubscriber.includes(timeStampIdentifier)) {
global.notificationChannelSubscriber.push(timeStampIdentifier);
}
global.isNotificationChannelON = true;
console.log("******* Notification channel for Operation key is turned ON ***************");
return global.isNotificationChannelON;
} catch (error) {
return false;
}
}

/**
* @param {HRTime} timeStampAsIdentifier an identifier the process that turns OFF the notification channel
* @return {boolean} result whether the notificationChannel is turned OFF or not
*/
static turnOFFNotificationChannel(timeStampAsIdentifier) {
try {
if (global.notificationChannelSubscriber.includes(timeStampAsIdentifier)) {
global.notificationChannelSubscriber.forEach((element, index) => {
if (element == timeStampAsIdentifier) {
global.notificationChannelSubscriber = global.notificationChannelSubscriber.splice(index, 1);
}
});
}
if (global.notificationChannelSubscriber.length > 0) {
global.isNotificationChannelON = false;
console.log("******* Notification channel for Operation key is turned OFF ***************");
}
return !global.isNotificationChannelON;
} catch (error) {
return false;
}
}

/**
* function to add notifications to the global operationKeyNotificationChannel
* @param {String} operationClientUuid of the operationKey updated instance
*/
static async addOperationKeyUpdateToNotificationChannel(operationClientUuid) {
try {
if (global.isNotificationChannelON) {
let operationKeyNotification = {
"eventTime": new Date(),
"operationClientUuid": operationClientUuid
};
console.log("Notification pushed :" + operationKeyNotification.eventTime + "," + operationKeyNotification.operationClientUuid);
global.operationKeyNotificationChannel.push(operationKeyNotification);
}
} catch (error) {
console.log(error);
}
}

/**
* This function waits for a desired time until an operation-key updation is received for a client
* @param {String} operationClientUuid for which the an operation-key update is monitored
* @param {Date} timestampOfCurrentRequest shall be used to monitor whether operation-key is updated after this event's occurance
* @param {Integer} waitTime will be the maximum time to wait for an operation-key update in Seconds
* @returns {promise} boolean that represents an operation-key update
*/
static async waitUntilOperationKeyIsUpdated(operationClientUuid, timestampOfCurrentRequest, waitTime) {
let startTime = process.hrtime();
console.log("Waiting to receive operation key update for the operationClientUuid " + operationClientUuid);
return await new Promise(resolve => {
const interval = setInterval(() => {
let operationKeyUpdated = isOperationKeyUpdated(operationClientUuid, timestampOfCurrentRequest);
let waitTimeExceeded = isWaitTimeExceeded(startTime, waitTime);
if (operationKeyUpdated == true) {
console.log("Operation key update received for the operationClientUuid " + operationClientUuid);
resolve(true);
clearInterval(interval);
} else if (waitTimeExceeded == true) {
console.log("Waiting time exceeded for receiving operation key for the operationClientUuid " + operationClientUuid);
resolve(false);
clearInterval(interval);
}
}, 100);
});
}
}
}

/**
Expand All @@ -405,42 +317,5 @@ function getConfiguredRemoteAddress(remoteAddress) {
return remoteAddress;
}

/**
*
* @param {HRTime} startTime of the process
* @param {Integer} waitingTime of the process in Seconds
* @returns
*/
function isWaitTimeExceeded(startTime, waitingTime) {
let NanoSecondPerSecond = 1e9;
let executionTime = process.hrtime(startTime);
let executionTimeInseconds = (executionTime[0] * NanoSecondPerSecond + executionTime[1]) / NanoSecondPerSecond
if (executionTimeInseconds >= waitingTime) {
return true
} else {
return false;
}
}

/**
*
* @param {String} operationClientUuid uuid of the operation client interface
* @param {HRTime} eventTime of the process
* @returns
*/
function isOperationKeyUpdated(operationClientUuid, eventTime) {
let result = false;
console.log(operationClientUuid + "," + eventTime);
let oKNotificationChannel = global.operationKeyNotificationChannel;
oKNotificationChannel.filter((notification) => {
console.log("*****************************************");
console.log(notification.operationClientUuid);
console.log(operationClientUuid);
if (notification.operationClientUuid == operationClientUuid && notification.eventTime > eventTime) {
result = true;
}
});
return result;
}

module.exports = OperationClientInterface;
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const onfAttributes = require('../../constants/OnfAttributes');
const fileOperation = require('../../../databaseDriver/JSONDriver');
const ForwardingDomain = require('../../models/ForwardingDomain');
const FcPort = require('../FcPort');
const operationKeyUpdateNotificationService = require('../../services/OperationKeyUpdateNotificationService');
/**
* @extends LayerProtocol
*/
Expand Down Expand Up @@ -64,9 +65,9 @@ class OperationServerInterface extends LayerProtocol {
*/
constructor(operationName) {
this.operationServerInterfaceCapability = new OperationServerInterfacePac.
OperationServerInterfaceCapability(operationName);
OperationServerInterfaceCapability(operationName);
this.operationServerInterfaceConfiguration = new OperationServerInterfacePac.
OperationServerInterfaceConfiguration();
OperationServerInterfaceConfiguration();
}
}

Expand All @@ -78,7 +79,7 @@ class OperationServerInterface extends LayerProtocol {
super(0,
OperationServerInterface.OperationServerInterfacePac.layerProtocolName);
this[onfAttributes.LAYER_PROTOCOL.OPERATION_SERVER_INTERFACE_PAC] = new
OperationServerInterface.OperationServerInterfacePac(operationName);
OperationServerInterface.OperationServerInterfacePac(operationName);
}

/**
Expand Down Expand Up @@ -162,12 +163,20 @@ class OperationServerInterface extends LayerProtocol {
* @returns {Promise<boolean>} true | false
**/
static async setOperationKeyAsync(operationServerUuid, operationKey) {
let operationKeyPath = onfPaths.OPERATION_SERVER_OPERATION_KEY.replace(
"{uuid}", operationServerUuid);
return await fileOperation.writeToDatabaseAsync(
operationKeyPath,
operationKey,
false);
let isOperationKeySet = false
let oldoperationKey = await this.getOperationKeyAsync(operationServerUuid);
if (oldoperationKey != operationKey) {
let operationKeyPath = onfPaths.OPERATION_SERVER_OPERATION_KEY.replace(
"{uuid}", operationServerUuid);
isOperationKeySet = await fileOperation.writeToDatabaseAsync(
operationKeyPath,
operationKey,
false);
}
if (isOperationKeySet == true || oldoperationKey == operationKey) {
operationKeyUpdateNotificationService.addOperationKeyUpdateToNotificationChannel(operationServerUuid);
}
return isOperationKeySet;
}

/**
Expand Down Expand Up @@ -196,7 +205,7 @@ class OperationServerInterface extends LayerProtocol {
**/
static async getOperationServerUuidAsync(operationName) {
let logicalTerminationPointList = await controlConstruct.
getLogicalTerminationPointListAsync(LayerProtocol.layerProtocolNameEnum.OPERATION_SERVER);
getLogicalTerminationPointListAsync(LayerProtocol.layerProtocolNameEnum.OPERATION_SERVER);
if (logicalTerminationPointList != undefined) {
for (let i = 0; i < logicalTerminationPointList.length; i++) {
let logicalTerminationPoint = logicalTerminationPointList[i];
Expand Down Expand Up @@ -257,4 +266,4 @@ class OperationServerInterface extends LayerProtocol {
return "s" === splitted[5];
}
}
module.exports = OperationServerInterface;
module.exports = OperationServerInterface;
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@

global.operationKeyNotificationChannel = [];
global.notificationChannelSubscriber = [];
global.isNotificationChannelON = false;


/**
* @param {HRTime} timeStampIdentifier an identifier the process that turns ON the notification channel
* @return {boolean} result whether the notificationChannel is turned ON or not
*/
exports.turnONNotificationChannel = function(timeStampIdentifier) {
try {
if (!global.notificationChannelSubscriber.includes(timeStampIdentifier)) {
global.notificationChannelSubscriber.push(timeStampIdentifier);
}
global.isNotificationChannelON = true;
console.log("******* Notification channel for Operation key is turned ON ***************");
return global.isNotificationChannelON;
} catch (error) {
return false;
}
}

/**
* @param {HRTime} timeStampAsIdentifier an identifier the process that turns OFF the notification channel
* @return {boolean} result whether the notificationChannel is turned OFF or not
*/
exports.turnOFFNotificationChannel = function(timeStampAsIdentifier) {
try {
if (global.notificationChannelSubscriber.includes(timeStampAsIdentifier)) {
global.notificationChannelSubscriber.forEach((element, index) => {
if (element == timeStampAsIdentifier) {
global.notificationChannelSubscriber = global.notificationChannelSubscriber.splice(index, 1);
}
});
}
if (global.notificationChannelSubscriber.length > 0) {
global.isNotificationChannelON = false;
console.log("******* Notification channel for Operation key is turned OFF ***************");
}
return !global.isNotificationChannelON;
} catch (error) {
return false;
}
}

/**
* function to add notifications to the global operationKeyNotificationChannel
* @param {String} operationUuid of the operationKey updated instance
*/
exports.addOperationKeyUpdateToNotificationChannel = async function(operationUuid) {
try {
if (global.isNotificationChannelON) {
let operationKeyNotification = {
"eventTime": new Date(),
"operationUuid": operationUuid
};
console.log("Notification pushed :" + operationKeyNotification.eventTime + "," + operationKeyNotification.operationUuid);
global.operationKeyNotificationChannel.push(operationKeyNotification);
}
} catch (error) {
console.log(error);
}
}

/**
* This function waits for a desired time until an operation-key updation is received for a client or server
* @param {String} operationUuid for which the an operation-key update is monitored
* @param {Date} timestampOfCurrentRequest shall be used to monitor whether operation-key is updated after this event's occurance
* @param {Integer} waitTime will be the maximum time to wait for an operation-key update in milli seconds
* @returns {promise} boolean that represents an operation-key update
*/
exports.waitUntilOperationKeyIsUpdated = async function(operationUuid, timestampOfCurrentRequest, waitTime) {
let startTime = process.hrtime();
console.log("Waiting to receive operation key update for the operationUuid " + operationUuid);
return await new Promise(resolve => {
const interval = setInterval(() => {
let operationKeyUpdated = isOperationKeyUpdated(operationUuid, timestampOfCurrentRequest);
let waitTimeExceeded = isWaitTimeExceeded(startTime, waitTime);
if (operationKeyUpdated == true) {
console.log("Operation key update received for the operationUuid " + operationUuid);
resolve(true);
clearInterval(interval);
} else if (waitTimeExceeded == true) {
console.log("Waiting time exceeded for receiving operation key for the operationUuid " + operationUuid);
resolve(false);
clearInterval(interval);
}
}, 100);
});
}


/**
*
* @param {HRTime} startTime of the process
* @param {Integer} waitingTime of the process in milliSeconds
* @returns
*/
function isWaitTimeExceeded(startTime, waitingTime) {
let NanoSecondPerSecond = 1e9;
let executionTime = process.hrtime(startTime);
let waitingTimeInSeconds = waitingTime/1000;
let executionTimeInseconds = (executionTime[0] * NanoSecondPerSecond + executionTime[1]) / NanoSecondPerSecond
if (executionTimeInseconds >= waitingTimeInSeconds) {
return true
} else {
return false;
}
}

/**
*
* @param {String} operationUuid uuid of the operation client or server interface
* @param {HRTime} eventTime of the process
* @returns
*/
function isOperationKeyUpdated(operationUuid, eventTime) {
let result = false;
console.log(operationUuid + "," + eventTime);
let oKNotificationChannel = global.operationKeyNotificationChannel;
oKNotificationChannel.filter((notification) => {
console.log("*****************************************");
console.log(notification.operationUuid);
console.log(operationUuid);
if (notification.operationUuid == operationUuid && notification.eventTime > eventTime) {
result = true;
}
});
return result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AutomationInput {
* constructor
* @param {String} forwardingName : name of the forwarding construct.
* @param {Object} attributeList : list of attributes in key value pairs.
* @param {String} context : it should be a string with the information of application name + release number
* @param {String|undefined} context : it should be a string with the information of application name + release number
*/
constructor(forwardingName, attributeList, context) {
this.forwardingName = forwardingName;
Expand Down
Loading