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