use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException in project cloud-pipeline by epam.
the class DockerClient method getRegistryEntries.
public Set<String> getRegistryEntries() {
try {
URI uri = new URI(String.format(LIST_REGISTRY_URL, hostName));
HttpEntity entity = getAuthHeaders();
ResponseEntity<RegistryListing> response = getRestTemplate().exchange(uri, HttpMethod.GET, entity, new ParameterizedTypeReference<RegistryListing>() {
});
if (response.getStatusCode() == HttpStatus.OK) {
return response.getBody().getRepositories();
} else {
throw new UnexpectedResponseStatusException(response.getStatusCode());
}
} catch (URISyntaxException | UnexpectedResponseStatusException e) {
LOGGER.error(e.getMessage(), e);
return Collections.emptySet();
}
}
use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException in project cloud-pipeline by epam.
the class DockerClient method getImageTags.
public List<String> getImageTags(String registryPath, String image) {
String url = String.format(TAGS_LIST, registryPath, image);
try {
URI uri = new URI(url);
HttpEntity entity = getAuthHeaders();
ResponseEntity<TagsListing> response = getRestTemplate().exchange(uri, HttpMethod.GET, entity, new ParameterizedTypeReference<TagsListing>() {
});
if (response.getStatusCode() == HttpStatus.OK) {
return response.getBody().getTags();
} else {
throw new UnexpectedResponseStatusException(response.getStatusCode());
}
} catch (URISyntaxException | HttpClientErrorException | UnexpectedResponseStatusException e) {
LOGGER.error(e.getMessage(), e);
throw new DockerConnectionException(url, e.getMessage());
}
}
use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException 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);
}
}
use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException 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);
}
}
use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException 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);
}
}
Aggregations