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;
}
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());
}
}
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;
}
Aggregations