Search in sources :

Example 1 with CurrentThreadExecutorService

use of com.epam.pipeline.util.CurrentThreadExecutorService 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)

Aggregations

PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)1 RunInstance (com.epam.pipeline.entity.pipeline.RunInstance)1 CurrentThreadExecutorService (com.epam.pipeline.util.CurrentThreadExecutorService)1 KubernetesTestUtils (com.epam.pipeline.util.KubernetesTestUtils)1 DoneableNode (io.fabric8.kubernetes.api.model.DoneableNode)1 DoneablePod (io.fabric8.kubernetes.api.model.DoneablePod)1 Node (io.fabric8.kubernetes.api.model.Node)1 NodeList (io.fabric8.kubernetes.api.model.NodeList)1 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 PodCondition (io.fabric8.kubernetes.api.model.PodCondition)1 PodList (io.fabric8.kubernetes.api.model.PodList)1 PodStatus (io.fabric8.kubernetes.api.model.PodStatus)1 Config (io.fabric8.kubernetes.client.Config)1 PodResource (io.fabric8.kubernetes.client.dsl.PodResource)1 Resource (io.fabric8.kubernetes.client.dsl.Resource)1 Before (org.junit.Before)1