Search in sources :

Example 11 with ToolGroup

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

the class DockerRegistryManagerTest method generateToolGroup.

private ToolGroup generateToolGroup(DockerRegistry registry) {
    ToolGroup group = new ToolGroup();
    group.setName(TEST_GROUP_NAME);
    group.setRegistryId(registry.getId());
    group.setOwner(TEST_USER);
    return group;
}
Also used : ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup)

Example 12 with ToolGroup

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

the class DockerRegistryEventServiceTest method shouldAddDockerRegistryEvent.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void shouldAddDockerRegistryEvent() {
    doNothing().when(entityManager).setManagers(anyListOf(SecuredEntityManager.class));
    ToolGroup toolGroup1 = new ToolGroup();
    toolGroup1.setId(1L);
    ToolGroup toolGroup2 = new ToolGroup();
    toolGroup2.setId(2L);
    when(issueManager.loadIssuesForEntity(any())).thenReturn(Arrays.asList(Issue.builder().id(1L).build(), Issue.builder().id(2L).build()));
    when(toolGroupManager.loadByRegistryId(anyLong())).thenReturn(Arrays.asList(toolGroup1, toolGroup2));
    when(toolManager.loadToolsByGroup(anyLong())).thenReturn(null);
    doNothing().when(eventDao).insertUpdateEvent(anyString(), anyLong());
    dockerRegistryEventService.updateEventsWithChildrenAndIssues(1L);
    verify(eventDao).insertUpdateEvent("docker_registry", 1L);
    verify(eventDao).insertUpdateEvent("tool_group", 1L);
    verify(eventDao).insertUpdateEvent("tool_group", 2L);
    // 1 registry + 2 toolGroup
    verify(eventDao, times(3)).insertUpdateEvent("issue", 1L);
    verify(eventDao, times(3)).insertUpdateEvent("issue", 2L);
    verifyNoMoreInteractions(eventDao);
}
Also used : SecuredEntityManager(com.epam.pipeline.manager.security.SecuredEntityManager) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with ToolGroup

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

the class DockerContainerOperationManager method commitContainer.

public PipelineRun commitContainer(PipelineRun run, DockerRegistry registry, String newImageName, boolean clearContainer, boolean stopPipeline) {
    final String containerId = kubernetesManager.getContainerIdFromKubernetesPod(run.getPodId(), run.getDockerImage());
    final String apiToken = authManager.issueTokenForCurrentUser(null).getToken();
    String dockerLogin;
    String dockerPassword;
    // Let's use pipe auth if it's enabled for registry
    if (registry.isPipelineAuth()) {
        dockerLogin = authManager.getAuthorizedUser();
        dockerPassword = apiToken;
    } else {
        dockerLogin = registry.getUserName() == null ? EMPTY : registry.getUserName();
        dockerPassword = registry.getPassword() == null ? EMPTY : registry.getPassword();
    }
    if (newImageName.startsWith(registry.getPath())) {
        newImageName = newImageName.replace(registry.getPath() + DELIMITER, EMPTY);
    }
    Matcher matcher = GROUP_AND_IMAGE.matcher(newImageName);
    Assert.isTrue(matcher.find(), messageHelper.getMessage(MessageConstants.ERROR_TOOL_GROUP_IS_NOT_PROVIDED, newImageName));
    String toolGroupName = matcher.group(1);
    ToolGroup toolGroup = toolGroupManager.loadByNameOrId(registry.getPath() + DELIMITER + toolGroupName);
    try {
        Assert.notNull(containerId, messageHelper.getMessage(MessageConstants.ERROR_CONTAINER_ID_FOR_RUN_NOT_FOUND, run.getId()));
        String commitContainerCommand = String.format(COMMIT_COMMAND_TEMPLATE, commitRunStarterScriptUrl, preferenceManager.getPreference(SystemPreferences.BASE_API_HOST), apiToken, commitScriptsDistributionsUrl, preferenceManager.getPreference(SystemPreferences.BASE_PIPE_DISTR_URL), run.getId(), containerId, clearContainer, stopPipeline, preferenceManager.getPreference(SystemPreferences.COMMIT_TIMEOUT), registry.getPath(), registry.getId(), toolGroup.getId(), newImageName, dockerLogin, dockerPassword, registry.isPipelineAuth());
        Process sshConnection = submitCommandViaSSH(run.getInstance().getNodeIP(), commitContainerCommand);
        boolean isFinished = sshConnection.waitFor(preferenceManager.getPreference(SystemPreferences.COMMIT_TIMEOUT), TimeUnit.SECONDS);
        Assert.state(isFinished && sshConnection.exitValue() == 0, messageHelper.getMessage(MessageConstants.ERROR_RUN_PIPELINES_COMMIT_FAILED, run.getId()));
    } catch (IllegalStateException | IllegalArgumentException | IOException e) {
        LOGGER.error(e.getMessage());
        updatePipelineRunCommitStatus(run, CommitStatus.FAILURE);
        throw new CmdExecutionException(COMMIT_COMMAND_DESCRIPTION, e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        updatePipelineRunCommitStatus(run, CommitStatus.FAILURE);
        throw new CmdExecutionException(COMMIT_COMMAND_DESCRIPTION, e);
    }
    updatePipelineRunCommitStatus(run, CommitStatus.COMMITTING);
    return run;
}
Also used : ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Matcher(java.util.regex.Matcher) IOException(java.io.IOException) CmdExecutionException(com.epam.pipeline.exception.CmdExecutionException)

Example 14 with ToolGroup

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

the class DockerRegistryManager method fetchToolGroup.

private ToolGroup fetchToolGroup(DockerRegistryEvent event, DockerRegistry registry, String group) {
    ToolGroup toolGroup;
    if (!toolGroupManager.doesToolGroupExist(registry.getPath(), group)) {
        String actor = event.getActor().getName();
        Assert.isTrue(permissionManager.isActionAllowedForUser(registry, actor, AclPermission.WRITE), messageHelper.getMessage(MessageConstants.ERROR_PERMISSION_IS_NOT_GRANTED, registry.getPath(), AclPermission.WRITE_PERMISSION));
        toolGroup = new ToolGroup();
        toolGroup.setName(group);
        toolGroup.setRegistryId(registry.getId());
        toolGroup.setOwner(event.getActor().getName());
        toolGroupManager.create(toolGroup);
    } else {
        toolGroup = toolGroupManager.loadByNameOrId(registry.getPath() + Constants.PATH_DELIMITER + group);
    }
    return toolGroup;
}
Also used : ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup)

Example 15 with ToolGroup

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

the class PipelineConfigurationManagerTest method setUp.

@Before
public void setUp() throws Exception {
    registry = new DockerRegistry();
    registry.setPath(TEST_REPO);
    registry.setOwner(TEST_USER);
    dockerRegistryDao.createDockerRegistry(registry);
    library = new ToolGroup();
    library.setName(TOOL_GROUP_NAME);
    library.setRegistryId(registry.getId());
    library.setOwner(TEST_USER);
    toolGroupDao.createToolGroup(library);
    tool = new Tool();
    tool.setImage(TEST_IMAGE);
    tool.setRam(TEST_RAM);
    tool.setCpu(TEST_CPU);
    tool.setOwner(TEST_USER);
    tool.setRegistryId(registry.getId());
    tool.setToolGroupId(library.getId());
    toolDao.createTool(tool);
    // Data storages of user 1
    NFSDataStorage dataStorage = new NFSDataStorage(dataStorageDao.createDataStorageId(), "testNFS", "test/path1");
    dataStorage.setMountOptions("testMountOptions1");
    dataStorage.setMountPoint("/some/other/path");
    dataStorage.setOwner(TEST_OWNER1);
    dataStorageDao.createDataStorage(dataStorage);
    dataStorages.add(dataStorage);
    S3bucketDataStorage bucketDataStorage = new S3bucketDataStorage(dataStorageDao.createDataStorageId(), "testBucket", "test/path2");
    bucketDataStorage.setOwner(TEST_OWNER1);
    dataStorageDao.createDataStorage(bucketDataStorage);
    dataStorages.add(bucketDataStorage);
    // Data storages of user 2
    dataStorage = new NFSDataStorage(dataStorageDao.createDataStorageId(), "testNFS2", "test/path3");
    dataStorage.setMountOptions("testMountOptions2");
    dataStorage.setOwner(TEST_OWNER2);
    dataStorageDao.createDataStorage(dataStorage);
    dataStorages.add(dataStorage);
    bucketDataStorage = new S3bucketDataStorage(dataStorageDao.createDataStorageId(), "testBucket2", "test/path4");
    bucketDataStorage.setOwner(TEST_OWNER2);
    dataStorageDao.createDataStorage(bucketDataStorage);
    dataStorages.add(bucketDataStorage);
    dataStorages.forEach(ds -> aclTestDao.createAclForObject(ds));
    aclTestDao.grantPermissions(dataStorage, TEST_OWNER1, Collections.singletonList((AclPermission) AclPermission.READ));
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) AclPermission(com.epam.pipeline.security.acl.AclPermission) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) NFSDataStorage(com.epam.pipeline.entity.datastorage.nfs.NFSDataStorage) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) Tool(com.epam.pipeline.entity.pipeline.Tool) Before(org.junit.Before)

Aggregations

ToolGroup (com.epam.pipeline.entity.pipeline.ToolGroup)53 Transactional (org.springframework.transaction.annotation.Transactional)27 DockerRegistry (com.epam.pipeline.entity.pipeline.DockerRegistry)25 Test (org.junit.Test)20 Tool (com.epam.pipeline.entity.pipeline.Tool)14 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)10 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)10 Before (org.junit.Before)10 AclPermission (com.epam.pipeline.security.acl.AclPermission)6 List (java.util.List)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Propagation (org.springframework.transaction.annotation.Propagation)6 DockerRegistryDao (com.epam.pipeline.dao.docker.DockerRegistryDao)4 AclTestDao (com.epam.pipeline.dao.util.AclTestDao)4 AclClass (com.epam.pipeline.entity.security.acl.AclClass)4 Optional (java.util.Optional)4 Assert (org.junit.Assert)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 PermissionGrantVO (com.epam.pipeline.controller.vo.PermissionGrantVO)3 ToolGroupDao (com.epam.pipeline.dao.tool.ToolGroupDao)3