Search in sources :

Example 1 with UnexpectedResponseStatusException

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

the class DockerClient method getRegistryEntries.

public Set<String> getRegistryEntries() {
    try {
        URI uri = new URI(String.format(LIST_REGISTRY_URL, hostName));
        HttpEntity entity = getAuthHeaders();
        ResponseEntity<RegistryListing> response = getRestTemplate().exchange(uri, HttpMethod.GET, entity, new ParameterizedTypeReference<RegistryListing>() {
        });
        if (response.getStatusCode() == HttpStatus.OK) {
            return response.getBody().getRepositories();
        } else {
            throw new UnexpectedResponseStatusException(response.getStatusCode());
        }
    } catch (URISyntaxException | UnexpectedResponseStatusException e) {
        LOGGER.error(e.getMessage(), e);
        return Collections.emptySet();
    }
}
Also used : HttpEntity(org.springframework.http.HttpEntity) UnexpectedResponseStatusException(com.epam.pipeline.exception.git.UnexpectedResponseStatusException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) RegistryListing(com.epam.pipeline.entity.docker.RegistryListing)

Example 2 with UnexpectedResponseStatusException

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

the class DockerClient method getImageTags.

public List<String> getImageTags(String registryPath, String image) {
    String url = String.format(TAGS_LIST, registryPath, image);
    try {
        URI uri = new URI(url);
        HttpEntity entity = getAuthHeaders();
        ResponseEntity<TagsListing> response = getRestTemplate().exchange(uri, HttpMethod.GET, entity, new ParameterizedTypeReference<TagsListing>() {
        });
        if (response.getStatusCode() == HttpStatus.OK) {
            return response.getBody().getTags();
        } else {
            throw new UnexpectedResponseStatusException(response.getStatusCode());
        }
    } catch (URISyntaxException | HttpClientErrorException | UnexpectedResponseStatusException e) {
        LOGGER.error(e.getMessage(), e);
        throw new DockerConnectionException(url, e.getMessage());
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HttpEntity(org.springframework.http.HttpEntity) TagsListing(com.epam.pipeline.entity.docker.TagsListing) UnexpectedResponseStatusException(com.epam.pipeline.exception.git.UnexpectedResponseStatusException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) DockerConnectionException(com.epam.pipeline.exception.docker.DockerConnectionException)

Example 3 with UnexpectedResponseStatusException

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

the class GitlabClient method commit.

public GitCommitEntry commit(GitPushCommitEntry commitEntry) throws GitClientException {
    try {
        String projectId = makeProjectId(namespace, projectName);
        String url = addUrlParameters(String.format(GIT_COMMITS, gitHost, projectId), null);
        URI uri = new URI(url);
        LOGGER.trace("Performing commit; URL: {}", uri);
        HttpHeaders headers = new HttpHeaders();
        headers.add(TOKEN_HEADER, token);
        HttpEntity entity = new HttpEntity<>(commitEntry, headers);
        ResponseEntity<GitCommitEntry> response = new RestTemplate().exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference<GitCommitEntry>() {
        });
        if (response.getStatusCode() == HttpStatus.OK || response.getStatusCode() == HttpStatus.CREATED) {
            return response.getBody();
        } else {
            throw new UnexpectedResponseStatusException(response.getStatusCode());
        }
    } catch (HttpClientErrorException e) {
        ObjectMapper mapper = new ObjectMapper();
        try {
            PipelineSourceItemErrorVO error = mapper.readValue(e.getResponseBodyAsByteArray(), PipelineSourceItemErrorVO.class);
            throw new GitClientException(error.getMessage());
        } catch (IOException e1) {
            throw new GitClientException(e.getMessage(), e);
        }
    } catch (UnsupportedEncodingException | URISyntaxException e) {
        throw new GitClientException(e.getMessage(), e);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HttpEntity(org.springframework.http.HttpEntity) UnexpectedResponseStatusException(com.epam.pipeline.exception.git.UnexpectedResponseStatusException) GitClientException(com.epam.pipeline.exception.git.GitClientException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) RestTemplate(org.springframework.web.client.RestTemplate) PipelineSourceItemErrorVO(com.epam.pipeline.controller.vo.PipelineSourceItemErrorVO) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GitCommitEntry(com.epam.pipeline.entity.git.GitCommitEntry)

Example 4 with UnexpectedResponseStatusException

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

the class GitlabClient method getRepositoryCommit.

public GitCommitEntry getRepositoryCommit(String commitId) throws GitClientException {
    try {
        String projectId = makeProjectId(namespace, projectName);
        String url = addUrlParameters(String.format(GIT_GET_COMMIT, gitHost, projectId, commitId), new HashMap<>());
        URI uri = new URI(url);
        LOGGER.trace("Getting repository commit {} from URL: {}", commitId, uri);
        RestTemplate template = new RestTemplate();
        ResponseEntity<GitCommitEntry> sourcesResponse = template.exchange(uri, HttpMethod.GET, getAuthHeaders(), new ParameterizedTypeReference<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) 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) GitCommitEntry(com.epam.pipeline.entity.git.GitCommitEntry)

Example 5 with UnexpectedResponseStatusException

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

the class GitlabClient method getRepositoryRevision.

public GitTagEntry getRepositoryRevision(String tag) throws GitClientException {
    try {
        String projectId = makeProjectId(namespace, projectName);
        String url = addUrlParameters(String.format(GIT_REVISION, gitHost, projectId, tag), new HashMap<>());
        URI uri = new URI(url);
        LOGGER.trace("Getting repository revisions from URL: {}", uri);
        RestTemplate template = new RestTemplate();
        ResponseEntity<GitTagEntry> sourcesResponse = template.exchange(uri, HttpMethod.GET, getAuthHeaders(), new ParameterizedTypeReference<GitTagEntry>() {
        });
        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) 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) GitTagEntry(com.epam.pipeline.entity.git.GitTagEntry)

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