Search in sources :

Example 1 with V1NodeAddress

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;
}
Also used : JobMasterAPI(edu.iu.dsc.tws.proto.jobmaster.JobMasterAPI) V1Node(io.kubernetes.client.openapi.models.V1Node) V1NodeList(io.kubernetes.client.openapi.models.V1NodeList) ArrayList(java.util.ArrayList) V1NodeAddress(io.kubernetes.client.openapi.models.V1NodeAddress) ApiException(io.kubernetes.client.openapi.ApiException)

Aggregations

JobMasterAPI (edu.iu.dsc.tws.proto.jobmaster.JobMasterAPI)1 ApiException (io.kubernetes.client.openapi.ApiException)1 V1Node (io.kubernetes.client.openapi.models.V1Node)1 V1NodeAddress (io.kubernetes.client.openapi.models.V1NodeAddress)1 V1NodeList (io.kubernetes.client.openapi.models.V1NodeList)1 ArrayList (java.util.ArrayList)1