Search in sources :

Example 16 with GitClientException

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

the class GitlabClient method getFileContents.

public byte[] getFileContents(String projectId, String path, String revision) throws GitClientException {
    Assert.isTrue(StringUtils.isNotBlank(path), "File path can't be null");
    Assert.isTrue(StringUtils.isNotBlank(revision), "Revision can't be null");
    try {
        if (StringUtils.isBlank(projectId)) {
            projectId = makeProjectId(namespace, projectName);
        }
        Map<String, Object> params = new HashMap<>();
        params.put("file_path", path);
        params.put("ref", revision);
        String url = addUrlParameters(String.format(GIT_GET_SOURCE_FILE_URL, gitHost, projectId), params);
        URI uri = new URI(url);
        LOGGER.trace("Getting file contents on path {}, URL: {}", path, uri);
        RestTemplate template = new RestTemplate();
        ResponseEntity<GitFile> sourcesResponse = template.exchange(uri, HttpMethod.GET, getAuthHeaders(), GitFile.class);
        if (sourcesResponse.getStatusCode() == HttpStatus.OK) {
            return Base64.getDecoder().decode(sourcesResponse.getBody().getContent());
        } else {
            throw new UnexpectedResponseStatusException(sourcesResponse.getStatusCode());
        }
    } catch (UnsupportedEncodingException | URISyntaxException | UnexpectedResponseStatusException e) {
        throw new GitClientException(e);
    }
}
Also used : HashMap(java.util.HashMap) GitFile(com.epam.pipeline.entity.git.GitFile) 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)

Example 17 with GitClientException

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

the class GitlabClient method projectExists.

public boolean projectExists(String name) throws GitClientException {
    String project = convertPipeNameToProject(name);
    try {
        URI uri = new URI(String.format(GIT_PROJECT_URL, gitHost, makeProjectId(adminName, project)));
        ResponseEntity<GitProject> response = new RestTemplate().exchange(uri, HttpMethod.GET, getAuthHeaders(), new ParameterizedTypeReference<GitProject>() {
        });
        return response.getStatusCode() == HttpStatus.OK;
    } catch (HttpClientErrorException e) {
        if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
            return false;
        }
        throw new UnexpectedResponseStatusException(e.getStatusCode());
    } catch (URISyntaxException | UnsupportedEncodingException e) {
        throw new GitClientException(e.getMessage(), e);
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) UnexpectedResponseStatusException(com.epam.pipeline.exception.git.UnexpectedResponseStatusException) GitProject(com.epam.pipeline.entity.git.GitProject) RestTemplate(org.springframework.web.client.RestTemplate) GitClientException(com.epam.pipeline.exception.git.GitClientException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 18 with GitClientException

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

the class GitlabClient method createGitProject.

private GitProject createGitProject(Template template, String description, String repoName, boolean indexingEnabled, String hookUrl) throws UnexpectedResponseStatusException, URISyntaxException, IOException {
    GitProject project = createRepo(repoName, description);
    if (indexingEnabled) {
        addProjectHook(String.valueOf(project.getId()), hookUrl);
    }
    uploadFolder(template, repoName, project);
    try {
        boolean fileExists = getFileContents(project.getId().toString(), DEFAULT_README, DEFAULT_BRANCH) != null;
        if (!fileExists) {
            createFile(project, DEFAULT_README, README_DEFAULT_CONTENTS);
        }
    } catch (HttpClientErrorException e) {
        createFile(project, DEFAULT_README, README_DEFAULT_CONTENTS);
    } catch (GitClientException exception) {
        LOGGER.debug(exception.getMessage(), exception);
    }
    return project;
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) GitProject(com.epam.pipeline.entity.git.GitProject) GitClientException(com.epam.pipeline.exception.git.GitClientException)

Example 19 with GitClientException

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

the class PipelineDocumentTemplateManager method applyChangeSummary.

private void applyChangeSummary(PipelineDocumentTemplate template) {
    try {
        List<Revision> revisions = pipelineVersionManager.loadAllVersionFromGit(template.getPipeline().getId(), null);
        Revision previousRevision = null;
        for (int i = 0; i < revisions.size(); i++) {
            if (revisions.get(i).getName().equals(template.getVersion().getName())) {
                if (i < revisions.size() - 1) {
                    previousRevision = revisions.get(i + 1);
                }
                break;
            }
        }
        if (previousRevision != null) {
            final Long oneSecond = 1000L;
            Date since = new Date(previousRevision.getCreatedDate().getTime() + oneSecond);
            template.setCommits(gitManager.getCommits(template.getPipeline(), template.getVersion().getName(), since));
        } else {
            template.setCommits(gitManager.getCommits(template.getPipeline(), template.getVersion().getName()));
        }
    } catch (GitClientException e) {
        log.error(e.getMessage(), e);
    }
}
Also used : Revision(com.epam.pipeline.entity.pipeline.Revision) GitClientException(com.epam.pipeline.exception.git.GitClientException) Date(java.util.Date)

Example 20 with GitClientException

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

the class PipelineConfigurationManager method getConfigurationFromRun.

public PipelineConfiguration getConfigurationFromRun(PipelineRun run) {
    PipelineConfiguration configuration = new PipelineConfiguration();
    configuration.setParameters(run.convertParamsToMap());
    configuration.setTimeout(run.getTimeout());
    configuration.setNodeCount(run.getNodeCount());
    configuration.setCmdTemplate(run.getCmdTemplate());
    configuration.setDockerImage(run.getDockerImage());
    RunInstance instance = run.getInstance();
    if (instance != null) {
        configuration.setInstanceDisk(String.valueOf(instance.getEffectiveNodeDisk()));
        configuration.setInstanceType(instance.getNodeType());
        configuration.setIsSpot(instance.getSpot());
        configuration.setInstanceImage(instance.getNodeImage());
        configuration.setAwsRegionId(awsRegionManager.loadByAwsRegionName(instance.getAwsRegionId()).getId());
    }
    setEndpointsErasure(configuration);
    if (run.getPipelineId() != null) {
        try {
            ConfigurationEntry entry = pipelineVersionManager.loadConfigurationEntry(run.getPipelineId(), run.getVersion(), run.getConfigName());
            PipelineConfiguration defaultConfiguration = entry.getConfiguration();
            configuration.setEnvironmentParams(defaultConfiguration.getEnvironmentParams());
            configuration.setMainClass(defaultConfiguration.getMainClass());
            configuration.setMainFile(defaultConfiguration.getMainFile());
        } catch (GitClientException e) {
            log.error(e.getMessage(), e);
        }
        configuration.setGitCredentials(gitManager.getGitCredentials(run.getPipelineId()));
    }
    configuration.buildEnvVariables();
    return configuration;
}
Also used : GitClientException(com.epam.pipeline.exception.git.GitClientException) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) ConfigurationEntry(com.epam.pipeline.entity.configuration.ConfigurationEntry)

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