Aharoni, Pavel (pa0916) | 0a8080c | 2018-11-22 15:45:19 +0200 | [diff] [blame] | 1 | /*-
|
| 2 | * ============LICENSE_START=======================================================
|
| 3 | * OSAM
|
| 4 | * ================================================================================
|
| 5 | * Copyright (C) 2018 AT&T
|
| 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
|
| 10 | *
|
| 11 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 12 | *
|
| 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.
|
| 18 | * ============LICENSE_END=========================================================
|
| 19 | */
|
| 20 | package org.onap.osam.controllers;
|
| 21 |
|
| 22 | import io.swagger.annotations.ApiOperation;
|
| 23 | import io.swagger.annotations.ApiParam;
|
| 24 | import org.onap.osam.common.dto.ChassisDTO;
|
| 25 | import org.onap.osam.common.dto.OLTChassisDTO;
|
| 26 | import org.onap.osam.common.dto.ONTDTO;
|
| 27 | import org.springframework.beans.factory.annotation.Autowired;
|
| 28 | import org.springframework.core.ParameterizedTypeReference;
|
| 29 | import org.springframework.http.HttpEntity;
|
| 30 | import org.springframework.http.HttpMethod;
|
| 31 | import org.springframework.http.ResponseEntity;
|
| 32 | import org.springframework.web.bind.annotation.*;
|
| 33 | import org.springframework.web.client.RestTemplate;
|
| 34 |
|
| 35 | import java.util.List;
|
| 36 | import java.util.Map;
|
| 37 |
|
| 38 | // TODO log
|
| 39 | @RestController
|
| 40 | @RequestMapping("device/chassis")
|
| 41 | public class OnapEnablerDeviceController extends OnapEnablerController {
|
| 42 |
|
| 43 | private static final String DEVICE_CHASSIS = "device/chassis";
|
| 44 |
|
| 45 | @Autowired
|
| 46 | public OnapEnablerDeviceController(RestTemplate restTemplate){
|
| 47 | this.restTemplate = restTemplate;
|
| 48 | }
|
| 49 |
|
| 50 | @ApiOperation(value = "Register a chassis on top of a POD",
|
| 51 | response = ChassisDTO.class)
|
| 52 | @RequestMapping(method = RequestMethod.POST)
|
| 53 | public ResponseEntity<ChassisDTO> postChassis(@RequestBody ChassisDTO chassisDTO) {
|
| 54 | return restTemplate.postForEntity(buildRequestPath(DEVICE_CHASSIS), new HttpEntity<>(chassisDTO), ChassisDTO.class);
|
| 55 | }
|
| 56 |
|
| 57 | @ApiOperation(value = "Unregister a chassis from a POD")
|
| 58 | @RequestMapping(method = RequestMethod.DELETE, value = "{clli}")
|
| 59 | public void deleteChassisByClli(@PathVariable String clli) {
|
| 60 | restTemplate.delete(buildRequestPath(DEVICE_CHASSIS, clli));
|
| 61 | }
|
| 62 |
|
| 63 | @ApiOperation(value = "Register OLT-specific chassis on top of a chassis",
|
| 64 | response = OLTChassisDTO.class)
|
| 65 | @RequestMapping(method = RequestMethod.POST, value = "olt")
|
| 66 | public ResponseEntity<OLTChassisDTO> postOLTChassis(@RequestBody OLTChassisDTO oltChassisDTO) {
|
| 67 | return restTemplate.postForEntity(buildRequestPath(DEVICE_CHASSIS, "olt"), new HttpEntity<>(oltChassisDTO), OLTChassisDTO.class);
|
| 68 | }
|
| 69 |
|
| 70 | @ApiOperation(value = "Register an ONT device on top of a OLT-specific chassis",
|
| 71 | response = ONTDTO.class)
|
| 72 | @RequestMapping(method = RequestMethod.POST, value = "olt/ont")
|
| 73 | public ResponseEntity<ONTDTO> postONTDevice(@RequestBody ONTDTO ontDTO) {
|
| 74 | return restTemplate.postForEntity(buildRequestPath(DEVICE_CHASSIS, "olt/ont"), new HttpEntity<>(ontDTO), ONTDTO.class);
|
| 75 | }
|
| 76 |
|
| 77 | @ApiOperation(value = "Get all chassis entities from all PODs",
|
| 78 | response = ChassisDTO.class,
|
| 79 | responseContainer = "List")
|
| 80 | @RequestMapping(method = RequestMethod.GET)
|
| 81 | public ResponseEntity<List<ChassisDTO>> getAllChassis() {
|
| 82 | return restTemplate.exchange(buildRequestPath(DEVICE_CHASSIS), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference<List<ChassisDTO>>(){});
|
| 83 | }
|
| 84 |
|
| 85 |
|
| 86 | @ApiOperation(value = "Get all OLT-specific chassis entities from all PODs, grouped by POD pnfId",
|
| 87 | response = OLTChassisDTO.class,
|
| 88 | responseContainer = "Map")
|
| 89 | @RequestMapping(method = RequestMethod.GET, value = "olt")
|
| 90 | public ResponseEntity<Map<String, List<OLTChassisDTO>>> getAllOLTDevices(){
|
| 91 | return restTemplate.exchange(buildRequestPath(DEVICE_CHASSIS, "olt"), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference<Map<String, List<OLTChassisDTO>>>(){});
|
| 92 | }
|
| 93 |
|
| 94 | @ApiOperation(value = "Get all ONT devices from all PODs, grouped by POD pnfId",
|
| 95 | response = ONTDTO.class,
|
| 96 | responseContainer = "Map")
|
| 97 | @RequestMapping(method = RequestMethod.GET, value = "olt/ont")
|
| 98 | public ResponseEntity<Map<String, List<ONTDTO>>> getAllONTDevices(){
|
| 99 | return restTemplate.exchange(buildRequestPath(DEVICE_CHASSIS, "olt/ont"), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference<Map<String, List<ONTDTO>>>(){});
|
| 100 | }
|
| 101 | }
|