3 * Copyright 2016 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 import React from 'react';
19 import RecordViewStore from '../recordViewer/recordViewStore.js';
20 import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx';
21 import Button from 'widgets/button/rw.button.js';
22 import Utils from 'utils/utils.js';
23 import UpTime from 'widgets/uptime/uptime.jsx';
24 import './nsrScalingGroups.scss';
26 class NsrScalingGroups extends React.Component {
32 handleExecuteClick = (nsr_id, scaling_group_id, max_instance_count, event) => {
34 if (this.getInstancesForScalingGroup(scaling_group_id) == max_instance_count) {
35 self.props.flux.actions.global.showNotification("Maximum allowed scaling instances created for this group. Cannot create any more");
38 RecordViewStore.createScalingGroupInstance({
40 scaling_group_id: scaling_group_id
44 handleDeleteClick = (nsr_id, scaling_group_id, scaling_instance_index, event) => {
45 RecordViewStore.deleteScalingGroupInstance({
47 scaling_group_id: scaling_group_id,
48 scaling_instance_index: scaling_instance_index
52 createScalingGroupTable = (scalingGroupDesriptorName) => {
55 this.props.data['scaling-group-record'] && this.props.data['scaling-group-record'].map((sgr, sgri) => {
57 sgr['instance'] ? sgr['instance'].map((sgrInstance, sgrInstanceIndex) => {
58 let id = sgrInstance['instance-id'];
59 let sgrName = sgr['scaling-group-name-ref'];
61 if (sgrName == scalingGroupDesriptorName) {
63 <tr key={sgrInstanceIndex}>
64 <td>{sgrInstanceIndex + 1}</td>
66 <td><UpTime initialTime={sgrInstance['create-time']} run={true} /></td>
67 <td>{sgrInstance['op-status']}</td>
68 <td>{sgrInstance['config-status']}</td>
70 {sgrInstance['is-default'] == 'false' ? <a onClick={this.handleDeleteClick.bind(this, this.props.data.id, sgrName, id)} title="Delete">
71 <span className="oi" data-glyph="trash" aria-hidden="true"></span>
79 <td colSpan="5" style={{textAlign: 'center'}}>No network services scaled in this group</td>
91 <table className="scalingGroupsInstancesTable">
94 <th style={{width: '6%'}}></th>
95 <th style={{width: '12%'}}>ID</th>
96 <th style={{width: '24%'}}>Uptime</th>
97 <th style={{width: '25%'}}>Status</th>
98 <th style={{width: '25%'}}>Config-Status</th>
99 <th style={{width: '7%'}}> </th>
107 getInstancesForScalingGroup = (scalingGroupDesriptorName) => {
109 this.props.data['scaling-group-record'] && this.props.data['scaling-group-record'].map((sgr, sgri) => {
110 sgr['instance'] && sgr['instance'].map((sgrInstance, sgrInstanceIndex) => {
111 if (sgr['scaling-group-name-ref'] == scalingGroupDesriptorName) {
121 let scalingGroups = [];
123 this.props.data['scaling-group-descriptor'] && this.props.data['scaling-group-descriptor'].map((sgd) => {
128 <span>{sgd['max-instance-count']}</span>
132 sgd['vnfd-member'] && sgd['vnfd-member'].map((vnf) => {
133 let instanceCount = vnf['count'];
135 <span>{vnf['short-name']} {instanceCount > 1 ? '(' + instanceCount + ')': ''}</span>
139 sgvnfs = Utils.arrayIntersperse(sgvnfs, ', ');
141 let sgInstanceTable = this.createScalingGroupTable(sgd.name);
143 let sgCreateInstanceButton = <Button label='Create Scaling Group Instance' className="dark" isDisabled={this.getInstancesForScalingGroup(sgd.name) == sgd["max-instance-count"]} isLoading={false} onClick={this.handleExecuteClick.bind(this, this.props.data.id, sgd.name, sgd['max-instance-count'])} />
147 <div className='launchpadCard_title' style={{textAlign:'right'}}><span style={{float:'left'}}>{sgd.name}</span></div>
148 <div className='vnfsList'><span className='vnfsLabel'>VNFS: </span><span>{sgvnfs}</span></div>
149 <div className='scalingGroupsInstancesTableWrapper'>
152 {sgCreateInstanceButton} {sgMaxCount}
155 scalingGroups.push(scalingGroup);
159 <div className='nsScalingGroups'>
169 export default SkyquakeComponent(NsrScalingGroups);