-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
OperationContext.java
executable file
·362 lines (286 loc) · 17.3 KB
/
OperationContext.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/**
* 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 java.util.HashMap;
import java.util.Map;
import io.fabric8.kubernetes.api.model.DeletionPropagation;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.dsl.Waitable;
import io.fabric8.kubernetes.client.utils.ApiVersionUtil;
import io.fabric8.kubernetes.client.utils.Utils;
import okhttp3.OkHttpClient;
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;
// Default to -1 to respect the value set in the resource or the Kubernetes default (30 seconds)
protected long gracePeriodSeconds = -1L;
protected DeletionPropagation propagationPolicy;
protected long watchRetryInitialBackoffMillis = Waitable.DEFAULT_INITIAL_BACKOFF_MILLIS;
protected double watchRetryBackoffMultiplier = Waitable.DEFAULT_BACKOFF_MULTIPLIER;
protected Map<String, String> labels;
protected Map<String, String[]> labelsNot;
protected Map<String, String[]> labelsIn;
protected Map<String, String[]> labelsNotIn;
protected Map<String, String> fields;
protected Map<String, String[]> fieldsNot;
public OperationContext() {
}
public OperationContext(OkHttpClient client, Config config, String plural, String namespace, String name, String apiGroupName, String apiGroupVersion, boolean cascading, Object item, Map<String, String> labels, Map<String, String[]> labelsNot, Map<String, String[]> labelsIn, Map<String, String[]> labelsNotIn, Map<String, String> fields, Map<String, String[]> fieldsNot, String resourceVersion, boolean reloadingFromServer, long gracePeriodSeconds, DeletionPropagation propagationPolicy, long watchRetryInitialBackoffMillis, double watchRetryBackoffMultiplier) {
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.fieldsNot = fieldsNot != null ? fieldsNot : new HashMap<>();
this.resourceVersion = resourceVersion;
this.reloadingFromServer = reloadingFromServer;
this.gracePeriodSeconds = gracePeriodSeconds;
this.propagationPolicy = propagationPolicy;
this.watchRetryInitialBackoffMillis = watchRetryInitialBackoffMillis;
this.watchRetryBackoffMultiplier = watchRetryBackoffMultiplier;
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<String, String> getLabels() {
return labels;
}
public Map<String, String[]> getLabelsNot() {
return labelsNot;
}
public Map<String, String[]> getLabelsIn() {
return labelsIn;
}
public Map<String, String[]> getLabelsNotIn() {
return labelsNotIn;
}
public Map<String, String> getFields() {
return fields;
}
public Map<String, String[]> getFieldsNot() {
return fieldsNot;
}
public String getResourceVersion() {
return resourceVersion;
}
public boolean getReloadingFromServer() {
return reloadingFromServer;
}
public long getGracePeriodSeconds() {
return gracePeriodSeconds;
}
public DeletionPropagation getPropagationPolicy() {
return propagationPolicy;
}
public long getWatchRetryInitialBackoffMillis() {
return watchRetryInitialBackoffMillis;
}
public double getWatchRetryBackoffMultiplier() {
return watchRetryBackoffMultiplier;
}
public OperationContext withOkhttpClient(OkHttpClient client) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading, item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withConfig(Config config) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withPlural(String plural) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withNamespace(String namespace) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withName(String name) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withApiGroupName(String apiGroupName) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withApiGroupVersion(String apiGroupVersion) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withItem(Object item) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withCascading(boolean cascading) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withLabels(Map<String, String> labels) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withLabelsIn(Map<String, String[]> labelsIn) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withLabelsNot(Map<String, String[]> labelsNot) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withLabelsNotIn(Map<String, String[]> labelsNotIn) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withFields(Map<String, String> fields) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withFieldsNot(Map<String, String[]> fieldsNot) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withResourceVersion(String resourceVersion) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withReloadingFromServer(boolean reloadingFromServer) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withGracePeriodSeconds(long gracePeriodSeconds) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withPropagationPolicy(DeletionPropagation propagationPolicy) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withWatchRetryInitialBackoffMillis(long watchRetryInitialBackoffMillis) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
public OperationContext withWatchRetryBackoffMultiplier(double watchRetryBackoffMultiplier) {
return new OperationContext(client, config, plural, namespace, name, apiGroupName, apiGroupVersion, cascading,item, labels, labelsNot, labelsIn, labelsNotIn, fields, fieldsNot, resourceVersion, reloadingFromServer, gracePeriodSeconds, propagationPolicy, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
/**
* Returns an OperationContext object merged with current object
*
* @param operationContext object with modifications
* @return a merged object between passed argument and current object
*/
public OperationContext withOperationContext(OperationContext operationContext) {
OkHttpClient clientCloned = getClient();
Config configCloned = getConfig();
Object itemCloned = getItem();
String resourceVersionCloned = getResourceVersion();
String pluralCloned = getPlural();
String apiGroupNameCloned = getApiGroupName();
String apiGroupVersionCloned = getApiGroupVersion();
String namespaceCloned = getNamespace();
String nameCloned = getName();
boolean cascadingCloned = getCascading();
boolean reloadingFromServerCloned = getReloadingFromServer();
long gracePeriodSecondsCloned = getGracePeriodSeconds();
long watchRetryInitialBackoffMillis = getWatchRetryInitialBackoffMillis();
double watchRetryBackoffMultiplier = getWatchRetryBackoffMultiplier();
DeletionPropagation propagationPolicyCloned = getPropagationPolicy();
Map<String, String> labelsCloned = getLabels();
Map<String, String[]> labelsNotCloned = getLabelsNot();
Map<String, String[]> labelsInCloned = getLabelsIn();
Map<String, String[]> labelsNotInCloned = getLabelsNotIn();
Map<String, String> fieldsCloned = getFields();
Map<String, String[]> fieldsNotCloned = getFieldsNot();
if (operationContext.getApiGroupVersion() != null) {
apiGroupVersionCloned = operationContext.getApiGroupVersion();
}
if (operationContext.getClient() != null) {
clientCloned = operationContext.getClient();
}
if (operationContext.getConfig() != null) {
configCloned = operationContext.getConfig();
}
if (operationContext.getPlural() != null) {
pluralCloned = operationContext.getPlural();
}
if (operationContext.getNamespace() != null) {
namespaceCloned = operationContext.getNamespace();
}
if (operationContext.getName() != null) {
nameCloned = operationContext.getName();
}
if (operationContext.getApiGroupName() != null) {
apiGroupNameCloned = operationContext.getApiGroupName();
}
if (operationContext.getCascading()) {
cascadingCloned = operationContext.getCascading();
}
if (operationContext.getItem() != null) {
itemCloned = operationContext.getItem();
}
if (operationContext.getLabels() != null) {
labelsCloned = operationContext.getLabels();
}
if (operationContext.getLabelsNot() != null) {
labelsNotCloned = operationContext.getLabelsNot();
}
if (operationContext.getLabelsIn() != null) {
labelsInCloned = operationContext.getLabelsIn();
}
if (operationContext.getLabelsNotIn() != null) {
labelsNotInCloned = operationContext.getLabelsNotIn();
}
if (operationContext.getFields() != null) {
fieldsCloned = operationContext.getFields();
}
if (operationContext.getFieldsNot() != null) {
fieldsNotCloned = operationContext.getFieldsNot();
}
if (operationContext.getResourceVersion() != null) {
resourceVersionCloned = operationContext.getResourceVersion();
}
if (operationContext.getReloadingFromServer()) {
reloadingFromServerCloned = operationContext.getReloadingFromServer();
}
if (operationContext.getGracePeriodSeconds() > 0) {
gracePeriodSecondsCloned = operationContext.getGracePeriodSeconds();
}
if (operationContext.getPropagationPolicy() != null) {
propagationPolicyCloned = operationContext.getPropagationPolicy();
}
return new OperationContext(clientCloned, configCloned, pluralCloned, namespaceCloned, nameCloned, apiGroupNameCloned, apiGroupVersionCloned, cascadingCloned, itemCloned, labelsCloned, labelsNotCloned, labelsInCloned, labelsNotInCloned, fieldsCloned, fieldsNotCloned, resourceVersionCloned, reloadingFromServerCloned, gracePeriodSecondsCloned, propagationPolicyCloned, watchRetryInitialBackoffMillis, watchRetryBackoffMultiplier);
}
}