Search in sources :

Example 36 with PipelineRun

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

the class ResourceMonitoringManagerTest method testPauseOnDemand.

@Test
public void testPauseOnDemand() throws InterruptedException {
    when(preferenceManager.getPreference(SystemPreferences.SYSTEM_IDLE_ACTION)).thenReturn(IdleRunAction.PAUSE.name());
    LocalDateTime lastNotificationDate = mockAlreadyNotifiedRuns();
    Thread.sleep(10);
    resourceMonitoringManager.monitorResourceUsage();
    verify(pipelineRunManager).updatePipelineRunsLastNotification(runsToUpdateCaptor.capture());
    verify(notificationManager).notifyIdleRuns(runsToNotifyCaptor.capture(), eq(NotificationType.IDLE_RUN));
    verify(notificationManager).notifyIdleRuns(any(), eq(NotificationType.IDLE_RUN_PAUSED));
    List<PipelineRun> updatedRuns = runsToUpdateCaptor.getValue();
    Assert.assertEquals(2, updatedRuns.size());
    Assert.assertFalse(updatedRuns.stream().anyMatch(r -> lastNotificationDate.equals(r.getLastIdleNotificationTime())));
    Assert.assertNull(updatedRuns.stream().filter(r -> r.getPodId().equals(idleOnDemandRun.getPodId())).findFirst().get().getLastIdleNotificationTime());
    verify(pipelineRunManager).pauseRun(TEST_IDLE_ON_DEMAND_RUN_ID, true);
    verify(pipelineRunManager, never()).pauseRun(TEST_OK_RUN_ID, true);
    List<Pair<PipelineRun, Double>> runsToNotify = runsToNotifyCaptor.getValue();
    Assert.assertEquals(1, runsToNotify.size());
}
Also used : LocalDateTime(java.time.LocalDateTime) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) Arrays(java.util.Arrays) InstanceType(com.epam.pipeline.entity.cluster.InstanceType) Mock(org.mockito.Mock) Date(java.util.Date) PipelineRunManager(com.epam.pipeline.manager.pipeline.PipelineRunManager) BehaviorSubject(io.reactivex.subjects.BehaviorSubject) LocalDateTime(java.time.LocalDateTime) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) HashMap(java.util.HashMap) IdleRunAction(com.epam.pipeline.entity.monitoring.IdleRunAction) Captor(org.mockito.Captor) MockitoAnnotations(org.mockito.MockitoAnnotations) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) ArgumentCaptor(org.mockito.ArgumentCaptor) MessageHelper(com.epam.pipeline.common.MessageHelper) Pair(org.apache.commons.lang3.tuple.Pair) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) NotificationType(com.epam.pipeline.entity.notification.NotificationSettings.NotificationType) Observable(io.reactivex.Observable) Before(org.junit.Before) DateUtils(com.epam.pipeline.entity.utils.DateUtils) InstanceOfferManager(com.epam.pipeline.manager.cluster.InstanceOfferManager) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) TaskScheduler(org.springframework.scheduling.TaskScheduler) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Instant(java.time.Instant) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Mockito.never(org.mockito.Mockito.never) ChronoUnit(java.time.temporal.ChronoUnit) Whitebox(org.mockito.internal.util.reflection.Whitebox) NotificationManager(com.epam.pipeline.manager.notification.NotificationManager) MonitoringESDao(com.epam.pipeline.dao.monitoring.MonitoringESDao) Assert(org.junit.Assert) Collections(java.util.Collections) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Example 37 with PipelineRun

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

the class ObjectCreatorUtils method createPipelineRun.

public static PipelineRun createPipelineRun(Long runId, Long pipelineId, Long parentRunId) {
    PipelineRun run = new PipelineRun();
    run.setId(runId);
    run.setPipelineId(pipelineId);
    run.setVersion(TEST_REVISION_1);
    run.setStartDate(new Date());
    run.setEndDate(new Date());
    run.setStatus(TaskStatus.RUNNING);
    run.setCommitStatus(CommitStatus.NOT_COMMITTED);
    run.setLastChangeCommitTime(new Date());
    run.setPodId(TEST_POD_ID);
    run.setOwner(TEST_NAME);
    run.setParentRunId(parentRunId);
    run.setServiceUrl(TEST_SERVICE_URL);
    RunInstance instance = new RunInstance();
    instance.setSpot(true);
    instance.setNodeId("1");
    run.setInstance(instance);
    return run;
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) Date(java.util.Date)

Example 38 with PipelineRun

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

the class FolderEventServiceTest method shouldAddFolderEvent.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void shouldAddFolderEvent() {
    doNothing().when(entityManager).setManagers(anyListOf(SecuredEntityManager.class));
    Folder folder2 = new Folder(2L);
    Pipeline pipeline = new Pipeline(1L);
    S3bucketDataStorage dataStorage = new S3bucketDataStorage(1L, "", "");
    RunConfiguration runConfiguration = new RunConfiguration();
    runConfiguration.setId(1L);
    MetadataEntity metadataEntity = new MetadataEntity();
    metadataEntity.setClassEntity(new MetadataClass(1L, METADATA_CLASS_NAME));
    metadataEntity.setId(1L);
    Folder folder1 = new Folder(1L);
    folder1.setChildFolders(Collections.singletonList(folder2));
    folder1.setPipelines(Collections.singletonList(pipeline));
    folder1.setStorages(Collections.singletonList(dataStorage));
    folder1.setConfigurations(Collections.singletonList(runConfiguration));
    folder1.setMetadata(Collections.singletonMap(METADATA_CLASS_NAME, 1));
    when(issueManager.loadIssuesForEntity(any())).thenReturn(Arrays.asList(Issue.builder().id(1L).build(), Issue.builder().id(2L).build()));
    when(pipelineRunManager.loadAllRunsByPipeline(anyLong())).thenReturn(Arrays.asList(new PipelineRun(1L, ""), new PipelineRun(2L, "")));
    when(dataStorageManager.load(1L)).thenReturn(dataStorage);
    when(folderManager.load(1L)).thenReturn(folder1);
    when(folderManager.load(2L)).thenReturn(folder2);
    when(metadataEntityManager.loadMetadataEntityByClassNameAndFolderId(anyLong(), anyString())).thenReturn(Collections.singletonList(metadataEntity));
    doNothing().when(eventDao).insertUpdateEvent(anyString(), anyLong());
    folderEventService.updateEventsWithChildrenAndIssues(1L);
    verify(eventDao).insertUpdateEvent("folder", 1L);
    verify(eventDao).insertUpdateEvent("folder", 2L);
    verify(eventDao).insertUpdateEvent("pipeline", 1L);
    verify(eventDao).insertUpdateEvent("run", 1L);
    verify(eventDao).insertUpdateEvent("run", 2L);
    verify(eventDao).insertUpdateEvent("S3", 1L);
    verify(eventDao).insertUpdateEvent("configuration", 1L);
    verify(eventDao).insertUpdateEvent("metadata_entity", 1L);
    verify(eventDao, times(6)).insertUpdateEvent("issue", 1L);
    verify(eventDao, times(6)).insertUpdateEvent("issue", 2L);
    verifyNoMoreInteractions(eventDao);
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) SecuredEntityManager(com.epam.pipeline.manager.security.SecuredEntityManager) RunConfiguration(com.epam.pipeline.entity.configuration.RunConfiguration) MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) 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 39 with PipelineRun

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

the class PipelineRunController method downloadLogs.

@RequestMapping(value = "/run/{runId}/logfile", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "Downloads pipeline run logs as a text file.", notes = "Downloads pipeline run logs a text file.", produces = MediaType.TEXT_PLAIN_VALUE)
@ApiResponses(value = { @ApiResponse(code = HTTP_STATUS_OK, message = API_STATUS_DESCRIPTION) })
public void downloadLogs(@PathVariable(value = RUN_ID) Long runId, HttpServletResponse response) throws IOException {
    PipelineRun run = runApiService.loadPipelineRun(runId);
    byte[] logs = runApiService.downloadLogs(runId).getBytes(Charset.defaultCharset());
    response.setContentType(MediaType.TEXT_PLAIN_VALUE);
    String pipelineName = !StringUtils.isEmpty(run.getPipelineName()) ? run.getPipelineName() : DEFAULT_PIPELINE_NAME;
    String pipelineVersion = !StringUtils.isEmpty(run.getVersion()) ? run.getVersion() : "";
    response.setHeader("Content-Disposition", String.format("attachment;filename=%s_%s_%d.log", pipelineName, pipelineVersion, run.getId()));
    response.setContentLengthLong(logs.length);
    try (ServletOutputStream stream = response.getOutputStream()) {
        stream.write(logs);
        stream.flush();
    }
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) ServletOutputStream(javax.servlet.ServletOutputStream) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 40 with PipelineRun

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

the class PipelineRunDao method searchPipelineGroups.

public List<PipelineRun> searchPipelineGroups(PagingRunFilterVO filter, PipelineRunFilterVO.ProjectFilter projectFilter) {
    MapSqlParameterSource params = getPagingParameters(filter);
    String query = wherePattern.matcher(loadRunsGroupingQuery).replaceFirst(makeFilterCondition(filter, projectFilter, params, false));
    Collection<PipelineRun> runs = getNamedParameterJdbcTemplate().query(query, params, PipelineRunParameters.getRunGroupExtractor());
    return runs.stream().filter(run -> run.getParentRunId() == null).sorted(getPipelineRunComparator()).collect(Collectors.toList());
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource)

Aggregations

PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)88 Test (org.junit.Test)31 Transactional (org.springframework.transaction.annotation.Transactional)29 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)23 EnvVarsBuilderTest (com.epam.pipeline.manager.execution.EnvVarsBuilderTest)22 ArrayList (java.util.ArrayList)18 RunInstance (com.epam.pipeline.entity.pipeline.RunInstance)17 Date (java.util.Date)15 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)14 List (java.util.List)14 PipelineConfiguration (com.epam.pipeline.entity.configuration.PipelineConfiguration)13 Map (java.util.Map)11 LocalDateTime (java.time.LocalDateTime)10 Arrays (java.util.Arrays)10 Collectors (java.util.stream.Collectors)10 PipelineUser (com.epam.pipeline.entity.user.PipelineUser)9 Collections (java.util.Collections)9 HashMap (java.util.HashMap)9 MessageHelper (com.epam.pipeline.common.MessageHelper)8 RunSid (com.epam.pipeline.entity.pipeline.run.parameter.RunSid)8