03cec9fa617b10ef058c512a2480c8649c87245a
[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(name, newMsProperties) {
32                         for (var policy in this.loopJsonCache["microServicePolicies"]) {
33                                 if (this.loopJsonCache["microServicePolicies"][policy]["name"] === name) {
34                                         this.loopJsonCache["microServicePolicies"][policy]["configurationsJson"] = 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         getOperationalPolicyJsonSchema() {
56                 return this.loopJsonCache["operationalPolicies"]["0"]["jsonRepresentation"];
57         }
58
59         getOperationalPolicies() {
60                 return this.loopJsonCache["operationalPolicies"];
61         }
62
63         getOperationalPoliciesNoJsonSchema() {
64                 var operationalPolicies = JSON.parse(JSON.stringify(this.loopJsonCache["operationalPolicies"]));
65                 delete operationalPolicies[0]["jsonRepresentation"];
66                 return operationalPolicies;
67         }
68
69         getGlobalProperties() {
70                 return this.loopJsonCache["globalPropertiesJson"];
71         }
72
73         getDcaeDeploymentProperties() {
74                 return this.loopJsonCache["globalPropertiesJson"]["dcaeDeployParameters"];
75         }
76
77         getMicroServicePolicies() {
78                 return this.loopJsonCache["microServicePolicies"];
79         }
80
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["configurationsJson"];
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
108         getMicroServiceForName(name) {
109                 var msProperties=this.getMicroServicePolicies();
110                 for (var policy in msProperties) {
111                         if (msProperties[policy]["name"] === name) {
112                                 return msProperties[policy];
113                         }
114                 }
115                 return null;
116         }
117
118         getMicroServicePropertiesForName(name) {
119                 var msConfig = this.getMicroServiceForName(name);
120                 if (msConfig !== null) {
121                         return msConfig["configurationsJson"];
122                 }
123                 return null;
124         }
125
126         getMicroServiceJsonRepresentationForName(name) {
127                 var msConfig = this.getMicroServiceForName(name);
128                 if (msConfig !== null) {
129                         return msConfig["jsonRepresentation"];
130                 }
131                 return null;
132         }
133
134         getResourceDetailsVfProperty() {
135                 return this.loopJsonCache["modelService"]["resourceDetails"]["VF"];
136         }
137
138         getResourceDetailsVfModuleProperty() {
139                 return this.loopJsonCache["modelService"]["resourceDetails"]["VFModule"];
140         }
141
142         getLoopLogsArray() {
143                 return this.loopJsonCache.loopLogs;
144         }
145
146         getComputedState() {
147                 return this.loopJsonCache.lastComputedState;
148         }
149
150         getComponentStates() {
151                 return this.loopJsonCache.components;
152         }
153 }