Search in sources :

Example 11 with V1beta1StatefulSet

use of io.kubernetes.client.models.V1beta1StatefulSet in project incubator-heron by apache.

the class AppsV1beta1Controller method createStatefulSet.

private V1beta1StatefulSet createStatefulSet(Resource containerResource, int numberOfInstances) {
    final String topologyName = getTopologyName();
    final Config runtimeConfiguration = getRuntimeConfiguration();
    final V1beta1StatefulSet statefulSet = new V1beta1StatefulSet();
    // setup stateful set metadata
    final V1ObjectMeta objectMeta = new V1ObjectMeta();
    objectMeta.name(topologyName);
    statefulSet.metadata(objectMeta);
    // create the stateful set spec
    final V1beta1StatefulSetSpec statefulSetSpec = new V1beta1StatefulSetSpec();
    statefulSetSpec.serviceName(topologyName);
    statefulSetSpec.setReplicas(Runtime.numContainers(runtimeConfiguration).intValue());
    // 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 the we know which pods to manage
    final V1LabelSelector selector = new V1LabelSelector();
    selector.matchLabels(getMatchLabels(topologyName));
    statefulSetSpec.selector(selector);
    // create a pod template
    final V1PodTemplateSpec podTemplateSpec = new V1PodTemplateSpec();
    // set up pod meta
    final V1ObjectMeta templateMetaData = new V1ObjectMeta().labels(getLabels(topologyName));
    templateMetaData.annotations(getPrometheusAnnotations());
    podTemplateSpec.setMetadata(templateMetaData);
    final List<String> command = getExecutorCommand("$" + ENV_SHARD_ID);
    podTemplateSpec.spec(getPodSpec(command, containerResource, numberOfInstances));
    statefulSetSpec.setTemplate(podTemplateSpec);
    statefulSet.spec(statefulSetSpec);
    return statefulSet;
}
Also used : Config(com.twitter.heron.spi.common.Config) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) V1PodTemplateSpec(io.kubernetes.client.models.V1PodTemplateSpec) V1LabelSelector(io.kubernetes.client.models.V1LabelSelector) V1beta1StatefulSet(io.kubernetes.client.models.V1beta1StatefulSet) V1beta1StatefulSetSpec(io.kubernetes.client.models.V1beta1StatefulSetSpec)

Example 12 with V1beta1StatefulSet

use of io.kubernetes.client.models.V1beta1StatefulSet in project incubator-heron by apache.

the class AppsV1beta1Controller method removeContainers.

@Override
public void removeContainers(Set<PackingPlan.ContainerPlan> containersToRemove) {
    final V1beta1StatefulSet statefulSet;
    try {
        statefulSet = getStatefulSet();
    } catch (ApiException ae) {
        final String message = ae.getMessage() + "\ndetails:" + ae.getResponseBody();
        throw new TopologyRuntimeManagementException(message, ae);
    }
    final int currentContainerCount = statefulSet.getSpec().getReplicas();
    final int newContainerCount = currentContainerCount - containersToRemove.size();
    final V1beta1StatefulSetSpec newSpec = new V1beta1StatefulSetSpec();
    newSpec.setReplicas(newContainerCount);
    try {
        doPatch(newSpec);
    } catch (ApiException e) {
        throw new TopologyRuntimeManagementException(e.getMessage() + "\ndetails\n" + e.getResponseBody());
    }
}
Also used : TopologyRuntimeManagementException(com.twitter.heron.scheduler.TopologyRuntimeManagementException) V1beta1StatefulSet(io.kubernetes.client.models.V1beta1StatefulSet) V1beta1StatefulSetSpec(io.kubernetes.client.models.V1beta1StatefulSetSpec) ApiException(io.kubernetes.client.ApiException)

Example 13 with V1beta1StatefulSet

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

the class AppsV1beta1ApiTest method readNamespacedStatefulSetTest.

/**
 * read the specified StatefulSet
 *
 * @throws ApiException
 *          if the Api call fails
 */
@Test
public void readNamespacedStatefulSetTest() throws ApiException {
    String name = null;
    String namespace = null;
    String pretty = null;
    Boolean exact = null;
    Boolean export = null;
    V1beta1StatefulSet response = api.readNamespacedStatefulSet(name, namespace, pretty, exact, export);
// TODO: test validations
}
Also used : V1beta1StatefulSet(io.kubernetes.client.models.V1beta1StatefulSet) Test(org.junit.Test)

Example 14 with V1beta1StatefulSet

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

the class AppsV1beta1ApiTest method replaceNamespacedStatefulSetStatusTest.

/**
 * replace status of the specified StatefulSet
 *
 * @throws ApiException
 *          if the Api call fails
 */
@Test
public void replaceNamespacedStatefulSetStatusTest() throws ApiException {
    String name = null;
    String namespace = null;
    V1beta1StatefulSet body = null;
    String pretty = null;
    V1beta1StatefulSet response = api.replaceNamespacedStatefulSetStatus(name, namespace, body, pretty);
// TODO: test validations
}
Also used : V1beta1StatefulSet(io.kubernetes.client.models.V1beta1StatefulSet) Test(org.junit.Test)

Example 15 with V1beta1StatefulSet

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

the class AppsV1beta1ApiTest method replaceNamespacedStatefulSetTest.

/**
 * replace the specified StatefulSet
 *
 * @throws ApiException
 *          if the Api call fails
 */
@Test
public void replaceNamespacedStatefulSetTest() throws ApiException {
    String name = null;
    String namespace = null;
    V1beta1StatefulSet body = null;
    String pretty = null;
    V1beta1StatefulSet response = api.replaceNamespacedStatefulSet(name, namespace, body, pretty);
// TODO: test validations
}
Also used : V1beta1StatefulSet(io.kubernetes.client.models.V1beta1StatefulSet) Test(org.junit.Test)

Aggregations

V1beta1StatefulSet (io.kubernetes.client.models.V1beta1StatefulSet)25 Type (java.lang.reflect.Type)14 ProgressRequestBody (io.kubernetes.client.ProgressRequestBody)7 ProgressResponseBody (io.kubernetes.client.ProgressResponseBody)7 Test (org.junit.Test)7 ApiException (io.kubernetes.client.ApiException)3 V1beta1StatefulSetSpec (io.kubernetes.client.models.V1beta1StatefulSetSpec)3 TopologyRuntimeManagementException (com.twitter.heron.scheduler.TopologyRuntimeManagementException)2 Response (com.squareup.okhttp.Response)1 TopologySubmissionException (com.twitter.heron.scheduler.TopologySubmissionException)1 Config (com.twitter.heron.spi.common.Config)1 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)1 Resource (com.twitter.heron.spi.packing.Resource)1 V1LabelSelector (io.kubernetes.client.models.V1LabelSelector)1 V1ObjectMeta (io.kubernetes.client.models.V1ObjectMeta)1 V1PodTemplateSpec (io.kubernetes.client.models.V1PodTemplateSpec)1 IOException (java.io.IOException)1