Search in sources :

Example 11 with V1ConfigMap

use of io.kubernetes.client.openapi.models.V1ConfigMap in project java by kubernetes-client.

the class CoreV1Api method createNamespacedConfigMapAsync.

/**
 * (asynchronously) create a ConfigMap
 *
 * @param namespace object name and auth scope, such as for teams and projects (required)
 * @param body (required)
 * @param pretty If 'true', then the output is pretty printed. (optional)
 * @param dryRun When present, indicates that modifications should not be persisted. An invalid or
 *     unrecognized dryRun directive will result in an error response and no further processing of
 *     the request. Valid values are: - All: all dry run stages will be processed (optional)
 * @param fieldManager fieldManager is a name associated with the actor or entity that is making
 *     these changes. The value must be less than or 128 characters long, and only contain
 *     printable characters, as defined by https://golang.org/pkg/unicode/#IsPrint. (optional)
 * @param fieldValidation fieldValidation determines how the server should respond to
 *     unknown/duplicate fields in the object in the request. Introduced as alpha in 1.23, older
 *     servers or servers with the `ServerSideFieldValidation` feature disabled will
 *     discard valid values specified in this param and not perform any server side field
 *     validation. Valid values are: - Ignore: ignores unknown/duplicate fields. - Warn: responds
 *     with a warning for each unknown/duplicate field, but successfully serves the request. -
 *     Strict: fails the request on unknown/duplicate fields. (optional)
 * @param _callback The callback to be executed when the API call finishes
 * @return The request call
 * @throws ApiException If fail to process the API call, e.g. serializing the request body object
 * @http.response.details
 *     <table summary="Response Details" border="1">
 * <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
 * <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
 * <tr><td> 201 </td><td> Created </td><td>  -  </td></tr>
 * <tr><td> 202 </td><td> Accepted </td><td>  -  </td></tr>
 * <tr><td> 401 </td><td> Unauthorized </td><td>  -  </td></tr>
 * </table>
 */
public okhttp3.Call createNamespacedConfigMapAsync(String namespace, V1ConfigMap body, String pretty, String dryRun, String fieldManager, String fieldValidation, final ApiCallback<V1ConfigMap> _callback) throws ApiException {
    okhttp3.Call localVarCall = createNamespacedConfigMapValidateBeforeCall(namespace, body, pretty, dryRun, fieldManager, fieldValidation, _callback);
    Type localVarReturnType = new TypeToken<V1ConfigMap>() {
    }.getType();
    localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
    return localVarCall;
}
Also used : Type(java.lang.reflect.Type) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap)

Example 12 with V1ConfigMap

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

the class K8sControllerExample method test1.

/**
 * test method
 */
public static void test1(JobAPI.Job job) {
    String jobID = "ft-job";
    String jobID2 = "ft-job-2";
    Config cnfg = Config.newBuilder().put("nothing", "nothing").build();
    RequestObjectBuilder.init(cnfg, jobID, 0, 0, null);
    V1ConfigMap cm = RequestObjectBuilder.createConfigMap(job);
    RequestObjectBuilder.init(cnfg, jobID2, 0, 0, null);
    V1ConfigMap cm2 = RequestObjectBuilder.createConfigMap(job);
    KubernetesController controller = KubernetesController.init("default");
    String key0 = KubernetesUtils.createRestartWorkerKey(0);
    String key1 = KubernetesUtils.createRestartJobMasterKey();
    if (controller.existConfigMap(cm2.getMetadata().getName())) {
        controller.deleteConfigMap(cm2.getMetadata().getName());
    } else {
        controller.createConfigMap(cm2);
        int restartCount = controller.getRestartCount(jobID2, key0);
        LOG.info("restartCount: " + restartCount);
        controller.addConfigMapParam(jobID2, key0, 0 + "");
        LOG.info("added restartCount: " + controller.getRestartCount(jobID2, key0));
        if (controller.updateConfigMapParam(jobID2, key0, 1 + "")) {
            LOG.info("updated restartCount: " + controller.getRestartCount(jobID2, key0));
        } else {
            LOG.info("Cannot update restartCount");
            LOG.info("restartCount: " + controller.getRestartCount(jobID2, key0));
        }
        if (controller.updateConfigMapParam(jobID2, key1, 10 + "")) {
            LOG.info("updated restartCount: " + controller.getRestartCount(jobID2, key1));
        } else {
            LOG.info("Cannot update restartCount");
            LOG.info("restartCount: " + controller.getRestartCount(jobID2, key1));
        }
        if (controller.removeRestartCount(jobID2, key0)) {
            LOG.info("removed restartCount: " + controller.getRestartCount(jobID2, key0));
        } else {
            LOG.info("cannot remove restartCount: " + controller.getRestartCount(jobID2, key0));
        }
    }
    if (controller.existConfigMap(cm.getMetadata().getName())) {
        controller.deleteConfigMap(cm.getMetadata().getName());
    } else {
        controller.createConfigMap(cm);
        int restartCount = controller.getRestartCount(jobID, key0);
        LOG.info("restartCount: " + restartCount);
    }
    LOG.info("done");
}
Also used : Config(edu.iu.dsc.tws.api.config.Config) JobConfig(edu.iu.dsc.tws.api.JobConfig) KubernetesController(edu.iu.dsc.tws.rsched.schedulers.k8s.KubernetesController) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap)

Example 13 with V1ConfigMap

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

the class ClientJobKillHandler method allDeleted.

/**
 * check whether Job resources deleted
 * log deleted resources
 * return true if all deleted
 */
public boolean allDeleted() {
    // check deleted StatefulSet objects
    if (!ssList.isEmpty()) {
        List<String> currentSSList = getSSList();
        Iterator<String> ssIterator = ssList.iterator();
        while (ssIterator.hasNext()) {
            String ssName = ssIterator.next();
            if (!currentSSList.contains(ssName)) {
                LOG.info("Deleted StatefulSet: " + ssName);
                ssIterator.remove();
            }
        }
    }
    // check deleted Service objects
    if (!serviceList.isEmpty()) {
        List<String> currentServiceList = getServiceList();
        Iterator<String> serviceIterator = serviceList.iterator();
        while (serviceIterator.hasNext()) {
            String serviceName = serviceIterator.next();
            if (!currentServiceList.contains(serviceName)) {
                LOG.info("Deleted Service: " + serviceName);
                serviceIterator.remove();
            }
        }
    }
    if (cm != null) {
        V1ConfigMap currentCM = controller.getJobConfigMap(jobID);
        if (currentCM == null) {
            LOG.info("Deleted ConfigMap: " + cm.getMetadata().getName());
            cm = null;
        }
    }
    if (pvc != null) {
        V1PersistentVolumeClaim currentPVC = controller.getJobPersistentVolumeClaim(jobID);
        if (currentPVC == null) {
            LOG.info("Deleted V1PersistentVolumeClaim: " + pvc.getMetadata().getName());
            pvc = null;
        }
    }
    return ssList.isEmpty() && serviceList.isEmpty() && cm == null && pvc == null;
}
Also used : V1PersistentVolumeClaim(io.kubernetes.client.openapi.models.V1PersistentVolumeClaim) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap)

Example 14 with V1ConfigMap

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

the class RequestObjectBuilder method createConfigMap.

/**
 * create a ConfigMap object
 * It will have start counts for workers
 * @return
 */
public static V1ConfigMap createConfigMap(JobAPI.Job job) {
    String configMapName = jobID;
    // set a label for ConfigMap
    HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
    // data pairs
    HashMap<String, String> dataMap = new HashMap<>();
    String encodedJob = Base64.getEncoder().encodeToString(job.toByteArray());
    dataMap.put(KubernetesConstants.JOB_OBJECT_CM_PARAM, encodedJob);
    V1ConfigMap cm = new V1ConfigMapBuilder().withApiVersion("v1").withNewMetadata().withName(configMapName).withLabels(labels).endMetadata().withData(dataMap).build();
    return cm;
}
Also used : V1ConfigMapBuilder(io.kubernetes.client.openapi.models.V1ConfigMapBuilder) HashMap(java.util.HashMap) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap)

Example 15 with V1ConfigMap

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

the class JobKillWatcher method run.

/**
 * start the watcher
 */
@Override
public void run() {
    String killParam = "KILL_JOB";
    String cmName = jobID;
    String labelSelector = KubernetesUtils.jobLabelSelector(jobID);
    Integer timeoutSeconds = Integer.MAX_VALUE;
    CoreV1Api v1Api = controller.createCoreV1Api();
    try {
        watcher = Watch.createWatch(controller.getApiClient(), v1Api.listNamespacedConfigMapCall(namespace, null, null, null, null, labelSelector, null, null, timeoutSeconds, Boolean.TRUE, null), new TypeToken<Watch.Response<V1ConfigMap>>() {
        }.getType());
    } catch (ApiException e) {
        String logMessage = "Exception when watching the ConfigMap: \n" + "exCode: " + e.getCode() + "\n" + "responseBody: " + e.getResponseBody();
        LOG.log(Level.SEVERE, logMessage, e);
        throw new RuntimeException(e);
    }
    try {
        for (Watch.Response<V1ConfigMap> item : watcher) {
            // it means that the pod is in the process of being deleted
            if (item.object != null && item.object.getData() != null && item.object.getMetadata().getName().equals(cmName) && item.object.getData().get(killParam) != null) {
                LOG.info("Job Kill parameter received. Killing the job");
                jobMaster.endJob(JobAPI.JobState.KILLED);
                return;
            }
        }
    } catch (RuntimeException e) {
        if (stopWatcher) {
            LOG.fine("Watcher is stopped.");
            return;
        } else {
            throw e;
        }
    } finally {
        try {
            watcher.close();
        } catch (IOException e) {
            LOG.warning("IOException when closing ConfigMapWatcher");
        }
    }
}
Also used : Watch(io.kubernetes.client.util.Watch) IOException(java.io.IOException) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) ApiException(io.kubernetes.client.openapi.ApiException)

Aggregations

V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)35 Test (org.junit.Test)11 Type (java.lang.reflect.Type)8 V1ConfigMapBuilder (io.kubernetes.client.openapi.models.V1ConfigMapBuilder)6 TopologySubmissionException (org.apache.heron.scheduler.TopologySubmissionException)6 Matchers.anyString (org.mockito.Matchers.anyString)6 ApiException (io.kubernetes.client.openapi.ApiException)5 LinkedList (java.util.LinkedList)5 TestTuple (org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple)5 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)4 JobConfig (edu.iu.dsc.tws.api.JobConfig)3 Config (edu.iu.dsc.tws.api.config.Config)3 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)3 HashMap (java.util.HashMap)3 Pair (org.apache.heron.common.basics.Pair)3 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)2 Twister2RuntimeException (edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException)2 KubernetesController (edu.iu.dsc.tws.rsched.schedulers.k8s.KubernetesController)2 JSON (io.kubernetes.client.openapi.JSON)2 V1ConfigMapList (io.kubernetes.client.openapi.models.V1ConfigMapList)2