use of org.springframework.web.util.UriComponentsBuilder in project open-kilda by telstra.
the class NorthboundServiceImpl method installSwitchRules.
@Override
public List<Long> installSwitchRules(SwitchId switchId, InstallRulesAction installAction) {
UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString("/api/v1/switches/{switch_id}/rules");
uriBuilder.queryParam("install-action", installAction);
HttpHeaders httpHeaders = buildHeadersWithCorrelationId();
httpHeaders.set(Utils.EXTRA_AUTH, String.valueOf(System.currentTimeMillis()));
Long[] installedRules = restTemplate.exchange(uriBuilder.build().toString(), HttpMethod.PUT, new HttpEntity(httpHeaders), Long[].class, switchId).getBody();
return Arrays.asList(installedRules);
}
use of org.springframework.web.util.UriComponentsBuilder in project open-kilda by telstra.
the class NorthboundServiceImpl method getFlowHistory.
@Override
public List<FlowHistoryEntry> getFlowHistory(String flowId, Long timeFrom, Long timeTo, Integer maxCount) {
UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString("/api/v1/flows/{flow_id}/history");
if (timeFrom != null) {
uriBuilder.queryParam("timeFrom", timeFrom);
}
if (timeTo != null) {
uriBuilder.queryParam("timeTo", timeTo);
}
if (maxCount != null) {
uriBuilder.queryParam("max_count", maxCount);
}
FlowHistoryEntry[] flowHistory = restTemplate.exchange(uriBuilder.build().toString(), HttpMethod.GET, new HttpEntity(buildHeadersWithCorrelationId()), FlowHistoryEntry[].class, flowId).getBody();
return Arrays.asList(flowHistory);
}
use of org.springframework.web.util.UriComponentsBuilder in project open-kilda by telstra.
the class NorthboundServiceV2Impl method getFlowLoop.
@Override
public List<FlowLoopResponse> getFlowLoop(String flowId, SwitchId switchId) {
UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString("/api/v2/flows/loops");
if (flowId != null) {
uriBuilder.queryParam("flow_id", flowId);
}
if (switchId != null) {
uriBuilder.queryParam("switch_id", switchId);
}
FlowLoopResponse[] flowLoopResponse = restTemplate.exchange(uriBuilder.build().toString(), HttpMethod.GET, new HttpEntity(buildHeadersWithCorrelationId()), FlowLoopResponse[].class).getBody();
return Arrays.asList(flowLoopResponse);
}
use of org.springframework.web.util.UriComponentsBuilder in project open-kilda by telstra.
the class FlowsIntegrationService method getFlowHistoryById.
/**
* Gets the flow history by id.
*
* @param flowId the flow id
* @return the flow history by id
*/
public List<FlowHistory> getFlowHistoryById(final String flowId, String timeFrom, String timeTo) throws IntegrationException {
try {
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(applicationProperties.getNbBaseUrl() + IConstants.NorthBoundUrl.GET_FLOW_HISTORY.replace("{flow_id}", UriUtils.encodePath(flowId, "UTF-8")));
builder = setFlowTimestamp(timeFrom, timeTo, builder);
String fullUri = builder.build().toUriString();
HttpResponse response = restClientManager.invoke(fullUri, HttpMethod.GET, "", "", applicationService.getAuthHeader());
if (RestClientManager.isValidResponse(response)) {
return restClientManager.getResponseList(response, FlowHistory.class);
}
return null;
} catch (InvalidResponseException e) {
LOGGER.error("Error occurred while retriving flow history with id: " + flowId, e);
throw new InvalidResponseException(e.getCode(), e.getResponse());
} catch (UnsupportedEncodingException e) {
LOGGER.error("Error occurred while retriving flow history with id: " + flowId, e);
e.printStackTrace();
}
return null;
}
use of org.springframework.web.util.UriComponentsBuilder in project open-kilda by telstra.
the class SwitchIntegrationService method getIslLinkProps.
/**
* Gets the isl link cost.
*
* @return the isl link cost
*/
public List<LinkProps> getIslLinkProps(final LinkProps keys) {
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(applicationProperties.getNbBaseUrl() + IConstants.NorthBoundUrl.GET_LINK_PROPS);
builder = setLinkProps(keys, builder);
String fullUri = builder.build().toUriString();
HttpResponse response = restClientManager.invoke(fullUri, HttpMethod.GET, "", "", applicationService.getAuthHeader());
try {
if (RestClientManager.isValidResponse(response)) {
List<LinkProps> linkPropsResponses = restClientManager.getResponseList(response, LinkProps.class);
if (!CollectionUtil.isEmpty(linkPropsResponses)) {
return linkPropsResponses;
}
}
} catch (InvalidResponseException e) {
LOGGER.warn("Error occurred while getting isl link props ", e);
return null;
}
return null;
}
Aggregations