-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip: creation of health objects/algo * [test]: maj de request * wip: it works for sameProcess services * works for newProcesses * add type inside response, update tests and doc * [fix] delete read message * [doc] fix changelog version
- Loading branch information
Showing
29 changed files
with
994 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
'use strict'; | ||
|
||
const errorManager = require('../../../../utils/errorManager'); | ||
const log4js = require('log4js'); | ||
const HealthRequest = require('../../../../requests/healthRequest'); | ||
|
||
var LOGGER = log4js.getLogger("CONTROLLER"); | ||
|
||
module.exports = { | ||
|
||
/** | ||
* | ||
* @function | ||
* @name checkHealthParameters | ||
* @description Vérification des paramètres d'une requête sur /health | ||
* @param {object} parameters - ensemble des paramètres de la requête | ||
* @return {object} HealthRequest - Instance de la classe HealthRequest | ||
* | ||
*/ | ||
|
||
checkHealthParameters: function(parameters) { | ||
|
||
LOGGER.debug("checkHealthParameters()"); | ||
|
||
// Il n'y a aucun paramètre obligatoire donc on peut créer l'objet request | ||
let healthRequest = new HealthRequest(); | ||
|
||
// Verbose | ||
if (parameters.verbose) { | ||
|
||
LOGGER.debug("user verbose:"); | ||
LOGGER.debug(parameters.verbose); | ||
|
||
if (parameters.verbose === "true") { | ||
healthRequest.verbose = true; | ||
} else if (parameters.verbose === "false") { | ||
healthRequest.verbose = false; | ||
} else { | ||
throw errorManager.createError(" Parameter 'verbose' is invalid: value should be 'true' or 'false'", 400); | ||
} | ||
|
||
} else { | ||
// paramètre non obligatoire | ||
LOGGER.debug("default verbose used: false"); | ||
} | ||
|
||
return healthRequest; | ||
|
||
}, | ||
|
||
/** | ||
* | ||
* @function | ||
* @name writeHealthResponse | ||
* @description Ré-écriture de la réponse pour une requête sur /health | ||
* @param {object} HealthRequest - Instance de la classe HealthRequest | ||
* @param {object} HealthResponse - Instance de la classe HealthResponse | ||
* @return {object} userResponse - Réponse envoyée à l'utilisateur | ||
* | ||
*/ | ||
|
||
writeHealthResponse: function(healthRequest, healthResponse) { | ||
|
||
let userResponse = {}; | ||
|
||
LOGGER.debug("writeHealthResponse()"); | ||
|
||
userResponse.state = healthResponse.globalState; | ||
|
||
if (!healthRequest.verbose) { | ||
return userResponse; | ||
} | ||
|
||
userResponse.administrator = {}; | ||
userResponse.administrator.state = healthResponse.adminState; | ||
|
||
userResponse.services = healthResponse.serviceStates; | ||
|
||
return userResponse; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
|
||
const Request = require('./request'); | ||
|
||
/** | ||
* | ||
* @class | ||
* @name healthRequest | ||
* @description Classe modélisant une requête d'état du serveur Road2. | ||
* | ||
*/ | ||
|
||
module.exports = class healthRequest extends Request { | ||
|
||
/** | ||
* | ||
* @function | ||
* @name constructor | ||
* @description Constructeur de la classe healthRequest | ||
* | ||
*/ | ||
|
||
constructor() { | ||
|
||
super("health","healthRequest"); | ||
|
||
this._verbose = false; | ||
|
||
} | ||
|
||
/** | ||
* | ||
* @function | ||
* @name get verbose | ||
* @description Récupérer le caractère verbeux de la requête | ||
* | ||
*/ | ||
get verbose() { | ||
return this._verbose; | ||
} | ||
|
||
/** | ||
* | ||
* @function | ||
* @name set verbose | ||
* @description Attribuer le caractère verbeux de la requête. | ||
* @param {Boolean} | ||
* | ||
*/ | ||
set verbose(v) { | ||
this._verbose = v; | ||
} | ||
|
||
} |
Oops, something went wrong.