Open Kilda Java Documentation
FloodlightServiceImpl.java
Go to the documentation of this file.
1 /* Copyright 2018 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.testing.service.floodlight;
17 
18 import static java.lang.String.format;
19 
27 
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.beans.factory.annotation.Qualifier;
32 import org.springframework.http.HttpStatus;
33 import org.springframework.stereotype.Service;
34 import org.springframework.web.client.HttpServerErrorException;
35 import org.springframework.web.client.RestTemplate;
36 
37 import java.util.Arrays;
38 import java.util.List;
39 
40 @Service
41 public class FloodlightServiceImpl implements FloodlightService {
42 
43  private static final Logger LOGGER = LoggerFactory.getLogger(FloodlightServiceImpl.class);
44 
45  @Autowired
46  @Qualifier("floodlightRestTemplate")
47  private RestTemplate restTemplate;
48 
49  @Override
50  public String addStaticFlow(StaticFlowEntry flow) {
51  return restTemplate.postForObject("/wm/staticentrypusher/json", flow, String.class);
52  }
53 
54  @Override
55  public String getAliveStatus() {
56  return restTemplate.getForObject("/wm/core/controller/summary/json", String.class);
57  }
58 
59  @Override
60  public List<CoreFlowEntry> getCoreFlows(SwitchId dpId) {
61  CoreFlowEntry[] coreFlows = restTemplate.getForObject("/wm/core/switch/{dp_id}/flow/json",
62  CoreFlowEntry[].class, dpId);
63  return Arrays.asList(coreFlows);
64  }
65 
66  @Override
68  return restTemplate.getForObject("/wm/staticentrypusher/list/{dp_id}/json",
69  DpIdEntriesList.class, dpId);
70  }
71 
72  @Override
73  public List<SwitchEntry> getSwitches() {
74  SwitchEntry[] result = restTemplate.getForObject("/wm/core/controller/switches/json", SwitchEntry[].class);
75  return Arrays.asList(result);
76  }
77 
78  @Override
80  return restTemplate.getForObject("/wm/kilda/flows/switch_id/{switch_id}", FlowEntriesMap.class, dpid);
81  }
82 
83  @Override
85  try {
86  return restTemplate.getForObject("/wm/kilda/meters/switch_id/{switch_id}", MetersEntriesMap.class, dpid);
87  } catch (HttpServerErrorException ex) {
88  if (ex.getStatusCode() == HttpStatus.NOT_IMPLEMENTED) {
89  throw
90  new UnsupportedOperationException(
91  format("Switch %s doesn't support dumping of meters.", dpid),
92  ex);
93  }
94 
95  throw ex;
96  }
97  }
98 }
list result
Definition: plan-d.py:72