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) throws PfModelException {
260 return ResponseEntity.ok().body(provider.deleteInstanceProperties(name, version));
264 * Queries details of all control loops.
266 * @param requestId request ID used in ONAP logging
267 * @param name the name of the control loop to get, null for all control loops
268 * @param version the version of the control loop to get, null for all control loops
269 * @return the control loops
270 * @throws PfModelException on errors getting commissioning of control loop
273 @GetMapping(value = "/instantiation",
274 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
275 @ApiOperation(value = "Query details of the requested control loops",
276 notes = "Queries details of the requested control loops, returning all control loop details",
277 response = ControlLoops.class,
279 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
282 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
283 response = String.class),
284 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
285 response = String.class),
286 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
287 response = String.class),
288 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
289 response = UUID.class)},
293 name = EXTENSION_NAME,
295 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
296 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
303 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
304 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
305 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
309 public ResponseEntity<ControlLoops> query(
311 name = REQUEST_ID_NAME,
312 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
313 @ApiParam(value = "Control Loop definition name", required = false) @RequestParam(
315 required = false) String name,
316 @ApiParam(value = "Control Loop definition version", required = false) @RequestParam(
318 required = false) String version)
319 throws PfModelException {
321 return ResponseEntity.ok().body(provider.getControlLoops(name, version));
325 * Updates a control loop.
327 * @param requestId request ID used in ONAP logging
328 * @param controlLoops the control loops
330 * @throws PfModelException on errors updating of control loops
333 @PutMapping(value = "/instantiation",
334 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML},
335 consumes = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
337 value = "Updates control loop definitions",
338 notes = "Updates control loop definitions, returning the updated control loop definition IDs",
339 response = InstantiationResponse.class,
341 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
344 name = VERSION_MINOR_NAME,
345 description = VERSION_MINOR_DESCRIPTION,
346 response = String.class),
348 name = VERSION_PATCH_NAME,
349 description = VERSION_PATCH_DESCRIPTION,
350 response = String.class),
352 name = VERSION_LATEST_NAME,
353 description = VERSION_LATEST_DESCRIPTION,
354 response = String.class),
356 name = REQUEST_ID_NAME,
357 description = REQUEST_ID_HDR_DESCRIPTION,
358 response = UUID.class)
363 name = EXTENSION_NAME,
365 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
366 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
373 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
374 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
375 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
379 public ResponseEntity<InstantiationResponse> update(
381 name = REQUEST_ID_NAME,
382 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
383 @ApiParam(value = "Entity Body of Control Loop", required = true) @RequestBody ControlLoops controlLoops)
384 throws PfModelException {
386 return ResponseEntity.ok().body(provider.updateControlLoops(controlLoops));
390 * Deletes a control loop definition.
392 * @param requestId request ID used in ONAP logging
393 * @param name the name of the control loop to delete
394 * @param version the version of the control loop to delete
396 * @throws PfModelException on errors deleting of control loop
399 @DeleteMapping(value = "/instantiation",
400 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
401 @ApiOperation(value = "Delete a control loop",
402 notes = "Deletes a control loop, returning optional error details",
403 response = InstantiationResponse.class,
405 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
408 name = VERSION_MINOR_NAME,
409 description = VERSION_MINOR_DESCRIPTION,
410 response = String.class),
412 name = VERSION_PATCH_NAME,
413 description = VERSION_PATCH_DESCRIPTION,
414 response = String.class),
416 name = VERSION_LATEST_NAME,
417 description = VERSION_LATEST_DESCRIPTION,
418 response = String.class),
420 name = REQUEST_ID_NAME,
421 description = REQUEST_ID_HDR_DESCRIPTION,
422 response = UUID.class)},
426 name = EXTENSION_NAME,
428 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
429 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
436 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
437 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
438 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
443 public ResponseEntity<InstantiationResponse> delete(
445 name = REQUEST_ID_NAME,
446 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
447 @ApiParam(value = "Control Loop definition name", required = true) @RequestParam("name") String name,
448 @ApiParam(value = "Control Loop definition version") @RequestParam(
450 required = false) String version)
451 throws PfModelException {
453 return ResponseEntity.ok().body(provider.deleteControlLoop(name, version));
457 * Issues control loop commands to control loops.
459 * @param requestId request ID used in ONAP logging
460 * @param command the command to issue to control loops
461 * @return the control loop definitions
462 * @throws PfModelException on errors issuing a command
463 * @throws ControlLoopException on errors issuing a command
466 @PutMapping(value = "/instantiation/command",
467 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML},
468 consumes = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
469 @ApiOperation(value = "Issue a command to the requested control loops",
470 notes = "Issues a command to a control loop, ordering a state change on the control loop",
471 response = InstantiationResponse.class,
473 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
476 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
477 response = String.class),
478 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
479 response = String.class),
480 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
481 response = String.class),
482 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
483 response = UUID.class)},
487 name = EXTENSION_NAME,
489 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
490 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
497 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
498 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
499 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
503 public ResponseEntity<InstantiationResponse> issueControlLoopCommand(
505 name = REQUEST_ID_NAME,
506 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
508 value = "Entity Body of control loop command",
509 required = true) @RequestBody InstantiationCommand command)
510 throws ControlLoopException, PfModelException {
512 return ResponseEntity.accepted().body(provider.issueControlLoopCommand(command));
516 * Queries details of all control loops.
518 * @param requestId request ID used in ONAP logging
519 * @param name the name of the control loop to get, null for all control loops
520 * @param version the version of the control loop to get, null for all control loops
521 * @return the control loops
522 * @throws PfModelException on errors getting commissioning of control loop
525 @GetMapping(value = "/instantiationState",
526 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
527 @ApiOperation(value = "Query details of the requested control loops",
528 notes = "Queries details of the requested control loops, returning all control loop details",
529 response = ControlLoops.class,
531 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
534 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
535 response = String.class),
536 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
537 response = String.class),
538 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
539 response = String.class),
540 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
541 response = UUID.class)},
545 name = EXTENSION_NAME,
547 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
548 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
555 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
556 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
557 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
561 public ResponseEntity<ControlLoopOrderStateResponse> getInstantiationOrderState(
563 name = REQUEST_ID_NAME,
564 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
565 @ApiParam(value = "Control Loop name", required = false) @RequestParam(
567 required = false) String name,
568 @ApiParam(value = "Control Loop version", required = false) @RequestParam(
570 required = false) String version)
571 throws PfModelException {
573 return ResponseEntity.ok().body(provider.getInstantiationOrderState(name, version));
577 * Queries Primed/De-Primed status of a control loop.
579 * @param requestId request ID used in ONAP logging
580 * @param name the name of the control loop to get, null for all control loops
581 * @param version the version of the control loop to get, null for all control loops
582 * @return the control loops
583 * @throws PfModelException on errors getting priming of control loop
586 @GetMapping(value = "/controlLoopPriming",
587 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
588 @ApiOperation(value = "Query priming details of the requested control loops",
589 notes = "Queries priming details of the requested control loops, returning primed/deprimed control loops",
590 response = ControlLoopPrimedResponse.class,
592 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
595 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
596 response = String.class),
597 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
598 response = String.class),
599 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
600 response = String.class),
601 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
602 response = UUID.class)},
606 name = EXTENSION_NAME,
608 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
609 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
616 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
617 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
618 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
622 public ResponseEntity<ControlLoopPrimedResponse> getControlLoopPriming(
624 name = REQUEST_ID_NAME,
625 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
626 @ApiParam(value = "Control Loop definition name", required = false) @RequestParam(
628 required = false) String name,
629 @ApiParam(value = "Control Loop definition version", required = false) @RequestParam(
631 required = false) String version)
632 throws PfModelException {
634 return ResponseEntity.ok().body(provider.getControlLoopPriming(name, version));