From 706b284cb8091ef00bc352bc5ee32f4fdca1162a Mon Sep 17 00:00:00 2001 From: "saul.gill" Date: Mon, 9 Aug 2021 14:19:33 +0100 Subject: 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 --- gui-clamp/ui-react/src/api/ControlLoopService.js | 78 ++++++++++-------------- 1 file changed, 33 insertions(+), 45 deletions(-) (limited to 'gui-clamp/ui-react/src/api') 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) { -- cgit 1.2.3-korg