Search in sources :

Example 46 with DockerRegistry

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

the class ToolGroupManager method createPrivate.

@Transactional(propagation = Propagation.REQUIRED)
public ToolGroup createPrivate(Long registryId) {
    ToolGroup privateGroup = new ToolGroup();
    String privateGroupName = makePrivateGroupName();
    privateGroup.setName(privateGroupName);
    privateGroup.setRegistryId(registryId);
    privateGroup.setOwner(authManager.getAuthorizedUser());
    privateGroup.setPrivateGroup(true);
    DockerRegistry registry = dockerRegistryManager.load(registryId);
    Assert.notNull(registry, messageHelper.getMessage(MessageConstants.ERROR_REGISTRY_NOT_FOUND, registryId));
    Assert.isTrue(!toolGroupDao.loadToolGroup(privateGroup.getName(), privateGroup.getRegistryId()).isPresent(), messageHelper.getMessage(MessageConstants.ERROR_TOOL_GROUP_ALREADY_EXIST, privateGroup.getName(), registry.getName()));
    privateGroup.setParent(registry);
    toolGroupDao.createToolGroup(privateGroup);
    makePrivate(privateGroup);
    return privateGroup;
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Transactional(org.springframework.transaction.annotation.Transactional)

Example 47 with DockerRegistry

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

the class ToolGroupManager method loadWithParents.

@Override
public ToolGroup loadWithParents(final Long id) {
    Optional<ToolGroup> loadResult = toolGroupDao.loadToolGroup(id);
    if (loadResult.isPresent()) {
        ToolGroup toolGroup = loadResult.get();
        toolGroup.setParent(new DockerRegistry(toolGroup.getRegistryId()));
    }
    return loadResult.orElse(null);
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup)

Example 48 with DockerRegistry

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

the class PipelineRunManager method commitRun.

/**
 * Commits docker image and push it to a docker registry from specified run
 * @param id {@link PipelineRun} id for pipeline run to be committed
 * @param registryId {@link DockerRegistry} id where new image will be pushed
 * @param deleteFiles if true files from pipeline working directory will be cleaned
 * @param stopPipeline if true pipeline will be stopped after commit
 * @param checkSize if true method will check if free disk space is enough for commit operation
 * @return  {@link PipelineRun} to be committed
 */
@Transactional(propagation = Propagation.REQUIRED)
public PipelineRun commitRun(Long id, Long registryId, String newImageName, boolean deleteFiles, boolean stopPipeline, boolean checkSize) {
    if (checkSize) {
        Assert.state(checkFreeSpaceAvailable(id), messageHelper.getMessage(MessageConstants.ERROR_INSTANCE_DISK_NOT_ENOUGH));
    }
    PipelineRun pipelineRun = pipelineRunDao.loadPipelineRun(id);
    DockerRegistry dockerRegistry = dockerRegistryManager.load(registryId);
    Assert.notNull(pipelineRun, messageHelper.getMessage(MessageConstants.ERROR_RUN_PIPELINES_NOT_FOUND, id));
    Assert.state(pipelineRun.getStatus() == TaskStatus.RUNNING, messageHelper.getMessage(MessageConstants.ERROR_PIPELINE_RUN_FINISHED, id));
    Assert.notNull(dockerRegistry, messageHelper.getMessage(MessageConstants.ERROR_REGISTRY_NOT_FOUND, registryId));
    String dockerImageFromRun = retrieveImageName(pipelineRun);
    String resolvedImageName = StringUtils.isEmpty(newImageName) ? dockerImageFromRun : newImageName;
    // check that there is no tool with this name in another registry
    toolManager.assertThatToolUniqueAcrossRegistries(resolvedImageName, dockerRegistry.getPath());
    return dockerContainerOperationManager.commitContainer(pipelineRun, dockerRegistry, resolvedImageName, deleteFiles, stopPipeline);
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) Transactional(org.springframework.transaction.annotation.Transactional)

Example 49 with DockerRegistry

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

the class DockerRegistryManagerTest method testLoadingImageTags.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testLoadingImageTags() {
    DockerRegistry registry = generateRegistry();
    registryDao.createDockerRegistry(registry);
    ToolGroup group = generateToolGroup(registry);
    toolGroupDao.createToolGroup(group);
    Tool tool = generateTool(group);
    toolManager.create(tool, true);
    DockerClient mockClient = Mockito.mock(DockerClient.class);
    when(dockerClientFactoryMock.getDockerClient(any(DockerRegistry.class), any())).thenReturn(mockClient);
    List<String> expected = Arrays.asList("TAG1", "TAG2");
    when(mockClient.getImageTags(ANOTHER_PATH, TEST_IMAGE)).thenReturn(expected);
    Assert.assertEquals(expected, dockerRegistryManager.loadImageTags(registry, tool));
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Tool(com.epam.pipeline.entity.pipeline.Tool) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 50 with DockerRegistry

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

the class DockerRegistryManagerTest method testDelete.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testDelete() {
    TestUtils.configureDockerClientMock(Mockito.mock(DockerClient.class), dockerClientFactoryMock);
    DockerRegistry registry = generateRegistry();
    registryDao.createDockerRegistry(registry);
    ToolGroup group = generateToolGroup(registry);
    toolGroupDao.createToolGroup(group);
    Tool tool = generateTool(group);
    toolManager.create(tool, true);
    dockerRegistryManager.delete(registry.getId(), true);
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Tool(com.epam.pipeline.entity.pipeline.Tool) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

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