blob: c73ed62b5c364748753942e7f66399765bd5beeb [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) {
sebdet2df6c082019-07-18 15:29:45 +020034 this.loopJsonCache["microServicePolicies"][policy]["properties"] = newMsProperties;
sebdet4946e5b2019-07-10 12:32:36 +020035 }
36 }
sebdetc8d61302019-07-04 15:50:34 +020037 }
sebdet4946e5b2019-07-10 12:32:36 +020038
39 updateGlobalProperties(newGlobalProperties) {
40 this.loopJsonCache["globalPropertiesJson"] = newGlobalProperties;
sebdetc8d61302019-07-04 15:50:34 +020041 }
sebdet4946e5b2019-07-10 12:32:36 +020042
sebdet493c3832019-07-15 17:26:18 +020043 updateOperationalPolicyProperties(newOpProperties) {
sebdet4946e5b2019-07-10 12:32:36 +020044 this.loopJsonCache["operationalPolicies"] = newOpProperties;
sebdetc8d61302019-07-04 15:50:34 +020045 }
sebdet4946e5b2019-07-10 12:32:36 +020046
47 getLoopName() {
48 return this.loopJsonCache["name"];
sebdetc8d61302019-07-04 15:50:34 +020049 }
sebdet4946e5b2019-07-10 12:32:36 +020050
sebdet493c3832019-07-15 17:26:18 +020051 getOperationalPolicyConfigurationJson() {
sebdet2df6c082019-07-18 15:29:45 +020052 return this.loopJsonCache["operationalPolicies"]["0"]["configurationsJson"];
sebdetc8d61302019-07-04 15:50:34 +020053 }
sebdetf9e2cee2019-08-09 18:36:09 +020054
55 getOperationalPolicyJsonSchema() {
xuegaoc488fed2019-12-19 11:58:45 +010056 return this.loopJsonCache["operationalPolicies"]["0"]["jsonRepresentation"];
sebdetf9e2cee2019-08-09 18:36:09 +020057 }
sebdet4946e5b2019-07-10 12:32:36 +020058
59 getOperationalPolicies() {
sebdet2df6c082019-07-18 15:29:45 +020060 return this.loopJsonCache["operationalPolicies"];
sebdetc8d61302019-07-04 15:50:34 +020061 }
sebdet4946e5b2019-07-10 12:32:36 +020062
xuegaoc488fed2019-12-19 11:58:45 +010063 getOperationalPoliciesNoJsonSchema() {
64 var operationalPolicies = JSON.parse(JSON.stringify(this.loopJsonCache["operationalPolicies"]));
65 delete operationalPolicies[0]["jsonRepresentation"];
66 return operationalPolicies;
67 }
68
sebdet493c3832019-07-15 17:26:18 +020069 getGlobalProperties() {
sebdet2df6c082019-07-18 15:29:45 +020070 return this.loopJsonCache["globalPropertiesJson"];
sebdetc8d61302019-07-04 15:50:34 +020071 }
sebdet4946e5b2019-07-10 12:32:36 +020072
sebdet493c3832019-07-15 17:26:18 +020073 getDcaeDeploymentProperties() {
sebdet2df6c082019-07-18 15:29:45 +020074 return this.loopJsonCache["globalPropertiesJson"]["dcaeDeployParameters"];
sebdetc8d61302019-07-04 15:50:34 +020075 }
sebdet4946e5b2019-07-10 12:32:36 +020076
sebdet2df6c082019-07-18 15:29:45 +020077 getMicroServicePolicies() {
78 return this.loopJsonCache["microServicePolicies"];
79 }
80
81 getMicroServiceForName(name) {
82 var msProperties=this.getMicroServicePolicies();
sebdet4946e5b2019-07-10 12:32:36 +020083 for (var policy in msProperties) {
sebdet2df6c082019-07-18 15:29:45 +020084 if (msProperties[policy]["name"] === name) {
85 return msProperties[policy];
sebdet4946e5b2019-07-10 12:32:36 +020086 }
87 }
88 return null;
sebdetc8d61302019-07-04 15:50:34 +020089 }
sebdet4946e5b2019-07-10 12:32:36 +020090
sebdet2df6c082019-07-18 15:29:45 +020091 getMicroServicePropertiesForName(name) {
92 var msConfig = this.getMicroServiceForName(name);
93 if (msConfig !== null) {
94 return msConfig["properties"];
sebdet4946e5b2019-07-10 12:32:36 +020095 }
96 return null;
sebdetc8d61302019-07-04 15:50:34 +020097 }
sebdet4946e5b2019-07-10 12:32:36 +020098
sebdet2df6c082019-07-18 15:29:45 +020099 getMicroServiceJsonRepresentationForName(name) {
100 var msConfig = this.getMicroServiceForName(name);
101 if (msConfig !== null) {
102 return msConfig["jsonRepresentation"];
sebdet4946e5b2019-07-10 12:32:36 +0200103 }
104 return null;
sebdetc8d61302019-07-04 15:50:34 +0200105 }
sebdet4946e5b2019-07-10 12:32:36 +0200106
107 getResourceDetailsVfProperty() {
xuegao289e8e12019-11-08 13:10:36 +0100108 return this.loopJsonCache["modelService"]["resourceDetails"]["VF"];
sebdetc8d61302019-07-04 15:50:34 +0200109 }
sebdet4946e5b2019-07-10 12:32:36 +0200110
111 getResourceDetailsVfModuleProperty() {
xuegao289e8e12019-11-08 13:10:36 +0100112 return this.loopJsonCache["modelService"]["resourceDetails"]["VFModule"];
sebdetc8d61302019-07-04 15:50:34 +0200113 }
sebdet4946e5b2019-07-10 12:32:36 +0200114
115 getLoopLogsArray() {
sebdetc8d61302019-07-04 15:50:34 +0200116 return this.loopJsonCache.loopLogs;
117 }
sebdet4946e5b2019-07-10 12:32:36 +0200118
sebdet190227a2019-07-19 16:51:19 +0200119 getComputedState() {
120 return this.loopJsonCache.lastComputedState;
121 }
122
sebdet4946e5b2019-07-10 12:32:36 +0200123 getComponentStates() {
sebdetc8d61302019-07-04 15:50:34 +0200124 return this.loopJsonCache.components;
125 }
sebdetc8d61302019-07-04 15:50:34 +0200126}