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