2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
24 import React from 'react'
25 import Button from 'react-bootstrap/Button';
26 import Modal from 'react-bootstrap/Modal';
27 import { LOOP_CACHE } from '../../../api/LoopCache'
28 import './OperationalPolicy.css'
29 import styled from 'styled-components';
31 const ModalStyled = styled(Modal)`
32 background-color: transparent;
35 export default class OperationalPolicyModal extends React.Component {
37 constructor(props, context) {
38 super(props, context);
40 this.handleClose = this.handleClose.bind(this);
41 this.initPolicySelect = this.initPolicySelect.bind(this);
43 this.allPolicies = [];
46 this.initPolicySelect();
55 this.setState({ show: false });
59 if (this.allPolicies['operational_policy'] === undefined || this.allPolicies['operational_policy'] === null) {
60 this.allPolicies = LOOP_CACHE.getOperationalPolicyProperty();
62 // Provision all policies ID first
63 if (this.policyIds.length == 0 && this.allPolicies['operational_policy'] != undefined) {
65 for (let i = 0; i < this.allPolicies['operational_policy']['policies'].length; i++) {
66 this.policyIds.push(this.allPolicies['operational_policy']['policies'][i]['id']);
71 renderPolicyIdSelect() {
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>))}
81 serializeElement(element) {
83 element.serializeArray().forEach(function () {
85 if (!o[this.name].push) {
86 o[this.name] = [o[this.name]];
88 o[this.name].push(this.value || '');
90 o[this.name] = this.value || '';
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");
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());
113 configureComponents() {
114 console.log("Load properties to op policy");
116 document.getElementsByClassName('form-control').forEach(function() {
117 this.val(this.allPolicies['operational_policy']['controlLoop'][this.id]);
119 // Set the sub-policies
120 this.allPolicies['operational_policy']['policies'].forEach(function(opPolicyElemIndex, opPolicyElemValue) {
122 /* var formNum = add_one_more();
123 forEach(document.getElementsByClassName('policyProperties').find('.form-control'), function(opPolicyPropIndex, opPolicyPropValue) {
125 $("#formId" + formNum + " .policyProperties").find("#" + opPolicyPropValue.id).val(
126 allPolicies['operational_policy']['policies'][opPolicyElemIndex][opPolicyPropValue.id]);
129 // Initial TargetResourceId options
130 initTargetResourceIdOptions(allPolicies['operational_policy']['policies'][opPolicyElemIndex]['target']['type'], formNum);
131 $.each($('.policyTarget').find('.form-control'), function(opPolicyTargetPropIndex, opPolicyTargetPropValue) {
133 $("#formId" + formNum + " .policyTarget").find("#" + opPolicyTargetPropValue.id).val(
134 allPolicies['operational_policy']['policies'][opPolicyElemIndex]['target'][opPolicyTargetPropValue.id]);
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) {
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) {
148 guardElemValue['id'] = guardElemId;
149 $("#formId" + formNum + " .guardProperties").find("#" + guardPropElemValue.id).val(
150 guardElemValue[guardPropElemValue.id]);
152 iniGuardPolicyType(guardElemId, formNum);
153 // And finally enable the flag
154 $("#formId" + formNum + " #enableGuardPolicy").prop("checked", true);
162 <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose}>
163 <Modal.Header closeButton>
164 <Modal.Title>Operational policies</Modal.Title>
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()}
178 <label htmlFor="timeout" className="col-sm-3"
179 style={{ paddingLeft: '5px', paddingRight: '10px' }}>Overall
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" />
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>
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"
198 readOnly="readonly" id="clname" value={LOOP_CACHE.getLoopName()} />
202 <div className="panel-heading" style={{ backgroundColor: 'white' }}>
203 <ul id="nav_Tabs" className="nav nav-tabs">
205 <a id="add_one_more" href="#desc_tab">
207 className="glyphicon glyphicon-plus" aria-hidden="true">
213 <div className="panel-body">
214 <div className="tab-content">
215 <div id="properties_tab" className="tab-pane fade in active"></div>
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>
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>
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">
257 <div className="form-group clearfix">
258 <label htmlFor="timeout" className="col-sm-4 control-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>
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>°
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>
286 <div className="form-group clearfix">
287 <label htmlFor="success" className="col-sm-4 control-label">When
289 <div className="col-sm-8">
290 <select className="form-control" id="success" name="success"
292 ng-options="policy for policy in policy_ids track by policy">
293 <option value="">-- choose an option --</option>
297 <div className="form-group clearfix">
298 <label htmlFor="failure" className="col-sm-4 control-label">When
300 <div className="col-sm-8">
301 <select className="form-control" id="failure" name="failure"
303 ng-options="policy for policy in policy_ids track by policy">
304 <option value="">-- choose an option --</option>
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>
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>
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>
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>
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
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>
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>
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 />
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 />
397 <div className="form-group clearfix">
398 <label htmlFor="modelName" className="col-sm-4 control-label">
400 <div className="col-sm-8">
401 <input className="form-control" name="modelName" id="modelName"
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 />
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 />
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" />
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>
441 <form className="guardProperties" className="form-horizontal"
442 title="Guard policy associated" style={{ border: '2px dotted gray' }}>
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" />
451 <label className="form-group note">Note: Prefix will be added to Guard Policy ID automatically based on Guard Policy Type</label>
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" />
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" />
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" />
474 <div className="form-group clearfix">
476 <label htmlFor="targets" className="col-sm-4 control-label">Guard
478 <div className="col-sm-8">
479 <input className="form-control" name="targets" id="targets" />
483 <div className="form-group clearfix" id="minMaxGuardPolicyDiv">
484 <label htmlFor="min" className="col-sm-4 control-label"> Min
486 <div className="col-sm-8">
487 <input className="form-control" name="min" id="min" />
489 <label htmlFor="max" className="col-sm-4 control-label"> Max
491 <div className="col-sm-8">
492 <input className="form-control" name="max" id="max" />
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" />
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"
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>
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" />
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" />
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" />
542 <Button variant="secondary" onClick={this.handleClose}>
545 <Button variant="primary" onClick={this.handleClose}>