diff --git a/webroot/config/networking/slo/common/ui/js/models/sloModel.js b/webroot/config/networking/slo/common/ui/js/models/sloModel.js index fb22a53ad..ba3dd4c32 100644 --- a/webroot/config/networking/slo/common/ui/js/models/sloModel.js +++ b/webroot/config/networking/slo/common/ui/js/models/sloModel.js @@ -15,7 +15,8 @@ define([ "security_logging_object_rate": 100, "rules_entries":{"rules":[]}, "network_policy_refs": [], - "security_group_refs": [] + "security_group_refs": [], + "admin_state": 'true' }, validations: { @@ -40,13 +41,21 @@ define([ var policyRuleList = [], secGrpRuleList =[], dataSourceList = []; var policyRefs = getValueByJsonPath(modelConfig, 'network_policy_refs',[]); var secGrpRefs = getValueByJsonPath(modelConfig, 'security_group_refs',[]); - var policyUuidList = [], secGrpUuidList = []; + var policyUuidList = [], secGrpUuidList = [], policyEmptyRuleUuid = [], + secGrpEmptyRuleUuid = []; /*Start for dataSourceList List*/ if(modelConfig.policyModel !== undefined){ _.each(policyRefs, function(policy) { - policyUuidList.push(policy.uuid); - }); - + var policyRule = getValueByJsonPath(policy, 'attr;rule',[]); + if(policyRule.length === 0){ + policyEmptyRuleUuid.push(policy.uuid); + } + }); + _.each(modelConfig.policyModel, function(policyModel) { + if(policyEmptyRuleUuid.indexOf(policyModel.uuid) === -1){ + policyUuidList.push(policyModel.uuid); + } + }); _.each(modelConfig.policyModel, function(model) { if(policyUuidList.indexOf(model.uuid) !== -1){ var ruleList = getValueByJsonPath(model, ctwc.POLICY_RULE, []); @@ -63,9 +72,16 @@ define([ if(modelConfig.secGrpModel !== undefined){ _.each(secGrpRefs, function(secGrp) { - secGrpUuidList.push(secGrp.uuid); + var secGroupRule = getValueByJsonPath(secGrp, 'attr;rule',[]); + if(secGroupRule.length === 0){ + secGrpEmptyRuleUuid.push(secGrp.uuid); + } + }); + _.each(modelConfig.secGrpModel, function(secGrpModel) { + if(secGrpEmptyRuleUuid.indexOf(secGrpModel.uuid) === -1){ + secGrpUuidList.push(secGrpModel.uuid); + } }); - _.each(modelConfig.secGrpModel, function(model) { if(secGrpUuidList.indexOf(model.uuid) !== -1){ var ruleList = getValueByJsonPath(model, ctwc.SERVICE_GRP_RULE, []); @@ -115,14 +131,23 @@ define([ modelConfig["rules_entries"]["rules"] = rulesCollectionModel; _.each(policyRefs, function(policy) { - var to = policy.to.join(':'); - newPolicyRefs.push(to); + var policyRules = getValueByJsonPath(policy, 'attr;rule',[]); + if(policyRules.length === 0){ + var to = policy.to.join(':'); + newPolicyRefs.push(to); + } }); _.each(secGrpRefs, function(secGrp) { - var to = secGrp.to.join(':'); - newSecGrpRefs.push(to); + var secGrpRules = getValueByJsonPath(secGrp, 'attr;rule',[]); + if(secGrpRules.length === 0){ + var to = secGrp.to.join(':'); + newSecGrpRefs.push(to); + } }); - + var adminState = getValueByJsonPath(modelConfig, 'id_perms;enable', true); + if(!adminState){ + modelConfig['admin_state'] = 'false'; + } modelConfig['network_policy_refs'] = newPolicyRefs; modelConfig['security_group_refs'] = newSecGrpRefs; this.formatRBACPermsModelConfig(modelConfig); @@ -131,18 +156,13 @@ define([ addSloRule: function(){ var rulesList = this.model().attributes['sloRuleDetails']; - if(this.model().attributes.network_policy_refs !== '' || this.model().attributes.security_group_refs !== ''){ - var newRuleModel = new SloRuleModel({ - "rule_uuid": "", - "rate": '', - "dataSource" : this.sloEditView.sloRuleList - }); - self.subscribeSloRuleModelChangeEvents(newRuleModel); - rulesList.add([newRuleModel]); - }else{ - this.sloEditView.model.showErrorAttr(ctwc.SLO_PREFIX_ID + cowc.FORM_SUFFIX_ID, - 'Please select Network Policy or Security Group.'); - } + var newRuleModel = new SloRuleModel({ + "rule_uuid": "", + "rate": '', + "dataSource" : this.sloEditView.sloRuleList + }); + self.subscribeSloRuleModelChangeEvents(newRuleModel); + rulesList.add([newRuleModel]); }, deleteSloRule: function(data, rules) { @@ -220,6 +240,7 @@ define([ if(newSloObj.security_logging_object_rate === ''){ newSloObj.security_logging_object_rate = '100'; } + var policyList = [], secGrpList = []; if(sloRules.length > 0){ var policyRuleList = {}, secGrpRuleList = {}; for(var i = 0; i < sloRules.length; i++){ @@ -247,7 +268,6 @@ define([ } } if(Object.keys(policyRuleList).length > 0){ - var policyList = []; for(var j in policyRuleList){ var policyObj = {}; policyObj.to = self.sloEditView.policyList[j].split(';'); @@ -255,12 +275,8 @@ define([ policyObj.attr.rule = policyRuleList[j]; policyList.push(policyObj); } - newSloObj['network_policy_refs'] = policyList; - }else{ - newSloObj['network_policy_refs'] = []; } if(Object.keys(secGrpRuleList).length > 0){ - var secGrpList = []; for(var k in secGrpRuleList){ var secGrpObj = {}; secGrpObj.to = self.sloEditView.secGrpList[k].split(';'); @@ -268,13 +284,43 @@ define([ secGrpObj.attr.rule = secGrpRuleList[k]; secGrpList.push(secGrpObj); } + } + } + if(newSloObj.network_policy_refs !== ''){ + var polList = [], policyRuleList = newSloObj.network_policy_refs.split(';'); + for(var j = 0; j < policyRuleList.length; j++){ + var policyObj = {}; + policyObj.to = policyRuleList[j].split(':'); + policyObj.attr = {}; + policyObj.attr.rule = []; + polList.push(policyObj); + } + var updatedPolicy = polList.concat(policyList); + newSloObj['network_policy_refs'] = updatedPolicy; + }else{ + if(policyList.length > 0){ + newSloObj['network_policy_refs'] = policyList; + }else{ + newSloObj['network_policy_refs'] = []; + } + } + if(newSloObj.security_group_refs !== ''){ + var secGroupList = [], secGrpRuleList = newSloObj.security_group_refs.split(';'); + for(var j = 0; j < secGrpRuleList.length; j++){ + var secGrpObj = {}; + secGrpObj.to = secGrpRuleList[j].split(':'); + secGrpObj.attr = {}; + secGrpObj.attr.rule = []; + secGroupList.push(secGrpObj); + } + var updatedSecGrpList = secGroupList.concat(secGrpList); + newSloObj['security_group_refs'] = updatedSecGrpList; + }else{ + if(secGrpList.length > 0){ newSloObj['security_group_refs'] = secGrpList; }else{ newSloObj['security_group_refs'] = []; } - }else{ - newSloObj['security_group_refs'] = []; - newSloObj['network_policy_refs'] = []; } delete newSloObj.rules_entries; delete newSloObj.sloRuleDetails; @@ -283,13 +329,17 @@ define([ newSloObj}, "reqUrl": "/security-logging-objects"}]}; ajaxConfig.url = ctwc.URL_CREATE_CONFIG_OBJECT; + newSloObj['id_perms'] = {}; + newSloObj['id_perms']['enable'] = (newSloObj.admin_state === 'true'); } else { postData = {"data":[{"data":{"security-logging-object": newSloObj}, "reqUrl": "/security-logging-object/" + newSloObj.uuid}]}; ajaxConfig.url = ctwc.URL_UPDATE_CONFIG_OBJECT; + newSloObj['id_perms']['enable'] = (newSloObj.admin_state === 'true'); } + postData = {"security-logging-object": newSloObj}; ajaxConfig.type = 'POST'; ajaxConfig.data = JSON.stringify(postData); diff --git a/webroot/config/networking/slo/common/ui/js/sloFormatters.js b/webroot/config/networking/slo/common/ui/js/sloFormatters.js index 53a76a382..9dc8f84dc 100644 --- a/webroot/config/networking/slo/common/ui/js/sloFormatters.js +++ b/webroot/config/networking/slo/common/ui/js/sloFormatters.js @@ -6,7 +6,7 @@ function(_){ var sloFormatters = function(){ this.formatSloRules = function(r, c, v, cd, dc) { - var sloRuleList = [], returnString = '', sloRules = []; + var sloRuleList = [], returnString = '', sloRules = [], newObj; var policyRefs = getValueByJsonPath(dc, 'network_policy_refs',[]); var secGrpRefs = getValueByJsonPath(dc, 'security_group_refs',[]); var refs = policyRefs.concat(secGrpRefs); @@ -18,10 +18,19 @@ _.each(rule, function(obj) { obj.objName = objName; }); - sloRules = sloRules.concat(rule); + if(rule.length === 0){ + rule.push({rule_uuid: '', objName: objName}); + sloRules = sloRules.concat(rule); + }else{ + sloRules = sloRules.concat(rule); + } } for(var i = 0; i < sloRules.length; i++){ - var newObj = sloRules[i].rule_uuid + ' ('+ sloRules[i].objName + ')';// + sloRules[i].rate; + if(sloRules[i].rule_uuid === ''){ + newObj = '* ('+ sloRules[i].objName + ')'; + }else{ + newObj = sloRules[i].rule_uuid + ' ('+ sloRules[i].objName + ')'; + } var sloRule = ''+ newObj +''; sloRuleList.push(sloRule); } @@ -44,7 +53,7 @@ }; this.formatSloRuleDetails = function(r, c, v, cd, dc) { - var sloRuleList = [], returnString = '', sloRules = []; + var sloRuleList = [], returnString = '', sloRules = [], ruleUUID, sloRule; var policyRefs = getValueByJsonPath(dc, 'network_policy_refs',[]); var secGrpRefs = getValueByJsonPath(dc, 'security_group_refs',[]); var refs = policyRefs.concat(secGrpRefs); @@ -57,11 +66,21 @@ _.each(rule, function(obj) { obj.objName = objName; }); - sloRules = sloRules.concat(rule); + if(rule.length === 0){ + rule.push({rule_uuid: '', objName: objName}); + sloRules = sloRules.concat(rule); + }else{ + sloRules = sloRules.concat(rule); + } } for(var i = 0; i < sloRules.length; i++){ - var ruleUUID = sloRules[i].rule_uuid + ' (' + sloRules[i].objName + ')'; - var sloRule = ''+ ruleUUID +''+ sloRules[i].rate +''; + if(sloRules[i].rule_uuid === ''){ + ruleUUID = '* (' + sloRules[i].objName + ')'; + sloRule = ''+ ruleUUID +''; + }else{ + ruleUUID = sloRules[i].rule_uuid + ' (' + sloRules[i].objName + ')'; + sloRule = ''+ ruleUUID +''+ sloRules[i].rate +''; + } sloRuleList.push(sloRule); } } @@ -150,6 +169,13 @@ return '-'; } }; + + this.adminStateFormatter = function(d, c, v, cd, dc) { + var adminState = + getValueByJsonPath(dc, 'id_perms;enable', false); + + return adminState ? 'Up' : 'Down'; + }; }; return sloFormatters; }); \ No newline at end of file diff --git a/webroot/config/networking/slo/common/ui/js/views/sloEditView.js b/webroot/config/networking/slo/common/ui/js/views/sloEditView.js index 628e2613b..312ee0805 100644 --- a/webroot/config/networking/slo/common/ui/js/views/sloEditView.js +++ b/webroot/config/networking/slo/common/ui/js/views/sloEditView.js @@ -74,14 +74,20 @@ define([ ctwu.bindPermissionsValidation(self); var secLoggingInfo = $(''); var ruleInfo = $(''); + var labelInfo = $(''); + var policyInfo = $(''); + var securityGrpInfo = $(''); $('#security_logging_object_rate label').append(secLoggingInfo); $('#sloRuleDetails table thead tr th:nth-child(2)').append(ruleInfo); + $('#sloRuleDetails > label').append(labelInfo); + $('#network_policy_refs label').append(policyInfo); + $('#security_group_refs label').append(securityGrpInfo); }, null, true ); }, fetchRuleList : function(options, self, callback) { - var returnArr = []; + var returnArr = [], networkPolicyChildList = [], secGrpChildList = []; self.policyList = {}, self.secGrpList = {}, self.sloRuleList = []; self.policyObj = [], self.secGrpObj = []; $.each(options.policyModel, function (i, obj) { @@ -91,6 +97,7 @@ define([ if(ruleList.length > 0){ for(var j = 0; j < ruleList.length; j++){ self.policyList[ruleList[j].rule_uuid] = obj.name; + networkPolicyChildList.push(policyHierarchicalList(ruleList[j], obj)); } } }); @@ -101,11 +108,12 @@ define([ if(ruleList.length > 0){ for(var k = 0; k < ruleList.length; k++){ self.secGrpList[ruleList[k].rule_uuid] = obj.name; + secGrpChildList.push(secGrpHierarchicalList(ruleList[k], obj)); } } }); - self.sloRuleList.push({text : 'Policy', value : 'network_policy', id :'network_policy', children : []}, - {text : 'Security Group', value : 'security_group', id : 'security_group', children : []}); + self.sloRuleList.push({text : 'Policy', value : 'network_policy', id :'network_policy', children : networkPolicyChildList}, + {text : 'Security Group', value : 'security_group', id : 'security_group', children : secGrpChildList}); callback(returnArr); }, @@ -162,7 +170,7 @@ define([ return hierarchicalList; } - function retainingPreviousRecords(updatedList, mode, deleteUUID){ + function retainingPreviousRecords(updatedList, mode, ruleUUID){ var sloRules = $.extend(true,{}, self.model.model().attributes.rules_entries.rules).toJSON(); var existingRuleList = []; _.each(sloRules, function(obj) { @@ -175,20 +183,17 @@ define([ obj.dataSource()[1].children = updatedList; } newObj.dataSource = obj.dataSource(); - if(deleteUUID.length > 0){ - var ruleUuid = newObj.rule_uuid.split(';'); - if(deleteUUID.indexOf(ruleUuid[0]) === -1){ - existingRuleList.push(newObj); - } - }else{ - existingRuleList.push(newObj); - } + existingRuleList.push(newObj); }); if(existingRuleList.length > 0){ var ruleModelColl = []; _.each(existingRuleList, function(obj) { - var newRuleModel = new SloRulesModel(obj); - ruleModelColl.push(newRuleModel); + var uuid = obj.rule_uuid.split(';')[0]; + if(ruleUUID.indexOf(uuid) === -1){ + var newRuleModel = new SloRulesModel(obj); + self.model.subscribeSloRuleModelChangeEvents(newRuleModel); + ruleModelColl.push(newRuleModel); + } }); var coll = new Backbone.Collection(ruleModelColl); self.model.sloRuleDetails([]); @@ -202,20 +207,27 @@ define([ } function onNetworkPolicyChanged(e){ - var policyRule = []; + var policyRule = [], ruleUuid = [],updatedChild = [], existingChild; if(e.added !== undefined){ if(e.added.constructor !== Array){ _.each(self.policyObj, function(obj) { if(e.added.value === obj.uuid){ var ruleList = getValueByJsonPath(obj, ctwc.POLICY_RULE, []); _.each(ruleList, function(rule) { - policyRule.push(policyHierarchicalList(rule, obj)); + policyRule.push(rule.rule_uuid); + ruleUuid.push(rule.rule_uuid); }); } }); - var updatedList = self.sloRuleList[0].children.concat(policyRule); - self.sloRuleList[0].children = updatedList; - retainingPreviousRecords(updatedList, 'network', []); + existingChild = self.sloRuleList[0].children; + _.each(existingChild, function(child) { + var id = child.id.split(';')[0]; + if(policyRule.indexOf(id) === -1){ + updatedChild.push(child); + } + }); + self.sloRuleList[0].children = updatedChild; + retainingPreviousRecords(updatedChild, 'network', ruleUuid); }else if(e.added.length > 0){ var existingList = []; _.each(e.added, function(obj) { @@ -225,12 +237,19 @@ define([ if(existingList.indexOf(obj.uuid) !== -1){ var ruleList = getValueByJsonPath(obj, ctwc.POLICY_RULE, []); _.each(ruleList, function(rule) { - policyRule.push(policyHierarchicalList(rule, obj)); + policyRule.push(rule.rule_uuid); + ruleUuid.push(rule.rule_uuid); }); } }); - var updatedList = self.sloRuleList[0].children.concat(policyRule); - self.sloRuleList[0].children = updatedList; + existingChild = self.sloRuleList[0].children; + _.each(existingChild, function(child) { + var id = child.id.split(';')[0]; + if(policyRule.indexOf(id) === -1){ + updatedChild.push(child); + } + }); + self.sloRuleList[0].children = updatedChild; } } if(e.removed !== undefined){ @@ -239,42 +258,41 @@ define([ _.each(self.policyObj, function(policy) { if(e.removed.value === policy.uuid){ ruleList = getValueByJsonPath(policy, ctwc.POLICY_RULE, []); + _.each(ruleList, function(rule) { + ruleUuid.push(rule.rule_uuid); + policyRule.push(policyHierarchicalList(rule, policy)); + }); } }); - var updatedList = self.sloRuleList[0].children, deleteUUID = []; - _.each(ruleList, function(rule) { - deleteUUID.push(rule.rule_uuid); - _.each(updatedList, function(list, k) { - if(list !== undefined){ - var ruleUuid = list.id.split(';')[0]; - if(ruleUuid === rule.rule_uuid){ - updatedList.splice(k,1); - } - } - }); - }); - console.log(deleteUUID); + var updatedList = self.sloRuleList[0].children.concat(policyRule); self.sloRuleList[0].children = updatedList; - retainingPreviousRecords(updatedList, 'network', deleteUUID); + retainingPreviousRecords(updatedList, 'network', ruleUuid); } } }; function onSecurityGroupChanged(e){ - var secGrpRule = []; + var secGrpRule = [], ruleUuid = [], updatedChild = [], existingChild; if(e.added !== undefined){ if(e.added.constructor !== Array){ _.each(self.secGrpObj, function(obj) { if(e.added.value === obj.uuid){ var ruleList = getValueByJsonPath(obj, ctwc.SERVICE_GRP_RULE, []); _.each(ruleList, function(rule) { - secGrpRule.push(secGrpHierarchicalList(rule, obj)); + secGrpRule.push(rule.rule_uuid); + ruleUuid.push(rule.rule_uuid); }); } }); - var updatedList = self.sloRuleList[1].children.concat(secGrpRule); - self.sloRuleList[1].children = updatedList; - retainingPreviousRecords(updatedList, 'sgp', []); + existingChild = self.sloRuleList[1].children; + _.each(existingChild, function(child) { + var id = child.id.split(';')[0]; + if(secGrpRule.indexOf(id) === -1){ + updatedChild.push(child); + } + }); + self.sloRuleList[1].children = updatedChild; + retainingPreviousRecords(updatedChild, 'sgp', ruleUuid); }else if(e.added.length > 0){ var existingList = []; _.each(e.added, function(obj) { @@ -284,12 +302,19 @@ define([ if(existingList.indexOf(obj.uuid) !== -1){ var ruleList = getValueByJsonPath(obj, ctwc.SERVICE_GRP_RULE, []); _.each(ruleList, function(rule) { - secGrpRule.push(secGrpHierarchicalList(rule, obj)); + secGrpRule.push(rule.rule_uuid); + ruleUuid.push(rule.rule_uuid); }); } }); - var updatedList = self.sloRuleList[1].children.concat(secGrpRule); - self.sloRuleList[1].children = updatedList; + existingChild = self.sloRuleList[1].children; + _.each(existingChild, function(child) { + var id = child.id.split(';')[0]; + if(secGrpRule.indexOf(id) === -1){ + updatedChild.push(child); + } + }); + self.sloRuleList[1].children = updatedChild; } } if(e.removed !== undefined){ @@ -298,22 +323,15 @@ define([ _.each(self.secGrpObj, function(secGrp) { if(e.removed.value === secGrp.uuid){ ruleList = getValueByJsonPath(secGrp, ctwc.SERVICE_GRP_RULE, []); + _.each(ruleList, function(rule) { + ruleUuid.push(rule.rule_uuid); + secGrpRule.push(secGrpHierarchicalList(rule, secGrp)); + }); } }); - var updatedList = self.sloRuleList[1].children, deleteUUID = []; - _.each(ruleList, function(rule) { - deleteUUID.push(rule.rule_uuid); - _.each(updatedList, function(list, k) { - if(list !== undefined){ - var ruleUuid = list.id.split(';')[0]; - if(ruleUuid === rule.rule_uuid){ - updatedList.splice(k,1); - } - } - }); - }); + var updatedList = self.sloRuleList[1].children.concat(secGrpRule); self.sloRuleList[1].children = updatedList; - retainingPreviousRecords(updatedList, 'sgp', deleteUUID); + retainingPreviousRecords(updatedList, 'sgp', ruleUuid); } } }; @@ -349,6 +367,27 @@ define([ placeholder: 'Enter Rate' } }]}, + { + columns: [ + { + elementId: 'admin_state', + view: "FormDropdownView", + viewConfig: { + label: 'Admin State', + path : 'admin_state', + class: 'col-xs-6', + dataBindValue : 'admin_state', + elementConfig : { + dataTextField : "text", + dataValueField : "id", + placeholder : 'Select Admin State', + data : [{id: 'true', text:'Up'}, + {id: 'false', text:'Down'}] + } + } + } + ] + }, { columns: [ { diff --git a/webroot/config/networking/slo/common/ui/js/views/sloGridView.js b/webroot/config/networking/slo/common/ui/js/views/sloGridView.js index 09cab54e7..d7f6a0936 100644 --- a/webroot/config/networking/slo/common/ui/js/views/sloGridView.js +++ b/webroot/config/networking/slo/common/ui/js/views/sloGridView.js @@ -281,6 +281,15 @@ define([ label: "Rate", keyClass:'col-xs-3', valueClass:'col-xs-9' + },{ + label: 'Admin State', + key: 'uuid', + keyClass:'col-xs-3', + valueClass:'col-xs-9', + templateGeneratorConfig: { + formatter: 'adminStateFormatter' + }, + templateGenerator: 'TextGenerator' },{ key: "uuid", templateGenerator: "TextGenerator", @@ -331,5 +340,10 @@ define([ return sloFormatters.FormatFirewallRule("", "", v, "", dc); }; + this.adminStateFormatter = function (v, dc) { + return sloFormatters.adminStateFormatter(null, + null, null, null, dc); + } + return sloGridView; }); \ No newline at end of file