9
9
* IBM Corporation - initial API and implementation
10
10
******************************************************************************/
11
11
12
- import React , { Fragment } from 'react'
13
- import PropTypes from 'prop-types'
12
+ import React , { Fragment } from 'react' ;
13
+ import PropTypes from 'prop-types' ;
14
14
import { connect } from 'react-redux' ;
15
- import IconRun from '@carbon/icons-react/es/play--filled/16'
15
+ import queryString from 'query-string' ;
16
+ import IconRun from '@carbon/icons-react/es/play--filled/16' ;
16
17
import IconStop from '@carbon/icons-react/lib/close--outline/16' ;
17
18
import { Button , InlineLoading } from 'carbon-components-react' ;
18
19
import { SocketEvents } from '../../utils/sockets/SocketEvents' ;
@@ -51,6 +52,11 @@ class ActionRunLoad extends React.Component {
51
52
componentDidMount ( ) {
52
53
this . props . socket . on ( SocketEvents . RUNLOAD_STATUS_CHANGED , data => {
53
54
if ( data . projectID === this . props . projectID ) {
55
+
56
+ if ( queryString . parse ( location . search ) . debugsocket ) {
57
+ console . log ( "SocketIO RX: " , data ) ;
58
+ }
59
+
54
60
switch ( data . status ) {
55
61
case 'preparing' : {
56
62
this . setState ( { showModalRunTest : false , loadRunStatus : data , inlineTextLabel : 'Preparing...' } ) ;
@@ -62,17 +68,32 @@ class ActionRunLoad extends React.Component {
62
68
}
63
69
case 'started' : {
64
70
this . setState ( { showModalRunTest : false , loadRunStatus : data , inlineTextLabel : 'Running...' } ) ;
71
+ this . startCountdown ( ) ;
65
72
break ;
66
73
}
67
74
case 'completed' : {
68
75
// after receiving a loadrun completion message, wait a bit, then reset the button back to ready
76
+ this . setState ( { showModalRunTest : false , loadRunStatus : data , inlineTextLabel : 'Completed...' } ) ;
77
+ let nextData = data ;
78
+ nextData . status = 'idle' ;
79
+ setTimeout ( ( ) => this . setState ( { loadRunStatus : nextData } ) , 3000 ) ;
80
+ break ;
81
+ }
82
+ case 'cancelling' : {
83
+ this . setState ( { showModalRunTest : false , loadRunStatus : data , inlineTextLabel : 'Cancelling...' } ) ;
84
+ break ;
85
+ }
86
+ case 'cancelled' : {
87
+ this . setState ( { showModalRunTest : false , loadRunStatus : data , inlineTextLabel : 'Cancelled...' } ) ;
69
88
let nextData = data ;
70
89
nextData . status = 'idle' ;
71
- setTimeout ( ( ) => this . setState ( { loadRunStatus : nextData } ) , 2000 ) ;
90
+ setTimeout ( ( ) => this . setState ( { loadRunStatus : nextData } ) , 2000 ) ;
72
91
break ;
73
92
}
74
93
default : {
75
- this . setState ( { loadRunStatus : data } ) ;
94
+ if ( queryString . parse ( location . search ) . debugsocket ) {
95
+ console . log ( "Ignoring UISocket RX: " , data ) ;
96
+ }
76
97
}
77
98
}
78
99
}
@@ -83,13 +104,13 @@ class ActionRunLoad extends React.Component {
83
104
* Ask API to start a new test
84
105
*/
85
106
handleRunTestDlgStart ( descriptionText ) {
107
+ this . setState ( { showModalRunTest : false , loadRunStatus : { status : 'requesting' } , inlineTextLabel : 'Requesting...' } ) ;
86
108
let instance = this ;
87
109
this . requestRunLoad ( descriptionText ) . then ( function ( result ) {
88
- instance . setState ( { showModalRunTest : false , inlineTextLabel : 'Running...' } ) ;
89
110
switch ( result . status ) {
90
111
case 202 : {
91
112
// success - request to start load accepted;
92
- instance . startCountdown ( ) ;
113
+ instance . setState ( { loadRunStatus : { status : 'requested' } , inlineTextLabel : 'Requested...' } ) ;
93
114
break ;
94
115
}
95
116
case 503 : {
@@ -112,7 +133,7 @@ class ActionRunLoad extends React.Component {
112
133
/**
113
134
* Send a post to the metric/runload api to start a new load test.
114
135
* An optional description parameter can be provided.
115
- * @param {string } desc
136
+ * @param {string } desc
116
137
*/
117
138
// eslint-disable-next-line class-methods-use-this
118
139
async requestRunLoad ( desc ) {
@@ -128,17 +149,16 @@ class ActionRunLoad extends React.Component {
128
149
}
129
150
130
151
async handleCancelLoad ( ) {
131
- this . setState ( { inlineTextLabel : "Cancelling..." } ) ;
132
152
try {
133
153
const response = await fetch ( `${ AppConstants . API_SERVER } /api/v1/projects/${ this . props . projectID } /loadtest/cancel` ,
134
154
{
135
155
method : "POST" ,
136
156
headers : { "Content-Type" : "application/json" }
137
157
} ) ;
138
158
const reply = await response ;
139
- this . setState ( { inlineTextLabel : "Cancelled" } ) ;
159
+ console . error ( "Cancel accepted" )
140
160
} catch ( err ) {
141
- this . setState ( { inlineTextLabel : "Cancel failed" } ) ;
161
+ console . error ( "Cancel failed:" , err ) ;
142
162
}
143
163
}
144
164
@@ -152,7 +172,7 @@ class ActionRunLoad extends React.Component {
152
172
153
173
showStartTestNotificationFail ( err ) {
154
174
this . setState (
155
- { showNotificationRunTestFail : true , notificationError : err } ,
175
+ { showNotificationRunTestFail : true , notificationError : err , loadRunStatus : { status : '' } } ,
156
176
( ) => setTimeout ( ( ) => this . setState ( { showNotificationRunTestFail : false } ) , 5000 )
157
177
) ;
158
178
}
@@ -177,10 +197,10 @@ class ActionRunLoad extends React.Component {
177
197
178
198
render ( ) {
179
199
const { showNotificationRunTestFail, loadRunStatus, inlineTextLabel, timeRemaining } = this . state ;
180
- let loadRunPreparing = loadRunStatus . status === 'preparing' ;
181
- let loadRunStarting = loadRunStatus . status === 'starting ' ;
182
- let loadRunActive = loadRunStatus . status === 'started' ;
183
- let loadRunSuccess = loadRunStatus . status === 'completed' ;
200
+
201
+ let loadRunCompleted = loadRunStatus . status === 'completed ' ;
202
+ const options = [ 'preparing' , 'starting' , 'started' , 'completed' , 'requesting' , 'requested' , 'cancelling' , 'cancelled' ]
203
+ const showBusy = options . includes ( loadRunStatus . status )
184
204
185
205
let inlineTextLabelFormatted = ( timeRemaining !== 0 ) ? `${ inlineTextLabel } ${ timeRemaining } ` : `${ inlineTextLabel } `
186
206
@@ -189,10 +209,10 @@ class ActionRunLoad extends React.Component {
189
209
< RunTestNotificationFail notification = { showNotificationRunTestFail } titleMessage = { 'Request Failed!' } notificationError = { this . state . notificationError } />
190
210
< div className = "ActionRunLoad" >
191
211
{
192
- ( loadRunActive || loadRunSuccess || loadRunPreparing || loadRunStarting ) ? (
212
+ ( showBusy ) ? (
193
213
< Fragment >
194
214
< div style = { { display : 'inline-block' , verticalAlign : "middle" } } >
195
- < InlineLoading style = { { marginLeft : '1rem' } } description = { inlineTextLabelFormatted } success = { loadRunSuccess } />
215
+ < InlineLoading style = { { marginLeft : '1rem' } } description = { inlineTextLabelFormatted } success = { loadRunCompleted } />
196
216
</ div >
197
217
< div style = { { display : 'inline-block' , verticalAlign : "middle" , float : 'right' } } >
198
218
< Button onClick = { ( ) => this . handleCancelLoad ( ) } style = { { verticalAlign : "middle" , padding : 0 , margin : 0 } } renderIcon = { IconStop } kind = "ghost" small iconDescription = "Stop the load run" > </ Button >
@@ -228,7 +248,7 @@ const ActionRunLoadWithSocket = props => (
228
248
ActionRunLoad . propTypes = {
229
249
projectID : PropTypes . string . isRequired ,
230
250
small : PropTypes . bool , // show small button
231
- kind : PropTypes . string // button kind eg: 'ghost'
251
+ kind : PropTypes . string // button kind eg: 'ghost'
232
252
}
233
253
234
254
0 commit comments