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