Search in sources :

Example 6 with UnexpectedResponseStatusException

use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException in project cloud-pipeline by epam.

the class GitlabClient method getRepositoryRevisions.

public List<GitTagEntry> getRepositoryRevisions(Long pageSize) throws GitClientException {
    try {
        String projectId = makeProjectId(namespace, projectName);
        Map<String, Object> params = new HashMap<>();
        if (pageSize != null) {
            params.put("per_page", pageSize);
        }
        String url = addUrlParameters(String.format(GIT_REVISIONS, gitHost, projectId), params);
        URI uri = new URI(url);
        LOGGER.trace("Getting repository revisions from URL: {}", uri);
        RestTemplate template = new RestTemplate();
        ResponseEntity<List<GitTagEntry>> sourcesResponse = template.exchange(uri, HttpMethod.GET, getAuthHeaders(), new ParameterizedTypeReference<List<GitTagEntry>>() {
        });
        if (sourcesResponse.getStatusCode() == HttpStatus.OK) {
            return sourcesResponse.getBody();
        } else {
            throw new UnexpectedResponseStatusException(sourcesResponse.getStatusCode());
        }
    } catch (UnsupportedEncodingException | URISyntaxException e) {
        throw new GitClientException(e);
    }
}
Also used : HashMap(java.util.HashMap) UnexpectedResponseStatusException(com.epam.pipeline.exception.git.UnexpectedResponseStatusException) GitClientException(com.epam.pipeline.exception.git.GitClientException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) RestTemplate(org.springframework.web.client.RestTemplate) List(java.util.List)

Example 7 with UnexpectedResponseStatusException

use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException in project cloud-pipeline by epam.

the class GitlabClient method getCommits.

public List<GitCommitEntry> getCommits(String refName, Date since, Date until) throws GitClientException {
    try {
        String projectId = makeProjectId(namespace, projectName);
        Map<String, Object> params = new HashMap<>();
        if (refName != null) {
            params.put("ref_name", refName);
        }
        TimeZone tz = TimeZone.getTimeZone("UTC");
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        df.setTimeZone(tz);
        if (since != null) {
            params.put("since", df.format(since));
        }
        if (until != null) {
            params.put("until", df.format(until));
        }
        String url = addUrlParameters(String.format(GIT_COMMITS, gitHost, projectId), params);
        URI uri = new URI(url);
        LOGGER.trace("Getting repository commits from URL: {}", uri);
        RestTemplate template = new RestTemplate();
        ResponseEntity<List<GitCommitEntry>> sourcesResponse = template.exchange(uri, HttpMethod.GET, getAuthHeaders(), new ParameterizedTypeReference<List<GitCommitEntry>>() {
        });
        if (sourcesResponse.getStatusCode() == HttpStatus.OK) {
            return sourcesResponse.getBody();
        } else {
            throw new UnexpectedResponseStatusException(sourcesResponse.getStatusCode());
        }
    } catch (UnsupportedEncodingException | URISyntaxException | HttpClientErrorException e) {
        throw new GitClientException(e.getMessage(), e);
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HashMap(java.util.HashMap) UnexpectedResponseStatusException(com.epam.pipeline.exception.git.UnexpectedResponseStatusException) GitClientException(com.epam.pipeline.exception.git.GitClientException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) TimeZone(java.util.TimeZone) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) RestTemplate(org.springframework.web.client.RestTemplate) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat)

Example 8 with UnexpectedResponseStatusException

use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException in project cloud-pipeline by epam.

the class GitlabClient method createRepo.

private GitProject createRepo(String repoName, String description) throws UnexpectedResponseStatusException, URISyntaxException {
    HttpHeaders headers = new HttpHeaders();
    headers.add(TOKEN_HEADER, token);
    Map<String, String> parameters = new HashMap<>();
    parameters.put("name", repoName);
    if (!StringUtils.isEmpty(description)) {
        parameters.put("description", description);
    }
    parameters.put("visibility", PUBLIC_VISIBILITY);
    HttpEntity entity = new HttpEntity<>(parameters, headers);
    URI uri = new URI(String.format(GIT_POST_PROJECT_URL, gitHost));
    LOGGER.trace("Creating repo {}, URL: {}, token: {}", repoName, uri, token);
    ResponseEntity<GitProject> response = new RestTemplate().exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference<GitProject>() {
    });
    if (response.getStatusCode() == HttpStatus.CREATED) {
        return response.getBody();
    } else {
        throw new UnexpectedResponseStatusException(response.getStatusCode());
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap) UnexpectedResponseStatusException(com.epam.pipeline.exception.git.UnexpectedResponseStatusException) GitProject(com.epam.pipeline.entity.git.GitProject) RestTemplate(org.springframework.web.client.RestTemplate) URI(java.net.URI)

Example 9 with UnexpectedResponseStatusException

use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException in project cloud-pipeline by epam.

the class GitlabClient method getVersion.

/**
 * Loads Gitlab version information
 * @return a GitlabVersion object
 * @throws GitClientException
 */
public GitlabVersion getVersion() throws GitClientException {
    try {
        URI uri = new URI(String.format(GITLAB_VERSION_URL, gitHost));
        ResponseEntity<GitlabVersion> versionResponse = new RestTemplate().exchange(uri, HttpMethod.GET, getAuthHeaders(), GitlabVersion.class);
        if (versionResponse.getStatusCode() == HttpStatus.OK) {
            return versionResponse.getBody();
        } else {
            throw new UnexpectedResponseStatusException(versionResponse.getStatusCode());
        }
    } catch (URISyntaxException e) {
        throw new GitClientException(e.getMessage(), e);
    }
}
Also used : GitlabVersion(com.epam.pipeline.entity.git.GitlabVersion) UnexpectedResponseStatusException(com.epam.pipeline.exception.git.UnexpectedResponseStatusException) RestTemplate(org.springframework.web.client.RestTemplate) GitClientException(com.epam.pipeline.exception.git.GitClientException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 10 with UnexpectedResponseStatusException

use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException in project cloud-pipeline by epam.

the class DockerClient method executeDeletion.

private void executeDeletion(String url, String image) {
    try {
        URI uri = new URI(url);
        HttpStatus status = getRestTemplate().execute(uri, HttpMethod.DELETE, request -> request.getHeaders().putAll(getAuthHeaders().getHeaders()), ClientHttpResponse::getStatusCode);
        if (status != HttpStatus.ACCEPTED) {
            throw new UnexpectedResponseStatusException(status);
        }
    } catch (URISyntaxException | UnexpectedResponseStatusException e) {
        throw new DockerConnectionException(url, e.getMessage());
    } catch (HttpClientErrorException e) {
        if (e.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
            LOGGER.error("Image not found:" + image);
            return;
        }
        throw new DockerConnectionException(url, e.getMessage());
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HttpStatus(org.springframework.http.HttpStatus) UnexpectedResponseStatusException(com.epam.pipeline.exception.git.UnexpectedResponseStatusException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) DockerConnectionException(com.epam.pipeline.exception.docker.DockerConnectionException)

Aggregations

UnexpectedResponseStatusException (com.epam.pipeline.exception.git.UnexpectedResponseStatusException)19 URI (java.net.URI)19 URISyntaxException (java.net.URISyntaxException)15 RestTemplate (org.springframework.web.client.RestTemplate)14 GitClientException (com.epam.pipeline.exception.git.GitClientException)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 HashMap (java.util.HashMap)8 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)8 HttpEntity (org.springframework.http.HttpEntity)6 DockerConnectionException (com.epam.pipeline.exception.docker.DockerConnectionException)4 HttpHeaders (org.springframework.http.HttpHeaders)4 List (java.util.List)3 GitCommitEntry (com.epam.pipeline.entity.git.GitCommitEntry)2 GitProject (com.epam.pipeline.entity.git.GitProject)2 GitRepositoryEntry (com.epam.pipeline.entity.git.GitRepositoryEntry)2 GitTagEntry (com.epam.pipeline.entity.git.GitTagEntry)2 PipelineSourceItemErrorVO (com.epam.pipeline.controller.vo.PipelineSourceItemErrorVO)1 ManifestV2 (com.epam.pipeline.entity.docker.ManifestV2)1 RawImageDescription (com.epam.pipeline.entity.docker.RawImageDescription)1 RegistryListing (com.epam.pipeline.entity.docker.RegistryListing)1