2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
24 package org.onap.clamp.loop;
26 import com.google.gson.JsonArray;
27 import com.google.gson.JsonObject;
28 import com.google.gson.reflect.TypeToken;
29 import java.lang.reflect.Type;
30 import java.util.List;
31 import org.onap.clamp.clds.util.JsonUtils;
32 import org.onap.clamp.policy.microservice.MicroServicePolicy;
33 import org.onap.clamp.policy.operational.OperationalPolicy;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.stereotype.Controller;
38 public class LoopController {
40 private final LoopService loopService;
41 private static final Type OPERATIONAL_POLICY_TYPE = new TypeToken<List<OperationalPolicy>>() {
44 private static final Type MICROSERVICE_POLICY_TYPE = new TypeToken<List<MicroServicePolicy>>() {
49 public LoopController(LoopService loopService) {
50 this.loopService = loopService;
53 public Loop createLoop(String loopName, String templateName) {
54 return loopService.createLoopFromTemplate(loopName, templateName);
57 public List<String> getLoopNames() {
58 return loopService.getClosedLoopNames();
61 public Loop getLoop(String loopName) {
62 return loopService.getLoop(loopName);
66 * Update the Operational Policy properties.
68 * @param loopName The loop name
69 * @param operationalPoliciesJson The new Operational Policy properties
70 * @return The updated loop
72 public Loop updateOperationalPolicies(String loopName, JsonArray operationalPoliciesJson) {
73 List<OperationalPolicy> operationalPolicies = JsonUtils.GSON.fromJson(operationalPoliciesJson,
74 OPERATIONAL_POLICY_TYPE);
75 return loopService.updateAndSaveOperationalPolicies(loopName, operationalPolicies);
79 * Update the whole array of MicroService policies properties.
81 * @param loopName The loop name
82 * @param microServicePoliciesJson The array of all MicroService policies
84 * @return The updated loop
86 public Loop updateMicroservicePolicies(String loopName, JsonArray microServicePoliciesJson) {
87 List<MicroServicePolicy> microservicePolicies = JsonUtils.GSON.fromJson(microServicePoliciesJson,
88 MICROSERVICE_POLICY_TYPE);
89 return loopService.updateAndSaveMicroservicePolicies(loopName, microservicePolicies);
93 * Update the global properties.
95 * @param loopName The loop name
96 * @param globalProperties The updated global properties
97 * @return The updated loop
99 public Loop updateGlobalPropertiesJson(String loopName, JsonObject globalProperties) {
100 return loopService.updateAndSaveGlobalPropertiesJson(loopName, globalProperties);
104 * This method add an operational policy to a loop instance.
106 * @param loopName The loop name
107 * @param policyType The policy model type
108 * @param policyVersion The policy model version
109 * @return The loop modified
111 public Loop addOperationalPolicy(String loopName, String policyType, String policyVersion) {
112 return loopService.addOperationalPolicy(loopName,policyType,policyVersion);
116 * This method deletes the loop.
118 * @param loopName The loop Name
120 public void deleteLoop(String loopName) {
121 loopService.deleteLoop(loopName);
125 * Update one MicroService policy properties.
127 * @param loopName The loop name
128 * @param newMicroservicePolicy The new MicroService policy properties
129 * @return The updated MicroService policy
131 public MicroServicePolicy updateMicroservicePolicy(String loopName, MicroServicePolicy newMicroservicePolicy) {
132 return loopService.updateMicroservicePolicy(loopName, newMicroservicePolicy);
136 * Get the SVG representation of the loop.
138 * @param loopName The loop name
139 * @return The SVG representation
141 public String getSvgRepresentation(String loopName) {
142 Loop loop = loopService.getLoop(loopName);
143 return loop != null ? loop.getSvgRepresentation() : null;
147 * Refresh the Operational Policy Json representation of the loop.
149 * @param loopName The loop name
150 * @return The refreshed Loop
152 public Loop refreshOpPolicyJsonRepresentation(String loopName) {
153 return loopService.refreshOpPolicyJsonRepresentation(loopName);