Search in sources :

Example 1 with NodeInstance

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

the class CAdvisorMonitoringManagerTest method testGetStatsForNodeWithoutIp.

@Test
public void testGetStatsForNodeWithoutIp() {
    NodeInstance nodeWithoutIP = getNodeInstance(NOT_INTERNALIP_ADDRESS, NOT_INTERNALIP_TYPE, NODE_WITHOUT_INTERNALIP_ADRESS);
    when(nodesManager.getNode(NODE_WITHOUT_INTERNALIP_ADRESS)).thenReturn(nodeWithoutIP);
    assertThat(cAdvisorMonitoringManager.getStatsForNode(NODE_WITHOUT_INTERNALIP_ADRESS), is(Collections.emptyList()));
}
Also used : NodeInstance(com.epam.pipeline.entity.cluster.NodeInstance) Test(org.junit.Test)

Example 2 with NodeInstance

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

the class NodesManager method getNodes.

public List<NodeInstance> getNodes() {
    List<NodeInstance> result;
    Config config = new Config();
    try (KubernetesClient client = new DefaultKubernetesClient(config)) {
        result = client.nodes().list().getItems().stream().map(NodeInstance::new).collect(Collectors.toList());
        this.attachRunsInfo(result);
    }
    return result;
}
Also used : DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Config(io.fabric8.kubernetes.client.Config) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) NodeInstance(com.epam.pipeline.entity.cluster.NodeInstance)

Example 3 with NodeInstance

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

the class NodesManager method terminateNode.

public NodeInstance terminateNode(String name) {
    NodeInstance nodeInstance = getNode(name);
    Assert.isTrue(!isNodeProtected(nodeInstance), messageHelper.getMessage(MessageConstants.ERROR_NODE_IS_PROTECTED, name));
    if (nodeInstance.getPipelineRun() != null) {
        PipelineRun run = nodeInstance.getPipelineRun();
        pipelineRunManager.updatePipelineStatusIfNotFinal(run.getId(), TaskStatus.STOPPED, null);
    }
    Optional<NodeInstanceAddress> internalIP = nodeInstance.getAddresses().stream().filter(a -> a.getType() != null && a.getType().equalsIgnoreCase("internalip")).findAny();
    if (internalIP.isPresent()) {
        String command = buildCommand(internalIP.get().getAddress(), nodeInstance.getName(), nodeTerminateScript);
        LOGGER.debug("Terminating node. Command: {}.", command);
        cmdExecutor.executeCommand(command);
    }
    return nodeInstance;
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) Arrays(java.util.Arrays) MessageConstants(com.epam.pipeline.common.MessageConstants) PipelineRunManager(com.epam.pipeline.manager.pipeline.PipelineRunManager) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) FilterPodsRequest(com.epam.pipeline.entity.cluster.FilterPodsRequest) Resource(io.fabric8.kubernetes.client.dsl.Resource) MessageHelper(com.epam.pipeline.common.MessageHelper) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) NodeInstanceAddress(com.epam.pipeline.entity.cluster.NodeInstanceAddress) Map(java.util.Map) ClusterDao(com.epam.pipeline.dao.cluster.ClusterDao) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Node(io.fabric8.kubernetes.api.model.Node) MapUtils(org.apache.commons.collections4.MapUtils) Logger(org.slf4j.Logger) DoneableNode(io.fabric8.kubernetes.api.model.DoneableNode) PodInstance(com.epam.pipeline.entity.cluster.PodInstance) Predicate(java.util.function.Predicate) TaskStatus(com.epam.pipeline.entity.pipeline.TaskStatus) HashedMap(org.apache.commons.collections4.map.HashedMap) Collectors(java.util.stream.Collectors) Config(io.fabric8.kubernetes.client.Config) NodeInstance(com.epam.pipeline.entity.cluster.NodeInstance) List(java.util.List) StringUtils(com.amazonaws.util.StringUtils) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) PostConstruct(javax.annotation.PostConstruct) CmdExecutor(com.epam.pipeline.manager.CmdExecutor) Optional(java.util.Optional) FilterNodesVO(com.epam.pipeline.controller.vo.FilterNodesVO) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) NodeInstanceAddress(com.epam.pipeline.entity.cluster.NodeInstanceAddress) NodeInstance(com.epam.pipeline.entity.cluster.NodeInstance)

Example 4 with NodeInstance

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

the class NodesManager method getNode.

public NodeInstance getNode(String name, FilterPodsRequest request) {
    NodeInstance nodeInstance = null;
    try (KubernetesClient client = new DefaultKubernetesClient()) {
        Resource<Node, DoneableNode> nodeSearchResult = client.nodes().withName(name);
        Node node = nodeSearchResult.get();
        if (node != null) {
            final List<String> statuses = request != null ? request.getPodStatuses() : null;
            nodeInstance = new NodeInstance(node);
            this.attachRunsInfo(Collections.singletonList(nodeInstance));
            nodeInstance.setPods(PodInstance.convertToInstances(client.pods().list(), FilterPodsRequest.getPodsByNodeNameAndStatusPredicate(name, statuses)));
        }
    }
    Assert.notNull(nodeInstance, messageHelper.getMessage(MessageConstants.ERROR_NODE_NOT_FOUND, name));
    return nodeInstance;
}
Also used : DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DoneableNode(io.fabric8.kubernetes.api.model.DoneableNode) Node(io.fabric8.kubernetes.api.model.Node) DoneableNode(io.fabric8.kubernetes.api.model.DoneableNode) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) NodeInstance(com.epam.pipeline.entity.cluster.NodeInstance)

Example 5 with NodeInstance

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

the class NodesManager method filterNodes.

public List<NodeInstance> filterNodes(FilterNodesVO filterNodesVO) {
    List<NodeInstance> result;
    Config config = new Config();
    try (KubernetesClient client = new DefaultKubernetesClient(config)) {
        Map<String, String> labelsMap = new HashedMap<>();
        if (!StringUtils.isNullOrEmpty(filterNodesVO.getRunId())) {
            labelsMap.put(NodeInstance.RUN_ID_LABEL, filterNodesVO.getRunId());
        }
        Predicate<NodeInstance> addressFilter = node -> true;
        if (!StringUtils.isNullOrEmpty(filterNodesVO.getAddress())) {
            Predicate<NodeInstanceAddress> addressEqualsPredicate = address -> !StringUtils.isNullOrEmpty(address.getAddress()) && address.getAddress().equalsIgnoreCase(filterNodesVO.getAddress());
            addressFilter = node -> node.getAddresses() != null && node.getAddresses().stream().filter(addressEqualsPredicate).count() > 0;
        }
        result = client.nodes().withLabels(labelsMap).list().getItems().stream().map(NodeInstance::new).filter(addressFilter).collect(Collectors.toList());
        this.attachRunsInfo(result);
    }
    return result;
}
Also used : Arrays(java.util.Arrays) MessageConstants(com.epam.pipeline.common.MessageConstants) PipelineRunManager(com.epam.pipeline.manager.pipeline.PipelineRunManager) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) FilterPodsRequest(com.epam.pipeline.entity.cluster.FilterPodsRequest) Resource(io.fabric8.kubernetes.client.dsl.Resource) MessageHelper(com.epam.pipeline.common.MessageHelper) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) NodeInstanceAddress(com.epam.pipeline.entity.cluster.NodeInstanceAddress) Map(java.util.Map) ClusterDao(com.epam.pipeline.dao.cluster.ClusterDao) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Node(io.fabric8.kubernetes.api.model.Node) MapUtils(org.apache.commons.collections4.MapUtils) Logger(org.slf4j.Logger) DoneableNode(io.fabric8.kubernetes.api.model.DoneableNode) PodInstance(com.epam.pipeline.entity.cluster.PodInstance) Predicate(java.util.function.Predicate) TaskStatus(com.epam.pipeline.entity.pipeline.TaskStatus) HashedMap(org.apache.commons.collections4.map.HashedMap) Collectors(java.util.stream.Collectors) Config(io.fabric8.kubernetes.client.Config) NodeInstance(com.epam.pipeline.entity.cluster.NodeInstance) List(java.util.List) StringUtils(com.amazonaws.util.StringUtils) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) PostConstruct(javax.annotation.PostConstruct) CmdExecutor(com.epam.pipeline.manager.CmdExecutor) Optional(java.util.Optional) FilterNodesVO(com.epam.pipeline.controller.vo.FilterNodesVO) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) NodeInstanceAddress(com.epam.pipeline.entity.cluster.NodeInstanceAddress) Config(io.fabric8.kubernetes.client.Config) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) HashedMap(org.apache.commons.collections4.map.HashedMap) NodeInstance(com.epam.pipeline.entity.cluster.NodeInstance)

Aggregations

NodeInstance (com.epam.pipeline.entity.cluster.NodeInstance)7 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)4 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)4 NodeInstanceAddress (com.epam.pipeline.entity.cluster.NodeInstanceAddress)3 DoneableNode (io.fabric8.kubernetes.api.model.DoneableNode)3 Node (io.fabric8.kubernetes.api.model.Node)3 Config (io.fabric8.kubernetes.client.Config)3 StringUtils (com.amazonaws.util.StringUtils)2 MessageConstants (com.epam.pipeline.common.MessageConstants)2 MessageHelper (com.epam.pipeline.common.MessageHelper)2 FilterNodesVO (com.epam.pipeline.controller.vo.FilterNodesVO)2 ClusterDao (com.epam.pipeline.dao.cluster.ClusterDao)2 FilterPodsRequest (com.epam.pipeline.entity.cluster.FilterPodsRequest)2 PodInstance (com.epam.pipeline.entity.cluster.PodInstance)2 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)2 TaskStatus (com.epam.pipeline.entity.pipeline.TaskStatus)2 CmdExecutor (com.epam.pipeline.manager.CmdExecutor)2 PipelineRunManager (com.epam.pipeline.manager.pipeline.PipelineRunManager)2 Resource (io.fabric8.kubernetes.client.dsl.Resource)2 ArrayList (java.util.ArrayList)2