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.so.adapters.vnfmadapter.lifecycle.LifecycleManager;
29 import org.onap.vnfmadapter.v1.model.CreateVnfRequest;
30 import org.onap.vnfmadapter.v1.model.CreateVnfResponse;
31 import org.onap.vnfmadapter.v1.model.DeleteVnfResponse;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.http.HttpStatus;
37 import org.springframework.http.ResponseEntity;
38 import org.springframework.stereotype.Controller;
39 import org.springframework.web.bind.annotation.DeleteMapping;
40 import org.springframework.web.bind.annotation.PathVariable;
41 import org.springframework.web.bind.annotation.PostMapping;
42 import org.springframework.web.bind.annotation.RequestBody;
43 import org.springframework.web.bind.annotation.RequestHeader;
44 import org.springframework.web.bind.annotation.RequestMapping;
45 import io.swagger.annotations.ApiParam;
48 * Controller for handling requests to the VNFM (Virtual Network Function Manager) adapter REST API.
51 @RequestMapping(value = BASE_URL, produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
52 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
53 public class VnfmAdapterController {
55 private static final Logger logger = LoggerFactory.getLogger(VnfmAdapterController.class);
56 private final LifecycleManager lifecycleManager;
59 VnfmAdapterController(final LifecycleManager lifecycleManager) {
60 this.lifecycleManager = lifecycleManager;
63 @PostMapping(value = "/vnfs/{vnfId}")
64 public ResponseEntity<CreateVnfResponse> vnfCreate(
65 @ApiParam(value = "The identifier of the VNF. This must be the vnf-id of an existing generic-vnf in AAI.",
66 required = true) @PathVariable("vnfId") final String vnfId,
67 @ApiParam(value = "VNF creation parameters",
68 required = true) @Valid @RequestBody final CreateVnfRequest createVnfRequest,
70 value = "Used to track REST requests for logging purposes. Identifies a single top level invocation of ONAP",
71 required = false) @RequestHeader(value = ONAPLogConstants.Headers.REQUEST_ID,
72 required = false) final String requestId,
74 value = "Used to track REST requests for logging purposes. Identifies the client application user agent or user invoking the API",
75 required = false) @RequestHeader(value = ONAPLogConstants.Headers.PARTNER_NAME,
76 required = false) final String partnerName,
78 value = "Used to track REST requests for logging purposes. Identifies a single invocation of a single component",
79 required = false) @RequestHeader(value = ONAPLogConstants.Headers.INVOCATION_ID,
80 required = false) final String invocationId) {
82 setLoggingMDCs(requestId, partnerName, invocationId);
84 logger.info("REST request vnfCreate with body: {}", createVnfRequest);
86 final CreateVnfResponse createVnfResponse = lifecycleManager.createVnf(vnfId, createVnfRequest);
88 return new ResponseEntity<>(createVnfResponse, HttpStatus.ACCEPTED);
91 @DeleteMapping(value = "/vnfs/{vnfId}")
92 public ResponseEntity<DeleteVnfResponse> vnfDelete(
93 @ApiParam(value = "The identifier of the VNF. This must be the vnf-id of an existing generic-vnf in AAI.",
94 required = true) @PathVariable("vnfId") final String vnfId,
96 value = "Used to track REST requests for logging purposes. Identifies a single top level invocation of ONAP",
97 required = false) @RequestHeader(value = ONAPLogConstants.Headers.REQUEST_ID,
98 required = false) final String requestId,
100 value = "Used to track REST requests for logging purposes. Identifies the client application user agent or user invoking the API",
101 required = false) @RequestHeader(value = ONAPLogConstants.Headers.PARTNER_NAME,
102 required = false) final String partnerName,
104 value = "Used to track REST requests for logging purposes. Identifies a single invocation of a single component",
105 required = false) @RequestHeader(value = ONAPLogConstants.Headers.INVOCATION_ID,
106 required = false) final String invocationId) {
108 setLoggingMDCs(requestId, partnerName, invocationId);
110 logger.info("REST request vnfDelete for VNF: {}", vnfId);
112 final DeleteVnfResponse response = new DeleteVnfResponse();
113 response.setJobId(UUID.randomUUID().toString());
115 return new ResponseEntity<>(response, HttpStatus.ACCEPTED);
118 private void setLoggingMDCs(final String requestId, final String partnerName, final String invocationId) {
119 MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId);
120 MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, partnerName);
121 MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
124 private void clearLoggingMDCs() {