/* * * Copyright 2016 RIFT.IO Inc * * 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. * */ import React from 'react'; import {Tab, Tabs, TabList, TabPanel} from 'react-tabs'; import DashboardCard from 'widgets/dashboard_card/dashboard_card.jsx'; import MonitoringParamsCarousel from '../monitoring_params/monitoringParamsCarousel.jsx'; import VnfrCard from '../vnfr/vnfrCard.jsx'; import {LaunchpadCard, LpCardNfviMetrics, EpaParams, NsrPrimitiveJobList} from '../launchpad_card/launchpadCard.jsx'; import VnfrConfigPrimitives from '../launchpad_card/vnfrConfigPrimitives.jsx'; import NsrConfigPrimitives from '../launchpad_card/nsrConfigPrimitives.jsx'; import NsrScalingGroups from '../launchpad_card/nsrScalingGroups.jsx'; import LoadingIndicator from 'widgets/loading-indicator/loadingIndicator.jsx'; import NfviMetricBars from 'widgets/nfvi-metric-bars/nfviMetricBars.jsx'; import ParseMP from '../monitoring_params/monitoringParamComponents.js'; import PlacementGroupsInfo from './placementGroupsInfo.jsx'; import JobListCard from '../launchpad_card/jobListCard.jsx'; import NSVirtualLinks from '../virtual_links/nsVirtualLinks.jsx'; import LaunchpadFleetStore from '../launchpadFleetStore.js'; import Prism from 'prismjs'; import 'prismjs/themes/prism.css'; import {SkyquakeRBAC, isRBACValid} from 'widgets/skyquake_rbac/skyquakeRBAC.jsx'; import ROLES from 'utils/roleConstants.js'; const PROJECT_ROLES = ROLES.PROJECT; export default class RecordCard extends React.Component { constructor(props) { super(props) } handleSelect = (index, last) => { // console.log('Selected tab is', index, 'last index is', last); } openConsole = (url, event) => { event.preventDefault(); LaunchpadFleetStore.getVDUConsoleLink(url); } render(){ let self = this; let html; let content; let card; let cardData = {}; let components = []; let configPrimitivesProps = {}; let displayConfigPrimitives = false; let configPrimitiveComponent = null; let scalingGroupsProps = {}; let displayScalingGroups = false; let scalingGroupComponent = null; let consoleUrlsComponent = null; let consoleUrlsList = []; let displayNSVirtualLinks = false; let nsVirtualLinksProps = {}; let nsVirtualLinksComponent = null; let displayVolumesTab = false; let volumesHTML = []; let tabList = []; let tabPanels = []; let notice = null; let hasAccess = isRBACValid(this.context.userProfile, [PROJECT_ROLES.LCM_ADMIN]); switch(this.props.type) { case 'vnfr' : cardData = this.props.data[0]; // Disabling config primitives for VNF configPrimitivesProps = [cardData]; displayConfigPrimitives = cardData['service-primitives-present']; if (displayConfigPrimitives) { configPrimitiveComponent = (
{/* */}
JOB LIST
{ //Sort for recent on top this.props.jobData .sort(function(a,b){ return parseInt(b['job-id']) - parseInt(a['job-id']); }) .map(function(job){ //Return only vnfr configs if(job["triggered-by"] == 'vnf-primitive') { return job.vnfr.map(function(v){ //That match the currently selected job id if(v.id == cardData.id) { return v.primitive.map(function(p, i) { return }) } }) } })}
); } if (cardData['vdur']) { cardData['vdur'].map((vdur, index) => { let consoleLink = vdur['console-url'] ? 'Obtain Token And Open VM Console' : 'None'; consoleUrlsList.push(
  • {vdur['name'] + '-' + vdur.id.substr(0,4)}

    {consoleLink} *
  • ) notice =
  • * If a separate browser window does not open, please check if the popup was blocked and allow it.
  • if(vdur.hasOwnProperty('volumes') && (vdur.volumes.length > 0)) { displayVolumesTab = true; vdur.volumes.map((volume, vi) => { // let html = Prism.highlight(JSON.stringify(volume), Prism.languages.javascript, 'javascript'); // volumesHTML.push( //
                    //       
                    //     
    function buildProperties(obj) { let p = []; _.forEach(obj, function(v, k) { p.push(
    {k}
    {v.constructor.name != 'Object' ? v : buildProperties(v)}
    ) }); return p; } volumesHTML.push(
    VOLUME
    { buildProperties(volume) }
    ) }) } }); consoleUrlsComponent = (
    ); } components = ParseMP.call(this, cardData["monitoring-param"], "vnfr-id"); break; case 'nsr' : cardData = this.props.data.nsrs[0]; configPrimitivesProps = cardData; scalingGroupsProps = cardData; displayConfigPrimitives = cardData['service-primitive']; displayScalingGroups = cardData['scaling-group-descriptor'] ? true : false; let sortedJobs = this.props.jobData.sort(function(a,b){ return parseInt(b['job-id']) - parseInt(a['job-id']); }); if (displayConfigPrimitives) { configPrimitiveComponent = (
    JOB LIST
    {sortedJobs.map(function(job, i){ if(job["triggered-by"] == 'ns-primitive') { return } }) .concat(sortedJobs.map(function(job) { if(!job.hasOwnProperty('job-name') && (job["triggered-by"] == 'ns-primitive')) { return job.vnfr.map(function(v, h){ //That match the currently selected job id if(v.id == cardData.id) { return v.primitive.map(function(p, i) { return }) } }) } })) }
    ); } if (displayScalingGroups) { scalingGroupComponent = (
    ); } // Virtual Links tab content displayNSVirtualLinks = true; nsVirtualLinksProps = cardData; if (displayNSVirtualLinks) { nsVirtualLinksComponent = (
    ); }; components = ParseMP.call(this, cardData["monitoring-param"], "vnfr-id"); break; } let mgmt_interface = cardData["dashboard-url"]; let mgmtHTML; let metricsAndParams = []; let nfviMetrics = ; metricsAndParams.push(
    {components.map(function(c, k) { return
    {c.title}{c.component}
    })}
    ) metricsAndParams.push((
    { nfviMetrics }
    )) if(mgmt_interface) { mgmtHTML = Open Application Dashboard; } if(this.props.isLoading) { html = } else { let glyphValue = (this.props.mmmrecordDetailsToggleValue) ? "chevron-left" : "chevron-right"; if (this.props.type == 'nsr') { tabList.push( NS Data ) } else if (this.props.type == 'vnfr') { tabList.push( VNF Data ) } tabPanels.push(
    MONITORING PARAMETERS {mgmtHTML}
    {metricsAndParams}
    ) if (this.props.type == 'nsr') { if (scalingGroupComponent) { tabList.push( Scaling Groups ); tabPanels.push(
    {scalingGroupComponent}
    ); } if(cardData.hasOwnProperty('vnfd-placement-group-maps') || cardData.hasOwnProperty('nsd-placement-group-maps')) { tabList.push( Placement ); tabPanels.push(
    ); } } if (configPrimitiveComponent) { let primitivesTabTitle = ''; if (this.props.type == 'nsr') { primitivesTabTitle = 'Service Primitive'; } else if (this.props.type == 'vnfr') { primitivesTabTitle = 'Service Primitive' } tabList.push( {primitivesTabTitle} ); tabPanels.push(
    {configPrimitiveComponent}
    ) } if (nsVirtualLinksComponent) { let nsVirtualLinksTabTitle = 'Virtual Links'; tabList.push( {nsVirtualLinksTabTitle} ); tabPanels.push(
    {nsVirtualLinksComponent}
    ); } if (consoleUrlsComponent) { let consoleUrlsTabTitle = ''; consoleUrlsTabTitle = 'VDU Console Links'; tabList.push( {consoleUrlsTabTitle} ); tabPanels.push(
    {consoleUrlsComponent}
    ) } if (displayVolumesTab) { tabList.push( Volumes ); tabPanels.push( {volumesHTML}
    ) } html = ( {tabList} {tabPanels} ); } return html; } } RecordCard.defaultProps = { type: "default", data: {}, isLoading: true, jobData: [] } RecordCard.contextTypes = { router: React.PropTypes.object, userProfile: React.PropTypes.object };