Skip to content

Commit bd791cf

Browse files
metacosmcsviri
authored andcommitted
chore(docs): add some javadoc (#2452)
Signed-off-by: Chris Laprun <[email protected]>
1 parent 4d6ac48 commit bd791cf

File tree

11 files changed

+224
-86
lines changed

11 files changed

+224
-86
lines changed

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/AbstractConfigurationService.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import io.javaoperatorsdk.operator.ReconcilerUtils;
1111
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
1212

13+
/**
14+
* An abstract implementation of {@link ConfigurationService} meant to ease custom implementations
15+
*/
1316
@SuppressWarnings("rawtypes")
1417
public class AbstractConfigurationService implements ConfigurationService {
1518
private final Map<String, ControllerConfiguration> configurations = new ConcurrentHashMap<>();
@@ -18,11 +21,11 @@ public class AbstractConfigurationService implements ConfigurationService {
1821
private Cloner cloner;
1922
private ExecutorServiceManager executorServiceManager;
2023

21-
public AbstractConfigurationService(Version version) {
24+
protected AbstractConfigurationService(Version version) {
2225
this(version, null);
2326
}
2427

25-
public AbstractConfigurationService(Version version, Cloner cloner) {
28+
protected AbstractConfigurationService(Version version, Cloner cloner) {
2629
this(version, cloner, null, null);
2730
}
2831

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java

+109-57
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,68 @@ public interface ConfigurationService {
3333
Logger log = LoggerFactory.getLogger(ConfigurationService.class);
3434

3535
int DEFAULT_MAX_CONCURRENT_REQUEST = 512;
36+
/**
37+
* The default numbers of concurrent reconciliations
38+
*/
39+
int DEFAULT_RECONCILIATION_THREADS_NUMBER = 50;
40+
/**
41+
* The default number of threads used to process dependent workflows
42+
*/
43+
int DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = DEFAULT_RECONCILIATION_THREADS_NUMBER;
44+
45+
/**
46+
* Creates a new {@link ConfigurationService} instance used to configure an
47+
* {@link io.javaoperatorsdk.operator.Operator} instance, starting from the specified base
48+
* configuration and overriding specific aspects according to the provided
49+
* {@link ConfigurationServiceOverrider} instance.
50+
*
51+
* <p>
52+
* <em>NOTE:</em> This overriding mechanism should only be used <strong>before</strong> creating
53+
* your Operator instance as the configuration service is set at creation time and cannot be
54+
* subsequently changed. As a result, overriding values this way after the Operator has been
55+
* configured will not take effect.
56+
* </p>
57+
*
58+
* @param baseConfiguration the {@link ConfigurationService} to start from
59+
* @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided
60+
* by the base configuration
61+
* @return a new {@link ConfigurationService} starting from the configuration provided as base but
62+
* with overridden values.
63+
*/
64+
static ConfigurationService newOverriddenConfigurationService(
65+
ConfigurationService baseConfiguration,
66+
Consumer<ConfigurationServiceOverrider> overrider) {
67+
if (overrider != null) {
68+
final var toOverride = new ConfigurationServiceOverrider(baseConfiguration);
69+
overrider.accept(toOverride);
70+
return toOverride.build();
71+
}
72+
return baseConfiguration;
73+
}
74+
75+
/**
76+
* Creates a new {@link ConfigurationService} instance used to configure an
77+
* {@link io.javaoperatorsdk.operator.Operator} instance, starting from the default configuration
78+
* and overriding specific aspects according to the provided {@link ConfigurationServiceOverrider}
79+
* instance.
80+
*
81+
* <p>
82+
* <em>NOTE:</em> This overriding mechanism should only be used <strong>before</strong> creating
83+
* your Operator instance as the configuration service is set at creation time and cannot be
84+
* subsequently changed. As a result, overriding values this way after the Operator has been
85+
* configured will not take effect.
86+
* </p>
87+
*
88+
* @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided
89+
* by the default configuration
90+
* @return a new {@link ConfigurationService} overriding the default values with the ones provided
91+
* by the specified {@link ConfigurationServiceOverrider}
92+
* @since 4.4.0
93+
*/
94+
static ConfigurationService newOverriddenConfigurationService(
95+
Consumer<ConfigurationServiceOverrider> overrider) {
96+
return newOverriddenConfigurationService(new BaseConfigurationService(), overrider);
97+
}
3698

3799
/**
38100
* Retrieves the configuration associated with the specified reconciler
@@ -44,7 +106,6 @@ public interface ConfigurationService {
44106
*/
45107
<R extends HasMetadata> ControllerConfiguration<R> getConfigurationFor(Reconciler<R> reconciler);
46108

47-
48109
/**
49110
* Used to clone custom resources.
50111
*
@@ -128,8 +189,6 @@ default boolean checkCRDAndValidateLocalModel() {
128189
return false;
129190
}
130191

131-
int DEFAULT_RECONCILIATION_THREADS_NUMBER = 50;
132-
133192
/**
134193
* The number of threads the operator can spin out to dispatch reconciliation requests to
135194
* reconcilers with the default executors
@@ -140,8 +199,6 @@ default int concurrentReconciliationThreads() {
140199
return DEFAULT_RECONCILIATION_THREADS_NUMBER;
141200
}
142201

143-
int DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = DEFAULT_RECONCILIATION_THREADS_NUMBER;
144-
145202
/**
146203
* Number of threads the operator can spin out to be used in the workflows with the default
147204
* executor.
@@ -152,27 +209,64 @@ default int concurrentWorkflowExecutorThreads() {
152209
return DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER;
153210
}
154211

212+
/**
213+
* Override to provide a custom {@link Metrics} implementation
214+
*
215+
* @return the {@link Metrics} implementation
216+
*/
155217
default Metrics getMetrics() {
156218
return Metrics.NOOP;
157219
}
158220

221+
/**
222+
* Override to provide a custom {@link ExecutorService} implementation to change how threads
223+
* handle concurrent reconciliations
224+
*
225+
* @return the {@link ExecutorService} implementation to use for concurrent reconciliation
226+
* processing
227+
*/
159228
default ExecutorService getExecutorService() {
160229
return Executors.newFixedThreadPool(concurrentReconciliationThreads());
161230
}
162231

232+
/**
233+
* Override to provide a custom {@link ExecutorService} implementation to change how dependent
234+
* workflows are processed in parallel
235+
*
236+
* @return the {@link ExecutorService} implementation to use for dependent workflow processing
237+
*/
163238
default ExecutorService getWorkflowExecutorService() {
164239
return Executors.newFixedThreadPool(concurrentWorkflowExecutorThreads());
165240
}
166241

242+
/**
243+
* Determines whether the associated Kubernetes client should be closed when the associated
244+
* {@link io.javaoperatorsdk.operator.Operator} is stopped.
245+
*
246+
* @return {@code true} if the Kubernetes should be closed on stop, {@code false} otherwise
247+
*/
167248
default boolean closeClientOnStop() {
168249
return true;
169250
}
170251

252+
/**
253+
* Override to provide a custom {@link DependentResourceFactory} implementation to change how
254+
* {@link io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource} are instantiated
255+
*
256+
* @return the custom {@link DependentResourceFactory} implementation
257+
*/
171258
@SuppressWarnings("rawtypes")
172259
default DependentResourceFactory dependentResourceFactory() {
173260
return DependentResourceFactory.DEFAULT;
174261
}
175262

263+
/**
264+
* Retrieves the optional {@link LeaderElectionConfiguration} to specify how the associated
265+
* {@link io.javaoperatorsdk.operator.Operator} handles leader election to ensure only one
266+
* instance of the operator runs on the cluster at any given time
267+
*
268+
* @return the {@link LeaderElectionConfiguration}
269+
*/
176270
default Optional<LeaderElectionConfiguration> getLeaderElectionConfiguration() {
177271
return Optional.empty();
178272
}
@@ -228,65 +322,23 @@ default Optional<InformerStoppedHandler> getInformerStoppedHandler() {
228322
});
229323
}
230324

325+
/**
326+
* Override to provide a custom {@link ManagedWorkflowFactory} implementation to change how
327+
* {@link io.javaoperatorsdk.operator.processing.dependent.workflow.ManagedWorkflow} are
328+
* instantiated
329+
*
330+
* @return the custom {@link ManagedWorkflowFactory} implementation
331+
*/
231332
@SuppressWarnings("rawtypes")
232333
default ManagedWorkflowFactory getWorkflowFactory() {
233334
return ManagedWorkflowFactory.DEFAULT;
234335
}
235336

236337
/**
237-
* Creates a new {@link ConfigurationService} instance used to configure an
238-
* {@link io.javaoperatorsdk.operator.Operator} instance, starting from the specified base
239-
* configuration and overriding specific aspects according to the provided
240-
* {@link ConfigurationServiceOverrider} instance.
241-
*
242-
* <p>
243-
* <em>NOTE:</em> This overriding mechanism should only be used <strong>before</strong> creating
244-
* your Operator instance as the configuration service is set at creation time and cannot be
245-
* subsequently changed. As a result, overriding values this way after the Operator has been
246-
* configured will not take effect.
247-
* </p>
248-
*
249-
* @param baseConfiguration the {@link ConfigurationService} to start from
250-
* @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided
251-
* by the base configuration
252-
* @return a new {@link ConfigurationService} starting from the configuration provided as base but
253-
* with overridden values.
254-
*/
255-
static ConfigurationService newOverriddenConfigurationService(
256-
ConfigurationService baseConfiguration,
257-
Consumer<ConfigurationServiceOverrider> overrider) {
258-
if (overrider != null) {
259-
final var toOverride = new ConfigurationServiceOverrider(baseConfiguration);
260-
overrider.accept(toOverride);
261-
return toOverride.build();
262-
}
263-
return baseConfiguration;
264-
}
265-
266-
/**
267-
* Creates a new {@link ConfigurationService} instance used to configure an
268-
* {@link io.javaoperatorsdk.operator.Operator} instance, starting from the default configuration
269-
* and overriding specific aspects according to the provided {@link ConfigurationServiceOverrider}
270-
* instance.
271-
*
272-
* <p>
273-
* <em>NOTE:</em> This overriding mechanism should only be used <strong>before</strong> creating
274-
* your Operator instance as the configuration service is set at creation time and cannot be
275-
* subsequently changed. As a result, overriding values this way after the Operator has been
276-
* configured will not take effect.
277-
* </p>
278-
*
279-
* @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided
280-
* by the default configuration
281-
* @return a new {@link ConfigurationService} overriding the default values with the ones provided
282-
* by the specified {@link ConfigurationServiceOverrider}
283-
* @since 4.4.0
338+
* Override to provide a custom {@link ExecutorServiceManager} implementation
339+
*
340+
* @return the custom {@link ExecutorServiceManager} implementation
284341
*/
285-
static ConfigurationService newOverriddenConfigurationService(
286-
Consumer<ConfigurationServiceOverrider> overrider) {
287-
return newOverriddenConfigurationService(new BaseConfigurationService(), overrider);
288-
}
289-
290342
default ExecutorServiceManager getExecutorServiceManager() {
291343
return new ExecutorServiceManager(this);
292344
}

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java

+23-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
*/
1616
public interface DependentResource<R, P extends HasMetadata> {
1717

18+
/**
19+
* Computes a default name for the specified DependentResource class
20+
*
21+
* @param dependentResourceClass the DependentResource class for which we want to compute a
22+
* default name
23+
* @return the default name for the specified DependentResource class
24+
*/
25+
@SuppressWarnings("rawtypes")
26+
static String defaultNameFor(Class<? extends DependentResource> dependentResourceClass) {
27+
return dependentResourceClass.getName();
28+
}
29+
1830
/**
1931
* Reconciles the dependent resource given the desired primary state
2032
*
@@ -65,21 +77,23 @@ default Optional<R> getSecondaryResource(P primary, Context<P> context) {
6577
}
6678

6779
/**
68-
* Computes a default name for the specified DependentResource class
80+
* Determines whether resources associated with this dependent need explicit handling when
81+
* deleted, usually meaning that the dependent implements {@link Deleter}
6982
*
70-
* @param dependentResourceClass the DependentResource class for which we want to compute a
71-
* default name
72-
* @return the default name for the specified DependentResource class
83+
* @return {@code true} if explicit handling of resource deletion is needed, {@link false}
84+
* otherwise
7385
*/
74-
@SuppressWarnings("rawtypes")
75-
static String defaultNameFor(Class<? extends DependentResource> dependentResourceClass) {
76-
return dependentResourceClass.getName();
77-
}
78-
7986
default boolean isDeletable() {
8087
return this instanceof Deleter;
8188
}
8289

90+
91+
/**
92+
* Retrieves the name identifying this DependentResource implementation, useful to refer to this
93+
* in {@link io.javaoperatorsdk.operator.processing.dependent.workflow.Workflow} instances
94+
*
95+
* @return the name identifying this DependentResource implementation
96+
*/
8397
default String name() {
8498
return defaultNameFor(getClass());
8599
}

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/EventSourceHealthIndicator.java

+7
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,12 @@
22

33
public interface EventSourceHealthIndicator {
44

5+
/**
6+
* Retrieves the health status of an
7+
* {@link io.javaoperatorsdk.operator.processing.event.source.EventSource}
8+
*
9+
* @return the health status
10+
* @see Status
11+
*/
512
Status getStatus();
613
}

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/Status.java

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.javaoperatorsdk.operator.health;
22

3+
/**
4+
* The health status of an {@link io.javaoperatorsdk.operator.processing.event.source.EventSource}
5+
*/
36
public enum Status {
47

58
HEALTHY, UNHEALTHY,

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
import io.javaoperatorsdk.operator.processing.dependent.Matcher.Result;
1717
import io.javaoperatorsdk.operator.processing.event.ResourceID;
1818

19+
/**
20+
* An abstract implementation of {@link DependentResource} to be used as base for custom
21+
* implementations, providing, in particular, the core {@link #reconcile(HasMetadata, Context)}
22+
* logic for dependents
23+
*
24+
* @param <R> the dependent resource type
25+
* @param <P> the associated primary resource type
26+
*/
1927
@Ignore
2028
public abstract class AbstractDependentResource<R, P extends HasMetadata>
2129
implements DependentResource<R, P>, NameSetter {
@@ -24,18 +32,16 @@ public abstract class AbstractDependentResource<R, P extends HasMetadata>
2432
private final boolean creatable = this instanceof Creator;
2533
private final boolean updatable = this instanceof Updater;
2634
private final boolean deletable = this instanceof Deleter;
27-
35+
private final DependentResourceReconciler<R, P> dependentResourceReconciler;
2836
protected Creator<R, P> creator;
2937
protected Updater<R, P> updater;
30-
private final DependentResourceReconciler<R, P> dependentResourceReconciler;
31-
3238
protected String name;
3339

34-
@SuppressWarnings({"unchecked"})
3540
protected AbstractDependentResource() {
3641
this(null);
3742
}
3843

44+
@SuppressWarnings("unchecked")
3945
protected AbstractDependentResource(String name) {
4046
creator = creatable ? (Creator<R, P>) this : null;
4147
updater = updatable ? (Updater<R, P>) this : null;
@@ -120,7 +126,8 @@ public Optional<R> getSecondaryResource(P primary, Context<P> context) {
120126
* secondary candidates for equality with the specified desired state, which might end up costly.
121127
*
122128
* @param secondaryResources to select the target resource from
123-
*
129+
* @param primary the primary resource
130+
* @param context the context in which this method is called
124131
* @return the matching secondary resource or {@link Optional#empty()} if none matches
125132
* @throws IllegalStateException if more than one candidate is found, in which case some other
126133
* mechanism might be necessary to distinguish between candidate secondary resources

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResource.java

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
* dependent resource is to manage the number of secondary resources dynamically it implement
1313
* {@link Creator} and {@link Deleter} interfaces out of the box. A concrete dependent resource can
1414
* implement additionally also {@link Updater}.
15+
*
16+
* @param <R> the dependent resource type
17+
* @param <P> the primary resource type
1518
*/
1619
public interface BulkDependentResource<R, P extends HasMetadata> {
1720

0 commit comments

Comments
 (0)