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