use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException 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);
}
}
use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException 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.UnexpectedResponseStatusException in project cloud-pipeline by epam.
the class GitlabClient method createRepo.
private GitProject createRepo(String repoName, String description) throws UnexpectedResponseStatusException, URISyntaxException {
HttpHeaders headers = new HttpHeaders();
headers.add(TOKEN_HEADER, token);
Map<String, String> parameters = new HashMap<>();
parameters.put("name", repoName);
if (!StringUtils.isEmpty(description)) {
parameters.put("description", description);
}
parameters.put("visibility", PUBLIC_VISIBILITY);
HttpEntity entity = new HttpEntity<>(parameters, headers);
URI uri = new URI(String.format(GIT_POST_PROJECT_URL, gitHost));
LOGGER.trace("Creating repo {}, URL: {}, token: {}", repoName, uri, token);
ResponseEntity<GitProject> response = new RestTemplate().exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference<GitProject>() {
});
if (response.getStatusCode() == HttpStatus.CREATED) {
return response.getBody();
} else {
throw new UnexpectedResponseStatusException(response.getStatusCode());
}
}
use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException 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.UnexpectedResponseStatusException in project cloud-pipeline by epam.
the class DockerClient method executeDeletion.
private void executeDeletion(String url, String image) {
try {
URI uri = new URI(url);
HttpStatus status = getRestTemplate().execute(uri, HttpMethod.DELETE, request -> request.getHeaders().putAll(getAuthHeaders().getHeaders()), ClientHttpResponse::getStatusCode);
if (status != HttpStatus.ACCEPTED) {
throw new UnexpectedResponseStatusException(status);
}
} catch (URISyntaxException | UnexpectedResponseStatusException e) {
throw new DockerConnectionException(url, e.getMessage());
} catch (HttpClientErrorException e) {
if (e.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
LOGGER.error("Image not found:" + image);
return;
}
throw new DockerConnectionException(url, e.getMessage());
}
}
Aggregations