Search in sources :

Example 81 with PipelineRun

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

the class AutoscaleManagerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    autoscaleManager = new AutoscaleManager(pipelineRunManager, executorService, clusterManager, nodesManager, kubernetesManager, preferenceManager, TEST_KUBE_NAMESPACE);
    when(executorService.getExecutorService()).thenReturn(new CurrentThreadExecutorService());
    // Mock preferences
    when(preferenceManager.getPreference(SystemPreferences.CLUSTER_NODEUP_RETRY_COUNT)).thenReturn(2);
    when(preferenceManager.getPreference(SystemPreferences.CLUSTER_SPOT_MAX_ATTEMPTS)).thenReturn(1);
    when(preferenceManager.getPreference(SystemPreferences.CLUSTER_SPOT)).thenReturn(true);
    when(preferenceManager.getPreference(SystemPreferences.CLUSTER_MAX_SIZE)).thenReturn(1);
    when(preferenceManager.getPreference(SystemPreferences.CLUSTER_NODEUP_MAX_THREADS)).thenReturn(1);
    when(preferenceManager.getPreference(SystemPreferences.CLUSTER_MIN_SIZE)).thenReturn(SystemPreferences.CLUSTER_MIN_SIZE.getDefaultValue());
    when(preferenceManager.getPreference(SystemPreferences.CLUSTER_RANDOM_SCHEDULING)).thenReturn(SystemPreferences.CLUSTER_RANDOM_SCHEDULING.getDefaultValue());
    when(preferenceManager.getPreference(SystemPreferences.CLUSTER_HIGH_NON_BATCH_PRIORITY)).thenReturn(SystemPreferences.CLUSTER_HIGH_NON_BATCH_PRIORITY.getDefaultValue());
    when(kubernetesManager.getKubernetesClient(any(Config.class))).thenReturn(kubernetesClient);
    // Mock no nodes in cluster
    NonNamespaceOperation<Node, NodeList, DoneableNode, Resource<Node, DoneableNode>> mockNodes = new KubernetesTestUtils.MockNodes().mockWithLabel(KubernetesConstants.RUN_ID_LABEL).mockWithoutLabel(KubernetesConstants.PAUSED_NODE_LABEL).mockNodeList(Collections.emptyList()).and().getMockedEntity();
    when(kubernetesClient.nodes()).thenReturn(mockNodes);
    // Mock one unsceduled pod
    Pod unscheduledPipelinePod = new Pod();
    ObjectMeta metadata = new ObjectMeta();
    metadata.setLabels(Collections.singletonMap(KubernetesConstants.RUN_ID_LABEL, TEST_RUN_ID.toString()));
    unscheduledPipelinePod.setMetadata(metadata);
    PodStatus status = new PodStatus();
    status.setPhase("Pending");
    PodCondition condition = new PodCondition();
    condition.setReason(KubernetesConstants.POD_UNSCHEDULABLE);
    status.setConditions(Collections.singletonList(condition));
    unscheduledPipelinePod.setStatus(status);
    PipelineRun testRun = new PipelineRun();
    testRun.setStatus(TaskStatus.RUNNING);
    testRun.setPipelineRunParameters(Collections.emptyList());
    RunInstance spotInstance = new RunInstance();
    spotInstance.setSpot(true);
    testRun.setInstance(spotInstance);
    when(pipelineRunManager.loadPipelineRun(Mockito.eq(TEST_RUN_ID))).thenReturn(testRun);
    when(clusterManager.fillInstance(any(RunInstance.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
    MixedOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> mockPods = new KubernetesTestUtils.MockPods().mockNamespace(TEST_KUBE_NAMESPACE).mockWithLabel("type", "pipeline").mockWithLabel(KubernetesConstants.RUN_ID_LABEL).mockPodList(Collections.singletonList(unscheduledPipelinePod)).and().getMockedEntity();
    when(kubernetesClient.pods()).thenReturn(mockPods);
}
Also used : CurrentThreadExecutorService(com.epam.pipeline.util.CurrentThreadExecutorService) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) DoneableNode(io.fabric8.kubernetes.api.model.DoneableNode) 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) Config(io.fabric8.kubernetes.client.Config) Node(io.fabric8.kubernetes.api.model.Node) DoneableNode(io.fabric8.kubernetes.api.model.DoneableNode) NodeList(io.fabric8.kubernetes.api.model.NodeList) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) Resource(io.fabric8.kubernetes.client.dsl.Resource) PodResource(io.fabric8.kubernetes.client.dsl.PodResource) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) PodCondition(io.fabric8.kubernetes.api.model.PodCondition) PodStatus(io.fabric8.kubernetes.api.model.PodStatus) KubernetesTestUtils(com.epam.pipeline.util.KubernetesTestUtils) Before(org.junit.Before)

Example 82 with PipelineRun

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

the class ResourceMonitoringManagerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    resourceMonitoringManager = new ResourceMonitoringManager(pipelineRunManager, preferenceManager, notificationManager, instanceOfferManager, monitoringESDao, taskScheduler, messageHelper);
    when(preferenceManager.getObservablePreference(SystemPreferences.SYSTEM_RESOURCE_MONITORING_PERIOD)).thenReturn(Observable.empty());
    when(preferenceManager.getPreference(SystemPreferences.SYSTEM_RESOURCE_MONITORING_PERIOD)).thenReturn(TEST_RESOURCE_MONITORING_DELAY);
    when(preferenceManager.getPreference(SystemPreferences.SYSTEM_IDLE_CPU_THRESHOLD_PERCENT)).thenReturn(TEST_IDLE_THRESHOLD_PERCENT);
    when(preferenceManager.getPreference(SystemPreferences.SYSTEM_IDLE_ACTION_TIMEOUT_MINUTES)).thenReturn(1);
    when(preferenceManager.getPreference(SystemPreferences.SYSTEM_MAX_IDLE_TIMEOUT_MINUTES)).thenReturn(TEST_MAX_IDLE_MONITORING_TIMEOUT);
    testType = new InstanceType();
    testType.setVCPU(2);
    testType.setName("t1.test");
    BehaviorSubject<List<InstanceType>> mockSubject = BehaviorSubject.createDefault(Collections.singletonList(testType));
    when(instanceOfferManager.getAllInstanceTypesObservable()).thenReturn(mockSubject);
    RunInstance spotInstance = new RunInstance(testType.getName(), 0, 0, null, null, null, null, true, null);
    okayRun = new PipelineRun();
    okayRun.setInstance(spotInstance);
    okayRun.setPodId("okay-pod");
    okayRun.setId(TEST_OK_RUN_ID);
    okayRun.setStartDate(new Date(Instant.now().minus(TEST_MAX_IDLE_MONITORING_TIMEOUT + 1, ChronoUnit.MINUTES).toEpochMilli()));
    okayRun.setProlongedAtTime(DateUtils.nowUTC().minus(TEST_MAX_IDLE_MONITORING_TIMEOUT + 1, ChronoUnit.MINUTES));
    idleSpotRun = new PipelineRun();
    idleSpotRun.setInstance(spotInstance);
    idleSpotRun.setPodId("idle-spot");
    idleSpotRun.setId(TEST_IDLE_SPOT_RUN_ID);
    idleSpotRun.setStartDate(new Date(Instant.now().minus(TEST_MAX_IDLE_MONITORING_TIMEOUT + 1, ChronoUnit.MINUTES).toEpochMilli()));
    idleSpotRun.setProlongedAtTime(DateUtils.nowUTC().minus(TEST_MAX_IDLE_MONITORING_TIMEOUT + 1, ChronoUnit.MINUTES));
    idleOnDemandRun = new PipelineRun();
    idleOnDemandRun.setInstance(new RunInstance(testType.getName(), 0, 0, null, null, null, null, false, null));
    idleOnDemandRun.setPodId("idle-on-demand");
    idleOnDemandRun.setId(TEST_IDLE_ON_DEMAND_RUN_ID);
    idleOnDemandRun.setStartDate(new Date(Instant.now().minus(TEST_MAX_IDLE_MONITORING_TIMEOUT + 1, ChronoUnit.MINUTES).toEpochMilli()));
    idleOnDemandRun.setProlongedAtTime(DateUtils.nowUTC().minus(TEST_MAX_IDLE_MONITORING_TIMEOUT + 1, ChronoUnit.MINUTES));
    idleRunToProlong = new PipelineRun();
    idleRunToProlong.setInstance(new RunInstance(testType.getName(), 0, 0, null, null, null, null, false, null));
    idleRunToProlong.setPodId("idle-to-prolong");
    idleRunToProlong.setId(TEST_IDLE_RUN_TO_PROLONG_ID);
    idleRunToProlong.setStartDate(new Date(Instant.now().minus(TEST_MAX_IDLE_MONITORING_TIMEOUT + 1, ChronoUnit.MINUTES).toEpochMilli()));
    idleRunToProlong.setProlongedAtTime(DateUtils.nowUTC().minus(TEST_MAX_IDLE_MONITORING_TIMEOUT + 1, ChronoUnit.MINUTES));
    mockStats = new HashMap<>();
    // in milicores, equals 80% of core load, per 2 cores,
    mockStats.put(okayRun.getPodId(), TEST_OK_RUN_CPU_LOAD);
    // should be = 40% load
    mockStats.put(idleSpotRun.getPodId(), TEST_IDLE_SPOT_RUN_CPU_LOAD);
    mockStats.put(idleOnDemandRun.getPodId(), TEST_IDLE_ON_DEMAND_RUN_CPU_LOAD);
    when(monitoringESDao.loadCpuUsageRateMetrics(any(), any(LocalDateTime.class), any(LocalDateTime.class))).thenReturn(mockStats);
    resourceMonitoringManager.init();
    verify(taskScheduler).scheduleWithFixedDelay(any(), eq(TEST_RESOURCE_MONITORING_DELAY.longValue()));
    Assert.assertNotNull(Whitebox.getInternalState(resourceMonitoringManager, "instanceTypeMap"));
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) LocalDateTime(java.time.LocalDateTime) List(java.util.List) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) InstanceType(com.epam.pipeline.entity.cluster.InstanceType) Date(java.util.Date) Before(org.junit.Before)

Example 83 with PipelineRun

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

the class ResourceMonitoringManagerTest method testNotifyTwice.

@Test
public void testNotifyTwice() throws InterruptedException {
    when(preferenceManager.getPreference(SystemPreferences.SYSTEM_IDLE_ACTION)).thenReturn(IdleRunAction.NOTIFY.name());
    LocalDateTime lastNotificationDate = mockAlreadyNotifiedRuns();
    Thread.sleep(10);
    resourceMonitoringManager.monitorResourceUsage();
    verify(pipelineRunManager).updatePipelineRunsLastNotification(runsToUpdateCaptor.capture());
    verify(notificationManager).notifyIdleRuns(runsToNotifyCaptor.capture(), eq(NotificationType.IDLE_RUN));
    List<PipelineRun> updatedRuns = runsToUpdateCaptor.getValue();
    Assert.assertEquals(2, updatedRuns.size());
    Assert.assertFalse(updatedRuns.stream().anyMatch(r -> r.getLastIdleNotificationTime().equals(lastNotificationDate)));
    List<Pair<PipelineRun, Double>> runsToNotify = runsToNotifyCaptor.getValue();
    Assert.assertEquals(2, 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 84 with PipelineRun

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

the class ResourceMonitoringManagerTest method testNoActionIfActionTimeoutIsNotFulfilled.

@Test
public void testNoActionIfActionTimeoutIsNotFulfilled() throws InterruptedException {
    when(preferenceManager.getPreference(SystemPreferences.SYSTEM_IDLE_ACTION)).thenReturn(IdleRunAction.NOTIFY.name());
    LocalDateTime now = DateUtils.nowUTC();
    idleOnDemandRun.setLastIdleNotificationTime(now.minusSeconds(HALF_AN_HOUR));
    idleSpotRun.setLastIdleNotificationTime(now.minusSeconds(HALF_AN_HOUR));
    when(pipelineRunManager.loadRunningPipelineRuns()).thenReturn(Arrays.asList(okayRun, idleOnDemandRun, idleSpotRun));
    Thread.sleep(10);
    resourceMonitoringManager.monitorResourceUsage();
    verify(pipelineRunManager).updatePipelineRunsLastNotification(runsToUpdateCaptor.capture());
    verify(notificationManager).notifyIdleRuns(runsToNotifyCaptor.capture(), eq(NotificationType.IDLE_RUN));
    List<PipelineRun> updatedRuns = runsToUpdateCaptor.getValue();
    Assert.assertEquals(0, updatedRuns.size());
    List<Pair<PipelineRun, Double>> runsToNotify = runsToNotifyCaptor.getValue();
    Assert.assertEquals(0, runsToNotify.size());
}
Also used : LocalDateTime(java.time.LocalDateTime) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Example 85 with PipelineRun

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

the class EnvVarsBuilderTest method buildEnvVarsTest.

@Test
public void buildEnvVarsTest() throws Exception {
    List<EnvVar> envVars = EnvVarsBuilder.buildEnvVars(new PipelineRun(), configuration, systemParams, null);
    Assert.assertTrue(isParameterRight(envVars, P1, P1_VALUE, NUMBER_TYPE));
    Assert.assertTrue(isParameterRight(envVars, P2, P2_VALUE, STRING_TYPE));
    Assert.assertTrue(isParameterRight(envVars, MAIN_CLASS, MAIN_CLASS_VALUE, STRING_TYPE));
    Assert.assertTrue(isParameterRight(envVars, MAIN_FILE, MAIN_FILE_VALUE, STRING_TYPE));
    Assert.assertTrue(isParameterRight(envVars, VERSION, VERSION_VALUE, STRING_TYPE));
    Assert.assertTrue(isParameterRight(envVars, PIPELINE_ID, PIPELINE_ID_VALUE, STRING_TYPE));
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Test(org.junit.Test)

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