Search in sources :

Example 6 with DockerConnectionException

use of com.epam.pipeline.exception.docker.DockerConnectionException in project cloud-pipeline by epam.

the class ToolManager method create.

/**
 * Creates a new Tool in the requested group
 * @param tool a tool to create
 * @return newly created group
 */
@Transactional(propagation = Propagation.REQUIRED)
public Tool create(final Tool tool, final boolean checkExistence) {
    Assert.notNull(tool.getImage(), messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_REQUIRED, "image", Tool.class.getSimpleName()));
    Assert.notNull(tool.getCpu(), messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_REQUIRED, "cpu", Tool.class.getSimpleName()));
    Assert.notNull(tool.getRam(), messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_REQUIRED, "ram", Tool.class.getSimpleName()));
    Assert.notNull(tool.getToolGroupId(), messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_REQUIRED, "toolGroupId", Tool.class.getSimpleName()));
    ToolGroup group = toolGroupManager.load(tool.getToolGroupId());
    tool.setParent(group);
    tool.setRegistryId(group.getRegistryId());
    tool.setToolGroupId(group.getId());
    if (!StringUtils.hasText(tool.getOwner())) {
        tool.setOwner(authManager.getAuthorizedUser());
    }
    Assert.isTrue(isToolUniqueInGroup(tool.getImage(), group.getId()), messageHelper.getMessage(MessageConstants.ERROR_TOOL_ALREADY_EXIST, tool.getImage(), group.getName()));
    validateInstanceType(tool);
    DockerRegistry registry = dockerRegistryManager.load(group.getRegistryId());
    if (checkExistence) {
        try {
            List<String> tags = dockerRegistryManager.loadImageTags(registry, tool.getImage());
            Assert.isTrue(!CollectionUtils.isEmpty(tags), messageHelper.getMessage(MessageConstants.ERROR_TOOL_IMAGE_UNAVAILABLE, tool.getImage()));
        } catch (DockerConnectionException e) {
            throw new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_TOOL_IMAGE_UNAVAILABLE, tool.getImage()));
        }
    }
    toolDao.createTool(tool);
    try {
        List<String> tags = dockerRegistryManager.loadImageTags(registry, tool.getImage());
        for (String tag : tags) {
            String digest = dockerRegistryManager.getDockerClient(registry, tool.getImage()).getVersionAttributes(registry, tool.getImage(), tag).getDigest();
            updateToolVersionScanStatus(tool.getId(), ToolScanStatus.NOT_SCANNED, DateUtils.now(), tag, null, digest);
        }
    } catch (DockerConnectionException e) {
        throw new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_TOOL_IMAGE_UNAVAILABLE, tool.getImage()));
    }
    return tool;
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) DockerConnectionException(com.epam.pipeline.exception.docker.DockerConnectionException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

DockerConnectionException (com.epam.pipeline.exception.docker.DockerConnectionException)6 UnexpectedResponseStatusException (com.epam.pipeline.exception.git.UnexpectedResponseStatusException)4 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)4 HttpEntity (org.springframework.http.HttpEntity)2 ManifestV2 (com.epam.pipeline.entity.docker.ManifestV2)1 RawImageDescription (com.epam.pipeline.entity.docker.RawImageDescription)1 TagsListing (com.epam.pipeline.entity.docker.TagsListing)1 DockerRegistry (com.epam.pipeline.entity.pipeline.DockerRegistry)1 ToolGroup (com.epam.pipeline.entity.pipeline.ToolGroup)1 DockerCertificateException (com.epam.pipeline.exception.docker.DockerCertificateException)1 DockerCredentialsException (com.epam.pipeline.exception.docker.DockerCredentialsException)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 HTTPException (javax.xml.ws.http.HTTPException)1 HttpStatus (org.springframework.http.HttpStatus)1 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)1 Transactional (org.springframework.transaction.annotation.Transactional)1 ResourceAccessException (org.springframework.web.client.ResourceAccessException)1