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=========================================================
20 package org.onap.so.sdncsimulator.controller;
22 import static org.onap.so.sdncsimulator.utils.Constants.OPERATIONS_URL;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.ws.rs.core.MediaType;
25 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
26 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
27 import org.onap.so.sdncsimulator.models.InputRequest;
28 import org.onap.so.sdncsimulator.models.Output;
29 import org.onap.so.sdncsimulator.models.OutputRequest;
30 import org.onap.so.sdncsimulator.providers.ServiceOperationsCacheServiceProvider;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired;
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.PostMapping;
38 import org.springframework.web.bind.annotation.RequestBody;
39 import org.springframework.web.bind.annotation.RequestMapping;
42 * @author Waqas Ikram (waqas.ikram@est.tech)
46 @RequestMapping(path = OPERATIONS_URL)
47 public class OperationsController {
49 private static final Logger LOGGER = LoggerFactory.getLogger(OperationsController.class);
51 private final ServiceOperationsCacheServiceProvider cacheServiceProvider;
54 public OperationsController(final ServiceOperationsCacheServiceProvider cacheServiceProvider) {
55 this.cacheServiceProvider = cacheServiceProvider;
58 @PostMapping(value = "/GENERIC-RESOURCE-API:service-topology-operation/",
59 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
60 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
61 public ResponseEntity<?> postServiceOperationInformation(
62 @RequestBody final InputRequest<GenericResourceApiServiceOperationInformation> inputRequest,
63 final HttpServletRequest request) {
64 LOGGER.info("Request Received: {} ...", inputRequest);
66 final GenericResourceApiServiceOperationInformation apiServiceOperationInformation = inputRequest.getInput();
68 if (apiServiceOperationInformation == null) {
69 LOGGER.error("Invalid input request: {}", inputRequest);
70 return ResponseEntity.badRequest().build();
73 final Output output = cacheServiceProvider.putServiceOperationInformation(apiServiceOperationInformation);
74 final OutputRequest outputRequest = new OutputRequest(output);
76 if (output.getResponseCode().equals(HttpStatus.OK.toString())) {
77 LOGGER.info("Sucessfully added service in cache sending response: {}", outputRequest);
78 return ResponseEntity.ok(outputRequest);
80 LOGGER.error("Unable to add input request: {}, will send OutputRequest: {}", inputRequest, outputRequest);
81 return ResponseEntity.badRequest().body(outputRequest);
85 @PostMapping(value = "/GENERIC-RESOURCE-API:vnf-topology-operation/",
86 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
87 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
88 public ResponseEntity<?> postVnfOperationInformation(
89 @RequestBody final InputRequest<GenericResourceApiVnfOperationInformation> inputRequest,
90 final HttpServletRequest request) {
91 LOGGER.info("Request Received: {} ...", inputRequest);
93 final GenericResourceApiVnfOperationInformation apiVnfOperationInformation = inputRequest.getInput();
94 if (apiVnfOperationInformation == null) {
95 LOGGER.error("Invalid input request: {}", inputRequest);
96 return ResponseEntity.badRequest().build();
99 final Output output = cacheServiceProvider.putVnfOperationInformation(apiVnfOperationInformation);
100 final OutputRequest outputRequest = new OutputRequest(output);
102 if (output.getResponseCode().equals(HttpStatus.OK.toString())) {
103 LOGGER.info("Sucessfully added vnf in cache sending response: {}", outputRequest);
104 return ResponseEntity.ok(outputRequest);
107 LOGGER.error("Unable to add input request: {}, will send OutputRequest: {}", inputRequest, outputRequest);
108 return ResponseEntity.badRequest().body(outputRequest);