Search in sources :

Example 11 with V1StatefulSet

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

the class JobMasterRequestObject method createStatefulSetObject.

/**
 * create StatefulSet object for a job
 */
public static V1StatefulSet createStatefulSetObject() {
    if (config == null) {
        LOG.severe("JobMasterRequestObject.init method has not been called.");
        return null;
    }
    V1StatefulSet statefulSet = new V1StatefulSet();
    String statefulSetName = KubernetesUtils.createJobMasterStatefulSetName(jobID);
    // set labels for the jm stateful set
    HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
    // job master statefulset
    labels.put("t2-mss", jobID);
    // construct metadata and set for jobID setting
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(statefulSetName);
    meta.setLabels(labels);
    statefulSet.setMetadata(meta);
    // construct JobSpec and set
    V1StatefulSetSpec setSpec = new V1StatefulSetSpec();
    setSpec.serviceName(KubernetesUtils.createJobMasterServiceName(jobID));
    setSpec.setReplicas(1);
    // add selector for the job
    V1LabelSelector selector = new V1LabelSelector();
    selector.putMatchLabelsItem("t2-mp", jobID);
    setSpec.setSelector(selector);
    // construct the pod template
    V1PodTemplateSpec template = constructPodTemplate();
    setSpec.setTemplate(template);
    statefulSet.setSpec(setSpec);
    return statefulSet;
}
Also used : V1StatefulSet(io.kubernetes.client.openapi.models.V1StatefulSet) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1StatefulSetSpec(io.kubernetes.client.openapi.models.V1StatefulSetSpec) IntOrString(io.kubernetes.client.custom.IntOrString) V1PodTemplateSpec(io.kubernetes.client.openapi.models.V1PodTemplateSpec) V1LabelSelector(io.kubernetes.client.openapi.models.V1LabelSelector)

Example 12 with V1StatefulSet

use of io.kubernetes.client.openapi.models.V1StatefulSet in project heron by twitter.

the class V1Controller method removeContainers.

/**
 * Removes a specified number of Pods from a <code>topology</code>'s <code>Executors</code>.
 * @param containersToRemove Set of containers to be removed.
 */
@Override
public void removeContainers(Set<PackingPlan.ContainerPlan> containersToRemove) {
    final V1StatefulSet statefulSet;
    try {
        statefulSet = getStatefulSet();
    } catch (ApiException ae) {
        final String message = ae.getMessage() + "\ndetails:" + ae.getResponseBody();
        throw new TopologyRuntimeManagementException(message, ae);
    }
    final V1StatefulSetSpec v1StatefulSet = Objects.requireNonNull(statefulSet.getSpec());
    final int currentContainerCount = Objects.requireNonNull(v1StatefulSet.getReplicas());
    final int newContainerCount = currentContainerCount - containersToRemove.size();
    try {
        patchStatefulSetReplicas(newContainerCount);
    } catch (ApiException e) {
        throw new TopologyRuntimeManagementException(e.getMessage() + "\ndetails\n" + e.getResponseBody());
    }
}
Also used : TopologyRuntimeManagementException(org.apache.heron.scheduler.TopologyRuntimeManagementException) V1StatefulSet(io.kubernetes.client.openapi.models.V1StatefulSet) V1StatefulSetSpec(io.kubernetes.client.openapi.models.V1StatefulSetSpec) ApiException(io.kubernetes.client.openapi.ApiException)

Example 13 with V1StatefulSet

use of io.kubernetes.client.openapi.models.V1StatefulSet in project heron by twitter.

the class V1Controller method createStatefulSet.

/**
 * Creates and configures the <code>StatefulSet</code> which the topology's <code>executor</code>s will run in.
 * @param containerResource Passed down to configure the <code>executor</code> resource limits.
 * @param numberOfInstances Used to configure the execution command and ports for the <code>executor</code>.
 * @param isExecutor Flag used to configure components specific to <code>executor</code> and <code>manager</code>.
 * @return A fully configured <code>StatefulSet</code> for the topology's <code>executors</code>.
 */
private V1StatefulSet createStatefulSet(Resource containerResource, int numberOfInstances, boolean isExecutor) {
    final String topologyName = getTopologyName();
    final Config runtimeConfiguration = getRuntimeConfiguration();
    final List<V1Volume> volumes = new LinkedList<>();
    final List<V1VolumeMount> volumeMounts = new LinkedList<>();
    // Collect Persistent Volume Claim configurations from the CLI.
    final Map<String, Map<KubernetesConstants.VolumeConfigKeys, String>> configsPVC = KubernetesContext.getVolumeClaimTemplates(getConfiguration(), isExecutor);
    // Collect all Volume configurations from the CLI and generate Volumes and Volume Mounts.
    createVolumeAndMountsPersistentVolumeClaimCLI(configsPVC, volumes, volumeMounts);
    createVolumeAndMountsHostPathCLI(KubernetesContext.getVolumeHostPath(getConfiguration(), isExecutor), volumes, volumeMounts);
    createVolumeAndMountsEmptyDirCLI(KubernetesContext.getVolumeEmptyDir(getConfiguration(), isExecutor), volumes, volumeMounts);
    createVolumeAndMountsNFSCLI(KubernetesContext.getVolumeNFS(getConfiguration(), isExecutor), volumes, volumeMounts);
    final V1StatefulSet statefulSet = new V1StatefulSet();
    // Setup StatefulSet's metadata.
    final V1ObjectMeta objectMeta = new V1ObjectMeta().name(getStatefulSetName(isExecutor)).labels(getPodLabels(topologyName));
    statefulSet.setMetadata(objectMeta);
    // Create the StatefulSet Spec.
    // Reduce replica count by one for Executors and set to one for Manager.
    final int replicasCount = isExecutor ? Runtime.numContainers(runtimeConfiguration).intValue() - 1 : 1;
    final V1StatefulSetSpec statefulSetSpec = new V1StatefulSetSpec().serviceName(topologyName).replicas(replicasCount);
    // Parallel pod management tells the StatefulSet controller to launch or terminate
    // all Pods in parallel, and not to wait for Pods to become Running and Ready or completely
    // terminated prior to launching or terminating another Pod.
    statefulSetSpec.setPodManagementPolicy("Parallel");
    // Add selector match labels "app=heron" and "topology=topology-name"
    // so we know which pods to manage.
    final V1LabelSelector selector = new V1LabelSelector().matchLabels(getPodMatchLabels(topologyName));
    statefulSetSpec.setSelector(selector);
    // Create a Pod Template.
    final V1PodTemplateSpec podTemplateSpec = loadPodFromTemplate(isExecutor);
    // Set up Pod Metadata.
    final V1ObjectMeta templateMetaData = new V1ObjectMeta().labels(getPodLabels(topologyName));
    Map<String, String> annotations = new HashMap<>();
    annotations.putAll(getPodAnnotations());
    annotations.putAll(getPrometheusAnnotations());
    templateMetaData.setAnnotations(annotations);
    podTemplateSpec.setMetadata(templateMetaData);
    configurePodSpec(podTemplateSpec, containerResource, numberOfInstances, isExecutor, volumes, volumeMounts);
    statefulSetSpec.setTemplate(podTemplateSpec);
    statefulSet.setSpec(statefulSetSpec);
    statefulSetSpec.setVolumeClaimTemplates(createPersistentVolumeClaims(configsPVC));
    return statefulSet;
}
Also used : HashMap(java.util.HashMap) Config(org.apache.heron.spi.common.Config) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) LinkedList(java.util.LinkedList) V1VolumeMount(io.kubernetes.client.openapi.models.V1VolumeMount) V1Volume(io.kubernetes.client.openapi.models.V1Volume) V1StatefulSet(io.kubernetes.client.openapi.models.V1StatefulSet) V1StatefulSetSpec(io.kubernetes.client.openapi.models.V1StatefulSetSpec) V1PodTemplateSpec(io.kubernetes.client.openapi.models.V1PodTemplateSpec) V1LabelSelector(io.kubernetes.client.openapi.models.V1LabelSelector) Map(java.util.Map) HashMap(java.util.HashMap) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap)

Example 14 with V1StatefulSet

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

the class KubectlScaleTest method testKubectlScaleStatefulSetShouldWork.

@Test
public void testKubectlScaleStatefulSetShouldWork() throws KubectlException {
    wireMockRule.stubFor(patch(urlPathEqualTo("/apis/apps/v1/namespaces/default/statefulsets/foo")).willReturn(aResponse().withStatus(200).withBody("{\"metadata\":{\"name\":\"foo\",\"namespace\":\"default\"}}")));
    V1StatefulSet scaled = Kubectl.scale(V1StatefulSet.class).apiClient(apiClient).name("foo").namespace("default").replicas(8).execute();
    wireMockRule.verify(1, patchRequestedFor(urlPathEqualTo("/apis/apps/v1/namespaces/default/statefulsets/foo")).withRequestBody(equalToJson("[{\"op\":\"replace\",\"path\":\"/spec/replicas\",\"value\":8}]")));
    assertNotNull(scaled);
}
Also used : V1StatefulSet(io.kubernetes.client.openapi.models.V1StatefulSet) Test(org.junit.Test)

Example 15 with V1StatefulSet

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

the class AppsV1Api method replaceNamespacedStatefulSetStatusWithHttpInfo.

/**
 * replace status of the specified StatefulSet
 *
 * @param name name of the StatefulSet (required)
 * @param namespace object name and auth scope, such as for teams and projects (required)
 * @param body (required)
 * @param pretty If &#39;true&#39;, 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 &#x60;ServerSideFieldValidation&#x60; 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)
 * @return ApiResponse&lt;V1StatefulSet&gt;
 * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the
 *     response body
 * @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> 401 </td><td> Unauthorized </td><td>  -  </td></tr>
 * </table>
 */
public ApiResponse<V1StatefulSet> replaceNamespacedStatefulSetStatusWithHttpInfo(String name, String namespace, V1StatefulSet body, String pretty, String dryRun, String fieldManager, String fieldValidation) throws ApiException {
    okhttp3.Call localVarCall = replaceNamespacedStatefulSetStatusValidateBeforeCall(name, namespace, body, pretty, dryRun, fieldManager, fieldValidation, null);
    Type localVarReturnType = new TypeToken<V1StatefulSet>() {
    }.getType();
    return localVarApiClient.execute(localVarCall, localVarReturnType);
}
Also used : Type(java.lang.reflect.Type) V1StatefulSet(io.kubernetes.client.openapi.models.V1StatefulSet)

Aggregations

V1StatefulSet (io.kubernetes.client.openapi.models.V1StatefulSet)23 Type (java.lang.reflect.Type)14 V1StatefulSetSpec (io.kubernetes.client.openapi.models.V1StatefulSetSpec)5 ApiException (io.kubernetes.client.openapi.ApiException)3 V1LabelSelector (io.kubernetes.client.openapi.models.V1LabelSelector)3 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)3 V1PodTemplateSpec (io.kubernetes.client.openapi.models.V1PodTemplateSpec)3 TopologyRuntimeManagementException (org.apache.heron.scheduler.TopologyRuntimeManagementException)2 JobAPI (edu.iu.dsc.tws.proto.system.job.JobAPI)1 IntOrString (io.kubernetes.client.custom.IntOrString)1 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)1 V1Service (io.kubernetes.client.openapi.models.V1Service)1 V1Volume (io.kubernetes.client.openapi.models.V1Volume)1 V1VolumeMount (io.kubernetes.client.openapi.models.V1VolumeMount)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 TopologySubmissionException (org.apache.heron.scheduler.TopologySubmissionException)1 Config (org.apache.heron.spi.common.Config)1