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