Search in sources :

Example 26 with UriComponentsBuilder

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 27 with UriComponentsBuilder

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);
}
Also used : FlowHistoryEntry(org.openkilda.messaging.payload.history.FlowHistoryEntry) HttpEntity(org.springframework.http.HttpEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 28 with UriComponentsBuilder

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);
}
Also used : HttpEntity(org.springframework.http.HttpEntity) FlowLoopResponse(org.openkilda.northbound.dto.v2.flows.FlowLoopResponse) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 29 with UriComponentsBuilder

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;
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) HttpResponse(org.apache.http.HttpResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException)

Example 30 with UriComponentsBuilder

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;
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) HttpResponse(org.apache.http.HttpResponse) LinkProps(org.openkilda.model.LinkProps) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException)

Aggregations

UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)162 Test (org.junit.Test)34 UriComponents (org.springframework.web.util.UriComponents)24 HttpEntity (org.springframework.http.HttpEntity)18 ServletUriComponentsBuilder (org.springframework.web.servlet.support.ServletUriComponentsBuilder)13 URI (java.net.URI)10 Test (org.junit.jupiter.api.Test)9 HttpHeaders (org.springframework.http.HttpHeaders)9 MvcUriComponentsBuilder (org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder)9 ArrayList (java.util.ArrayList)8 SearchRequest (org.nzbhydra.searching.searchrequests.SearchRequest)8 List (java.util.List)7 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)7 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)6 User (com.serotonin.m2m2.vo.User)5 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5