Search in sources :

Example 46 with PipelineRun

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;
}
Also used : MapUtils(org.apache.commons.collections4.MapUtils) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Arrays(java.util.Arrays) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EnvVar(io.fabric8.kubernetes.api.model.EnvVar)

Example 47 with PipelineRun

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"));
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 48 with PipelineRun

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);
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) ExtendedRole(com.epam.pipeline.entity.user.ExtendedRole) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) PodList(io.fabric8.kubernetes.api.model.PodList) PodResource(io.fabric8.kubernetes.client.dsl.PodResource) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) Pod(io.fabric8.kubernetes.api.model.Pod) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) DateTime(org.joda.time.DateTime) PodStatus(io.fabric8.kubernetes.api.model.PodStatus) KubernetesTestUtils(com.epam.pipeline.util.KubernetesTestUtils) Before(org.junit.Before)

Example 49 with PipelineRun

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());
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 50 with PipelineRun

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());
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) RunLog(com.epam.pipeline.entity.pipeline.RunLog) ArrayList(java.util.ArrayList) PipelineTask(com.epam.pipeline.entity.pipeline.PipelineTask) Test(org.junit.Test) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest)

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