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);
}
}
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);
}
}
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;
}
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);
}
}
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;
}
Aggregations