Search in sources :

Example 81 with ApiException

use of io.kubernetes.client.openapi.ApiException 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)

Example 82 with ApiException

use of io.kubernetes.client.openapi.ApiException in project twister2 by DSC-SPIDAL.

the class KubernetesController method existConfigMap.

/**
 * return true if there is already a ConfigMap object with the same name on Kubernetes master,
 * otherwise return false
 */
public boolean existConfigMap(String jobID) {
    String configMapName = jobID;
    V1ConfigMapList configMapList = null;
    try {
        configMapList = coreApi.listNamespacedConfigMap(namespace, null, null, null, null, null, null, null, null, null);
    } catch (ApiException e) {
        LOG.log(Level.SEVERE, "Exception when getting ConfigMap list.", e);
        throw new RuntimeException(e);
    }
    for (V1ConfigMap configMap : configMapList.getItems()) {
        if (configMapName.equals(configMap.getMetadata().getName())) {
            return true;
        }
    }
    return false;
}
Also used : Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) V1ConfigMapList(io.kubernetes.client.openapi.models.V1ConfigMapList) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) ApiException(io.kubernetes.client.openapi.ApiException)

Aggregations

ApiException (io.kubernetes.client.openapi.ApiException)82 V1Pod (io.kubernetes.client.openapi.models.V1Pod)21 IOException (java.io.IOException)21 V1PodList (io.kubernetes.client.openapi.models.V1PodList)18 Test (org.junit.Test)18 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)17 KubectlException (io.kubernetes.client.extended.kubectl.exception.KubectlException)14 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)13 ApiClient (io.kubernetes.client.openapi.ApiClient)10 AppsV1Api (io.kubernetes.client.openapi.apis.AppsV1Api)10 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)8 V1Deployment (io.kubernetes.client.openapi.models.V1Deployment)8 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)8 V1Status (io.kubernetes.client.openapi.models.V1Status)8 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)8 Watch (io.kubernetes.client.util.Watch)8 List (java.util.List)8 Configuration (io.kubernetes.client.openapi.Configuration)6 HashMap (java.util.HashMap)6 V1Patch (io.kubernetes.client.custom.V1Patch)5