Search in sources :

Example 6 with GitClientException

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

the class GitManager method getConfigurationFileEntry.

private GitRepositoryEntry getConfigurationFileEntry(Long id, String version) throws GitClientException {
    Pipeline pipeline = pipelineManager.load(id);
    try {
        loadRevision(pipeline, version);
    } catch (GitClientException e) {
        LOGGER.error(e.getMessage(), e);
        throw new IllegalArgumentException(e.getMessage());
    }
    GitRepositoryEntry configurationFileEntry = null;
    List<GitRepositoryEntry> rootEntries = this.getGitlabClientForPipeline(pipeline).getRepositoryContents("", getRevisionName(version), false);
    for (GitRepositoryEntry rootEntry : rootEntries) {
        if (rootEntry.getName().equalsIgnoreCase(CONFIG_FILE_NAME)) {
            configurationFileEntry = rootEntry;
            break;
        }
    }
    return configurationFileEntry;
}
Also used : GitClientException(com.epam.pipeline.exception.git.GitClientException) GitRepositoryEntry(com.epam.pipeline.entity.git.GitRepositoryEntry) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline)

Example 7 with GitClientException

use of com.epam.pipeline.exception.git.GitClientException 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 8 with GitClientException

use of com.epam.pipeline.exception.git.GitClientException 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 9 with GitClientException

use of com.epam.pipeline.exception.git.GitClientException 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)

Example 10 with GitClientException

use of com.epam.pipeline.exception.git.GitClientException 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)

Aggregations

GitClientException (com.epam.pipeline.exception.git.GitClientException)23 UnsupportedEncodingException (java.io.UnsupportedEncodingException)11 URISyntaxException (java.net.URISyntaxException)11 UnexpectedResponseStatusException (com.epam.pipeline.exception.git.UnexpectedResponseStatusException)10 URI (java.net.URI)10 RestTemplate (org.springframework.web.client.RestTemplate)10 List (java.util.List)7 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)7 HashMap (java.util.HashMap)6 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)5 IOException (java.io.IOException)5 Date (java.util.Date)5 Autowired (org.springframework.beans.factory.annotation.Autowired)4 PipelineConfiguration (com.epam.pipeline.entity.configuration.PipelineConfiguration)3 GitCommitEntry (com.epam.pipeline.entity.git.GitCommitEntry)3 GitProject (com.epam.pipeline.entity.git.GitProject)3 GitTagEntry (com.epam.pipeline.entity.git.GitTagEntry)3 Revision (com.epam.pipeline.entity.pipeline.Revision)3 RunInstance (com.epam.pipeline.entity.pipeline.RunInstance)3 TaskGraphVO (com.epam.pipeline.controller.vo.TaskGraphVO)2