sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 1 | /*- |
| 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 | * =================================================================== |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 21 | * |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 22 | */ |
sebdet | e44fdb1 | 2019-07-12 12:25:56 +0200 | [diff] [blame] | 23 | |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 24 | export default class LoopCache { |
sebdet | e44fdb1 | 2019-07-12 12:25:56 +0200 | [diff] [blame] | 25 | loopJsonCache; |
| 26 | |
| 27 | constructor(loopJson) { |
| 28 | this.loopJsonCache=loopJson; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 29 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 30 | |
sebdet | b65f121 | 2019-08-23 07:49:25 -0700 | [diff] [blame] | 31 | updateMicroServiceProperties(name, newMsProperties) { |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 32 | for (var policy in this.loopJsonCache["microServicePolicies"]) { |
sebdet | b65f121 | 2019-08-23 07:49:25 -0700 | [diff] [blame] | 33 | if (this.loopJsonCache["microServicePolicies"][policy]["name"] === name) { |
sebdet | 58135b8 | 2020-02-27 11:39:50 -0800 | [diff] [blame] | 34 | this.loopJsonCache["microServicePolicies"][policy]["configurationsJson"] = newMsProperties; |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 35 | } |
| 36 | } |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 37 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 38 | |
xuegao | 635445a | 2020-03-02 11:37:20 +0100 | [diff] [blame] | 39 | updateMicroServicePdpGroup(name, pdpGroup, pdpSubgroup) { |
| 40 | for (var policy in this.loopJsonCache["microServicePolicies"]) { |
| 41 | if (this.loopJsonCache["microServicePolicies"][policy]["name"] === name) { |
| 42 | this.loopJsonCache["microServicePolicies"][policy]["pdpGroup"] = pdpGroup; |
| 43 | this.loopJsonCache["microServicePolicies"][policy]["pdpSubgroup"] = pdpSubgroup; |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 48 | updateGlobalProperties(newGlobalProperties) { |
| 49 | this.loopJsonCache["globalPropertiesJson"] = newGlobalProperties; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 50 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 51 | |
xuegao | 635445a | 2020-03-02 11:37:20 +0100 | [diff] [blame] | 52 | updateOperationalPolicyProperties(name, newOpProperties) { |
| 53 | for (var policy in this.loopJsonCache["operationalPolicies"]) { |
| 54 | if (this.loopJsonCache["operationalPolicies"][policy]["name"] === name) { |
| 55 | this.loopJsonCache["operationalPolicies"][policy]["configurationsJson"] = newOpProperties; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | updateOperationalPolicyPdpGroup(name, pdpGroup, pdpSubgroup) { |
| 61 | for (var policy in this.loopJsonCache["operationalPolicies"]) { |
| 62 | if (this.loopJsonCache["operationalPolicies"][policy]["name"] === name) { |
| 63 | this.loopJsonCache["operationalPolicies"][policy]["pdpGroup"] = pdpGroup; |
| 64 | this.loopJsonCache["operationalPolicies"][policy]["pdpSubgroup"] = pdpSubgroup; |
| 65 | } |
| 66 | } |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 67 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 68 | |
| 69 | getLoopName() { |
| 70 | return this.loopJsonCache["name"]; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 71 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 72 | |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 73 | getOperationalPolicyConfigurationJson() { |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 74 | return this.loopJsonCache["operationalPolicies"]["0"]["configurationsJson"]; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 75 | } |
xuegao | 635445a | 2020-03-02 11:37:20 +0100 | [diff] [blame] | 76 | |
sebdet | f9e2cee | 2019-08-09 18:36:09 +0200 | [diff] [blame] | 77 | getOperationalPolicyJsonSchema() { |
xuegao | c488fed | 2019-12-19 11:58:45 +0100 | [diff] [blame] | 78 | return this.loopJsonCache["operationalPolicies"]["0"]["jsonRepresentation"]; |
sebdet | f9e2cee | 2019-08-09 18:36:09 +0200 | [diff] [blame] | 79 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 80 | |
| 81 | getOperationalPolicies() { |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 82 | return this.loopJsonCache["operationalPolicies"]; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 83 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 84 | |
xuegao | c488fed | 2019-12-19 11:58:45 +0100 | [diff] [blame] | 85 | getOperationalPoliciesNoJsonSchema() { |
| 86 | var operationalPolicies = JSON.parse(JSON.stringify(this.loopJsonCache["operationalPolicies"])); |
| 87 | delete operationalPolicies[0]["jsonRepresentation"]; |
| 88 | return operationalPolicies; |
| 89 | } |
| 90 | |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 91 | getGlobalProperties() { |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 92 | return this.loopJsonCache["globalPropertiesJson"]; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 93 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 94 | |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 95 | getDcaeDeploymentProperties() { |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 96 | return this.loopJsonCache["globalPropertiesJson"]["dcaeDeployParameters"]; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 97 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 98 | |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 99 | getMicroServicePolicies() { |
| 100 | return this.loopJsonCache["microServicePolicies"]; |
| 101 | } |
| 102 | |
sebdet | c11160e | 2020-02-25 15:13:31 -0800 | [diff] [blame] | 103 | getOperationalPolicyForName(name) { |
| 104 | var opProperties=this.getOperationalPolicies(); |
| 105 | for (var policy in opProperties) { |
| 106 | if (opProperties[policy]["name"] === name) { |
| 107 | return opProperties[policy]; |
| 108 | } |
| 109 | } |
| 110 | return null; |
| 111 | } |
| 112 | |
| 113 | getOperationalPolicyPropertiesForName(name) { |
| 114 | var opConfig = this.getOperationalPolicyForName(name); |
| 115 | if (opConfig !== null) { |
sebdet | 58135b8 | 2020-02-27 11:39:50 -0800 | [diff] [blame] | 116 | return opConfig["configurationsJson"]; |
sebdet | c11160e | 2020-02-25 15:13:31 -0800 | [diff] [blame] | 117 | } |
| 118 | return null; |
| 119 | } |
| 120 | |
| 121 | getOperationalPolicyJsonRepresentationForName(name) { |
xuegao | 635445a | 2020-03-02 11:37:20 +0100 | [diff] [blame] | 122 | var opConfig = this.getOperationalPolicyForName(name); |
| 123 | if (opConfig !== null) { |
| 124 | return opConfig["jsonRepresentation"]; |
| 125 | } |
| 126 | return null; |
| 127 | } |
sebdet | c11160e | 2020-02-25 15:13:31 -0800 | [diff] [blame] | 128 | |
xuegao | 635445a | 2020-03-02 11:37:20 +0100 | [diff] [blame] | 129 | getOperationalPolicySupportedPdpgroup(name) { |
| 130 | var opConfig=this.getOperationalPolicyForName(name); |
| 131 | if (opConfig !== null) { |
| 132 | return opConfig["policyModel"]["policyPdpGroup"]["supportedPdpGroups"]; |
| 133 | } |
| 134 | return null; |
| 135 | } |
| 136 | |
| 137 | getOperationalPolicyPdpGroup(name) { |
| 138 | var opConfig=this.getOperationalPolicyForName(name); |
| 139 | if (opConfig !== null) { |
| 140 | return opConfig["pdpGroup"]; |
| 141 | } |
| 142 | return null; |
| 143 | } |
| 144 | |
| 145 | getOperationalPolicyPdpSubgroup(name) { |
| 146 | var opConfig=this.getOperationalPolicyForName(name); |
| 147 | if (opConfig !== null) { |
| 148 | return opConfig["pdpSubgroup"]; |
| 149 | } |
| 150 | return null; |
| 151 | } |
| 152 | |
| 153 | getMicroServiceSupportedPdpgroup(name) { |
| 154 | var microService=this.getMicroServiceForName(name); |
| 155 | if (microService !== null) { |
| 156 | return microService["policyModel"]["policyPdpGroup"]["supportedPdpGroups"]; |
| 157 | } |
| 158 | return null; |
| 159 | } |
| 160 | |
| 161 | getMicroServicePdpGroup(name) { |
| 162 | var microService=this.getMicroServiceForName(name); |
| 163 | if (microService !== null) { |
| 164 | return microService["pdpGroup"]; |
| 165 | } |
| 166 | return null; |
| 167 | } |
| 168 | |
| 169 | getMicroServicePdpSubgroup(name) { |
| 170 | var microService=this.getMicroServiceForName(name); |
| 171 | if (microService !== null) { |
| 172 | return microService["pdpSubgroup"]; |
| 173 | } |
| 174 | return null; |
| 175 | } |
sebdet | c11160e | 2020-02-25 15:13:31 -0800 | [diff] [blame] | 176 | |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 177 | getMicroServiceForName(name) { |
| 178 | var msProperties=this.getMicroServicePolicies(); |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 179 | for (var policy in msProperties) { |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 180 | if (msProperties[policy]["name"] === name) { |
| 181 | return msProperties[policy]; |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | return null; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 185 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 186 | |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 187 | getMicroServicePropertiesForName(name) { |
| 188 | var msConfig = this.getMicroServiceForName(name); |
| 189 | if (msConfig !== null) { |
sebdet | 58135b8 | 2020-02-27 11:39:50 -0800 | [diff] [blame] | 190 | return msConfig["configurationsJson"]; |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 191 | } |
| 192 | return null; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 193 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 194 | |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 195 | getMicroServiceJsonRepresentationForName(name) { |
| 196 | var msConfig = this.getMicroServiceForName(name); |
| 197 | if (msConfig !== null) { |
| 198 | return msConfig["jsonRepresentation"]; |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 199 | } |
| 200 | return null; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 201 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 202 | |
| 203 | getResourceDetailsVfProperty() { |
xuegao | 289e8e1 | 2019-11-08 13:10:36 +0100 | [diff] [blame] | 204 | return this.loopJsonCache["modelService"]["resourceDetails"]["VF"]; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 205 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 206 | |
| 207 | getResourceDetailsVfModuleProperty() { |
xuegao | 289e8e1 | 2019-11-08 13:10:36 +0100 | [diff] [blame] | 208 | return this.loopJsonCache["modelService"]["resourceDetails"]["VFModule"]; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 209 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 210 | |
| 211 | getLoopLogsArray() { |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 212 | return this.loopJsonCache.loopLogs; |
| 213 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 214 | |
sebdet | 190227a | 2019-07-19 16:51:19 +0200 | [diff] [blame] | 215 | getComputedState() { |
| 216 | return this.loopJsonCache.lastComputedState; |
| 217 | } |
| 218 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 219 | getComponentStates() { |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 220 | return this.loopJsonCache.components; |
| 221 | } |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 222 | } |