Search in sources :

Example 41 with DockerRegistry

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);
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup)

Example 42 with DockerRegistry

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;
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) Transactional(org.springframework.transaction.annotation.Transactional)

Example 43 with DockerRegistry

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;
    }
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) DockerClient(com.epam.pipeline.manager.docker.DockerClient) ToolVersion(com.epam.pipeline.entity.docker.ToolVersion) Tool(com.epam.pipeline.entity.pipeline.Tool)

Example 44 with DockerRegistry

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

Example 45 with DockerRegistry

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());
}
Also used : ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) MessageConstants(com.epam.pipeline.common.MessageConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) PermissionGrantVO(com.epam.pipeline.controller.vo.PermissionGrantVO) ToolGroupWithIssues(com.epam.pipeline.entity.pipeline.ToolGroupWithIssues) DockerRegistryManager(com.epam.pipeline.manager.docker.DockerRegistryManager) Matcher(java.util.regex.Matcher) MessageHelper(com.epam.pipeline.common.MessageHelper) Pair(org.apache.commons.lang3.tuple.Pair) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) AclPermission(com.epam.pipeline.security.acl.AclPermission) GrantPermissionManager(com.epam.pipeline.manager.security.GrantPermissionManager) Constants(com.epam.pipeline.config.Constants) SecuredEntityManager(com.epam.pipeline.manager.security.SecuredEntityManager) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) ToolGroupWithIssuesMapper(com.epam.pipeline.mapper.ToolGroupWithIssuesMapper) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) List(java.util.List) AclSync(com.epam.pipeline.manager.security.acl.AclSync) NumberUtils(org.apache.commons.lang3.math.NumberUtils) AclClass(com.epam.pipeline.entity.security.acl.AclClass) Optional(java.util.Optional) AuthManager(com.epam.pipeline.manager.security.AuthManager) Pattern(java.util.regex.Pattern) ToolGroupDao(com.epam.pipeline.dao.tool.ToolGroupDao) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry)

Aggregations

DockerRegistry (com.epam.pipeline.entity.pipeline.DockerRegistry)57 Transactional (org.springframework.transaction.annotation.Transactional)24 ToolGroup (com.epam.pipeline.entity.pipeline.ToolGroup)22 Tool (com.epam.pipeline.entity.pipeline.Tool)19 Test (org.junit.Test)14 Before (org.junit.Before)10 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)7 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)6 MessageHelper (com.epam.pipeline.common.MessageHelper)4 AclClass (com.epam.pipeline.entity.security.acl.AclClass)4 DockerClient (com.epam.pipeline.manager.docker.DockerClient)4 DockerRegistryManager (com.epam.pipeline.manager.docker.DockerRegistryManager)4 IOException (java.io.IOException)4 List (java.util.List)4 Optional (java.util.Optional)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 MessageConstants (com.epam.pipeline.common.MessageConstants)3 PermissionGrantVO (com.epam.pipeline.controller.vo.PermissionGrantVO)3 AbstractSecuredEntity (com.epam.pipeline.entity.AbstractSecuredEntity)3 ToolVersionScanResult (com.epam.pipeline.entity.scan.ToolVersionScanResult)3