io.alauda.kubernetes.client.dsl.internal.RollableScalableResourceOperation Maven / Gradle / Ivy
/**
* Copyright (C) 2018 Alauda
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.alauda.kubernetes.client.dsl.internal;
import io.alauda.kubernetes.api.builder.Visitor;
import io.alauda.kubernetes.api.model.Doneable;
import io.alauda.kubernetes.api.model.HasMetadata;
import io.alauda.kubernetes.api.model.KubernetesResourceList;
import io.alauda.kubernetes.client.Config;
import io.alauda.kubernetes.client.KubernetesClientException;
import io.alauda.kubernetes.client.dsl.Resource;
import io.alauda.kubernetes.client.dsl.RollableScalableResource;
import io.alauda.kubernetes.client.dsl.base.HasMetadataOperation;
import io.alauda.kubernetes.client.utils.Utils;
import okhttp3.OkHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
/**
* Operations for resources that represent scalable, rolling-updatable sets of Pods.
*/
public abstract class RollableScalableResourceOperation, R extends Resource>
extends HasMetadataOperation implements RollableScalableResource {
private final Logger Log = LoggerFactory.getLogger(this.getClass());
final Boolean rolling;
final long rollingTimeout;
final TimeUnit rollingTimeUnit;
public RollableScalableResourceOperation(OkHttpClient client, Config config, String apiGroup, String apiVersion, String resourceT, String namespace, String name, Boolean cascading, T item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields, Boolean rolling, long rollingTimeout, TimeUnit rollingTimeUnit) {
super(client, config, apiGroup, apiVersion, resourceT, namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields);
this.rolling = rolling;
this.rollingTimeout = rollingTimeout;
this.rollingTimeUnit = rollingTimeUnit;
reaper = new ScalableReaper(this);
}
abstract T withReplicas(int count);
abstract RollingUpdater getRollingUpdater(long rollingTimeout, TimeUnit rollingTimeUnit);
// There are no common interfaces through which we could get these values.
abstract int getCurrentReplicas(T current);
abstract int getDesiredReplicas(T item);
abstract long getObservedGeneration(T current);
@Override
public T scale(int count) {
return scale(count, false);
}
@Override
public T scale(int count, boolean wait) {
T res = withReplicas(count);
if (wait) {
waitUntilScaled(count);
res = getMandatory();
}
return res;
}
/**
* Let's wait until there are enough Ready pods.
*/
private void waitUntilScaled(final int count) {
final ArrayBlockingQueue © 2015 - 2025 Weber Informatics LLC | Privacy Policy