Open Kilda Java Documentation
LinkController.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.northbound.controller;
17 
24 
25 import io.swagger.annotations.Api;
26 import io.swagger.annotations.ApiOperation;
27 import io.swagger.annotations.ApiResponse;
28 import io.swagger.annotations.ApiResponses;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.context.annotation.PropertySource;
31 import org.springframework.http.HttpStatus;
32 import org.springframework.http.MediaType;
33 import org.springframework.web.bind.annotation.GetMapping;
34 import org.springframework.web.bind.annotation.RequestBody;
35 import org.springframework.web.bind.annotation.RequestMapping;
36 import org.springframework.web.bind.annotation.RequestMethod;
37 import org.springframework.web.bind.annotation.RequestParam;
38 import org.springframework.web.bind.annotation.ResponseStatus;
39 import org.springframework.web.bind.annotation.RestController;
40 
41 import java.util.List;
42 
46 @RestController
47 @PropertySource("classpath:northbound.properties")
48 @Api
49 @ApiResponses(value = {
50  @ApiResponse(code = 200, message = "Operation is successful"),
51  @ApiResponse(code = 400, response = MessageError.class, message = "Invalid input data"),
52  @ApiResponse(code = 401, response = MessageError.class, message = "Unauthorized"),
53  @ApiResponse(code = 403, response = MessageError.class, message = "Forbidden"),
54  @ApiResponse(code = 404, response = MessageError.class, message = "Not found"),
55  @ApiResponse(code = 500, response = MessageError.class, message = "General error"),
56  @ApiResponse(code = 503, response = MessageError.class, message = "Service unavailable")})
57 public class LinkController {
58 
59  @Autowired
60  private LinkService linkService;
61 
67  @ApiOperation(value = "Get all links", response = LinkDto.class, responseContainer = "List")
68  @GetMapping(path = "/links")
69  @ResponseStatus(HttpStatus.OK)
70  public List<LinkDto> getLinks() {
71  return linkService.getLinks();
72  }
73 
79  @ApiOperation(value = "Get all link properties (static), based on arguments.", response = LinkPropsDto.class,
80  responseContainer = "List")
81  @RequestMapping(path = "/link/props",
82  method = RequestMethod.GET,
83  produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
84  @ResponseStatus(HttpStatus.OK)
85  public List<LinkPropsDto> getLinkProps(@RequestParam(value = "src_switch", required = false) SwitchId srcSwitch,
86  @RequestParam(value = "src_port", required = false) Integer srcPort,
87  @RequestParam(value = "dst_switch", required = false) SwitchId dstSwitch,
88  @RequestParam(value = "dst_port", required = false) Integer dstPort) {
89  return linkService.getLinkProps(srcSwitch, srcPort, dstSwitch, dstPort);
90  }
91 
98  @ApiOperation(value = "Create/Update link properties", response = BatchResults.class)
99  @RequestMapping(path = "/link/props",
100  method = RequestMethod.PUT,
101  produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
102  @ResponseStatus(HttpStatus.OK)
103  public BatchResults putLinkProps(
104  @RequestBody List<LinkPropsDto> keysAndProps) {
105  return linkService.setLinkProps(keysAndProps);
106  }
107 
114  @ApiOperation(value = "Delete link properties (static), based on arguments.", response = BatchResults.class)
115  @RequestMapping(path = "/link/props",
116  method = RequestMethod.DELETE,
117  produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
118  @ResponseStatus(HttpStatus.OK)
119  public BatchResults delLinkProps(
120  @RequestBody List<LinkPropsDto> keysAndProps) {
121  return linkService.delLinkProps(keysAndProps);
122  }
123 }
value
Definition: nodes.py:62