use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class DockerRegistryManager method createToolFromEvent.
private Optional<Tool> createToolFromEvent(String registry, DockerRegistryEvent registryEvent) {
DockerRegistry dockerRegistry = fetchDockerRegistry(registry, registryEvent);
String fullToolName = registryEvent.getTarget().getRepository();
ImmutablePair<String, String> groupAndTool = toolGroupManager.getGroupAndTool(fullToolName);
ToolGroup toolGroup = fetchToolGroup(registryEvent, dockerRegistry, groupAndTool.getLeft());
return enableToolIfNeeded(registryEvent, dockerRegistry, fullToolName, toolGroup);
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class DockerRegistryManager method updateDockerRegistry.
@Transactional(propagation = Propagation.REQUIRED)
public DockerRegistry updateDockerRegistry(DockerRegistry dockerRegistry) {
DockerRegistry loadedDockerRegistry = loadByIdOrName(dockerRegistry);
Assert.notNull(loadedDockerRegistry, messageHelper.getMessage(MessageConstants.ERROR_REGISTRY_NOT_FOUND, dockerRegistry.getPath()));
loadedDockerRegistry.setDescription(dockerRegistry.getDescription());
dockerRegistryDao.updateDockerRegistry(loadedDockerRegistry);
return loadedDockerRegistry;
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class ToolManager method getCurrentImageSize.
public long getCurrentImageSize(final String dockerImage) {
LOGGER.info("Getting size of image {}", dockerImage);
Tool tool = loadByNameOrId(dockerImage);
DockerRegistry dockerRegistry = dockerRegistryManager.load(tool.getRegistryId());
String imageWithoutTag = getImageWithoutTag(tool.getImage());
String tag = getTagFromImageName(dockerImage);
DockerClient dockerClient = dockerRegistryManager.getDockerClient(dockerRegistry, imageWithoutTag);
try {
ToolVersion toolVersion = dockerClient.getVersionAttributes(dockerRegistry, imageWithoutTag, tag);
if (Objects.isNull(toolVersion) || Objects.isNull(toolVersion.getSize())) {
LOGGER.warn(messageHelper.getMessage(MessageConstants.ERROR_TOOL_VERSION_INVALID_SIZE, dockerImage));
return 0;
}
return toolVersion.getSize();
} catch (IllegalArgumentException e) {
LOGGER.error("An error occurred while getting image size: {} ", e.getMessage());
return 0;
}
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry 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;
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class ToolGroupManager method loadByRegistryName.
private List<ToolGroup> loadByRegistryName(String registryName) {
String currentUserName = makePrivateGroupName();
DockerRegistry registry = dockerRegistryManager.loadByNameOrId(registryName);
return toolGroupDao.loadToolGroups(registry.getId()).stream().peek(g -> g.setPrivateGroup(g.getName().equalsIgnoreCase(currentUserName))).collect(Collectors.toList());
}
Aggregations