From eb8e3f1dd891ac98f1bbaf35a2a0679146785236 Mon Sep 17 00:00:00 2001 From: sebdet Date: Sun, 24 Jan 2021 18:12:36 +0100 Subject: Add New UI component for policies list Add new Ui components to list policies + the small refactoring of React Routes Issue-ID: POLICY-2925 Signed-off-by: sebdet Change-Id: I784d7c144a3a3af98a9d62b5d40b5172dbdaed47 Signed-off-by: sebdet --- ui-react/src/LoopUI.js | 657 +++++++++++---------- ui-react/src/__snapshots__/LoopUI.test.js.snap | 8 +- ui-react/src/__snapshots__/OnapClamp.test.js.snap | 8 +- ui-react/src/api/LoopCache.test.js | 2 +- ui-react/src/api/LoopCacheMockFile.json | 125 ++++ ui-react/src/api/LoopCache_mokeLoopJsonCache.json | 125 ---- ui-react/src/api/PoliciesListCache.js | 34 ++ ui-react/src/api/PoliciesListCacheMockFile.json | 215 +++++++ ui-react/src/api/PolicyService.js | 43 ++ .../components/dialogs/Policy/ViewAllPolicies.js | 188 ++++++ ui-react/src/components/menu/MenuBar.js | 161 ++--- .../menu/__snapshots__/MenuBar.test.js.snap | 565 ++++++++++-------- 12 files changed, 1336 insertions(+), 795 deletions(-) create mode 100644 ui-react/src/api/LoopCacheMockFile.json delete mode 100644 ui-react/src/api/LoopCache_mokeLoopJsonCache.json create mode 100644 ui-react/src/api/PoliciesListCache.js create mode 100644 ui-react/src/api/PoliciesListCacheMockFile.json create mode 100644 ui-react/src/api/PolicyService.js create mode 100644 ui-react/src/components/dialogs/Policy/ViewAllPolicies.js (limited to 'ui-react') diff --git a/ui-react/src/LoopUI.js b/ui-react/src/LoopUI.js index 5491ab187..339a2c048 100644 --- a/ui-react/src/LoopUI.js +++ b/ui-react/src/LoopUI.js @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP CLAMP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -41,6 +41,7 @@ import CreateLoopModal from './components/dialogs/Loop/CreateLoopModal'; import OpenLoopModal from './components/dialogs/Loop/OpenLoopModal'; import ModifyLoopModal from './components/dialogs/Loop/ModifyLoopModal'; import PolicyModal from './components/dialogs/Policy/PolicyModal'; +import ViewAllPolicies from './components/dialogs/Policy/ViewAllPolicies'; import LoopPropertiesModal from './components/dialogs/Loop/LoopPropertiesModal'; import UserInfoModal from './components/dialogs/UserInfoModal'; import LoopService from './api/LoopService'; @@ -57,334 +58,334 @@ import Spinner from 'react-bootstrap/Spinner'; import { Link } from 'react-router-dom'; const StyledMainDiv = styled.div` - background-color: ${props => props.theme.backgroundColor}; + background-color: ${props => props.theme.backgroundColor}; ` const StyledSpinnerDiv = styled.div` - justify-content: center !important; - display: flex !important; + justify-content: center !important; + display: flex !important; `; const ProjectNameStyled = styled.a` - vertical-align: middle; - padding-left: 30px; - font-size: 36px; - font-weight: bold; + vertical-align: middle; + padding-left: 30px; + font-size: 36px; + font-weight: bold; ` const StyledRouterLink = styled(Link)` - color: ${props => props.theme.menuFontColor}; - background-color: ${props => props.theme.backgroundColor}; + color: ${props => props.theme.menuFontColor}; + background-color: ${props => props.theme.backgroundColor}; ` const StyledLoginInfo = styled.a` - color: ${props => props.theme.menuFontColor}; - background-color: ${props => props.theme.backgroundColor}; + color: ${props => props.theme.menuFontColor}; + background-color: ${props => props.theme.backgroundColor}; ` const LoopViewDivStyled = styled.div` - height: 100%; - overflow: hidden; - margin-left: 10px; - margin-right: 10px; - margin-bottom: 10px; - color: ${props => props.theme.loopViewerFontColor}; - background-color: ${props => props.theme.loopViewerBackgroundColor}; - border: 1px solid transparent; - border-color: ${props => props.theme.loopViewerHeaderBackgroundColor}; + height: 100%; + overflow: hidden; + margin-left: 10px; + margin-right: 10px; + margin-bottom: 10px; + color: ${props => props.theme.loopViewerFontColor}; + background-color: ${props => props.theme.loopViewerBackgroundColor}; + border: 1px solid transparent; + border-color: ${props => props.theme.loopViewerHeaderBackgroundColor}; ` const LoopViewHeaderDivStyled = styled.div` - background-color: ${props => props.theme.loopViewerHeaderBackgroundColor}; - padding: 10px 10px; - color: ${props => props.theme.loopViewerHeaderFontColor}; + background-color: ${props => props.theme.loopViewerHeaderBackgroundColor}; + padding: 10px 10px; + color: ${props => props.theme.loopViewerHeaderFontColor}; ` const LoopViewBodyDivStyled = styled.div` - background-color: ${props => (props.theme.loopViewerBackgroundColor)}; - padding: 10px 10px; - color: ${props => (props.theme.loopViewerHeaderFontColor)}; - height: 95%; + background-color: ${props => (props.theme.loopViewerBackgroundColor)}; + padding: 10px 10px; + color: ${props => (props.theme.loopViewerHeaderFontColor)}; + height: 95%; ` export default class LoopUI extends React.Component { - state = { - userName: null, - loopName: OnapConstants.defaultLoopName, - loopCache: new LoopCache({}), - showSucAlert: false, - showFailAlert: false, - busyLoadingCount: 0 - }; - - constructor() { - super(); - this.getUser = this.getUser.bind(this); - this.updateLoopCache = this.updateLoopCache.bind(this); - this.loadLoop = this.loadLoop.bind(this); - this.closeLoop = this.closeLoop.bind(this); - this.showSucAlert = this.showSucAlert.bind(this); - this.showFailAlert = this.showFailAlert.bind(this); - this.disableAlert = this.disableAlert.bind(this); - this.setBusyLoading = this.setBusyLoading.bind(this); - this.clearBusyLoading = this.clearBusyLoading.bind(this); - this.isBusyLoading = this.isBusyLoading.bind(this); - this.renderGlobalStyle = this.renderGlobalStyle.bind(this); - this.renderSvg = this.renderSvg.bind(this); - } - - componentWillMount() { - this.getUser(); - } - - getUser() { - UserService.login().then(user => { - this.setState({ userName: user }) - }); - } - - renderMenuNavBar() { - return ( - - ); - } - - renderUserLoggedNavBar() { - return ( - - Signed in as: - {this.state.userName} - - ); - } - - renderLogoNavBar() { - return ( - - - CLAMP - - ); - } - - renderAlertBar() { - return ( -
- - {this.state.showMessage} - - - {this.state.showMessage} - -
- ); - } - - renderNavBar() { - return ( - - {this.renderLogoNavBar()} - - {this.renderMenuNavBar()} - {this.renderUserLoggedNavBar()} - - ); - } - - renderLoopViewHeader() { - return ( - - Loop Viewer - {this.state.loopName} - ({this.state.loopCache.getTemplateName()}) - - ); - } - - renderSvg() { - return ( - - ) - } - renderLoopViewBody() { - return ( - - {this.renderSvg()} - - - - ); - } - - getLoopCache() { - return this.state.loopCache; - - } - - renderLoopViewer() { - return ( - - {this.renderLoopViewHeader()} - {this.renderLoopViewBody()} - - ); - } - - updateLoopCache(loopJson) { - - // If call with an empty object for loopJson, this is a reset to empty - // from someplace like PerformActions for the case where we are "deleting" - // a Control Loop model. Set the loopName to the default. - - if (loopJson === null) { - this.setState({ loopName: OnapConstants.defaultLoopName }); - this.setState({ loopCache: new LoopCache({}) }); - } else { - this.setState({ loopCache: new LoopCache(loopJson) }); - this.setState({ loopName: this.state.loopCache.getLoopName() }); - } - console.info(this.state.loopName+" loop loaded successfully"); + state = { + userName: null, + loopName: OnapConstants.defaultLoopName, + loopCache: new LoopCache({}), + showSucAlert: false, + showFailAlert: false, + busyLoadingCount: 0 + }; + + constructor() { + super(); + this.getUser = this.getUser.bind(this); + this.updateLoopCache = this.updateLoopCache.bind(this); + this.loadLoop = this.loadLoop.bind(this); + this.closeLoop = this.closeLoop.bind(this); + this.showSucAlert = this.showSucAlert.bind(this); + this.showFailAlert = this.showFailAlert.bind(this); + this.disableAlert = this.disableAlert.bind(this); + this.setBusyLoading = this.setBusyLoading.bind(this); + this.clearBusyLoading = this.clearBusyLoading.bind(this); + this.isBusyLoading = this.isBusyLoading.bind(this); + this.renderGlobalStyle = this.renderGlobalStyle.bind(this); + this.renderSvg = this.renderSvg.bind(this); + } + + componentWillMount() { + this.getUser(); + } + + getUser() { + UserService.login().then(user => { + this.setState({ userName: user }) + }); + } + + renderMenuNavBar() { + return ( + + ); + } + + renderUserLoggedNavBar() { + return ( + + Signed in as: + {this.state.userName} + + ); + } + + renderLogoNavBar() { + return ( + + + CLAMP + + ); + } + + renderAlertBar() { + return ( +
+ + {this.state.showMessage} + + + {this.state.showMessage} + +
+ ); + } + + renderNavBar() { + return ( + + {this.renderLogoNavBar()} + + {this.renderMenuNavBar()} + {this.renderUserLoggedNavBar()} + + ); + } + + renderLoopViewHeader() { + return ( + + Loop Viewer - {this.state.loopName} - ({this.state.loopCache.getTemplateName()}) + + ); + } + + renderSvg() { + return ( + + ) + } + renderLoopViewBody() { + return ( + + {this.renderSvg()} + + + + ); + } + + getLoopCache() { + return this.state.loopCache; + + } + + renderLoopViewer() { + return ( + + {this.renderLoopViewHeader()} + {this.renderLoopViewBody()} + + ); + } + + updateLoopCache(loopJson) { + + // If call with an empty object for loopJson, this is a reset to empty + // from someplace like PerformActions for the case where we are "deleting" + // a Control Loop model. Set the loopName to the default. + + if (loopJson === null) { + this.setState({ loopName: OnapConstants.defaultLoopName }); + this.setState({ loopCache: new LoopCache({}) }); + } else { + this.setState({ loopCache: new LoopCache(loopJson) }); + this.setState({ loopName: this.state.loopCache.getLoopName() }); + } + console.info(this.state.loopName+" loop loaded successfully"); } - showSucAlert(message) { - this.setState ({ showSucAlert: true, showMessage:message }); - } - - showFailAlert(message) { - this.setState ({ showFailAlert: true, showMessage:message }); - } - - disableAlert() { - this.setState ({ showSucAlert: false, showFailAlert: false }); - } - - loadLoop(loopName) { - this.setBusyLoading(); - LoopService.getLoop(loopName).then(loop => { - console.debug("Updating loopCache"); - LoopActionService.refreshStatus(loopName).then(data => { - this.updateLoopCache(data); - this.clearBusyLoading(); - this.props.history.push('/'); - }) - .catch(error => { - this.updateLoopCache(loop); - this.clearBusyLoading(); - this.props.history.push('/'); - }); - }); - } - - setBusyLoading() { - this.setState((state,props) => ({ busyLoadingCount: ++state.busyLoadingCount })); - } - - clearBusyLoading() { - this.setState((state,props) => ({ busyLoadingCount: --state.busyLoadingCount })); - } - - isBusyLoading() { - if (this.state.busyLoadingCount === 0) { - return false; - } else { - return true; - } - } - - closeLoop() { - this.setState({ loopCache: new LoopCache({}), loopName: OnapConstants.defaultLoopName }); - this.props.history.push('/'); - } - - renderRoutes() { - return( - - ()} /> - ()} /> - ()} /> - ()} /> - - ()} - /> - ()} - /> - ()} - /> - ()} - /> - ()} - /> - - ()} /> - - - ()} - /> - ()} - /> - ()} - /> - ()} - /> - ()} - /> - ()} - /> - ()} - /> - - ); - } + showSucAlert(message) { + this.setState ({ showSucAlert: true, showMessage:message }); + } + + showFailAlert(message) { + this.setState ({ showFailAlert: true, showMessage:message }); + } + + disableAlert() { + this.setState ({ showSucAlert: false, showFailAlert: false }); + } + + loadLoop(loopName) { + this.setBusyLoading(); + LoopService.getLoop(loopName).then(loop => { + console.debug("Updating loopCache"); + LoopActionService.refreshStatus(loopName).then(data => { + this.updateLoopCache(data); + this.clearBusyLoading(); + this.props.history.push('/'); + }) + .catch(error => { + this.updateLoopCache(loop); + this.clearBusyLoading(); + this.props.history.push('/'); + }); + }); + } + + setBusyLoading() { + this.setState((state,props) => ({ busyLoadingCount: ++state.busyLoadingCount })); + } + + clearBusyLoading() { + this.setState((state,props) => ({ busyLoadingCount: --state.busyLoadingCount })); + } + + isBusyLoading() { + if (this.state.busyLoadingCount === 0) { + return false; + } else { + return true; + } + } + + closeLoop() { + this.setState({ loopCache: new LoopCache({}), loopName: OnapConstants.defaultLoopName }); + this.props.history.push('/'); + } + + renderRoutes() { + return( + + ()} /> + ()} /> + ()} /> + ()} /> + ()} /> + ()} + /> + ()} + /> + ()} + /> + ()} + /> + ()} + /> + + ()} /> + + + ()} + /> + ()} + /> + ()} + /> + ()} + /> + ()} + /> + ()} + /> + ()} + /> + + ); + } renderGlobalStyle() { return ( @@ -393,30 +394,30 @@ export default class LoopUI extends React.Component { }; - renderSpinner() { - if (this.isBusyLoading()) { - return ( - - - Loading... - - - ); - } else { - return (
); - } - } - - render() { - return ( - - {this.renderGlobalStyle()} - {this.renderRoutes()} - {this.renderSpinner()} - {this.renderAlertBar()} - {this.renderNavBar()} - {this.renderLoopViewer()} - - ); - } + renderSpinner() { + if (this.isBusyLoading()) { + return ( + + + Loading... + + + ); + } else { + return (
); + } + } + + render() { + return ( + + {this.renderGlobalStyle()} + {this.renderRoutes()} + {this.renderSpinner()} + {this.renderAlertBar()} + {this.renderNavBar()} + {this.renderLoopViewer()} + + ); + } } diff --git a/ui-react/src/__snapshots__/LoopUI.test.js.snap b/ui-react/src/__snapshots__/LoopUI.test.js.snap index cae9182ff..1a8a98257 100644 --- a/ui-react/src/__snapshots__/LoopUI.test.js.snap +++ b/ui-react/src/__snapshots__/LoopUI.test.js.snap @@ -14,11 +14,15 @@ exports[`Verify LoopUI Test the render method 1`] = ` render={[Function]} /> + + { const loopCache = new LoopCache(json); diff --git a/ui-react/src/api/LoopCacheMockFile.json b/ui-react/src/api/LoopCacheMockFile.json new file mode 100644 index 000000000..cb9ed87b0 --- /dev/null +++ b/ui-react/src/api/LoopCacheMockFile.json @@ -0,0 +1,125 @@ +{ + "name": "LOOP_Jbv1z_v1_0_ResourceInstanceName1_tca", + "dcaeBlueprintId": "typeId-3a942643-a8f7-4e54-b2c1-eea8daba2b17", + "globalPropertiesJson": { + "dcaeDeployParameters": { + "location_id": "", + "service_id": "", + "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca" + } + }, + "loopTemplate": {"name": "loopTemplateTest"}, + "modelService": { + "serviceDetails": { + "serviceType": "", + "namingPolicy": "", + "environmentContext": "General_Revenue-Bearing", + "serviceEcompNaming": "true", + "serviceRole": "", + "name": "vLoadBalancerMS", + "description": "vLBMS", + "invariantUUID": "30ec5b59-4799-48d8-ac5f-1058a6b0e48f", + "ecompGeneratedNaming": "true", + "category": "Network L4+", + "type": "Service", + "UUID": "63cac700-ab9a-4115-a74f-7eac85e3fce0", + "instantiationType": "A-la-carte" + }, + "resourceDetails": { + "CP": {}, + "VL": {}, + "VF": { + "vLoadBalancerMS 0": { + "resourceVendor": "Test", + "resourceVendorModelNumber": "", + "name": "vLoadBalancerMS", + "description": "vLBMS", + "invariantUUID": "1a31b9f2-e50d-43b7-89b3-a040250cf506", + "subcategory": "Load Balancer", + "category": "Application L4+", + "type": "VF", + "UUID": "b4c4f3d7-929e-4b6d-a1cd-57e952ddc3e6", + "version": "1.0", + "resourceVendorRelease": "1.0", + "customizationUUID": "465246dc-7748-45f4-a013-308d92922552" + } + }, + "CR": {}, + "VFC": {}, + "PNF": {}, + "Service": {}, + "CVFC": {}, + "Service Proxy": {}, + "Configuration": {}, + "AllottedResource": {}, + "VFModule": { + "Vloadbalancerms..vpkg..module-1": { + "vfModuleModelInvariantUUID": "ca052563-eb92-4b5b-ad41-9111768ce043", + "vfModuleModelVersion": "1", + "vfModuleModelName": "Vloadbalancerms..vpkg..module-1", + "vfModuleModelUUID": "1e725ccc-b823-4f67-82b9-4f4367070dbc", + "vfModuleModelCustomizationUUID": "1bffdc31-a37d-4dee-b65c-dde623a76e52", + "min_vf_module_instances": 0, + "vf_module_label": "vpkg", + "max_vf_module_instances": 1, + "vf_module_type": "Expansion", + "isBase": false, + "initial_count": 0, + "volume_group": false + } + } + } + }, + "lastComputedState": "DESIGN", + "components": { + "POLICY": { + "componentState": { + "stateName": "NOT_SENT", + "description": "The policies defined have NOT yet been created on the policy engine" + } + }, + "DCAE": { + "componentState": { + "stateName": "BLUEPRINT_DEPLOYED", + "description": "The DCAE blueprint has been found in the DCAE inventory but not yet instancianted for this loop" + } + } + }, + "operationalPolicies": [ + { + "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca", + "configurationsJson": { + "operational_policy": { + "controlLoop": {}, + "policies": [] + } + }, + "pdpGroup": "pdpGroupTest", + "pdpSubgroup": "pdpSubgroupTest", + "jsonRepresentation": { + "schema": {} + } + } + ], + "microServicePolicies": [ + { + "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca", + "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app", + "configurationsJson": {"domain": "measurementsForVfScaling"}, + "shared": false, + "pdpGroup": "pdpGroupTest", + "pdpSubgroup": "pdpSubgroupTest", + "policyModel": {"policyPdpGroup": {"supportedPdpGroups": "supportedPdpGroupsTest"}}, + "jsonRepresentation": {"schema": {}} + } + ], + "loopLogs": [ + { + "id": 1, + "logType": "INFO", + "logComponent": "CLAMP", + "message": "Operational policies UPDATED", + "logInstant": "2019-07-08T09:44:37Z" + } + ] +} diff --git a/ui-react/src/api/LoopCache_mokeLoopJsonCache.json b/ui-react/src/api/LoopCache_mokeLoopJsonCache.json deleted file mode 100644 index cb9ed87b0..000000000 --- a/ui-react/src/api/LoopCache_mokeLoopJsonCache.json +++ /dev/null @@ -1,125 +0,0 @@ -{ - "name": "LOOP_Jbv1z_v1_0_ResourceInstanceName1_tca", - "dcaeBlueprintId": "typeId-3a942643-a8f7-4e54-b2c1-eea8daba2b17", - "globalPropertiesJson": { - "dcaeDeployParameters": { - "location_id": "", - "service_id": "", - "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca" - } - }, - "loopTemplate": {"name": "loopTemplateTest"}, - "modelService": { - "serviceDetails": { - "serviceType": "", - "namingPolicy": "", - "environmentContext": "General_Revenue-Bearing", - "serviceEcompNaming": "true", - "serviceRole": "", - "name": "vLoadBalancerMS", - "description": "vLBMS", - "invariantUUID": "30ec5b59-4799-48d8-ac5f-1058a6b0e48f", - "ecompGeneratedNaming": "true", - "category": "Network L4+", - "type": "Service", - "UUID": "63cac700-ab9a-4115-a74f-7eac85e3fce0", - "instantiationType": "A-la-carte" - }, - "resourceDetails": { - "CP": {}, - "VL": {}, - "VF": { - "vLoadBalancerMS 0": { - "resourceVendor": "Test", - "resourceVendorModelNumber": "", - "name": "vLoadBalancerMS", - "description": "vLBMS", - "invariantUUID": "1a31b9f2-e50d-43b7-89b3-a040250cf506", - "subcategory": "Load Balancer", - "category": "Application L4+", - "type": "VF", - "UUID": "b4c4f3d7-929e-4b6d-a1cd-57e952ddc3e6", - "version": "1.0", - "resourceVendorRelease": "1.0", - "customizationUUID": "465246dc-7748-45f4-a013-308d92922552" - } - }, - "CR": {}, - "VFC": {}, - "PNF": {}, - "Service": {}, - "CVFC": {}, - "Service Proxy": {}, - "Configuration": {}, - "AllottedResource": {}, - "VFModule": { - "Vloadbalancerms..vpkg..module-1": { - "vfModuleModelInvariantUUID": "ca052563-eb92-4b5b-ad41-9111768ce043", - "vfModuleModelVersion": "1", - "vfModuleModelName": "Vloadbalancerms..vpkg..module-1", - "vfModuleModelUUID": "1e725ccc-b823-4f67-82b9-4f4367070dbc", - "vfModuleModelCustomizationUUID": "1bffdc31-a37d-4dee-b65c-dde623a76e52", - "min_vf_module_instances": 0, - "vf_module_label": "vpkg", - "max_vf_module_instances": 1, - "vf_module_type": "Expansion", - "isBase": false, - "initial_count": 0, - "volume_group": false - } - } - } - }, - "lastComputedState": "DESIGN", - "components": { - "POLICY": { - "componentState": { - "stateName": "NOT_SENT", - "description": "The policies defined have NOT yet been created on the policy engine" - } - }, - "DCAE": { - "componentState": { - "stateName": "BLUEPRINT_DEPLOYED", - "description": "The DCAE blueprint has been found in the DCAE inventory but not yet instancianted for this loop" - } - } - }, - "operationalPolicies": [ - { - "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca", - "configurationsJson": { - "operational_policy": { - "controlLoop": {}, - "policies": [] - } - }, - "pdpGroup": "pdpGroupTest", - "pdpSubgroup": "pdpSubgroupTest", - "jsonRepresentation": { - "schema": {} - } - } - ], - "microServicePolicies": [ - { - "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca", - "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app", - "configurationsJson": {"domain": "measurementsForVfScaling"}, - "shared": false, - "pdpGroup": "pdpGroupTest", - "pdpSubgroup": "pdpSubgroupTest", - "policyModel": {"policyPdpGroup": {"supportedPdpGroups": "supportedPdpGroupsTest"}}, - "jsonRepresentation": {"schema": {}} - } - ], - "loopLogs": [ - { - "id": 1, - "logType": "INFO", - "logComponent": "CLAMP", - "message": "Operational policies UPDATED", - "logInstant": "2019-07-08T09:44:37Z" - } - ] -} diff --git a/ui-react/src/api/PoliciesListCache.js b/ui-react/src/api/PoliciesListCache.js new file mode 100644 index 000000000..30c9348d0 --- /dev/null +++ b/ui-react/src/api/PoliciesListCache.js @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END============================================ + * =================================================================== + * + */ + +export default class PoliciesListCache { + policiesJsonCache; + + constructor(policiesJson) { + this.policiesJsonCache=policiesJson; + } + + getAllPolicies() { + return this.policiesJsonCache["policies"]; + } +} diff --git a/ui-react/src/api/PoliciesListCacheMockFile.json b/ui-react/src/api/PoliciesListCacheMockFile.json new file mode 100644 index 000000000..5c6bd5b6b --- /dev/null +++ b/ui-react/src/api/PoliciesListCacheMockFile.json @@ -0,0 +1,215 @@ +{ + "policies": [ + { + "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0": { + "type": "onap.policies.monitoring.tcagen2", + "type_version": "1.0.0", + "properties": { + "tca.policy": { + "domain": "measurementsForVfScaling", + "metricsPerEventName": [ + { + "policyScope": "DCAE", + "thresholds": [ + { + "version": "1.0.2", + "severity": "MAJOR", + "thresholdValue": 200, + "closedLoopEventStatus": "ONSET", + "closedLoopControlName": "LOOP_test", + "direction": "LESS_OR_EQUAL", + "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta" + } + ], + "eventName": "vLoadBalancer", + "policyVersion": "v0.0.1", + "controlLoopSchemaType": "VM", + "policyName": "DCAE.Config_tca-hi-lo" + } + ] + } + }, + "name": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0", + "version": "1.0.0", + "metadata": { + "policy-id": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0", + "policy-version": "1.0.0" + }, + "pdpGroupInfo": { + "pdpGroup": "pdpGroup2", + "pdpSubGroup": "subGroup2" + }, + "supportedPdpGroups": [ + { + "pdpGroup2": [ + "subGroup2", + "subGroup3" + ] + } + ] + } + }, + { + "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd": { + "type": "onap.policies.controlloop.operational.common.Drools", + "type_version": "1.0.0", + "properties": { + "abatement": false, + "operations": [ + { + "failure_retries": "final_failure_retries", + "id": "test1", + "failure_timeout": "final_failure_timeout", + "failure": "final_failure", + "operation": { + "payload": { + "artifact_name": "baseconfiguration", + "artifact_version": "1.0.0", + "mode": "async", + "data": "{\"resource-assignment-properties\":{\"request-id\":\"\",\"service-instance-id\":\"\",\"hostname\":\"\",\"request-info\":{\"prop1\":\"\",\"prop2\":\"\"}}}" + }, + "target": { + "entityIds": { + "resourceID": "Vloadbalancerms..vdns..module-3", + "modelInvariantId": "4c10ba9b-f88f-415e-9de3-5d33336047fa", + "modelVersionId": "4fa73b49-8a6c-493e-816b-eb401567b720", + "modelName": "Vloadbalancerms..vdns..module-3", + "modelVersion": "1", + "modelCustomizationId": "bafcdab0-801d-4d81-9ead-f464640a38b1" + }, + "targetType": "VNF" + }, + "actor": "SDNR", + "operation": "BandwidthOnDemand" + }, + "failure_guard": "final_failure_guard", + "retries": 0, + "timeout": 0, + "failure_exception": "final_failure_exception", + "description": "test", + "success": "final_success" + } + ], + "trigger": "test1", + "timeout": 0, + "id": "LOOP_test" + }, + "name": "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd", + "version": "1.0.0", + "metadata": { + "policy-id": "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd", + "policy-version": "1.0.0" + }, + "pdpGroupInfo": { + "pdpGroup": "pdpGroup2", + "pdpSubGroup": "subGroup3" + }, + "supportedPdpGroups": [ + { + "pdpGroup2": [ + "subGroup2", + "subGroup3" + ] + } + ] + } + }, + { + "SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP": { + "type": "onap.policies.Naming", + "type_version": "1.0.0", + "properties": { + "naming-models": [ + { + "naming-type": "VNF", + "naming-recipe": "AIC_CLOUD_REGION|DELIMITER|CONSTANT|DELIMITER|TIMESTAMP", + "name-operation": "to_lower_case()", + "naming-properties": [ + { + "property-name": "AIC_CLOUD_REGION" + }, + { + "property-name": "CONSTANT", + "property-value": "onap-nf" + }, + { + "property-name": "TIMESTAMP" + }, + { + "property-value": "-", + "property-name": "DELIMITER" + } + ] + }, + { + "naming-type": "VNFC", + "naming-recipe": "VNF_NAME|DELIMITER|NFC_NAMING_CODE|DELIMITER|SEQUENCE", + "name-operation": "to_lower_case()", + "naming-properties": [ + { + "property-name": "VNF_NAME" + }, + { + "property-name": "SEQUENCE", + "increment-sequence": { + "max": "zzz", + "scope": "ENTIRETY", + "start-value": "1", + "length": "3", + "increment": "1", + "sequence-type": "alpha-numeric" + } + }, + { + "property-name": "NFC_NAMING_CODE" + }, + { + "property-value": "-", + "property-name": "DELIMITER" + } + ] + }, + { + "naming-type": "VF-MODULE", + "naming-recipe": "VNF_NAME|DELIMITER|VF_MODULE_LABEL|DELIMITER|VF_MODULE_TYPE|DELIMITER|SEQUENCE", + "name-operation": "to_lower_case()", + "naming-properties": [ + { + "property-name": "VNF_NAME" + }, + { + "property-value": "-", + "property-name": "DELIMITER" + }, + { + "property-name": "VF_MODULE_LABEL" + }, + { + "property-name": "VF_MODULE_TYPE" + }, + { + "property-name": "SEQUENCE", + "increment-sequence": { + "max": "zzz", + "scope": "PRECEEDING", + "start-value": "1", + "length": "3", + "increment": "1", + "sequence-type": "alpha-numeric" + } + } + ] + } + ], + "policy-instance-name": "ONAP_NF_NAMING_TIMESTAMP" + }, + "name": "SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", + "version": "1.0.0", + "metadata": { + "policy-id": "SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", + "policy-version": "1.0.0" + } + } + } + ] +} \ No newline at end of file diff --git a/ui-react/src/api/PolicyService.js b/ui-react/src/api/PolicyService.js new file mode 100644 index 000000000..d591b093d --- /dev/null +++ b/ui-react/src/api/PolicyService.js @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP POLICY-CLAMP + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END============================================ + * =================================================================== + * + */ + +export default class PolicyService { + static getPoliciesList() { + return fetch(window.location.pathname + 'restservices/clds/v2/policies/list', { + method: 'GET', + credentials: 'same-origin' + }) + .then(function (response) { + console.debug("getPoliciesList response received: ", response.status); + if (response.ok) { + return response.json(); + } else { + console.error("getPoliciesList query failed"); + return {}; + } + }) + .catch(function (error) { + console.error("getPoliciesList error received", error); + return {}; + }); + } +} diff --git a/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js b/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js new file mode 100644 index 000000000..216a8abd2 --- /dev/null +++ b/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js @@ -0,0 +1,188 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP POLICY-CLAMP + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END============================================ + * =================================================================== + * + */ + +import React, { forwardRef } from 'react' +import Button from 'react-bootstrap/Button'; +import Modal from 'react-bootstrap/Modal'; +import styled from 'styled-components'; +import ArrowUpward from '@material-ui/icons/ArrowUpward'; +import ChevronLeft from '@material-ui/icons/ChevronLeft'; +import ChevronRight from '@material-ui/icons/ChevronRight'; +import Clear from '@material-ui/icons/Clear'; +import FirstPage from '@material-ui/icons/FirstPage'; +import LastPage from '@material-ui/icons/LastPage'; +import Search from '@material-ui/icons/Search'; +import MaterialTable from "material-table"; +import LoopCache from '../../../api/LoopCache'; +import PolicyService from '../../../api/PolicyService'; +import Select from 'react-select'; + +const ModalStyled = styled(Modal)` + background-color: transparent; +` + +const standardCellStyle = { border: '1px solid black' }; +const cellPdpGroupStyle = { backgroundColor: '#039be5', color: '#FFF', border: '1px solid black'}; +const headerStyle = { backgroundColor: '#ddd', border: '2px solid black' }; +const rowHeaderStyle = {backgroundColor:'#ddd', fontSize: '15pt', text: 'bold', border: '1px solid black'}; +const selectPdpGroupStyle = { + width: 2000 +} + +export default class ViewAllPolicies extends React.Component { + state = { + show: true, + content: 'Please select a policy to display it', + selectedRow: -1, + policiesListData: [], + policyColumnsDefinition: [ + { + title: "#", field: "index", render: rowData => rowData.tableData.id + 1, + cellStyle: standardCellStyle, + headerStyle: headerStyle + }, + { + title: "Policy Name", field: "name", + cellStyle: standardCellStyle, + headerStyle: headerStyle + }, + { + title: "Policy Version", field: "version", + cellStyle: standardCellStyle, + headerStyle: headerStyle + }, + { + title: "Policy Type", field: "type", + cellStyle: standardCellStyle, + headerStyle: headerStyle + }, + { + title: "Policy Type Version", field: "type_version", + cellStyle: standardCellStyle, + headerStyle: headerStyle + }, + { + title: "Deployed in PDP", field: "pdpGroupInfo.pdpGroup", + cellStyle: cellPdpGroupStyle, + headerStyle: headerStyle, + render: rowData => this.renderPdpGroupDropBox(rowData) + }, + { + title: "PDP Group", field: "pdpGroupInfo.pdpGroup", + cellStyle: cellPdpGroupStyle, + headerStyle: headerStyle + }, + { + title: "PDP SubGroup", field: "pdpGroupInfo.pdpSubGroup", + cellStyle: cellPdpGroupStyle, + headerStyle: headerStyle + } + ], + tableIcons: { + FirstPage: forwardRef((props, ref) => ), + LastPage: forwardRef((props, ref) => ), + NextPage: forwardRef((props, ref) => ), + PreviousPage: forwardRef((props, ref) => ), + ResetSearch: forwardRef((props, ref) => ), + Search: forwardRef((props, ref) => ), + SortArrow: forwardRef((props, ref) => ) + } + }; + + constructor(props, context) { + super(props, context); + this.handleClose = this.handleClose.bind(this); + this.renderPdpGroupDropBox = this.renderPdpGroupDropBox.bind(this); + this.handlePdpGroupChange = this.handlePdpGroupChange.bind(this); + + this.getAllPolicies(); + + } + + handlePdpGroupChange(e) { + let pdpSplit = e.value.split("/"); + let selectedPdpGroup = pdpSplit[0]; + let selectedSubPdpGroup = pdpSplit[1]; + if (typeof selectedSubPdpGroup !== "undefined") { + this.state.policiesListData[this.state.selectedRow]["pdpGroupInfo"] = {"pdpGroup":selectedPdpGroup,"pdpSubGroup":selectedSubPdpGroup}; + } else { + delete this.state.policiesListData[this.state.selectedRow]["pdpGroupInfo"]; + } + } + + renderPdpGroupDropBox(dataRow) { + let optionItems = [{label: "NOT DEPLOYED", value: "NOT DEPLOYED"}]; + let selectedItem = {label: "NOT DEPLOYED", value: "NOT DEPLOYED"}; + if (typeof dataRow.supportedPdpGroups !== "undefined") { + for (const pdpGroup of dataRow["supportedPdpGroups"]) { + for (const pdpSubGroup of Object.values(pdpGroup)[0]) { + optionItems.push({ label: Object.keys(pdpGroup)[0]+"/"+pdpSubGroup, + value: Object.keys(pdpGroup)[0]+"/"+pdpSubGroup }); + } + } + } + if (typeof dataRow.pdpGroupInfo !== "undefined") { + selectedItem = {label: dataRow["pdpGroupInfo"]["pdpGroup"]+"/"+dataRow["pdpGroupInfo"]["pdpSubGroup"], + value: dataRow["pdpGroupInfo"]["pdpGroup"]+"/"+dataRow["pdpGroupInfo"]["pdpSubGroup"]}; + } + return (