Search in sources :

Example 16 with Pipeline

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

the class DtsRunner method runEntry.

private PipelineRun runEntry(DtsRunConfigurationEntry entry, Long configurationId, List<Long> entitiesIds, PipelineConfiguration configuration) {
    Pipeline pipeline = entry.getPipelineId() == null ? null : pipelineManager.load(entry.getPipelineId());
    PipelineRun run = pipelineRunManager.createPipelineRun(entry.getPipelineVersion(), configuration, pipeline, null, entitiesIds, configurationId);
    run.setConfigName(entry.getConfigName());
    run.setDockerImage(toolManager.getExternalToolName(run.getDockerImage()));
    run.setExecutionPreferences(DtsExecutionPreferences.builder().dtsId(entry.getDtsId()).coresNumber(entry.getCoresNumber()).build());
    Map<SystemParams, String> systemParams = pipelineLauncher.matchCommonParams(run, preferenceManager.getPreference(SystemPreferences.BASE_API_HOST_EXTERNAL), configuration.getGitCredentials());
    systemParams.put(SystemParams.DISTRIBUTION_URL, preferenceManager.getPreference(SystemPreferences.DTS_DISTRIBUTION_URL));
    GitCredentials gitCredentials = configuration.getGitCredentials();
    String gitCloneUrl = gitCredentials == null ? run.getRepository() : gitCredentials.getUrl();
    String pipelineCommand = commandBuilder.build(configuration, systemParams);
    run.setActualCmd(pipelineCommand);
    String launchCmd = preferenceManager.getPreference(SystemPreferences.DTS_LAUNCH_CMD_TEMPLATE);
    String launchScriptUrl = preferenceManager.getPreference(SystemPreferences.DTS_LAUNCH_URL);
    String fullCmd = String.format(launchCmd, launchScriptUrl, launchScriptUrl, gitCloneUrl, run.getRevisionName(), pipelineCommand);
    pipelineRunManager.save(run);
    DtsSubmission submission = buildSubmission(run, configuration, entry.getCoresNumber(), systemParams, fullCmd);
    log.debug("Creating DTS submission");
    try {
        DtsSubmission scheduled = submissionManager.createSubmission(entry.getDtsId(), submission);
        if (scheduled.getState().getStatus() != TaskStatus.RUNNING) {
            return failRun(run, String.format("Submission failed to start: %s", scheduled.getState().getReason()));
        }
        log.debug("Successfully scheduled submission on DTS");
        return run;
    } catch (DtsRequestException e) {
        return failRun(run, e.getMessage());
    }
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) GitCredentials(com.epam.pipeline.entity.git.GitCredentials) SystemParams(com.epam.pipeline.manager.execution.SystemParams) DtsRequestException(com.epam.pipeline.exception.DtsRequestException) DtsSubmission(com.epam.pipeline.entity.dts.DtsSubmission) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline)

Example 17 with Pipeline

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

the class FolderDaoTest method testCRUD.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testCRUD() {
    Folder folder = getFolder();
    // load
    Folder loaded = folderDao.loadFolder(folder.getId());
    assertEquals(folder.getId(), loaded.getId());
    assertEquals(folder.getName(), loaded.getName());
    assertNull(folder.getParentId());
    // update
    Folder parent = new Folder();
    parent.setName("Parent");
    parent.setOwner(TEST_USER);
    folderDao.createFolder(parent);
    // loadAll, 2 root projects
    List<Folder> result = folderDao.loadAllFolders();
    assertEquals(2, result.size());
    folder.setParentId(parent.getId());
    folder.setName("Test2");
    folderDao.updateFolder(folder);
    Folder loaded2 = folderDao.loadFolder(folder.getId());
    assertEquals(folder.getId(), loaded2.getId());
    assertEquals(folder.getName(), loaded2.getName());
    assertEquals(folder.getParentId(), loaded2.getParentId());
    Folder loadedParent = folderDao.loadFolder(parent.getId());
    assertEquals(parent.getId(), loadedParent.getId());
    assertEquals(1, loadedParent.getChildFolders().size());
    assertEquals(folder.getId(), loadedParent.getChildFolders().get(0).getId());
    // loadAll
    List<Folder> result2 = folderDao.loadAllFolders();
    assertEquals(1, result2.size());
    // add pipeline
    Pipeline pipeline = ObjectCreatorUtils.constructPipeline(TEST_NAME, TEST_REPO, parent.getId());
    pipeline.setOwner(TEST_USER);
    pipelineDao.createPipeline(pipeline);
    Folder loadedParent2 = folderDao.loadFolder(parent.getId());
    assertEquals(pipeline.getId(), loadedParent2.getPipelines().get(0).getId());
    assertEquals(0, loadedParent2.getChildFolders().get(0).getPipelines().size());
    // delete
    folderDao.deleteFolder(folder.getId());
    assertNull(folderDao.loadFolder(folder.getId()));
    // loadAll
    List<Folder> result3 = folderDao.loadAllFolders();
    assertEquals(1, result3.size());
}
Also used : Folder(com.epam.pipeline.entity.pipeline.Folder) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with Pipeline

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

the class PipelineRunDaoTest method testLoadActiveServicesByUserInGroup.

@Test
public void testLoadActiveServicesByUserInGroup() {
    List<RunSid> runSids = new ArrayList<>();
    RunSid runSid = new RunSid();
    runSid.setName(GROUP_NAME);
    runSid.setIsPrincipal(false);
    runSids.add(runSid);
    Pipeline testPipeline = getPipeline();
    PipelineRun run = createRunWithRunSids(testPipeline.getId(), null, runSids);
    PagingRunFilterVO filterVO = new PagingRunFilterVO();
    filterVO.setPage(1);
    filterVO.setPageSize(TEST_PAGE_SIZE);
    PipelineUser user = new PipelineUser();
    user.setUserName(TEST_USER);
    user.setGroups(Collections.singletonList(GROUP_NAME));
    List<PipelineRun> runs = pipelineRunDao.loadActiveServices(filterVO, user);
    assertEquals(1, runs.size());
    assertEquals(run.getId(), runs.get(0).getId());
    assertEquals(1, runs.size());
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) RunSid(com.epam.pipeline.entity.pipeline.run.parameter.RunSid) ArrayList(java.util.ArrayList) PagingRunFilterVO(com.epam.pipeline.controller.vo.PagingRunFilterVO) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) EnvVarsBuilderTest(com.epam.pipeline.manager.execution.EnvVarsBuilderTest) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test)

Example 19 with Pipeline

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

the class PipelineRunDaoTest method testLoadActiveServicesByUserIsPrincipal.

@Test
public void testLoadActiveServicesByUserIsPrincipal() {
    List<RunSid> runSids = new ArrayList<>();
    RunSid runSid1 = new RunSid();
    runSid1.setName(TEST_USER);
    runSid1.setIsPrincipal(true);
    runSids.add(runSid1);
    Pipeline testPipeline = getPipeline();
    PipelineRun run = createRunWithRunSids(testPipeline.getId(), null, runSids);
    PagingRunFilterVO filterVO = new PagingRunFilterVO();
    filterVO.setPage(1);
    filterVO.setPageSize(TEST_PAGE_SIZE);
    PipelineUser user = new PipelineUser();
    user.setUserName(TEST_USER);
    List<PipelineRun> runs = pipelineRunDao.loadActiveServices(filterVO, user);
    assertEquals(1, runs.size());
    assertEquals(run.getId(), runs.get(0).getId());
    assertEquals(1, runs.size());
    int servicesCount = pipelineRunDao.countActiveServices(user);
    assertEquals(runs.size(), servicesCount);
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) RunSid(com.epam.pipeline.entity.pipeline.run.parameter.RunSid) ArrayList(java.util.ArrayList) PagingRunFilterVO(com.epam.pipeline.controller.vo.PagingRunFilterVO) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) EnvVarsBuilderTest(com.epam.pipeline.manager.execution.EnvVarsBuilderTest) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test)

Example 20 with Pipeline

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

the class PipelineRunDaoTest method searchPipelineRuns.

@Test
public void searchPipelineRuns() {
    Pipeline testPipeline2 = getPipeline();
    LocalDate now = LocalDate.now();
    LocalDate date = LocalDate.of(now.getYear(), now.getMonth(), 1);
    PipelineRun stopped = new PipelineRun();
    stopped.setPipelineId(testPipeline.getId());
    stopped.setVersion(TEST_REVISION_1);
    stopped.setStartDate(Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant()));
    stopped.setEndDate(stopped.getStartDate());
    stopped.setStatus(TaskStatus.STOPPED);
    stopped.setCommitStatus(CommitStatus.NOT_COMMITTED);
    stopped.setLastChangeCommitTime(new Date());
    stopped.setPodId(TEST_POD_ID);
    stopped.setParams(TEST_PARAMS);
    stopped.setOwner(USER);
    stopped.setConfigurationId(CONFIGURATION_ID_1);
    stopped.setEntitiesIds(Stream.of(ENTITY_ID_1, ENTITY_ID_2).collect(Collectors.toList()));
    pipelineRunDao.createPipelineRun(stopped);
    LocalDate date2 = LocalDate.of(now.getYear(), now.getMonth(), 2);
    PipelineRun failed = new PipelineRun();
    failed.setPipelineId(testPipeline.getId());
    failed.setVersion(TEST_REVISION_3);
    failed.setStartDate(Date.from(date2.atStartOfDay(ZoneId.systemDefault()).toInstant()));
    failed.setEndDate(failed.getStartDate());
    failed.setStatus(TaskStatus.FAILURE);
    failed.setCommitStatus(CommitStatus.NOT_COMMITTED);
    failed.setLastChangeCommitTime(new Date());
    failed.setPodId(TEST_POD_ID);
    failed.setParams(TEST_PARAMS);
    failed.setOwner(USER);
    failed.setConfigurationId(CONFIGURATION_ID_2);
    failed.setEntitiesIds(Stream.of(ENTITY_ID_2, ENTITY_ID_3).collect(Collectors.toList()));
    pipelineRunDao.createPipelineRun(failed);
    LocalDate date3 = LocalDate.of(now.getYear(), now.getMonth(), 3);
    PipelineRun running = new PipelineRun();
    running.setPipelineId(testPipeline2.getId());
    running.setVersion(TEST_REVISION_2);
    running.setStartDate(Date.from(date3.atStartOfDay(ZoneId.systemDefault()).toInstant()));
    running.setEndDate(running.getStartDate());
    running.setStatus(TaskStatus.RUNNING);
    running.setCommitStatus(CommitStatus.NOT_COMMITTED);
    running.setLastChangeCommitTime(new Date());
    running.setPodId(TEST_POD_ID);
    running.setParams(TEST_PARAMS);
    running.setOwner(USER);
    running.setConfigurationId(CONFIGURATION_ID_3);
    running.setEntitiesIds(Stream.of(ENTITY_ID_1, ENTITY_ID_3).collect(Collectors.toList()));
    pipelineRunDao.createPipelineRun(running);
    PagingRunFilterVO filterVO = new PagingRunFilterVO();
    filterVO.setPage(1);
    filterVO.setPageSize(TEST_PAGE_SIZE);
    List<PipelineRun> runs = pipelineRunDao.searchPipelineRuns(filterVO);
    assertFalse(runs.isEmpty());
    assertEquals(3, runs.size());
    filterVO.setPipelineIds(Collections.singletonList(testPipeline.getId()));
    runs = pipelineRunDao.searchPipelineRuns(filterVO);
    assertEquals(2, runs.size());
    assertTrue(runs.stream().allMatch(r -> r.getVersion().equals(TEST_REVISION_1) || r.getVersion().equals(TEST_REVISION_3)));
    filterVO.setStatuses(Arrays.asList(TaskStatus.FAILURE, TaskStatus.STOPPED));
    runs = pipelineRunDao.searchPipelineRuns(filterVO);
    assertEquals(2, runs.size());
    filterVO.setStatuses(null);
    filterVO.setVersions(Collections.singletonList(TEST_REVISION_3));
    runs = pipelineRunDao.searchPipelineRuns(filterVO);
    assertEquals(1, runs.size());
    assertTrue(runs.stream().allMatch(r -> r.getVersion().equals(TEST_REVISION_3)));
    filterVO.setStatuses(Collections.singletonList(TaskStatus.RUNNING));
    runs = pipelineRunDao.searchPipelineRuns(filterVO);
    assertTrue(runs.isEmpty());
    filterVO.setVersions(null);
    filterVO.setPipelineIds(null);
    filterVO.setStatuses(Collections.singletonList(TaskStatus.FAILURE));
    runs = pipelineRunDao.searchPipelineRuns(filterVO);
    assertEquals(1, runs.size());
    assertTrue(runs.stream().allMatch(r -> r.getStatus() == TaskStatus.FAILURE));
    filterVO.setStatuses(null);
    filterVO.setStartDateFrom(Date.from(date2.atStartOfDay(ZoneId.systemDefault()).toInstant()));
    runs = pipelineRunDao.searchPipelineRuns(filterVO);
    assertEquals(2, runs.size());
    assertTrue(runs.stream().allMatch(r -> r.getStartDate().getTime() >= date2.atStartOfDay(ZoneId.systemDefault()).toInstant().getEpochSecond()));
    filterVO.setEndDateTo(Date.from(LocalDateTime.of(now.getYear(), now.getMonth(), 2, HOURS_23, MINUTES_59).atZone(ZoneId.systemDefault()).toInstant()));
    runs = pipelineRunDao.searchPipelineRuns(filterVO);
    assertEquals(1, runs.size());
    // test filter by configuration ids
    filterVO.setStartDateFrom(null);
    filterVO.setEndDateTo(null);
    filterVO.setConfigurationIds(Stream.of(CONFIGURATION_ID_1, CONFIGURATION_ID_2).collect(Collectors.toList()));
    runs = pipelineRunDao.searchPipelineRuns(filterVO);
    assertEquals(2, runs.size());
    // test filter by entities ids
    filterVO.setConfigurationIds(null);
    filterVO.setEntitiesIds(Stream.of(ENTITY_ID_1, ENTITY_ID_2).collect(Collectors.toList()));
    runs = pipelineRunDao.searchPipelineRuns(filterVO);
    assertEquals(3, runs.size());
    filterVO.setEntitiesIds(Stream.of(ENTITY_ID_1).collect(Collectors.toList()));
    runs = pipelineRunDao.searchPipelineRuns(filterVO);
    assertEquals(2, runs.size());
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) PipelineRunFilterVO(com.epam.pipeline.controller.vo.PipelineRunFilterVO) Arrays(java.util.Arrays) EnvVarsBuilderTest(com.epam.pipeline.manager.execution.EnvVarsBuilderTest) RunSid(com.epam.pipeline.entity.pipeline.run.parameter.RunSid) Date(java.util.Date) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) CommitStatus(com.epam.pipeline.entity.pipeline.CommitStatus) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) Propagation(org.springframework.transaction.annotation.Propagation) EnvVarsBuilder(com.epam.pipeline.manager.execution.EnvVarsBuilder) Map(java.util.Map) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) Before(org.junit.Before) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) DateUtils(com.epam.pipeline.entity.utils.DateUtils) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) TaskStatus(com.epam.pipeline.entity.pipeline.TaskStatus) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) PagingRunFilterVO(com.epam.pipeline.controller.vo.PagingRunFilterVO) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) LocalDate(java.time.LocalDate) SystemParams(com.epam.pipeline.manager.execution.SystemParams) Optional(java.util.Optional) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) PagingRunFilterVO(com.epam.pipeline.controller.vo.PagingRunFilterVO) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) EnvVarsBuilderTest(com.epam.pipeline.manager.execution.EnvVarsBuilderTest) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test)

Aggregations

Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)88 Test (org.junit.Test)41 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)25 Transactional (org.springframework.transaction.annotation.Transactional)18 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)16 GitCommitEntry (com.epam.pipeline.entity.git.GitCommitEntry)14 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)13 Revision (com.epam.pipeline.entity.pipeline.Revision)12 Folder (com.epam.pipeline.entity.pipeline.Folder)10 Before (org.junit.Before)9 GitFile (com.epam.pipeline.entity.git.GitFile)8 GitRepositoryEntry (com.epam.pipeline.entity.git.GitRepositoryEntry)7 EnvVarsBuilderTest (com.epam.pipeline.manager.execution.EnvVarsBuilderTest)7 Date (java.util.Date)7 List (java.util.List)7 GitTagEntry (com.epam.pipeline.entity.git.GitTagEntry)6 PipelineUser (com.epam.pipeline.entity.user.PipelineUser)6 IsEmptyString.isEmptyString (org.hamcrest.text.IsEmptyString.isEmptyString)6 Matchers.anyString (org.mockito.Matchers.anyString)6 EntityVO (com.epam.pipeline.controller.vo.EntityVO)5