From 3d202a04b99f0e61b6ccf8b7a5610e1a15ca58e7 Mon Sep 17 00:00:00 2001 From: Herbert Eiselt Date: Mon, 11 Feb 2019 14:54:12 +0100 Subject: Add sdnr wt odlux Add complete sdnr wireless transport app odlux core and apps Change-Id: I5dcbfb8f3b790e3bda7c8df67bd69d81958f65e5 Issue-ID: SDNC-576 Signed-off-by: Herbert Eiselt --- sdnr/wt/odlux/apps/connectApp/.babelrc | 17 ++ sdnr/wt/odlux/apps/connectApp/package.json | 40 ++++ sdnr/wt/odlux/apps/connectApp/pom.xml | 110 ++++++++++ .../src/actions/mountedNetworkElementsActions.ts | 90 ++++++++ .../src/actions/requiredNetworkElementsActions.ts | 38 ++++ .../src/components/connectionStatusLog.tsx | 36 ++++ .../src/components/editNetworkElementDialog.tsx | 228 +++++++++++++++++++++ .../src/components/requiredNetworkElements.tsx | 194 ++++++++++++++++++ .../src/components/unknownNetworkElements.tsx | 196 ++++++++++++++++++ .../src/handlers/connectAppRootHandler.tsx | 26 +++ .../src/handlers/connectionStatusLogHandler.tsx | 30 +++ .../src/handlers/mountedNetworkElementsHandler.tsx | 81 ++++++++ .../handlers/requiredNetworkElementsHandler.tsx | 18 ++ sdnr/wt/odlux/apps/connectApp/src/index.html | 26 +++ .../connectApp/src/models/connectionStatusLog.ts | 9 + .../src/models/mountedNetworkElements.ts | 11 + .../connectApp/src/models/networkElementBase.ts | 5 + .../src/models/requiredNetworkElements.ts | 10 + .../apps/connectApp/src/models/topologyNetconf.ts | 36 ++++ sdnr/wt/odlux/apps/connectApp/src/plugin.tsx | 39 ++++ .../apps/connectApp/src/services/connectService.ts | 204 ++++++++++++++++++ .../apps/connectApp/src/views/connectView.tsx | 93 +++++++++ .../sdnr/wt/odlux/bundles/MyOdluxBundle.java | 68 ++++++ .../resources/OSGI-INF/blueprint/blueprint.xml | 9 + sdnr/wt/odlux/apps/connectApp/tsconfig.json | 37 ++++ sdnr/wt/odlux/apps/connectApp/webpack.config.js | 139 +++++++++++++ 26 files changed, 1790 insertions(+) create mode 100644 sdnr/wt/odlux/apps/connectApp/.babelrc create mode 100644 sdnr/wt/odlux/apps/connectApp/package.json create mode 100644 sdnr/wt/odlux/apps/connectApp/pom.xml create mode 100644 sdnr/wt/odlux/apps/connectApp/src/actions/mountedNetworkElementsActions.ts create mode 100644 sdnr/wt/odlux/apps/connectApp/src/actions/requiredNetworkElementsActions.ts create mode 100644 sdnr/wt/odlux/apps/connectApp/src/components/connectionStatusLog.tsx create mode 100644 sdnr/wt/odlux/apps/connectApp/src/components/editNetworkElementDialog.tsx create mode 100644 sdnr/wt/odlux/apps/connectApp/src/components/requiredNetworkElements.tsx create mode 100644 sdnr/wt/odlux/apps/connectApp/src/components/unknownNetworkElements.tsx create mode 100644 sdnr/wt/odlux/apps/connectApp/src/handlers/connectAppRootHandler.tsx create mode 100644 sdnr/wt/odlux/apps/connectApp/src/handlers/connectionStatusLogHandler.tsx create mode 100644 sdnr/wt/odlux/apps/connectApp/src/handlers/mountedNetworkElementsHandler.tsx create mode 100644 sdnr/wt/odlux/apps/connectApp/src/handlers/requiredNetworkElementsHandler.tsx create mode 100644 sdnr/wt/odlux/apps/connectApp/src/index.html create mode 100644 sdnr/wt/odlux/apps/connectApp/src/models/connectionStatusLog.ts create mode 100644 sdnr/wt/odlux/apps/connectApp/src/models/mountedNetworkElements.ts create mode 100644 sdnr/wt/odlux/apps/connectApp/src/models/networkElementBase.ts create mode 100644 sdnr/wt/odlux/apps/connectApp/src/models/requiredNetworkElements.ts create mode 100644 sdnr/wt/odlux/apps/connectApp/src/models/topologyNetconf.ts create mode 100644 sdnr/wt/odlux/apps/connectApp/src/plugin.tsx create mode 100644 sdnr/wt/odlux/apps/connectApp/src/services/connectService.ts create mode 100644 sdnr/wt/odlux/apps/connectApp/src/views/connectView.tsx create mode 100644 sdnr/wt/odlux/apps/connectApp/src2/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/bundles/MyOdluxBundle.java create mode 100644 sdnr/wt/odlux/apps/connectApp/src2/main/resources/OSGI-INF/blueprint/blueprint.xml create mode 100644 sdnr/wt/odlux/apps/connectApp/tsconfig.json create mode 100644 sdnr/wt/odlux/apps/connectApp/webpack.config.js (limited to 'sdnr/wt/odlux/apps/connectApp') diff --git a/sdnr/wt/odlux/apps/connectApp/.babelrc b/sdnr/wt/odlux/apps/connectApp/.babelrc new file mode 100644 index 000000000..3d8cd1260 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/.babelrc @@ -0,0 +1,17 @@ +{ + "presets": [ + ["@babel/preset-react"], + ["@babel/preset-env", { + "targets": { + "chrome": "66" + }, + "spec": true, + "loose": false, + "modules": false, + "debug": false, + "useBuiltIns": "usage", + "forceAllTransforms": true + }] + ], + "plugins": [] +} diff --git a/sdnr/wt/odlux/apps/connectApp/package.json b/sdnr/wt/odlux/apps/connectApp/package.json new file mode 100644 index 000000000..29e1cb970 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/package.json @@ -0,0 +1,40 @@ +{ + "name": "@odlux/connect-app", + "version": "0.1.1", + "description": "A react based modular UI to display network connect data from a database.", + "main": "index.js", + "scripts": { + "start": "webpack-dev-server --env debug", + "build": "webpack --env release --config webpack.config.js", + "build:dev": "webpack --env debug --config webpack.config.js" + }, + "repository": { + "type": "git", + "url": "https://git.mfico.de/highstreet-technologies/odlux.git" + }, + "keywords": [ + "reactjs", + "redux", + "ui", + "framework" + ], + "author": "Matthias Fischer", + "license": "MIT", + "dependencies": { + "@odlux/framework" : "*" + }, + "peerDependencies": { + "@types/react": "16.4.14", + "@types/react-dom": "16.0.8", + "@types/react-router-dom": "4.3.1", + "@material-ui/core": "3.8.3", + "@material-ui/icons": "3.0.2", + "@types/classnames": "2.2.6", + "@types/flux": "3.1.8", + "@types/jquery": "3.3.10", + "jquery": "3.3.1", + "react": "16.5.2", + "react-dom": "16.5.2", + "react-router-dom": "4.3.1" + } +} \ No newline at end of file diff --git a/sdnr/wt/odlux/apps/connectApp/pom.xml b/sdnr/wt/odlux/apps/connectApp/pom.xml new file mode 100644 index 000000000..b1cabdb5e --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/pom.xml @@ -0,0 +1,110 @@ + + + + + org.onap.ccsdk.parent + odlparent + 1.2.1-SNAPSHOT + + + 4.0.0 + org.onap.ccsdk.features.sdnr.wt + sdnr-wt-odlux-app-connectApp + 0.4.1-SNAPSHOT + bundle + sdnr-wt-odlux-app-connectApp + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0 + + + + + ${project.groupId} + sdnr-wt-odlux-core-model + ${project.version} + + + + src2/main/java + + + maven-clean-plugin + 2.5 + + + + dist + false + + + + + + com.github.eirslett + frontend-maven-plugin + 1.8-SNAPSHOT + + + install node and yarn + + install-node-and-yarn + + + initialize + + v8.10.0 + v1.12.3 + + + + yarn build + + yarn + + + run build + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + org.onap.ccsdk.features.sdnr.wt.odlux.model.*,com.opensymphony.* + + + + + + + + dist + odlux + + + src2/main/resources + + + + + + highstreet repo + https://cloud-highstreet-technologies.com/mvn/ + + true + always + + + + \ No newline at end of file diff --git a/sdnr/wt/odlux/apps/connectApp/src/actions/mountedNetworkElementsActions.ts b/sdnr/wt/odlux/apps/connectApp/src/actions/mountedNetworkElementsActions.ts new file mode 100644 index 000000000..e342f6314 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/actions/mountedNetworkElementsActions.ts @@ -0,0 +1,90 @@ +import { Action } from '../../../../framework/src/flux/action'; +import { Dispatch } from '../../../../framework/src/flux/store'; + +import { MountedNetworkElementType } from '../models/mountedNetworkElements'; +import { RequiredNetworkElementType } from '../models/requiredNetworkElements'; + +import { connectService } from '../services/connectService'; +import { AddSnackbarNotification } from '../../../../framework/src/actions/snackbarActions'; + +/** Represents the base action. */ +export class BaseAction extends Action { } + +/** Represents an action causing the store to load all mounted network elements. */ +export class LoadAllMountedNetworkElementsAction extends BaseAction { } + +/** Represents an action causing the store to update all mounted network elements. */ +export class AllMountedNetworkElementsLoadedAction extends BaseAction { + constructor(public mountedNetworkElements: MountedNetworkElementType[] | null, public error?: string) { + super(); + } +} + +/** Represents an action causing the store to update all mounted network elements. */ +export class AddMountedNetworkElement extends BaseAction { + constructor(public mountedNetworkElement: MountedNetworkElementType | null, public error?: string) { + super(); + } +} + +export class RemoveMountedNetworkElement extends BaseAction { + constructor(public mountId: string) { + super(); + } +} + +export class UpdateConnectionStateMountedNetworkElement extends BaseAction { + constructor(public mountId: string, connectionState: string) { + super(); + } +} + + +export class UpdateRequiredMountedNetworkElement extends BaseAction { + constructor(public mountId: string, public required: boolean) { + super(); + } +} + +/** + * An actioncrator for a async thunk action to add an allready mounted element to the state of this app. + * Note: Use this action to add created object notified by the websocket. +*/ +export const addMountedNetworkElementAsyncActionCreator = (mountId: string) => async (dispatch: Dispatch) => { + connectService.getMountedNetworkElementByMountId(mountId).then(mountedNetworkElement => { + mountedNetworkElement && dispatch(new AddMountedNetworkElement(mountedNetworkElement)); + }).catch(error => { + dispatch(new AddMountedNetworkElement(null, error)); + }); +}; + +/** Represents an async thunk action to load all mounted network elements. */ +export const loadAllMountedNetworkElementsAsync = (dispatch: Dispatch) => { + dispatch(new LoadAllMountedNetworkElementsAction()); + connectService.getMountedNetworkElementsList().then(mountedNetworkElements => { + mountedNetworkElements && dispatch(new AllMountedNetworkElementsLoadedAction(mountedNetworkElements)); + }).catch(error => { + dispatch(new AllMountedNetworkElementsLoadedAction(null, error)); + }); +}; + +/** Represents an async thunk action to load all mounted network elements. */ +export const mountNetworkElementActionCreatorAsync = (networkElement: RequiredNetworkElementType) => (dispatch: Dispatch) => { + connectService.mountNetworkElement(networkElement).then((success) => { + success && dispatch(new AddSnackbarNotification({ message: `Requesting mount [${ networkElement.mountId }]`, options: { variant: 'info' } })) + || dispatch(new AddSnackbarNotification({ message: `Failed to mount [${ networkElement.mountId }]`, options: { variant: 'warning' } })); + }).catch(error => { + dispatch(new AddMountedNetworkElement(null, error)); + }); +}; + +export const unmountNetworkElementActionCreatorAsync = (mountId: string) => (dispatch: Dispatch) => { + connectService.unmountNetworkElement(mountId).then((success) => { + success && dispatch(new AddSnackbarNotification({ message: `Requesting unmount [${ mountId }]`, options: { variant: 'info' } })) + || dispatch(new AddSnackbarNotification({ message: `Failed to unmount [${ mountId }]`, options: { variant: 'warning' } })); + }).catch(error => { + dispatch(new AddMountedNetworkElement(null, error)); + }); +}; + + diff --git a/sdnr/wt/odlux/apps/connectApp/src/actions/requiredNetworkElementsActions.ts b/sdnr/wt/odlux/apps/connectApp/src/actions/requiredNetworkElementsActions.ts new file mode 100644 index 000000000..979321957 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/actions/requiredNetworkElementsActions.ts @@ -0,0 +1,38 @@ +import { Action } from '../../../../framework/src/flux/action'; +import { Dispatch } from '../../../../framework/src/flux/store'; +import { RequiredNetworkElementType } from '../models/requiredNetworkElements'; +import { requiredNetworkElementsReloadAction } from '../handlers/requiredNetworkElementsHandler'; +import { UpdateRequiredMountedNetworkElement } from '../actions/mountedNetworkElementsActions'; + +import { AddSnackbarNotification } from '../../../../framework/src/actions/snackbarActions'; + +import { connectService } from '../services/connectService'; + +/** Represents the base action. */ +export class BaseAction extends Action { } + + +/** Represents an async thunk action that will add an element to the required network elements. */ +export const addToRequiredNetworkElementsAsyncActionCreator = (element: RequiredNetworkElementType) => (dispatch: Dispatch) => { + connectService.insertRequiredNetworkElement(element).then(_ => { + window.setTimeout(() => { + dispatch(requiredNetworkElementsReloadAction); + dispatch(new UpdateRequiredMountedNetworkElement(element.mountId, true)); + dispatch(new AddSnackbarNotification({ message: `Successfully added [${ element.mountId }]`, options: { variant: 'success' } })); + }, 900); + }); +}; + +/** Represents an async thunk action that will delete an element from the required network elements. */ +export const removeFromRequiredNetworkElementsAsyncActionCreator = (element: RequiredNetworkElementType) => (dispatch: Dispatch) => { + connectService.deleteRequiredNetworkElement(element).then(_ => { + window.setTimeout(() => { + dispatch(requiredNetworkElementsReloadAction); + dispatch(new UpdateRequiredMountedNetworkElement(element.mountId, false)); + dispatch(new AddSnackbarNotification({ message: `Successfully removed [${ element.mountId }]`, options: { variant: 'success' } })); + }, 900); + }); +}; + + + diff --git a/sdnr/wt/odlux/apps/connectApp/src/components/connectionStatusLog.tsx b/sdnr/wt/odlux/apps/connectApp/src/components/connectionStatusLog.tsx new file mode 100644 index 000000000..b4b08fcf3 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/components/connectionStatusLog.tsx @@ -0,0 +1,36 @@ +import * as React from 'react'; +import connect, { IDispatcher, Connect } from '../../../../framework/src/flux/connect'; +import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore'; +import { MaterialTable, ColumnType, MaterialTableCtorType } from '../../../../framework/src/components/material-table'; + +import { createConnectionStatusLogActions, createConnectionStatusLogProperties } from '../handlers/connectionStatusLogHandler'; +import { ConnectionStatusLogType } from '../models/connectionStatusLog'; + +const mapProps = (state: IApplicationStoreState) => ({ + connectionStatusLogProperties: createConnectionStatusLogProperties(state), +}); + +const mapDispatch = (dispatcher: IDispatcher) => ({ + connectionStatusLogActions: createConnectionStatusLogActions(dispatcher.dispatch), +}); + +const ConnectionStatusTable = MaterialTable as MaterialTableCtorType; + +type ConnectionStatusLogComponentProps = Connect; + +class ConnectionStatusLogComponent extends React.Component { + render(): JSX.Element { + return ( + + + ); + }; + +} + +export const ConnectionStatusLog = connect(mapProps, mapDispatch)(ConnectionStatusLogComponent); +export default ConnectionStatusLog; \ No newline at end of file diff --git a/sdnr/wt/odlux/apps/connectApp/src/components/editNetworkElementDialog.tsx b/sdnr/wt/odlux/apps/connectApp/src/components/editNetworkElementDialog.tsx new file mode 100644 index 000000000..ee876e854 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/components/editNetworkElementDialog.tsx @@ -0,0 +1,228 @@ +import * as React from 'react'; + +import Button from '@material-ui/core/Button'; +import TextField from '@material-ui/core/TextField'; +import Dialog from '@material-ui/core/Dialog'; +import DialogActions from '@material-ui/core/DialogActions'; +import DialogContent from '@material-ui/core/DialogContent'; +import DialogContentText from '@material-ui/core/DialogContentText'; +import DialogTitle from '@material-ui/core/DialogTitle'; + +import { IDispatcher, connect, Connect } from '../../../../framework/src/flux/connect'; + +import { + addToRequiredNetworkElementsAsyncActionCreator, + removeFromRequiredNetworkElementsAsyncActionCreator +} from '../actions/requiredNetworkElementsActions'; + +import { RequiredNetworkElementType } from '../models/requiredNetworkElements'; +import { unmountNetworkElementActionCreatorAsync, mountNetworkElementActionCreatorAsync } from '../actions/mountedNetworkElementsActions'; +export enum EditNetworkElementDialogMode { + None = "none", + UnknownNetworkElementToRequiredNetworkElements = "unknownNetworkElementToRequiredNetworkElements", + RequiredNetworkElementToUnknownNetworkElements = "requiredNetworkElementToUnknownNetworkElements", + MountNetworkElementToRequiredNetworkElements = "mountNetworkElementToRequiredNetworkElements", + MountNetworkElementToUnknonwNetworkElements = "mountNetworkElementToRequiredUnknownElements", + MountNetworkElement = "mountNetworkElement", + UnmountNetworkElement = "unmountNetworkElement", +} + +const mapDispatch = (dispatcher: IDispatcher) => ({ + addToRequiredNetworkElements: (element: RequiredNetworkElementType) => { + dispatcher.dispatch(addToRequiredNetworkElementsAsyncActionCreator(element)); + }, + removeFromRequiredNetworkElements: (element: RequiredNetworkElementType) => { + dispatcher.dispatch(removeFromRequiredNetworkElementsAsyncActionCreator(element)); + }, + mountNetworkElement: (element: RequiredNetworkElementType) => { + dispatcher.dispatch(mountNetworkElementActionCreatorAsync(element)); + }, + mountAndRquireNetworkElement: (element: RequiredNetworkElementType) => { + dispatcher.dispatch(addToRequiredNetworkElementsAsyncActionCreator(element)); + dispatcher.dispatch(mountNetworkElementActionCreatorAsync(element)); + }, + unmountNetworkElement: (element: RequiredNetworkElementType) => { + dispatcher.dispatch(unmountNetworkElementActionCreatorAsync(element && element.mountId)); + } +} +); + +type DialogSettings = { + dialogTitle: string, + dialogDescription: string, + applyButtonText: string, + cancelButtonText: string, + enableMountIdEditor: boolean, + enableUsernameEditor: boolean, + enableExtendedEditor: boolean, +} + +const settings: { [key: string]: DialogSettings } = { + [EditNetworkElementDialogMode.None]: { + dialogTitle: "", + dialogDescription: "", + applyButtonText: "", + cancelButtonText: "", + enableMountIdEditor: false, + enableUsernameEditor: false, + enableExtendedEditor: false, + }, + [EditNetworkElementDialogMode.UnknownNetworkElementToRequiredNetworkElements] : { + dialogTitle: "Add to required network elements" , + dialogDescription: "Create a new NetworkElement in planning database as clone of existing real NetworkElement." , + applyButtonText: "Add to required network elements" , + cancelButtonText: "Cancel", + enableMountIdEditor: false, + enableUsernameEditor: true, + enableExtendedEditor: false, + }, + [EditNetworkElementDialogMode.RequiredNetworkElementToUnknownNetworkElements]: { + dialogTitle: "Remove from required network elements", + dialogDescription: "Do you really want to remove the required element:", + applyButtonText: "Remove network element", + cancelButtonText: "Cancel", + enableMountIdEditor: false, + enableUsernameEditor: false, + enableExtendedEditor: false, + }, + [EditNetworkElementDialogMode.MountNetworkElementToUnknonwNetworkElements]: { + dialogTitle: "Mount to unknown network elements", + dialogDescription: "Mount this network element:", + applyButtonText: "Mount network element", + cancelButtonText: "Cancel", + enableMountIdEditor: true, + enableUsernameEditor: true, + enableExtendedEditor: true, + }, + [EditNetworkElementDialogMode.MountNetworkElementToRequiredNetworkElements]: { + dialogTitle: "Mount to required network elements", + dialogDescription: "Mount this network element:", + applyButtonText: "Mount network element", + cancelButtonText: "Cancel", + enableMountIdEditor: true, + enableUsernameEditor: true, + enableExtendedEditor: true, + }, + [EditNetworkElementDialogMode.MountNetworkElement]: { + dialogTitle: "Mount network element", + dialogDescription: "mount this network element:", + applyButtonText: "mount network element", + cancelButtonText: "Cancel", + enableMountIdEditor: false, + enableUsernameEditor: false, + enableExtendedEditor: false, + }, + [EditNetworkElementDialogMode.UnmountNetworkElement]: { + dialogTitle: "Unmount network element", + dialogDescription: "unmount this network element:", + applyButtonText: "Unmount network element", + cancelButtonText: "Cancel", + enableMountIdEditor: false, + enableUsernameEditor: false, + enableExtendedEditor: false, + }, +} + +type EditNetworkElementDialogComponentProps = Connect & { + mode: EditNetworkElementDialogMode; + initialNetworkElement: RequiredNetworkElementType; + onClose: () => void; +}; + +type EditNetworkElementDialogComponentState = RequiredNetworkElementType & { + required: boolean; +}; + +class EditNetworkElementDialogComponent extends React.Component { + constructor(props: EditNetworkElementDialogComponentProps) { + super(props); + + this.state = { + mountId: this.props.initialNetworkElement.mountId, + host: this.props.initialNetworkElement.host, + port: this.props.initialNetworkElement.port, + password: this.props.initialNetworkElement.password, + username: this.props.initialNetworkElement.username, + required: false + }; + } + + render(): JSX.Element { + const setting = settings[this.props.mode]; + return ( + + { setting.dialogTitle } + + + { setting.dialogDescription } + + { this.setState({mountId: event.target.value}); } } /> + { this.setState({host: event.target.value}); } }/> + { this.setState({port: +event.target.value}); } }/> + { setting.enableUsernameEditor && { this.setState({ username: event.target.value }); } } /> || null } + { setting.enableUsernameEditor && { this.setState({ password: event.target.value }); } } /> || null } + + + + + + + ) + } + + private onApply = (element: RequiredNetworkElementType) => { + this.props.onClose && this.props.onClose(); + switch (this.props.mode) { + case EditNetworkElementDialogMode.UnknownNetworkElementToRequiredNetworkElements: + element && this.props.addToRequiredNetworkElements(element); + break; + case EditNetworkElementDialogMode.RequiredNetworkElementToUnknownNetworkElements: + element && this.props.removeFromRequiredNetworkElements(element); + break; + case EditNetworkElementDialogMode.MountNetworkElementToUnknonwNetworkElements: + element && this.props.mountNetworkElement(element); + break; + case EditNetworkElementDialogMode.MountNetworkElementToRequiredNetworkElements: + element && this.props.mountAndRquireNetworkElement(element); + break; + case EditNetworkElementDialogMode.MountNetworkElement: + element && this.props.mountNetworkElement(element); + break; + case EditNetworkElementDialogMode.UnmountNetworkElement: + element && this.props.unmountNetworkElement(element); + break; + } + }; + + private onCancel = () => { + this.props.onClose && this.props.onClose(); + } + + static getDerivedStateFromProps(props: EditNetworkElementDialogComponentProps, state: EditNetworkElementDialogComponentState & { _initialNetworkElement: RequiredNetworkElementType }): EditNetworkElementDialogComponentState & { _initialNetworkElement: RequiredNetworkElementType } { + if (props.initialNetworkElement !== state._initialNetworkElement) { + state = { + ...state, + ...props.initialNetworkElement, + _initialNetworkElement: props.initialNetworkElement, + }; + } + return state; + } +} + +export const EditNetworkElementDialog = connect(undefined, mapDispatch)(EditNetworkElementDialogComponent); +export default EditNetworkElementDialog; \ No newline at end of file diff --git a/sdnr/wt/odlux/apps/connectApp/src/components/requiredNetworkElements.tsx b/sdnr/wt/odlux/apps/connectApp/src/components/requiredNetworkElements.tsx new file mode 100644 index 000000000..13f5fec20 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/components/requiredNetworkElements.tsx @@ -0,0 +1,194 @@ +import * as React from 'react'; +import { Theme, createStyles, withStyles, WithStyles } from '@material-ui/core/styles'; + +import AddIcon from '@material-ui/icons/Add'; +import LinkIcon from '@material-ui/icons/Link'; +import LinkOffIcon from '@material-ui/icons/LinkOff'; +import RemoveIcon from '@material-ui/icons/RemoveCircleOutline'; + +import Button from '@material-ui/core/Button'; +import IconButton from '@material-ui/core/IconButton'; + +import { MaterialTable, ColumnType, MaterialTableCtorType } from '../../../../framework/src/components/material-table'; +import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore'; +import { connect, Connect, IDispatcher } from '../../../../framework/src/flux/connect'; +import { NavigateToApplication } from '../../../../framework/src/actions/navigationActions'; + + +import { RequiredNetworkElementType } from '../models/requiredNetworkElements'; +import { createRequiredNetworkElementsActions, createRequiredNetworkElementsProperties } from '../handlers/requiredNetworkElementsHandler'; + +import EditNetworkElementDialog, { EditNetworkElementDialogMode } from './editNetworkElementDialog'; +import { Tooltip } from '@material-ui/core'; +import { NetworkElementBaseType } from 'models/networkElementBase'; + +const styles = (theme: Theme) => createStyles({ + connectionStatusConnected: { + color: 'darkgreen', + }, + connectionStatusConnecting: { + color: theme.palette.primary.main, + }, + connectionStatusDisconnected: { + color: 'red', + }, + button: { + margin: 0, + padding: "6px 6px", + minWidth: 'unset' + }, + spacer: { + marginLeft: theme.spacing.unit, + marginRight: theme.spacing.unit, + display: "inline" + } +}); + +const mapProps = (state: IApplicationStoreState) => ({ + requiredNetworkElementsProperties: createRequiredNetworkElementsProperties(state), + mountedNetworkElements: state.connectApp.mountedNetworkElements +}); + +const mapDispatch = (dispatcher: IDispatcher) => ({ + requiredNetworkElementsActions: createRequiredNetworkElementsActions(dispatcher.dispatch), + navigateToApplication: (applicationName: string, path?: string) => dispatcher.dispatch(new NavigateToApplication(applicationName, path)), +}); + +type RequiredNetworkElementsListComponentProps = WithStyles & Connect; +type RequiredNetworkElementsListComponentState = { + networkElementToEdit: RequiredNetworkElementType, + networkElementEditorMode: EditNetworkElementDialogMode +} + +const emptyRequireNetworkElement = { mountId: '', host: '', port: 0 }; + +const RequiredNetworkElementTable = MaterialTable as MaterialTableCtorType; + +export class RequiredNetworkElementsListComponent extends React.Component { + + constructor(props: RequiredNetworkElementsListComponentProps) { + super(props); + + this.state = { + networkElementToEdit: emptyRequireNetworkElement, + networkElementEditorMode: EditNetworkElementDialogMode.None + }; + } + + // private navigationCreator + + render(): JSX.Element { + const { classes } = this.props; + const { networkElementToEdit } = this.state; + const addRequireNetworkElementAction = { + icon: AddIcon, tooltip: 'Add', onClick: () => { + this.setState({ + networkElementEditorMode: EditNetworkElementDialogMode.MountNetworkElementToRequiredNetworkElements, + networkElementToEdit: emptyRequireNetworkElement, + }); + } + }; + return ( + <> + { + const unknownNetworkElement = this.props.mountedNetworkElements.elements.find(el => el.mountId === rowData.mountId); + const connectionStatus = unknownNetworkElement && unknownNetworkElement.connectionStatus || 'disconnected'; + const cssClasses = connectionStatus === "connected" + ? classes.connectionStatusConnected + : connectionStatus === "disconnected" + ? classes.connectionStatusDisconnected + : classes.connectionStatusConnecting + return
{ connectionStatus }
+ + } + }, + { property: "host", title: "Host", type: ColumnType.text }, + { property: "port", title: "Port", type: ColumnType.text }, + // { property: "username", title: "Username", type: ColumnType.text }, + // { property: "password", title: "Password", type: ColumnType.text }, + { + property: "actions", title: "Actions", type: ColumnType.custom, customControl: ({ rowData }) => { + const unknownNetworkElement = this.props.mountedNetworkElements.elements.find(el => el.mountId === rowData.mountId); + const connectionStatus = unknownNetworkElement && unknownNetworkElement.connectionStatus || 'disconnected'; + return ( + <> +
+ this.onOpenMountdNetworkElementsDialog(event, rowData) }> + this.onOpenUnmountdNetworkElementsDialog(event, rowData) }> + this.onOpenRemoveRequiredNetworkElementDialog(event, rowData) } > +
+
+ +
+
+ + + + + +
+ + ) + } + }, + ] } idProperty="mountId" { ...this.props.requiredNetworkElementsActions } { ...this.props.requiredNetworkElementsProperties } asynchronus > +
+ + + ); + }; + + public componentDidMount() { + this.props.requiredNetworkElementsActions.onRefresh(); + } + + private onOpenRemoveRequiredNetworkElementDialog = (event: React.MouseEvent, element: RequiredNetworkElementType) => { + this.setState({ + networkElementToEdit: element, + networkElementEditorMode: EditNetworkElementDialogMode.RequiredNetworkElementToUnknownNetworkElements + }); + event.preventDefault(); + event.stopPropagation(); + } + + private onOpenUnmountdNetworkElementsDialog = (event: React.MouseEvent, element: RequiredNetworkElementType) => { + this.setState({ + networkElementToEdit: element, + networkElementEditorMode: EditNetworkElementDialogMode.UnmountNetworkElement + }); + event.preventDefault(); + event.stopPropagation(); + } + + private onOpenMountdNetworkElementsDialog = (event: React.MouseEvent, element: RequiredNetworkElementType) => { + this.setState({ + networkElementToEdit: element, + networkElementEditorMode: EditNetworkElementDialogMode.MountNetworkElement + }); + event.preventDefault(); + event.stopPropagation(); + } + + private onCloseEditNetworkElementDialog = () => { + this.setState({ + networkElementEditorMode: EditNetworkElementDialogMode.None, + networkElementToEdit: emptyRequireNetworkElement, + }); + } + + private navigateToApplicationHandlerCreator = (applicationName: string, element: NetworkElementBaseType) => (event: React.MouseEvent) => { + this.props.navigateToApplication(applicationName, element.mountId); + event.preventDefault(); + event.stopPropagation(); + } +} + +export const RequiredNetworkElementsList = withStyles(styles)(connect(mapProps, mapDispatch)(RequiredNetworkElementsListComponent)); +export default RequiredNetworkElementsList; \ No newline at end of file diff --git a/sdnr/wt/odlux/apps/connectApp/src/components/unknownNetworkElements.tsx b/sdnr/wt/odlux/apps/connectApp/src/components/unknownNetworkElements.tsx new file mode 100644 index 000000000..432103128 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/components/unknownNetworkElements.tsx @@ -0,0 +1,196 @@ +import * as React from 'react'; +import { Theme, createStyles, WithStyles, withStyles, Tooltip } from '@material-ui/core'; + +import AddIcon from '@material-ui/icons/Add'; +import LinkOffIcon from '@material-ui/icons/LinkOff'; +import AddCircleIcon from '@material-ui/icons/AddCircleOutline'; + +import Button from '@material-ui/core/Button'; +import IconButton from '@material-ui/core/IconButton'; + +import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore'; +import { MaterialTable, ColumnType, MaterialTableCtorType } from '../../../../framework/src/components/material-table'; +import { Connect, connect, IDispatcher } from '../../../../framework/src/flux/connect'; +import { NavigateToApplication } from '../../../../framework/src/actions/navigationActions'; + +import { RequiredNetworkElementType } from '../models/requiredNetworkElements'; +import { IMountedNetworkElementsState } from '../handlers/mountedNetworkElementsHandler'; +import EditNetworkElementDialog, { EditNetworkElementDialogMode } from './editNetworkElementDialog'; +import { NetworkElementBaseType } from 'models/networkElementBase'; + + +const styles = (theme: Theme) => createStyles({ + button: { + margin: 0, + padding: "6px 6px", + minWidth: 'unset' + }, + spacer: { + marginLeft: theme.spacing.unit, + marginRight: theme.spacing.unit, + display: "inline" + } +}); + +const mapProps = ({ connectApp: state }: IApplicationStoreState) => ({ + mountedNetworkElements: state.mountedNetworkElements +}); + +const mapDispatch = (dispatcher: IDispatcher) => ({ + navigateToApplication: (applicationName: string, path?: string) => dispatcher.dispatch(new NavigateToApplication(applicationName, path)), +}); +type UnknownNetworkElementDisplayType = NetworkElementBaseType & { + connectionStatus: string, + coreModelRev: string, + airInterfaceRev: string +} + +type UnknownNetworkElementsListProps = WithStyles & Connect & {} + +type UnknownNetworkElementsListState = { + + unknownNetworkElements: UnknownNetworkElementDisplayType[]; + + networkElementToEdit: RequiredNetworkElementType; + networkElementEditorMode: EditNetworkElementDialogMode; +} + + +const emptyRequireNetworkElement = { mountId: '', host: '', port: 0 }; +const UnknownNetworkElementTable = MaterialTable as MaterialTableCtorType; +export class UnknownNetworkElementsListComponent extends React.Component { + + constructor(props: UnknownNetworkElementsListProps) { + super(props); + + this.state = { + unknownNetworkElements: [], + networkElementToEdit: emptyRequireNetworkElement, + networkElementEditorMode: EditNetworkElementDialogMode.None, + }; + } + + static getDerivedStateFromProps(props: UnknownNetworkElementsListProps, state: UnknownNetworkElementsListState & { _mountedNetworkElements: IMountedNetworkElementsState }) { + if (props.mountedNetworkElements != state._mountedNetworkElements) { + state.unknownNetworkElements = props.mountedNetworkElements.elements.filter(element => !element.required).map(element => { + + // handle onfCoreModelRevision + const onfCoreModelRevision = element.capabilities.find((cap) => { + return cap.module === 'core-model' || cap.module === 'CoreModel-CoreNetworkModule-ObjectClasses' ; + }); + const onfAirInterfaceRevision = element.capabilities.find((cap) => { + return cap.module === 'microwave-model' || cap.module === 'MicrowaveModel-ObjectClasses-AirInterface' ; + }); + return { + mountId: element.mountId, + host: element.host, + port: element.port, + connectionStatus: element.connectionStatus, + coreModelRev: onfCoreModelRevision && onfCoreModelRevision.revision || 'unknown', + airInterfaceRev: onfAirInterfaceRevision && onfAirInterfaceRevision.revision || 'unknown' + } + } + ); + } + return state; + } + + render(): JSX.Element { + const { classes } = this.props; + const { networkElementToEdit, networkElementEditorMode, unknownNetworkElements } = this.state; + const addRequireNetworkElementAction = { + icon: AddIcon, tooltip: 'Add', onClick: () => { + this.setState({ + networkElementEditorMode: EditNetworkElementDialogMode.MountNetworkElementToUnknonwNetworkElements, + networkElementToEdit: emptyRequireNetworkElement, + }); + } + }; + return ( + <> + ( + <> +
+ this.onOpenUnmountdNetworkElementsDialog(event, rowData) } > + this.onOpenAddToRequiredNetworkElementsDialog(event, rowData) } > +
+
+ +
+
+
+ + + + + +
+
+ + ) + }, + ] } idProperty="mountId" > +
+ + + + ); + }; + + private onOpenAddToRequiredNetworkElementsDialog = (event: React.MouseEvent, element: UnknownNetworkElementDisplayType) => { + this.setState({ + networkElementToEdit: { + mountId: element.mountId, + host: element.host, + port: element.port, + username: 'admin', + password: 'admin', + }, + networkElementEditorMode: EditNetworkElementDialogMode.UnknownNetworkElementToRequiredNetworkElements + }); + event.preventDefault(); + event.stopPropagation(); + } + + private onOpenUnmountdNetworkElementsDialog = (event: React.MouseEvent, element: UnknownNetworkElementDisplayType) => { + this.setState({ + networkElementToEdit: { + mountId: element.mountId, + host: element.host, + port: element.port + }, + networkElementEditorMode: EditNetworkElementDialogMode.UnmountNetworkElement + }); + event.preventDefault(); + event.stopPropagation(); + } + + private onCloseEditNetworkElementDialog = () => { + this.setState({ + networkElementEditorMode: EditNetworkElementDialogMode.None, + networkElementToEdit: emptyRequireNetworkElement, + }); + } + + private navigateToApplicationHandlerCreator = (applicationName: string, element: NetworkElementBaseType) => (event: React.MouseEvent) => { + this.props.navigateToApplication(applicationName, element.mountId); + event.preventDefault(); + event.stopPropagation(); + } + +} + +export const UnknownNetworkElementsList = withStyles(styles)(connect(mapProps, mapDispatch)(UnknownNetworkElementsListComponent)); +export default UnknownNetworkElementsList; diff --git a/sdnr/wt/odlux/apps/connectApp/src/handlers/connectAppRootHandler.tsx b/sdnr/wt/odlux/apps/connectApp/src/handlers/connectAppRootHandler.tsx new file mode 100644 index 000000000..26d02c4e9 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/handlers/connectAppRootHandler.tsx @@ -0,0 +1,26 @@ +import { combineActionHandler } from '../../../../framework/src/flux/middleware'; +import { IRequiredNetworkElementsState, requiredNetworkElementsActionHandler } from './requiredNetworkElementsHandler'; +import { IMountedNetworkElementsState, mountedNetworkElementsActionHandler } from './mountedNetworkElementsHandler'; +import { IConnectionStatusLogState, connectionStatusLogActionHandler } from './connectionStatusLogHandler'; + +export interface IConnectAppStoreState { + + requiredNetworkElements: IRequiredNetworkElementsState; + mountedNetworkElements: IMountedNetworkElementsState; + connectionStatusLog: IConnectionStatusLogState; +} + +declare module '../../../../framework/src/store/applicationStore' { + interface IApplicationStoreState { + connectApp: IConnectAppStoreState + } +} + +const actionHandlers = { + requiredNetworkElements: requiredNetworkElementsActionHandler, + mountedNetworkElements: mountedNetworkElementsActionHandler, + connectionStatusLog: connectionStatusLogActionHandler +}; + +export const connectAppRootHandler = combineActionHandler (actionHandlers); +export default connectAppRootHandler; diff --git a/sdnr/wt/odlux/apps/connectApp/src/handlers/connectionStatusLogHandler.tsx b/sdnr/wt/odlux/apps/connectApp/src/handlers/connectionStatusLogHandler.tsx new file mode 100644 index 000000000..140020eaa --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/handlers/connectionStatusLogHandler.tsx @@ -0,0 +1,30 @@ +import { createExternal,IExternalTableState } from '../../../../framework/src/components/material-table/utilities'; +import { createSearchDataHandler } from '../../../../framework/src/utilities/elasticSearch'; + +import { ConnectionStatusLogType } from '../models/connectionStatusLog'; +export interface IConnectionStatusLogState extends IExternalTableState { } + +// create eleactic search material data fetch handler +const connectionStatusLogSearchHandler = createSearchDataHandler<{ event: ConnectionStatusLogType }, ConnectionStatusLogType>('sdnevents_v1/eventlog', null, + (event) => ({ + _id: event._id, + timeStamp: event._source.event.timeStamp, + objectId: event._source.event.objectId, + type: event._source.event.type, + elementStatus: event._source.event.type === 'ObjectCreationNotificationXml' + ? 'connected' + : event._source.event.type === 'ObjectDeletionNotificationXml' + ? 'disconnected' + : 'unknown' + }), + (name) => `event.${ name }`); + +export const { + actionHandler: connectionStatusLogActionHandler, + createActions: createConnectionStatusLogActions, + createProperties: createConnectionStatusLogProperties, + reloadAction: connectionStatusLogReloadAction, + + // set value action, to change a value +} = createExternal(connectionStatusLogSearchHandler, appState => appState.connectApp.connectionStatusLog); + diff --git a/sdnr/wt/odlux/apps/connectApp/src/handlers/mountedNetworkElementsHandler.tsx b/sdnr/wt/odlux/apps/connectApp/src/handlers/mountedNetworkElementsHandler.tsx new file mode 100644 index 000000000..70b4d8f2a --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/handlers/mountedNetworkElementsHandler.tsx @@ -0,0 +1,81 @@ +import { IActionHandler } from '../../../../framework/src/flux/action'; + +import { + AddMountedNetworkElement, + AllMountedNetworkElementsLoadedAction, + LoadAllMountedNetworkElementsAction, + RemoveMountedNetworkElement, + UpdateConnectionStateMountedNetworkElement, + UpdateRequiredMountedNetworkElement +} from '../actions/mountedNetworkElementsActions'; + +import { MountedNetworkElementType } from '../models/mountedNetworkElements'; + +export interface IMountedNetworkElementsState { + elements: MountedNetworkElementType[]; + busy: boolean; +} + +const mountedNetworkElementsStateInit: IMountedNetworkElementsState = { + elements: [], + busy: false +}; + +export const mountedNetworkElementsActionHandler: IActionHandler = (state = mountedNetworkElementsStateInit, action) => { + if (action instanceof LoadAllMountedNetworkElementsAction) { + + state = { + ...state, + busy: true + }; + + } else if (action instanceof AllMountedNetworkElementsLoadedAction) { + if (!action.error && action.mountedNetworkElements) { + state = { + ...state, + elements: action.mountedNetworkElements, + busy: false + }; + } else { + state = { + ...state, + busy: false + }; + } + } else if (action instanceof AddMountedNetworkElement) { + action.mountedNetworkElement && (state = { + ...state, + elements: [...state.elements, action.mountedNetworkElement], + }); + } else if (action instanceof RemoveMountedNetworkElement) { + state = { + ...state, + elements: state.elements.filter(e => e.mountId !== action.mountId), + }; + } else if (action instanceof UpdateConnectionStateMountedNetworkElement) { + const index = state.elements.findIndex(el => el.mountId === action.mountId); + if (index > -1) { + state = { + ...state, + elements: [ + ...state.elements.slice(0, index), + { ...state.elements[index], connectionStatus: action.mountId }, + ...state.elements.slice(index + 1) + ] + } + } + } else if (action instanceof UpdateRequiredMountedNetworkElement) { + const index = state.elements.findIndex(el => el.mountId === action.mountId); + if (index > -1 && (state.elements[index].required !== action.required)) { + state = { + ...state, + elements: [ + ...state.elements.slice(0, index), + { ...state.elements[index], required: action.required }, + ...state.elements.slice(index + 1) + ] + } + } + }; + return state; +}; \ No newline at end of file diff --git a/sdnr/wt/odlux/apps/connectApp/src/handlers/requiredNetworkElementsHandler.tsx b/sdnr/wt/odlux/apps/connectApp/src/handlers/requiredNetworkElementsHandler.tsx new file mode 100644 index 000000000..b2d547717 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/handlers/requiredNetworkElementsHandler.tsx @@ -0,0 +1,18 @@ +import { createExternal,IExternalTableState } from '../../../../framework/src/components/material-table/utilities'; +import { createSearchDataHandler } from '../../../../framework/src/utilities/elasticSearch'; + +import { RequiredNetworkElementType } from '../models/requiredNetworkElements'; +export interface IRequiredNetworkElementsState extends IExternalTableState { } + +// create eleactic search material data fetch handler +const requiredNetworkElementsSearchHandler = createSearchDataHandler('mwtn/required-networkelement'); + +export const { + actionHandler: requiredNetworkElementsActionHandler, + createActions: createRequiredNetworkElementsActions, + createProperties: createRequiredNetworkElementsProperties, + reloadAction: requiredNetworkElementsReloadAction, + + // set value action, to change a value +} = createExternal(requiredNetworkElementsSearchHandler, appState => appState.connectApp.requiredNetworkElements); + diff --git a/sdnr/wt/odlux/apps/connectApp/src/index.html b/sdnr/wt/odlux/apps/connectApp/src/index.html new file mode 100644 index 000000000..c28708a83 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/index.html @@ -0,0 +1,26 @@ + + + + + + + + + Document + + + +
+ + + + + + \ No newline at end of file diff --git a/sdnr/wt/odlux/apps/connectApp/src/models/connectionStatusLog.ts b/sdnr/wt/odlux/apps/connectApp/src/models/connectionStatusLog.ts new file mode 100644 index 000000000..d3aa20379 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/models/connectionStatusLog.ts @@ -0,0 +1,9 @@ + +export type ConnectionStatusLogType = { + _id: string; + elementStatus: string; + timeStamp: string; + objectId: string; + type: string; +} + diff --git a/sdnr/wt/odlux/apps/connectApp/src/models/mountedNetworkElements.ts b/sdnr/wt/odlux/apps/connectApp/src/models/mountedNetworkElements.ts new file mode 100644 index 000000000..4ab7c8e20 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/models/mountedNetworkElements.ts @@ -0,0 +1,11 @@ +import { NetworkElementBaseType } from "./networkElementBase"; + +/** +* Represents data of an mounted network elements. +*/ +export type MountedNetworkElementType = NetworkElementBaseType & { + connectionStatus: string; + required: boolean; + capabilities: { module: string, revision: string }[]; +}; + diff --git a/sdnr/wt/odlux/apps/connectApp/src/models/networkElementBase.ts b/sdnr/wt/odlux/apps/connectApp/src/models/networkElementBase.ts new file mode 100644 index 000000000..85390bef9 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/models/networkElementBase.ts @@ -0,0 +1,5 @@ +export type NetworkElementBaseType = { + mountId: string, + host: string, + port: number, +} \ No newline at end of file diff --git a/sdnr/wt/odlux/apps/connectApp/src/models/requiredNetworkElements.ts b/sdnr/wt/odlux/apps/connectApp/src/models/requiredNetworkElements.ts new file mode 100644 index 000000000..08d1f91ec --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/models/requiredNetworkElements.ts @@ -0,0 +1,10 @@ +import { NetworkElementBaseType } from "./networkElementBase"; + +/** +* Represents data of Required Network Elements. +*/ +export type RequiredNetworkElementType = NetworkElementBaseType & { + username?: string; + password?: string; +} + diff --git a/sdnr/wt/odlux/apps/connectApp/src/models/topologyNetconf.ts b/sdnr/wt/odlux/apps/connectApp/src/models/topologyNetconf.ts new file mode 100644 index 000000000..5cf29c708 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/models/topologyNetconf.ts @@ -0,0 +1,36 @@ +export interface UnavailableCapability { + capability: string; + "failure-reason": string; +} + +export interface NetconfNodeTopologyUnavailableCapabilities { + "unavailable-capability": UnavailableCapability[]; +} + +export interface AvailableCapability { + "capability-origin": string; + capability: string; +} + +export interface NetconfNodeTopologyAvailableCapabilities { + "available-capability": AvailableCapability[]; +} + +export interface NetconfNodeTopologyClusteredConnectionStatus { + "netconf-master-node": string +} + +export interface TopologyNode { + "node-id": string; + "netconf-node-topology:clustered-connection-status": NetconfNodeTopologyClusteredConnectionStatus; + "netconf-node-topology:unavailable-capabilities": NetconfNodeTopologyUnavailableCapabilities; + "netconf-node-topology:available-capabilities": NetconfNodeTopologyAvailableCapabilities; + "netconf-node-topology:host": string; + "netconf-node-topology:connection-status": string; + "netconf-node-topology:port": number; +} + +export interface Topology { + "topology-id": string; + node: TopologyNode[]; +} diff --git a/sdnr/wt/odlux/apps/connectApp/src/plugin.tsx b/sdnr/wt/odlux/apps/connectApp/src/plugin.tsx new file mode 100644 index 000000000..4e61c326b --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/plugin.tsx @@ -0,0 +1,39 @@ + +import { faPlug } from '@fortawesome/free-solid-svg-icons'; + +import applicationManager from '../../../framework/src/services/applicationManager'; +import { subscribe, IFormatedMessage } from '../../../framework/src/services/notificationService'; + +import connectAppRootHandler from './handlers/connectAppRootHandler'; +import ConnectApplication from './views/connectView'; +import { RemoveMountedNetworkElement, addMountedNetworkElementAsyncActionCreator } from './actions/mountedNetworkElementsActions' ; +import { AddSnackbarNotification } from '../../../framework/src/actions/snackbarActions'; + +type ObjectNotification = { + counter: string; + nodeName: string; + objectId: string; + timeStamp: string; +} + +export function register() { + const applicationApi = applicationManager.registerApplication({ + name: "connectApp", + icon: faPlug, + rootComponent: ConnectApplication, + rootActionHandler: connectAppRootHandler, + menuEntry: "Connect App" + }); + + // subscribe to the websocket notifications + subscribe(["ObjectCreationNotification", "ObjectDeletionNotification"], (msg => { + const store = applicationApi && applicationApi.applicationStore; + if (msg && msg.notifType === "ObjectCreationNotification" && store) { + store.dispatch(addMountedNetworkElementAsyncActionCreator(msg.objectId)); + store.dispatch(new AddSnackbarNotification({ message: `Adding network element [${ msg.objectId }]`, options: { variant: 'info' } })); + } else if (msg && msg.notifType === "ObjectDeletionNotification" && store) { + store.dispatch(new AddSnackbarNotification({ message: `Removing network element [${ msg.objectId }]`, options: { variant: 'info' } })); + store.dispatch(new RemoveMountedNetworkElement(msg.objectId)); + } + })); +} \ No newline at end of file diff --git a/sdnr/wt/odlux/apps/connectApp/src/services/connectService.ts b/sdnr/wt/odlux/apps/connectApp/src/services/connectService.ts new file mode 100644 index 000000000..0adcd49c6 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/services/connectService.ts @@ -0,0 +1,204 @@ +import { RequiredNetworkElementType } from '../models/requiredNetworkElements'; +import { MountedNetworkElementType } from 'models/mountedNetworkElements'; +import { Topology, TopologyNode } from 'models/topologyNetconf'; + +import { requestRest } from '../../../../framework/src/services/restService'; +import { Result, HitEntry } from '../../../../framework/src/models/elasticSearch'; + + +/** + * Represents a web api accessor service for all Network Elements actions. + */ +class ConnectService { + /** + * Gets all known required network elements from the backend. + */ + public async getAllRequiredNetworkElements(): Promise<(RequiredNetworkElementType & { _id: string })[] | null> { + const path = 'database/mwtn/required-networkelement/_search'; + const query = { "query": { "match_all": {} } }; + + const result = await requestRest>(path, { method: "POST", body: JSON.stringify(query) }); + return result && result.hits && result.hits.hits && result.hits.hits.map(ne => ({ + _id: ne._id, + mountId: ne._source && ne._source.mountId, + host: ne._source && ne._source.host, + port: ne._source && ne._source.port, + username: ne._source && ne._source.username, + password: ne._source && ne._source.password, + })) || null; + } + + public async getRequiredNetworkElementByMountId(mountId:string): Promise<(RequiredNetworkElementType & { _id: string }) | null> { + const path = `database/mwtn/required-networkelement/${mountId}`; + + const result = await requestRest & { found: boolean }>(path, { method: "GET" }); + return result && result.found && result._source && { + _id: result._id, + mountId: result._source.mountId, + host: result._source.host, + port: result._source.port, + username: result._source.username, + password: result._source.password, + } || null; + + } + + /** + * Inserts data into the required network elements table. + */ + public async insertRequiredNetworkElement(element: RequiredNetworkElementType): Promise { + const path = `database/mwtn/required-networkelement/${ element.mountId }`; + const result = await requestRest(path, { method: "POST", body: JSON.stringify(element) }); + return result || null; + } + + /** + * Deletes data from the Required Network Elements backend. + */ + public async deleteRequiredNetworkElement(element: RequiredNetworkElementType): Promise { + const path = `database/mwtn/required-networkelement/${ element.mountId }`; + const result = await requestRest(path, { method: "DELETE", body: JSON.stringify(element) }); + return result || null; + } + + + + private static mapTopologyNode = (mountPoint: TopologyNode, required: boolean ) => { + // handle onfCapabilities + let onfCapabilities: { module: string, revision: string }[] | undefined = undefined; + let onfCoreModelRevision: string[] | undefined = undefined; + let onfAirInterfaceRevision: string[] | undefined = undefined; + + const capId = 'netconf-node-topology:available-capabilities'; + if (mountPoint[capId] && mountPoint[capId]['available-capability']) { + onfCapabilities = mountPoint[capId]['available-capability'].filter((cap) => { + return cap.capability.includes('?revision='); + }).map((cap) => { + return { + module: cap.capability.split(')')[1], + revision: cap.capability.split('?revision=')[1].substring(0, 10) + }; + }).sort((a, b) => { + if (a.module < b.module) return -1; + if (a.module > b.module) return 1; + return 0; + }); + } + + // handle clustered-connection-status + const statusId = 'netconf-node-topology:clustered-connection-status'; + let client = 'localhost'; + + if (mountPoint[statusId] && mountPoint[statusId]['netconf-master-node']) { + let node = mountPoint[statusId]['netconf-master-node']; + node = node.substring(node.indexOf('@')); + client = node.substring(1, node.indexOf(':')); + } + const mountId = mountPoint["node-id"]; + return { + mountId: mountId, + host: mountPoint["netconf-node-topology:host"], + port: mountPoint["netconf-node-topology:port"], + connectionStatus: mountPoint['netconf-node-topology:connection-status'], + capabilities: onfCapabilities || [], + required: required, + client + } + } + + /** Get all mounted network elements and fills the property required according to the database contents. */ + public async getMountedNetworkElementsList(): Promise { + const path = 'restconf/operational/network-topology:network-topology/topology/topology-netconf'; + + const topologyRequestPomise = requestRest<{ topology: Topology[] | null }>(path, { method: "GET" }, true); + const requiredNetworkElementsPromise = this.getAllRequiredNetworkElements(); + + const [netconfResponse, requiredNetworkElements] = await Promise.all([topologyRequestPomise, requiredNetworkElementsPromise]); + + // process topologyNetconf (get all known network elements) + const topologyNetconf = netconfResponse && netconfResponse.topology && netconfResponse.topology.find(topology => topology["topology-id"] === 'topology-netconf'); + let mountPoints = topologyNetconf && topologyNetconf.node && topologyNetconf.node.filter( + mountPoint => mountPoint['node-id'] !== 'controller-config').map(mountedElement => { + const required = requiredNetworkElements && requiredNetworkElements.some( + requiredElement => requiredElement.mountId === mountedElement["node-id"]); + return ConnectService.mapTopologyNode(mountedElement, !!required); + }); + + return mountPoints || []; + } + + /** Get one mounted network element. */ + public async getMountedNetworkElementByMountId(mountId: string): Promise { + const path = 'restconf/operational/network-topology:network-topology/topology/topology-netconf/node/' + mountId; + const getMountedNetworkElementByMountIdPromise = requestRest<{ node: TopologyNode[] | null }>(path, { method: "GET" }, true); + const getRequiredNetworkElementByMountIdPromise = this.getRequiredNetworkElementByMountId(mountId); + + const [mountedNetworkElement, requiredNetworkElement] = await Promise.all([getMountedNetworkElementByMountIdPromise, getRequiredNetworkElementByMountIdPromise]); + return mountedNetworkElement && mountedNetworkElement.node && ConnectService.mapTopologyNode(mountedNetworkElement.node[0], requiredNetworkElement && requiredNetworkElement.mountId === mountedNetworkElement.node[0]["node-id"] || false) || null; + } + + /** Mounts an required network element. */ + public async mountNetworkElement(networkElement: RequiredNetworkElementType): Promise { + const path = 'restconf/config/network-topology:network-topology/topology/topology-netconf/node/' + networkElement.mountId; + const mountXml = [ + '', + `${ networkElement.mountId }`, + `${ networkElement.host }`, + `${ networkElement.port }`, + `${ networkElement.username }`, + `${ networkElement.password }`, + ' false', + + ' ', + ' false', + ' 20000', + ' 100', + ' 2000', + ' 1.5', + + ' ', + ' 120', + ''].join(''); + + try { + const result = await requestRest<{}>(path, { + method: 'PUT', + headers: { + 'Content-Type': 'application/xml', + 'Accept': 'application/xml', + 'Authorization': 'Basic YWRtaW46YWRtaW4=' + }, + body: mountXml + }, true); + // expect an empty answer + return result === null; + } catch { + return false; + } + }; + + /** Unmounts a network element by its id. */ + public async unmountNetworkElement(mountId: string): Promise { + const path = 'restconf/config/network-topology:network-topology/topology/topology-netconf/node/' + mountId; + + try { + const result = await requestRest<{}>(path, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/xml', + 'Accept': 'application/xml', + 'Authorization': 'Basic YWRtaW46YWRtaW4=' + }, + }, true); + // expect an empty answer + return result === null; + + } catch { + return false; + } + }; + + +} +export const connectService = new ConnectService(); +export default connectService; diff --git a/sdnr/wt/odlux/apps/connectApp/src/views/connectView.tsx b/sdnr/wt/odlux/apps/connectApp/src/views/connectView.tsx new file mode 100644 index 000000000..b73eb39d7 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/views/connectView.tsx @@ -0,0 +1,93 @@ +import * as React from 'react'; + +import connect, { IDispatcher, Connect } from '../../../../framework/src/flux/connect'; +import { Panel } from '../../../../framework/src/components/material-ui'; + +import { requiredNetworkElementsReloadAction } from '../handlers/requiredNetworkElementsHandler'; +import { loadAllMountedNetworkElementsAsync } from '../actions/mountedNetworkElementsActions'; +import { connectionStatusLogReloadAction } from '../handlers/connectionStatusLogHandler'; + +import { RequiredNetworkElementsList } from '../components/requiredNetworkElements'; +import { ConnectionStatusLog } from '../components/connectionStatusLog'; +import { UnknownNetworkElementsList } from '../components/unknownNetworkElements'; + +const mapDispatcher = (dispatcher: IDispatcher) => ({ + onLoadUnknownNetworkElements: () => { + dispatcher.dispatch(loadAllMountedNetworkElementsAsync); + }, + onLoadRequiredNetworkElements: () => { + dispatcher.dispatch(requiredNetworkElementsReloadAction); + }, + onLoadConnectionStatusLog: () => { + dispatcher.dispatch(connectionStatusLogReloadAction); + } +}); + +type PanelId = null | "RequiredNetworkElements" | "UnknownNetworkElements" | "ConnectionStatusLog"; + +type ConnectApplicationComponentProps = Connect ; + +type ConnectApplicationComponentState = { + activePanel: PanelId; +}; + +class ConnectApplicationComponent extends React.Component{ + /** + * Initialises this instance + */ + constructor(props: ConnectApplicationComponentProps) { + super(props); + + this.state = { + activePanel: null + }; + } + private onTogglePanel = (panelId: PanelId) => { + const nextActivePanel = panelId === this.state.activePanel ? null : panelId; + this.setState({ + activePanel: nextActivePanel + }, () => { + switch (nextActivePanel) { + case 'RequiredNetworkElements': + this.props.onLoadRequiredNetworkElements(); + break; + case 'UnknownNetworkElements': + // todo: should we update the application state ? + break; + case 'ConnectionStatusLog': + this.props.onLoadConnectionStatusLog(); + break; + case null: + // do nothing if all panels are closed + break; + default: + console.warn("Unknown nextActivePanel [" + nextActivePanel + "] in connectView"); + break; + } + }); + }; + + render(): JSX.Element { + const { activePanel } = this.state; + + return ( + <> + + + + + + + + + + + ); + }; + public componentDidMount() { + this.props.onLoadUnknownNetworkElements(); + } +} + +export const ConnectApplication = (connect(undefined, mapDispatcher)(ConnectApplicationComponent)); +export default ConnectApplication; \ No newline at end of file diff --git a/sdnr/wt/odlux/apps/connectApp/src2/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/bundles/MyOdluxBundle.java b/sdnr/wt/odlux/apps/connectApp/src2/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/bundles/MyOdluxBundle.java new file mode 100644 index 000000000..1e882fc69 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src2/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/bundles/MyOdluxBundle.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH 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========================================================================== + ******************************************************************************/ +package org.onap.ccsdk.features.sdnr.wt.odlux.bundles; + +import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundle; +import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundleLoader; + +public class MyOdluxBundle extends OdluxBundle { + + @Override + public void initialize() { + super.initialize(); + } + + @Override + public void clean() { + super.clean(); + } + + @Override + public String getResourceFileContent(String filename) { + return super.getResourceFileContent(filename); + } + + @Override + public boolean hasResource(String filename) { + return super.hasResource(filename); + } + + @Override + public void setBundleName(String bundleName) { + super.setBundleName(bundleName); + } + + @Override + public void setLoader(OdluxBundleLoader loader) { + super.setLoader(loader); + } + + @Override + public String getBundleName() { + return super.getBundleName(); + } + + @Override + public OdluxBundleLoader getLoader() { + return super.getLoader(); + } + + public MyOdluxBundle() { + super(); + } +} diff --git a/sdnr/wt/odlux/apps/connectApp/src2/main/resources/OSGI-INF/blueprint/blueprint.xml b/sdnr/wt/odlux/apps/connectApp/src2/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 000000000..adc9b777b --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src2/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/sdnr/wt/odlux/apps/connectApp/tsconfig.json b/sdnr/wt/odlux/apps/connectApp/tsconfig.json new file mode 100644 index 000000000..a66b5d828 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/tsconfig.json @@ -0,0 +1,37 @@ +{ + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist", + "sourceMap": true, + "forceConsistentCasingInFileNames": true, + "allowSyntheticDefaultImports": false, + "allowUnreachableCode": false, + "allowUnusedLabels": false, + "noFallthroughCasesInSwitch": true, + "noImplicitAny": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "strictNullChecks": true, + "pretty": true, + "newLine": "LF", + "module": "es2015", + "target": "es2016", + "moduleResolution": "node", + "experimentalDecorators": true, + "jsx": "preserve", + "lib": [ + "dom", + "es2015", + "es2016" + ], + "types": [ + "prop-types", + "react", + "react-dom" + ] + }, + "exclude": [ + "dist", + "node_modules" + ] +} diff --git a/sdnr/wt/odlux/apps/connectApp/webpack.config.js b/sdnr/wt/odlux/apps/connectApp/webpack.config.js new file mode 100644 index 000000000..a70e62976 --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/webpack.config.js @@ -0,0 +1,139 @@ +/** + * Webpack 4 configuration file + * see https://webpack.js.org/configuration/ + * see https://webpack.js.org/configuration/dev-server/ + */ + +"use strict"; + +const path = require("path"); +const webpack = require("webpack"); +const CopyWebpackPlugin = require("copy-webpack-plugin"); +const TerserPlugin = require('terser-webpack-plugin'); + +// const __dirname = (path => path.replace(/^([a-z]\:)/, c => c.toUpperCase()))(process.__dirname()); + +module.exports = (env) => { + const distPath = path.resolve(__dirname, env === "release" ? "." : "../..", "dist"); + const frameworkPath = path.resolve(__dirname, env === "release" ? "../../framework" : "../..", "dist"); + return [{ + name: "App", + + mode: "none", //disable default behavior + + target: "web", + + context: path.resolve(__dirname, "src"), + + entry: { + connectApp: ["./plugin.tsx"] + }, + + devtool: env === "release" ? false : "source-map", + + resolve: { + extensions: [".ts", ".tsx", ".js", ".jsx"] + }, + + output: { + path: distPath, + filename: "[name].js", + library: "[name]", + libraryTarget: "umd2", + chunkFilename: "[name].js" + }, + module: { + rules: [{ + test: /\.tsx?$/, + exclude: /node_modules/, + use: [{ + loader: "babel-loader" + }, { + loader: "ts-loader" + }] + }, { + test: /\.jsx?$/, + exclude: /node_modules/, + use: [{ + loader: "babel-loader" + }] + }] + }, + + optimization: { + noEmitOnErrors: true, + namedModules: env !== "release", + minimize: env === "release", + minimizer: env !== "release" ? [] : [new TerserPlugin({ + terserOptions: { + warnings: false, // false, true, "verbose" + compress: { + drop_console: true, + drop_debugger: true, + } + } + })], + }, + plugins: [ + new webpack.DllReferencePlugin({ + context: path.resolve(__dirname, "../../framework/src"), + manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")), + sourceType: "umd2" + }), + new webpack.DllReferencePlugin({ + context: path.resolve(__dirname, "../../framework/src"), + manifest: require(path.resolve(frameworkPath, "app-manifest.json")), + sourceType: "umd2" + }), + ...(env === "release") ? [ + new webpack.DefinePlugin({ + "process.env": { + NODE_ENV: "'production'", + VERSION: JSON.stringify(require("./package.json").version) + } + }), + ] : [ + new webpack.DefinePlugin({ + "process.env": { + NODE_ENV: "'development'", + VERSION: JSON.stringify(require("./package.json").version) + } + }), + new CopyWebpackPlugin([{ + from: 'index.html', + to: distPath + }]), + ] + ], + + devServer: { + public: "http://localhost:3100", + contentBase: frameworkPath, + + compress: true, + headers: { + "Access-Control-Allow-Origin": "*" + }, + host: "0.0.0.0", + port: 3100, + disableHostCheck: true, + historyApiFallback: true, + inline: true, + hot: false, + quiet: false, + stats: { + colors: true + }, + proxy: { + "/restconf": { + target: "http://localhost:8181", + secure: false + }, + "/database": { + target: "http://localhost:8181", + secure: false + } + } + } + }]; +} -- cgit 1.2.3-korg