Search in sources :

Example 46 with Tool

use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.

the class ToolManager method deleteToolIcon.

@Transactional(propagation = Propagation.REQUIRED)
public void deleteToolIcon(long toolId) {
    Tool tool = load(toolId);
    Assert.notNull(tool, messageHelper.getMessage(MessageConstants.ERROR_TOOL_NOT_FOUND, toolId));
    toolDao.deleteToolIcon(toolId);
}
Also used : Tool(com.epam.pipeline.entity.pipeline.Tool) Transactional(org.springframework.transaction.annotation.Transactional)

Example 47 with Tool

use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.

the class ToolManager method updateTool.

@Transactional(propagation = Propagation.REQUIRED)
public Tool updateTool(Tool tool) {
    Tool loadedTool = toolDao.loadTool(tool.getRegistryId(), tool.getImage());
    Assert.notNull(loadedTool, messageHelper.getMessage(MessageConstants.ERROR_TOOL_NOT_FOUND, tool.getImage()));
    if (!StringUtils.isEmpty(tool.getCpu())) {
        loadedTool.setCpu(tool.getCpu());
    }
    if (!StringUtils.isEmpty(tool.getRam())) {
        loadedTool.setRam(tool.getRam());
    }
    validateInstanceType(tool);
    loadedTool.setInstanceType(tool.getInstanceType());
    loadedTool.setDisk(tool.getDisk());
    loadedTool.setDescription(tool.getDescription());
    loadedTool.setShortDescription(tool.getShortDescription());
    loadedTool.setLabels(tool.getLabels());
    loadedTool.setEndpoints(tool.getEndpoints());
    loadedTool.setDefaultCommand(tool.getDefaultCommand());
    toolDao.updateTool(loadedTool);
    return loadedTool;
}
Also used : Tool(com.epam.pipeline.entity.pipeline.Tool) Transactional(org.springframework.transaction.annotation.Transactional)

Example 48 with Tool

use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.

the class ToolManager method loadToolAttributes.

public ToolDescription loadToolAttributes(Long toolId) {
    Tool tool = load(toolId);
    Map<String, ToolVersionScanResult> versionScanResults = toolVulnerabilityDao.loadAllToolVersionScans(toolId);
    ToolDescription toolDescription = new ToolDescription();
    toolDescription.setToolId(toolId);
    List<ToolVersionAttributes> versions = ListUtils.emptyIfNull(loadTags(toolId)).stream().map(version -> ToolVersionAttributes.builder().version(version).attributes(getToolVersion(toolId, version)).scanResult(getToolVersionScanResult(tool, versionScanResults, version)).build()).collect(Collectors.toList());
    toolDescription.setVersions(versions);
    return toolDescription;
}
Also used : ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Date(java.util.Date) ToolScanManager(com.epam.pipeline.manager.docker.scan.ToolScanManager) LoggerFactory(org.slf4j.LoggerFactory) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) ManifestV2(com.epam.pipeline.entity.docker.ManifestV2) ToolVersionAttributes(com.epam.pipeline.entity.docker.ToolVersionAttributes) Vulnerability(com.epam.pipeline.entity.scan.Vulnerability) ToolDependency(com.epam.pipeline.entity.scan.ToolDependency) Matcher(java.util.regex.Matcher) MessageHelper(com.epam.pipeline.common.MessageHelper) Pair(org.apache.commons.lang3.tuple.Pair) ListUtils(org.apache.commons.collections4.ListUtils) Map(java.util.Map) ToolWithIssuesCount(com.epam.pipeline.entity.pipeline.ToolWithIssuesCount) SecuredEntityManager(com.epam.pipeline.manager.security.SecuredEntityManager) DateUtils(com.epam.pipeline.entity.utils.DateUtils) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) Collection(java.util.Collection) ToolVulnerabilityDao(com.epam.pipeline.dao.tool.ToolVulnerabilityDao) Collectors(java.util.stream.Collectors) ContextualPreferenceLevel(com.epam.pipeline.entity.contextual.ContextualPreferenceLevel) Objects(java.util.Objects) Tool(com.epam.pipeline.entity.pipeline.Tool) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) AclSync(com.epam.pipeline.manager.security.acl.AclSync) CollectionUtils(org.springframework.util.CollectionUtils) Optional(java.util.Optional) DockerConnectionException(com.epam.pipeline.exception.docker.DockerConnectionException) Pattern(java.util.regex.Pattern) ToolVersionManager(com.epam.pipeline.manager.docker.ToolVersionManager) FilenameUtils(org.apache.commons.io.FilenameUtils) MessageConstants(com.epam.pipeline.common.MessageConstants) DockerRegistryManager(com.epam.pipeline.manager.docker.DockerRegistryManager) ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) ToolDescription(com.epam.pipeline.entity.docker.ToolDescription) ToolVersion(com.epam.pipeline.entity.docker.ToolVersion) ToolScanStatus(com.epam.pipeline.entity.pipeline.ToolScanStatus) InstanceOfferManager(com.epam.pipeline.manager.cluster.InstanceOfferManager) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) Logger(org.slf4j.Logger) ToolDao(com.epam.pipeline.dao.tool.ToolDao) ToolScanResult(com.epam.pipeline.entity.scan.ToolScanResult) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolVersionScanResult(com.epam.pipeline.entity.scan.ToolVersionScanResult) NumberUtils(org.apache.commons.lang3.math.NumberUtils) AclClass(com.epam.pipeline.entity.security.acl.AclClass) ImageDescription(com.epam.pipeline.entity.docker.ImageDescription) AuthManager(com.epam.pipeline.manager.security.AuthManager) Collections(java.util.Collections) DockerClient(com.epam.pipeline.manager.docker.DockerClient) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) InputStream(java.io.InputStream) ToolVersionAttributes(com.epam.pipeline.entity.docker.ToolVersionAttributes) ToolVersionScanResult(com.epam.pipeline.entity.scan.ToolVersionScanResult) ToolDescription(com.epam.pipeline.entity.docker.ToolDescription) Tool(com.epam.pipeline.entity.pipeline.Tool)

Example 49 with Tool

use of com.epam.pipeline.entity.pipeline.Tool 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 50 with Tool

use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.

the class ToolManager method fetchTool.

private Tool fetchTool(String registry, String image) {
    Long registryId = !StringUtils.isEmpty(registry) ? dockerRegistryManager.loadByNameOrId(registry).getId() : null;
    Tool tool = toolDao.loadTool(registryId, getImageWithoutTag(image));
    Assert.notNull(tool, messageHelper.getMessage(MessageConstants.ERROR_TOOL_NOT_FOUND, image));
    return tool;
}
Also used : Tool(com.epam.pipeline.entity.pipeline.Tool)

Aggregations

Tool (com.epam.pipeline.entity.pipeline.Tool)72 Transactional (org.springframework.transaction.annotation.Transactional)28 DockerRegistry (com.epam.pipeline.entity.pipeline.DockerRegistry)24 Test (org.junit.Test)22 ToolGroup (com.epam.pipeline.entity.pipeline.ToolGroup)14 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)11 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)9 DockerClient (com.epam.pipeline.manager.docker.DockerClient)9 List (java.util.List)9 PipelineConfiguration (com.epam.pipeline.entity.configuration.PipelineConfiguration)8 MessageHelper (com.epam.pipeline.common.MessageHelper)7 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)7 ToolVersionScanResult (com.epam.pipeline.entity.scan.ToolVersionScanResult)7 ToolScanExternalServiceException (com.epam.pipeline.exception.ToolScanExternalServiceException)7 DockerRegistryManager (com.epam.pipeline.manager.docker.DockerRegistryManager)7 Optional (java.util.Optional)7 MessageConstants (com.epam.pipeline.common.MessageConstants)6 ManifestV2 (com.epam.pipeline.entity.docker.ManifestV2)6 ToolScanStatus (com.epam.pipeline.entity.pipeline.ToolScanStatus)6 DockerClientFactory (com.epam.pipeline.manager.docker.DockerClientFactory)6