Search in sources :

Example 1 with NodeInstanceAddress

use of com.epam.pipeline.entity.cluster.NodeInstanceAddress 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 2 with NodeInstanceAddress

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

the class CAdvisorMonitoringManagerTest method getNodeInstance.

private NodeInstance getNodeInstance(String address, String type, String nodeName) {
    NodeAddress nodeAddress = new NodeAddress(address, type);
    NodeInstanceAddress nodeInstanceAddress = new NodeInstanceAddress(nodeAddress);
    NodeInstance nodeWithIP = new NodeInstance();
    nodeWithIP.setName(nodeName);
    nodeWithIP.setAddresses(Collections.singletonList(nodeInstanceAddress));
    return nodeWithIP;
}
Also used : NodeInstanceAddress(com.epam.pipeline.entity.cluster.NodeInstanceAddress) NodeAddress(io.fabric8.kubernetes.api.model.NodeAddress) NodeInstance(com.epam.pipeline.entity.cluster.NodeInstance)

Example 3 with NodeInstanceAddress

use of com.epam.pipeline.entity.cluster.NodeInstanceAddress 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)3 NodeInstanceAddress (com.epam.pipeline.entity.cluster.NodeInstanceAddress)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 DoneableNode (io.fabric8.kubernetes.api.model.DoneableNode)2 Node (io.fabric8.kubernetes.api.model.Node)2 Config (io.fabric8.kubernetes.client.Config)2 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 Resource (io.fabric8.kubernetes.client.dsl.Resource)2 ArrayList (java.util.ArrayList)2