use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException in project cloud-pipeline by epam.
the class DockerClient method getRawImageDescription.
private RawImageDescription getRawImageDescription(DockerRegistry registry, String imageName, String tag, HttpEntity headers) {
String url = String.format(IMAGE_DESCRIPTION_URL, registry.getPath(), imageName, tag);
try {
URI uri = new URI(url);
ResponseEntity<RawImageDescription> response = getRestTemplate().exchange(uri, HttpMethod.GET, headers, new ParameterizedTypeReference<RawImageDescription>() {
});
if (response.getStatusCode() == HttpStatus.OK) {
return response.getBody();
} else {
throw new UnexpectedResponseStatusException(response.getStatusCode());
}
} catch (URISyntaxException | 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 DockerClient method getManifest.
/**
* Gets a V2 Manifest for a specified image and tag
* @param registry a registry, where image is located
* @param imageName a name of an image (repository)
* @param tag tag name
* @return image's manifest
*/
public Optional<ManifestV2> getManifest(DockerRegistry registry, String imageName, String tag) {
String url = String.format(IMAGE_DESCRIPTION_URL, registry.getPath(), imageName, tag);
try {
URI uri = new URI(url);
ResponseEntity<ManifestV2> response = getRestTemplate().exchange(uri, HttpMethod.GET, getV2AuthHeaders(), new ParameterizedTypeReference<ManifestV2>() {
});
if (response.getStatusCode() == HttpStatus.OK) {
List<String> digest = response.getHeaders().get("docker-content-digest");
ManifestV2 manifest = response.getBody();
manifest.setDigest(digest.get(0));
return Optional.of(manifest);
} else {
throw new UnexpectedResponseStatusException(response.getStatusCode());
}
} catch (URISyntaxException | UnexpectedResponseStatusException e) {
LOGGER.error(e.getMessage(), e);
throw new DockerConnectionException(url, e.getMessage());
} catch (HttpClientErrorException e) {
LOGGER.error(e.getMessage(), e);
return Optional.empty();
}
}
use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException 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.UnexpectedResponseStatusException 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);
}
}
use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException in project cloud-pipeline by epam.
the class GitlabClient method createFile.
private void createFile(GitProject project, String path, String content) throws URISyntaxException, UnexpectedResponseStatusException, UnsupportedEncodingException {
HttpHeaders headers = new HttpHeaders();
headers.add(TOKEN_HEADER, token);
Map<String, Object> parameters = new HashMap<>();
parameters.put("file_path", path);
parameters.put("branch_name", DEFAULT_BRANCH);
parameters.put("commit_message", "New pipeline initial commit");
parameters.put("content", content);
String url = addUrlParameters(String.format(GIT_POST_FILE_URL, gitHost, project.getId().toString(), URLEncoder.encode(path, Charset.defaultCharset().displayName())), parameters);
URI uri = new URI(url);
HttpEntity entity = new HttpEntity(headers);
ResponseEntity<GitRepositoryEntry> response = new RestTemplate().exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference<GitRepositoryEntry>() {
});
if (response.getStatusCode() != HttpStatus.CREATED) {
throw new UnexpectedResponseStatusException(response.getStatusCode());
}
}
Aggregations