blob: 6822f3ff3042fa1e83801ea3be878ef5bc1ae498 [file] [log] [blame]
sebdet4946e5b2019-07-10 12:32:36 +02001/*-
2 * ============LICENSE_START=======================================================
3 * ONAP CLAMP
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
6 * reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
21 *
22 */
23
24import React from 'react'
25import Button from 'react-bootstrap/Button';
26import Modal from 'react-bootstrap/Modal';
sebdet4946e5b2019-07-10 12:32:36 +020027import './OperationalPolicy.css'
28import styled from 'styled-components';
29
30const ModalStyled = styled(Modal)`
31 background-color: transparent;
32`
33
34export default class OperationalPolicyModal extends React.Component {
35
sebdet493c3832019-07-15 17:26:18 +020036 state = {
37 show: true,
38 loopCache: this.props.loopCache,
39 };
40
41 allPolicies = [];
42 policyIds = [];
43
sebdet4946e5b2019-07-10 12:32:36 +020044 constructor(props, context) {
45 super(props, context);
46
sebdet4946e5b2019-07-10 12:32:36 +020047 this.handleClose = this.handleClose.bind(this);
48 this.initPolicySelect = this.initPolicySelect.bind(this);
sebdet4946e5b2019-07-10 12:32:36 +020049 this.initPolicySelect();
sebdet4946e5b2019-07-10 12:32:36 +020050 }
51
52 handleClose() {
53 this.setState({ show: false });
sebdet493c3832019-07-15 17:26:18 +020054 this.props.history.push('/')
sebdet4946e5b2019-07-10 12:32:36 +020055 }
56
57 initPolicySelect() {
58 if (this.allPolicies['operational_policy'] === undefined || this.allPolicies['operational_policy'] === null) {
sebdet493c3832019-07-15 17:26:18 +020059 this.allPolicies = this.state.loopCache.getOperationalPolicyConfigurationJson();
sebdet4946e5b2019-07-10 12:32:36 +020060 }
61 // Provision all policies ID first
xuegaof248df62019-07-15 15:16:18 +020062 if (this.policyIds.length === 0 && this.allPolicies['operational_policy'] !== undefined) {
sebdet4946e5b2019-07-10 12:32:36 +020063
64 for (let i = 0; i < this.allPolicies['operational_policy']['policies'].length; i++) {
65 this.policyIds.push(this.allPolicies['operational_policy']['policies'][i]['id']);
66 }
67 }
68 }
69
70 renderPolicyIdSelect() {
71 return (
72 <select type="text" id="trigger_policy" name="trigger_policy"
73 className="form-control">
74 <option value="">-- choose an option --</option>
75 {this.policyIds.map(policyId => (<option key={policyId}>{policyId}</option>))}
76 </select>
77 );
78 }
79
80 serializeElement(element) {
81 var o = {};
82 element.serializeArray().forEach(function () {
83 if (o[this.name]) {
84 if (!o[this.name].push) {
85 o[this.name] = [o[this.name]];
86 }
87 o[this.name].push(this.value || '');
88 } else {
89 o[this.name] = this.value || '';
90 }
91 });
92 return o;
93 }
94
95 // When we change the name of a policy
sebdet493c3832019-07-15 17:26:18 +020096 isDuplicatedId(event) {
sebdet4946e5b2019-07-10 12:32:36 +020097 // update policy id structure
98 var formNum = document.getElementById(event.target).closest('.formId').attr('id').substring(6);
99 var policyId = document.getElementById(event.target).val();
100 if (this.policyIds.includes(policyId)) {
101 console.log("Duplicated ID, cannot proceed");
102 return true;
103 } else {
104 this.duplicated = false;
105 this.policyIds.splice(this.policyIds.indexOf(document.getElementById("#formId" + formNum + " #id").val()), 1);
106 this.policyIds.push(document.getElementById(event.target).val());
107 // Update the tab now
108 document.getElementById("#go_properties_tab" + formNum).text(document.getElementById(event.target).val());
109 }
110 }
111
112 configureComponents() {
sebdet493c3832019-07-15 17:26:18 +0200113 console.log("Load properties to op policy");
114 // Set the header
115 document.getElementsByClassName('form-control').forEach(function () {
116 this.val(this.allPolicies['operational_policy']['controlLoop'][this.id]);
117 });
118 // Set the sub-policies
119 this.allPolicies['operational_policy']['policies'].forEach(function (opPolicyElemIndex, opPolicyElemValue) {
sebdet4946e5b2019-07-10 12:32:36 +0200120
sebdet493c3832019-07-15 17:26:18 +0200121 /* var formNum = add_one_more();
122 forEach(document.getElementsByClassName('policyProperties').find('.form-control'), function(opPolicyPropIndex, opPolicyPropValue) {
123
124 $("#formId" + formNum + " .policyProperties").find("#" + opPolicyPropValue.id).val(
125 allPolicies['operational_policy']['policies'][opPolicyElemIndex][opPolicyPropValue.id]);
126 });
127
128 // Initial TargetResourceId options
129 initTargetResourceIdOptions(allPolicies['operational_policy']['policies'][opPolicyElemIndex]['target']['type'], formNum);
130 $.each($('.policyTarget').find('.form-control'), function(opPolicyTargetPropIndex, opPolicyTargetPropValue) {
131
132 $("#formId" + formNum + " .policyTarget").find("#" + opPolicyTargetPropValue.id).val(
133 allPolicies['operational_policy']['policies'][opPolicyElemIndex]['target'][opPolicyTargetPropValue.id]);
134 });
135
136 // update the current tab label
137 $("#go_properties_tab" + formNum).text(
138 allPolicies['operational_policy']['policies'][opPolicyElemIndex]['id']);
139 // Check if there is a guard set for it
140 $.each(allPolicies['guard_policies'], function(guardElemId, guardElemValue) {
141
142 if (guardElemValue.recipe === $($("#formId" + formNum + " #recipe")[0]).val()) {
143 // Found one, set all guard prop
144 $.each($('.guardProperties').find('.form-control'), function(guardPropElemIndex,
145 guardPropElemValue) {
146
147 guardElemValue['id'] = guardElemId;
148 $("#formId" + formNum + " .guardProperties").find("#" + guardPropElemValue.id).val(
149 guardElemValue[guardPropElemValue.id]);
150 });
151 iniGuardPolicyType(guardElemId, formNum);
152 // And finally enable the flag
153 $("#formId" + formNum + " #enableGuardPolicy").prop("checked", true);
154 }
155 });*/
156 });
157 }
sebdet4946e5b2019-07-10 12:32:36 +0200158
159 render() {
160 return (
161 <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose}>
162 <Modal.Header closeButton>
163 <Modal.Title>Operational policies</Modal.Title>
164 </Modal.Header>
165 <Modal.Body>
166 <div attribute-test="policywindowproperties" id="configure-widgets"
167 className="disabled-block-container">
168 <div attribute-test="policywindowpropertiesb" className="modal-body row">
169 <div className="panel panel-default col-sm-10 policyPanel">
170 <form id="operationalPolicyHeaderForm" className="form-horizontal">
171 <div className="form-group clearfix">
172 <label className="col-sm-2">Parent policy</label>
173 <div className="col-sm-3" style={{ padding: '0px' }}>
174 {this.renderPolicyIdSelect()}
175 </div>
176
177 <label htmlFor="timeout" className="col-sm-3"
178 style={{ paddingLeft: '5px', paddingRight: '10px' }}>Overall
179 Time Limit</label>
180 <div className="col-sm-2" style={{ paddingLeft: '0px' }}>
181 <input type="text" ng-pattern="/^[0-9]*$/" ng-model="number"
182 className="form-control" id="timeout" name="timeout" />
183 </div>
184
185 <label htmlFor="abatement" className="col-sm-2">Abatement</label>
186 <div className="col-sm-2" style={{ paddingLeft: '0px' }}>
187 <select className="form-control" id="abatement" name="abatement">
188 <option value="false">False</option>
189 <option value="true">True</option>
190 </select>
191 </div>
192 </div>
193 <div className="form-group clearfix row">
194 <label className="col-sm-4 control-label" htmlFor="clname">ControlLoopName</label>
195 <div className="col-sm-8">
196 <input type="text" className="form-control" name="controlLoopName"
sebdet493c3832019-07-15 17:26:18 +0200197 readOnly="readonly" id="clname" value={this.state.loopCache.getLoopName()} />
sebdet4946e5b2019-07-10 12:32:36 +0200198 </div>
199 </div>
200 </form>
201 <div className="panel-heading" style={{ backgroundColor: 'white' }}>
202 <ul id="nav_Tabs" className="nav nav-tabs">
203 <li>
204 <a id="add_one_more" href="#desc_tab">
205 <span
206 className="glyphicon glyphicon-plus" aria-hidden="true">
207 </span>
208 </a>
209 </li>
210 </ul>
211 </div>
212 <div className="panel-body">
213 <div className="tab-content">
214 <div id="properties_tab" className="tab-pane fade in active"></div>
215 </div>
216 </div>
217 </div>
218
219 <span id="formSpan" style={{ display: 'none' }}>
220 <form className="policyProperties" className="form-horizontal"
221 style={{ border: '2px dotted gray' }}
222 title="Operational Policy Properties">
223 <div className="form-group clearfix">
224 <label className="col-sm-4 control-label" htmlFor="id">ID</label>
225 <div className="col-sm-8">
226 <input type="text" className="form-control" name="id" id="id"
sebdet493c3832019-07-15 17:26:18 +0200227 onKeyUp="updateTabLabel($event)" />
sebdet4946e5b2019-07-10 12:32:36 +0200228 <span >ID must be unique</span>
229 </div>
230 </div>
231 <div className="form-group clearfix">
232 <label className="col-sm-4 control-label" htmlFor="recipe">Recipe</label>
233 <div className="col-sm-8">
234 <select className="form-control" name="recipe" id="recipe"
235 ng-model="recipe" ng-click="updateGuardRecipe($event)">
236 <option value="">-- choose an option --</option>
237 <option value="Restart">Restart</option>
238 <option value="Rebuild">Rebuild</option>
239 <option value="Migrate">Migrate</option>
240 <option value="Health-Check">Health-Check</option>
241 <option value="ModifyConfig">ModifyConfig</option>
242 <option value="VF Module Create">VF Module Create</option>
243 <option value="VF Module Delete">VF Module Delete</option>
244 <option value="Reroute">Reroute</option>
245 </select>
246 </div>
247 </div>
248 <div className="form-group clearfix">
249 <label htmlFor="retry" className="col-sm-4 control-label"> Retry</label>
250 <div className="col-sm-8">
251 <input type="text" maxLength="5" className="form-control" id="retry"
252 ng-pattern="/^[0-9]*$/" ng-model="number" name="retry">
253 </input>
254 </div>
255 </div>
256 <div className="form-group clearfix">
257 <label htmlFor="timeout" className="col-sm-4 control-label">
258 Timeout</label>
259 <div className="col-sm-8">
260 <input type="text" maxLength="5" className="form-control"
261 id="timeout" ng-pattern="/^[0-9]*$/" ng-model="number"
262 name="timeout"></input>
263 </div>
264 </div>
265
266 <div className="form-group clearfix">
267 <label htmlFor="actor" className="col-sm-4 control-label"> Actor</label>
268 <div className="col-sm-8">
269 <select className="form-control" id="actor" name="actor" ng-click="updateGuardActor($event)" ng-model="actor">
270 <option value="">-- choose an option --</option>
271 <option value="APPC">APPC</option>
272 <option value="SO">SO</option>
273 <option value="VFC">VFC</option>
274 <option value="SDNC">SDNC</option>°
275 <option value="SDNR">SDNR</option>°
276 </select>
277 </div>
278
279 <label htmlFor="payload" className="col-sm-4 control-label">
280 Payload (YAML)</label>
281 <div className="col-sm-8">
282 <textarea className="form-control" id="payload" name="payload"></textarea>
283 </div>
284 </div>
285 <div className="form-group clearfix">
286 <label htmlFor="success" className="col-sm-4 control-label">When
287 Success</label>
288 <div className="col-sm-8">
289 <select className="form-control" id="success" name="success"
290 ng-model="null_dump"
291 ng-options="policy for policy in policy_ids track by policy">
292 <option value="">-- choose an option --</option>
293 </select>
294 </div>
295 </div>
296 <div className="form-group clearfix">
297 <label htmlFor="failure" className="col-sm-4 control-label">When
298 Failure</label>
299 <div className="col-sm-8">
300 <select className="form-control" id="failure" name="failure"
301 ng-model="null_dump"
302 ng-options="policy for policy in policy_ids track by policy">
303 <option value="">-- choose an option --</option>
304 </select>
305
306 </div>
307 </div>
308 <div className="form-group clearfix">
309 <label htmlFor="failure_timeout" className="col-sm-4 control-label">When
310 Failure Timeout</label>
311 <div className="col-sm-8">
312 <select className="form-control" id="failure_timeout"
313 name="failure_timeout" ng-model="null_dump"
314 ng-options="policy for policy in policy_ids track by policy">
315 <option value="">-- choose an option --</option>
316 </select>
317 </div>
318 </div>
319 <div className="form-group clearfix">
320 <label htmlFor="failure_retries" className="col-sm-4 control-label">When
321 Failure Retries</label>
322 <div className="col-sm-8">
323 <select className="form-control" id="failure_retries"
324 name="failure_retries" ng-model="null_dump"
325 ng-options="policy for policy in policy_ids track by policy">
326 <option value="">-- choose an option --</option>
327 </select>
328 </div>
329 </div>
330 <div className="form-group clearfix">
331 <label htmlFor="failure_exception" className="col-sm-4 control-label">When
332 Failure Exception</label>
333 <div className="col-sm-8">
334 <select className="form-control" id="failure_exception"
335 name="failure_exception" ng-model="null_dump"
336 ng-options="policy for policy in policy_ids track by policy">
337 <option value="">-- choose an option --</option>
338 </select>
339 </div>
340 </div>
341 <div className="form-group clearfix">
342 <label htmlFor="failure_guard" className="col-sm-4 control-label">When
343 Failure Guard</label>
344 <div className="col-sm-8">
345 <select className="form-control" id="failure_guard"
346 name="failure_guard" ng-model="null_dump"
347 ng-options="policy for policy in policy_ids track by policy">
348 <option value="">-- choose an option --</option>
349 </select>
350 </div>
351 </div>
352 </form>
353 <form className="policyTarget" className="form-horizontal"
354 title="Operational Policy Target" style={{ border: '2px dotted gray' }}>
355 <div className="form-group clearfix">
356 <label htmlFor="type" className="col-sm-4 control-label"> Target
357 Type</label>
358 <div className="col-sm-8">
359 <select className="form-control" name="type" id="type"
360 ng-click="initTargetResourceId($event)" ng-model="type">
361 <option value="">-- choose an option --</option>
362 <option value="VFMODULE">VFMODULE</option>
363 <option value="VM">VM</option>
364 <option value="VNF">VNF</option>
365 </select>
366 </div>
367 </div>
368 <div className="form-group clearfix">
369 <label htmlFor="resourceID" className="col-sm-4 control-label">
370 Target ResourceId</label>
371 <div className="col-sm-8">
372 <select className="form-control" name="resourceID" id="resourceID"
373 ng-click="changeTargetResourceId($event)"
374 ng-model="resourceId">
375 <option value="">-- choose an option --</option>
376 </select>
377 </div>
378 </div>
379 <div id="metadata">
380 <div className="form-group clearfix">
381 <label htmlFor="modelInvariantId" className="col-sm-4 control-label">
382 Model Invariant Id</label>
383 <div className="col-sm-8">
384 <input className="form-control" name="modelInvariantId"
385 id="modelInvariantId" readOnly />
386 </div>
387 </div>
388 <div className="form-group clearfix">
389 <label htmlFor="modelVersionId" className="col-sm-4 control-label">
390 Model Version Id</label>
391 <div className="col-sm-8">
392 <input className="form-control" name="modelVersionId"
393 id="modelVersionId" readOnly />
394 </div>
395 </div>
396 <div className="form-group clearfix">
397 <label htmlFor="modelName" className="col-sm-4 control-label">
398 Model Name</label>
399 <div className="col-sm-8">
400 <input className="form-control" name="modelName" id="modelName"
401 readOnly />
402 </div>
403 </div>
404 <div className="form-group clearfix">
405 <label htmlFor="modelVersion" className="col-sm-4 control-label">
406 Model Version</label>
407 <div className="col-sm-8">
408 <input className="form-control" name="modelVersion"
409 id="modelVersion" readOnly />
410 </div>
411 </div>
412 <div className="form-group clearfix">
413 <label htmlFor="modelCustomizationId" className="col-sm-4 control-label">
414 Model Customization Id</label>
415 <div className="col-sm-8">
416 <input className="form-control" name="modelCustomizationId"
417 id="modelCustomizationId" readOnly />
418 </div>
419 </div>
420 </div>
421 </form>
422 <div className="form-group clearfix">
423 <label htmlFor="enableGuardPolicy" className="col-sm-4 control-label">
424 Enable Guard Policy</label>
425 <div className="col-sm-8">
426 <input type="checkbox" className="form-control"
427 name="enableGuardPolicy" id="enableGuardPolicy" />
428 </div>
429
430 <div className="col-sm-8">
431 <label htmlFor="guardPolicyType" className="col-sm-4 control-label">
432 Guard Policy Type</label> <select className="form-control"
433 name="guardPolicyType" id="guardPolicyType"
434 ng-click="changeGuardPolicyType()" ng-model="guardType">
435 <option value="GUARD_MIN_MAX">MinMax</option>
436 <option value="GUARD_YAML">FrequencyLimiter</option>
437 </select>
438 </div>
439 </div>
440 <form className="guardProperties" className="form-horizontal"
441 title="Guard policy associated" style={{ border: '2px dotted gray' }}>
442
443 <div className="form-group clearfix withnote">
444 <label className="col-sm-4 control-label" htmlFor="id">Guard Policy ID</label>
445 <div className="col-sm-8">
446 <input type="text" className="form-control" name="id" id="id" ng-blur="changeGuardId()" ng-model="id" />
447 </div>
448 </div>
449 <div>
450 <label className="form-group note">Note: Prefix will be added to Guard Policy ID automatically based on Guard Policy Type</label>
451 </div>
452 <div className="form-group clearfix">
453 <label className="col-sm-4 control-label" htmlFor="recipe">Recipe</label>
454 <div className="col-sm-8">
455 <input type="text" className="form-control" name="recipe"
456 readOnly="readonly" id="recipe" />
457 </div>
458 </div>
459 <div className="form-group clearfix">
460 <label className="col-sm-4 control-label" htmlFor="clname">ControlLoopName</label>
461 <div className="col-sm-8">
462 <input type="text" className="form-control" name="clname"
463 readOnly="readonly" id="clname" ng-model="clname" />
464 </div>
465 </div>
466 <div className="form-group clearfix">
467 <label htmlFor="actor" className="col-sm-4 control-label">Actor</label>
468 <div className="col-sm-8">
469 <input type="text" className="form-control" name="actor"
470 readOnly="readonly" id="actor" />
471 </div>
472 </div>
473 <div className="form-group clearfix">
474
475 <label htmlFor="targets" className="col-sm-4 control-label">Guard
476 targets</label>
477 <div className="col-sm-8">
478 <input className="form-control" name="targets" id="targets" />
479 </div>
480 </div>
481
482 <div className="form-group clearfix" id="minMaxGuardPolicyDiv">
483 <label htmlFor="min" className="col-sm-4 control-label"> Min
484 Guard</label>
485 <div className="col-sm-8">
486 <input className="form-control" name="min" id="min" />
487 </div>
488 <label htmlFor="max" className="col-sm-4 control-label"> Max
489 Guard</label>
490 <div className="col-sm-8">
491 <input className="form-control" name="max" id="max" />
492 </div>
493 </div>
494 <div className="form-group clearfix"
495 id="frequencyLimiterGuardPolicyDiv" style={{ display: 'none' }}>
496 <label htmlFor="limit" className="col-sm-4 control-label">Limit</label>
497 <div className="col-sm-8">
498 <input className="form-control" name="limit" id="limit" />
499 </div>
500 <label htmlFor="timeUnits" className="col-sm-4 control-label">Time Units</label>
501 <div className="col-sm-8">
502 <select className="form-control" name="timeUnits"
503 id="timeUnits">
504 <option value=""></option>
505 <option value="minute">minute</option>
506 <option value="hour">hour</option>
507 <option value="day">day</option>
508 <option value="week">week</option>
509 <option value="month">month</option>
510 <option value="year">year</option>
511 </select>
512 </div>
513 <label htmlFor="timeWindow" className="col-sm-4 control-label">Time Window</label>
514 <div className="col-sm-8">
515 <input className="form-control" name="timeWindow" id="timeWindow" />
516 </div>
517 </div>
518 <div className="form-group clearfix">
519 <label htmlFor="guardActiveStart" className="col-sm-4 control-label">
520 Guard Active Start</label>
521 <div className="col-sm-8">
522 <input className="form-control" name="guardActiveStart"
523 id="guardActiveStart" value="00:00:00Z" />
524 </div>
525 <label htmlFor="guardActiveEnd" className="col-sm-4 control-label">
526 Guard Active End</label>
527 <div className="col-sm-8">
528 <input className="form-control" name="guardActiveEnd"
529 id="guardActiveEnd" value="00:00:01Z" />
530 </div>
531 </div>
532
533 </form>
534
535 </span>
536 </div>
537 </div>
xuegaof248df62019-07-15 15:16:18 +0200538
sebdet4946e5b2019-07-10 12:32:36 +0200539 </Modal.Body>
540 <Modal.Footer>
541 <Button variant="secondary" onClick={this.handleClose}>
542 Close
543 </Button>
544 <Button variant="primary" onClick={this.handleClose}>
545 Save Changes
546 </Button>
547 </Modal.Footer>
548 </ModalStyled>
549
550 );
551 }
sebdet493c3832019-07-15 17:26:18 +0200552}