diff options
author | saul.gill <saul.gill@est.tech> | 2021-08-09 14:19:33 +0100 |
---|---|---|
committer | saul.gill <saul.gill@est.tech> | 2021-08-11 14:18:58 +0100 |
commit | 706b284cb8091ef00bc352bc5ee32f4fdca1162a (patch) | |
tree | b7eb30cc36c9f0dc75c24784d71faeb992ace429 /gui-clamp/ui-react/src/api | |
parent | bdc4cc9d4a75bfdd2f5656f102d2f6ac7817e4ef (diff) |
Add error handling and refactoring
Added error for when common or instance props can't be retrieved
Added error for monitoring when control loops can't be retrieved
Made node templates collapsed by default when editing properties
Added single service function to get common or instance properties
Issue-ID: POLICY-3439
Change-Id: I74560a06aae1a820862f977d5e7ac86597a093c0
Signed-off-by: saul.gill <saul.gill@est.tech>
Diffstat (limited to 'gui-clamp/ui-react/src/api')
-rw-r--r-- | gui-clamp/ui-react/src/api/ControlLoopService.js | 78 |
1 files changed, 33 insertions, 45 deletions
diff --git a/gui-clamp/ui-react/src/api/ControlLoopService.js b/gui-clamp/ui-react/src/api/ControlLoopService.js index 513fe68..4a2fdbd 100644 --- a/gui-clamp/ui-react/src/api/ControlLoopService.js +++ b/gui-clamp/ui-react/src/api/ControlLoopService.js @@ -21,42 +21,9 @@ export default class ControlLoopService { static async getControlLoopInstantiation(windowLocationPathname) { - return await fetch(windowLocationPathname + '/restservices/clds/v2/toscaControlLoop/getToscaInstantiation', { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - credentials: 'same-origin', - }).then(response => { - console.log("fetchControlLoopInstantiation received " + response.status); - - if (response.ok) { - console.info("fetchControlLoopInstantiation query successful"); - return response.json(); - } else { - return response.text().then(responseBody => { - throw Error("HTTP " + response.status + "," + responseBody); - }); - } - }).catch(error => { - console.error("fetchControlLoopInstantiation error occurred ", error); - alert("fetchControlLoopInstantiation error occurred " + error); - return undefined; - }); - } - - static async getInstanceProperties(name, version, windowLocationPathname) { - const params = { - name: name, - version: version, - common: "false" - } - - const response = await fetch(windowLocationPathname + '/restservices/clds/v2/toscaControlLoop/getCommonOrInstanceProperties' + '?' + (new URLSearchParams(params))); + const response = await fetch(windowLocationPathname + '/restservices/clds/v2/toscaControlLoop/getToscaInstantiation'); - this.checkResponseForError(response); - - return response; + return response } static async createInstanceProperties(instancePropertiesTemplate, windowLocationPathname) { @@ -83,11 +50,6 @@ export default class ControlLoopService { const response = await fetch(windowLocationPathname + '/restservices/clds/v2/toscaControlLoop/getToscaTemplate' + '?' + (new URLSearchParams(params))); - if (!response.ok) { - const message = `An error has occurred: ${ response.status }`; - throw new Error(message); - } - const data = await response; return data; @@ -108,20 +70,46 @@ export default class ControlLoopService { } - static async getCommonProperties(name, version, windowLocationPathName) { + static async deleteToscaTemplate(name, version, windowLocationPathname) { + const params = { + name: name, + version: version + } + + const response = await fetch(windowLocationPathname + + '/restservices/clds/v2/toscaControlLoop/decommissionToscaTemplate' + '?' + (new URLSearchParams(params)), + { + method: 'DELETE' + }); + + const data = await response; + + return data; + } + + static async getToscaControlLoopDefinitions(windowLocationPathname) { + + const response = await fetch(windowLocationPathname + + '/restservices/clds/v2/toscaControlLoop/getElementDefinitions'); + + this.checkResponseForError(response); + + const data = await response; + + return data; + } + + static async getCommonOrInstanceProperties(name, version, windowLocationPathName, isCommon) { const params = { name: name, version: version, - common: "true" + common: isCommon } const response = await fetch(windowLocationPathName + '/restservices/clds/v2/toscaControlLoop/getCommonOrInstanceProperties' + '?' + (new URLSearchParams(params))); - this.checkResponseForError(response); - return response; - } static async getToscaServiceTemplateSchema(section, windowLocationPathName) { |