Skip to content

Commit f6a60f7

Browse files
authored
Enable spotless for enrich gradle project in 7 dot 5 branch. (#48977)
Backport of #48908 The enrich project doesn't have much history as all the other gradle projects, so it makes sense to enable spotless for this gradle project. Also: * restructure xcontent mapping code to be more readable with new code style. * Applied codestyle after code style update.
1 parent 3067147 commit f6a60f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2077
-1220
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ subprojects {
106106
// is greater than the number of unformatted projects, this can be
107107
// switched to an exclude list, and eventualy removed completely.
108108
def projectPathsToFormat = [
109-
// ':build-tools'
109+
':x-pack:plugin:enrich'
110110
]
111111

112112
if (projectPathsToFormat.contains(project.path)) {

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/AbstractEnrichProcessor.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,31 @@ public abstract class AbstractEnrichProcessor extends AbstractProcessor {
3535
protected final String matchField;
3636
protected final int maxMatches;
3737

38-
protected AbstractEnrichProcessor(String tag, Client client, String policyName, String field, String targetField,
39-
boolean ignoreMissing, boolean overrideEnabled, String matchField, int maxMatches) {
38+
protected AbstractEnrichProcessor(
39+
String tag,
40+
Client client,
41+
String policyName,
42+
String field,
43+
String targetField,
44+
boolean ignoreMissing,
45+
boolean overrideEnabled,
46+
String matchField,
47+
int maxMatches
48+
) {
4049
this(tag, createSearchRunner(client), policyName, field, targetField, ignoreMissing, overrideEnabled, matchField, maxMatches);
4150
}
4251

43-
protected AbstractEnrichProcessor(String tag,
44-
BiConsumer<SearchRequest, BiConsumer<SearchResponse, Exception>> searchRunner,
45-
String policyName, String field, String targetField, boolean ignoreMissing, boolean overrideEnabled,
46-
String matchField, int maxMatches) {
52+
protected AbstractEnrichProcessor(
53+
String tag,
54+
BiConsumer<SearchRequest, BiConsumer<SearchResponse, Exception>> searchRunner,
55+
String policyName,
56+
String field,
57+
String targetField,
58+
boolean ignoreMissing,
59+
boolean overrideEnabled,
60+
String matchField,
61+
int maxMatches
62+
) {
4763
super(tag);
4864
this.policyName = policyName;
4965
this.searchRunner = searchRunner;
@@ -155,13 +171,11 @@ int getMaxMatches() {
155171

156172
private static BiConsumer<SearchRequest, BiConsumer<SearchResponse, Exception>> createSearchRunner(Client client) {
157173
return (req, handler) -> {
158-
client.execute(EnrichCoordinatorProxyAction.INSTANCE, req, ActionListener.wrap(
159-
resp -> {
160-
handler.accept(resp, null);
161-
},
162-
e -> {
163-
handler.accept(null, e);
164-
}));
174+
client.execute(
175+
EnrichCoordinatorProxyAction.INSTANCE,
176+
req,
177+
ActionListener.wrap(resp -> { handler.accept(resp, null); }, e -> { handler.accept(null, e); })
178+
);
165179
};
166180
}
167181
}

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichMetadata.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
109109

110110
@Override
111111
public boolean equals(Object o) {
112-
if (this == o) return true;
113-
if (o == null || getClass() != o.getClass()) return false;
112+
if (this == o)
113+
return true;
114+
if (o == null || getClass() != o.getClass())
115+
return false;
114116
EnrichMetadata that = (EnrichMetadata) o;
115117
return policies.equals(that.policies);
116118
}

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java

Lines changed: 79 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -70,33 +70,57 @@
7070

7171
public class EnrichPlugin extends Plugin implements ActionPlugin, IngestPlugin {
7272

73-
static final Setting<Integer> ENRICH_FETCH_SIZE_SETTING =
74-
Setting.intSetting("enrich.fetch_size", 10000, 1, 1000000, Setting.Property.NodeScope);
73+
static final Setting<Integer> ENRICH_FETCH_SIZE_SETTING = Setting.intSetting(
74+
"enrich.fetch_size",
75+
10000,
76+
1,
77+
1000000,
78+
Setting.Property.NodeScope
79+
);
7580

76-
static final Setting<Integer> ENRICH_MAX_CONCURRENT_POLICY_EXECUTIONS =
77-
Setting.intSetting("enrich.max_concurrent_policy_executions", 50, 1, Setting.Property.NodeScope);
81+
static final Setting<Integer> ENRICH_MAX_CONCURRENT_POLICY_EXECUTIONS = Setting.intSetting(
82+
"enrich.max_concurrent_policy_executions",
83+
50,
84+
1,
85+
Setting.Property.NodeScope
86+
);
7887

79-
static final Setting<TimeValue> ENRICH_CLEANUP_PERIOD =
80-
Setting.timeSetting("enrich.cleanup_period", new TimeValue(15, TimeUnit.MINUTES), Setting.Property.NodeScope);
88+
static final Setting<TimeValue> ENRICH_CLEANUP_PERIOD = Setting.timeSetting(
89+
"enrich.cleanup_period",
90+
new TimeValue(15, TimeUnit.MINUTES),
91+
Setting.Property.NodeScope
92+
);
8193

82-
public static final Setting<Integer> COORDINATOR_PROXY_MAX_CONCURRENT_REQUESTS =
83-
Setting.intSetting("enrich.coordinator_proxy.max_concurrent_requests", 8, 1, 10000, Setting.Property.NodeScope);
94+
public static final Setting<Integer> COORDINATOR_PROXY_MAX_CONCURRENT_REQUESTS = Setting.intSetting(
95+
"enrich.coordinator_proxy.max_concurrent_requests",
96+
8,
97+
1,
98+
10000,
99+
Setting.Property.NodeScope
100+
);
84101

85-
public static final Setting<Integer> COORDINATOR_PROXY_MAX_LOOKUPS_PER_REQUEST =
86-
Setting.intSetting("enrich.coordinator_proxy.max_lookups_per_request", 128, 1, 10000, Setting.Property.NodeScope);
102+
public static final Setting<Integer> COORDINATOR_PROXY_MAX_LOOKUPS_PER_REQUEST = Setting.intSetting(
103+
"enrich.coordinator_proxy.max_lookups_per_request",
104+
128,
105+
1,
106+
10000,
107+
Setting.Property.NodeScope
108+
);
87109

88-
static final Setting<Integer> ENRICH_MAX_FORCE_MERGE_ATTEMPTS =
89-
Setting.intSetting("enrich.max_force_merge_attempts", 3, 1, 10, Setting.Property.NodeScope);
110+
static final Setting<Integer> ENRICH_MAX_FORCE_MERGE_ATTEMPTS = Setting.intSetting(
111+
"enrich.max_force_merge_attempts",
112+
3,
113+
1,
114+
10,
115+
Setting.Property.NodeScope
116+
);
90117

91118
private static final String QUEUE_CAPACITY_SETTING_NAME = "enrich.coordinator_proxy.queue_capacity";
92-
public static final Setting<Integer> COORDINATOR_PROXY_QUEUE_CAPACITY = new Setting<>(QUEUE_CAPACITY_SETTING_NAME,
93-
settings -> {
94-
int maxConcurrentRequests = COORDINATOR_PROXY_MAX_CONCURRENT_REQUESTS.get(settings);
95-
int maxLookupsPerRequest = COORDINATOR_PROXY_MAX_LOOKUPS_PER_REQUEST.get(settings);
96-
return String.valueOf(maxConcurrentRequests * maxLookupsPerRequest);
97-
},
98-
val -> Setting.parseInt(val, 1, Integer.MAX_VALUE, QUEUE_CAPACITY_SETTING_NAME),
99-
Setting.Property.NodeScope);
119+
public static final Setting<Integer> COORDINATOR_PROXY_QUEUE_CAPACITY = new Setting<>(QUEUE_CAPACITY_SETTING_NAME, settings -> {
120+
int maxConcurrentRequests = COORDINATOR_PROXY_MAX_CONCURRENT_REQUESTS.get(settings);
121+
int maxLookupsPerRequest = COORDINATOR_PROXY_MAX_LOOKUPS_PER_REQUEST.get(settings);
122+
return String.valueOf(maxConcurrentRequests * maxLookupsPerRequest);
123+
}, val -> Setting.parseInt(val, 1, Integer.MAX_VALUE, QUEUE_CAPACITY_SETTING_NAME), Setting.Property.NodeScope);
100124

101125
private final Settings settings;
102126
private final Boolean enabled;
@@ -119,7 +143,9 @@ public Map<String, Processor.Factory> getProcessors(Processor.Parameters paramet
119143
return Collections.singletonMap(EnrichProcessorFactory.TYPE, factory);
120144
}
121145

122-
protected XPackLicenseState getLicenseState() { return XPackPlugin.getSharedLicenseState(); }
146+
protected XPackLicenseState getLicenseState() {
147+
return XPackPlugin.getSharedLicenseState();
148+
}
123149

124150
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
125151
if (enabled == false) {
@@ -138,10 +164,15 @@ public Map<String, Processor.Factory> getProcessors(Processor.Parameters paramet
138164
);
139165
}
140166

141-
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
142-
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter,
143-
IndexNameExpressionResolver indexNameExpressionResolver,
144-
Supplier<DiscoveryNodes> nodesInCluster) {
167+
public List<RestHandler> getRestHandlers(
168+
Settings settings,
169+
RestController restController,
170+
ClusterSettings clusterSettings,
171+
IndexScopedSettings indexScopedSettings,
172+
SettingsFilter settingsFilter,
173+
IndexNameExpressionResolver indexNameExpressionResolver,
174+
Supplier<DiscoveryNodes> nodesInCluster
175+
) {
145176
if (enabled == false) {
146177
return emptyList();
147178
}
@@ -156,17 +187,29 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
156187
}
157188

158189
@Override
159-
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool,
160-
ResourceWatcherService resourceWatcherService, ScriptService scriptService,
161-
NamedXContentRegistry xContentRegistry, Environment environment,
162-
NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry) {
190+
public Collection<Object> createComponents(
191+
Client client,
192+
ClusterService clusterService,
193+
ThreadPool threadPool,
194+
ResourceWatcherService resourceWatcherService,
195+
ScriptService scriptService,
196+
NamedXContentRegistry xContentRegistry,
197+
Environment environment,
198+
NodeEnvironment nodeEnvironment,
199+
NamedWriteableRegistry namedWriteableRegistry
200+
) {
163201
if (enabled == false || transportClientMode) {
164202
return emptyList();
165203
}
166204

167205
EnrichPolicyLocks enrichPolicyLocks = new EnrichPolicyLocks();
168-
EnrichPolicyMaintenanceService enrichPolicyMaintenanceService = new EnrichPolicyMaintenanceService(settings, client,
169-
clusterService, threadPool, enrichPolicyLocks);
206+
EnrichPolicyMaintenanceService enrichPolicyMaintenanceService = new EnrichPolicyMaintenanceService(
207+
settings,
208+
client,
209+
clusterService,
210+
threadPool,
211+
enrichPolicyLocks
212+
);
170213
enrichPolicyMaintenanceService.initialize();
171214
return Arrays.asList(
172215
enrichPolicyLocks,
@@ -188,8 +231,11 @@ public Collection<Module> createGuiceModules() {
188231
public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
189232
return Arrays.asList(
190233
new NamedWriteableRegistry.Entry(MetaData.Custom.class, EnrichMetadata.TYPE, EnrichMetadata::new),
191-
new NamedWriteableRegistry.Entry(NamedDiff.class, EnrichMetadata.TYPE,
192-
in -> EnrichMetadata.readDiffFrom(MetaData.Custom.class, EnrichMetadata.TYPE, in))
234+
new NamedWriteableRegistry.Entry(
235+
NamedDiff.class,
236+
EnrichMetadata.TYPE,
237+
in -> EnrichMetadata.readDiffFrom(MetaData.Custom.class, EnrichMetadata.TYPE, in)
238+
)
193239
);
194240
}
195241

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyExecutor.java

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ public class EnrichPolicyExecutor {
4343
private final int maxForceMergeAttempts;
4444
private final Semaphore policyExecutionPermits;
4545

46-
public EnrichPolicyExecutor(Settings settings,
47-
ClusterService clusterService,
48-
Client client,
49-
TaskManager taskManager,
50-
ThreadPool threadPool,
51-
IndexNameExpressionResolver indexNameExpressionResolver,
52-
EnrichPolicyLocks policyLocks,
53-
LongSupplier nowSupplier) {
46+
public EnrichPolicyExecutor(
47+
Settings settings,
48+
ClusterService clusterService,
49+
Client client,
50+
TaskManager taskManager,
51+
ThreadPool threadPool,
52+
IndexNameExpressionResolver indexNameExpressionResolver,
53+
EnrichPolicyLocks policyLocks,
54+
LongSupplier nowSupplier
55+
) {
5456
this.clusterService = clusterService;
5557
this.client = client;
5658
this.taskManager = taskManager;
@@ -69,8 +71,14 @@ private void tryLockingPolicy(String policyName) {
6971
if (policyExecutionPermits.tryAcquire() == false) {
7072
// Release policy lock, and throw a different exception
7173
policyLocks.releasePolicy(policyName);
72-
throw new EsRejectedExecutionException("Policy execution failed. Policy execution for [" + policyName + "] would exceed " +
73-
"maximum concurrent policy executions [" + maximumConcurrentPolicyExecutions + "]");
74+
throw new EsRejectedExecutionException(
75+
"Policy execution failed. Policy execution for ["
76+
+ policyName
77+
+ "] would exceed "
78+
+ "maximum concurrent policy executions ["
79+
+ maximumConcurrentPolicyExecutions
80+
+ "]"
81+
);
7482
}
7583
}
7684

@@ -88,8 +96,12 @@ private class PolicyCompletionListener implements ActionListener<ExecuteEnrichPo
8896
private final BiConsumer<Task, ExecuteEnrichPolicyStatus> onResponse;
8997
private final BiConsumer<Task, Exception> onFailure;
9098

91-
PolicyCompletionListener(String policyName, ExecuteEnrichPolicyTask task,
92-
BiConsumer<Task, ExecuteEnrichPolicyStatus> onResponse, BiConsumer<Task, Exception> onFailure) {
99+
PolicyCompletionListener(
100+
String policyName,
101+
ExecuteEnrichPolicyTask task,
102+
BiConsumer<Task, ExecuteEnrichPolicyStatus> onResponse,
103+
BiConsumer<Task, Exception> onFailure
104+
) {
93105
this.policyName = policyName;
94106
this.task = task;
95107
this.onResponse = onResponse;
@@ -120,10 +132,24 @@ public void onFailure(Exception e) {
120132
}
121133
}
122134

123-
protected Runnable createPolicyRunner(String policyName, EnrichPolicy policy, ExecuteEnrichPolicyTask task,
124-
ActionListener<ExecuteEnrichPolicyStatus> listener) {
125-
return new EnrichPolicyRunner(policyName, policy, task, listener, clusterService, client, indexNameExpressionResolver, nowSupplier,
126-
fetchSize, maxForceMergeAttempts);
135+
protected Runnable createPolicyRunner(
136+
String policyName,
137+
EnrichPolicy policy,
138+
ExecuteEnrichPolicyTask task,
139+
ActionListener<ExecuteEnrichPolicyStatus> listener
140+
) {
141+
return new EnrichPolicyRunner(
142+
policyName,
143+
policy,
144+
task,
145+
listener,
146+
clusterService,
147+
client,
148+
indexNameExpressionResolver,
149+
nowSupplier,
150+
fetchSize,
151+
maxForceMergeAttempts
152+
);
127153
}
128154

129155
private EnrichPolicy getPolicy(ExecuteEnrichPolicyAction.Request request) {
@@ -143,18 +169,28 @@ public Task runPolicy(ExecuteEnrichPolicyAction.Request request, TaskListener<Ex
143169
return runPolicy(request, getPolicy(request), listener);
144170
}
145171

146-
public Task runPolicy(ExecuteEnrichPolicyAction.Request request, EnrichPolicy policy,
147-
ActionListener<ExecuteEnrichPolicyStatus> listener) {
172+
public Task runPolicy(
173+
ExecuteEnrichPolicyAction.Request request,
174+
EnrichPolicy policy,
175+
ActionListener<ExecuteEnrichPolicyStatus> listener
176+
) {
148177
return runPolicy(request, policy, (t, r) -> listener.onResponse(r), (t, e) -> listener.onFailure(e));
149178
}
150179

151-
public Task runPolicy(ExecuteEnrichPolicyAction.Request request, EnrichPolicy policy,
152-
TaskListener<ExecuteEnrichPolicyStatus> listener) {
180+
public Task runPolicy(
181+
ExecuteEnrichPolicyAction.Request request,
182+
EnrichPolicy policy,
183+
TaskListener<ExecuteEnrichPolicyStatus> listener
184+
) {
153185
return runPolicy(request, policy, listener::onResponse, listener::onFailure);
154186
}
155187

156-
private Task runPolicy(ExecuteEnrichPolicyAction.Request request, EnrichPolicy policy,
157-
BiConsumer<Task, ExecuteEnrichPolicyStatus> onResponse, BiConsumer<Task, Exception> onFailure) {
188+
private Task runPolicy(
189+
ExecuteEnrichPolicyAction.Request request,
190+
EnrichPolicy policy,
191+
BiConsumer<Task, ExecuteEnrichPolicyStatus> onResponse,
192+
BiConsumer<Task, Exception> onFailure
193+
) {
158194
tryLockingPolicy(request.getName());
159195
try {
160196
return runPolicyTask(request, policy, onResponse, onFailure);
@@ -165,8 +201,12 @@ private Task runPolicy(ExecuteEnrichPolicyAction.Request request, EnrichPolicy p
165201
}
166202
}
167203

168-
private Task runPolicyTask(final ExecuteEnrichPolicyAction.Request request, EnrichPolicy policy,
169-
BiConsumer<Task, ExecuteEnrichPolicyStatus> onResponse, BiConsumer<Task, Exception> onFailure) {
204+
private Task runPolicyTask(
205+
final ExecuteEnrichPolicyAction.Request request,
206+
EnrichPolicy policy,
207+
BiConsumer<Task, ExecuteEnrichPolicyStatus> onResponse,
208+
BiConsumer<Task, Exception> onFailure
209+
) {
170210
Task asyncTask = taskManager.register("enrich", TASK_ACTION, new TaskAwareRequest() {
171211
@Override
172212
public void setParentTask(TaskId taskId) {

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyLocks.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ public void lockPolicy(String policyName) {
7070
Semaphore runLock = policyLocks.computeIfAbsent(policyName, (name) -> new Semaphore(1));
7171
boolean acquired = runLock.tryAcquire();
7272
if (acquired == false) {
73-
throw new EsRejectedExecutionException("Could not obtain lock because policy execution for [" + policyName +
74-
"] is already in progress.");
73+
throw new EsRejectedExecutionException(
74+
"Could not obtain lock because policy execution for [" + policyName + "] is already in progress."
75+
);
7576
}
7677
policyRunCounter.incrementAndGet();
7778
} finally {
@@ -105,8 +106,7 @@ public EnrichPolicyExecutionState captureExecutionState() {
105106
*/
106107
boolean isSameState(EnrichPolicyExecutionState previousState) {
107108
EnrichPolicyExecutionState currentState = captureExecutionState();
108-
return currentState.anyPolicyInFlight == previousState.anyPolicyInFlight &&
109-
currentState.executions == previousState.executions;
109+
return currentState.anyPolicyInFlight == previousState.anyPolicyInFlight && currentState.executions == previousState.executions;
110110
}
111111

112112
/**

0 commit comments

Comments
 (0)