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;
}
Aggregations