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 | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 34 | this.loopJsonCache["microServicePolicies"][policy]["properties"] = 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 | |
| 39 | updateGlobalProperties(newGlobalProperties) { |
| 40 | this.loopJsonCache["globalPropertiesJson"] = newGlobalProperties; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 41 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 42 | |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 43 | updateOperationalPolicyProperties(newOpProperties) { |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 44 | this.loopJsonCache["operationalPolicies"] = newOpProperties; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 45 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 46 | |
| 47 | getLoopName() { |
| 48 | return this.loopJsonCache["name"]; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 49 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 50 | |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 51 | getOperationalPolicyConfigurationJson() { |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 52 | return this.loopJsonCache["operationalPolicies"]["0"]["configurationsJson"]; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 53 | } |
sebdet | f9e2cee | 2019-08-09 18:36:09 +0200 | [diff] [blame] | 54 | |
| 55 | getOperationalPolicyJsonSchema() { |
xuegao | c488fed | 2019-12-19 11:58:45 +0100 | [diff] [blame] | 56 | return this.loopJsonCache["operationalPolicies"]["0"]["jsonRepresentation"]; |
sebdet | f9e2cee | 2019-08-09 18:36:09 +0200 | [diff] [blame] | 57 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 58 | |
| 59 | getOperationalPolicies() { |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 60 | return this.loopJsonCache["operationalPolicies"]; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 61 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 62 | |
xuegao | c488fed | 2019-12-19 11:58:45 +0100 | [diff] [blame] | 63 | getOperationalPoliciesNoJsonSchema() { |
| 64 | var operationalPolicies = JSON.parse(JSON.stringify(this.loopJsonCache["operationalPolicies"])); |
| 65 | delete operationalPolicies[0]["jsonRepresentation"]; |
| 66 | return operationalPolicies; |
| 67 | } |
| 68 | |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 69 | getGlobalProperties() { |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 70 | return this.loopJsonCache["globalPropertiesJson"]; |
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 | getDcaeDeploymentProperties() { |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 74 | return this.loopJsonCache["globalPropertiesJson"]["dcaeDeployParameters"]; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 75 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 76 | |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 77 | getMicroServicePolicies() { |
| 78 | return this.loopJsonCache["microServicePolicies"]; |
| 79 | } |
| 80 | |
sebdet | c11160e | 2020-02-25 15:13:31 -0800 | [diff] [blame^] | 81 | getOperationalPolicyForName(name) { |
| 82 | var opProperties=this.getOperationalPolicies(); |
| 83 | for (var policy in opProperties) { |
| 84 | if (opProperties[policy]["name"] === name) { |
| 85 | return opProperties[policy]; |
| 86 | } |
| 87 | } |
| 88 | return null; |
| 89 | } |
| 90 | |
| 91 | getOperationalPolicyPropertiesForName(name) { |
| 92 | var opConfig = this.getOperationalPolicyForName(name); |
| 93 | if (opConfig !== null) { |
| 94 | return opConfig["properties"]; |
| 95 | } |
| 96 | return null; |
| 97 | } |
| 98 | |
| 99 | getOperationalPolicyJsonRepresentationForName(name) { |
| 100 | var opConfig = this.getOperationalPolicyForName(name); |
| 101 | if (opConfig !== null) { |
| 102 | return opConfig["jsonRepresentation"]; |
| 103 | } |
| 104 | return null; |
| 105 | } |
| 106 | |
| 107 | |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 108 | getMicroServiceForName(name) { |
| 109 | var msProperties=this.getMicroServicePolicies(); |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 110 | for (var policy in msProperties) { |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 111 | if (msProperties[policy]["name"] === name) { |
| 112 | return msProperties[policy]; |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | return null; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 116 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 117 | |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 118 | getMicroServicePropertiesForName(name) { |
| 119 | var msConfig = this.getMicroServiceForName(name); |
| 120 | if (msConfig !== null) { |
| 121 | return msConfig["properties"]; |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 122 | } |
| 123 | return null; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 124 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 125 | |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 126 | getMicroServiceJsonRepresentationForName(name) { |
| 127 | var msConfig = this.getMicroServiceForName(name); |
| 128 | if (msConfig !== null) { |
| 129 | return msConfig["jsonRepresentation"]; |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 130 | } |
| 131 | return null; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 132 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 133 | |
| 134 | getResourceDetailsVfProperty() { |
xuegao | 289e8e1 | 2019-11-08 13:10:36 +0100 | [diff] [blame] | 135 | return this.loopJsonCache["modelService"]["resourceDetails"]["VF"]; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 136 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 137 | |
| 138 | getResourceDetailsVfModuleProperty() { |
xuegao | 289e8e1 | 2019-11-08 13:10:36 +0100 | [diff] [blame] | 139 | return this.loopJsonCache["modelService"]["resourceDetails"]["VFModule"]; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 140 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 141 | |
| 142 | getLoopLogsArray() { |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 143 | return this.loopJsonCache.loopLogs; |
| 144 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 145 | |
sebdet | 190227a | 2019-07-19 16:51:19 +0200 | [diff] [blame] | 146 | getComputedState() { |
| 147 | return this.loopJsonCache.lastComputedState; |
| 148 | } |
| 149 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 150 | getComponentStates() { |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 151 | return this.loopJsonCache.components; |
| 152 | } |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 153 | } |