Search in sources :

Example 1 with V1StatefulSetSpec

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

the class V1Controller method addContainers.

/**
 * Adds a specified number of Pods to a <code>topology</code>'s <code>Executors</code>.
 * @param containersToAdd Set of containers to be added.
 * @return The passed in <code>Packing Plan</code>.
 */
@Override
public Set<PackingPlan.ContainerPlan> addContainers(Set<PackingPlan.ContainerPlan> containersToAdd) {
    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 + containersToAdd.size();
    try {
        patchStatefulSetReplicas(newContainerCount);
    } catch (ApiException ae) {
        throw new TopologyRuntimeManagementException(ae.getMessage() + "\ndetails\n" + ae.getResponseBody());
    }
    return containersToAdd;
}
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 2 with V1StatefulSetSpec

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

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

Aggregations

V1StatefulSet (io.kubernetes.client.openapi.models.V1StatefulSet)3 V1StatefulSetSpec (io.kubernetes.client.openapi.models.V1StatefulSetSpec)3 ApiException (io.kubernetes.client.openapi.ApiException)2 TopologyRuntimeManagementException (org.apache.heron.scheduler.TopologyRuntimeManagementException)2 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)1 V1LabelSelector (io.kubernetes.client.openapi.models.V1LabelSelector)1 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)1 V1PodTemplateSpec (io.kubernetes.client.openapi.models.V1PodTemplateSpec)1 V1Volume (io.kubernetes.client.openapi.models.V1Volume)1 V1VolumeMount (io.kubernetes.client.openapi.models.V1VolumeMount)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Config (org.apache.heron.spi.common.Config)1