use of com.epam.pipeline.entity.pipeline.PipelineRun in project cloud-pipeline by epam.
the class EnvVarsBuilder method buildEnvVars.
public static List<EnvVar> buildEnvVars(PipelineRun run, PipelineConfiguration configuration, Map<SystemParams, String> sysParams, Map<String, String> externalProperties) {
List<EnvVar> fullEnvVars = new ArrayList<>();
Map<String, String> envVarsMap = new HashMap<>();
sysParams.entrySet().stream().map(sysParam -> {
String name = sysParam.getKey().getEnvName();
String value = sysParam.getValue();
if (!sysParam.getKey().isSecure()) {
envVarsMap.put(name, value);
}
return new EnvVar(name, value, null);
}).forEach(fullEnvVars::add);
configuration.getParameters().entrySet().stream().map(parameter -> {
String name = parameter.getKey();
String value = parameter.getValue().getValue();
String type = parameter.getValue().getType();
return matchParameterToEnvVars(name, value, type, envVarsMap);
}).flatMap(Arrays::stream).forEach(fullEnvVars::add);
configuration.getEnvironmentParams().entrySet().stream().map(parameter -> {
String name = parameter.getKey();
String value = parameter.getValue();
envVarsMap.put(name, value);
return new EnvVar(name, value, null);
}).forEach(fullEnvVars::add);
if (!MapUtils.isEmpty(externalProperties)) {
externalProperties.entrySet().stream().map(property -> {
String name = getBashName(property.getKey());
envVarsMap.put(name, property.getValue());
return new EnvVar(name, property.getValue(), null);
}).forEach(fullEnvVars::add);
}
run.setEnvVars(envVarsMap);
return fullEnvVars;
}
use of com.epam.pipeline.entity.pipeline.PipelineRun in project cloud-pipeline by epam.
the class NotificationManagerTest method testNotifyIdleRun.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testNotifyIdleRun() {
PipelineRun run1 = new PipelineRun();
run1.setOwner(testUser1.getUserName());
run1.setStartDate(DateUtils.now());
run1.setId(1L);
PipelineRun run2 = new PipelineRun();
run2.setStartDate(DateUtils.now());
run2.setOwner(testUser2.getUserName());
run2.setId(2L);
notificationManager.notifyIdleRuns(Arrays.asList(new ImmutablePair<>(run1, TEST_CPU_RATE1), new ImmutablePair<>(run2, TEST_CPU_RATE2)), NotificationType.IDLE_RUN);
List<NotificationMessage> messages = monitoringNotificationDao.loadAllNotifications();
Assert.assertEquals(2, messages.size());
messages.forEach(m -> Assert.assertEquals(SystemPreferences.SYSTEM_IDLE_CPU_THRESHOLD_PERCENT.getDefaultValue().doubleValue(), m.getTemplateParameters().get("idleCpuLevel")));
NotificationMessage run1Message = messages.stream().filter(m -> m.getToUserId().equals(testUser1.getId())).findFirst().get();
Assert.assertEquals(TEST_CPU_RATE1 * PERCENT, run1Message.getTemplateParameters().get("cpuRate"));
Assert.assertEquals(run1.getId().intValue(), run1Message.getTemplateParameters().get("id"));
NotificationMessage run2Message = messages.stream().filter(m -> m.getToUserId().equals(testUser2.getId())).findFirst().get();
Assert.assertEquals(TEST_CPU_RATE2 * PERCENT, run2Message.getTemplateParameters().get("cpuRate"));
Assert.assertEquals(run2.getId().intValue(), run2Message.getTemplateParameters().get("id"));
}
use of com.epam.pipeline.entity.pipeline.PipelineRun in project cloud-pipeline by epam.
the class NotificationManagerTest method setUp.
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
admin = new PipelineUser("admin");
userDao.createUser(admin, Collections.singletonList(DefaultRoles.ROLE_ADMIN.getId()));
testOwner = new PipelineUser("testOwner");
userDao.createUser(testOwner, Collections.emptyList());
testUser1 = new PipelineUser("TestUser1");
userDao.createUser(testUser1, Collections.emptyList());
testUser2 = new PipelineUser("TestUser2");
userDao.createUser(testUser2, Collections.emptyList());
longRunningTemplate = createTemplate(1L, "testTemplate");
longRunningSettings = createSettings(NotificationType.LONG_RUNNING, longRunningTemplate.getId(), 1L, 1L);
issueTemplate = createTemplate(3L, "issueTemplate");
issueSettings = createSettings(NotificationType.NEW_ISSUE, issueTemplate.getId(), -1L, -1L);
issueCommentTemplate = createTemplate(4L, "issueCommentTemplate");
issueCommentSettings = createSettings(NotificationType.NEW_ISSUE_COMMENT, issueCommentTemplate.getId(), -1L, -1L);
createTemplate(NotificationType.IDLE_RUN.getId(), "idle-run-template");
createSettings(NotificationType.IDLE_RUN, NotificationType.IDLE_RUN.getId(), -1, -1);
longRunnging = new PipelineRun();
DateTime date = DateTime.now(DateTimeZone.UTC).minus(Duration.standardMinutes(6));
longRunnging.setStartDate(date.toDate());
longRunnging.setStatus(TaskStatus.RUNNING);
longRunnging.setOwner(admin.getUserName());
longRunnging.setPodId("longRunning");
when(pipelineRunManager.loadRunningAndTerminatedPipelineRuns()).thenReturn(Collections.singletonList(longRunnging));
when(pipelineRunManager.loadPipelineRun(org.mockito.Matchers.any())).thenReturn(longRunnging);
when(kubernetesManager.getKubernetesClient()).thenReturn(mockClient);
ExtendedRole noAdmins = new ExtendedRole();
noAdmins.setUsers(Collections.emptyList());
Pod mockPod = mock(Pod.class);
PodStatus podStatus = new PodStatus(null, null, "hostIp", "", "", "podIp", "bla-bla", "5 o'clock");
podMetadata = new ObjectMeta();
podMetadata.setLabels(Collections.emptyMap());
when(mockPod.getStatus()).thenReturn(podStatus);
when(mockPod.getMetadata()).thenReturn(podMetadata);
MixedOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> mockPods = new KubernetesTestUtils.MockPods().mockNamespace(Matchers.any(String.class)).mockWithName(Matchers.any(String.class)).mockPod(mockPod).and().getMockedEntity();
when(mockClient.pods()).thenReturn(mockPods);
}
use of com.epam.pipeline.entity.pipeline.PipelineRun in project cloud-pipeline by epam.
the class NotificationManagerTest method testNotifyLongRunning.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testNotifyLongRunning() {
podMonitor.updateStatus();
List<NotificationMessage> messages = monitoringNotificationDao.loadAllNotifications();
Assert.assertEquals(1, messages.size());
Assert.assertEquals(admin.getId(), messages.get(0).getToUserId());
Assert.assertTrue(messages.get(0).getCopyUserIds().contains(admin.getId()));
Assert.assertEquals(longRunningTemplate.getId(), messages.get(0).getTemplate().getId());
ArgumentCaptor<PipelineRun> runCaptor = ArgumentCaptor.forClass(PipelineRun.class);
verify(pipelineRunManager).updatePipelineRunLastNotification(runCaptor.capture());
PipelineRun capturedRun = runCaptor.getValue();
Assert.assertNotNull(capturedRun.getLastNotificationTime());
}
use of com.epam.pipeline.entity.pipeline.PipelineRun in project cloud-pipeline by epam.
the class RunLogManagerTest method downloadLogs.
@Test
public void downloadLogs() throws Exception {
PipelineRun run = new PipelineRun(1L, "");
List<RunLog> logs = new ArrayList<>();
logs.add(RunLog.builder().date(Date.from(Instant.now())).task(new PipelineTask(FIRST_TASK)).logText("First task Log1").build());
logs.add(RunLog.builder().date(Date.from(Instant.now())).task(new PipelineTask(SECOND_TASK)).logText("Second task Log1").build());
logs.add(RunLog.builder().date(Date.from(Instant.now())).task(new PipelineTask(FIRST_TASK)).logText("First task Log2").build());
Mockito.when(runManagerMock.loadPipelineRun(run.getId())).thenReturn(run);
Mockito.when(logDao.loadAllLogsForRun(run.getId())).thenReturn(logs);
String result = logManager.downloadLogs(run);
Assert.assertNotNull(result);
Assert.assertTrue(!result.isEmpty());
}
Aggregations