Search in sources :

Example 1 with V1beta1StatefulSetSpec

use of io.kubernetes.client.models.V1beta1StatefulSetSpec 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 2 with V1beta1StatefulSetSpec

use of io.kubernetes.client.models.V1beta1StatefulSetSpec 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 3 with V1beta1StatefulSetSpec

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

the class AppsV1beta1Controller method addContainers.

@Override
public Set<PackingPlan.ContainerPlan> addContainers(Set<PackingPlan.ContainerPlan> containersToAdd) {
    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 + containersToAdd.size();
    final V1beta1StatefulSetSpec newSpec = new V1beta1StatefulSetSpec();
    newSpec.setReplicas(newContainerCount);
    try {
        doPatch(newSpec);
    } catch (ApiException ae) {
        throw new TopologyRuntimeManagementException(ae.getMessage() + "\ndetails\n" + ae.getResponseBody());
    }
    return containersToAdd;
}
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)

Aggregations

V1beta1StatefulSet (io.kubernetes.client.models.V1beta1StatefulSet)3 V1beta1StatefulSetSpec (io.kubernetes.client.models.V1beta1StatefulSetSpec)3 TopologyRuntimeManagementException (com.twitter.heron.scheduler.TopologyRuntimeManagementException)2 ApiException (io.kubernetes.client.ApiException)2 Config (com.twitter.heron.spi.common.Config)1 V1LabelSelector (io.kubernetes.client.models.V1LabelSelector)1 V1ObjectMeta (io.kubernetes.client.models.V1ObjectMeta)1 V1PodTemplateSpec (io.kubernetes.client.models.V1PodTemplateSpec)1