use of io.kubernetes.client.openapi.models.V1NodeAddress in project twister2 by DSC-SPIDAL.
the class KubernetesController method getNodeInfo.
/**
* get NodeInfoUtils objects for the nodes on this cluster
*
* @return the NodeInfoUtils object list. If it can not get the list from K8s master, return null.
*/
public ArrayList<JobMasterAPI.NodeInfo> getNodeInfo(String rackLabelKey, String datacenterLabelKey) {
V1NodeList nodeList = null;
try {
nodeList = coreApi.listNode(null, null, null, null, null, null, null, null, null);
} catch (ApiException e) {
LOG.log(Level.SEVERE, "Exception when getting NodeList.", e);
return null;
}
ArrayList<JobMasterAPI.NodeInfo> nodeInfoList = new ArrayList<>();
for (V1Node node : nodeList.getItems()) {
List<V1NodeAddress> addressList = node.getStatus().getAddresses();
for (V1NodeAddress nodeAddress : addressList) {
if ("InternalIP".equalsIgnoreCase(nodeAddress.getType())) {
String nodeIP = nodeAddress.getAddress();
String rackName = null;
String datacenterName = null;
// get labels
Map<String, String> labelMap = node.getMetadata().getLabels();
for (String key : labelMap.keySet()) {
if (key.equalsIgnoreCase(rackLabelKey)) {
rackName = labelMap.get(key);
}
if (key.equalsIgnoreCase(datacenterLabelKey)) {
datacenterName = labelMap.get(key);
}
}
JobMasterAPI.NodeInfo nodeInfo = NodeInfoUtils.createNodeInfo(nodeIP, rackName, datacenterName);
nodeInfoList.add(nodeInfo);
break;
}
}
}
return nodeInfoList;
}
Aggregations