Skip to content

Commit

Permalink
Merge pull request #563 from openBackhaul/develop
Browse files Browse the repository at this point in the history
Merging develop to main to tag the v2.1.1_impl
  • Loading branch information
IswaryaaS authored Jul 29, 2024
2 parents bd671e4 + 373b652 commit 5a26257
Show file tree
Hide file tree
Showing 20 changed files with 13,216 additions and 12,829 deletions.
13,980 changes: 7,310 additions & 6,670 deletions server/api/openapi.yaml

Large diffs are not rendered by default.

174 changes: 156 additions & 18 deletions server/controllers/BasicServices.js

Large diffs are not rendered by default.

113 changes: 89 additions & 24 deletions server/controllers/IndividualServices.js

Large diffs are not rendered by default.

3,790 changes: 3,790 additions & 0 deletions server/database/config.json

Large diffs are not rendered by default.

3,376 changes: 0 additions & 3,376 deletions server/database/load.json

This file was deleted.

4 changes: 2 additions & 2 deletions server/dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:14
FROM node:18

# Create app directory
WORKDIR /home/openbackhaul/applicationLayerTopology
Expand All @@ -13,7 +13,7 @@ RUN npm ci --only=production
# Bundle app source
COPY . .

EXPOSE 3005
EXPOSE 3029

#Command to start the application
CMD [ "node", "index.js" ]
20 changes: 10 additions & 10 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ var path = require('path');
var http = require('http');
var oas3Tools = require('openbackhaul-oas3-tools');
var appCommons = require('onf-core-model-ap/applicationPattern/commons/AppCommons');
var PrepareApprovedLinks = require('./service/individualServices/PrepareApprovedLinks');
var serverPort = 3005;
//var PrepareApprovedLinks = require('./service/individualServices/PrepareApprovedLinks');
var serverPort = 3029;

const ElasticsearchPreparation = require('./service/individualServices/ElasticsearchPreparation');
const preApprovedLinks = require('./utils/preApprovedLinks.json');
//const preApprovedLinks = require('./utils/preApprovedLinks.json');

// uncomment if you do not want to validate security e.g. operation-key, basic auth, etc
// appCommons.openApiValidatorOptions.validateSecurity = false;
Expand All @@ -28,7 +28,7 @@ appCommons.setupExpressApp(app);


//setting the path to the database
global.databasePath = './database/load.json'
global.databasePath = './database/config.json'

ElasticsearchPreparation.prepareElasticsearch().catch(err => {
console.error(`Error preparing Elasticsearch : ${err}`);
Expand All @@ -39,13 +39,13 @@ ElasticsearchPreparation.prepareElasticsearch().catch(err => {
console.log('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort);
console.log('Swagger-ui is available on http://localhost:%d/docs', serverPort);
});
PrepareApprovedLinks.createPreApprovedLinks(preApprovedLinks).catch(
err => {
console.error(`Error entering preapproved links : ${err}`);
}
);
// PrepareApprovedLinks.createPreApprovedLinks(preApprovedLinks).catch(
// err => {
// console.error(`Error entering preapproved links : ${err}`);
// }
// );
appCommons.performApplicationRegistration();
}
}
);


2,487 changes: 341 additions & 2,146 deletions server/package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "applicationlayertopology",
"version": "2.0.1",
"version": "2.1.1",
"description": "No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)",
"main": "index.js",
"scripts": {
Expand All @@ -22,8 +22,8 @@
"lodash.isequal": "^4.5.0",
"moment": "^2.29.1",
"node-statsd": "^0.1.1",
"onf-core-model-ap": "2.0.2-alpha.2",
"onf-core-model-ap-bs": "2.0.2-alpha.2",
"onf-core-model-ap": "2.1.1",
"onf-core-model-ap-bs": "2.1.1",
"openbackhaul-oas3-tools": "2.3.1-alpha.3",
"randexp": "^0.5.3",
"response-time": "^2.3.2",
Expand Down
295 changes: 295 additions & 0 deletions server/service/BasicServciesService.js

Large diffs are not rendered by default.

396 changes: 183 additions & 213 deletions server/service/IndividualServicesService.js

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions server/service/individualServices/ControlConstructService.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,46 @@ class ControlConstructService {
}
}

/**
* @description creates one LTP in control-construct.
* @param {String} controlConstructUuid
* @param {Object} ltpToBeAdded
* @returns {Promise<Object>} { took }
*/
static async createControlConstructLtp(controlConstructUuid, ltpToBeAdded) {
let esUuid = await ElasticsearchPreparation.getCorrectEsUuid(false);
let client = await elasticsearchService.getClient(false, esUuid);
let indexAlias = await getIndexAliasAsync(esUuid);
let response = await lock.acquire(controlConstructUuid, async () => {
let r = await client.updateByQuery({
index: indexAlias,
refresh: true,
body: {
script: {
source: `ctx._source['logical-termination-point'].add(params['ltpToBeAdded'])`,
params: {
"ltpToBeAdded": ltpToBeAdded
}
},
query: {
term: {
"uuid": controlConstructUuid
}
}
}
});
return r;
})
if (response.body.updated === 1) {
return { "took": response.body.took };
} else {
if (response.body.total === 0) {
throw new createHttpError.BadRequest(`CC with uuid ${controlConstructUuid} does not exist.`)
}
throw new Error("LTP was not updated")
}
}

/**
* @description Replaces forwarding-construct in control-construct
* @param {String} controlConstructUuid
Expand Down Expand Up @@ -438,6 +478,8 @@ class ControlConstructService {
let intermitent = (backendTime[0] * 1000 + backendTime[1] / 1000000);
if (res.body.result === 'created' || res.body.result === 'updated') {
return { "took": took + intermitent };
} else {
return { "took": -1 };
}
}

Expand Down
16 changes: 11 additions & 5 deletions server/service/individualServices/ElasticsearchPreparation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { elasticsearchService, getIndexAliasAsync, operationalStateEnum } = require('onf-core-model-ap/applicationPattern/services/ElasticsearchService');
const logicalTerminationPoint = require('onf-core-model-ap/applicationPattern/onfModel/models/LogicalTerminationPoint');
const LayerProtocol = require('onf-core-model-ap/applicationPattern/onfModel/models/LayerProtocol');
const controlConstruct = require('onf-core-model-ap/applicationPattern/onfModel/models/ControlConstruct');
const onfAttributes = require('onf-core-model-ap/applicationPattern/onfModel/constants/OnfAttributes');

module.exports = {
prepareElasticsearch,
Expand All @@ -13,8 +14,12 @@ module.exports = {
* @returns {Promise<String>} LINKS ES UUID or CC ES UUID
*/
async function getCorrectEsUuid(links) {
let uuids = await logicalTerminationPoint.getUuidListForTheProtocolAsync(LayerProtocol.layerProtocolNameEnum.ES_CLIENT);
return links ? uuids.find(uuid => uuid.endsWith('001')) : uuids.find(uuid => uuid.endsWith('000'));
let ltpList = await controlConstruct.getLogicalTerminationPointListAsync(LayerProtocol.layerProtocolNameEnum.ES_CLIENT);
if(links) {
return ltpList.find(ltp => ltp[onfAttributes.GLOBAL_CLASS.UUID].endsWith('001'))[onfAttributes.GLOBAL_CLASS.UUID];
} else {
return ltpList.find(ltp => ltp[onfAttributes.GLOBAL_CLASS.UUID].endsWith('000'))[onfAttributes.GLOBAL_CLASS.UUID];
}
}

/**
Expand All @@ -32,8 +37,9 @@ async function getCorrectEsUuid(links) {
*/
async function prepareElasticsearch() {
console.log("Configuring Elasticsearch...");
let uuids = await logicalTerminationPoint.getUuidListForTheProtocolAsync(LayerProtocol.layerProtocolNameEnum.ES_CLIENT);
for (let uuid of uuids) {
let ltpList = await controlConstruct.getLogicalTerminationPointListAsync(LayerProtocol.layerProtocolNameEnum.ES_CLIENT);
for (let ltp of ltpList) {
let uuid = ltp[onfAttributes.GLOBAL_CLASS.UUID];
let ping = await elasticsearchService.getElasticsearchClientOperationalStateAsync(uuid);
if (ping === operationalStateEnum.UNAVAILABLE) {
let err = new Error(`Elasticsearch unavailable. Skipping Elasticsearch configuration.`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const RequestHeader = require('onf-core-model-ap/applicationPattern/rest/client/
const RestRequestBuilder = require('onf-core-model-ap/applicationPattern/rest/client/RequestBuilder');
const ExecutionAndTraceService = require('onf-core-model-ap/applicationPattern/services/ExecutionAndTraceService');
const onfAttributes = require('onf-core-model-ap/applicationPattern/onfModel/constants/OnfAttributes');
const createHttpError = require('http-errors');

var traceIndicatorIncrementer = 1;

Expand All @@ -30,7 +31,7 @@ exports.automateForwardingConstructAsync = async function (forwardingAutomationI
fcp[onfAttributes.FC_PORT.PORT_DIRECTION] === FcPort.portDirectionEnum.OUTPUT
);
let found = await findOutputMatchesContextAsync(fcOutputPortList, forwardingAutomationInput.context);
return await dispatchEvent(
return await exports.dispatchEvent(
found[onfAttributes.FC_PORT.LOGICAL_TERMINATION_POINT],
forwardingAutomationInput.attributeList,
headers.user,
Expand Down Expand Up @@ -70,7 +71,7 @@ async function findOutputMatchesContextAsync(fcPortList, context) {
* @param {String} traceIndicator Sequence number of the request.
* @param {String} customerJourney Holds information supporting customer’s journey to which the execution applies.
*/
async function dispatchEvent(operationClientUuid, httpRequestBody, user, xCorrelator, traceIndicator, customerJourney) {
exports.dispatchEvent = async function (operationClientUuid, httpRequestBody, user, xCorrelator, traceIndicator, customerJourney) {
let operationKey = await OperationClientInterface.getOperationKeyAsync(
operationClientUuid);
let operationName = await OperationClientInterface.getOperationNameAsync(
Expand All @@ -82,20 +83,20 @@ async function dispatchEvent(operationClientUuid, httpRequestBody, user, xCorrel
let serverApplicationReleaseNumber = await HttpClientInterface.getReleaseNumberAsync(httpClientUuid[0]);
let originator = await HttpServerInterface.getApplicationNameAsync();
let httpRequestHeader = new RequestHeader(
user,
user,
originator,
xCorrelator,
traceIndicator,
customerJourney,
xCorrelator,
traceIndicator,
customerJourney,
operationKey
);
);
httpRequestHeader = OnfAttributeFormatter.modifyJsonObjectKeysToKebabCase(httpRequestHeader);
let response = await RestRequestBuilder.BuildAndTriggerRestRequest(
operationClientUuid,
"POST",
httpRequestHeader,
"POST",
httpRequestHeader,
httpRequestBody
);
);
let responseCode = response.status;
if (responseCode == 408) {
ExecutionAndTraceService.recordServiceRequestFromClient(serverApplicationName, serverApplicationReleaseNumber, xCorrelator, traceIndicator, user, originator, operationName, responseCode, httpRequestBody, response.data)
Expand All @@ -114,3 +115,64 @@ async function dispatchEvent(operationClientUuid, httpRequestBody, user, xCorrel
}
return response;
}

/**
* This funtion formulates the request body based on the operation name and application
* @param {String} operationClientUuid uuid of the client operation that needs to be addressed
* @param {object} httpRequestBody request body for the operation
* @param {String} user username of the request initiator.
* @param {String} xCorrelator UUID for the service execution flow that allows to correlate requests and responses.
* @param {String} traceIndicator Sequence number of the request.
* @param {String} customerJourney Holds information supporting customer’s journey to which the execution applies.
* @param {String} httpMethod method of the request if undefined defaults to POST
* @param {Object} params path and query params
*/
exports.dispatchEventWithDefaultOperationKey = async function (operationClientUuid, httpRequestBody, user, xCorrelator, traceIndicator, customerJourney, httpMethod = "POST", params) {
try {
let operationKey = "Operation key not yet provided.";
let operationName = await OperationClientInterface.getOperationNameAsync(
operationClientUuid);
// we need information from the database at this stage, because the database might change
// before the response is received, see https://github.com/openBackhaul/ExecutionAndTraceLog/issues/227
let httpClientUuid = await LogicalTerminationPoint.getServerLtpListAsync(operationClientUuid);
let serverApplicationName = await HttpClientInterface.getApplicationNameAsync(httpClientUuid[0]);
let serverApplicationReleaseNumber = await HttpClientInterface.getReleaseNumberAsync(httpClientUuid[0]);
let originator = await HttpServerInterface.getApplicationNameAsync();
let httpRequestHeader = new RequestHeader(
user,
originator,
xCorrelator,
traceIndicator,
customerJourney,
operationKey
);
httpRequestHeader = OnfAttributeFormatter.modifyJsonObjectKeysToKebabCase(httpRequestHeader);
let response = await RestRequestBuilder.BuildAndTriggerRestRequest(
operationClientUuid,
httpMethod,
httpRequestHeader,
httpRequestBody,
params
);
let responseCode = response.status;
if (responseCode == 408) {
ExecutionAndTraceService.recordServiceRequestFromClient(serverApplicationName, serverApplicationReleaseNumber, xCorrelator, traceIndicator, user, originator, operationName, responseCode, httpRequestBody, response.data)
.catch((error) => console.log(`record service request ${JSON.stringify({
xCorrelator,
traceIndicator,
user,
originator,
serverApplicationName,
serverApplicationReleaseNumber,
operationName,
responseCode,
reqBody: httpRequestBody,
resBody: response.data
})} failed with error: ${error.message}`));
}
return response;
} catch (error) {
console.log(error)
return createHttpError.InternalServerError(`${error}`);
}
}
Loading

0 comments on commit 5a26257

Please sign in to comment.