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());
}
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;
}
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);
}
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();
}
}
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());
}
Aggregations