3ee5acc68d3e0136d0896bad6546312a2cd0d4e2
[clamp.git] / ui-react / src / api / LoopCache.js
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  */
23
24 export default class LoopCache {
25         loopJsonCache;
26
27         constructor(loopJson) {
28                 this.loopJsonCache=loopJson;
29         }
30
31         updateMicroServiceProperties(type, newMsProperties) {
32                         for (var policy in this.loopJsonCache["microServicePolicies"]) {
33                                 if (this.loopJsonCache["microServicePolicies"][policy]["name"] === type) {
34                                         this.loopJsonCache["microServicePolicies"][policy]["properties"] = newMsProperties;
35                                 }
36                         }
37         }
38
39         updateGlobalProperties(newGlobalProperties) {
40                 this.loopJsonCache["globalPropertiesJson"] = newGlobalProperties;
41         }
42
43         updateOperationalPolicyProperties(newOpProperties) {
44                 this.loopJsonCache["operationalPolicies"] = newOpProperties;
45         }
46
47         getLoopName() {
48                 return this.loopJsonCache["name"];
49         }
50
51         getOperationalPolicyConfigurationJson() {
52                 return this.loopJsonCache["operationalPolicies"]["0"]["configurationsJson"];
53         }
54
55         getOperationalPolicies() {
56                 return this.loopJsonCache["operationalPolicies"];
57         }
58
59         getGlobalProperties() {
60                 return this.loopJsonCache["globalPropertiesJson"];
61         }
62
63         getDcaeDeploymentProperties() {
64                 return this.loopJsonCache["globalPropertiesJson"]["dcaeDeployParameters"];
65         }
66
67         getMicroServicePolicies() {
68                 return this.loopJsonCache["microServicePolicies"];
69         }
70
71         getMicroServiceForName(name) {
72                 var msProperties=this.getMicroServicePolicies();
73                 for (var policy in msProperties) {
74                         if (msProperties[policy]["name"] === name) {
75                                 return msProperties[policy];
76                         }
77                 }
78                 return null;
79         }
80
81         getMicroServicePropertiesForName(name) {
82                 var msConfig = this.getMicroServiceForName(name);
83                 if (msConfig !== null) {
84                         return msConfig["properties"];
85                 }
86                 return null;
87         }
88
89         getMicroServiceJsonRepresentationForName(name) {
90                 var msConfig = this.getMicroServiceForName(name);
91                 if (msConfig !== null) {
92                         return msConfig["jsonRepresentation"];
93                 }
94                 return null;
95         }
96
97         getResourceDetailsVfProperty() {
98                 return this.loopJsonCache["modelPropertiesJson"]["resourceDetails"]["VF"];
99         }
100
101         getResourceDetailsVfModuleProperty() {
102                 return this.loopJsonCache["modelPropertiesJson"]["resourceDetails"]["VFModule"];
103         }
104
105         getLoopLogsArray() {
106                 return this.loopJsonCache.loopLogs;
107         }
108
109         getComputedState() {
110                 return this.loopJsonCache.lastComputedState;
111         }
112
113         getComponentStates() {
114                 return this.loopJsonCache.components;
115         }
116 }