2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 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.so.adapters.vnfmadapter.rest;
23 import static org.onap.so.adapters.vnfmadapter.Constants.BASE_URL;
24 import java.util.UUID;
25 import javax.validation.Valid;
26 import javax.ws.rs.core.MediaType;
27 import org.onap.logging.ref.slf4j.ONAPLogConstants;
28 import org.onap.vnfmadapter.v1.model.CreateVnfRequest;
29 import org.onap.vnfmadapter.v1.model.CreateVnfResponse;
30 import org.onap.vnfmadapter.v1.model.DeleteVnfResponse;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 import org.springframework.http.HttpStatus;
35 import org.springframework.http.ResponseEntity;
36 import org.springframework.stereotype.Controller;
37 import org.springframework.web.bind.annotation.DeleteMapping;
38 import org.springframework.web.bind.annotation.PathVariable;
39 import org.springframework.web.bind.annotation.PostMapping;
40 import org.springframework.web.bind.annotation.RequestBody;
41 import org.springframework.web.bind.annotation.RequestHeader;
42 import org.springframework.web.bind.annotation.RequestMapping;
43 import io.swagger.annotations.ApiParam;
46 * Controller for handling requests to the VNFM (Virtual Network Function Manager) adapter REST API.
49 @RequestMapping(value = BASE_URL, produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
50 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
51 public class VnfmAdapterController {
53 private static final Logger logger = LoggerFactory.getLogger(VnfmAdapterController.class);
55 @PostMapping(value = "/vnfs/{vnfId}")
56 public ResponseEntity<CreateVnfResponse> vnfCreate(
57 @ApiParam(value = "The identifier of the VNF. This must be the vnf-id of an existing generic-vnf in AAI.",
58 required = true) @PathVariable("vnfId") final String vnfId,
59 @ApiParam(value = "VNF creation parameters",
60 required = true) @Valid @RequestBody final CreateVnfRequest createVnfRequest,
62 value = "Used to track REST requests for logging purposes. Identifies a single top level invocation of ONAP",
63 required = false) @RequestHeader(value = ONAPLogConstants.Headers.REQUEST_ID,
64 required = false) final String requestId,
66 value = "Used to track REST requests for logging purposes. Identifies the client application user agent or user invoking the API",
67 required = false) @RequestHeader(value = ONAPLogConstants.Headers.PARTNER_NAME,
68 required = false) final String partnerName,
70 value = "Used to track REST requests for logging purposes. Identifies a single invocation of a single component",
71 required = false) @RequestHeader(value = ONAPLogConstants.Headers.INVOCATION_ID,
72 required = false) final String invocationId) {
74 setLoggingMDCs(requestId, partnerName, invocationId);
76 logger.info("REST request vnfCreate with body: {}", createVnfRequest);
78 final CreateVnfResponse response = new CreateVnfResponse();
79 response.setJobId(UUID.randomUUID().toString());
81 return new ResponseEntity<>(response, HttpStatus.ACCEPTED);
84 @DeleteMapping(value = "/vnfs/{vnfId}")
85 public ResponseEntity<DeleteVnfResponse> vnfDelete(
86 @ApiParam(value = "The identifier of the VNF. This must be the vnf-id of an existing generic-vnf in AAI.",
87 required = true) @PathVariable("vnfId") final String vnfId,
89 value = "Used to track REST requests for logging purposes. Identifies a single top level invocation of ONAP",
90 required = false) @RequestHeader(value = ONAPLogConstants.Headers.REQUEST_ID,
91 required = false) final String requestId,
93 value = "Used to track REST requests for logging purposes. Identifies the client application user agent or user invoking the API",
94 required = false) @RequestHeader(value = ONAPLogConstants.Headers.PARTNER_NAME,
95 required = false) final String partnerName,
97 value = "Used to track REST requests for logging purposes. Identifies a single invocation of a single component",
98 required = false) @RequestHeader(value = ONAPLogConstants.Headers.INVOCATION_ID,
99 required = false) final String invocationId) {
101 setLoggingMDCs(requestId, partnerName, invocationId);
103 logger.info("REST request vnfDelete for VNF: {}", vnfId);
105 final DeleteVnfResponse response = new DeleteVnfResponse();
106 response.setJobId(UUID.randomUUID().toString());
108 return new ResponseEntity<>(response, HttpStatus.ACCEPTED);
111 private void setLoggingMDCs(final String requestId, final String partnerName, final String invocationId) {
112 MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId);
113 MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, partnerName);
114 MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
117 private void clearLoggingMDCs() {