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 './OperationalPolicy.css'
28 import styled from 'styled-components';
30 const ModalStyled = styled(Modal)`
31 background-color: transparent;
34 export default class OperationalPolicyModal extends React.Component {
38 loopCache: this.props.loopCache,
44 constructor(props, context) {
45 super(props, context);
47 this.handleClose = this.handleClose.bind(this);
48 this.initPolicySelect = this.initPolicySelect.bind(this);
49 this.initPolicySelect();
53 this.setState({ show: false });
54 this.props.history.push('/')
58 if (this.allPolicies['operational_policy'] === undefined || this.allPolicies['operational_policy'] === null) {
59 this.allPolicies = this.state.loopCache.getOperationalPolicyConfigurationJson();
61 // Provision all policies ID first
62 if (this.policyIds.length === 0 && this.allPolicies['operational_policy'] !== undefined) {
64 for (let i = 0; i < this.allPolicies['operational_policy']['policies'].length; i++) {
65 this.policyIds.push(this.allPolicies['operational_policy']['policies'][i]['id']);
70 renderPolicyIdSelect() {
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>))}
80 serializeElement(element) {
82 element.serializeArray().forEach(function () {
84 if (!o[this.name].push) {
85 o[this.name] = [o[this.name]];
87 o[this.name].push(this.value || '');
89 o[this.name] = this.value || '';
95 // When we change the name of a policy
96 isDuplicatedId(event) {
97 // 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");
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());
112 configureComponents() {
113 console.log("Load properties to op policy");
115 document.getElementsByClassName('form-control').forEach(function () {
116 this.val(this.allPolicies['operational_policy']['controlLoop'][this.id]);
118 // Set the sub-policies
119 this.allPolicies['operational_policy']['policies'].forEach(function (opPolicyElemIndex, opPolicyElemValue) {
121 /* var formNum = add_one_more();
122 forEach(document.getElementsByClassName('policyProperties').find('.form-control'), function(opPolicyPropIndex, opPolicyPropValue) {
124 $("#formId" + formNum + " .policyProperties").find("#" + opPolicyPropValue.id).val(
125 allPolicies['operational_policy']['policies'][opPolicyElemIndex][opPolicyPropValue.id]);
128 // Initial TargetResourceId options
129 initTargetResourceIdOptions(allPolicies['operational_policy']['policies'][opPolicyElemIndex]['target']['type'], formNum);
130 $.each($('.policyTarget').find('.form-control'), function(opPolicyTargetPropIndex, opPolicyTargetPropValue) {
132 $("#formId" + formNum + " .policyTarget").find("#" + opPolicyTargetPropValue.id).val(
133 allPolicies['operational_policy']['policies'][opPolicyElemIndex]['target'][opPolicyTargetPropValue.id]);
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) {
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) {
147 guardElemValue['id'] = guardElemId;
148 $("#formId" + formNum + " .guardProperties").find("#" + guardPropElemValue.id).val(
149 guardElemValue[guardPropElemValue.id]);
151 iniGuardPolicyType(guardElemId, formNum);
152 // And finally enable the flag
153 $("#formId" + formNum + " #enableGuardPolicy").prop("checked", true);
161 <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose}>
162 <Modal.Header closeButton>
163 <Modal.Title>Operational policies</Modal.Title>
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()}
177 <label htmlFor="timeout" className="col-sm-3"
178 style={{ paddingLeft: '5px', paddingRight: '10px' }}>Overall
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" />
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>
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"
197 readOnly="readonly" id="clname" value={this.state.loopCache.getLoopName()} />
201 <div className="panel-heading" style={{ backgroundColor: 'white' }}>
202 <ul id="nav_Tabs" className="nav nav-tabs">
204 <a id="add_one_more" href="#desc_tab">
206 className="glyphicon glyphicon-plus" aria-hidden="true">
212 <div className="panel-body">
213 <div className="tab-content">
214 <div id="properties_tab" className="tab-pane fade in active"></div>
219 <span id="formSpan" style={{ display: 'none' }}>
220 <form className="policyProperties 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"
227 onKeyUp="updateTabLabel($event)" />
228 <span >ID must be unique</span>
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>
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">
256 <div className="form-group clearfix">
257 <label htmlFor="timeout" className="col-sm-4 control-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>
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>°
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>
285 <div className="form-group clearfix">
286 <label htmlFor="success" className="col-sm-4 control-label">When
288 <div className="col-sm-8">
289 <select className="form-control" id="success" name="success"
291 ng-options="policy for policy in policy_ids track by policy">
292 <option value="">-- choose an option --</option>
296 <div className="form-group clearfix">
297 <label htmlFor="failure" className="col-sm-4 control-label">When
299 <div className="col-sm-8">
300 <select className="form-control" id="failure" name="failure"
302 ng-options="policy for policy in policy_ids track by policy">
303 <option value="">-- choose an option --</option>
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>
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>
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>
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>
353 <form className="policyTarget 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
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>
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>
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 />
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 />
396 <div className="form-group clearfix">
397 <label htmlFor="modelName" className="col-sm-4 control-label">
399 <div className="col-sm-8">
400 <input className="form-control" name="modelName" id="modelName"
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 />
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 />
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" />
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>
440 <form className="guardProperties form-horizontal"
441 title="Guard policy associated" style={{ border: '2px dotted gray' }}>
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" />
450 <label className="form-group note">Note: Prefix will be added to Guard Policy ID automatically based on Guard Policy Type</label>
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" />
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" />
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" />
473 <div className="form-group clearfix">
475 <label htmlFor="targets" className="col-sm-4 control-label">Guard
477 <div className="col-sm-8">
478 <input className="form-control" name="targets" id="targets" />
482 <div className="form-group clearfix" id="minMaxGuardPolicyDiv">
483 <label htmlFor="min" className="col-sm-4 control-label"> Min
485 <div className="col-sm-8">
486 <input className="form-control" name="min" id="min" />
488 <label htmlFor="max" className="col-sm-4 control-label"> Max
490 <div className="col-sm-8">
491 <input className="form-control" name="max" id="max" />
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" />
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"
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>
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" />
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" />
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" />
541 <Button variant="secondary" onClick={this.handleClose}>
544 <Button variant="primary" onClick={this.handleClose}>