use of com.epam.pipeline.exception.git.GitClientException 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);
}
}
use of com.epam.pipeline.exception.git.GitClientException 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);
}
}
use of com.epam.pipeline.exception.git.GitClientException in project cloud-pipeline by epam.
the class InstanceOfferManager method getInstanceEstimatedPrice.
public InstancePrice getInstanceEstimatedPrice(Long id, String version, String configName, String instanceType, int instanceDisk, Boolean spot, Long regionId) throws GitClientException {
Boolean useSpot = spot;
if (StringUtils.isEmpty(instanceType) || instanceDisk <= 0 || useSpot == null) {
PipelineConfiguration pipelineConfiguration = versionManager.loadParametersFromScript(id, version, configName);
if (StringUtils.isEmpty(instanceType)) {
instanceType = pipelineConfiguration.getInstanceType();
}
if (instanceDisk <= 0) {
instanceDisk = Integer.parseInt(pipelineConfiguration.getInstanceDisk());
}
if (useSpot == null) {
useSpot = pipelineConfiguration.getIsSpot();
}
}
Assert.isTrue(isInstanceAllowed(instanceType), messageHelper.getMessage(MessageConstants.ERROR_INSTANCE_TYPE_IS_NOT_ALLOWED, instanceType));
AwsRegion region = awsRegionManager.loadRegionOrGetDefault(regionId);
double pricePerHourForInstance = getPricePerHourForInstance(instanceType, isSpotRequest(useSpot), region.getAwsRegionName());
double pricePerDisk = getPriceForDisk(instanceDisk, region.getAwsRegionName());
double pricePerHour = pricePerDisk + pricePerHourForInstance;
InstancePrice instancePrice = new InstancePrice(instanceType, instanceDisk, pricePerHour);
List<PipelineRun> runs = pipelineRunManager.loadAllRunsByPipeline(id, version).stream().filter(run -> run.getStatus().isFinal()).collect(Collectors.toList());
if (!runs.isEmpty()) {
long minimumDuration = -1;
long maximumDuration = -1;
long totalDurations = 0;
for (PipelineRun run : runs) {
long duration = run.getEndDate().getTime() - run.getStartDate().getTime();
if (minimumDuration == -1 || minimumDuration > duration) {
minimumDuration = duration;
}
if (maximumDuration == -1 || maximumDuration < duration) {
maximumDuration = duration;
}
totalDurations += duration;
}
double averageDuration = (double) totalDurations / runs.size();
instancePrice.setAverageTimePrice(pricePerHour * averageDuration / ONE_HOUR);
instancePrice.setMinimumTimePrice(pricePerHour * minimumDuration / ONE_HOUR);
instancePrice.setMaximumTimePrice(pricePerHour * maximumDuration / ONE_HOUR);
}
return instancePrice;
}
use of com.epam.pipeline.exception.git.GitClientException in project cloud-pipeline by epam.
the class GitlabClient method createRepositoryRevision.
public GitTagEntry createRepositoryRevision(String name, String ref, String message, String releaseDescription) throws GitClientException {
if (name == null) {
throw new GitClientException("Tag name is required");
}
if (ref == null) {
throw new GitClientException("Ref (commit SHA, another tag name, or branch name) is required");
}
try {
String projectId = makeProjectId(namespace, projectName);
Map<String, Object> params = new HashMap<>();
params.put("tag_name", name);
params.put("ref", ref);
if (message != null) {
params.put("message", message);
}
if (releaseDescription != null) {
params.put("release_description", releaseDescription);
}
String url = addUrlParameters(String.format(GIT_REVISIONS, gitHost, projectId), params);
URI uri = new URI(url);
LOGGER.trace("Creating new tag using URL: {}", uri);
RestTemplate template = new RestTemplate();
ResponseEntity<GitTagEntry> sourcesResponse = template.exchange(uri, HttpMethod.POST, getAuthHeaders(), new ParameterizedTypeReference<GitTagEntry>() {
});
if (sourcesResponse.getStatusCode() == HttpStatus.CREATED) {
return sourcesResponse.getBody();
} else {
throw new UnexpectedResponseStatusException(sourcesResponse.getStatusCode());
}
} catch (UnsupportedEncodingException | URISyntaxException e) {
throw new GitClientException(e);
}
}
use of com.epam.pipeline.exception.git.GitClientException in project cloud-pipeline by epam.
the class GitlabClient method getRepositoryContents.
/**
* Retrieves repository contents - a list of files in a repository
* @param path a path in a repository to browse
* @return a list of {@link GitRepositoryEntry}, representing files and folders
* @throws GitClientException if something goes wrong
*/
public List<GitRepositoryEntry> getRepositoryContents(String path, String revision, boolean recursive) throws GitClientException {
try {
String projectId = makeProjectId(namespace, projectName);
Map<String, Object> params = new HashMap<>();
if (StringUtils.isNotBlank(path)) {
params.put("path", path);
}
if (StringUtils.isNotBlank(revision)) {
params.put("ref_name", revision);
}
params.put("recursive", recursive);
String url = addUrlParameters(String.format(GIT_GET_SOURCES_ROOT_URL, gitHost, projectId), params);
URI uri = new URI(url);
LOGGER.trace("Getting repository contents on path {}, URL: {}", path, uri);
RestTemplate template = new RestTemplate();
ResponseEntity<List<GitRepositoryEntry>> sourcesResponse = template.exchange(uri, HttpMethod.GET, getAuthHeaders(), new ParameterizedTypeReference<List<GitRepositoryEntry>>() {
});
if (sourcesResponse.getStatusCode() == HttpStatus.OK) {
return sourcesResponse.getBody();
} else {
throw new UnexpectedResponseStatusException(sourcesResponse.getStatusCode());
}
} catch (UnsupportedEncodingException | URISyntaxException e) {
throw new GitClientException(e);
}
}
Aggregations