diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/AppsAPIGroupClient.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/AppsAPIGroupClient.java index f5d46dfcdf5..95498993095 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/AppsAPIGroupClient.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/AppsAPIGroupClient.java @@ -51,21 +51,21 @@ public AppsAPIGroupClient(OkHttpClient httpClient, final Config config) throws K @Override public MixedOperation> daemonSets() { - return new DaemonSetOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new DaemonSetOperationsImpl(httpClient, getConfiguration()); } @Override public MixedOperation> deployments() { - return new DeploymentOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new DeploymentOperationsImpl(httpClient, getConfiguration()); } @Override public MixedOperation> replicaSets() { - return new ReplicaSetOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new ReplicaSetOperationsImpl(httpClient, getConfiguration()); } @Override public MixedOperation> statefulSets() { - return new StatefulSetOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new StatefulSetOperationsImpl(httpClient, getConfiguration()); } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/AutoscalingAPIGroupClient.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/AutoscalingAPIGroupClient.java index 65ed8f4bc3f..1ecaf3dc909 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/AutoscalingAPIGroupClient.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/AutoscalingAPIGroupClient.java @@ -33,6 +33,6 @@ public AutoscalingAPIGroupClient(OkHttpClient httpClient, final Config config) t } public MixedOperation> horizontalPodAutoscalers() { - return new HorizontalPodAutoscalerOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new HorizontalPodAutoscalerOperationsImpl(httpClient, getConfiguration()); } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/BaseClient.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/BaseClient.java index 76d30f7bdbe..7c09b34c065 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/BaseClient.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/BaseClient.java @@ -16,6 +16,7 @@ package io.fabric8.kubernetes.client; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -136,7 +137,7 @@ public C adapt(Class type) { @Override public RootPaths rootPaths() { - return new BaseOperation(httpClient, configuration, null, null, "", null, null, false, null, null, false, RootPaths.class, null, null) { + return new BaseOperation(new OperationContext().withOkhttpClient(httpClient).withConfig(configuration)) { }.getRootPaths(); } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/BatchAPIGroupClient.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/BatchAPIGroupClient.java index a5474d137b8..1f642dcb83c 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/BatchAPIGroupClient.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/BatchAPIGroupClient.java @@ -41,11 +41,11 @@ public BatchAPIGroupClient(OkHttpClient httpClient, final Config config) throws @Override public MixedOperation> jobs() { - return new JobOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new JobOperationsImpl(httpClient, getConfiguration()); } @Override public MixedOperation> cronjobs() { - return new CronJobOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new CronJobOperationsImpl(httpClient, getConfiguration()); } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/DefaultKubernetesClient.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/DefaultKubernetesClient.java index 930435590a0..893b02cb3c6 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/DefaultKubernetesClient.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/DefaultKubernetesClient.java @@ -106,7 +106,7 @@ public static DefaultKubernetesClient fromConfig(InputStream is) { @Override public MixedOperation> componentstatuses() { - return new ComponentStatusOperationsImpl(httpClient, getConfiguration(), null); + return new ComponentStatusOperationsImpl(httpClient, getConfiguration()); } @Override @@ -152,12 +152,12 @@ public NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicable> endpoints() { - return new EndpointsOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new EndpointsOperationsImpl(httpClient, getConfiguration()); } @Override public MixedOperation> events() { - return new EventOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new EventOperationsImpl(httpClient, getConfiguration()); } @Override @@ -177,22 +177,22 @@ public NonNamespaceOperation> persistentVolumeClaims() { - return new PersistentVolumeClaimOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new PersistentVolumeClaimOperationsImpl(httpClient, getConfiguration()); } @Override public MixedOperation> pods() { - return new PodOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new PodOperationsImpl(httpClient, getConfiguration()); } @Override public MixedOperation> replicationControllers() { - return new ReplicationControllerOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new ReplicationControllerOperationsImpl(httpClient, getConfiguration()); } @Override public MixedOperation> resourceQuotas() { - return new ResourceQuotaOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new ResourceQuotaOperationsImpl(httpClient, getConfiguration()); } @Override @@ -202,17 +202,17 @@ public SchedulingAPIGroupDSL scheduling() { @Override public MixedOperation> secrets() { - return new SecretOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new SecretOperationsImpl(httpClient, getConfiguration()); } @Override public MixedOperation> services() { - return new ServiceOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new ServiceOperationsImpl(httpClient, getConfiguration()); } @Override public MixedOperation> serviceAccounts() { - return new ServiceAccountOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new ServiceAccountOperationsImpl(httpClient, getConfiguration()); } @Override @@ -222,12 +222,12 @@ public KubernetesListMixedOperation lists() { @Override public MixedOperation> configMaps() { - return new ConfigMapOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new ConfigMapOperationsImpl(httpClient, getConfiguration()); } @Override public MixedOperation> limitRanges() { - return new LimitRangeOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new LimitRangeOperationsImpl(httpClient, getConfiguration()); } @Override @@ -237,7 +237,11 @@ public NonNamespaceOperation> MixedOperation> customResources(CustomResourceDefinition crd, Class resourceType, Class listClass, Class doneClass) { - return new CustomResourceOperationsImpl(httpClient, getConfiguration(), crd, resourceType, listClass, doneClass); + return new CustomResourceOperationsImpl(new CustomResourceOperationContext().withOkhttpClient(httpClient).withConfig(getConfiguration()) + .withCrd(crd) + .withType(resourceType) + .withListType(listClass) + .withDoneableType(doneClass)); } @Override diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/ExtensionsAPIGroupClient.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/ExtensionsAPIGroupClient.java index b291770775e..7e43fec6112 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/ExtensionsAPIGroupClient.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/ExtensionsAPIGroupClient.java @@ -63,13 +63,13 @@ public ExtensionsAPIGroupClient(OkHttpClient httpClient, final Config config) th @Override @Deprecated public MixedOperation> daemonSets() { - return new DaemonSetOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new DaemonSetOperationsImpl(httpClient, getConfiguration()); } @Override @Deprecated public MixedOperation> deployments() { - return new DeploymentOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new DeploymentOperationsImpl(httpClient, getConfiguration()); } @Override @@ -80,30 +80,30 @@ public MixedOperation> ingresses() { - return new IngressOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new IngressOperationsImpl(httpClient, getConfiguration()); } @Override @Deprecated public MixedOperation> jobs() { - return new JobOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new JobOperationsImpl(httpClient, getConfiguration()); } @Override @Deprecated public MixedOperation> networkPolicies() { - return new NetworkPolicyOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new NetworkPolicyOperationsImpl(httpClient, getConfiguration()); } @Override public MixedOperation> podSecurityPolicies() { - return new PodSecurityPolicyOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new PodSecurityPolicyOperationsImpl(httpClient, getConfiguration()); } @Override @Deprecated public MixedOperation> replicaSets() { - return new ReplicaSetOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new ReplicaSetOperationsImpl(httpClient, getConfiguration()); } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/NetworkAPIGroupClient.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/NetworkAPIGroupClient.java index 74ca73f801b..af0c78737b6 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/NetworkAPIGroupClient.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/NetworkAPIGroupClient.java @@ -36,6 +36,6 @@ public NetworkAPIGroupClient(OkHttpClient httpClient, final Config config) throw @Override public MixedOperation> networkPolicies() { - return new NetworkPolicyOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new NetworkPolicyOperationsImpl(httpClient, getConfiguration()); } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/PolicyAPIGroupClient.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/PolicyAPIGroupClient.java index 5a156da7023..64904322b83 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/PolicyAPIGroupClient.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/PolicyAPIGroupClient.java @@ -35,6 +35,6 @@ public PolicyAPIGroupClient(OkHttpClient httpClient, final Config config) throws @Override public MixedOperation> podDisruptionBudget() { - return new PodDisruptionBudgetOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new PodDisruptionBudgetOperationsImpl(httpClient, getConfiguration()); } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/RbacAPIGroupClient.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/RbacAPIGroupClient.java index f6adebcb0c9..d59aa7ae168 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/RbacAPIGroupClient.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/RbacAPIGroupClient.java @@ -41,12 +41,12 @@ public RbacAPIGroupClient(OkHttpClient httpClient, final Config config) throws K @Override public MixedOperation> roles() { - return new RoleOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new RoleOperationsImpl(httpClient, getConfiguration()); } @Override public MixedOperation> roleBindings() { - return new RoleBindingOperationsImpl(httpClient, getConfiguration(), getNamespace()); + return new RoleBindingOperationsImpl(httpClient, getConfiguration()); } @Override diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/SchedulingAPIGroupClient.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/SchedulingAPIGroupClient.java index c27ea73d07b..e2fd3a250da 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/SchedulingAPIGroupClient.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/SchedulingAPIGroupClient.java @@ -31,6 +31,6 @@ public SchedulingAPIGroupClient(OkHttpClient httpClient, final Config config) th @Override public MixedOperation> priorityClass() { - return new PriorityClassOperationsImpl(httpClient, getConfiguration(), null); + return new PriorityClassOperationsImpl(httpClient, getConfiguration()); } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java index e3371f033f6..2c81354c19f 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java @@ -21,6 +21,7 @@ import io.fabric8.kubernetes.api.model.KubernetesResourceList; import io.fabric8.kubernetes.api.model.LabelSelector; import io.fabric8.kubernetes.api.model.LabelSelectorRequirement; +import io.fabric8.kubernetes.api.model.ObjectMeta; import io.fabric8.kubernetes.api.model.RootPaths; import io.fabric8.kubernetes.client.*; import io.fabric8.kubernetes.client.dsl.Deletable; @@ -54,7 +55,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.TreeMap; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.function.Predicate; @@ -62,8 +62,6 @@ import okhttp3.OkHttpClient; import okhttp3.Request; -import static io.fabric8.kubernetes.client.utils.ApiVersionUtil.*; - public class BaseOperation, R extends Resource> extends OperationSupport implements @@ -80,9 +78,6 @@ public class BaseOperation labelsNotIn; private final Map fields; - private final Class type; - private final Class listType; - private final Class doneableType; private final String resourceVersion; private final Boolean reloadingFromServer; private final long gracePeriodSeconds; @@ -91,61 +86,25 @@ public class BaseOperation labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, apiGroup(item, apiGroupName), apiVersion(item, apiVersionNumber), resourceT, namespace, name(item, name)); - this.cascading = cascading; - this.item = item; - this.reloadingFromServer = reloadingFromServer; - this.type = (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; - this.listType = (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[1]; - this.doneableType = (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[2]; - this.reaper = null; - this.resourceVersion = resourceVersion; - this.gracePeriodSeconds = gracePeriodSeconds; - this.labels = labels; - this.labelsNot = labelsNot; - this.labelsIn = labelsIn; - this.labelsNotIn = labelsNotIn; - this.fields = fields; - } - - protected BaseOperation(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, Class type, Class listType, Class doneableType) { - super(client, config, apiGroup, apiVersion(item, apiVersion), resourceT, namespace, name(item, name)); - this.cascading = cascading; - this.item = item; - this.resourceVersion = resourceVersion; - this.reloadingFromServer = reloadingFromServer; - this.type = type; - this.listType = listType; - this.doneableType = doneableType; - this.reaper = null; - this.gracePeriodSeconds = gracePeriodSeconds; - this.labels = labels; - this.labelsNot = labelsNot; - this.labelsIn = labelsIn; - this.labelsNotIn = labelsNotIn; - this.fields = fields; - } - - protected BaseOperation(OkHttpClient client, Config config, String apiGroup, String apiVersion, String resourceT, String namespace, String name, Boolean cascading, T item, String resourceVersion, Boolean reloadingFromServer, Class type, Class listType, Class doneableType) { - super(client, config, apiGroup, apiVersion(item, apiVersion), resourceT, namespace, name(item, name)); - this.cascading = cascading; - this.item = item; - this.resourceVersion = resourceVersion; - this.reloadingFromServer = reloadingFromServer; - this.type = type; - this.listType = listType; - this.doneableType = doneableType; + protected Class type; + protected Class listType; + protected Class doneableType; + + protected BaseOperation(OperationContext ctx) { + super(ctx); + this.cascading = ctx.getCascading(); + this.item = (T) ctx.getItem(); + this.reloadingFromServer = ctx.getReloadingFromServer(); + this.resourceVersion = ctx.getResourceVersion(); + this.gracePeriodSeconds = ctx.getGracePeriodSeconds(); + this.labels = ctx.getLabels(); + this.labelsNot = ctx.getLabelsNot(); + this.labelsIn = ctx.getLabelsIn(); + this.labelsNotIn = ctx.getLabelsNotIn(); + this.fields = ctx.getFields(); this.reaper = null; - this.gracePeriodSeconds = -1; - this.labels = new TreeMap<>(); - this.labelsNot = new TreeMap<>(); - this.labelsIn = new TreeMap<>(); - this.labelsNotIn = new TreeMap<>(); - this.fields = new TreeMap<>(); } - /** * Returns the name and falls back to the item name. * @param item The item. @@ -164,7 +123,9 @@ private static String name(T item, String name) { } - + public BaseOperation newInstance(OperationContext context) { + return new BaseOperation(context); + } /** * Helper method for list() and list(limit, continue) methods @@ -293,63 +254,34 @@ public R withName(String name) { if (name == null || name.length() == 0) { throw new IllegalArgumentException("Name must be provided."); } - try { - return (R) getClass() - .getConstructor(OkHttpClient.class, getConfigType(), String.class, String.class, String.class, String.class, Boolean.class, getType(), String.class, Boolean.class, long.class, Map.class, Map.class, Map.class, Map.class, Map.class) - .newInstance(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); - } catch (Throwable t) { - throw KubernetesClientException.launderThrowable(t); - } + return (R) newInstance(context.withName(name)); } @Override public Replaceable lockResourceVersion(String resourceVersion) { - try { - return getClass() - .getConstructor(OkHttpClient.class, getConfigType(), String.class, String.class, String.class, String.class, Boolean.class, getType(), String.class, Boolean.class, long.class, Map.class, Map.class, Map.class, Map.class, Map.class) - .newInstance(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), resourceVersion, isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); - } catch (Throwable t) { - throw KubernetesClientException.launderThrowable(t); - } + return newInstance(context.withResourceVersion(resourceVersion)); } @Override public NonNamespaceOperation inNamespace(String namespace) { - try { - return getClass() - .getConstructor(OkHttpClient.class, getConfigType(), String.class, String.class, String.class, String.class, Boolean.class, getType(), String.class, Boolean.class, long.class, Map.class, Map.class, Map.class, Map.class, Map.class) - .newInstance(client, getConfig(), getAPIGroup(), getAPIVersion(), namespace, getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); - } catch (Throwable t) { - throw KubernetesClientException.launderThrowable(t); - } + return newInstance(context.withNamespace(namespace)); } @Override public NonNamespaceOperation inAnyNamespace() { - return inNamespace(null); + Config updated = new ConfigBuilder(config).withNamespace(null).build(); + return newInstance(context.withConfig(updated).withNamespace(null)); } @Override public EditReplacePatchDeletable cascading(boolean cascading) { - try { - return getClass() - .getConstructor(OkHttpClient.class, getConfigType(), String.class, String.class, String.class, String.class, Boolean.class, getType(), String.class, Boolean.class, long.class, Map.class, Map.class, Map.class, Map.class, Map.class) - .newInstance(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), cascading, getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); - } catch (Throwable t) { - throw KubernetesClientException.launderThrowable(t); - } + return newInstance(context.withCascading(cascading)); } @Override public R load(InputStream is) { - try { - return (R) getClass() - .getConstructor(OkHttpClient.class, getConfigType(), String.class, String.class, String.class, String.class, Boolean.class, getType(), String.class, Boolean.class, long.class, Map.class, Map.class, Map.class, Map.class, Map.class) - .newInstance(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), unmarshal(is, type), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); - } catch (Throwable t) { - throw KubernetesClientException.launderThrowable(t); - } + return (R) newInstance(context.withItem(unmarshal(is, type))); } @Override @@ -377,13 +309,7 @@ public R load(String path) { @Override public Gettable fromServer() { - try { - return (R) getClass() - .getConstructor(OkHttpClient.class, getConfigType(), String.class, String.class, String.class, String.class, Boolean.class, getType(), String.class, Boolean.class, long.class, Map.class, Map.class, Map.class, Map.class, Map.class) - .newInstance(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), true, getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); - } catch (Throwable t) { - throw KubernetesClientException.launderThrowable(t); - } + return newInstance(context.withReloadingFromServer(true)); } @Override @@ -392,7 +318,7 @@ public T create(T... resources) throws KubernetesClientException { if (resources.length > 1) { throw new IllegalArgumentException("Too many items to create."); } else if (resources.length == 1) { - return handleCreate(resources[0]); + return withItem(resources[0]).create(); } else if (getItem() == null) { throw new IllegalArgumentException("Nothing to create."); } else { @@ -690,25 +616,21 @@ public Boolean delete(List items) { updateApiVersionResource(item); try { - R op = createItemOperation(item); + R op = (R) withItem(item); deleted &= op.delete(); } catch (KubernetesClientException e) { if (e.getCode() != HttpURLConnection.HTTP_NOT_FOUND) { throw e; } return false; - } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { - throw KubernetesClientException.launderThrowable(forOperationType("delete"), e); } } } return deleted; } - protected R createItemOperation(T item) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { - return (R) getClass() - .getConstructor(OkHttpClient.class, getConfigType(), String.class, String.class, String.class, String.class, Boolean.class, getType(), String.class, Boolean.class, long.class, Map.class, Map.class, Map.class, Map.class, Map.class) - .newInstance(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), item, getResourceVersion(), true, getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); + public BaseOperation withItem(T item) { + return newInstance(context.withItem(item)); } void deleteThis() throws KubernetesClientException { @@ -730,13 +652,7 @@ void deleteList() throws KubernetesClientException { @Override public Watchable> withResourceVersion(String resourceVersion) { - try { - return getClass() - .getConstructor(OkHttpClient.class, getConfigType(), String.class, String.class, String.class, String.class, Boolean.class, getType(), String.class, Boolean.class, long.class, Map.class, Map.class, Map.class, Map.class, Map.class) - .newInstance(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), resourceVersion, isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); - } catch (Throwable t) { - throw KubernetesClientException.launderThrowable(t); - } + return newInstance(context.withResourceVersion(resourceVersion)); } public Watch watch(final Watcher watcher) throws KubernetesClientException { @@ -922,13 +838,7 @@ public OperationInfo forOperationType(String type) { @Override public Deletable withGracePeriod(long gracePeriodSeconds) { - try { - return getClass() - .getConstructor(OkHttpClient.class, getConfigType(), String.class, String.class, String.class, String.class, Boolean.class, getType(), String.class, Boolean.class, long.class, Map.class, Map.class, Map.class, Map.class, Map.class) - .newInstance(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), gracePeriodSeconds, getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); - } catch (Throwable t) { - throw KubernetesClientException.launderThrowable(t); - } + return newInstance(context.withGracePeriodSeconds(gracePeriodSeconds)); } protected Class getConfigType() { diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/HasMetadataOperation.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/HasMetadataOperation.java index 4b474a5eaae..de626db50f5 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/HasMetadataOperation.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/HasMetadataOperation.java @@ -36,16 +36,8 @@ public class HasMetadataOperation, R extends Resource> extends BaseOperation< T, L, D, R> { - protected HasMetadataOperation(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) { - super(client, config, apiGroup, apiVersion, resourceT, namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); - } - - protected HasMetadataOperation(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, Class type, Class listType, Class doneableType) { - super(client, config, apiGroup, apiVersion, resourceT, namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields, type, listType, doneableType); - } - - public HasMetadataOperation(OkHttpClient client, Config config, String apiGroup, String apiVersion, String resourceT, String namespace, String name, Boolean cascading, T item, String resourceVersion, Boolean reloadingFromServer, Class type, Class listType, Class doneableType) { - super(client, config, apiGroup, apiVersion, resourceT, namespace, name, cascading, item, resourceVersion, reloadingFromServer, type, listType, doneableType); + public HasMetadataOperation(OperationContext ctx) { + super(ctx); } @Override diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/OperationContext.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/OperationContext.java new file mode 100644 index 00000000000..6557b5d55d9 --- /dev/null +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/OperationContext.java @@ -0,0 +1,211 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * 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.fabric8.kubernetes.client.dsl.base; + +import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.utils.ApiVersionUtil; +import io.fabric8.kubernetes.client.utils.Utils; +import okhttp3.OkHttpClient; + +import java.util.HashMap; +import java.util.Map; + +public class OperationContext { + + protected OkHttpClient client; + protected Config config; + protected Object item; + protected String resourceVersion; + protected String plural; + + protected String apiGroupName; + protected String apiGroupVersion; + + protected String namespace; + protected String name; + protected boolean cascading; + protected boolean reloadingFromServer; + + protected long gracePeriodSeconds; + + protected Map labels; + protected Map labelsNot; + protected Map labelsIn; + protected Map labelsNotIn; + protected Map fields; + + + public OperationContext() { + } + + public OperationContext(OkHttpClient client, Config config, String plural, String namespace, String name, String apiGroupName, String apiGroupVersion, boolean cascading, Object item, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields, String resourceVersion, boolean reloadingFromServer, long gracePeriodSeconds) { + this.client = client; + this.config = config; + this.plural = plural; + this.namespace = Utils.isNotNullOrEmpty(namespace) ? namespace : (config != null ? config.getNamespace() : null); + this.name = name; + this.cascading = cascading; + this.labels = labels != null ? labels : new HashMap<>(); + this.labelsNot = labelsNot != null ? labelsNot : new HashMap<>(); + this.labelsIn = labelsIn != null ? labelsIn : new HashMap<>(); + this.labelsNotIn = labelsNotIn != null ? labelsNotIn : new HashMap<>(); + this.fields = fields != null ? fields : new HashMap<>(); + this.resourceVersion = resourceVersion; + this.reloadingFromServer = reloadingFromServer; + this.gracePeriodSeconds = gracePeriodSeconds; + this.item = item; + this.apiGroupName = ApiVersionUtil.apiGroup(item, apiGroupName); + this.apiGroupVersion = ApiVersionUtil.apiVersion(item, apiGroupVersion); + } + + public OkHttpClient getClient() { + return client; + } + + public Config getConfig() { + return config; + } + + public String getPlural() { + return plural; + } + + public String getNamespace() { + return namespace; + } + + public String getName() { + return name; + } + + public String getApiGroupName() { + return apiGroupName; + } + + public String getApiGroupVersion() { + return apiGroupVersion; + } + + public boolean getCascading() { + return cascading; + } + + public Object getItem() { + return item; + } + + public Map getLabels() { + return labels; + } + + public Map getLabelsNot() { + return labelsNot; + } + + public Map getLabelsIn() { + return labelsIn; + } + + public Map getLabelsNotIn() { + return labelsNotIn; + } + + public Map getFields() { + return fields; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public boolean getReloadingFromServer() { + return reloadingFromServer; + } + + public long getGracePeriodSeconds() { + return gracePeriodSeconds; + } + + + public OperationContext withOkhttpClient(OkHttpClient client) { + return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + } + + public OperationContext withConfig(Config config) { + return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + } + + public OperationContext withPlural(String plural) { + return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + } + + public OperationContext withNamespace(String namespace) { + return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + } + + public OperationContext withName(String name) { + return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + } + + + public OperationContext withApiGroupName(String apiGroupName) { + return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + } + + public OperationContext withApiGroupVersion(String apiGroupVersion) { + return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + } + + public OperationContext withItem(Object item) { + return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + } + + public OperationContext withCascading(boolean cascading) { + return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + } + + public OperationContext withLabels(Map labels) { + return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + } + + public OperationContext withLabelsIn(Map labelsIn) { + return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + } + + public OperationContext withLabelsNot(Map labelsNot) { + return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + } + + public OperationContext withLabelsNotIn(Map labelsNotIn) { + return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + } + + public OperationContext withFields(Map fields) { + return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + } + + public OperationContext withResourceVersion(String resourceVersion) { + return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + } + + public OperationContext withReloadingFromServer(boolean reloadingFromServer) { + return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + } + + public OperationContext withGracePeriodSeconds(long gracePeriodSeconds) { + return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + } +} diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/OperationSupport.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/OperationSupport.java index cbc1e987e2c..8d5bd6992c8 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/OperationSupport.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/OperationSupport.java @@ -57,33 +57,39 @@ public class OperationSupport { protected static final ObjectMapper YAML_MAPPER = Serialization.yamlMapper(); private static final String CLIENT_STATUS_FLAG = "CLIENT_STATUS_FLAG"; + protected OperationContext context; protected final OkHttpClient client; protected final Config config; protected final String resourceT; - protected final String namespace; - protected final String name; - protected final String apiGroupName; - protected final String apiGroupVersion; + protected String namespace; + protected String name; + protected String apiGroupName; + protected String apiGroupVersion; public OperationSupport() { - this(null, null, null, null, null, null, null); + this (new OperationContext()); } - public OperationSupport(OkHttpClient client, ConfigAndApiGroupsInfo configAndApiGroupsInfo, String resourceT, String namespace, String name) { - this(client, configAndApiGroupsInfo.getConfig(), configAndApiGroupsInfo.getApiGroupName(), configAndApiGroupsInfo.getApiGroupVersion(), resourceT, namespace ,name); + public OperationSupport(OkHttpClient client, Config config) { + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - public OperationSupport(OkHttpClient client, Config config, String apiGroupName, String apiGroupVersion, String resourceT, String namespace, String name) { - this.client = client; - this.config = config; - this.resourceT = resourceT; - this.namespace = namespace; - this.name = name; - this.apiGroupName = apiGroupName; - if (apiGroupVersion != null) { - this.apiGroupVersion = apiGroupVersion; - } else if (config != null) { - this.apiGroupVersion = config.getApiVersion(); + public OperationSupport(OkHttpClient client, Config config, String namespace) { + this(new OperationContext().withOkhttpClient(client).withConfig(config).withNamespace(namespace)); + } + + public OperationSupport(OperationContext ctx) { + this.context = ctx; + this.client = ctx.getClient(); + this.config = ctx.getConfig(); + this.resourceT = ctx.getPlural(); + this.namespace = ctx.getNamespace(); + this.name = ctx.getName() ; + this.apiGroupName = ctx.getApiGroupName(); + if (ctx.getApiGroupVersion() != null) { + this.apiGroupVersion = ctx.getApiGroupVersion(); + } else if (ctx.getConfig() != null) { + this.apiGroupVersion = ctx.getConfig().getApiVersion(); } else { this.apiGroupVersion = "v1"; } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ClusterOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ClusterOperationsImpl.java index e59b9359b0b..64086c6c6e2 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ClusterOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ClusterOperationsImpl.java @@ -20,6 +20,7 @@ import io.fabric8.kubernetes.client.VersionInfo; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.KubernetesClientException; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import io.fabric8.kubernetes.client.dsl.base.OperationSupport; import io.fabric8.kubernetes.client.utils.URLUtils; import okhttp3.OkHttpClient; @@ -33,7 +34,7 @@ public class ClusterOperationsImpl extends OperationSupport { private String versionEndpoint; public ClusterOperationsImpl(OkHttpClient client, Config config, String item) { - super(client, config, null, null, null, null, null); + super(new OperationContext().withOkhttpClient(client).withConfig(config)); this.versionEndpoint = item; } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ClusterRoleBindingOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ClusterRoleBindingOperationsImpl.java index f3f186e0b5d..cb3fc8755fc 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ClusterRoleBindingOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ClusterRoleBindingOperationsImpl.java @@ -15,29 +15,37 @@ */ package io.fabric8.kubernetes.client.dsl.internal; -import java.util.Map; -import java.util.TreeMap; - import io.fabric8.kubernetes.api.model.rbac.DoneableClusterRoleBinding; import io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding; import io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingList; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; public class ClusterRoleBindingOperationsImpl extends HasMetadataOperation> { public ClusterRoleBindingOperationsImpl(OkHttpClient client, Config config) { - this(client, config, "rbac.authorization.k8s.io", "v1", null, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - public ClusterRoleBindingOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, ClusterRoleBinding item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, apiGroup, apiVersion, "clusterrolebindings", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + public ClusterRoleBindingOperationsImpl(OperationContext context) { + super(context.withApiGroupName("rbac.authorization.k8s.io") + .withApiGroupVersion("v1") + .withPlural("clusterrolebindings")); + this.type = ClusterRoleBinding.class; + this.listType = ClusterRoleBindingList.class; + this.doneableType = DoneableClusterRoleBinding.class; } @Override public boolean isResourceNamespaced() { return false; } + + @Override + public ClusterRoleBindingOperationsImpl newInstance(OperationContext context) { + return new ClusterRoleBindingOperationsImpl(context); + } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ClusterRoleOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ClusterRoleOperationsImpl.java index a8a6fe64ba8..f0010da0a01 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ClusterRoleOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ClusterRoleOperationsImpl.java @@ -15,8 +15,6 @@ */ package io.fabric8.kubernetes.client.dsl.internal; -import java.util.Map; -import java.util.TreeMap; import io.fabric8.kubernetes.api.model.rbac.DoneableClusterRole; import io.fabric8.kubernetes.api.model.rbac.ClusterRole; @@ -24,16 +22,26 @@ import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; public class ClusterRoleOperationsImpl extends HasMetadataOperation> { public ClusterRoleOperationsImpl(OkHttpClient client, Config config) { - this(client, config,"rbac.authorization.k8s.io", "v1", null, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - public ClusterRoleOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, ClusterRole item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, apiGroup, apiVersion, "clusterroles", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + public ClusterRoleOperationsImpl(OperationContext context) { + super(context.withApiGroupName("rbac.authorization.k8s.io") + .withApiGroupVersion("v1") + .withPlural("clusterroles")); + this.type = ClusterRole.class; + this.listType = ClusterRoleList.class; + this.doneableType = DoneableClusterRole.class; + } + @Override + public ClusterRoleOperationsImpl newInstance(OperationContext context) { + return new ClusterRoleOperationsImpl(context); } @Override diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ComponentStatusOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ComponentStatusOperationsImpl.java index d8cf2c9ae9e..2354db4b764 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ComponentStatusOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ComponentStatusOperationsImpl.java @@ -16,6 +16,7 @@ package io.fabric8.kubernetes.client.dsl.internal; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import io.fabric8.kubernetes.api.model.ComponentStatus; @@ -30,14 +31,21 @@ public class ComponentStatusOperationsImpl extends HasMetadataOperation> { - public ComponentStatusOperationsImpl(OkHttpClient client, Config config, String namespace) { - this(client, config, null, null, namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); - } - - - public ComponentStatusOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, ComponentStatus item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, apiGroup, apiVersion, "componentstatuses", null, name, cascading, item, resourceVersion, reloadingFromServer, -1, labels, labelsNot, labelsIn, labelsNotIn, fields); - } + public ComponentStatusOperationsImpl(OkHttpClient client, Config config) { + this(new OperationContext().withOkhttpClient(client).withConfig(config)); + } + + public ComponentStatusOperationsImpl(OperationContext context) { + super(context.withPlural("componentstatuses")); + this.type = ComponentStatus.class; + this.listType = ComponentStatusList.class; + this.doneableType = DoneableComponentStatus.class; + } + + @Override + public ComponentStatusOperationsImpl newInstance(OperationContext context) { + return new ComponentStatusOperationsImpl(context); + } @Override public boolean isResourceNamespaced() { diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CronJobOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CronJobOperationsImpl.java index 75daba9efd9..7c06702b272 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CronJobOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CronJobOperationsImpl.java @@ -23,6 +23,7 @@ import io.fabric8.kubernetes.client.KubernetesClientException; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import java.io.InputStream; @@ -30,18 +31,31 @@ import java.util.TreeMap; public class CronJobOperationsImpl extends HasMetadataOperation> { - public CronJobOperationsImpl(OkHttpClient client, Config config, String namespace) { - this(client, config, "batch", "v1beta1", namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + + public CronJobOperationsImpl(OkHttpClient client, Config config) { + this(new OperationContext().withOkhttpClient(client).withConfig(config)); + } + + public CronJobOperationsImpl(OperationContext context) { + super(context.withApiGroupName("batch") + .withApiGroupVersion("v1beta1") + .withPlural("cronjobs")); + this.type = CronJob.class; + this.listType = CronJobList.class; + this.doneableType = DoneableCronJob.class; } - public CronJobOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, CronJob item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, apiGroup, apiVersion, "cronjobs", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + + @Override + public CronJobOperationsImpl newInstance(OperationContext context) { + return new CronJobOperationsImpl(context); } + @Override public Resource load(InputStream is) { try { CronJob item = unmarshal(is, CronJob.class); - return new CronJobOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), item, getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); + return new CronJobOperationsImpl(context.withItem(item)); } catch (Throwable t) { throw KubernetesClientException.launderThrowable(t); } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CustomResourceDefinitionOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CustomResourceDefinitionOperationsImpl.java index e2a06a34418..f8c7abdbcdd 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CustomResourceDefinitionOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CustomResourceDefinitionOperationsImpl.java @@ -21,6 +21,7 @@ import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import io.fabric8.kubernetes.client.dsl.MixedOperation; @@ -31,26 +32,23 @@ */ public class CustomResourceDefinitionOperationsImpl extends HasMetadataOperation> { - public CustomResourceDefinitionOperationsImpl(OkHttpClient client, Config config) { - this(client, config, null, null, null, null, false, null, "v1beta1", false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); - } - public CustomResourceDefinitionOperationsImpl(OkHttpClient client, Config config, String namespace, String name, Boolean cascading, CustomResourceDefinition item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - this(client, config, "apiextensions.k8s.io", null, namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); - } - public CustomResourceDefinitionOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, CustomResourceDefinition item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, notBlank(apiGroup, "apiextensions.k8s.io"), notBlank(apiVersion, "v1beta1"), "customresourcedefinitions", namespace, name, cascading, item, notBlank(resourceVersion, "v1beta1"), reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + public CustomResourceDefinitionOperationsImpl(OkHttpClient client, Config config) { + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - @Override - public Resource withName(String name) { - return new CustomResourceDefinitionOperationsImpl(client, config, apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); + public CustomResourceDefinitionOperationsImpl(OperationContext context) { + super(context.withApiGroupName("apiextensions.k8s.io") + .withApiGroupVersion("v1beta1") + .withPlural("customresourcedefinitions")); + this.type = CustomResourceDefinition.class; + this.listType = CustomResourceDefinitionList.class; + this.doneableType = DoneableCustomResourceDefinition.class; } - @Override - public MixedOperation> inNamespace(String namespace) { - return new CustomResourceDefinitionOperationsImpl(client, config, apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); + public CustomResourceDefinitionOperationsImpl newInstance(OperationContext context) { + return new CustomResourceDefinitionOperationsImpl(context); } @Override @@ -58,8 +56,4 @@ public boolean isResourceNamespaced() { return false; } - private static final String notBlank(String value, String defaultValue) { - return (value != null && !value.isEmpty()) ? value : defaultValue; - } - } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CustomResourceOperationContext.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CustomResourceOperationContext.java new file mode 100644 index 00000000000..b0c53dfa9f4 --- /dev/null +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CustomResourceOperationContext.java @@ -0,0 +1,143 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * 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.fabric8.kubernetes.client.dsl.internal; + +import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; +import okhttp3.OkHttpClient; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +public class CustomResourceOperationContext extends OperationContext { + + protected Object crd; + protected Class type; + protected Class listType; + protected Class doneableType; + + public CustomResourceOperationContext() { + } + + public CustomResourceOperationContext(OkHttpClient client, Config config, String plural, String namespace, String name, String apiGroupName, String apiGroupVersion, boolean cascading, Object item, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields, String resourceVersion, boolean reloadingFromServer, long gracePeriodSeconds, Object crd, Class type, Class listType, Class doneableType) { + super(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading, item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + this.crd = crd; + this.type = type; + this.listType = listType; + this.doneableType = doneableType; + } + + public Object getCrd() { + return crd; + } + + public Class getType() { + return type; + } + + public Class getListType() { + return listType; + } + + public Class getDoneableType() { + return doneableType; + } + + public CustomResourceOperationContext withOkhttpClient(OkHttpClient client) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withConfig(Config config) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withPlural(String plural) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withNamespace(String namespace) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withName(String name) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withApiGroupName(String apiGroupName) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withApiGroupVersion(String apiGroupVersion) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + @Override + public CustomResourceOperationContext withItem(Object item) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withCascading(boolean cascading) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withLabels(Map labels) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withLabelsIn(Map labelsIn) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withLabelsNot(Map labelsNot) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withLabelsNotIn(Map labelsNotIn) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withFields(Map fields) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withResourceVersion(String resourceVersion) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withReloadingFromServer(boolean reloadingFromServer) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withGracePeriodSeconds(long gracePeriodSeconds) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withCrd(Object crd) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withType(Class type) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withListType(Class listType) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } + + public CustomResourceOperationContext withDoneableType(Class doneableType) { + return new CustomResourceOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, crd, type, listType, doneableType); + } +} diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CustomResourceOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CustomResourceOperationsImpl.java index 7d271e13434..fbb9eb19e28 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CustomResourceOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CustomResourceOperationsImpl.java @@ -31,6 +31,7 @@ import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.Watchable; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import io.fabric8.kubernetes.internal.KubernetesDeserializer; import okhttp3.OkHttpClient; @@ -45,24 +46,20 @@ public class CustomResourceOperationsImpl resourceType, Class resourceListType, Class doneType) { - this(httpClient, configuration, apiGroup(crd), apiVersion(crd), resourceT(crd), resourceNamespaced(crd), null, null, false, null, null, false, resourceType, resourceListType, doneType); + public CustomResourceOperationsImpl(OkHttpClient client, Config config) { + this(new CustomResourceOperationContext().withOkhttpClient(client).withConfig(config)); } - public CustomResourceOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String resourceT, boolean resouceNamespaced, String namespace, String name, Boolean cascading, T item, String resourceVersion, Boolean reloadingFromServer, Class type, Class listType, Class doneableType) { - super(client, config, apiGroup, apiVersion, resourceT, namespace, name, cascading, item, resourceVersion, reloadingFromServer, type, listType, doneableType); - this.resourceNamespaced = resouceNamespaced; - this.apiVersion = getAPIGroup() + "/" + getAPIVersion(); + public CustomResourceOperationsImpl(CustomResourceOperationContext context) { + super(context.withApiGroupName(apiGroup((CustomResourceDefinition) context.getCrd())) + .withApiGroupVersion(apiVersion((CustomResourceDefinition) context.getCrd())) + .withPlural(resourceT((CustomResourceDefinition) context.getCrd()))); - KubernetesDeserializer.registerCustomKind(type.getSimpleName(), type); - if (KubernetesResource.class.isAssignableFrom(listType)) { - KubernetesDeserializer.registerCustomKind(listType.getSimpleName(), (Class) listType); - } - } + this.type = context.getType(); + this.listType = context.getListType(); + this.doneableType = context.getDoneableType(); - protected CustomResourceOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String resourceT, boolean resouceNamespaced, String namespace, String name, Boolean cascading, T item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields, Class type, Class listType, Class doneableType) { - super(client, config, apiGroup, apiVersion, resourceT, namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields, type, listType, doneableType); - this.resourceNamespaced = resouceNamespaced; + this.resourceNamespaced = resourceNamespaced((CustomResourceDefinition) context.getCrd()); this.apiVersion = getAPIGroup() + "/" + getAPIVersion(); KubernetesDeserializer.registerCustomKind(type.getSimpleName(), type); @@ -71,6 +68,11 @@ protected CustomResourceOperationsImpl(OkHttpClient client, Config config, Strin } } + @Override + public CustomResourceOperationsImpl newInstance(OperationContext context) { + return new CustomResourceOperationsImpl((CustomResourceOperationContext) context); + } + protected static String apiGroup(CustomResourceDefinition crd) { return crd.getSpec().getGroup(); } @@ -91,56 +93,8 @@ protected static boolean resourceNamespaced(CustomResourceDefinition crd) { return "Namespaced".equals(crd.getSpec().getScope()); } - @Override - public NonNamespaceOperation> inAnyNamespace() { - return inNamespace(null); - } - - @Override - public NonNamespaceOperation> inNamespace(String namespace) { - return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), resourceNamespaced, namespace, getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getType(), getListType(), getDoneableType()); - } - @Override public boolean isResourceNamespaced() { return resourceNamespaced; } - - @Override - public Resource withName(String name) { - if (name == null || name.length() == 0) { - throw new IllegalArgumentException("Name must be provided."); - } - return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), resourceNamespaced, getNamespace(), name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getType(), getListType(), getDoneableType()); - } - - @Override - public Replaceable lockResourceVersion(String resourceVersion) { - return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), resourceNamespaced, getNamespace(), getName(), isCascading(), getItem(), resourceVersion, isReloadingFromServer(), getType(), getListType(), getDoneableType()); - } - - @Override - protected Resource createItemOperation(T item) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { - return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), resourceNamespaced, getNamespace(), getName(), isCascading(), item, getResourceVersion(), isReloadingFromServer(), getType(), getListType(), getDoneableType()); - } - - @Override - public Resource load(InputStream is) { - return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), resourceNamespaced, getNamespace(), getName(), isCascading(), unmarshal(is, getType()), getResourceVersion(), isReloadingFromServer(), getType(), getListType(), getDoneableType()); - } - - @Override - public Gettable fromServer() { - return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), resourceNamespaced, getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), true, getType(), getListType(), getDoneableType()); - } - - @Override - public Watchable> withResourceVersion(String resourceVersion) { - return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), resourceNamespaced, getNamespace(), getName(), isCascading(), getItem(), resourceVersion, isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), getType(), getListType(), getDoneableType()); - } - - @Override - public EditReplacePatchDeletable cascading(boolean cascading) { - return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), resourceNamespaced, getNamespace(), getName(), cascading, getItem(), getResourceVersion(), isReloadingFromServer(), getType(), getListType(), getDoneableType()); - } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/DeploymentOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/DeploymentOperationsImpl.java index 8f23278127a..52e38de8e3f 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/DeploymentOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/DeploymentOperationsImpl.java @@ -19,8 +19,8 @@ import io.fabric8.kubernetes.api.model.ContainerBuilder; import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder; import io.fabric8.kubernetes.client.dsl.*; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import io.fabric8.kubernetes.client.utils.Utils; -import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.apps.DeploymentList; @@ -28,17 +28,11 @@ import io.fabric8.kubernetes.api.model.LabelSelector; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.KubernetesClientException; -import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; -import okhttp3.Request; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.net.MalformedURLException; -import java.net.URL; import java.util.Collections; -import java.util.Map; import java.util.Objects; -import java.util.TreeMap; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import java.util.concurrent.CountDownLatch; @@ -53,18 +47,24 @@ public class DeploymentOperationsImpl extends RollableScalableResourceOperation< static final transient Logger LOG = LoggerFactory.getLogger(DeploymentOperationsImpl.class); - public DeploymentOperationsImpl(OkHttpClient client, Config config, String namespace) { - this(client, config, "apps", "v1", namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), config.getRollingTimeout(), TimeUnit.SECONDS); + public DeploymentOperationsImpl(OkHttpClient client, Config config) { + this(new RollingOperationContext().withOkhttpClient(client).withConfig(config)); } - public DeploymentOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, Deployment item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, apiGroup, apiVersion, "deployments", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields,false, config.getRollingTimeout(), TimeUnit.SECONDS); + public DeploymentOperationsImpl(RollingOperationContext context) { + super(context.withApiGroupName("apps") + .withApiGroupVersion("v1") + .withPlural("deployments")); + this.type = Deployment .class; + this.listType = DeploymentList.class; + this.doneableType = DoneableDeployment.class; + reaper = new DeploymentReaper(this); } - public DeploymentOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, Deployment item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields, Long rollingTimeout, TimeUnit rollingTimeUnit) { - super(client, config, apiGroup, apiVersion, "deployments", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields,false, rollingTimeout, rollingTimeUnit); - reaper = new DeploymentReaper(this); + @Override + public DeploymentOperationsImpl newInstance(OperationContext context) { + return new DeploymentOperationsImpl((RollingOperationContext) context); } @Override @@ -108,7 +108,7 @@ public Deployment patch(Deployment item) { @Override public DeploymentOperationsImpl rolling() { - return new DeploymentOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rollingTimeout, rollingTimeUnit); + return new DeploymentOperationsImpl(((RollingOperationContext)context).withRolling(true)); } @Override @@ -163,12 +163,12 @@ public Deployment updateImage(String image) { @Override public ImageEditReplacePatchable withTimeoutInMillis(long timeoutInMillis) { - return new DeploymentOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), namespace, getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), timeoutInMillis, TimeUnit.MILLISECONDS); + return new DeploymentOperationsImpl(((RollingOperationContext)context).withRollingTimeout(timeoutInMillis)); } @Override public ImageEditReplacePatchable withTimeout(long timeout, TimeUnit unit) { - return new DeploymentOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), namespace, getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), timeout, unit); + return new DeploymentOperationsImpl(((RollingOperationContext)context).withRollingTimeUnit(unit)); } /** @@ -274,7 +274,7 @@ private void reapMatchingReplicaSets(LabelSelector selector) { if (selector == null || (selector.getMatchLabels() == null && selector.getMatchExpressions() == null)) { return; } - ReplicaSetOperationsImpl rsOper = new ReplicaSetOperationsImpl(oper.client, oper.getConfig(), oper.getNamespace()); + ReplicaSetOperationsImpl rsOper = new ReplicaSetOperationsImpl((RollingOperationContext) oper.context); rsOper.inNamespace(oper.getNamespace()).withLabelSelector(selector).delete(); } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/DeploymentRollingUpdater.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/DeploymentRollingUpdater.java index 3f7db2652f7..76d5a532134 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/DeploymentRollingUpdater.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/DeploymentRollingUpdater.java @@ -110,6 +110,6 @@ protected Deployment setReplicas(Deployment obj, int replicas) { @Override protected Operation> resources() { - return new DeploymentOperationsImpl(client, config, namespace); + return new DeploymentOperationsImpl(client, config); } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/JobOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/JobOperationsImpl.java index 07fee027aea..703ac34d965 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/JobOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/JobOperationsImpl.java @@ -15,6 +15,7 @@ */ package io.fabric8.kubernetes.client.dsl.internal; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import io.fabric8.kubernetes.api.model.batch.DoneableJob; import io.fabric8.kubernetes.api.model.batch.Job; @@ -28,9 +29,7 @@ import org.slf4j.LoggerFactory; import java.io.InputStream; -import java.util.Map; import java.util.Objects; -import java.util.TreeMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -43,20 +42,30 @@ public class JobOperationsImpl extends HasMetadataOperation(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + public JobOperationsImpl(OkHttpClient client, Config config) { + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - public JobOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, Job item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, apiGroup, apiVersion, "jobs", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); - reaper = new JobReaper(this); + public JobOperationsImpl(OperationContext context) { + super(context.withApiGroupName("batch") + .withApiGroupVersion("v1") + .withPlural("jobs")); + + this.type = Job.class; + this.listType = JobList.class; + this.doneableType = DoneableJob.class; + } + + @Override + public JobOperationsImpl newInstance(OperationContext context) { + return new JobOperationsImpl(context); } @Override public ScalableResource load(InputStream is) { try { Job item = unmarshal(is, Job.class); - return new JobOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), item, getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); + return new JobOperationsImpl(context.withItem(item)); } catch (Throwable t) { throw KubernetesClientException.launderThrowable(t); } @@ -64,7 +73,7 @@ public ScalableResource load(InputStream is) { @Override public ScalableResource fromServer() { - return new JobOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), true, getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); + return new JobOperationsImpl(context.withReloadingFromServer(true)); } @Override diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/KubernetesListOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/KubernetesListOperationsImpl.java index 0bfaeeaf14b..afd7be6f500 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/KubernetesListOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/KubernetesListOperationsImpl.java @@ -18,6 +18,7 @@ import io.fabric8.kubernetes.client.dsl.KubernetesListMixedOperation; import io.fabric8.kubernetes.client.dsl.KubernetesListOperation; import io.fabric8.kubernetes.client.dsl.Loadable; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import io.fabric8.kubernetes.api.builder.Function; import io.fabric8.kubernetes.api.builder.VisitableBuilder; @@ -60,7 +61,7 @@ public KubernetesListOperationsImpl(OkHttpClient client, Config config, String n } public KubernetesListOperationsImpl(OkHttpClient client, Config config, String namespace, String name, Boolean cascading, Boolean fromServer, Boolean deletingExisting, KubernetesList item, String resourceVersion) { - super(client, config, null, null, null, namespace, null); + super(client, config, namespace); this.fromServer = fromServer; this.deletingExisting = deletingExisting; this.item = item; diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NamespaceOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NamespaceOperationsImpl.java index 7a40bc3566d..179e9c01438 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NamespaceOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NamespaceOperationsImpl.java @@ -16,6 +16,7 @@ package io.fabric8.kubernetes.client.dsl.internal; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import io.fabric8.kubernetes.api.model.DoneableNamespace; import io.fabric8.kubernetes.api.model.Namespace; @@ -23,19 +24,22 @@ import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; -import java.util.Map; -import java.util.TreeMap; - public class NamespaceOperationsImpl extends HasMetadataOperation> { public NamespaceOperationsImpl(OkHttpClient client, Config config) { - this(client, config, null, null, null, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + this(new OperationContext().withOkhttpClient(client).withConfig(config)); + } + + public NamespaceOperationsImpl(OperationContext context) { + super(context.withPlural("namespaces")); + this.type = Namespace.class; + this.listType = NamespaceList.class; + this.doneableType = DoneableNamespace.class; } - public NamespaceOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, - Boolean cascading, Namespace item, String resourceVersion, Boolean reloadingFromServer, - long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, apiGroup, apiVersion, "namespaces", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + @Override + public NamespaceOperationsImpl newInstance(OperationContext context) { + return new NamespaceOperationsImpl(context); } @Override diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableImpl.java index 86e50f8333c..1cb9454cbe1 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableImpl.java @@ -103,7 +103,7 @@ public NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableImpl(OkHttpCl } public NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableImpl(OkHttpClient client, Config config, String namespace, String explicitNamespace, Boolean fromServer, Boolean deletingExisting, List visitors, Object item, long gracePeriodSeconds, Boolean cascading) { - super(client, config, null, null, null, null, null); + super(client, config); this.fallbackNamespace = namespace; this.explicitNamespace = explicitNamespace; this.fromServer = fromServer; diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java index 80486b5b083..1d80bb02d96 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java @@ -174,7 +174,7 @@ public NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl(OkHt } public NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl(OkHttpClient client, Config config, String namespace, String explicitNamespace, Boolean fromServer, Boolean deletingExisting, List visitors, Object item, InputStream inputStream, Map parameters, long gracePeriodSeconds, Boolean cascading) { - super(client, config, null, null, null, null, null); + super(client, config); this.fallbackNamespace = namespace; this.explicitNamespace = explicitNamespace; this.fromServer = fromServer; diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NodeOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NodeOperationsImpl.java index 33955714378..1fc1e49fc8b 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NodeOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NodeOperationsImpl.java @@ -16,6 +16,7 @@ package io.fabric8.kubernetes.client.dsl.internal; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import io.fabric8.kubernetes.api.model.DoneableNode; import io.fabric8.kubernetes.api.model.Node; @@ -23,17 +24,22 @@ import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; -import java.util.Map; -import java.util.TreeMap; - public class NodeOperationsImpl extends HasMetadataOperation> { public NodeOperationsImpl(OkHttpClient client, Config config) { - this(client, config, null, null, null, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + this(new OperationContext().withOkhttpClient(client).withConfig(config)); + } + + public NodeOperationsImpl(OperationContext context) { + super(context.withPlural("nodes")); + this.type = Node.class; + this.listType = NodeList.class; + this.doneableType = DoneableNode.class; } - public NodeOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, Node item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, apiGroup, apiVersion, "nodes", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + @Override + public NodeOperationsImpl newInstance(OperationContext context) { + return new NodeOperationsImpl(context); } @Override diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PersistentVolumeOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PersistentVolumeOperationsImpl.java index fa5c5045d68..b3cc712132e 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PersistentVolumeOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PersistentVolumeOperationsImpl.java @@ -16,6 +16,7 @@ package io.fabric8.kubernetes.client.dsl.internal; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import io.fabric8.kubernetes.api.model.DoneablePersistentVolume; import io.fabric8.kubernetes.api.model.PersistentVolume; @@ -23,18 +24,23 @@ import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; -import java.util.Map; -import java.util.TreeMap; - public class PersistentVolumeOperationsImpl extends HasMetadataOperation> { public PersistentVolumeOperationsImpl(OkHttpClient client, Config config) { - this(client, config, null, null, null, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + this(new OperationContext().withOkhttpClient(client).withConfig(config)); + } + + public PersistentVolumeOperationsImpl(OperationContext context) { + super(context.withPlural("persistentvolumes")); + this.type = PersistentVolume.class; + this.listType = PersistentVolumeList.class; + this.doneableType = DoneablePersistentVolume.class; } - public PersistentVolumeOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, PersistentVolume item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, null, apiVersion, "persistentvolumes", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + @Override + public PersistentVolumeOperationsImpl newInstance(OperationContext context) { + return new PersistentVolumeOperationsImpl(context); } @Override diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodOperationContext.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodOperationContext.java new file mode 100644 index 00000000000..10170957ad3 --- /dev/null +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodOperationContext.java @@ -0,0 +1,299 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * 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.fabric8.kubernetes.client.dsl.internal; + +import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.dsl.ExecListener; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; +import okhttp3.OkHttpClient; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; +import java.util.Map; + +public class PodOperationContext extends OperationContext { + + private String containerId; + private InputStream in; + private OutputStream out; + private OutputStream err; + private OutputStream errChannel; + + private PipedOutputStream inPipe; + private PipedInputStream outPipe; + private PipedInputStream errPipe; + private PipedInputStream errChannelPipe; + private boolean tty; + private boolean terminatedStatus; + private boolean timestamps; + private String sinceTimestamp; + private Integer sinceSeconds; + private Integer tailingLines; + private boolean prettyOutput; + private ExecListener execListener; + private Integer limitBytes; + private Integer bufferSize; + + public PodOperationContext() { + } + + public PodOperationContext(OkHttpClient client, Config config, String plural, String namespace, String name, String apiGroupName, String apiGroupVersion, boolean cascading, Object item, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields, String resourceVersion, boolean reloadingFromServer, long gracePeriodSeconds, String containerId, InputStream in, OutputStream out, OutputStream err, OutputStream errChannel, PipedOutputStream inPipe, PipedInputStream outPipe, PipedInputStream errPipe, PipedInputStream errChannelPipe, Boolean tty, Boolean terminatedStatus, Boolean timestampes, String sinceTimestamp, Integer sinceSeconds, Integer tailingLines, Boolean prettyOutput, Integer limitBytes, Integer bufferSize, ExecListener execListener) { + super(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading, item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + this.containerId = containerId; + this.in = in; + this.out = out; + this.err = err; + this.errChannel = errChannel; + this.inPipe = inPipe; + this.outPipe = outPipe; + this.errPipe = errPipe; + this.errChannelPipe = errChannelPipe; + this.tty = tty; + this.terminatedStatus = terminatedStatus; + this.timestamps = timestampes; + this.sinceTimestamp = sinceTimestamp; + this.sinceSeconds = sinceSeconds; + this.tailingLines = tailingLines; + this.prettyOutput = prettyOutput; + this.execListener = execListener; + this.limitBytes = limitBytes; + this.bufferSize = bufferSize; + } + + public String getContainerId() { + return containerId; + } + + public InputStream getIn() { + return in; + } + + public OutputStream getOut() { + return out; + } + + public OutputStream getErr() { + return err; + } + + public OutputStream getErrChannel() { + return errChannel; + } + + public PipedOutputStream getInPipe() { + return inPipe; + } + + public PipedInputStream getOutPipe() { + return outPipe; + } + + public PipedInputStream getErrPipe() { + return errPipe; + } + + public PipedInputStream getErrChannelPipe() { + return errChannelPipe; + } + + public boolean isTty() { + return tty; + } + + public boolean isTerminatedStatus() { + return terminatedStatus; + } + + public boolean isTimestamps() { + return timestamps; + } + + public String getSinceTimestamp() { + return sinceTimestamp; + } + + public Integer getSinceSeconds() { + return sinceSeconds; + } + + public Integer getTailingLines() { + return tailingLines; + } + + public boolean isPrettyOutput() { + return prettyOutput; + } + + public ExecListener getExecListener() { + return execListener; + } + + public Integer getLimitBytes() { + return limitBytes; + } + + public Integer getBufferSize() { + return bufferSize; + } + + public PodOperationContext withOkhttpClient(OkHttpClient client) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withConfig(Config config) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withPlural(String plural) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withNamespace(String namespace) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withName(String name) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withApiGroupName(String apiGroupName) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withApiGroupVersion(String apiGroupVersion) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + @Override + public PodOperationContext withItem(Object item) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withCascading(boolean cascading) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withLabels(Map labels) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withLabelsIn(Map labelsIn) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withLabelsNot(Map labelsNot) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withLabelsNotIn(Map labelsNotIn) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withFields(Map fields) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withResourceVersion(String resourceVersion) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withReloadingFromServer(boolean reloadingFromServer) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withGracePeriodSeconds(long gracePeriodSeconds) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + + public PodOperationContext withContainerId(String containerId) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withIn(InputStream in) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withOut(OutputStream out) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withErr(OutputStream err) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withErrChannel(OutputStream errChannel) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withInPipe(PipedOutputStream inPipe) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withOutPipe(PipedInputStream outPipe) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withErrPipe(PipedInputStream errPipe) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withErrChannelPipe(PipedInputStream errChannelPipe) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withTty(boolean tty) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withTerminatedStatus(boolean terminatedStatus) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withTimestamps(boolean timestamps) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withSinceTimestamp(String sinceTimestamp) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withSinceSeconds(Integer sinceSeconds) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withTailingLines(Integer tailingLines) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withPrettyOutput(boolean prettyOutput) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withExecListener(ExecListener execListener) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withLimitBytes(Integer limitBytes) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } + + public PodOperationContext withBufferSize(Integer bufferSize) { + return new PodOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, containerId, in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, bufferSize, execListener); + } +} diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodOperationsImpl.java index 1ab3f457c5f..620923a039a 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodOperationsImpl.java @@ -24,8 +24,6 @@ import java.net.URL; import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; -import java.util.Map; -import java.util.TreeMap; import java.util.concurrent.TimeUnit; import io.fabric8.kubernetes.api.model.DoneablePod; @@ -52,6 +50,7 @@ import io.fabric8.kubernetes.client.dsl.TtyExecOutputErrorable; import io.fabric8.kubernetes.client.dsl.TtyExecable; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import io.fabric8.kubernetes.client.utils.URLUtils; import okhttp3.*; @@ -80,44 +79,45 @@ public class PodOperationsImpl extends HasMetadataOperation(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); - } - - public PodOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, Pod item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - this(client, config, apiGroup, apiVersion, namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields, - null, null, null, null, null, null, null, null, null, false, false, false, null, null, null, false, null, null, null); - } - - @Deprecated - public PodOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, Pod item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields, String containerId, InputStream in, PipedOutputStream inPipe, OutputStream out, PipedInputStream outPipe, OutputStream err, PipedInputStream errPipe, OutputStream errChannel, PipedInputStream errChannelPipe, boolean withTTY, boolean withTerminatedStatus, boolean withTimestamps, String sinceTimestamp, Integer sinceSeconds, Integer withTailingLines, boolean withPrettyOutput, ExecListener execListener, Integer limitBytes) { - this(client, config, apiGroup, apiVersion, namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields, containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, null); - } + public PodOperationsImpl(PodOperationContext context) { + super(context.withPlural("pods")); + this.type = Pod.class; + this.listType = PodList.class; + this.doneableType = DoneablePod.class; + + this.containerId = context.getContainerId(); + this.in = context.getIn(); + this.inPipe = context.getInPipe(); + this.out = context.getOut(); + this.outPipe = context.getOutPipe(); + this.err = context.getErr(); + this.errPipe = context.getErrPipe(); + this.errChannel = context.getErrChannel(); + this.errChannelPipe = context.getErrChannelPipe(); + this.withTTY = context.isTty(); + this.withTerminatedStatus = context.isTerminatedStatus(); + this.withTimestamps = context.isTimestamps(); + this.sinceTimestamp = context.getSinceTimestamp(); + this.sinceSeconds = context.getSinceSeconds(); + this.withTailingLines = context.getTailingLines(); + this.withPrettyOutput = context.isPrettyOutput(); + this.execListener = context.getExecListener(); + this.limitBytes = context.getLimitBytes(); + this.bufferSize = context.getBufferSize(); + } - public PodOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, Pod item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields, String containerId, InputStream in, PipedOutputStream inPipe, OutputStream out, PipedInputStream outPipe, OutputStream err, PipedInputStream errPipe, OutputStream errChannel, PipedInputStream errChannelPipe, boolean withTTY, boolean withTerminatedStatus, boolean withTimestamps, String sinceTimestamp, Integer sinceSeconds, Integer withTailingLines, boolean withPrettyOutput, ExecListener execListener, Integer limitBytes, Integer bufferSize) { - super(client, config, apiGroup, apiVersion, "pods", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); - this.containerId = containerId; - this.in = in; - this.inPipe = inPipe; - this.out = out; - this.outPipe = outPipe; - this.err = err; - this.errPipe = errPipe; - this.errChannel = errChannel; - this.errChannelPipe = errChannelPipe; - this.withTTY = withTTY; - this.withTerminatedStatus = withTerminatedStatus; - this.withTimestamps = withTimestamps; - this.sinceTimestamp = sinceTimestamp; - this.sinceSeconds = sinceSeconds; - this.withTailingLines = withTailingLines; - this.withPrettyOutput = withPrettyOutput; - this.execListener = execListener; - this.limitBytes = limitBytes; - this.bufferSize = bufferSize; - } + @Override + public PodOperationsImpl newInstance(OperationContext context) { + return new PodOperationsImpl((PodOperationContext) context); + } + public PodOperationContext getContext() { + return (PodOperationContext) context; + } protected String getLogParameters() { StringBuilder sb = new StringBuilder(); sb.append("log?pretty=").append(withPrettyOutput); @@ -178,7 +178,7 @@ public Reader getLogReader() { @Override public String getLog(Boolean isPretty) { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, isPretty, execListener, limitBytes, bufferSize).getLog(); + return new PodOperationsImpl(getContext().withPrettyOutput(isPretty)).getLog(); } @Override @@ -230,7 +230,7 @@ public LocalPortForward portForward(int port, int localPort) { @Override public ContainerResource inContainer(String containerId) { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withContainerId(containerId)); } @Override @@ -281,12 +281,12 @@ public ExecWatch exec(String... command) { @Override public TtyExecOutputErrorable readingInput(InputStream in) { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withIn(in)); } @Override public TtyExecOutputErrorable writingInput(PipedOutputStream inPipe) { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withInPipe(inPipe)); } @Override @@ -296,17 +296,17 @@ public TtyExecOutputErrorable @Override public TtyExecOutputErrorable redirectingInput(Integer bufferSize) { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, new PipedOutputStream(), out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withBufferSize(bufferSize)); } @Override public TtyExecErrorable writingOutput(OutputStream out) { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withOut(out)); } @Override public TtyExecErrorable readingOutput(PipedInputStream outPipe) { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withOutPipe(outPipe)); } @Override @@ -316,12 +316,12 @@ public TtyExecErrorable redir @Override public TtyExecErrorChannelable writingError(OutputStream err) { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withErr(err)); } @Override public TtyExecErrorChannelable readingError(PipedInputStream errPipe) { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withErrPipe(errPipe)); } @Override @@ -331,12 +331,12 @@ public TtyExecErrorChannelable writingErrorChannel(OutputStream errChannel) { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withErrChannel(errChannel)); } @Override public TtyExecable readingErrorChannel(PipedInputStream errChannelPipe) { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withErrChannelPipe(errChannelPipe)); } @Override @@ -348,48 +348,48 @@ public TtyExecable redirectingErrorChannel() { @Override public ExecListenable withTTY() { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, true, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withTty(true)); } @Override public Loggable withPrettyOutput() { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, true, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withPrettyOutput(true)); } @Override public PrettyLoggable tailingLines(int withTailingLines) { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withTailingLines(withTailingLines)); } @Override public TailPrettyLoggable sinceTime(String sinceTimestamp) { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withSinceTimestamp(sinceTimestamp)); } @Override public TailPrettyLoggable sinceSeconds(int sinceSeconds) { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withSinceSeconds(sinceSeconds)); } @Override public TimeTailPrettyLoggable terminated() { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, true, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withTerminatedStatus(true)); } @Override public Execable usingListener(ExecListener execListener) { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withExecListener(execListener)); } @Override public BytesLimitTerminateTimeTailPrettyLoggable limitBytes(int limitBytes) { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withLimitBytes(limitBytes)); } @Override public BytesLimitTerminateTimeTailPrettyLoggable usingTimestamps() { - return new PodOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), containerId, in, inPipe, out, outPipe, err, errPipe, errChannel, errChannelPipe, withTTY, withTerminatedStatus, true, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, execListener, limitBytes, bufferSize); + return new PodOperationsImpl(getContext().withTimestamps(true)); } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodPresetOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodPresetOperationsImpl.java deleted file mode 100644 index 8c6489c4268..00000000000 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodPresetOperationsImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (C) 2015 Red Hat, Inc. - * - * 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.fabric8.kubernetes.client.dsl.internal; - -import io.fabric8.kubernetes.api.model.settings.DoneablePodPreset; -import io.fabric8.kubernetes.api.model.settings.PodPreset; -import io.fabric8.kubernetes.api.model.settings.PodPresetList; -import io.fabric8.kubernetes.client.Config; -import io.fabric8.kubernetes.client.dsl.Resource; -import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; -import okhttp3.OkHttpClient; - -import java.util.Map; -import java.util.TreeMap; - -public class PodPresetOperationsImpl extends HasMetadataOperation> { - public PodPresetOperationsImpl(OkHttpClient client, Config config) { - this(client, config, "settings.k8s.io", "v1alpha1", null, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); - } - public PodPresetOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, PodPreset item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, apiGroup, apiVersion, "podpresets", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); - } - - @Override - public boolean isResourceNamespaced() { - return true; - } -} diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodSecurityPolicyOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodSecurityPolicyOperationsImpl.java index 411133b10a3..61fa3ffc546 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodSecurityPolicyOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodSecurityPolicyOperationsImpl.java @@ -20,20 +20,28 @@ import io.fabric8.kubernetes.api.model.extensions.PodSecurityPolicyList; import io.fabric8.kubernetes.api.model.extensions.DoneablePodSecurityPolicy; import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; -import java.util.Map; -import java.util.TreeMap; - public class PodSecurityPolicyOperationsImpl extends HasMetadataOperation>{ - public PodSecurityPolicyOperationsImpl(OkHttpClient client, Config config, String namespace) { - this(client, config, "extensions","v1beta1", namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + public PodSecurityPolicyOperationsImpl(OkHttpClient client, Config config) { + this(new OperationContext().withOkhttpClient(client).withConfig(config)); + } + + public PodSecurityPolicyOperationsImpl(OperationContext context) { + super(context.withApiGroupName("extensions") + .withApiGroupVersion("v1beta1") + .withPlural("podsecuritypolicies")); + this.type = PodSecurityPolicy.class; + this.listType = PodSecurityPolicyList.class; + this.doneableType = DoneablePodSecurityPolicy.class; } - public PodSecurityPolicyOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading,PodSecurityPolicy item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, apiGroup, apiVersion, "podsecuritypolicies", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + @Override + public PodSecurityPolicyOperationsImpl newInstance(OperationContext context) { + return new PodSecurityPolicyOperationsImpl(context); } @Override diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PriorityClassOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PriorityClassOperationsImpl.java index bc0378fa2b7..b84de291f67 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PriorityClassOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PriorityClassOperationsImpl.java @@ -21,18 +21,29 @@ import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; -import java.util.Map; -import java.util.TreeMap; public class PriorityClassOperationsImpl extends HasMetadataOperation> { - public PriorityClassOperationsImpl(OkHttpClient client, Config config, String namespace) { - this(client, config, "scheduling.k8s.io","v1beta1", namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + + public PriorityClassOperationsImpl(OkHttpClient client, Config config) { + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - public PriorityClassOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, PriorityClass item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, apiGroup, apiVersion, "priorityclasses", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + public PriorityClassOperationsImpl(OperationContext context) { + super(context.withApiGroupName("scheduling.k8s.io") + .withApiGroupVersion("v1beta1") + .withPlural("priorityclasses")); + + this.type = PriorityClass.class; + this.listType = PriorityClassList.class; + this.doneableType = DoneablePriorityClass.class; + } + + @Override + public PriorityClassOperationsImpl newInstance(OperationContext context) { + return new PriorityClassOperationsImpl(context); } @Override diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ReplicaSetOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ReplicaSetOperationsImpl.java index 9623bd6b4b4..1ee71e47aea 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ReplicaSetOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ReplicaSetOperationsImpl.java @@ -23,71 +23,34 @@ import io.fabric8.kubernetes.api.model.apps.ReplicaSetList; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.KubernetesClientException; -import io.fabric8.kubernetes.client.Watch; -import io.fabric8.kubernetes.client.Watcher; -import io.fabric8.kubernetes.client.dsl.EditReplacePatchDeletable; import io.fabric8.kubernetes.client.dsl.ImageEditReplacePatchable; import io.fabric8.kubernetes.client.dsl.RollableScalableResource; import io.fabric8.kubernetes.client.dsl.TimeoutImageEditReplacePatchable; -import io.fabric8.kubernetes.client.dsl.Watchable; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import java.util.Collections; -import java.util.Map; -import java.util.TreeMap; import java.util.concurrent.TimeUnit; public class ReplicaSetOperationsImpl extends RollableScalableResourceOperation> implements TimeoutImageEditReplacePatchable { - public ReplicaSetOperationsImpl(OkHttpClient client, Config config, String namespace) { - this(client, config, "apps", "v1", namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), false, config.getRollingTimeout(), TimeUnit.MILLISECONDS); + public ReplicaSetOperationsImpl(OkHttpClient client, Config config) { + this(new RollingOperationContext().withOkhttpClient(client).withConfig(config)); } - public ReplicaSetOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, ReplicaSet item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - this(client, config, apiGroup, apiVersion, namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields, false, config.getRollingTimeout(), TimeUnit.MILLISECONDS); - } - - public ReplicaSetOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, ReplicaSet 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, "replicasets", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields, rolling, rollingTimeout, rollingTimeUnit); - } - - @Override - public ImageEditReplacePatchable withTimeout(long timeout, TimeUnit unit) { - return new ReplicaSetOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), namespace, getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, timeout, unit); - } - - @Override - public ImageEditReplacePatchable withTimeoutInMillis(long timeoutInMillis) { - return new ReplicaSetOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), namespace, getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, timeoutInMillis, TimeUnit.MILLISECONDS); - } - - @Override - public RollableScalableResource withName(String name) { - if (name == null || name.length() == 0) { - throw new IllegalArgumentException("Name must be provided."); - } - return new ReplicaSetOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, rollingTimeout, rollingTimeUnit); - } - - @Override - public RollableScalableResource fromServer() { - return new ReplicaSetOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), true, getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, rollingTimeout, rollingTimeUnit); + public ReplicaSetOperationsImpl(RollingOperationContext context) { + super(context.withApiGroupName("apps") + .withApiGroupVersion("v1") + .withPlural("replicasets")); + this.type = ReplicaSet.class; + this.listType = ReplicaSetList.class; + this.doneableType = DoneableReplicaSet.class; } @Override - public Watchable> withResourceVersion(String resourceVersion) { - return new ReplicaSetOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), resourceVersion, isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, rollingTimeout, rollingTimeUnit); - } - - @Override - public EditReplacePatchDeletable cascading(boolean enabled) { - return new ReplicaSetOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), enabled, getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, rollingTimeout, rollingTimeUnit); - } - - @Override - public ReplicaSetOperationsImpl rolling() { - return new ReplicaSetOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), true, rollingTimeout, rollingTimeUnit); + public ReplicaSetOperationsImpl newInstance(OperationContext context) { + return new ReplicaSetOperationsImpl((RollingOperationContext) context); } @Override @@ -139,4 +102,18 @@ long getObservedGeneration(ReplicaSet current) { return (current != null && current.getStatus() != null && current.getStatus().getObservedGeneration() != null)? current.getStatus().getObservedGeneration() : -1; } + @Override + public TimeoutImageEditReplacePatchable rolling() { + return new ReplicaSetOperationsImpl(((RollingOperationContext)context).withRolling(true)); + } + + @Override + public ImageEditReplacePatchable withTimeout(long timeout, TimeUnit unit) { + return new ReplicaSetOperationsImpl(((RollingOperationContext)context).withRollingTimeout(unit.toMillis(timeout)).withRollingTimeUnit(TimeUnit.MILLISECONDS)); + } + + @Override + public ImageEditReplacePatchable withTimeoutInMillis(long timeoutInMillis) { + return new ReplicaSetOperationsImpl(((RollingOperationContext)context).withRollingTimeout(timeoutInMillis)); + } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ReplicaSetRollingUpdater.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ReplicaSetRollingUpdater.java index 7c288d3c07a..1a186923129 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ReplicaSetRollingUpdater.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ReplicaSetRollingUpdater.java @@ -110,6 +110,6 @@ protected ReplicaSet setReplicas(ReplicaSet obj, int replicas) { @Override protected Operation> resources() { - return new ReplicaSetOperationsImpl(client, config, namespace); + return new ReplicaSetOperationsImpl(client, config); } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ReplicationControllerOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ReplicationControllerOperationsImpl.java index 50f71fa9ce3..758858b6e6e 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ReplicationControllerOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ReplicationControllerOperationsImpl.java @@ -23,63 +23,45 @@ import io.fabric8.kubernetes.api.model.ReplicationControllerList; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.KubernetesClientException; -import io.fabric8.kubernetes.client.Watch; -import io.fabric8.kubernetes.client.Watcher; -import io.fabric8.kubernetes.client.dsl.EditReplacePatchDeletable; import io.fabric8.kubernetes.client.dsl.ImageEditReplacePatchable; -import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; import io.fabric8.kubernetes.client.dsl.RollableScalableResource; import io.fabric8.kubernetes.client.dsl.TimeoutImageEditReplacePatchable; -import io.fabric8.kubernetes.client.dsl.Watchable; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import java.io.InputStream; import java.util.Collections; -import java.util.Map; -import java.util.TreeMap; import java.util.concurrent.TimeUnit; public class ReplicationControllerOperationsImpl extends RollableScalableResourceOperation> implements TimeoutImageEditReplacePatchable { - public ReplicationControllerOperationsImpl(OkHttpClient client, Config config, String namespace) { - this(client, config, null, null, namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), false, config.getRollingTimeout(), TimeUnit.MILLISECONDS); + public ReplicationControllerOperationsImpl(OkHttpClient client, Config config) { + this(new RollingOperationContext().withOkhttpClient(client).withConfig(config)); } - public ReplicationControllerOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, ReplicationController item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - this(client, config, apiGroup, apiVersion, namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields, false, config.getRollingTimeout(), TimeUnit.MILLISECONDS); + public ReplicationControllerOperationsImpl(RollingOperationContext context) { + super(context.withPlural("replicationcontrollers")); + this.type = ReplicationController.class; + this.listType = ReplicationControllerList.class; + this.doneableType = DoneableReplicationController.class; } - public ReplicationControllerOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, ReplicationController 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, null, apiVersion, "replicationcontrollers", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields, rolling, rollingTimeout, rollingTimeUnit); + @Override + public ReplicationControllerOperationsImpl newInstance(OperationContext context) { + return new ReplicationControllerOperationsImpl((RollingOperationContext) context); } @Override public RollableScalableResource load(InputStream is) { try { ReplicationController item = unmarshal(is, ReplicationController.class); - return new ReplicationControllerOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), item, getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, rollingTimeout, rollingTimeUnit); + return new ReplicationControllerOperationsImpl((RollingOperationContext) context.withItem(item)); } catch (Throwable t) { throw KubernetesClientException.launderThrowable(t); } } - @Override - public NonNamespaceOperation> inNamespace(String namespace) { - return new ReplicationControllerOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), namespace, getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, rollingTimeout, rollingTimeUnit); - } - - - @Override - public ImageEditReplacePatchable withTimeout(long timeout, TimeUnit unit) { - return new ReplicationControllerOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), namespace, getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, timeout, unit); - } - - @Override - public ImageEditReplacePatchable withTimeoutInMillis(long timeoutInMillis) { - return new ReplicationControllerOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), namespace, getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, timeoutInMillis, TimeUnit.MILLISECONDS); - } - @Override ReplicationController withReplicas(int count) { return cascading(false).edit().editSpec().withReplicas(count).endSpec().done(); @@ -106,34 +88,6 @@ long getObservedGeneration(ReplicationController current) { && current.getStatus().getObservedGeneration() != null) ? current.getStatus().getObservedGeneration() : -1; } - @Override - public RollableScalableResource withName(String name) { - if (name == null || name.length() == 0) { - throw new IllegalArgumentException("Name must be provided."); - } - return new ReplicationControllerOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, rollingTimeout, rollingTimeUnit); - } - - @Override - public RollableScalableResource fromServer() { - return new ReplicationControllerOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), true, getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, rollingTimeout, rollingTimeUnit); - } - - @Override - public Watchable> withResourceVersion(String resourceVersion) { - return new ReplicationControllerOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), resourceVersion, isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, rollingTimeout, rollingTimeUnit); - } - - @Override - public EditReplacePatchDeletable cascading(boolean enabled) { - return new ReplicationControllerOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), enabled, getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, rollingTimeout, rollingTimeUnit); - } - - @Override - public ReplicationControllerOperationsImpl rolling() { - return new ReplicationControllerOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), true, rollingTimeout, rollingTimeUnit); - } - @Override public ReplicationController updateImage(String image) { ReplicationController oldRC = get(); @@ -157,5 +111,18 @@ public ReplicationController updateImage(String image) { return new ReplicationControllerRollingUpdater(client, config, namespace).rollUpdate(oldRC, newRCBuilder.build()); } + @Override + public TimeoutImageEditReplacePatchable rolling() { + return new ReplicaSetOperationsImpl(((RollingOperationContext)context).withRolling(true)); + } + @Override + public ImageEditReplacePatchable withTimeout(long timeout, TimeUnit unit) { + return new ReplicationControllerOperationsImpl(((RollingOperationContext)context).withRollingTimeout(unit.toMillis(timeout)).withRollingTimeUnit(TimeUnit.MILLISECONDS)); + } + + @Override + public ImageEditReplacePatchable withTimeoutInMillis(long timeoutInMillis) { + return new ReplicationControllerOperationsImpl(((RollingOperationContext)context).withRollingTimeout(timeoutInMillis)); + } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ReplicationControllerRollingUpdater.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ReplicationControllerRollingUpdater.java index ecc6ba5cc16..dc2d16f1de2 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ReplicationControllerRollingUpdater.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ReplicationControllerRollingUpdater.java @@ -82,6 +82,6 @@ protected ReplicationController setReplicas(ReplicationController obj, int repli @Override protected Operation> resources() { - return new ReplicationControllerOperationsImpl(client, config, namespace); + return new ReplicationControllerOperationsImpl(client, config); } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/RollableScalableResourceOperation.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/RollableScalableResourceOperation.java index 97bfa5e4451..bb373b42768 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/RollableScalableResourceOperation.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/RollableScalableResourceOperation.java @@ -19,19 +19,15 @@ import io.fabric8.kubernetes.api.model.Doneable; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.KubernetesResourceList; -import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.KubernetesClientException; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.RollableScalableResource; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; -import io.fabric8.kubernetes.client.utils.ApiVersionUtil; import io.fabric8.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; @@ -48,15 +44,15 @@ public abstract class RollableScalableResourceOperation labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields, Boolean rolling, long rollingTimeout, TimeUnit rollingTimeUnit) { - super(client, config, ApiVersionUtil.apiGroup(item, apiVersionGroup), ApiVersionUtil.apiVersion(item, apiVersionNumber), resourceT, namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); - this.rolling = rolling; - this.rollingTimeout = rollingTimeout; - this.rollingTimeUnit = rollingTimeUnit; + public RollableScalableResourceOperation(RollingOperationContext context) { + super(context); + this.rolling = context.getRolling(); + this.rollingTimeout = context.getRollingTimeout(); + this.rollingTimeUnit = context.getRollingTimeUnit(); reaper = new ScalableReaper(this); } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/RollingOperationContext.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/RollingOperationContext.java new file mode 100644 index 00000000000..3f105d28a15 --- /dev/null +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/RollingOperationContext.java @@ -0,0 +1,133 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * 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.fabric8.kubernetes.client.dsl.internal; + +import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; +import okhttp3.OkHttpClient; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +public class RollingOperationContext extends OperationContext { + + private boolean rolling; + private long rollingTimeout; + private TimeUnit rollingTimeUnit; + + public RollingOperationContext() { + } + + public RollingOperationContext(OkHttpClient client, Config config, String plural, String namespace, String name, String apiGroupName, String apiGroupVersion, boolean cascading, Object item, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields, String resourceVersion, boolean reloadingFromServer, long gracePeriodSeconds, boolean rolling, long rollingTimeout, TimeUnit rollingTimeUnit) { + super(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading, item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + this.rolling = rolling; + this.rollingTimeout = rollingTimeout; + this.rollingTimeUnit = rollingTimeUnit != null ? rollingTimeUnit : TimeUnit.MILLISECONDS; + } + + public Boolean getRolling() { + return rolling; + } + + public long getRollingTimeout() { + return rollingTimeout; + } + + public TimeUnit getRollingTimeUnit() { + return rollingTimeUnit; + } + + public RollingOperationContext withOkhttpClient(OkHttpClient client) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withConfig(Config config) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withPlural(String plural) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withNamespace(String namespace) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withName(String name) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withApiGroupName(String apiGroupName) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withApiGroupVersion(String apiGroupVersion) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + @Override + public RollingOperationContext withItem(Object item) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withCascading(boolean cascading) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withLabels(Map labels) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withLabelsIn(Map labelsIn) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withLabelsNot(Map labelsNot) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withLabelsNotIn(Map labelsNotIn) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withFields(Map fields) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withResourceVersion(String resourceVersion) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withReloadingFromServer(boolean reloadingFromServer) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withGracePeriodSeconds(long gracePeriodSeconds) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withRolling(boolean rolling) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withRollingTimeout(long rollingTimeout) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } + + public RollingOperationContext withRollingTimeUnit(TimeUnit rollingTimeUnit) { + return new RollingOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, rolling, rollingTimeout, rollingTimeUnit); + } +} diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/RollingUpdater.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/RollingUpdater.java index 418fda7fea6..247825f2432 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/RollingUpdater.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/RollingUpdater.java @@ -256,7 +256,7 @@ private String md5sum(HasMetadata obj) throws NoSuchAlgorithmException, JsonProc protected abstract Operation> resources(); protected Operation> pods() { - return new PodOperationsImpl(client, config, namespace); + return new PodOperationsImpl(client, config); } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ServiceOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ServiceOperationsImpl.java index 8fbeddb197f..c9243b2beed 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ServiceOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ServiceOperationsImpl.java @@ -26,6 +26,7 @@ import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.dsl.ServiceResource; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import io.fabric8.kubernetes.client.utils.URLUtils; import okhttp3.OkHttpClient; @@ -35,12 +36,20 @@ public class ServiceOperationsImpl extends HasMetadataOperation> implements ServiceResource { - public ServiceOperationsImpl(OkHttpClient client, Config config, String namespace) { - this(client, config, null, null, namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + public ServiceOperationsImpl(OkHttpClient client, Config config) { + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - public ServiceOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, Service item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, apiGroup, apiVersion, "services", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + public ServiceOperationsImpl(OperationContext context) { + super(context.withPlural("services")); + this.type = Service.class; + this.listType = ServiceList.class; + this.doneableType = DoneableService.class; + } + + @Override + public ServiceOperationsImpl newInstance(OperationContext context) { + return new ServiceOperationsImpl(context); } @Override @@ -80,7 +89,7 @@ public Service waitUntilReady(long amount, TimeUnit timeUnit) throws Interrupted // if awaiting existence took very long, let's give at least 10 seconds to awaiting readiness long remaining = Math.max(10_000, timeUnit.toMillis(amount) - alreadySpent); - EndpointsOperationsImpl endpointsOperation = new EndpointsOperationsImpl(client, config, apiGroupVersion, getNamespace(), getName(), isCascading(), null, null, isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); + EndpointsOperationsImpl endpointsOperation = new EndpointsOperationsImpl(context); endpointsOperation.waitUntilReady(remaining, TimeUnit.MILLISECONDS); return get(); diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StatefulSetOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StatefulSetOperationsImpl.java index c5caccd9fad..d7421effa38 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StatefulSetOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StatefulSetOperationsImpl.java @@ -23,44 +23,34 @@ import io.fabric8.kubernetes.api.model.apps.StatefulSetList; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.KubernetesClientException; -import io.fabric8.kubernetes.client.Watch; -import io.fabric8.kubernetes.client.Watcher; -import io.fabric8.kubernetes.client.dsl.EditReplacePatchDeletable; import io.fabric8.kubernetes.client.dsl.ImageEditReplacePatchable; import io.fabric8.kubernetes.client.dsl.RollableScalableResource; import io.fabric8.kubernetes.client.dsl.TimeoutImageEditReplacePatchable; -import io.fabric8.kubernetes.client.dsl.Watchable; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import java.util.Collections; -import java.util.Map; -import java.util.TreeMap; import java.util.concurrent.TimeUnit; public class StatefulSetOperationsImpl extends RollableScalableResourceOperation> implements TimeoutImageEditReplacePatchable { - - public StatefulSetOperationsImpl(OkHttpClient client, Config config, String namespace) { - this(client, config, "apps","v1", namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), false, config.getRollingTimeout(), TimeUnit.MILLISECONDS); - } - - public StatefulSetOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, StatefulSet item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - this(client, config, apiGroup, apiVersion, namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields, false, config.getRollingTimeout(), TimeUnit.MILLISECONDS); + public StatefulSetOperationsImpl(OkHttpClient client, Config config) { + this(new RollingOperationContext().withOkhttpClient(client).withConfig(config)); } - public StatefulSetOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, StatefulSet 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, "statefulsets", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields, rolling, rollingTimeout, rollingTimeUnit); - } - - @Override - public ImageEditReplacePatchable withTimeout(long timeout, TimeUnit unit) { - return new StatefulSetOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), namespace, getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, timeout, unit); + public StatefulSetOperationsImpl(RollingOperationContext context) { + super(context.withApiGroupName("apps") + .withApiGroupVersion("v1") + .withPlural("statefulsets")); + this.type = StatefulSet.class; + this.listType = StatefulSetList.class; + this.doneableType = DoneableStatefulSet.class; } @Override - public ImageEditReplacePatchable withTimeoutInMillis(long timeoutInMillis) { - return new StatefulSetOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), namespace, getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, timeoutInMillis, TimeUnit.MILLISECONDS); + public StatefulSetOperationsImpl newInstance(OperationContext context) { + return new StatefulSetOperationsImpl((RollingOperationContext) context); } @Override @@ -89,32 +79,10 @@ long getObservedGeneration(StatefulSet current) { ? current.getStatus().getObservedGeneration() : -1; } - @Override - public RollableScalableResource withName(String name) { - if (name == null || name.length() == 0) { - throw new IllegalArgumentException("Name must be provided."); - } - return new StatefulSetOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, rollingTimeout, rollingTimeUnit); - } - - @Override - public RollableScalableResource fromServer() { - return new StatefulSetOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), true, getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, rollingTimeout, rollingTimeUnit); - } - - @Override - public Watchable> withResourceVersion(String resourceVersion) { - return new StatefulSetOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), resourceVersion, isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, rollingTimeout, rollingTimeUnit); - } - - @Override - public EditReplacePatchDeletable cascading(boolean enabled) { - return new StatefulSetOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), enabled, getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), rolling, rollingTimeout, rollingTimeUnit); - } @Override public StatefulSetOperationsImpl rolling() { - return new StatefulSetOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), true, rollingTimeout, rollingTimeUnit); + return new StatefulSetOperationsImpl(((RollingOperationContext)context).withRolling(true)); } @Override @@ -141,4 +109,13 @@ public StatefulSet updateImage(String image) { return new StatefulSetRollingUpdater(client, config, namespace).rollUpdate(oldRC, newRCBuilder.build()); } + @Override + public ImageEditReplacePatchable withTimeout(long timeout, TimeUnit unit) { + return new StatefulSetOperationsImpl(((RollingOperationContext)context).withRollingTimeout(unit.toMillis(timeout)).withRollingTimeUnit(TimeUnit.MILLISECONDS)); + } + + @Override + public ImageEditReplacePatchable withTimeoutInMillis(long timeoutInMillis) { + return new StatefulSetOperationsImpl(((RollingOperationContext)context).withRollingTimeout(timeoutInMillis)); + } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StatefulSetRollingUpdater.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StatefulSetRollingUpdater.java index 44f55b41bd0..108b4d18f30 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StatefulSetRollingUpdater.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StatefulSetRollingUpdater.java @@ -110,6 +110,6 @@ protected StatefulSet setReplicas(StatefulSet obj, int replicas) { @Override protected Operation> resources() { - return new StatefulSetOperationsImpl(client, config, namespace); + return new StatefulSetOperationsImpl(client, config); } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StorageClassOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StorageClassOperationsImpl.java index ebc0eef7ef5..ed20788670c 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StorageClassOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StorageClassOperationsImpl.java @@ -21,18 +21,27 @@ import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; -import java.util.Map; -import java.util.TreeMap; - public class StorageClassOperationsImpl extends HasMetadataOperation> { + public StorageClassOperationsImpl(OkHttpClient client, Config config) { - this(client, config, "storage.k8s.io", "v1", null, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - public StorageClassOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, StorageClass item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, apiGroup, apiVersion, "storageclasses", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + public StorageClassOperationsImpl(OperationContext context) { + super(context.withApiGroupName("storage.k8s.io") + .withApiGroupVersion("v1") + .withPlural("storageclasses")); + this.type = StorageClass.class; + this.listType = StorageClassList.class; + this.doneableType = DoneableStorageClass.class; + } + + @Override + public StorageClassOperationsImpl newInstance(OperationContext context) { + return new StorageClassOperationsImpl(context); } @Override diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ValidatingWebhookConfigurationOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ValidatingWebhookConfigurationOperationsImpl.java index 82f6d51dc18..00e4fafaf33 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ValidatingWebhookConfigurationOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ValidatingWebhookConfigurationOperationsImpl.java @@ -19,6 +19,7 @@ import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import io.fabric8.kubernetes.client.utils.ApiVersionUtil; import okhttp3.OkHttpClient; @@ -34,26 +35,21 @@ public class ValidatingWebhookConfigurationOperationsImpl extends HasMetadataOperation> { - public ValidatingWebhookConfigurationOperationsImpl(OkHttpClient client, Config config, String namespace) { - this(client, config, "admissionregistration.k8s.io", "v1beta1", namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + public ValidatingWebhookConfigurationOperationsImpl(OkHttpClient client, Config config) { + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - public ValidatingWebhookConfigurationOperationsImpl(OkHttpClient client, Config config, String apiGroupVersion, String namespace, String name, Boolean cascading, ValidatingWebhookConfiguration item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, "admissionregistration.k8s.io", apiGroupVersion, "validatingwebhookconfigurations", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + public ValidatingWebhookConfigurationOperationsImpl(OperationContext context) { + super(context.withApiGroupName("admissionregistration.k8s.io") + .withApiGroupVersion("v1beta1") + .withPlural("validatingwebhookconfigurations")); + this.type = ValidatingWebhookConfiguration.class; + this.listType = ValidatingWebhookConfigurationList.class; + this.doneableType = DoneableValidatingWebhookConfiguration.class; } - - public ValidatingWebhookConfigurationOperationsImpl(OkHttpClient client, Config config, String apiGroupName, String apiGroupVersion, String namespace, String name, Boolean cascading, ValidatingWebhookConfiguration item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, apiGroupName, apiGroupVersion, "validatingwebhookconfigurations", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); - } - - @Override - public NonNamespaceOperation> inNamespace(String namespace) { - return new ValidatingWebhookConfigurationOperationsImpl(client, config, apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); - } - @Override - public Resource withName(String name) { - return new ValidatingWebhookConfigurationOperationsImpl(client, config, apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); + public ValidatingWebhookConfigurationOperationsImpl newInstance(OperationContext context) { + return new ValidatingWebhookConfigurationOperationsImpl(context); } @Override diff --git a/kubernetes-client/src/main/resources/resource-handler.vm b/kubernetes-client/src/main/resources/resource-handler.vm index 785f8f7dfb0..c475393c858 100644 --- a/kubernetes-client/src/main/resources/resource-handler.vm +++ b/kubernetes-client/src/main/resources/resource-handler.vm @@ -51,6 +51,7 @@ import io.fabric8.kubernetes.client.Watch; import io.fabric8.kubernetes.client.Watcher; import io.fabric8.kubernetes.client.dsl.internal.${model.name}OperationsImpl; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import ${model.fullyQualifiedName}; @@ -67,17 +68,17 @@ public class ${model.name}Handler implements ResourceHandler<${model.name}, ${mo @Override public ${model.name} create(OkHttpClient client, Config config, String namespace, ${model.name} item) { - return new ${model.name}OperationsImpl(client, config, "$apiGroup", "$apiVersion", namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).create(); + return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).create(); } @Override public ${model.name} replace(OkHttpClient client, Config config, String namespace, ${model.name} item) { - return new ${model.name}OperationsImpl(client, config, "$apiGroup", "$apiVersion", namespace, null, true, item, null, true, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).replace(item); + return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).replace(item); } @Override public ${model.name} reload(OkHttpClient client, Config config, String namespace, ${model.name} item) { - return new ${model.name}OperationsImpl(client, config, "$apiGroup", "$apiVersion", namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).fromServer().get(); + return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).fromServer().get(); } @Override @@ -87,26 +88,26 @@ public class ${model.name}Handler implements ResourceHandler<${model.name}, ${mo @Override public Boolean delete(OkHttpClient client, Config config, String namespace, ${model.name} item) { - return new ${model.name}OperationsImpl(client, config, "$apiGroup", "$apiVersion", namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).delete(item); + return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).delete(item); } @Override public Watch watch(OkHttpClient client, Config config, String namespace, ${model.name} item, Watcher<${model.name}> watcher) { - return new ${model.name}OperationsImpl(client, config, "$apiGroup", "$apiVersion", namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).watch(watcher); + return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).watch(watcher); } @Override public Watch watch(OkHttpClient client, Config config, String namespace, ${model.name} item, String resourceVersion, Watcher<${model.name}> watcher) { - return new ${model.name}OperationsImpl(client, config, "$apiGroup", "$apiVersion", namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).watch(resourceVersion, watcher); + return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).watch(resourceVersion, watcher); } @Override public ${model.name} waitUntilReady(OkHttpClient client, Config config, String namespace, ${model.name} item, long amount, TimeUnit timeUnit) throws InterruptedException { - return new ${model.name}OperationsImpl(client, config, "$apiGroup", "$apiVersion", namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).waitUntilReady(amount, timeUnit); + return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).waitUntilReady(amount, timeUnit); } @Override public ${model.name} waitUntilCondition(OkHttpClient client, Config config, String namespace, ${model.name} item, Predicate<${model.name}> condition, long amount, TimeUnit timeUnit) throws InterruptedException { - return new ${model.name}OperationsImpl(client, config, "$apiGroup", "$apiVersion", namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).waitUntilCondition(condition, amount, timeUnit); + return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).waitUntilCondition(condition, amount, timeUnit); } } diff --git a/kubernetes-client/src/main/resources/resource-operation.vm b/kubernetes-client/src/main/resources/resource-operation.vm index 79198c2f402..ad723e1106b 100644 --- a/kubernetes-client/src/main/resources/resource-operation.vm +++ b/kubernetes-client/src/main/resources/resource-operation.vm @@ -49,6 +49,7 @@ import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; import io.fabric8.kubernetes.client.utils.ApiVersionUtil; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; @@ -63,25 +64,20 @@ import java.util.TreeMap; public class ${model.name}OperationsImpl extends HasMetadataOperation<${model.name}, ${model.name}List, Doneable${model.name}, Resource<${model.name}, Doneable${model.name}>> { - public ${model.name}OperationsImpl(OkHttpClient client, Config config, String namespace) { - this(client, config, "$apiGroupName", "$apiGroupVersion", namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + public ${model.name}OperationsImpl(OkHttpClient client, Config config) { + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - public ${model.name}OperationsImpl(OkHttpClient client, Config config, String apiGroupVersion, String namespace, String name, Boolean cascading, ${model.name} item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, "$apiGroupName", apiGroupVersion, "#pluralize ($model.name.toLowerCase())", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + public ${model.name}OperationsImpl(OperationContext context) { + super(context.withApiGroupName("$apiGroupName") + .withApiGroupVersion("$apiGroupVersion") + .withPlural("#pluralize ($model.name.toLowerCase())")); + this.type = ${model.name}.class; + this.listType = ${model.name}List.class; + this.doneableType = Doneable${model.name}.class; } - public ${model.name}OperationsImpl(OkHttpClient client, Config config, String apiGroupName, String apiGroupVersion, String namespace, String name, Boolean cascading, ${model.name} item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, config, apiGroupName, apiGroupVersion, "#pluralize ($model.name.toLowerCase())", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); - } - - @Override - public NonNamespaceOperation<${model.name}, ${model.name}List, Doneable${model.name}, Resource<${model.name}, Doneable${model.name}>> inNamespace(String namespace) { - return new ${model.name}OperationsImpl(client, config, apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); - } - - @Override - public Resource<${model.name}, Doneable${model.name}> withName(String name) { - return new ${model.name}OperationsImpl(client, config, apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); + public ${model.name}OperationsImpl newInstance(OperationContext context) { + return new ${model.name}OperationsImpl(context); } } diff --git a/kubernetes-itests/src/test/java/io/fabric8/commons/DeleteEntity.java b/kubernetes-itests/src/test/java/io/fabric8/commons/DeleteEntity.java index 99dab60154a..e260ec4455e 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/commons/DeleteEntity.java +++ b/kubernetes-itests/src/test/java/io/fabric8/commons/DeleteEntity.java @@ -65,6 +65,18 @@ public Boolean call() { return this.client.apps().replicaSets().inNamespace(this.namespace).list().getItems().size() == 0; case "NetworkPolicy": return this.client.network().networkPolicies().inNamespace(this.namespace).list().getItems().size() == 0; + case "SecurityContextConstraints": + return ((OpenShiftClient)this.client).securityContextConstraints().withName(this.name).get() == null; + case "ClusterRoleBinding": + return this.client.rbac().clusterRoleBindings().withName(this.name).get() == null; + case "ClusterRole": + return this.client.rbac().clusterRoles().withName(this.name).get() == null; + case "RoleBinding": + return this.client.rbac().roleBindings().inNamespace(this.namespace).withName(this.name).get() == null; + case "Role": + return this.client.rbac().roles().inNamespace(this.namespace).withName(this.name).get() == null; + case "PodSecurityPolicy": + return this.client.extensions().podSecurityPolicies().withName(this.name).get() == null; default: return false; } diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/ClusterRoleBindingIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/ClusterRoleBindingIT.java index a13831a967c..55219f06864 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/ClusterRoleBindingIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/ClusterRoleBindingIT.java @@ -15,6 +15,7 @@ */ package io.fabric8.kubernetes; +import io.fabric8.commons.DeleteEntity; import io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding; import io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingBuilder; import io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingList; @@ -31,6 +32,9 @@ import org.junit.Test; import org.junit.runner.RunWith; +import java.util.concurrent.TimeUnit; + +import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -179,8 +183,11 @@ public void delete() { ClusterRoleBindingList clusterRoleBindingListBefore = client.rbac().clusterRoleBindings().list(); boolean deleted = client.rbac().clusterRoleBindings().withName("read-nodes").delete(); - assertTrue(deleted); + + DeleteEntity clusterRoleBindingDeleteEntity = new DeleteEntity<>(ClusterRoleBinding.class, client, "read-nodes", null); + await().atMost(30, TimeUnit.SECONDS).until(clusterRoleBindingDeleteEntity); + ClusterRoleBindingList clusterRoleBindingListAfter = client.rbac().clusterRoleBindings().list(); assertEquals(clusterRoleBindingListBefore.getItems().size()-1,clusterRoleBindingListAfter.getItems().size()); diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/ClusterRoleIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/ClusterRoleIT.java index 3b47b37d838..49ed4c4a3e0 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/ClusterRoleIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/ClusterRoleIT.java @@ -16,7 +16,9 @@ package io.fabric8.kubernetes; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import io.fabric8.commons.DeleteEntity; import io.fabric8.kubernetes.api.model.rbac.ClusterRole; import io.fabric8.kubernetes.api.model.rbac.ClusterRoleList; import io.fabric8.kubernetes.api.model.rbac.ClusterRoleBuilder; @@ -31,6 +33,7 @@ import org.junit.Test; import org.junit.After; +import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -202,8 +205,11 @@ public void delete() { ClusterRoleList clusterRoleListBefore = client.rbac().clusterRoles().list(); boolean deleted = client.rbac().clusterRoles().withName("node-reader").delete(); - assertTrue(deleted); + + DeleteEntity deleteEntity = new DeleteEntity<>(ClusterRole.class, client, "node-reader", null); + await().atMost(30, TimeUnit.SECONDS).until(deleteEntity); + ClusterRoleList clusterRoleListAfter = client.rbac().clusterRoles().list(); assertEquals(clusterRoleListBefore.getItems().size()-1,clusterRoleListAfter.getItems().size()); } @@ -211,6 +217,8 @@ public void delete() { @After public void cleanup() { client.rbac().clusterRoles().withName("node-reader").delete(); + DeleteEntity deleteEntity = new DeleteEntity<>(ClusterRole.class, client, "node-reader", null); + await().atMost(30, TimeUnit.SECONDS).until(deleteEntity); } } diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/NetworkPolicyIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/NetworkPolicyIT.java index 675a5700f28..4ea0876fdfa 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/NetworkPolicyIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/NetworkPolicyIT.java @@ -170,12 +170,16 @@ public void delete(){ boolean deleted = client.network().networkPolicies().delete(networkPolicy); assertTrue(deleted); + + DeleteEntity deleteEntity = new DeleteEntity<>(NetworkPolicy.class, client, "networkpolicy", currentNamespace); + await().atMost(30, TimeUnit.SECONDS).until(deleteEntity); + NetworkPolicyList networkPolicyList = client.network().networkPolicies().list(); assertEquals(0,networkPolicyList.getItems().size()); } @After - public void cleanup() throws InterruptedException { + public void cleanup() { if (client.network().networkPolicies().list().getItems().size()!= 0) { client.network().networkPolicies().delete(); } diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodSecurityPolicyIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodSecurityPolicyIT.java index d553227c1b8..ecd1e7cae65 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodSecurityPolicyIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodSecurityPolicyIT.java @@ -16,6 +16,7 @@ package io.fabric8.kubernetes; +import io.fabric8.commons.DeleteEntity; import io.fabric8.kubernetes.api.model.extensions.PodSecurityPolicy; import io.fabric8.kubernetes.api.model.extensions.PodSecurityPolicyBuilder; import io.fabric8.kubernetes.api.model.extensions.PodSecurityPolicyList; @@ -24,6 +25,8 @@ import org.arquillian.cube.kubernetes.impl.requirement.RequiresKubernetes; import org.arquillian.cube.requirement.ArquillianConditionalRunner; import org.jboss.arquillian.test.api.ArquillianResource; + +import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertFalse; @@ -34,6 +37,7 @@ import org.junit.runner.RunWith; import java.util.Collections; +import java.util.concurrent.TimeUnit; @RunWith(ArquillianConditionalRunner.class) @RequiresKubernetes @@ -124,6 +128,9 @@ public void update(){ public void delete(){ boolean deleted = client.extensions().podSecurityPolicies().delete(podSecurityPolicy); assertTrue(deleted); + + DeleteEntity deleteEntity = new DeleteEntity<>(PodSecurityPolicy.class, client, "test-example", null); + await().atMost(30, TimeUnit.SECONDS).until(deleteEntity); PodSecurityPolicyList podSecurityPolicyList = client.extensions().podSecurityPolicies().list(); assertEquals(0,podSecurityPolicyList.getItems().size()); } @@ -131,5 +138,7 @@ public void delete(){ @After public void cleanup() { client.extensions().podSecurityPolicies().withName("test-example").delete(); + DeleteEntity deleteEntity = new DeleteEntity<>(PodSecurityPolicy.class, client, "test-example", null); + await().atMost(30, TimeUnit.SECONDS).until(deleteEntity); } } diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/RoleBindingIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/RoleBindingIT.java index e4b4a2d73b1..2adae97f1e1 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/RoleBindingIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/RoleBindingIT.java @@ -15,6 +15,7 @@ */ package io.fabric8.kubernetes; +import io.fabric8.commons.DeleteEntity; import io.fabric8.kubernetes.api.model.rbac.RoleBinding; import io.fabric8.kubernetes.api.model.rbac.RoleBindingList; import io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder; @@ -31,7 +32,9 @@ import org.junit.runner.RunWith; import java.util.Collections; +import java.util.concurrent.TimeUnit; +import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -170,11 +173,16 @@ public void update() { @Test public void delete() { - boolean deleted = client.rbac().roleBindings().inNamespace(currentNamespace).delete(); + Integer initialCountBeforeDeletion = client.rbac().roleBindings().inNamespace(currentNamespace).list().getItems().size(); + boolean deleted = client.rbac().roleBindings().inNamespace(currentNamespace).withName("read-jobs").delete(); assertTrue(deleted); + + DeleteEntity deleteEntity = new DeleteEntity<>(RoleBinding.class, client, "read-jobs", currentNamespace); + await().atMost(30, TimeUnit.SECONDS).until(deleteEntity); + RoleBindingList roleBindingList = client.rbac().roleBindings().inNamespace(currentNamespace).list(); - assertEquals(0,roleBindingList.getItems().size()); + assertEquals(initialCountBeforeDeletion - 1,roleBindingList.getItems().size()); } @After diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/RoleIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/RoleIT.java index 2c65d8f2e82..193d858a244 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/RoleIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/RoleIT.java @@ -15,6 +15,7 @@ */ package io.fabric8.kubernetes; +import io.fabric8.commons.DeleteEntity; import io.fabric8.kubernetes.api.model.rbac.Role; import io.fabric8.kubernetes.api.model.rbac.RoleList; import io.fabric8.kubernetes.api.model.rbac.RoleBuilder; @@ -29,6 +30,9 @@ import org.junit.Test; import org.junit.After; +import java.util.concurrent.TimeUnit; + +import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -196,11 +200,16 @@ public void update() { @Test public void delete() { + Integer countBeforeDeletion = client.rbac().roles().inNamespace(currentNamespace).list().getItems().size(); boolean deleted = client.rbac().roles().inNamespace(currentNamespace).delete(); assertTrue(deleted); + + DeleteEntity deleteEntity = new DeleteEntity<>(Role.class, client, "job-reader", currentNamespace); + await().atMost(30, TimeUnit.SECONDS).until(deleteEntity); + RoleList roleList = client.rbac().roles().inNamespace(currentNamespace).list(); - assertEquals(0,roleList.getItems().size()); + assertEquals(countBeforeDeletion - 1,roleList.getItems().size()); } @After diff --git a/kubernetes-itests/src/test/java/io/fabric8/openshift/SecurityContextConstraintsIT.java b/kubernetes-itests/src/test/java/io/fabric8/openshift/SecurityContextConstraintsIT.java index cee0f4834ac..bd6ca22ede5 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/openshift/SecurityContextConstraintsIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/openshift/SecurityContextConstraintsIT.java @@ -16,6 +16,7 @@ package io.fabric8.openshift; +import io.fabric8.commons.DeleteEntity; import io.fabric8.openshift.api.model.SecurityContextConstraints; import io.fabric8.openshift.api.model.SecurityContextConstraintsBuilder; import io.fabric8.openshift.api.model.SecurityContextConstraintsList; @@ -29,7 +30,9 @@ import org.junit.runner.RunWith; import java.util.Collections; +import java.util.concurrent.TimeUnit; +import static org.awaitility.Awaitility.await; import static org.junit.Assert.*; @RunWith(ArquillianConditionalRunner.class) @@ -152,11 +155,14 @@ public void delete(){ assertFalse(sccList.getItems().contains(scc)); } - @After public void cleanup() { + if (client.securityContextConstraints().list().getItems().size()!= 0) { + client.securityContextConstraints().withName("test-scc").delete(); + } - client.securityContextConstraints().withName("test-scc").delete(); + DeleteEntity sccDelete = new DeleteEntity<>(SecurityContextConstraints.class, client, "test-scc", null); + await().atMost(30, TimeUnit.SECONDS).until(sccDelete); } } diff --git a/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesServer.java b/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesServer.java index 1d4f8b5799c..a21d2d58d0c 100644 --- a/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesServer.java +++ b/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesServer.java @@ -22,6 +22,7 @@ import io.fabric8.mockwebserver.crud.CrudDispatcher; import io.fabric8.mockwebserver.dsl.MockServerExpectation; import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; import org.junit.rules.ExternalResource; import java.util.HashMap; @@ -91,4 +92,13 @@ public void expectAndReturnAsString(String method, String path, int code, String public MockWebServer getMockServer() { return mock.getServer(); } + + public RecordedRequest getLastRequest() throws InterruptedException { + int count = mock.getServer().getRequestCount(); + RecordedRequest request = null; + while (count-- > 0) { + request = mock.getServer().takeRequest(); + } + return request; + } } diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CreateOrReplaceResourceTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CreateOrReplaceResourceTest.java index a45640c8195..fa9afcdd764 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CreateOrReplaceResourceTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CreateOrReplaceResourceTest.java @@ -26,6 +26,7 @@ import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.server.mock.KubernetesServer; import okhttp3.mockwebserver.RecordedRequest; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; @@ -35,6 +36,7 @@ import static org.junit.Assert.assertNotNull; public class CreateOrReplaceResourceTest { + @Rule public KubernetesServer server = new KubernetesServer(); @@ -47,13 +49,9 @@ public void testResourceReplace() throws Exception { .withNewMetadata().withResourceVersion("12345").and().build()).once(); KubernetesClient client = server.getClient(); - assertNotNull(client.resource(new PodBuilder().withNewMetadata().withName("pod123").and().withNewSpec().and().build()).createOrReplace()); - - server.getMockServer().takeRequest(); - server.getMockServer().takeRequest(); - RecordedRequest request = server.getMockServer().takeRequest(); - Pod requestPod = new ObjectMapper().readerFor(Pod.class).readValue(request.getBody().inputStream()); - assertEquals("12345", requestPod.getMetadata().getResourceVersion()); + Pod pod = client.resource(new PodBuilder().withNewMetadata().withName("pod123").and().withNewSpec().and().build()).createOrReplace(); + assertNotNull(pod); + assertEquals("12345", pod.getMetadata().getResourceVersion()); } @Test @@ -131,11 +129,8 @@ public void testResourceReplaceFromLoad() throws Exception { Pod pod = (Pod) result.get(0); assertEquals("12345", pod.getMetadata().getResourceVersion()); - RecordedRequest request = server.getMockServer().takeRequest(); + RecordedRequest request = server.getLastRequest(); assertEquals("/api/v1/namespaces/test/pods/nginx", request.getPath()); - server.getMockServer().takeRequest(); - - request = server.getMockServer().takeRequest(); Pod requestPod = new ObjectMapper().readerFor(Pod.class).readValue(request.getBody().inputStream()); assertEquals("nginx", requestPod.getMetadata().getName()); } @@ -152,10 +147,7 @@ public void testCreateFromLoad() throws Exception { assertNotNull(pod); assertEquals("12345", pod.getMetadata().getResourceVersion()); - RecordedRequest request = server.getMockServer().takeRequest(); - assertEquals("/api/v1/namespaces/test/pods/nginx", request.getPath()); - - request = server.getMockServer().takeRequest(); + RecordedRequest request = server.getLastRequest(); Pod requestPod = new ObjectMapper().readerFor(Pod.class).readValue(request.getBody().inputStream()); assertEquals("nginx", requestPod.getMetadata().getName()); } @@ -172,10 +164,9 @@ public void testReplaceFromLoad() throws Exception { assertNotNull(pod); assertEquals("12345", pod.getMetadata().getResourceVersion()); - RecordedRequest request = server.getMockServer().takeRequest(); - assertEquals("/api/v1/namespaces/test/pods/nginx", request.getPath()); - request = server.getMockServer().takeRequest(); + RecordedRequest request = server.getLastRequest(); + assertEquals("/api/v1/namespaces/test/pods/nginx", request.getPath()); Pod requestPod = new ObjectMapper().readerFor(Pod.class).readValue(request.getBody().inputStream()); assertEquals("nginx", requestPod.getMetadata().getName()); } @@ -194,8 +185,7 @@ public void testReplaceWithoutLock() throws Exception { assertNotNull(map); assertEquals("1001", map.getMetadata().getResourceVersion()); - server.getMockServer().takeRequest(); // ignore the first request - RecordedRequest request = server.getMockServer().takeRequest(); + RecordedRequest request = server.getLastRequest(); ConfigMap replacedMap = new ObjectMapper().readerFor(ConfigMap.class).readValue(request.getBody().inputStream()); assertEquals("1000", replacedMap.getMetadata().getResourceVersion()); } @@ -212,7 +202,7 @@ public void testReplaceWithLock() throws Exception { assertNotNull(map); assertEquals("1001", map.getMetadata().getResourceVersion()); - RecordedRequest request = server.getMockServer().takeRequest(); + RecordedRequest request = server.getLastRequest(); ConfigMap replacedMap = new ObjectMapper().readerFor(ConfigMap.class).readValue(request.getBody().inputStream()); assertEquals("900", replacedMap.getMetadata().getResourceVersion()); } diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CronJobTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CronJobTest.java index bd9de7f4747..19775bf9e24 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CronJobTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CronJobTest.java @@ -228,7 +228,7 @@ public void testDeleteWithNamespaceMismatch() { KubernetesClient client = server.getClient(); Boolean deleted = client.batch().cronjobs().inNamespace("test1").delete(cronjob1); - assertNotNull(deleted); + assertFalse(deleted); } @Test(expected = KubernetesClientException.class) diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/DeploymentTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/DeploymentTest.java index deea4c669ac..62e41b808e8 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/DeploymentTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/DeploymentTest.java @@ -268,7 +268,7 @@ public void testDeleteWithNamespaceMismatch() { KubernetesClient client = server.getClient(); Boolean deleted = client.apps().deployments().inNamespace("test1").delete(deployment1); - assertNotNull(deleted); + assertFalse(deleted); } @Test(expected = KubernetesClientException.class) diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/JobTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/JobTest.java index 6dbcd47b272..f601e899301 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/JobTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/JobTest.java @@ -218,7 +218,6 @@ public void testDeleteMulti() { @Test(expected = KubernetesClientException.class) public void testDeleteWithNamespaceMismatch() { Job job1 = new JobBuilder().withNewMetadata().withName("job1").withNamespace("test").and().build(); - Job job2 = new JobBuilder().withNewMetadata().withName("job2").withNamespace("ns1").and().build(); KubernetesClient client = server.getClient(); Boolean deleted = client.batch().jobs().inNamespace("test1").delete(job1); diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/KubernetesListTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/KubernetesListTest.java index a817e4ac0ca..ade176117fb 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/KubernetesListTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/KubernetesListTest.java @@ -33,6 +33,7 @@ import java.io.InputStream; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -102,6 +103,6 @@ public void testDeleteWithMismatch() { KubernetesClient client = server.getClient(); Boolean result = client.lists().inNamespace("test1").delete(list); - assertTrue(result); + assertFalse(result); } } diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PodDisruptionBudgetTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PodDisruptionBudgetTest.java index aa54fba3424..645bd44b5b4 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PodDisruptionBudgetTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PodDisruptionBudgetTest.java @@ -31,6 +31,7 @@ import static junit.framework.TestCase.assertNotNull; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -136,7 +137,7 @@ public void testDeleteWithNamespaceMismatch() { KubernetesClient client = server.getClient(); Boolean deleted = client.policy().podDisruptionBudget().inNamespace("test1").delete(podDisruptionBudget1); - assertNotNull(deleted); + assertFalse(deleted); } @Test(expected = KubernetesClientException.class) diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PodTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PodTest.java index 0d02cc8636c..8b4cae25c86 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PodTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PodTest.java @@ -172,7 +172,7 @@ public void testDeleteWithNamespaceMismatch() { KubernetesClient client = server.getClient(); Boolean deleted = client.pods().inNamespace("test1").delete(pod1); - assertNotNull(deleted); + assertFalse(deleted); } @Test(expected = KubernetesClientException.class) diff --git a/kubernetes-tests/src/test/java/io/fabric8/openshift/client/server/mock/OpenshiftRoleBindingTest.java b/kubernetes-tests/src/test/java/io/fabric8/openshift/client/server/mock/OpenshiftRoleBindingTest.java index 79c7d3fe006..b062abd2ef9 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/openshift/client/server/mock/OpenshiftRoleBindingTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/openshift/client/server/mock/OpenshiftRoleBindingTest.java @@ -56,8 +56,8 @@ public void testCreateWithOnlySubjects() throws Exception { ); assertEquals(expectedOpenshiftRoleBinding, response); - RecordedRequest request = server.getMockServer().takeRequest(); - assertEquals(expectedOpenshiftRoleBinding, new ObjectMapper().readerFor(OpenshiftRoleBinding.class).readValue(request.getBody().inputStream())); + RecordedRequest request = server.getLastRequest(); + assertEquals(expectedOpenshiftRoleBinding, new ObjectMapper().readerFor(OpenshiftRoleBinding.class).readValue(request.getBody().readByteArray())); } @Test @@ -75,7 +75,7 @@ public void testCreateWithUserNamesAndGroupsAndNoSubjects() throws Exception { ); assertEquals(expectedOpenshiftRoleBinding, response); - RecordedRequest request = server.getMockServer().takeRequest(); + RecordedRequest request = server.getLastRequest(); assertEquals(expectedOpenshiftRoleBinding, new ObjectMapper().readerFor(OpenshiftRoleBinding.class).readValue(request.getBody().inputStream())); } @@ -95,7 +95,7 @@ public void testCreateWithUserNamesAndGroupsAndOverwriteSubjects() throws Except ); assertEquals(expectedOpenshiftRoleBinding, response); - RecordedRequest request = server.getMockServer().takeRequest(); + RecordedRequest request = server.getLastRequest(); assertEquals(expectedOpenshiftRoleBinding, new ObjectMapper().readerFor(OpenshiftRoleBinding.class).readValue(request.getBody().inputStream())); } @@ -117,9 +117,7 @@ public void testReplaceWithOnlySubjects() throws Exception { ); assertEquals(expectedOpenshiftRoleBinding, response); - // Initial GET - server.getMockServer().takeRequest(); - RecordedRequest request = server.getMockServer().takeRequest(); + RecordedRequest request = server.getLastRequest(); assertEquals(expectedOpenshiftRoleBinding, new ObjectMapper().readerFor(OpenshiftRoleBinding.class).readValue(request.getBody().inputStream())); } @@ -139,9 +137,8 @@ public void testReplaceWithUserNamesAndGroupsAndNoSubjects() throws Exception { ); assertEquals(expectedOpenshiftRoleBinding, response); - // Initial GET - server.getMockServer().takeRequest(); - RecordedRequest request = server.getMockServer().takeRequest(); + + RecordedRequest request = server.getLastRequest(); assertEquals(expectedOpenshiftRoleBinding, new ObjectMapper().readerFor(OpenshiftRoleBinding.class).readValue(request.getBody().inputStream())); } @@ -162,9 +159,7 @@ public void testReplaceWithUserNamesAndGroupsAndOverwriteSubjects() throws Excep ); assertEquals(expectedOpenshiftRoleBinding, response); - // Initial GET - server.getMockServer().takeRequest(); - RecordedRequest request = server.getMockServer().takeRequest(); + RecordedRequest request = server.getLastRequest(); assertEquals(expectedOpenshiftRoleBinding, new ObjectMapper().readerFor(OpenshiftRoleBinding.class).readValue(request.getBody().inputStream())); } @@ -186,9 +181,7 @@ public void testPatchWithOnlySubjects() throws Exception { ); assertEquals(expectedOpenshiftRoleBinding, response); - // Initial GET - server.getMockServer().takeRequest(); - RecordedRequest request = server.getMockServer().takeRequest(); + RecordedRequest request = server.getLastRequest(); assertEquals( "[{\"op\":\"replace\",\"path\":\"/userNames/0\",\"value\":\"testuser1\"},{\"op\":\"add\",\"path\":\"/userNames/1\",\"value\":\"testuser2\"},{\"op\":\"add\",\"path\":\"/userNames/2\",\"value\":\"system:serviceaccount:test:svcacct\"},{\"op\":\"add\",\"path\":\"/metadata\",\"value\":{}},{\"op\":\"add\",\"path\":\"/groupNames\",\"value\":[\"testgroup\"]},{\"op\":\"add\",\"path\":\"/subjects\",\"value\":[{\"kind\":\"User\",\"name\":\"testuser1\"},{\"kind\":\"User\",\"name\":\"testuser2\"},{\"kind\":\"ServiceAccount\",\"name\":\"svcacct\",\"namespace\":\"test\"},{\"kind\":\"Group\",\"name\":\"testgroup\"}]}]", request.getBody().readUtf8() @@ -211,9 +204,7 @@ public void testPatchWithUserNamesAndGroupsAndNoSubjects() throws Exception { ); assertEquals(expectedOpenshiftRoleBinding, response); - // Initial GET - server.getMockServer().takeRequest(); - RecordedRequest request = server.getMockServer().takeRequest(); + RecordedRequest request = server.getLastRequest(); assertEquals( "[{\"op\":\"replace\",\"path\":\"/userNames/0\",\"value\":\"testuser1\"},{\"op\":\"add\",\"path\":\"/userNames/1\",\"value\":\"testuser2\"},{\"op\":\"add\",\"path\":\"/userNames/2\",\"value\":\"system:serviceaccount:test:svcacct\"},{\"op\":\"add\",\"path\":\"/metadata\",\"value\":{}},{\"op\":\"add\",\"path\":\"/groupNames\",\"value\":[\"testgroup\"]},{\"op\":\"add\",\"path\":\"/subjects\",\"value\":[{\"kind\":\"User\",\"name\":\"testuser1\"},{\"kind\":\"User\",\"name\":\"testuser2\"},{\"kind\":\"ServiceAccount\",\"name\":\"svcacct\",\"namespace\":\"test\"},{\"kind\":\"Group\",\"name\":\"testgroup\"}]}]", request.getBody().readUtf8() @@ -237,9 +228,7 @@ public void testPatchWithUserNamesAndGroupsAndOverwriteSubjects() throws Excepti ); assertEquals(expectedOpenshiftRoleBinding, response); - // Initial GET - server.getMockServer().takeRequest(); - RecordedRequest request = server.getMockServer().takeRequest(); + RecordedRequest request = server.getLastRequest(); assertEquals( "[{\"op\":\"replace\",\"path\":\"/userNames/0\",\"value\":\"testuser1\"},{\"op\":\"add\",\"path\":\"/userNames/1\",\"value\":\"testuser2\"},{\"op\":\"add\",\"path\":\"/userNames/2\",\"value\":\"system:serviceaccount:test:svcacct\"},{\"op\":\"add\",\"path\":\"/metadata\",\"value\":{}},{\"op\":\"add\",\"path\":\"/groupNames\",\"value\":[\"testgroup\"]},{\"op\":\"add\",\"path\":\"/subjects\",\"value\":[{\"kind\":\"User\",\"name\":\"testuser1\"},{\"kind\":\"User\",\"name\":\"testuser2\"},{\"kind\":\"ServiceAccount\",\"name\":\"svcacct\",\"namespace\":\"test\"},{\"kind\":\"Group\",\"name\":\"testgroup\"}]}]", request.getBody().readUtf8() @@ -261,7 +250,7 @@ public void testCreateInline() throws Exception { .done(); assertEquals(expectedOpenshiftRoleBinding, response); - RecordedRequest request = server.getMockServer().takeRequest(); + RecordedRequest request = server.getLastRequest(); assertEquals(expectedOpenshiftRoleBinding, new ObjectMapper().readerFor(OpenshiftRoleBinding.class).readValue(request.getBody().inputStream())); } diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/DefaultOpenShiftClient.java b/openshift-client/src/main/java/io/fabric8/openshift/client/DefaultOpenShiftClient.java index 022d4f00db0..6352395f222 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/DefaultOpenShiftClient.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/DefaultOpenShiftClient.java @@ -28,6 +28,8 @@ import io.fabric8.kubernetes.api.model.DoneablePod; import io.fabric8.kubernetes.api.model.DoneableReplicationController; import io.fabric8.kubernetes.api.model.DoneableResourceQuota; +import io.fabric8.kubernetes.api.model.DoneableSecret; +import io.fabric8.kubernetes.api.model.DoneableService; import io.fabric8.kubernetes.api.model.DoneableServiceAccount; import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition; import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinitionList; @@ -52,6 +54,7 @@ import io.fabric8.openshift.api.model.DoneableOpenshiftClusterRoleBinding; import io.fabric8.openshift.api.model.DoneableOpenshiftRole; import io.fabric8.openshift.api.model.DoneableOpenshiftRoleBinding; +import io.fabric8.openshift.api.model.DoneableProject; import io.fabric8.openshift.api.model.DoneableRoute; import io.fabric8.openshift.api.model.DoneableSecurityContextConstraints; import io.fabric8.openshift.api.model.DoneableTemplate; @@ -133,7 +136,7 @@ public URL getOpenshiftUrl() { @Override public MixedOperation> componentstatuses() { - return new ComponentStatusOperationsImpl(httpClient, getConfiguration(), null); + return new ComponentStatusOperationsImpl(httpClient, getConfiguration()); } @Override @@ -248,7 +251,7 @@ public MixedOperation> MixedOperation> customResources(CustomResourceDefinition crd, Class resourceType, Class listClass, Class doneClass) { - return new CustomResourceOperationsImpl(httpClient, getConfiguration(), crd, resourceType, listClass, doneClass); + return new CustomResourceOperationsImpl(new CustomResourceOperationContext().withOkhttpClient(httpClient).withConfig(getConfiguration()).withCrd(crd).withType(resourceType).withListType(listClass).withDoneableType(doneClass)); } @Override @@ -263,32 +266,32 @@ public NonNamespaceOperation> builds() { - return new BuildOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration()), getNamespace()); + return new BuildOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration())); } @Override public MixedOperation> buildConfigs() { - return new BuildConfigOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration()), getNamespace()); + return new BuildConfigOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration())); } @Override public MixedOperation> deploymentConfigs() { - return new DeploymentConfigOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration()), getNamespace()); + return new DeploymentConfigOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration())); } @Override public MixedOperation> groups() { - return new GroupOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration()), getNamespace()); + return new GroupOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration())); } @Override public MixedOperation> imageStreams() { - return new ImageStreamOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration()), getNamespace()); + return new ImageStreamOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration())); } @Override public MixedOperation> imageStreamTags() { - return new ImageStreamTagOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration()), getNamespace()); + return new ImageStreamTagOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration())); } @Override @@ -323,37 +326,37 @@ public ProjectRequestOperation projectrequests() { @Override public MixedOperation> roles() { - return new OpenshiftRoleOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration()), getNamespace()); + return new OpenshiftRoleOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration())); } @Override public MixedOperation> roleBindings() { - return new OpenshiftRoleBindingOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration()), getNamespace()); + return new OpenshiftRoleBindingOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration())); } @Override public MixedOperation> routes() { - return new RouteOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration()), getNamespace()); + return new RouteOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration())); } @Override public ParameterMixedOperation> templates() { - return new TemplateOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration()), getNamespace()); + return new TemplateOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration())); } @Override public MixedOperation> users() { - return new UserOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration()), getNamespace()); + return new UserOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration())); } @Override public SubjectAccessReviewOperation subjectAccessReviews() { - return new SubjectAccessReviewOperationImpl(httpClient, OpenShiftConfig.wrap(getConfiguration()), null, getNamespace()); + return new SubjectAccessReviewOperationImpl(httpClient, OpenShiftConfig.wrap(getConfiguration())); } @Override public MixedOperation> clusterRoleBindings() { - return new OpenshiftClusterRoleBindingOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration()), getNamespace()); + return new OpenshiftClusterRoleBindingOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration())); } @Override diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/BuildConfigOperationContext.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/BuildConfigOperationContext.java new file mode 100644 index 00000000000..0f94d3ce4d5 --- /dev/null +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/BuildConfigOperationContext.java @@ -0,0 +1,217 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * 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.fabric8.openshift.client.dsl.internal; + +import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; +import io.fabric8.openshift.client.OpenShiftConfig; +import okhttp3.OkHttpClient; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +public class BuildConfigOperationContext extends OperationContext { + + private String secret; + private String triggerType; + + private String authorName; + private String authorEmail; + private String committerName; + private String committerEmail; + private String commit; + private String message; + private String asFile; + + private long timeout; + private TimeUnit timeoutUnit; + + public BuildConfigOperationContext() { + } + + public BuildConfigOperationContext(OkHttpClient client, Config config, String plural, String namespace, String name, String apiGroupName, String apiGroupVersion, boolean cascading, Object item, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields, String resourceVersion, boolean reloadingFromServer, long gracePeriodSeconds, String secret, String triggerType, String authorName, String authorEmail, String committerName, String committerEmail, String commit, String message, String asFile, Long timeout, TimeUnit timeUnit) { + super(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading, item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + this.secret = secret; + this.triggerType = triggerType; + this.authorName = authorName; + this.authorEmail = authorEmail; + this.committerName = committerName; + this.committerEmail = committerEmail; + this.commit = commit; + this.message = message; + this.asFile = asFile; + this.timeout = timeout; + this.timeoutUnit = timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS; + } + + public String getSecret() { + return secret; + } + + public String getTriggerType() { + return triggerType; + } + + public String getAuthorName() { + return authorName; + } + + public String getAuthorEmail() { + return authorEmail; + } + + public String getCommitterName() { + return committerName; + } + + public String getCommitterEmail() { + return committerEmail; + } + + public String getCommit() { + return commit; + } + + public String getMessage() { + return message; + } + + public String getAsFile() { + return asFile; + } + + public long getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutUnit() { + return timeoutUnit; + } + + public BuildConfigOperationContext withOkhttpClient(OkHttpClient client) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withConfig(Config config) { + return new BuildConfigOperationContext(client, OpenShiftConfig.wrap(config), plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withPlural(String plural) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withNamespace(String namespace) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withName(String name) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + + public BuildConfigOperationContext withApiGroupName(String apiGroupName) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withApiGroupVersion(String apiGroupVersion) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + @Override + public BuildConfigOperationContext withItem(Object item) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withCascading(boolean cascading) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withLabels(Map labels) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withLabelsIn(Map labelsIn) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withLabelsNot(Map labelsNot) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withLabelsNotIn(Map labelsNotIn) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withFields(Map fields) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withResourceVersion(String resourceVersion) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withReloadingFromServer(boolean reloadingFromServer) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withGracePeriodSeconds(long gracePeriodSeconds) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withSecret(String secret) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withTriggerType(String triggerType) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withAuthorName(String authorName) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withAuthorEmail(String authorEmail) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withCommitterName(String committerName) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withCommitterEmail(String committerEmail) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withCommit(String commit) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withMessage(String message) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withAsFile(String asFile) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withTimeout(long timeout) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } + + public BuildConfigOperationContext withTimeoutUnit(TimeUnit timeoutUnit) { + return new BuildConfigOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + } +} diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/BuildConfigOperationsImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/BuildConfigOperationsImpl.java index 8950929f18d..aafe2dd8e10 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/BuildConfigOperationsImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/BuildConfigOperationsImpl.java @@ -24,6 +24,7 @@ import io.fabric8.kubernetes.client.dsl.Typeable; import io.fabric8.kubernetes.client.dsl.Watchable; import io.fabric8.kubernetes.client.dsl.base.BaseOperation; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import io.fabric8.kubernetes.client.utils.URLUtils; import io.fabric8.kubernetes.client.utils.Utils; import io.fabric8.openshift.api.model.Build; @@ -64,6 +65,7 @@ import java.util.concurrent.TimeUnit; import static io.fabric8.openshift.client.OpenShiftAPIGroups.BUILD; +import static io.fabric8.openshift.client.OpenShiftAPIGroups.USER; public class BuildConfigOperationsImpl extends OpenShiftOperation> @@ -86,56 +88,40 @@ public class BuildConfigOperationsImpl extends OpenShiftOperation(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), null, null, null, null, null, null, null, null, null, config.getBuildTimeout(), TimeUnit.MILLISECONDS); + public BuildConfigOperationsImpl(OkHttpClient client, OpenShiftConfig config) { + this(new BuildConfigOperationContext().withOkhttpClient(client).withConfig(config)); } - public BuildConfigOperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, BuildConfig item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - this(client, config, apiGroup, apiVersion, namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields, null, null, null, null, null, null, null, null, null, config.getBuildTimeout(), TimeUnit.MILLISECONDS); - } + public BuildConfigOperationsImpl(BuildConfigOperationContext context) { + super(context.withApiGroupName(BUILD) + .withPlural("buildconfigs")); + + this.type = BuildConfig.class; + this.listType = BuildConfigList.class; + this.doneableType = DoneableBuildConfig.class; + + this.triggerType = context.getTriggerType(); + this.secret = context.getSecret(); + this.authorName = context.getAuthorName(); + this.authorEmail = context.getAuthorEmail() ; + this.committerName = context.getCommitterName(); + this.committerEmail = context.getCommitterEmail(); + this.commit = context.getCommit(); + this.message = context.getMessage(); + this.asFile = context.getAsFile(); + this.timeout = context.getTimeout(); + this.timeoutUnit = context.getTimeoutUnit(); - public BuildConfigOperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, BuildConfig item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields, String secret, String triggerType, String authorName, String authorEmail, String committerName, String committerEmail, String commit, String message, String asFile, long timeout, TimeUnit timeoutUnit) { - super(client, OpenShiftOperation.withApiGroup(client, apiGroup, apiVersion, config), "buildconfigs", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); - this.triggerType = triggerType; - this.secret = secret; - this.authorName = authorName; - this.authorEmail = authorEmail; - this.committerName = committerName; - this.committerEmail = committerEmail; - this.commit = commit; - this.message = message; - this.asFile = asFile; reaper = new BuildConfigReaper(this); - this.timeout = timeout; - this.timeoutUnit = timeoutUnit; - } - - @Override - public BuildConfigResource withName(String name) { - if (name == null || name.length() == 0) { - throw new IllegalArgumentException("Name must be provided."); - } - return new BuildConfigOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); - } - - @Override - public OpenShiftOperation> inNamespace(String namespace) { - return new BuildConfigOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), namespace, getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); - } - - @Override - public Gettable fromServer() { - return new BuildConfigOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), namespace, getName(), isCascading(), getItem(), getResourceVersion(), true, getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); } @Override - public Typeable> withSecret(String secret) { - return new BuildConfigOperationsImpl(client,getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + public BuildConfigOperationsImpl newInstance(OperationContext context) { + return new BuildConfigOperationsImpl((BuildConfigOperationContext) context); } - @Override - public BuildConfigResource load(InputStream is) { - return new BuildConfigOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), unmarshal(is, getType()), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + public BuildConfigOperationContext getContext() { + return (BuildConfigOperationContext) context; } @Override @@ -153,7 +139,7 @@ public Build instantiate(BuildRequest request) { @Override public CommitterAuthorMessageAsFileTimeoutInputStreamable instantiateBinary() { - return new BuildConfigOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + return new BuildConfigOperationsImpl(getContext()); } @@ -175,15 +161,13 @@ public Void trigger(WebHookTrigger trigger) { } @Override - public Triggerable withType(String type) { - return new BuildConfigOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), secret, type, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + public Triggerable withType(String triggerType) { + return new BuildConfigOperationsImpl(getContext().withTriggerType(triggerType)); } @Override public Watchable> withResourceVersion(String resourceVersion) { - BuildConfigOperationsImpl buildConfigOperations = new BuildConfigOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), namespace, getName(), isCascading(), getItem(), resourceVersion, isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); - - return buildConfigOperations; + return new BuildConfigOperationsImpl(getContext().withResourceVersion(resourceVersion)); } /* @@ -196,7 +180,7 @@ private void deleteBuilds() { return; } String buildConfigLabelValue = getName().substring(0, Math.min(getName().length(), 63)); - BuildList matchingBuilds = new BuildOperationsImpl(client, (OpenShiftConfig) config, namespace).inNamespace(namespace).withLabel(BUILD_CONFIG_LABEL, buildConfigLabelValue).list(); + BuildList matchingBuilds = new BuildOperationsImpl(client, (OpenShiftConfig) config).inNamespace(namespace).withLabel(BUILD_CONFIG_LABEL, buildConfigLabelValue).list(); if (matchingBuilds.getItems() != null) { @@ -206,7 +190,7 @@ private void deleteBuilds() { matchingBuild.getMetadata().getAnnotations() != null && getName().equals(matchingBuild.getMetadata().getAnnotations().get(BUILD_CONFIG_ANNOTATION))) { - new BuildOperationsImpl(client, (OpenShiftConfig) config, namespace).inNamespace(matchingBuild.getMetadata().getNamespace()).withName(matchingBuild.getMetadata().getName()).delete(); + new BuildOperationsImpl(client, (OpenShiftConfig) config).inNamespace(matchingBuild.getMetadata().getNamespace()).withName(matchingBuild.getMetadata().getName()).delete(); } @@ -314,42 +298,47 @@ private String getQueryParameters() throws MalformedURLException { @Override public TimeoutInputStreamable asFile(String fileName) { - return new BuildConfigOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, fileName, timeout, timeoutUnit); + return new BuildConfigOperationsImpl(getContext().withAsFile(fileName)); } @Override public MessageAsFileTimeoutInputStreamable withAuthorEmail(String email) { - return new BuildConfigOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), secret, triggerType, authorName, email, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + return new BuildConfigOperationsImpl(getContext().withAuthorEmail(email)); } @Override public AuthorMessageAsFileTimeoutInputStreamable withCommitterEmail(String committerEmail) { - return new BuildConfigOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + return new BuildConfigOperationsImpl(getContext().withCommitterEmail(committerEmail)); } @Override public AsFileTimeoutInputStreamable withMessage(String message) { - return new BuildConfigOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + return new BuildConfigOperationsImpl(getContext().withMessage(message)); } @Override public AuthorEmailable> withAuthorName(String authorName) { - return new BuildConfigOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + return new BuildConfigOperationsImpl(getContext().withAuthorName(authorName)); } @Override public CommitterEmailable> withCommitterName(String committerName) { - return new BuildConfigOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, timeoutUnit); + return new BuildConfigOperationsImpl(getContext().withCommitterName(committerName)); } @Override public InputStreamable withTimeout(long timeout, TimeUnit unit) { - return new BuildConfigOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeout, unit); + return new BuildConfigOperationsImpl(getContext().withTimeout(timeout).withTimeoutUnit(unit)); } @Override public InputStreamable withTimeoutInMillis(long timeoutInMillis) { - return new BuildConfigOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), secret, triggerType, authorName, authorEmail, committerName, committerEmail, commit, message, asFile, timeoutInMillis, TimeUnit.MILLISECONDS); + return withTimeout(timeoutInMillis, TimeUnit.MILLISECONDS); + } + + @Override + public Typeable> withSecret(String secret) { + return new BuildConfigOperationsImpl(getContext().withSecret(secret)); } private static class BuildConfigReaper implements Reaper { diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/BuildOperationContext.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/BuildOperationContext.java new file mode 100644 index 00000000000..2dc80356cc3 --- /dev/null +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/BuildOperationContext.java @@ -0,0 +1,259 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * 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.fabric8.openshift.client.dsl.internal; + +import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; +import io.fabric8.openshift.client.OpenShiftConfig; +import okhttp3.OkHttpClient; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; +import java.util.Map; + +public class BuildOperationContext extends OperationContext { + + private InputStream in; + private OutputStream out; + private OutputStream err; + + private PipedOutputStream inPipe; + private PipedInputStream outPipe; + private PipedInputStream errPipe; + private boolean tty; + private boolean terminatedStatus; + private boolean timestamps; + private String sinceTimestamp; + private Integer sinceSeconds; + private Integer tailingLines; + private boolean prettyOutput; + private Integer limitBytes; + private String version; + + public BuildOperationContext() { + } + + public BuildOperationContext(OkHttpClient client, Config config, String plural, String namespace, String name, String apiGroupName, String apiGroupVersion, Boolean cascading, Object item, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, InputStream in, OutputStream out, OutputStream err, PipedOutputStream inPipe, PipedInputStream outPipe, PipedInputStream errPipe, Boolean tty, Boolean terminatedStatus, Boolean timestampes, String sinceTimestamp, Integer sinceSeconds, Integer tailingLines, Boolean prettyOutput, Integer limitBytes, String version) { + super(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading, item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + this.in = in; + this.out = out; + this.err = err; + this.inPipe = inPipe; + this.outPipe = outPipe; + this.errPipe = errPipe; + this.tty = tty; + this.terminatedStatus = terminatedStatus; + this.timestamps = true; + this.sinceTimestamp = sinceTimestamp; + this.sinceSeconds = sinceSeconds; + this.tailingLines = tailingLines; + this.prettyOutput = prettyOutput; + this.limitBytes = limitBytes; + this.version = version; + } + + public String getVersion() { + return version; + } + + public InputStream getIn() { + return in; + } + + public OutputStream getOut() { + return out; + } + + public OutputStream getErr() { + return err; + } + + + public PipedOutputStream getInPipe() { + return inPipe; + } + + public PipedInputStream getOutPipe() { + return outPipe; + } + + public PipedInputStream getErrPipe() { + return errPipe; + } + + + public boolean isTty() { + return tty; + } + + public boolean isTerminatedStatus() { + return terminatedStatus; + } + + public boolean isTimestamps() { + return timestamps; + } + + public String getSinceTimestamp() { + return sinceTimestamp; + } + + public Integer getSinceSeconds() { + return sinceSeconds; + } + + public Integer getTailingLines() { + return tailingLines; + } + + public boolean isPrettyOutput() { + return prettyOutput; + } + + public Integer getLimitBytes() { + return limitBytes; + } + + + public BuildOperationContext withOkhttpClient(OkHttpClient client) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withConfig(Config config) { + return new BuildOperationContext(client, OpenShiftConfig.wrap(config), plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withPlural(String plural) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withNamespace(String namespace) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withName(String name) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withApiGroupName(String apiGroupName) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withApiGroupVersion(String apiGroupVersion) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + @Override + public BuildOperationContext withItem(Object item) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withCascading(boolean cascading) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withLabels(Map labels) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withLabelsIn(Map labelsIn) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withLabelsNot(Map labelsNot) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withLabelsNotIn(Map labelsNotIn) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withFields(Map fields) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withResourceVersion(String resourceVersion) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withReloadingFromServer(boolean reloadingFromServer) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withGracePeriodSeconds(long gracePeriodSeconds) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + + public BuildOperationContext withIn(InputStream in) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withOut(OutputStream out) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withErr(OutputStream err) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withInPipe(PipedOutputStream inPipe) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withOutPipe(PipedInputStream outPipe) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withErrPipe(PipedInputStream errPipe) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withTty(boolean tty) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withTerminatedStatus(boolean terminatedStatus) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withTimestamps(boolean timestamps) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withSinceTimestamp(String sinceTimestamp) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withSinceSeconds(Integer sinceSeconds) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withTailingLines(Integer tailingLines) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withPrettyOutput(boolean prettyOutput) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + + public BuildOperationContext withLimitBytes(Integer limitBytes) { + return new BuildOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, in, out, err, inPipe, outPipe, errPipe, tty, terminatedStatus, timestamps, sinceTimestamp, sinceSeconds, tailingLines, prettyOutput, limitBytes, version); + } + +} diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/BuildOperationsImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/BuildOperationsImpl.java index 37836298127..76cc89ee00a 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/BuildOperationsImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/BuildOperationsImpl.java @@ -22,6 +22,8 @@ import io.fabric8.kubernetes.client.dsl.PrettyLoggable; import io.fabric8.kubernetes.client.dsl.TailPrettyLoggable; import io.fabric8.kubernetes.client.dsl.TimeTailPrettyLoggable; +import io.fabric8.kubernetes.client.dsl.base.BaseOperation; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import io.fabric8.kubernetes.client.dsl.internal.LogWatchCallback; import io.fabric8.kubernetes.client.utils.URLUtils; import io.fabric8.openshift.client.dsl.BuildResource; @@ -68,31 +70,42 @@ public class BuildOperationsImpl extends OpenShiftOperation(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), null, null, null, null, null, null, false, false, false, null, null, null, false, null, null); + + public BuildOperationsImpl(OkHttpClient client, OpenShiftConfig config) { + this(new BuildOperationContext().withOkhttpClient(client).withConfig(config)); } - public BuildOperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, Build item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - this(client, config, apiGroup, apiVersion, namespace, name, cascading, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), null, null, null, null, null, null, false, false, false, null, null, null, false, null, null); + public BuildOperationsImpl(BuildOperationContext context) { + super(context.withApiGroupName(BUILD) + .withPlural("builds")); + this.type = Build.class; + this.listType = BuildList.class; + this.doneableType = DoneableBuild.class; + + this.in = context.getIn(); + this.out = context.getOut(); + this.err = context.getErr(); + this.inPipe = context.getInPipe(); + this.outPipe = context.getOutPipe(); + this.errPipe = context.getErrPipe(); + this.withTTY = context.isTty(); + this.withTerminatedStatus = context.isTerminatedStatus(); + this.withTimestamps = context.isTimestamps(); + this.sinceTimestamp = context.getSinceTimestamp(); + this.sinceSeconds = context.getSinceSeconds(); + this.withTailingLines = context.getTailingLines(); + this.withPrettyOutput = context.isPrettyOutput(); + this.version = context.getVersion(); + this.limitBytes = context.getLimitBytes(); + } + + @Override + public BuildOperationsImpl newInstance(OperationContext context) { + return new BuildOperationsImpl((BuildOperationContext) context); } - public BuildOperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, Build item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields, InputStream in, OutputStream out, OutputStream err, PipedOutputStream inPipe, PipedInputStream outPipe, PipedInputStream errPipe, boolean withTTY, boolean withTerminatedStatus, boolean withTimestamps, String sinceTimestamp, Integer sinceSeconds, Integer withTailingLines, boolean withPrettyOutput, String version, Integer limitBytes) { - super(client, OpenShiftOperation.withApiGroup(client, apiGroup, apiVersion, config), "builds", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); - this.in = in; - this.out = out; - this.err = err; - this.inPipe = inPipe; - this.outPipe = outPipe; - this.errPipe = errPipe; - this.withTTY = withTTY; - this.withTerminatedStatus = withTerminatedStatus; - this.withTimestamps = withTimestamps; - this.sinceTimestamp = sinceTimestamp; - this.sinceSeconds = sinceSeconds; - this.withTailingLines = withTailingLines; - this.withPrettyOutput = withPrettyOutput; - this.version = version; - this.limitBytes = limitBytes; + BuildOperationContext getContext() { + return (BuildOperationContext) context; } protected String getLogParameters() { @@ -146,7 +159,7 @@ public String getLog() { @Override public String getLog(Boolean isPretty) { - return new BuildOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), in,out,err,inPipe, outPipe, errPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, version, limitBytes).getLog(); + return new BuildOperationsImpl(getContext().withPrettyOutput(isPretty)).getLog(); } /** @@ -181,36 +194,36 @@ public LogWatch watchLog(OutputStream out) { @Override public Loggable withPrettyOutput() { - return new BuildOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), in,out,err,inPipe, outPipe, errPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, true, version, limitBytes); + return new BuildOperationsImpl(getContext().withPrettyOutput(true)); } @Override - public PrettyLoggable tailingLines(int withTailingLines) { - return new BuildOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), in,out,err,inPipe, outPipe, errPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, version, limitBytes); + public PrettyLoggable tailingLines(int tailingLines) { + return new BuildOperationsImpl(getContext().withTailingLines(tailingLines)); } @Override public TimeTailPrettyLoggable terminated() { - return new BuildOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), in,out,err,inPipe, outPipe, errPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, version, limitBytes); + return new BuildOperationsImpl(getContext().withTerminatedStatus(true)); } @Override public TailPrettyLoggable sinceTime(String sinceTimestamp) { - return new BuildOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), in,out,err,inPipe, outPipe, errPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, version, limitBytes); + return new BuildOperationsImpl(getContext().withSinceTimestamp(sinceTimestamp)); } @Override public TailPrettyLoggable sinceSeconds(int sinceSeconds) { - return new BuildOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), in,out,err,inPipe, outPipe, errPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, version, limitBytes); + return new BuildOperationsImpl(getContext().withSinceSeconds(sinceSeconds)); } @Override public BytesLimitTerminateTimeTailPrettyLoggable limitBytes(int limitBytes) { - return new BuildOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), in,out,err,inPipe, outPipe, errPipe, withTTY, withTerminatedStatus, withTimestamps, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, version, limitBytes); + return new BuildOperationsImpl(getContext().withLimitBytes(limitBytes)); } @Override public BytesLimitTerminateTimeTailPrettyLoggable usingTimestamps() { - return new BuildOperationsImpl(client, getConfig(), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), in,out,err,inPipe, outPipe, errPipe, withTTY, withTerminatedStatus, true, sinceTimestamp, sinceSeconds, withTailingLines, withPrettyOutput, version, limitBytes); + return new BuildOperationsImpl(getContext().withTimestamps(true)); } } diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/DeploymentConfigOperationsImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/DeploymentConfigOperationsImpl.java index f2ef666ca76..bbb144101e6 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/DeploymentConfigOperationsImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/DeploymentConfigOperationsImpl.java @@ -15,13 +15,16 @@ */ package io.fabric8.openshift.client.dsl.internal; +import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.dsl.base.BaseOperation; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; +import io.fabric8.kubernetes.client.dsl.internal.RollingOperationContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Map; import java.util.Objects; -import java.util.TreeMap; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import java.util.concurrent.CountDownLatch; @@ -38,7 +41,6 @@ import io.fabric8.openshift.api.model.DeploymentConfig; import io.fabric8.openshift.api.model.DeploymentConfigList; import io.fabric8.openshift.api.model.DoneableDeploymentConfig; -import io.fabric8.openshift.client.OpenShiftConfig; import io.fabric8.openshift.client.dsl.DeployableScalableResource; import okhttp3.OkHttpClient; @@ -50,16 +52,23 @@ public class DeploymentConfigOperationsImpl extends OpenShiftOperation(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + public DeploymentConfigOperationsImpl(OkHttpClient client, Config config) { + this(new RollingOperationContext().withOkhttpClient(client).withConfig(config)); } - public DeploymentConfigOperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, DeploymentConfig item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, OpenShiftOperation.withApiGroup(client, apiGroup, apiVersion, config), "deploymentconfigs", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + public DeploymentConfigOperationsImpl(RollingOperationContext context) { + super(context.withApiGroupName(APPS).withPlural("deploymentconfigs")); + this.type = DeploymentConfig.class; + this.listType = DeploymentConfigList.class; + this.doneableType = DoneableDeploymentConfig.class; reaper = new DeploymentConfigReaper(this, client); } + @Override + public DeploymentConfigOperationsImpl newInstance(OperationContext context) { + return new DeploymentConfigOperationsImpl((RollingOperationContext) context); + } + @Override public DoneableDeploymentConfig edit() { if (isCascading()) { @@ -131,7 +140,8 @@ public boolean reap() { Map selector = new HashMap<>(); selector.put(DEPLOYMENT_CONFIG_REF, deployment.getMetadata().getName()); if (selector != null && !selector.isEmpty()) { - Boolean deleted = new ReplicationControllerOperationsImpl(client, operation.getConfig(), operation.getNamespace()) + Boolean deleted = new ReplicationControllerOperationsImpl(client, operation.getConfig()) + .inNamespace(operation.namespace) .withLabels(selector) .delete(); } diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/GroupOperationsImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/GroupOperationsImpl.java index 18439d7c8a3..3bb6ebc1afa 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/GroupOperationsImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/GroupOperationsImpl.java @@ -16,6 +16,7 @@ package io.fabric8.openshift.client.dsl.internal; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import io.fabric8.openshift.api.model.DoneableGroup; import io.fabric8.openshift.api.model.Group; @@ -28,12 +29,22 @@ import static io.fabric8.openshift.client.OpenShiftAPIGroups.USER; public class GroupOperationsImpl extends OpenShiftOperation> { - public GroupOperationsImpl(OkHttpClient client, OpenShiftConfig config, String namespace) { - this(client, config, USER, null, namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + + public GroupOperationsImpl(OkHttpClient client, OpenShiftConfig config) { + this(new OperationContext().withOkhttpClient(client).withConfig(config)); + } + + public GroupOperationsImpl(OperationContext context) { + super(context.withApiGroupName(USER) + .withPlural("groups")); + this.type = Group.class; + this.listType = GroupList.class; + this.doneableType = DoneableGroup.class; } - public GroupOperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, Group item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, OpenShiftOperation.withApiGroup(client, apiGroup, apiVersion, config), "groups", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + @Override + public GroupOperationsImpl newInstance(OperationContext context) { + return new GroupOperationsImpl(context); } @Override diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OAuthAccessTokenOperationsImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OAuthAccessTokenOperationsImpl.java index 799d2f44c25..bb88f9291f0 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OAuthAccessTokenOperationsImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OAuthAccessTokenOperationsImpl.java @@ -16,14 +16,13 @@ package io.fabric8.openshift.client.dsl.internal; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import io.fabric8.openshift.api.model.DoneableOAuthAccessToken; import io.fabric8.openshift.api.model.OAuthAccessToken; import io.fabric8.openshift.api.model.OAuthAccessTokenList; import io.fabric8.openshift.client.OpenShiftConfig; -import java.util.Map; -import java.util.TreeMap; import static io.fabric8.openshift.client.OpenShiftAPIGroups.OAUTH; @@ -31,11 +30,20 @@ public class OAuthAccessTokenOperationsImpl extends OpenShiftOperation> { public OAuthAccessTokenOperationsImpl(OkHttpClient client, OpenShiftConfig config) { - this(client, config, OAUTH, null, null, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - public OAuthAccessTokenOperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, OAuthAccessToken item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, OpenShiftOperation.withApiGroup(client, apiGroup, apiVersion, config), "oauthaccesstokens", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + public OAuthAccessTokenOperationsImpl(OperationContext context) { + super(context.withApiGroupName(OAUTH) + .withPlural("oauthaccesstokens")); + this.type = OAuthAccessToken.class; + this.listType = OAuthAccessTokenList.class; + this.doneableType = DoneableOAuthAccessToken.class; + } + + @Override + public OAuthAccessTokenOperationsImpl newInstance(OperationContext context) { + return new OAuthAccessTokenOperationsImpl(context); } @Override diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OAuthAuthorizeTokenOperationsImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OAuthAuthorizeTokenOperationsImpl.java index 5d6a552d237..d3426030f5e 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OAuthAuthorizeTokenOperationsImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OAuthAuthorizeTokenOperationsImpl.java @@ -16,6 +16,8 @@ package io.fabric8.openshift.client.dsl.internal; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; +import io.fabric8.openshift.api.model.OAuthAccessToken; import okhttp3.OkHttpClient; import io.fabric8.openshift.api.model.DoneableOAuthAuthorizeToken; import io.fabric8.openshift.api.model.OAuthAuthorizeToken; @@ -32,11 +34,20 @@ public class OAuthAuthorizeTokenOperationsImpl extends OpenShiftOperation> { public OAuthAuthorizeTokenOperationsImpl(OkHttpClient client, OpenShiftConfig config) { - this(client, config, AUTHORIZATION, null, null, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - public OAuthAuthorizeTokenOperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, OAuthAuthorizeToken item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, OpenShiftOperation.withApiGroup(client, apiGroup, apiVersion, config), "oauthauthorizetokens", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + public OAuthAuthorizeTokenOperationsImpl(OperationContext context) { + super(context.withApiGroupName(OAUTH) + .withPlural("oauthauthorizetokens")); + this.type = OAuthAuthorizeToken.class; + this.listType = OAuthAuthorizeTokenList.class; + this.doneableType = DoneableOAuthAuthorizeToken.class; + } + + @Override + public OAuthAuthorizeTokenOperationsImpl newInstance(OperationContext context) { + return new OAuthAuthorizeTokenOperationsImpl(context); } @Override diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OAuthClientOperationsImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OAuthClientOperationsImpl.java index 259878c6f6d..c4b74b610ba 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OAuthClientOperationsImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OAuthClientOperationsImpl.java @@ -16,6 +16,7 @@ package io.fabric8.openshift.client.dsl.internal; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import io.fabric8.openshift.api.model.DoneableOAuthClient; import io.fabric8.openshift.api.model.OAuthClient; @@ -31,11 +32,20 @@ public class OAuthClientOperationsImpl extends OpenShiftOperation> { public OAuthClientOperationsImpl(OkHttpClient client, OpenShiftConfig config) { - this(client, config, OAUTH, null, null, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - public OAuthClientOperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, OAuthClient item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, OpenShiftOperation.withApiGroup(client, apiGroup, apiVersion, config), "oauthclients", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + public OAuthClientOperationsImpl(OperationContext context) { + super(context.withApiGroupName(OAUTH) + .withPlural("oauthclients")); + this.type = OAuthClient.class; + this.listType = OAuthClientList.class; + this.doneableType = DoneableOAuthClient.class; + } + + @Override + public OAuthClientOperationsImpl newInstance(OperationContext context) { + return new OAuthClientOperationsImpl(context); } @Override diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OpenShiftOperation.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OpenShiftOperation.java index 94a7c62ce30..a2462a6d8cf 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OpenShiftOperation.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OpenShiftOperation.java @@ -22,63 +22,37 @@ import io.fabric8.kubernetes.client.KubernetesClientException; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; -import io.fabric8.kubernetes.client.dsl.base.ConfigAndApiGroupsInfo; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import io.fabric8.kubernetes.client.utils.URLUtils; +import io.fabric8.kubernetes.client.utils.Utils; import io.fabric8.openshift.client.DefaultOpenShiftClient; import io.fabric8.openshift.client.OpenShiftClient; import io.fabric8.openshift.client.OpenShiftConfig; -import okhttp3.OkHttpClient; import java.net.MalformedURLException; import java.net.URL; -import java.util.Map; public class OpenShiftOperation, R extends Resource> extends HasMetadataOperation { - protected OpenShiftOperation(OkHttpClient client, ConfigAndApiGroupsInfo config, 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) { - super(client, config.getConfig(), config.getApiGroupName(), config.getApiGroupVersion(), resourceT, namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); - this.apiVersion = config.getApiGroupVersion(); + public OpenShiftOperation(OperationContext ctx) { + super(wrap(ctx)); } - /** - * If the current client supports the new API Group REST API at /apis/*.openshift.io/v1 - * then lets use that URL otherwise lets stick to the legacy /oapi/v1 API - * - * @param openShiftClient the OpenShift client to use - * @param apiGroupName the API Group name like apps.openshift.io or build.openshift.io - * @param config the current configuration - * @return the current configuration if API groups are not supported otherwise the new configuration - */ - public static ConfigAndApiGroupsInfo withApiGroup(OpenShiftClient openShiftClient, String apiGroupName, String apiVersion, OpenShiftConfig config) { + public static OperationContext wrap(OperationContext context) { + OpenShiftConfig config = OpenShiftConfig.wrap(context.getConfig()); String oapiVersion = config.getOapiVersion(); - if (config.isOpenShiftAPIGroups(openShiftClient)) { - String apiGroupUrl = URLUtils.join(config.getMasterUrl(), "apis", apiGroupName, oapiVersion); - String apiGroupVersion = URLUtils.join(apiGroupName, oapiVersion); - return new ConfigAndApiGroupsInfo(new OpenShiftConfig(config, apiGroupUrl), apiGroupName, apiGroupVersion); + OpenShiftClient oc = new DefaultOpenShiftClient(context.getClient(), config); + if (Utils.isNotNullOrEmpty(context.getApiGroupName()) && config.isOpenShiftAPIGroups(oc)) { + String apiGroupUrl = URLUtils.join(config.getMasterUrl(), "apis", context.getApiGroupName(), oapiVersion); + String apiGroupVersion = URLUtils.join(context.getApiGroupName(), oapiVersion); + return context.withConfig(new OpenShiftConfig(config, apiGroupUrl)).withApiGroupName(context.getApiGroupName()).withApiGroupVersion(apiGroupVersion); } else { - if (apiVersion == null) { - apiVersion = oapiVersion; - } - return new ConfigAndApiGroupsInfo(config, apiGroupName, apiVersion); + String apiGroupUrl = URLUtils.join(config.getMasterUrl(), "oapi", oapiVersion); + return context.withConfig(new OpenShiftConfig(config, apiGroupUrl)).withApiGroupName(context.getApiGroupName()).withApiGroupVersion(oapiVersion); } } - /** - * If the current client supports the new API Group REST API at /apis/*.openshift.io/v1 - * then lets use that URL otherwise lets stick to the legacy /oapi/v1 API - * - * @param httpClient the HTTP client to use - * @param apiGroupName the API Group name like apps.openshift.io or build.openshift.io - * @param config the current configuration - * @return the current configuration if API groups are not supported otherwise the new configuration - */ - public static ConfigAndApiGroupsInfo withApiGroup(OkHttpClient httpClient, String apiGroupName, String apiVersion, OpenShiftConfig config) { - OpenShiftClient openShiftClient = new DefaultOpenShiftClient(httpClient, config); - return withApiGroup(openShiftClient, apiGroupName, apiVersion, config); - } - - @Override public URL getRootUrl() { try { diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OpenshiftClusterRoleBindingOperationsImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OpenshiftClusterRoleBindingOperationsImpl.java index fccbe95f26c..86023931e78 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OpenshiftClusterRoleBindingOperationsImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OpenshiftClusterRoleBindingOperationsImpl.java @@ -16,23 +16,31 @@ package io.fabric8.openshift.client.dsl.internal; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import io.fabric8.openshift.api.model.OpenshiftClusterRoleBinding; import io.fabric8.openshift.api.model.OpenshiftClusterRoleBindingList; import io.fabric8.openshift.api.model.DoneableOpenshiftClusterRoleBinding; import io.fabric8.openshift.client.OpenShiftConfig; -import java.util.Map; -import java.util.TreeMap; - import static io.fabric8.openshift.client.OpenShiftAPIGroups.AUTHORIZATION; public class OpenshiftClusterRoleBindingOperationsImpl extends OpenShiftOperation> { - public OpenshiftClusterRoleBindingOperationsImpl(OkHttpClient client, OpenShiftConfig config, String namespace) { - this(client, config, AUTHORIZATION, null, namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + + public OpenshiftClusterRoleBindingOperationsImpl(OkHttpClient client, OpenShiftConfig config) { + this(new OperationContext().withOkhttpClient(client).withConfig(config)); + } + + public OpenshiftClusterRoleBindingOperationsImpl(OperationContext context) { + super(context.withApiGroupName(AUTHORIZATION) + .withPlural("clusterrolebindings")); + this.type = OpenshiftClusterRoleBinding.class; + this.listType = OpenshiftClusterRoleBindingList.class; + this.doneableType = DoneableOpenshiftClusterRoleBinding.class; } - public OpenshiftClusterRoleBindingOperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, OpenshiftClusterRoleBinding item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, OpenShiftOperation.withApiGroup(client, apiGroup, apiVersion, config), "clusterrolebindings", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + @Override + public OpenshiftClusterRoleBindingOperationsImpl newInstance(OperationContext context) { + return new OpenshiftClusterRoleBindingOperationsImpl(context); } } diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OpenshiftRoleBindingOperationsImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OpenshiftRoleBindingOperationsImpl.java index 7e44f6d03a2..3f7bbbda54f 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OpenshiftRoleBindingOperationsImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/OpenshiftRoleBindingOperationsImpl.java @@ -20,6 +20,7 @@ import io.fabric8.kubernetes.api.model.ObjectReferenceBuilder; import io.fabric8.kubernetes.client.KubernetesClientException; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import io.fabric8.openshift.api.model.DoneableOpenshiftRoleBinding; import io.fabric8.openshift.api.model.OpenshiftRoleBinding; import io.fabric8.openshift.api.model.OpenshiftRoleBindingBuilder; @@ -36,12 +37,22 @@ import static io.fabric8.openshift.client.OpenShiftAPIGroups.AUTHORIZATION; public class OpenshiftRoleBindingOperationsImpl extends OpenShiftOperation> { - public OpenshiftRoleBindingOperationsImpl(OkHttpClient client, OpenShiftConfig config, String namespace) { - this(client, config, AUTHORIZATION, null, namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + + public OpenshiftRoleBindingOperationsImpl(OkHttpClient client, OpenShiftConfig config) { + this(new OperationContext().withOkhttpClient(client).withConfig(config)); + } + + public OpenshiftRoleBindingOperationsImpl(OperationContext context) { + super(context.withApiGroupName(AUTHORIZATION) + .withPlural("rolebindings")); + this.type = OpenshiftRoleBinding.class; + this.listType = OpenshiftRoleBindingList.class; + this.doneableType = DoneableOpenshiftRoleBinding.class; } - public OpenshiftRoleBindingOperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, OpenshiftRoleBinding item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, OpenShiftOperation.withApiGroup(client, apiGroup, apiVersion, config), "rolebindings", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + @Override + public OpenshiftRoleBindingOperationsImpl newInstance(OperationContext context) { + return new OpenshiftRoleBindingOperationsImpl(context); } @Override diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/ProjectOperationsImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/ProjectOperationsImpl.java index 1a22db74b34..542c693df38 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/ProjectOperationsImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/ProjectOperationsImpl.java @@ -16,6 +16,7 @@ package io.fabric8.openshift.client.dsl.internal; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import io.fabric8.openshift.api.model.DoneableProject; import io.fabric8.openshift.api.model.Project; @@ -31,13 +32,20 @@ public class ProjectOperationsImpl extends OpenShiftOperation> { public ProjectOperationsImpl(OkHttpClient client, OpenShiftConfig config) { - this(client, config, PROJECT, null, null, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - public ProjectOperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, Project item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, OpenShiftOperation.withApiGroup(client, apiGroup, apiVersion, config), "projects", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + public ProjectOperationsImpl(OperationContext context) { + super(context.withApiGroupName(PROJECT) + .withPlural("projects")); + this.type = Project.class; + this.listType = ProjectList.class; + this.doneableType = DoneableProject.class; + } + @Override + public ProjectOperationsImpl newInstance(OperationContext context) { + return new ProjectOperationsImpl(context); } - @Override public boolean isResourceNamespaced() { diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/ProjectRequestsOperationImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/ProjectRequestsOperationImpl.java index 8fd665df626..5631708e372 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/ProjectRequestsOperationImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/ProjectRequestsOperationImpl.java @@ -15,6 +15,7 @@ */ package io.fabric8.openshift.client.dsl.internal; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import io.fabric8.kubernetes.client.utils.URLUtils; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -36,15 +37,13 @@ public class ProjectRequestsOperationImpl extends OperationSupport implements ProjectRequestOperation { - private final ProjectRequest item; - public ProjectRequestsOperationImpl(OkHttpClient client, OpenShiftConfig config) { - this(client, config, null, null); + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - public ProjectRequestsOperationImpl(OkHttpClient client, OpenShiftConfig config, String apiVersion, ProjectRequest item) { - super(client, OpenShiftOperation.withApiGroup(client, PROJECT, apiVersion, config), "projectrequests", null, null); - this.item = item; + public ProjectRequestsOperationImpl(OperationContext context) { + super(context.withApiGroupName(PROJECT) + .withPlural("projectrequests")); } @Override @@ -123,6 +122,6 @@ public Status list(Integer limitVal, String continueVal) { } public ProjectRequest getItem() { - return item; + return (ProjectRequest) context.getItem(); } } diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/SecurityContextConstraintsOperationsImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/SecurityContextConstraintsOperationsImpl.java index 38f11c79ff7..3e705d7293a 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/SecurityContextConstraintsOperationsImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/SecurityContextConstraintsOperationsImpl.java @@ -15,6 +15,7 @@ */ package io.fabric8.openshift.client.dsl.internal; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import io.fabric8.openshift.api.model.DoneableSecurityContextConstraints; import io.fabric8.openshift.api.model.SecurityContextConstraints; import io.fabric8.openshift.api.model.SecurityContextConstraintsList; @@ -28,13 +29,22 @@ import static io.fabric8.openshift.client.OpenShiftAPIGroups.SECURITY; public class SecurityContextConstraintsOperationsImpl extends OpenShiftOperation> { + public SecurityContextConstraintsOperationsImpl(OkHttpClient client, OpenShiftConfig config) { - this(client, config, SECURITY, null, null, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + this(new OperationContext().withOkhttpClient(client).withConfig(config)); + } + public SecurityContextConstraintsOperationsImpl(OperationContext context) { + super(context.withApiGroupName(SECURITY) + .withPlural("securitycontextconstraints")); + this.type = SecurityContextConstraints.class; + this.listType = SecurityContextConstraintsList.class; + this.doneableType = DoneableSecurityContextConstraints.class; } - public SecurityContextConstraintsOperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, SecurityContextConstraints item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, OpenShiftOperation.withApiGroup(client, apiGroup, apiVersion, config), "securitycontextconstraints", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + @Override + public SecurityContextConstraintsOperationsImpl newInstance(OperationContext context) { + return new SecurityContextConstraintsOperationsImpl(context); } @Override diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/SubjectAccessReviewOperationImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/SubjectAccessReviewOperationImpl.java index 9299e61f2b4..55091799317 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/SubjectAccessReviewOperationImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/SubjectAccessReviewOperationImpl.java @@ -16,6 +16,7 @@ package io.fabric8.openshift.client.dsl.internal; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.KubernetesClientException; @@ -40,18 +41,18 @@ public class SubjectAccessReviewOperationImpl extends OperationSupport implements SubjectAccessReviewOperation { - public SubjectAccessReviewOperationImpl(OkHttpClient client, OpenShiftConfig config) { - this(client, config, null, null); + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - public SubjectAccessReviewOperationImpl(OkHttpClient client, OpenShiftConfig config, String apiVersion, String namespace) { - super(client, OpenShiftOperation.withApiGroup(client, AUTHORIZATION, apiVersion, config), "subjectaccessreviews", namespace, null); + public SubjectAccessReviewOperationImpl(OperationContext context) { + super(context.withApiGroupName(AUTHORIZATION) + .withPlural("subjectaccessreviews")); } @Override public CreateableLocalSubjectAccessReview inNamespace(String namespace) { - return new SubjectAccessReviewOperationImpl(client, OpenShiftConfig.wrap(getConfig()), null, namespace).local(); + return new SubjectAccessReviewOperationImpl(client, OpenShiftConfig.wrap(getConfig())).local(); } @Override diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/TemplateOperationContext.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/TemplateOperationContext.java new file mode 100644 index 00000000000..ad89a9044d7 --- /dev/null +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/TemplateOperationContext.java @@ -0,0 +1,114 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * 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.fabric8.openshift.client.dsl.internal; + +import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; +import io.fabric8.openshift.client.OpenShiftConfig; +import okhttp3.OkHttpClient; + +import java.util.Map; + +public class TemplateOperationContext extends OperationContext { + + private Map parameters; + + public TemplateOperationContext() { + } + + public TemplateOperationContext(OkHttpClient client, Config config, String plural, String namespace, String name, String apiGroupName, String apiGroupVersion, Boolean cascading, Object item, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map parameters) { + super(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading, item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds); + this.parameters = parameters; + } + + public Map getParameters() { + return parameters; + } + + public TemplateOperationContext withOkhttpClient(OkHttpClient client) { + return new TemplateOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } + + public TemplateOperationContext withConfig(Config config) { + return new TemplateOperationContext(client, OpenShiftConfig.wrap(config), plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } + + public TemplateOperationContext withPlural(String plural) { + return new TemplateOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } + + public TemplateOperationContext withNamespace(String namespace) { + return new TemplateOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } + + public TemplateOperationContext withName(String name) { + return new TemplateOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } + + + public TemplateOperationContext withApiGroupName(String apiGroupName) { + return new TemplateOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } + + public TemplateOperationContext withApiGroupVersion(String apiGroupVersion) { + return new TemplateOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } + + @Override + public TemplateOperationContext withItem(Object item) { + return new TemplateOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } + + public TemplateOperationContext withCascading(boolean cascading) { + return new TemplateOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } + + public TemplateOperationContext withLabels(Map labels) { + return new TemplateOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } + + public TemplateOperationContext withLabelsIn(Map labelsIn) { + return new TemplateOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } + + public TemplateOperationContext withLabelsNot(Map labelsNot) { + return new TemplateOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } + + public TemplateOperationContext withLabelsNotIn(Map labelsNotIn) { + return new TemplateOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } + + public TemplateOperationContext withFields(Map fields) { + return new TemplateOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } + + public TemplateOperationContext withResourceVersion(String resourceVersion) { + return new TemplateOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } + + public TemplateOperationContext withReloadingFromServer(boolean reloadingFromServer) { + return new TemplateOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } + + public TemplateOperationContext withGracePeriodSeconds(long gracePeriodSeconds) { + return new TemplateOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } + + public TemplateOperationContext withParameters(Map parameters) { + return new TemplateOperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, resourceVersion, reloadingFromServer, gracePeriodSeconds, parameters); + } +} diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/TemplateOperationsImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/TemplateOperationsImpl.java index 2b533bdb694..2615566e498 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/TemplateOperationsImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/TemplateOperationsImpl.java @@ -23,6 +23,7 @@ import io.fabric8.kubernetes.api.model.KubernetesResourceList; import io.fabric8.kubernetes.client.KubernetesClientException; import io.fabric8.kubernetes.client.dsl.MixedOperation; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import io.fabric8.kubernetes.client.utils.Serialization; import io.fabric8.kubernetes.client.utils.URLUtils; import io.fabric8.kubernetes.client.utils.Utils; @@ -66,27 +67,30 @@ public class TemplateOperationsImpl private static final String EXPRESSION = "expression"; private static final TypeReference> MAPS_REFERENCE = new TypeReference>() { }; + private final Map parameters; - public TemplateOperationsImpl(OkHttpClient client, OpenShiftConfig config, String namespace) { - this(client, config, TEMPLATE, null, namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + public TemplateOperationsImpl(OkHttpClient client, OpenShiftConfig config) { + this(new TemplateOperationContext().withOkhttpClient(client).withConfig(config)); } - public TemplateOperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, Template item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - this(client, config, apiGroup, apiVersion, "templates", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields, null); + public TemplateOperationsImpl(TemplateOperationContext context) { + super(context.withApiGroupName(TEMPLATE) + .withPlural("templates")); + this.parameters = context.getParameters(); + this.type = Template.class; + this.listType = TemplateList.class; + this.doneableType = DoneableTemplate.class; } - - public TemplateOperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, Template item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields, Map parameters) { - this(client, config, apiGroup, apiVersion, "templates", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields, parameters); + @Override + public TemplateOperationsImpl newInstance(OperationContext context) { + return new TemplateOperationsImpl((TemplateOperationContext) context); } - - public TemplateOperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroup, String apiVersion, String resourceT, String namespace, String name, Boolean cascading, Template item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields, Map parameters) { - super(client, OpenShiftOperation.withApiGroup(client, apiGroup, apiVersion, config), resourceT, namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); - this.parameters = parameters; + public TemplateOperationContext getContext() { + return (TemplateOperationContext) context; } - @Override public KubernetesList process(File f) { try (FileInputStream is = new FileInputStream(f)) { @@ -162,8 +166,7 @@ public KubernetesList processLocally(ParameterValue... values) { @Override public MixedOperation> withParameters(Map parameters) { - return new TemplateOperationsImpl(client, OpenShiftConfig.wrap(config), getAPIGroup(), getAPIVersion(), namespace, getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), - getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), parameters); + return new TemplateOperationsImpl(getContext().withParameters(parameters)); } public KubernetesList processLocally(Map valuesMap) { @@ -273,23 +276,7 @@ public TemplateResource load(InputSt .withObjects(items.toArray(new HasMetadata[items.size()])).build(); } - return new TemplateOperationsImpl(client, OpenShiftConfig.wrap(config), apiGroupName, null, namespace, null, false, template, null, false, 0L, - null, null, null, null, null, null); - } - - @Override - public TemplateResource withName(String name) { - if (name == null || name.length() == 0) { - throw new IllegalArgumentException("Name must be provided."); - } - return new TemplateOperationsImpl(client, OpenShiftConfig.wrap(config), getAPIGroup(), getAPIVersion(), namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), - getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), parameters); - } - - @Override - public OpenShiftOperation> inNamespace(String namespace) { - return new TemplateOperationsImpl(client, OpenShiftConfig.wrap(config), getAPIGroup(), getAPIVersion(), namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), - getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields(), parameters); + return new TemplateOperationsImpl(getContext().withItem(template)); } @Override diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/UserOperationsImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/UserOperationsImpl.java index e92d9299622..77f65b10c4c 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/UserOperationsImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/UserOperationsImpl.java @@ -16,24 +16,32 @@ package io.fabric8.openshift.client.dsl.internal; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; import okhttp3.OkHttpClient; import io.fabric8.openshift.api.model.DoneableUser; import io.fabric8.openshift.api.model.User; import io.fabric8.openshift.api.model.UserList; import io.fabric8.openshift.client.OpenShiftConfig; -import java.util.Map; -import java.util.TreeMap; - import static io.fabric8.openshift.client.OpenShiftAPIGroups.USER; public class UserOperationsImpl extends OpenShiftOperation> { - public UserOperationsImpl(OkHttpClient client, OpenShiftConfig config, String namespace) { - this(client, config, USER, null, namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + + public UserOperationsImpl(OkHttpClient client, OpenShiftConfig config) { + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - public UserOperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroup, String apiVersion, String namespace, String name, Boolean cascading, User item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, OpenShiftOperation.withApiGroup(client, apiGroup, apiVersion, config), "users", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + public UserOperationsImpl(OperationContext context) { + super(context.withApiGroupName(USER) + .withPlural("users")); + this.type = User.class; + this.listType = UserList.class; + this.doneableType = DoneableUser.class; + } + + @Override + public UserOperationsImpl newInstance(OperationContext context) { + return new UserOperationsImpl(context); } @Override diff --git a/openshift-client/src/main/resources/resource-handler.vm b/openshift-client/src/main/resources/resource-handler.vm index 072c620f02c..5f60ea9ae69 100644 --- a/openshift-client/src/main/resources/resource-handler.vm +++ b/openshift-client/src/main/resources/resource-handler.vm @@ -53,6 +53,8 @@ import io.fabric8.kubernetes.client.Watcher; import io.fabric8.openshift.client.dsl.internal.${model.name}OperationsImpl; import io.fabric8.kubernetes.client.utils.ApiVersionUtil; +import io.fabric8.openshift.client.OpenShiftConfig; + import okhttp3.OkHttpClient; import ${model.fullyQualifiedName}; @@ -61,8 +63,8 @@ import ${model.fullyQualifiedName}Builder; import java.util.TreeMap; import java.util.concurrent.TimeUnit; - public class ${model.name}Handler implements ResourceHandler<${model.name}, ${model.name}Builder> { + @Override public String getKind() { return ${model.name}.class.getSimpleName(); @@ -70,17 +72,17 @@ public class ${model.name}Handler implements ResourceHandler<${model.name}, ${mo @Override public ${model.name} create(OkHttpClient client, Config config, String namespace, ${model.name} item) { - return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config), ApiVersionUtil.apiGroup(item, "$apiGroupName"), ApiVersionUtil.apiVersion(item, "$apiGroupVersion"), namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).create(); + return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config)).withItem(item).inNamespace(namespace).create(); } @Override public ${model.name} replace(OkHttpClient client, Config config, String namespace, ${model.name} item) { - return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config), ApiVersionUtil.apiGroup(item, "$apiGroupName"), ApiVersionUtil.apiVersion(item, "$apiGroupVersion"), namespace, null, true, item, null, true, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).replace(item); + return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config)).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).replace(item); } @Override public ${model.name} reload(OkHttpClient client, Config config, String namespace, ${model.name} item) { - return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config), ApiVersionUtil.apiGroup(item, "$apiGroupName"), ApiVersionUtil.apiVersion(item, "$apiGroupVersion"), namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).fromServer().get(); + return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config)).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).fromServer().get(); } @Override @@ -90,26 +92,26 @@ public class ${model.name}Handler implements ResourceHandler<${model.name}, ${mo @Override public Boolean delete(OkHttpClient client, Config config, String namespace, ${model.name} item) { - return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config),ApiVersionUtil. apiGroup(item, "$apiGroupName"), ApiVersionUtil.apiVersion(item, "$apiGroupVersion"), namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).delete(item); + return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config)).withItem(item).inNamespace(namespace).delete(item); } @Override public Watch watch(OkHttpClient client, Config config, String namespace, ${model.name} item, Watcher<${model.name}> watcher) { - return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config), ApiVersionUtil.apiGroup(item, "$apiGroupName"), ApiVersionUtil.apiVersion(item, "$apiGroupVersion"), namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).watch(watcher); + return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config)).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).watch(watcher); } @Override public Watch watch(OkHttpClient client, Config config, String namespace, ${model.name} item, String resourceVersion, Watcher<${model.name}> watcher) { - return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config), ApiVersionUtil.apiGroup(item, "$apiGroupName"), ApiVersionUtil.apiVersion(item, "$apiGroupVersion"), namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).watch(resourceVersion, watcher); + return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config)).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).watch(resourceVersion, watcher); } @Override public ${model.name} waitUntilReady(OkHttpClient client, Config config, String namespace, ${model.name} item, long amount, TimeUnit timeUnit) throws InterruptedException { - return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config), ApiVersionUtil.apiGroup(item, "$apiGroupName"), ApiVersionUtil.apiVersion(item, "$apiGroupVersion"), namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).waitUntilReady(amount, timeUnit); + return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config)).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).waitUntilReady(amount, timeUnit); } @Override public ${model.name} waitUntilCondition(OkHttpClient client, Config config, String namespace, ${model.name} item, Predicate<${model.name}> condition, long amount, TimeUnit timeUnit) throws InterruptedException { - return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config), ApiVersionUtil.apiGroup(item, "$apiGroupName"), ApiVersionUtil.apiVersion(item, "$apiGroupVersion"), namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).waitUntilCondition(condition, amount, timeUnit); + return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config)).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).waitUntilCondition(condition, amount, timeUnit); } } diff --git a/openshift-client/src/main/resources/resource-operation.vm b/openshift-client/src/main/resources/resource-operation.vm index cd4558be60c..924d22c8a90 100644 --- a/openshift-client/src/main/resources/resource-operation.vm +++ b/openshift-client/src/main/resources/resource-operation.vm @@ -49,6 +49,8 @@ import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; import io.fabric8.kubernetes.client.utils.ApiVersionUtil; +import io.fabric8.kubernetes.client.dsl.base.OperationContext; +import io.fabric8.openshift.client.OpenShiftConfig; import okhttp3.OkHttpClient; @@ -63,21 +65,20 @@ import java.util.TreeMap; public class ${model.name}OperationsImpl extends OpenShiftOperation<${model.name}, ${model.name}List, Doneable${model.name}, Resource<${model.name}, Doneable${model.name}>> { - public ${model.name}OperationsImpl(OkHttpClient client, OpenShiftConfig config, String namespace) { - this(client, config, "$apiGroupName", "$apiGroupVersion", namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); - } - - public ${model.name}OperationsImpl(OkHttpClient client, OpenShiftConfig config, String apiGroupName, String apiGroupVersion, String namespace, String name, Boolean cascading, ${model.name} item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { - super(client, OpenShiftOperation.withApiGroup(client, apiGroupName, apiGroupVersion, config), "#pluralize ($model.name.toLowerCase())", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + public ${model.name}OperationsImpl(OkHttpClient client, OpenShiftConfig config) { + this(new OperationContext().withOkhttpClient(client).withConfig(config)); } - @Override - public NonNamespaceOperation<${model.name}, ${model.name}List, Doneable${model.name}, Resource<${model.name}, Doneable${model.name}>> inNamespace(String namespace) { - return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); + public ${model.name}OperationsImpl(OperationContext context) { + super(context.withApiGroupName("$apiGroupName") + .withApiGroupVersion("$apiGroupVersion") + .withPlural("#pluralize ($model.name.toLowerCase())")); + this.type = ${model.name}.class; + this.listType = ${model.name}List.class; + this.doneableType = Doneable${model.name}.class; } - @Override - public Resource<${model.name}, Doneable${model.name}> withName(String name) { - return new ${model.name}OperationsImpl(client, OpenShiftConfig.wrap(config), apiGroupName, apiGroupVersion, namespace, name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); + public ${model.name}OperationsImpl newInstance(OperationContext context) { + return new ${model.name}OperationsImpl(context); } } diff --git a/openshift-server-mock/src/main/java/io/fabric8/openshift/client/server/mock/OpenShiftServer.java b/openshift-server-mock/src/main/java/io/fabric8/openshift/client/server/mock/OpenShiftServer.java index 79a394ef4b2..a6ae06e03e9 100644 --- a/openshift-server-mock/src/main/java/io/fabric8/openshift/client/server/mock/OpenShiftServer.java +++ b/openshift-server-mock/src/main/java/io/fabric8/openshift/client/server/mock/OpenShiftServer.java @@ -25,6 +25,7 @@ import io.fabric8.openshift.client.NamespacedOpenShiftClient; import io.fabric8.openshift.client.OpenshiftAdapterSupport; import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; import org.junit.rules.ExternalResource; import java.util.HashMap; @@ -90,4 +91,13 @@ public void expectAndReturnAsString(String path, int code, String body) { public MockWebServer getMockServer() { return mock.getServer(); } + + public RecordedRequest getLastRequest() throws InterruptedException { + int count = mock.getServer().getRequestCount(); + RecordedRequest request = null; + while (count-- > 0) { + request = mock.getServer().takeRequest(); + } + return request; + } }