2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.clamp.controlloop.runtime.main.rest;
24 import io.swagger.annotations.ApiOperation;
25 import io.swagger.annotations.ApiParam;
26 import io.swagger.annotations.ApiResponse;
27 import io.swagger.annotations.ApiResponses;
28 import io.swagger.annotations.Authorization;
29 import io.swagger.annotations.Extension;
30 import io.swagger.annotations.ExtensionProperty;
31 import io.swagger.annotations.ResponseHeader;
32 import java.util.UUID;
33 import lombok.RequiredArgsConstructor;
34 import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
35 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
36 import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.ControlLoopOrderStateResponse;
37 import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.ControlLoopPrimedResponse;
38 import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstancePropertiesResponse;
39 import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationCommand;
40 import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationResponse;
41 import org.onap.policy.clamp.controlloop.runtime.instantiation.ControlLoopInstantiationProvider;
42 import org.onap.policy.clamp.controlloop.runtime.main.web.AbstractRestController;
43 import org.onap.policy.models.base.PfModelException;
44 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
45 import org.springframework.http.MediaType;
46 import org.springframework.http.ResponseEntity;
47 import org.springframework.web.bind.annotation.DeleteMapping;
48 import org.springframework.web.bind.annotation.GetMapping;
49 import org.springframework.web.bind.annotation.PostMapping;
50 import org.springframework.web.bind.annotation.PutMapping;
51 import org.springframework.web.bind.annotation.RequestBody;
52 import org.springframework.web.bind.annotation.RequestHeader;
53 import org.springframework.web.bind.annotation.RequestParam;
54 import org.springframework.web.bind.annotation.RestController;
57 * Class to provide REST end points for creating, deleting, query and commanding a control loop definition.
60 @RequiredArgsConstructor
61 public class InstantiationController extends AbstractRestController {
63 private static final String TAGS = "Clamp Control Loop Instantiation API";
65 // The CL provider for instantiation requests
66 private final ControlLoopInstantiationProvider provider;
69 * Creates a control loop.
71 * @param requestId request ID used in ONAP logging
72 * @param controlLoops the control loops
74 * @throws PfModelException on errors creating a control loop
77 @PostMapping(value = "/instantiation",
78 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML},
79 consumes = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
81 value = "Commissions control loop definitions",
82 notes = "Commissions control loop definitions, returning the control loop IDs",
83 response = InstantiationResponse.class,
85 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
88 name = VERSION_MINOR_NAME,
89 description = VERSION_MINOR_DESCRIPTION,
90 response = String.class),
92 name = VERSION_PATCH_NAME,
93 description = VERSION_PATCH_DESCRIPTION,
94 response = String.class),
96 name = VERSION_LATEST_NAME,
97 description = VERSION_LATEST_DESCRIPTION,
98 response = String.class),
100 name = REQUEST_ID_NAME,
101 description = REQUEST_ID_HDR_DESCRIPTION,
102 response = UUID.class)
107 name = EXTENSION_NAME,
109 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
110 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
117 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
118 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
119 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
123 public ResponseEntity<InstantiationResponse> create(
125 name = REQUEST_ID_NAME,
126 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
127 @ApiParam(value = "Entity Body of Control Loop", required = true) @RequestBody ControlLoops controlLoops)
128 throws PfModelException {
130 return ResponseEntity.ok().body(provider.createControlLoops(controlLoops));
134 * Saves instance properties.
136 * @param requestId request ID used in ONAP logging
137 * @param body the body of control loop following TOSCA definition
141 @PostMapping(value = "/instanceProperties",
142 consumes = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML},
143 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
145 value = "Saves instance properties",
146 notes = "Saves instance properties, returning the saved instances properties and it's version",
147 response = InstancePropertiesResponse.class,
149 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
152 name = VERSION_MINOR_NAME,
153 description = VERSION_MINOR_DESCRIPTION,
154 response = String.class),
156 name = VERSION_PATCH_NAME,
157 description = VERSION_PATCH_DESCRIPTION,
158 response = String.class),
160 name = VERSION_LATEST_NAME,
161 description = VERSION_LATEST_DESCRIPTION,
162 response = String.class),
164 name = REQUEST_ID_NAME,
165 description = REQUEST_ID_HDR_DESCRIPTION,
166 response = UUID.class)
171 name = EXTENSION_NAME,
173 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
174 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
181 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
182 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
183 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
187 public ResponseEntity<InstancePropertiesResponse> createInstanceProperties(
189 name = REQUEST_ID_NAME,
190 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
191 @ApiParam(value = "Body of instance properties", required = true) @RequestBody ToscaServiceTemplate body)
192 throws PfModelException {
194 return ResponseEntity.ok().body(provider.createInstanceProperties(body));
198 * Deletes a control loop definition and instance properties.
200 * @param requestId request ID used in ONAP logging
201 * @param name the name of the control loop to delete
202 * @param version the version of the control loop to delete
204 * @throws PfModelException on errors deleting of control loop and instance properties
207 @DeleteMapping(value = "/instanceProperties",
208 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
209 @ApiOperation(value = "Delete a control loop and instance properties",
210 notes = "Deletes a control loop and instance properties, returning optional error details",
211 response = InstantiationResponse.class,
213 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
216 name = VERSION_MINOR_NAME,
217 description = VERSION_MINOR_DESCRIPTION,
218 response = String.class),
220 name = VERSION_PATCH_NAME,
221 description = VERSION_PATCH_DESCRIPTION,
222 response = String.class),
224 name = VERSION_LATEST_NAME,
225 description = VERSION_LATEST_DESCRIPTION,
226 response = String.class),
228 name = REQUEST_ID_NAME,
229 description = REQUEST_ID_HDR_DESCRIPTION,
230 response = UUID.class)},
234 name = EXTENSION_NAME,
236 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
237 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
244 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
245 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
246 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
251 public ResponseEntity<InstantiationResponse> deleteInstanceProperties(
253 name = REQUEST_ID_NAME,
254 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
255 @ApiParam(value = "Control Loop definition name", required = true) @RequestParam("name") String name,
256 @ApiParam(value = "Control Loop definition version") @RequestParam(
258 required = true) String version)
259 throws PfModelException {
261 return ResponseEntity.ok().body(provider.deleteInstanceProperties(name, version));
265 * Queries details of all control loops.
267 * @param requestId request ID used in ONAP logging
268 * @param name the name of the control loop to get, null for all control loops
269 * @param version the version of the control loop to get, null for all control loops
270 * @return the control loops
271 * @throws PfModelException on errors getting commissioning of control loop
274 @GetMapping(value = "/instantiation",
275 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
276 @ApiOperation(value = "Query details of the requested control loops",
277 notes = "Queries details of the requested control loops, returning all control loop details",
278 response = ControlLoops.class,
280 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
283 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
284 response = String.class),
285 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
286 response = String.class),
287 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
288 response = String.class),
289 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
290 response = UUID.class)},
294 name = EXTENSION_NAME,
296 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
297 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
304 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
305 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
306 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
310 public ResponseEntity<ControlLoops> query(
312 name = REQUEST_ID_NAME,
313 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
314 @ApiParam(value = "Control Loop definition name", required = false) @RequestParam(
316 required = false) String name,
317 @ApiParam(value = "Control Loop definition version", required = false) @RequestParam(
319 required = false) String version)
320 throws PfModelException {
322 return ResponseEntity.ok().body(provider.getControlLoops(name, version));
326 * Updates a control loop.
328 * @param requestId request ID used in ONAP logging
329 * @param controlLoops the control loops
331 * @throws PfModelException on errors updating of control loops
334 @PutMapping(value = "/instantiation",
335 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML},
336 consumes = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
338 value = "Updates control loop definitions",
339 notes = "Updates control loop definitions, returning the updated control loop definition IDs",
340 response = InstantiationResponse.class,
342 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
345 name = VERSION_MINOR_NAME,
346 description = VERSION_MINOR_DESCRIPTION,
347 response = String.class),
349 name = VERSION_PATCH_NAME,
350 description = VERSION_PATCH_DESCRIPTION,
351 response = String.class),
353 name = VERSION_LATEST_NAME,
354 description = VERSION_LATEST_DESCRIPTION,
355 response = String.class),
357 name = REQUEST_ID_NAME,
358 description = REQUEST_ID_HDR_DESCRIPTION,
359 response = UUID.class)
364 name = EXTENSION_NAME,
366 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
367 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
374 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
375 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
376 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
380 public ResponseEntity<InstantiationResponse> update(
382 name = REQUEST_ID_NAME,
383 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
384 @ApiParam(value = "Entity Body of Control Loop", required = true) @RequestBody ControlLoops controlLoops)
385 throws PfModelException {
387 return ResponseEntity.ok().body(provider.updateControlLoops(controlLoops));
391 * Deletes a control loop definition.
393 * @param requestId request ID used in ONAP logging
394 * @param name the name of the control loop to delete
395 * @param version the version of the control loop to delete
397 * @throws PfModelException on errors deleting of control loop
400 @DeleteMapping(value = "/instantiation",
401 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
402 @ApiOperation(value = "Delete a control loop",
403 notes = "Deletes a control loop, returning optional error details",
404 response = InstantiationResponse.class,
406 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
409 name = VERSION_MINOR_NAME,
410 description = VERSION_MINOR_DESCRIPTION,
411 response = String.class),
413 name = VERSION_PATCH_NAME,
414 description = VERSION_PATCH_DESCRIPTION,
415 response = String.class),
417 name = VERSION_LATEST_NAME,
418 description = VERSION_LATEST_DESCRIPTION,
419 response = String.class),
421 name = REQUEST_ID_NAME,
422 description = REQUEST_ID_HDR_DESCRIPTION,
423 response = UUID.class)},
427 name = EXTENSION_NAME,
429 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
430 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
437 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
438 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
439 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
444 public ResponseEntity<InstantiationResponse> delete(
446 name = REQUEST_ID_NAME,
447 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
448 @ApiParam(value = "Control Loop definition name", required = true) @RequestParam("name") String name,
449 @ApiParam(value = "Control Loop definition version") @RequestParam(
451 required = true) String version)
452 throws PfModelException {
454 return ResponseEntity.ok().body(provider.deleteControlLoop(name, version));
458 * Issues control loop commands to control loops.
460 * @param requestId request ID used in ONAP logging
461 * @param command the command to issue to control loops
462 * @return the control loop definitions
463 * @throws PfModelException on errors issuing a command
464 * @throws ControlLoopException on errors issuing a command
467 @PutMapping(value = "/instantiation/command",
468 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML},
469 consumes = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
470 @ApiOperation(value = "Issue a command to the requested control loops",
471 notes = "Issues a command to a control loop, ordering a state change on the control loop",
472 response = InstantiationResponse.class,
474 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
477 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
478 response = String.class),
479 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
480 response = String.class),
481 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
482 response = String.class),
483 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
484 response = UUID.class)},
488 name = EXTENSION_NAME,
490 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
491 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
498 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
499 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
500 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
504 public ResponseEntity<InstantiationResponse> issueControlLoopCommand(
506 name = REQUEST_ID_NAME,
507 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
509 value = "Entity Body of control loop command",
510 required = true) @RequestBody InstantiationCommand command)
511 throws ControlLoopException, PfModelException {
513 return ResponseEntity.accepted().body(provider.issueControlLoopCommand(command));
517 * Queries details of all control loops.
519 * @param requestId request ID used in ONAP logging
520 * @param name the name of the control loop to get, null for all control loops
521 * @param version the version of the control loop to get, null for all control loops
522 * @return the control loops
523 * @throws PfModelException on errors getting commissioning of control loop
526 @GetMapping(value = "/instantiationState",
527 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
528 @ApiOperation(value = "Query details of the requested control loops",
529 notes = "Queries details of the requested control loops, returning all control loop details",
530 response = ControlLoops.class,
532 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
535 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
536 response = String.class),
537 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
538 response = String.class),
539 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
540 response = String.class),
541 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
542 response = UUID.class)},
546 name = EXTENSION_NAME,
548 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
549 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
556 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
557 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
558 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
562 public ResponseEntity<ControlLoopOrderStateResponse> getInstantiationOrderState(
564 name = REQUEST_ID_NAME,
565 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
566 @ApiParam(value = "Control Loop name", required = false) @RequestParam(
568 required = false) String name,
569 @ApiParam(value = "Control Loop version", required = false) @RequestParam(
571 required = false) String version)
572 throws PfModelException {
574 return ResponseEntity.ok().body(provider.getInstantiationOrderState(name, version));
578 * Queries Primed/De-Primed status of a control loop.
580 * @param requestId request ID used in ONAP logging
581 * @param name the name of the control loop to get, null for all control loops
582 * @param version the version of the control loop to get, null for all control loops
583 * @return the control loops
584 * @throws PfModelException on errors getting priming of control loop
587 @GetMapping(value = "/controlLoopPriming",
588 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
589 @ApiOperation(value = "Query priming details of the requested control loops",
590 notes = "Queries priming details of the requested control loops, returning primed/deprimed control loops",
591 response = ControlLoopPrimedResponse.class,
593 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
596 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
597 response = String.class),
598 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
599 response = String.class),
600 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
601 response = String.class),
602 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
603 response = UUID.class)},
607 name = EXTENSION_NAME,
609 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
610 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
617 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
618 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
619 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
623 public ResponseEntity<ControlLoopPrimedResponse> getControlLoopPriming(
625 name = REQUEST_ID_NAME,
626 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
627 @ApiParam(value = "Control Loop definition name", required = false) @RequestParam(
629 required = false) String name,
630 @ApiParam(value = "Control Loop definition version", required = false) @RequestParam(
632 required = false) String version)
633 throws PfModelException {
635 return ResponseEntity.ok().body(provider.getControlLoopPriming(name, version));