2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.controlloop.participant.simulator.simulation.rest;
23 import io.swagger.annotations.ApiOperation;
24 import io.swagger.annotations.ApiParam;
25 import io.swagger.annotations.ApiResponse;
26 import io.swagger.annotations.ApiResponses;
27 import io.swagger.annotations.Authorization;
28 import io.swagger.annotations.Extension;
29 import io.swagger.annotations.ExtensionProperty;
30 import io.swagger.annotations.ResponseHeader;
32 import java.util.UUID;
33 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
34 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
35 import org.onap.policy.clamp.controlloop.models.messages.rest.TypedSimpleResponse;
36 import org.onap.policy.clamp.controlloop.participant.simulator.main.rest.AbstractRestController;
37 import org.onap.policy.clamp.controlloop.participant.simulator.simulation.SimulationProvider;
38 import org.springframework.http.ResponseEntity;
39 import org.springframework.web.bind.annotation.GetMapping;
40 import org.springframework.web.bind.annotation.PathVariable;
41 import org.springframework.web.bind.annotation.PutMapping;
42 import org.springframework.web.bind.annotation.RequestBody;
43 import org.springframework.web.bind.annotation.RequestHeader;
44 import org.springframework.web.bind.annotation.RestController;
47 * Class to provide REST end points for participant simulator to query/update details of controlLoopElements.
50 public class SimulationElementController extends AbstractRestController {
55 * @param simulationProvider the Simulation Provider
57 public SimulationElementController(SimulationProvider simulationProvider) {
58 super(simulationProvider);
62 * Queries details of all control loop element within the simulator.
64 * @param requestId request ID used in ONAP logging
65 * @param name the name of the Control Loop element to get, null to get all
66 * @param version the version of the Control Loop element to get, null to get all
67 * @return the control loop elements
70 @GetMapping("/elements/{name}/{version}")
72 value = "Query details of the requested simulated control loop elements",
73 notes = "Queries details of the requested simulated control loop elements, "
74 + "returning all control loop element details",
75 response = ControlLoops.class,
77 "Clamp Control Loop Participant Simulator API"
79 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
82 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
83 response = String.class),
84 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
85 response = String.class),
86 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
87 response = String.class),
88 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
89 response = UUID.class)},
93 name = EXTENSION_NAME,
95 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
96 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
103 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
104 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
105 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
109 public ResponseEntity<Map<UUID, ControlLoopElement>> elements(
111 name = REQUEST_ID_NAME,
112 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
113 @ApiParam(value = "Control loop element name", required = true) @PathVariable("name") String name,
115 value = "Control loop element version",
116 required = true) @PathVariable("version") String version) {
118 return ResponseEntity.ok().body(getSimulationProvider().getControlLoopElements(name, version));
122 * Updates a control loop element in the simulator.
124 * @param requestId request ID used in ONAP logging
125 * @param body the body of a control loop element
129 @PutMapping("/elements")
131 value = "Updates simulated control loop elements",
132 notes = "Updates simulated control loop elements, returning the updated control loop definition IDs",
133 response = TypedSimpleResponse.class,
135 "Clamp Control Loop Participant Simulator API"
137 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
140 name = VERSION_MINOR_NAME,
141 description = VERSION_MINOR_DESCRIPTION,
142 response = String.class),
144 name = VERSION_PATCH_NAME,
145 description = VERSION_PATCH_DESCRIPTION,
146 response = String.class),
148 name = VERSION_LATEST_NAME,
149 description = VERSION_LATEST_DESCRIPTION,
150 response = String.class),
152 name = REQUEST_ID_NAME,
153 description = REQUEST_ID_HDR_DESCRIPTION,
154 response = UUID.class)
159 name = EXTENSION_NAME,
161 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
162 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
169 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
170 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
171 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
175 public ResponseEntity<TypedSimpleResponse<ControlLoopElement>> update(
177 name = REQUEST_ID_NAME,
178 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
179 @ApiParam(value = "Body of a control loop element", required = true) @RequestBody ControlLoopElement body) {
181 return ResponseEntity.ok().body(getSimulationProvider().updateControlLoopElement(body));