From 71d6358a8f787c5d2688a485d42ff9514dc58a56 Mon Sep 17 00:00:00 2001 From: brunomilitzer Date: Thu, 8 Jul 2021 15:33:55 +0100 Subject: Add Upload Control Loop Instantiation Created Functionality to Upload JSON file to Control Loop Instantiation. Issue-ID: POLICY-3436 Change-Id: Iefd538c91154b7e61615ab63b440378e2feea502 Signed-off-by: brunomilitzer --- gui-clamp/ui-react/src/LoopUI.js | 6 +- .../ui-react/src/__snapshots__/LoopUI.test.js.snap | 6 +- .../src/__snapshots__/OnapClamp.test.js.snap | 6 +- gui-clamp/ui-react/src/api/ControlLoopService.js | 24 +++- .../dialogs/ControlLoop/ControlLoopElementItem.js | 124 ------------------- .../dialogs/ControlLoop/ControlLoopElements.js | 41 ------- .../dialogs/ControlLoop/ControlLoopItem.js | 128 ------------------- .../ControlLoop/InstantiationElementItem.js | 124 +++++++++++++++++++ .../dialogs/ControlLoop/InstantiationElements.js | 41 +++++++ .../dialogs/ControlLoop/InstantiationItem.js | 128 +++++++++++++++++++ .../dialogs/ControlLoop/MonitorInstantiation.js | 72 +++++++++++ .../ControlLoop/MonitorInstantiation.test.js | 64 ++++++++++ .../ControlLoop/MonitoringControlLoopModal.js | 71 ----------- .../ControlLoop/UploadToscaInstantiation.js | 136 +++++++++++++++++++++ .../ControlLoop/UploadToscaInstantiation.test.js | 102 ++++++++++++++++ .../ControlLoop/UploadToscaInstantiationFile.js | 52 ++++++++ .../UploadToscaInstantiationFile.test.js | 61 +++++++++ .../MonitorInstantiation.test.js.snap | 32 +++++ .../UploadToscaInstantiation.test.js.snap | 91 ++++++++++++++ .../UploadToscaInstantiationFile.test.js.snap | 16 +++ .../Policy/toscaInstantiationData.test.json | 59 +++++++++ gui-clamp/ui-react/src/components/menu/MenuBar.js | 4 +- .../menu/__snapshots__/MenuBar.test.js.snap | 74 ++++++++++- 23 files changed, 1086 insertions(+), 376 deletions(-) delete mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopElementItem.js delete mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopElements.js delete mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopItem.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationElementItem.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationElements.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationItem.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.test.js delete mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitoringControlLoopModal.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiation.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiation.test.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiationFile.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiationFile.test.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/MonitorInstantiation.test.js.snap create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaInstantiation.test.js.snap create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaInstantiationFile.test.js.snap create mode 100644 gui-clamp/ui-react/src/components/dialogs/Policy/toscaInstantiationData.test.json (limited to 'gui-clamp/ui-react/src') diff --git a/gui-clamp/ui-react/src/LoopUI.js b/gui-clamp/ui-react/src/LoopUI.js index 752c89d..109a0b3 100644 --- a/gui-clamp/ui-react/src/LoopUI.js +++ b/gui-clamp/ui-react/src/LoopUI.js @@ -52,8 +52,9 @@ import Spinner from 'react-bootstrap/Spinner'; import { Link } from 'react-router-dom'; import ReadAndConvertYaml from "./components/dialogs/ControlLoop/ReadAndConvertYaml"; -import MonitoringControlLoopModal from "./components/dialogs/ControlLoop/MonitoringControlLoopModal"; +import MonitorInstantiation from "./components/dialogs/ControlLoop/MonitorInstantiation"; import GetLocalToscaFileForUpload from "./components/dialogs/ControlLoop/GetLocalToscaFileForUpload"; +import UploadToscaInstantiation from "./components/dialogs/ControlLoop/UploadToscaInstantiation"; const StyledMainDiv = styled.div` background-color: ${ props => props.theme.backgroundColor }; @@ -382,7 +383,8 @@ export default class LoopUI extends React.Component { showSucAlert={ this.showSucAlert } showFailAlert={ this.showFailAlert }/>) } /> - () }/> + () }/> + () }/> ); } diff --git a/gui-clamp/ui-react/src/__snapshots__/LoopUI.test.js.snap b/gui-clamp/ui-react/src/__snapshots__/LoopUI.test.js.snap index 6d25823..040fdaa 100644 --- a/gui-clamp/ui-react/src/__snapshots__/LoopUI.test.js.snap +++ b/gui-clamp/ui-react/src/__snapshots__/LoopUI.test.js.snap @@ -82,7 +82,11 @@ exports[`Verify LoopUI Test the render method 1`] = ` render={[Function]} /> +
diff --git a/gui-clamp/ui-react/src/__snapshots__/OnapClamp.test.js.snap b/gui-clamp/ui-react/src/__snapshots__/OnapClamp.test.js.snap index f5680b1..5d8a207 100644 --- a/gui-clamp/ui-react/src/__snapshots__/OnapClamp.test.js.snap +++ b/gui-clamp/ui-react/src/__snapshots__/OnapClamp.test.js.snap @@ -111,7 +111,11 @@ exports[`Verify OnapClamp Test the render method 1`] = ` render={[Function]} /> +
diff --git a/gui-clamp/ui-react/src/api/ControlLoopService.js b/gui-clamp/ui-react/src/api/ControlLoopService.js index 1882f78..30b0522 100644 --- a/gui-clamp/ui-react/src/api/ControlLoopService.js +++ b/gui-clamp/ui-react/src/api/ControlLoopService.js @@ -19,7 +19,7 @@ export default class ControlLoopService { - static async getControlLoopList(windowLocationPathname) { + static async fetchControlLoopInstantiation(windowLocationPathname) { return await fetch(windowLocationPathname + '/restservices/clds/v2/toscaControlLoop/getToscaInstantiation', { method: 'GET', @@ -28,10 +28,10 @@ export default class ControlLoopService { }, credentials: 'same-origin', }).then(response => { - console.log("getControlLoopList received " + response.status); + console.log("fetchControlLoopInstantiation received " + response.status); if (response.ok) { - console.info("getControlLoopList query successful"); + console.info("fetchControlLoopInstantiation query successful"); return response.json(); } else { return response.text().then(responseBody => { @@ -39,12 +39,26 @@ export default class ControlLoopService { }); } }).catch(error => { - console.error("getControlLoopList error occurred ", error); - alert("getControlLoopList error occurred " + error); + console.error("fetchControlLoopInstantiation error occurred ", error); + alert("fetchControlLoopInstantiation error occurred " + error); return undefined; }); } + static async uploadToscaInstantiation(toscaObject, windowLocationPathname) { + + const response = await fetch(windowLocationPathname + '/restservices/clds/v2/toscaControlLoop/postToscaInstantiation', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + credentials: 'same-origin', + body: JSON.stringify(toscaObject) + }); + + return response; + } + static async getToscaTemplate(name, version, windowLocationPathname) { const params = { name: name, diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopElementItem.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopElementItem.js deleted file mode 100644 index 632cacd..0000000 --- a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopElementItem.js +++ /dev/null @@ -1,124 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -import React, { useEffect, useState } from "react"; -import styled from "styled-components"; -import { Button } from "react-bootstrap"; - -const UninitialisedBox = styled.div` - margin: 0; - padding: 0 0 1px 0; - border-bottom: 1px solid #7f7f7f; - background: #cccccc; - font-weight: normal; - border-radius: 0; -` -const PassiveBox = styled.div` - margin: 0; - padding: 0 0 1px 0; - border-bottom: 1px solid #7f7f7f; - background: #ffe87c; - font-weight: normal; - border-radius: 0; -` -const RunningBox = styled.div` - margin: 0; - padding: 0 0 1px 0; - border-bottom: 1px solid #7f7f7f; - background: #7ec699; - font-weight: normal; - border-radius: 0; -` -const ButtonStyle = styled(Button)` - margin: 0; - padding: 5px 12px; - width: 100%; - text-align: left; - background: transparent !important; - color: #000000 !important; - text-decoration: none !important; - border: none; - border-radius: 0; - - :hover, :active :focus { - color: #000000 !important; - outline: 0 !important; - box-shadow: none !important; - background: transparent !important; - text-decoration: none !important; - } -` - -const ControlLoopElementItem = (props) => { - const [title, setTitle] = useState(""); - - useEffect(() => { - const title = props.title.split("."); - setTitle(title[4]); - }, []); - - const toggleState = () => { - switch (props.orderedState) { - case 'UNINITIALISED': - return renderUninitialisedOrderedState(); - case 'PASSIVE': - return renderPassiveOrderedState(); - case 'RUNNING': - return renderRunningOrderedState(); - } - } - - const renderUninitialisedOrderedState = () => { - return ( - - - - ) - } - - const renderPassiveOrderedState = () => { - return ( - - - - ) - } - - const renderRunningOrderedState = () => { - return ( - - - - ) - } - - return ( - - { toggleState() } - - ); -} - -export default ControlLoopElementItem; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopElements.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopElements.js deleted file mode 100644 index 57bdf40..0000000 --- a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopElements.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -import React, { useEffect, useState } from "react"; -import ControlLoopElementItem from "./ControlLoopElementItem"; - -const ControlLoopElements = (props) => { - const [clElements, setClElements] = useState([]); - - useEffect(() => { - setClElements(Object.values(props.elements)); - }, []); - - return ( - - { - clElements.map((clEl, index) => ( - - )) - } - - ); -} - -export default ControlLoopElements; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopItem.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopItem.js deleted file mode 100644 index f149517..0000000 --- a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopItem.js +++ /dev/null @@ -1,128 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -import React from "react"; -import styled from 'styled-components'; - -import { Accordion, Button, Card } from "react-bootstrap"; - -const AccordionBody = styled.div` - margin: 0; - padding: 0; - border: 1px solid #7f7f7f; - border-radius: 0; -` - -const CardBody = styled(Card.Body)` - padding: 0; - margin: 0; -` - -const UninitialisedHeader = styled.div` - margin: 0; - padding: 0 0 1px 0; - border-bottom: 1px solid #7f7f7f; - background: #cccccc; - font-weight: normal; - border-radius: 0; -` - -const PassiveHeader = styled.div` - margin: 0; - padding: 0 0 1px 0; - border-bottom: 1px solid #7f7f7f; - background: #ffe87c; - font-weight: normal; - border-radius: 0; -` - -const RunningHeader = styled.div` - margin: 0; - padding: 0 0 1px 0; - border-bottom: 1px solid #7f7f7f; - background: #7ec699; - font-weight: normal; - border-radius: 0; -` - -const ToggleButton = styled(Button)` - color: #000000; - text-decoration: none; - - :hover, :active { - color: #000000; - text-decoration: none !important; - } -` - -const ControlLoopItem = (props) => { - const toggleState = () => { - switch (props.orderedState) { - case 'UNINITIALISED': - return renderUninitialisedOrderedState() - case 'PASSIVE': - return renderPassiveOrderedState(); - case 'RUNNING': - return renderRunningOrderedState(); - } - } - - const renderUninitialisedOrderedState = () => { - return ( - - - { props.title } - - - ) - } - - const renderPassiveOrderedState = () => { - return ( - - - { props.title } - - - ) - } - - const renderRunningOrderedState = () => { - return ( - - - { props.title } - - - ) - } - - return ( - - - { toggleState() } - - { props.children } - - - - ); -} - -export default ControlLoopItem; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationElementItem.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationElementItem.js new file mode 100644 index 0000000..0e2c407 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationElementItem.js @@ -0,0 +1,124 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import React, { useEffect, useState } from "react"; +import styled from "styled-components"; +import { Button } from "react-bootstrap"; + +const UninitialisedBox = styled.div` + margin: 0; + padding: 0 0 1px 0; + border-bottom: 1px solid #7f7f7f; + background: #cccccc; + font-weight: normal; + border-radius: 0; +` +const PassiveBox = styled.div` + margin: 0; + padding: 0 0 1px 0; + border-bottom: 1px solid #7f7f7f; + background: #ffe87c; + font-weight: normal; + border-radius: 0; +` +const RunningBox = styled.div` + margin: 0; + padding: 0 0 1px 0; + border-bottom: 1px solid #7f7f7f; + background: #7ec699; + font-weight: normal; + border-radius: 0; +` +const ButtonStyle = styled(Button)` + margin: 0; + padding: 5px 12px; + width: 100%; + text-align: left; + background: transparent !important; + color: #000000 !important; + text-decoration: none !important; + border: none; + border-radius: 0; + + :hover, :active :focus { + color: #000000 !important; + outline: 0 !important; + box-shadow: none !important; + background: transparent !important; + text-decoration: none !important; + } +` + +const InstantiationElementItem = (props) => { + const [title, setTitle] = useState(""); + + useEffect(() => { + const title = props.title.split("."); + setTitle(title[4]); + }, []); + + const toggleState = () => { + switch (props.orderedState) { + case 'UNINITIALISED': + return renderUninitialisedOrderedState(); + case 'PASSIVE': + return renderPassiveOrderedState(); + case 'RUNNING': + return renderRunningOrderedState(); + } + } + + const renderUninitialisedOrderedState = () => { + return ( + + + + ) + } + + const renderPassiveOrderedState = () => { + return ( + + + + ) + } + + const renderRunningOrderedState = () => { + return ( + + + + ) + } + + return ( + + { toggleState() } + + ); +} + +export default InstantiationElementItem; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationElements.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationElements.js new file mode 100644 index 0000000..d8e6348 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationElements.js @@ -0,0 +1,41 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import React, { useEffect, useState } from "react"; +import InstantiationElementItem from "./InstantiationElementItem"; + +const InstantiationElements = (props) => { + const [clElements, setClElements] = useState([]); + + useEffect(() => { + setClElements(Object.values(props.elements)); + }, []); + + return ( + + { + clElements.map((clEl, index) => ( + + )) + } + + ); +} + +export default InstantiationElements; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationItem.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationItem.js new file mode 100644 index 0000000..a59770b --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationItem.js @@ -0,0 +1,128 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import React from "react"; +import styled from 'styled-components'; + +import { Accordion, Button, Card } from "react-bootstrap"; + +const AccordionBody = styled.div` + margin: 0; + padding: 0; + border: 1px solid #7f7f7f; + border-radius: 0; +` + +const CardBody = styled(Card.Body)` + padding: 0; + margin: 0; +` + +const UninitialisedHeader = styled.div` + margin: 0; + padding: 0 0 1px 0; + border-bottom: 1px solid #7f7f7f; + background: #cccccc; + font-weight: normal; + border-radius: 0; +` + +const PassiveHeader = styled.div` + margin: 0; + padding: 0 0 1px 0; + border-bottom: 1px solid #7f7f7f; + background: #ffe87c; + font-weight: normal; + border-radius: 0; +` + +const RunningHeader = styled.div` + margin: 0; + padding: 0 0 1px 0; + border-bottom: 1px solid #7f7f7f; + background: #7ec699; + font-weight: normal; + border-radius: 0; +` + +const ToggleButton = styled(Button)` + color: #000000; + text-decoration: none; + + :hover, :active { + color: #000000; + text-decoration: none !important; + } +` + +const InstantiationItem = (props) => { + const toggleState = () => { + switch (props.orderedState) { + case 'UNINITIALISED': + return renderUninitialisedOrderedState() + case 'PASSIVE': + return renderPassiveOrderedState(); + case 'RUNNING': + return renderRunningOrderedState(); + } + } + + const renderUninitialisedOrderedState = () => { + return ( + + + { props.title } + + + ) + } + + const renderPassiveOrderedState = () => { + return ( + + + { props.title } + + + ) + } + + const renderRunningOrderedState = () => { + return ( + + + { props.title } + + + ) + } + + return ( + + + { toggleState() } + + { props.children } + + + + ); +} + +export default InstantiationItem; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.js new file mode 100644 index 0000000..428defa --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.js @@ -0,0 +1,72 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import React, { useEffect, useState } from "react"; +import styled from "styled-components"; +import Modal from "react-bootstrap/Modal"; +import Button from "react-bootstrap/Button"; +import InstantiationItem from "./InstantiationItem"; +import ControlLoopService from "../../../api/ControlLoopService"; +import InstantiationElements from "./InstantiationElements"; + +const ModalStyled = styled(Modal)` + background-color: transparent; +` + +const MonitorInstantiation = (props) => { + const [show, setShow] = useState(true); + const [controlLoopList, setControlLoopList] = useState([]); + const [windowLocationPathname, setWindowLocationPathname] = useState(''); + + useEffect(() => { + setWindowLocationPathname(window.location.pathname); + + ControlLoopService.fetchControlLoopInstantiation(windowLocationPathname).then(controlLoopList => { + setControlLoopList(controlLoopList['controlLoopList']); + }); + }, []) + + const handleClose = () => { + console.log('handleClose called'); + setShow(false); + props.history.push('/'); + } + + return ( + + + Tosca Instantiation - Monitoring + + + { + controlLoopList.map((clList, index) => ( + + + + )) + } + + + + + + ) +} + +export default MonitorInstantiation; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.test.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.test.js new file mode 100644 index 0000000..5e30924 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.test.js @@ -0,0 +1,64 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import { mount, shallow } from "enzyme"; +import toJson from "enzyme-to-json"; +import { createMemoryHistory } from "history"; +import React from "react"; +import MonitorInstantiation from "./MonitorInstantiation"; +import { act } from "react-dom/test-utils"; + +describe('Verify MonitoringInstantiation', () => { + + it("renders without crashing", () => { + shallow(); + }); + + it("renders correctly", () => { + const tree = shallow(); + expect(toJson(tree)).toMatchSnapshot(); + }); + + it('should have a Button element', () => { + const container = shallow() + expect(container.find('Button').length).toEqual(1); + }); + + it('handleClose called when bottom button clicked', () => { + const history = createMemoryHistory(); + const component = mount() + const logSpy = jest.spyOn(console, 'log'); + + act(() => { + component.find('[variant="secondary"]').simulate('click'); + expect(logSpy).toHaveBeenCalledWith('handleClose called'); + }); + }); + + it('handleClose called when top-right button clicked', () => { + const history = createMemoryHistory(); + const component = mount() + const logSpy = jest.spyOn(console, 'log'); + + act(() => { + component.find('[size="xl"]').get(0).props.onHide(); + expect(logSpy).toHaveBeenCalledWith('handleClose called'); + }); + }); +}); diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitoringControlLoopModal.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitoringControlLoopModal.js deleted file mode 100644 index 03fb64b..0000000 --- a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitoringControlLoopModal.js +++ /dev/null @@ -1,71 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -import React, { useEffect, useState } from "react"; -import styled from "styled-components"; -import Modal from "react-bootstrap/Modal"; -import Button from "react-bootstrap/Button"; -import ControlLoopItem from "./ControlLoopItem"; -import ControlLoopService from "../../../api/ControlLoopService"; -import ControlLoopElements from "./ControlLoopElements"; - -const ModalStyled = styled(Modal)` - background-color: transparent; -` - -const MonitoringControlLoopModal = (props) => { - const [show, setShow] = useState(true); - const [controlLoopList, setControlLoopList] = useState([]); - const [windowLocationPathname, setWindowLocationPathname] = useState(''); - - useEffect(() => { - setWindowLocationPathname(window.location.pathname); - - ControlLoopService.getControlLoopList(windowLocationPathname).then(controlLoopList => { - setControlLoopList(controlLoopList['controlLoopList']); - }); - }, []) - - const handleClose = () => { - setShow(false); - props.history.push('/'); - } - - return ( - - - Tosca Control Loop - Monitoring - - - { - controlLoopList.map((clList, index) => ( - - - - )) - } - - - - - - ) -} - -export default MonitoringControlLoopModal; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiation.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiation.js new file mode 100644 index 0000000..d9bbe8b --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiation.js @@ -0,0 +1,136 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import React, { useState } from "react"; +import Modal from "react-bootstrap/Modal"; +import Button from "react-bootstrap/Button"; +import styled from "styled-components"; +import Row from "react-bootstrap/Row"; +import Form from "react-bootstrap/Form"; +import UploadToscaInstantiationFile from "./UploadToscaInstantiationFile"; +import jsYaml from "js-yaml"; +import Alert from "react-bootstrap/Alert"; + +const ModalStyled = styled(Modal)` + background-color: transparent; +` +const StyledMessagesDiv = styled.div` + overflow: auto; + min-width: 100%; + max-height: 300px; + padding: 5px 5px 0px 5px; + text-align: center; +` + +const UploadToscaInstantiation = (props) => { + const [show, setShow] = useState(true); + const [fileIsSelected, setFileIsSelected] = useState(false); + const [selectedFile, setSelectedFile] = useState(); + const [jsonObject, setJsonObject] = useState([]); + const [alertMessages, setAlertMessages] = useState(); + + const fileUploadHandler = (event) => { + event.preventDefault(); + console.log('fileUploadHandler called'); + + const file = event.currentTarget.files[0]; + + if (file !== undefined) { + console.log('fileDefined called'); + setSelectedFile(file); + setFileIsSelected(true); + + const fileReader = new FileReader(); + fileReader.onload = () => { + const jsonFile = jsYaml.load(fileReader.result, 'utf8') + setJsonObject(jsonFile) + } + + fileReader.readAsText(file); + } else { + console.log('fileUndefined called'); + } + } + + const onResponseReceivedHandler = async (response) => { + console.log('onResponseReceivedHandler called'); + + if (await response.ok) { + setAlertMessages( + Upload Success +

Tosca Instantiation from { selectedFile.name } was Successfully Uploaded

+
+

Type: { selectedFile.type }

Size: { +selectedFile.size / 1000 }Kb

+
); + } else { + setAlertMessages( + Upload Failure +

Tosca Instantiation from { selectedFile.name } failed to upload

+

Status code: { await response.status }: { response.statusText }

+

Response Text: { await response.text() }

+
+

Type: { selectedFile.type }

Size: { +selectedFile.size / 1000 }Kb

+
); + } + } + + const handleClose = () => { + console.log('handleClose called'); + setShow(false); + props.history.push('/'); + } + + return ( + + + Tosca Control Loop - Create Instantiation + +
+ +
+ + + + Only .yaml, .yml and .json files are supported + + + + { alertMessages } + + +
+
+
+ + + +
+ ) +} + +export default UploadToscaInstantiation; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiation.test.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiation.test.js new file mode 100644 index 0000000..79daafb --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiation.test.js @@ -0,0 +1,102 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import { mount, shallow } from "enzyme"; +import React from "react"; +import toJson from "enzyme-to-json"; +import UploadToscaInstantiation from "./UploadToscaInstantiation"; +import { createMemoryHistory } from "history"; +import { act } from "react-dom/test-utils"; + +describe("Verify UploadToscaInstantiation", () => { + const fs = require("fs"); + const jsonFile = fs.readFileSync("src/components/dialogs/Policy/toscaInstantiationData.test.json"); + const file = new Blob([jsonFile], { type: 'file' }); + + it("renders without crashing", () => { + shallow(); + }); + + it("renders correctly", () => { + const tree = shallow(); + expect(toJson(tree)).toMatchSnapshot(); + }); + + it('should have a Button element', () => { + const container = shallow() + expect(container.find('Button').length).toEqual(1); + }); + + it('handleClose called when bottom button clicked', () => { + const history = createMemoryHistory(); + const component = mount() + const logSpy = jest.spyOn(console, 'log'); + + + act(() => { + component.find('[variant="secondary"]').simulate('click'); + expect(logSpy).toHaveBeenCalledWith('handleClose called'); + }); + }); + + it('handleClose called when top-right button clicked', () => { + const history = createMemoryHistory(); + const component = mount() + const logSpy = jest.spyOn(console, 'log'); + + + act(() => { + component.find('[size="lg"]').get(0).props.onHide(); + expect(logSpy).toHaveBeenCalledWith('handleClose called'); + }); + }); + + it('fileUploadHandler called when uploading a defined file', () => { + const component = mount() + const logSpy = jest.spyOn(console, 'log'); + + const event = { + preventDefault() { + }, + currentTarget: { files: [file] } + }; + + act(() => { + component.find('[type="file"]').get(0).props.onChange(event); + expect(logSpy).toHaveBeenCalledWith('fileUploadHandler called'); + expect(logSpy).toHaveBeenCalledWith('fileDefined called'); + }); + }); + + it('fileUploadHandler called when uploading a undefined file', () => { + const component = mount() + const logSpy = jest.spyOn(console, 'log'); + + const event = { + preventDefault() { + }, + currentTarget: { files: [] } + }; + + act(() => { + component.find('[type="file"]').get(0).props.onChange(event); + expect(logSpy).toHaveBeenCalledWith('fileUndefined called'); + }); + }); +}); diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiationFile.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiationFile.js new file mode 100644 index 0000000..5329bc0 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiationFile.js @@ -0,0 +1,52 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import React, { useEffect, useState } from "react"; +import Button from "react-bootstrap/Button"; +import ControlLoopService from "../../../api/ControlLoopService"; + +const UploadToscaInstantiationFile = (props) => { + const [windowLocationPathName, setWindowLocationPathname] = useState(''); + + const postToscaInstantiationHandler = async (event) => { + event.preventDefault(); + console.log('postToscaInstantiationHandler called'); + + setWindowLocationPathname(window.location.pathname); + + const response = await ControlLoopService.uploadToscaInstantiation(props.jsonObject, windowLocationPathName) + .catch(error => error.message); + + props.onResponseReceived(response); + } + + return ( + + + + ); +} + +export default UploadToscaInstantiationFile; + diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiationFile.test.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiationFile.test.js new file mode 100644 index 0000000..83ab8d5 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiationFile.test.js @@ -0,0 +1,61 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import { mount, shallow } from "enzyme"; +import React from "react"; +import UploadToscaInstantiationFile from "./UploadToscaInstantiationFile"; +import toJson from "enzyme-to-json"; +import { act } from "react-dom/test-utils"; + +describe('Verify UploadToscaInstantiationFile', () => { + + it("renders without crashing", () => { + shallow(); + }); + + it("renders correctly", () => { + const tree = shallow(); + expect(toJson(tree)).toMatchSnapshot(); + }); + + it('should have a Button element', () => { + const container = shallow() + expect(container.find('Button').length).toEqual(1); + }); + + it('Button should have a specific text', () => { + const container = shallow() + expect(container.find('Button').text()).toBe('Upload Tosca Instantiation'); + }); + + it('button should call postToscaInstantiationHandler when clicked', async () => { + const mockFunction = jest.fn(() => 'default'); + const component = mount() + const logSpy = jest.spyOn(console, 'log'); + const event = { + preventDefault() { + } + }; + + await act(async () => { + component.find('[variant="primary"]').get(0).props.onClick(event); + expect(logSpy).toHaveBeenCalledWith('postToscaInstantiationHandler called'); + }); + }); +}); diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/MonitorInstantiation.test.js.snap b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/MonitorInstantiation.test.js.snap new file mode 100644 index 0000000..6504b54 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/MonitorInstantiation.test.js.snap @@ -0,0 +1,32 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Verify MonitoringInstantiation renders correctly 1`] = ` + + + + Tosca Instantiation - Monitoring + + + + + + + +`; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaInstantiation.test.js.snap b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaInstantiation.test.js.snap new file mode 100644 index 0000000..77e4b99 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaInstantiation.test.js.snap @@ -0,0 +1,91 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Verify UploadToscaInstantiation renders correctly 1`] = ` + + + + Tosca Control Loop - Create Instantiation + + +
+ +
+ + + + + Only .yaml, .yml and .json files are supported + + + + + +
+
+
+ + + +
+`; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaInstantiationFile.test.js.snap b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaInstantiationFile.test.js.snap new file mode 100644 index 0000000..3ac5087 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaInstantiationFile.test.js.snap @@ -0,0 +1,16 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Verify UploadToscaInstantiationFile renders correctly 1`] = ` + + + +`; diff --git a/gui-clamp/ui-react/src/components/dialogs/Policy/toscaInstantiationData.test.json b/gui-clamp/ui-react/src/components/dialogs/Policy/toscaInstantiationData.test.json new file mode 100644 index 0000000..d740203 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/Policy/toscaInstantiationData.test.json @@ -0,0 +1,59 @@ +{ + "controlLoopList": [ + { + "name": "PMSHInstance0", + "version": "1.0.1", + "definition": { + "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition", + "version": "1.2.3" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "PMSH control loop instance 0", + "elements": { + "709c62b3-8918-41b9-a747-d21eb79c6c20": { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c20", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", + "version": "1.2.3" + }, + "participantType": { + "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", + "version": "2.3.4" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "DCAE Control Loop Element for the PMSH instance 0 control loop" + }, + "709c62b3-8918-41b9-a747-d21eb79c6c21": { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c21", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement", + "version": "1.2.3" + }, + "participantType": { + "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", + "version": "2.3.1" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "Monitoring Policy Control Loop Element for the PMSH instance 0 control loop" + }, + "709c62b3-8918-41b9-a747-d21eb79c6c22": { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c22", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement", + "version": "1.2.3" + }, + "participantType": { + "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", + "version": "2.3.1" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "Operational Policy Control Loop Element for the PMSH instance 0 control loop" + } + } + } + ] +} diff --git a/gui-clamp/ui-react/src/components/menu/MenuBar.js b/gui-clamp/ui-react/src/components/menu/MenuBar.js index 4574a2a..f32d6c8 100644 --- a/gui-clamp/ui-react/src/components/menu/MenuBar.js +++ b/gui-clamp/ui-react/src/components/menu/MenuBar.js @@ -114,7 +114,9 @@ export default class MenuBar extends React.Component { UnDeploy to DCAE (UNDEPLOY) - Monitoring Control Loop + Instantiation + Monitor Instantiation + Upload Tosca Instantiation Commissioning View Tosca Template diff --git a/gui-clamp/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap b/gui-clamp/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap index 2712218..9543c12 100644 --- a/gui-clamp/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap +++ b/gui-clamp/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap @@ -1005,6 +1005,76 @@ exports[`Verify MenuBar Test the render method 1`] = ` + + Instantiation + + + Monitor Instantiation + - Monitoring Control Loop + Upload Tosca Instantiation