use of com.epam.pipeline.exception.docker.DockerConnectionException 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.docker.DockerConnectionException 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());
}
}
use of com.epam.pipeline.exception.docker.DockerConnectionException 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.docker.DockerConnectionException 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.docker.DockerConnectionException in project cloud-pipeline by epam.
the class DockerClient method checkAvailability.
public void checkAvailability() {
HttpEntity entity = getAuthHeaders();
String uri = String.format(HEALTH_ENTRY_POINT, hostName);
try {
getRestTemplate().exchange(uri, HttpMethod.GET, entity, String.class);
} catch (HTTPException | ResourceAccessException e) {
if (e.getCause() instanceof SSLHandshakeException) {
throw new DockerCertificateException(hostName, e.getCause());
} else {
throw new DockerConnectionException(hostName, e.getMessage(), e);
}
} catch (HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.UNAUTHORIZED) {
throw new DockerCredentialsException(hostName, userName, password, e);
} else {
throw new DockerConnectionException(hostName, e.getMessage(), e);
}
}
}
Aggregations