Open Kilda Java Documentation
TopologyEngineServiceImpl.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.topology;
17 
22 
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.beans.factory.annotation.Qualifier;
27 import org.springframework.core.ParameterizedTypeReference;
28 import org.springframework.http.HttpMethod;
29 import org.springframework.http.HttpStatus;
30 import org.springframework.stereotype.Service;
31 import org.springframework.web.client.HttpClientErrorException;
32 import org.springframework.web.client.RestTemplate;
33 
34 import java.util.Arrays;
35 import java.util.List;
36 
37 @Service
39 
40  private static final Logger LOGGER = LoggerFactory.getLogger(TopologyEngineServiceImpl.class);
41 
42  @Autowired
43  @Qualifier("topologyEngineRestTemplate")
44  private RestTemplate restTemplate;
45 
46  @Override
47  public Integer getLinkBandwidth(SwitchId srcSwitch, SwitchId srcPort) {
48  return restTemplate.getForObject("/api/v1/topology/links/bandwidth/{src_switch}/{src_port}", Integer.class,
49  srcSwitch, srcPort);
50  }
51 
52  @Override
53  public List<Flow> getAllFlows() {
54  Flow[] links = restTemplate.getForObject("/api/v1/topology/flows", Flow[].class);
55  return Arrays.asList(links);
56  }
57 
58  @Override
59  public ImmutablePair<Flow, Flow> getFlow(String flowId) {
60  try {
61  return restTemplate.exchange("/api/v1/topology/flows/{flow_id}", HttpMethod.GET, null,
62  new ParameterizedTypeReference<ImmutablePair<Flow, Flow>>() {
63  }, flowId).getBody();
64  } catch (HttpClientErrorException ex) {
65  if (ex.getStatusCode() != HttpStatus.NOT_FOUND) {
66  throw ex;
67  }
68 
69  return null;
70  }
71  }
72 
73  @Override
74  public void restoreFlows() {
75  restTemplate.getForObject("/api/v1/flows/restore", String.class);
76  }
77 
78  @Override
79  public String clearTopology() {
80  return restTemplate.getForObject("/api/v1/topology/clear", String.class);
81  }
82 
83  @Override
84  public List<PathInfoData> getPaths(SwitchId srcSwitch, SwitchId dstSwitch) {
85  PathInfoData[] paths = restTemplate
86  .getForObject("/api/v1/topology/routes/src/{src_switch}/dst/{dst_switch}",
87  PathInfoData[].class, srcSwitch, dstSwitch);
88  return Arrays.asList(paths);
89  }
90 }
List< PathInfoData > getPaths(SwitchId srcSwitch, SwitchId dstSwitch)