2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2021 Nordix Foundation.
4 * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
5 * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.pap.main.rest;
25 import io.swagger.annotations.ApiOperation;
26 import io.swagger.annotations.ApiParam;
27 import io.swagger.annotations.ApiResponse;
28 import io.swagger.annotations.ApiResponses;
29 import io.swagger.annotations.Authorization;
30 import io.swagger.annotations.Extension;
31 import io.swagger.annotations.ExtensionProperty;
32 import io.swagger.annotations.ResponseHeader;
33 import java.util.UUID;
34 import lombok.RequiredArgsConstructor;
35 import org.apache.commons.lang3.tuple.Pair;
36 import org.onap.policy.models.base.PfModelException;
37 import org.onap.policy.models.pap.concepts.PdpGroupStateChangeResponse;
38 import org.onap.policy.models.pdp.enums.PdpState;
39 import org.springframework.http.HttpStatus;
40 import org.springframework.http.ResponseEntity;
41 import org.springframework.web.bind.annotation.PathVariable;
42 import org.springframework.web.bind.annotation.PutMapping;
43 import org.springframework.web.bind.annotation.RequestHeader;
44 import org.springframework.web.bind.annotation.RequestMapping;
45 import org.springframework.web.bind.annotation.RequestParam;
46 import org.springframework.web.bind.annotation.RestController;
49 * Class to provide REST end points for PAP component to change state of a PDP group.
51 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
54 @RequestMapping(path = "/policy/pap/v1")
55 @RequiredArgsConstructor
56 public class PdpGroupStateChangeControllerV1 extends PapRestControllerV1 {
58 private final PdpGroupStateChangeProvider provider;
61 * Changes state of a PDP group.
63 * @param requestId request ID used in ONAP logging
64 * @param groupName name of the PDP group to be deleted
65 * @param state state of the PDP group
67 * @throws PfModelException the exception
70 @PutMapping("pdps/groups/{name}")
71 @ApiOperation(value = "Change state of a PDP Group",
72 notes = "Changes state of PDP Group, returning optional error details",
73 response = PdpGroupStateChangeResponse.class,
74 tags = {"PdpGroup State Change"},
75 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
77 @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
78 response = String.class),
79 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
80 response = String.class),
81 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
82 response = String.class),
83 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
84 response = UUID.class)},
85 extensions = {@Extension(name = EXTENSION_NAME,
87 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
88 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
91 @ApiResponses(value = {
92 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
93 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
94 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
97 public ResponseEntity<PdpGroupStateChangeResponse> changeGroupState(
98 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader(
100 value = REQUEST_ID_NAME) final UUID requestId,
101 @ApiParam(value = "PDP Group Name") @PathVariable("name") String groupName,
102 @ApiParam(value = "PDP Group State") @RequestParam("state") final PdpState state) throws PfModelException {
104 final Pair<HttpStatus, PdpGroupStateChangeResponse> pair = provider.changeGroupState(groupName, state);
105 return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.status(pair.getLeft())), requestId)
106 .body(pair.getRight());