Search in sources :

Example 1 with FilterNodesVO

use of com.epam.pipeline.controller.vo.FilterNodesVO 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

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