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 | * =================================================================== |
| 21 | * |
| 22 | */ |
sebdet | e44fdb1 | 2019-07-12 12:25:56 +0200 | [diff] [blame^] | 23 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 24 | class LoopCache { |
sebdet | e44fdb1 | 2019-07-12 12:25:56 +0200 | [diff] [blame^] | 25 | loopJsonCache; |
| 26 | |
| 27 | constructor(loopJson) { |
| 28 | this.loopJsonCache=loopJson; |
| 29 | //LoopCache.SET_LOOP_JSON_CACHE(require('./example.json'); |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 30 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 31 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 32 | updateMsProperties(type, newMsProperties) { |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 33 | if (newMsProperties["name"] == type) { |
| 34 | for (var policy in this.loopJsonCache["microServicePolicies"]) { |
| 35 | if (this.loopJsonCache["microServicePolicies"][policy]["name"] == type) { |
| 36 | this.loopJsonCache["microServicePolicies"][policy] = newMsProperties; |
| 37 | } |
| 38 | } |
| 39 | } |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 40 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 41 | |
| 42 | updateGlobalProperties(newGlobalProperties) { |
| 43 | this.loopJsonCache["globalPropertiesJson"] = newGlobalProperties; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 44 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 45 | |
| 46 | updateOpPolicyProperties(newOpProperties) { |
| 47 | this.loopJsonCache["operationalPolicies"] = newOpProperties; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 48 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 49 | |
| 50 | getLoopName() { |
| 51 | return this.loopJsonCache["name"]; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 52 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 53 | |
| 54 | getOperationalPolicyProperty() { |
| 55 | return JSON.parse(JSON.stringify(this.loopJsonCache["operationalPolicies"]["0"]["configurationsJson"])); |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 56 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 57 | |
| 58 | getOperationalPolicies() { |
| 59 | return JSON.parse(JSON.stringify(this.loopJsonCache["operationalPolicies"])); |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 60 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 61 | |
| 62 | getGlobalProperty() { |
| 63 | return JSON.parse(JSON.stringify(this.loopJsonCache["globalPropertiesJson"])); |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 64 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 65 | |
| 66 | getDeploymentProperties() { |
| 67 | return JSON.parse(JSON.stringify(this.loopJsonCache["globalPropertiesJson"]["dcaeDeployParameters"])); |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 68 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 69 | |
| 70 | getMsJson(type) { |
| 71 | var msProperties = this.loopJsonCache["microServicePolicies"]; |
| 72 | for (var policy in msProperties) { |
| 73 | if (msProperties[policy]["name"] == type) { |
| 74 | return JSON.parse(JSON.stringify(msProperties[policy])); |
| 75 | } |
| 76 | } |
| 77 | return null; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 78 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 79 | |
| 80 | getMsProperty(type) { |
| 81 | var msProperties = this.loopJsonCache["microServicePolicies"]; |
| 82 | for (var policy in msProperties) { |
| 83 | if (msProperties[policy]["name"] == type) { |
| 84 | if (msProperties[policy]["properties"] !== null && msProperties[policy]["properties"] !== undefined) { |
| 85 | return JSON.parse(JSON.stringify(msProperties[policy]["properties"])); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | return null; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 90 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 91 | |
| 92 | getMsUI(type) { |
| 93 | var msProperties = this.loopJsonCache["microServicePolicies"]; |
| 94 | for (var policy in msProperties) { |
| 95 | if (msProperties[policy]["name"] == type) { |
| 96 | return JSON.parse(JSON.stringify(msProperties[policy]["jsonRepresentation"])); |
| 97 | } |
| 98 | } |
| 99 | return null; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 100 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 101 | |
| 102 | getResourceDetailsVfProperty() { |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 103 | return this.loopJsonCache["modelPropertiesJson"]["resourceDetails"]["VF"]; |
| 104 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 105 | |
| 106 | getResourceDetailsVfModuleProperty() { |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 107 | return this.loopJsonCache["modelPropertiesJson"]["resourceDetails"]["VFModule"]; |
| 108 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 109 | |
| 110 | getLoopLogsArray() { |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 111 | return this.loopJsonCache.loopLogs; |
| 112 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 113 | |
| 114 | getComponentStates() { |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 115 | return this.loopJsonCache.components; |
| 116 | } |
| 117 | |
sebdet | e44fdb1 | 2019-07-12 12:25:56 +0200 | [diff] [blame^] | 118 | get getLoopJsonCache() { |
| 119 | return this.loopJsonCache; |
| 120 | } |
| 121 | |
| 122 | set setLoopJsonCache(newJson) { |
| 123 | this.loopJsonCache = newJson; |
| 124 | } |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 125 | } |
sebdet | e44fdb1 | 2019-07-12 12:25:56 +0200 | [diff] [blame^] | 126 | |
| 127 | export const LOOP_CACHE = new LoopCache(require('./example.json')); |
| 128 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 129 | export default LoopCache; |