blob: c54337f2f0b588c9cab42742e4190ad7126cff0f [file] [log] [blame]
sebdetc8d61302019-07-04 15:50:34 +02001/*-
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 * ===================================================================
xuegaof248df62019-07-15 15:16:18 +020021 *
sebdetc8d61302019-07-04 15:50:34 +020022 */
sebdete44fdb12019-07-12 12:25:56 +020023
sebdet493c3832019-07-15 17:26:18 +020024export default class LoopCache {
sebdete44fdb12019-07-12 12:25:56 +020025 loopJsonCache;
26
27 constructor(loopJson) {
28 this.loopJsonCache=loopJson;
sebdetc8d61302019-07-04 15:50:34 +020029 }
sebdet4946e5b2019-07-10 12:32:36 +020030
sebdetb65f1212019-08-23 07:49:25 -070031 updateMicroServiceProperties(name, newMsProperties) {
sebdet4946e5b2019-07-10 12:32:36 +020032 for (var policy in this.loopJsonCache["microServicePolicies"]) {
sebdetb65f1212019-08-23 07:49:25 -070033 if (this.loopJsonCache["microServicePolicies"][policy]["name"] === name) {
sebdet58135b82020-02-27 11:39:50 -080034 this.loopJsonCache["microServicePolicies"][policy]["configurationsJson"] = newMsProperties;
sebdet4946e5b2019-07-10 12:32:36 +020035 }
36 }
sebdetc8d61302019-07-04 15:50:34 +020037 }
sebdet4946e5b2019-07-10 12:32:36 +020038
xuegao635445a2020-03-02 11:37:20 +010039 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
sebdet4946e5b2019-07-10 12:32:36 +020048 updateGlobalProperties(newGlobalProperties) {
49 this.loopJsonCache["globalPropertiesJson"] = newGlobalProperties;
sebdetc8d61302019-07-04 15:50:34 +020050 }
sebdet4946e5b2019-07-10 12:32:36 +020051
xuegao635445a2020-03-02 11:37:20 +010052 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 }
sebdetc8d61302019-07-04 15:50:34 +020067 }
sebdet4946e5b2019-07-10 12:32:36 +020068
69 getLoopName() {
70 return this.loopJsonCache["name"];
sebdetc8d61302019-07-04 15:50:34 +020071 }
sebdet4946e5b2019-07-10 12:32:36 +020072
sebdetf9e2cee2019-08-09 18:36:09 +020073 getOperationalPolicyJsonSchema() {
xuegaoc488fed2019-12-19 11:58:45 +010074 return this.loopJsonCache["operationalPolicies"]["0"]["jsonRepresentation"];
sebdetf9e2cee2019-08-09 18:36:09 +020075 }
sebdet4946e5b2019-07-10 12:32:36 +020076
77 getOperationalPolicies() {
sebdet2df6c082019-07-18 15:29:45 +020078 return this.loopJsonCache["operationalPolicies"];
sebdetc8d61302019-07-04 15:50:34 +020079 }
sebdet4946e5b2019-07-10 12:32:36 +020080
xuegaoc488fed2019-12-19 11:58:45 +010081 getOperationalPoliciesNoJsonSchema() {
82 var operationalPolicies = JSON.parse(JSON.stringify(this.loopJsonCache["operationalPolicies"]));
83 delete operationalPolicies[0]["jsonRepresentation"];
84 return operationalPolicies;
85 }
86
sebdet493c3832019-07-15 17:26:18 +020087 getGlobalProperties() {
sebdet2df6c082019-07-18 15:29:45 +020088 return this.loopJsonCache["globalPropertiesJson"];
sebdetc8d61302019-07-04 15:50:34 +020089 }
sebdet4946e5b2019-07-10 12:32:36 +020090
sebdet493c3832019-07-15 17:26:18 +020091 getDcaeDeploymentProperties() {
sebdet2df6c082019-07-18 15:29:45 +020092 return this.loopJsonCache["globalPropertiesJson"]["dcaeDeployParameters"];
sebdetc8d61302019-07-04 15:50:34 +020093 }
sebdet4946e5b2019-07-10 12:32:36 +020094
sebdet2df6c082019-07-18 15:29:45 +020095 getMicroServicePolicies() {
96 return this.loopJsonCache["microServicePolicies"];
97 }
98
sebdetc11160e2020-02-25 15:13:31 -080099 getOperationalPolicyForName(name) {
100 var opProperties=this.getOperationalPolicies();
101 for (var policy in opProperties) {
102 if (opProperties[policy]["name"] === name) {
103 return opProperties[policy];
104 }
105 }
106 return null;
107 }
108
109 getOperationalPolicyPropertiesForName(name) {
110 var opConfig = this.getOperationalPolicyForName(name);
111 if (opConfig !== null) {
sebdet58135b82020-02-27 11:39:50 -0800112 return opConfig["configurationsJson"];
sebdetc11160e2020-02-25 15:13:31 -0800113 }
114 return null;
115 }
116
117 getOperationalPolicyJsonRepresentationForName(name) {
xuegao635445a2020-03-02 11:37:20 +0100118 var opConfig = this.getOperationalPolicyForName(name);
119 if (opConfig !== null) {
120 return opConfig["jsonRepresentation"];
121 }
122 return null;
123 }
sebdetc11160e2020-02-25 15:13:31 -0800124
sebdet2dd4e992020-03-04 15:47:39 -0800125 getOperationalPolicySupportedPdpGroup(name) {
xuegao635445a2020-03-02 11:37:20 +0100126 var opConfig=this.getOperationalPolicyForName(name);
127 if (opConfig !== null) {
sebdet2dd4e992020-03-04 15:47:39 -0800128 if (opConfig["policyModel"]["policyPdpGroup"] !== undefined && opConfig["policyModel"]["policyPdpGroup"]["supportedPdpGroups"] !== undefined) {
129 return opConfig["policyModel"]["policyPdpGroup"]["supportedPdpGroups"];
130 }
xuegao635445a2020-03-02 11:37:20 +0100131 }
sebdet2dd4e992020-03-04 15:47:39 -0800132 return [];
xuegao635445a2020-03-02 11:37:20 +0100133 }
134
135 getOperationalPolicyPdpGroup(name) {
136 var opConfig=this.getOperationalPolicyForName(name);
137 if (opConfig !== null) {
138 return opConfig["pdpGroup"];
139 }
140 return null;
141 }
142
143 getOperationalPolicyPdpSubgroup(name) {
144 var opConfig=this.getOperationalPolicyForName(name);
145 if (opConfig !== null) {
146 return opConfig["pdpSubgroup"];
147 }
148 return null;
149 }
150
sebdet2dd4e992020-03-04 15:47:39 -0800151 getMicroServiceSupportedPdpGroup(name) {
xuegao635445a2020-03-02 11:37:20 +0100152 var microService=this.getMicroServiceForName(name);
153 if (microService !== null) {
sebdet2dd4e992020-03-04 15:47:39 -0800154 if (microService["policyModel"]["policyPdpGroup"] !== undefined && microService["policyModel"]["policyPdpGroup"]["supportedPdpGroups"] !== undefined) {
155 return microService["policyModel"]["policyPdpGroup"]["supportedPdpGroups"];
156 }
xuegao635445a2020-03-02 11:37:20 +0100157 }
sebdet2dd4e992020-03-04 15:47:39 -0800158 return [];
xuegao635445a2020-03-02 11:37:20 +0100159 }
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 }
sebdetc11160e2020-02-25 15:13:31 -0800176
sebdet2df6c082019-07-18 15:29:45 +0200177 getMicroServiceForName(name) {
178 var msProperties=this.getMicroServicePolicies();
sebdet4946e5b2019-07-10 12:32:36 +0200179 for (var policy in msProperties) {
sebdet2df6c082019-07-18 15:29:45 +0200180 if (msProperties[policy]["name"] === name) {
181 return msProperties[policy];
sebdet4946e5b2019-07-10 12:32:36 +0200182 }
183 }
184 return null;
sebdetc8d61302019-07-04 15:50:34 +0200185 }
sebdet4946e5b2019-07-10 12:32:36 +0200186
sebdet2df6c082019-07-18 15:29:45 +0200187 getMicroServicePropertiesForName(name) {
188 var msConfig = this.getMicroServiceForName(name);
189 if (msConfig !== null) {
sebdet58135b82020-02-27 11:39:50 -0800190 return msConfig["configurationsJson"];
sebdet4946e5b2019-07-10 12:32:36 +0200191 }
192 return null;
sebdetc8d61302019-07-04 15:50:34 +0200193 }
sebdet4946e5b2019-07-10 12:32:36 +0200194
sebdet2df6c082019-07-18 15:29:45 +0200195 getMicroServiceJsonRepresentationForName(name) {
196 var msConfig = this.getMicroServiceForName(name);
197 if (msConfig !== null) {
198 return msConfig["jsonRepresentation"];
sebdet4946e5b2019-07-10 12:32:36 +0200199 }
200 return null;
sebdetc8d61302019-07-04 15:50:34 +0200201 }
sebdet4946e5b2019-07-10 12:32:36 +0200202
203 getResourceDetailsVfProperty() {
xuegao289e8e12019-11-08 13:10:36 +0100204 return this.loopJsonCache["modelService"]["resourceDetails"]["VF"];
sebdetc8d61302019-07-04 15:50:34 +0200205 }
sebdet4946e5b2019-07-10 12:32:36 +0200206
207 getResourceDetailsVfModuleProperty() {
xuegao289e8e12019-11-08 13:10:36 +0100208 return this.loopJsonCache["modelService"]["resourceDetails"]["VFModule"];
sebdetc8d61302019-07-04 15:50:34 +0200209 }
sebdet4946e5b2019-07-10 12:32:36 +0200210
211 getLoopLogsArray() {
sebdetc8d61302019-07-04 15:50:34 +0200212 return this.loopJsonCache.loopLogs;
213 }
sebdet4946e5b2019-07-10 12:32:36 +0200214
sebdet190227a2019-07-19 16:51:19 +0200215 getComputedState() {
216 return this.loopJsonCache.lastComputedState;
217 }
218
sebdet4946e5b2019-07-10 12:32:36 +0200219 getComponentStates() {
sebdetc8d61302019-07-04 15:50:34 +0200220 return this.loopJsonCache.components;
221 }
sebdetc8d61302019-07-04 15:50:34 +0200222}