Skip to content

Commit 100f1fc

Browse files
committed
add ProjectIdBridge
1 parent e8e349f commit 100f1fc

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.logstashbridge.common;
11+
12+
import org.elasticsearch.cluster.metadata.ProjectId;
13+
import org.elasticsearch.logstashbridge.StableBridgeAPI;
14+
15+
public interface ProjectIdBridge extends StableBridgeAPI<ProjectId> {
16+
String id();
17+
18+
static ProjectIdBridge fromInternal(final ProjectId projectId) {
19+
return new ProxyInternal(projectId);
20+
}
21+
22+
static ProjectIdBridge fromId(final String id) {
23+
final ProjectId internal = ProjectId.fromId(id);
24+
return new ProxyInternal(internal);
25+
}
26+
27+
static ProjectIdBridge getDefault() {
28+
return ProxyInternal.DEFAULT;
29+
}
30+
31+
class ProxyInternal implements ProjectIdBridge {
32+
private final ProjectId internalDelegate;
33+
34+
static final ProjectIdBridge.ProxyInternal DEFAULT = new ProjectIdBridge.ProxyInternal(ProjectId.DEFAULT);
35+
36+
public ProxyInternal(ProjectId internalDelegate) {
37+
this.internalDelegate = internalDelegate;
38+
}
39+
40+
@Override
41+
public String id() {
42+
return toInternal().id();
43+
}
44+
45+
@Override
46+
public ProjectId toInternal() {
47+
return this.internalDelegate;
48+
}
49+
}
50+
}

libs/logstash-bridge/src/main/java/org/elasticsearch/logstashbridge/ingest/ProcessorBridge.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.ingest.IngestService;
1616
import org.elasticsearch.ingest.Processor;
1717
import org.elasticsearch.logstashbridge.StableBridgeAPI;
18+
import org.elasticsearch.logstashbridge.common.ProjectIdBridge;
1819
import org.elasticsearch.logstashbridge.env.EnvironmentBridge;
1920
import org.elasticsearch.logstashbridge.script.ScriptServiceBridge;
2021
import org.elasticsearch.logstashbridge.threadpool.ThreadPoolBridge;
@@ -178,22 +179,23 @@ public Processor.Parameters toInternal() {
178179
* An external bridge for {@link Processor.Factory}
179180
*/
180181
interface Factory extends StableBridgeAPI<Processor.Factory> {
181-
@Deprecated // supply ProjectId
182+
183+
@Deprecated // supply ProjectIdBridge
182184
default ProcessorBridge create(
183185
Map<String, ProcessorBridge.Factory> registry,
184186
String processorTag,
185187
String description,
186188
Map<String, Object> config
187189
) throws Exception {
188-
return this.create(registry, processorTag, description, config, ProjectId.DEFAULT);
190+
return this.create(registry, processorTag, description, config, ProjectIdBridge.getDefault());
189191
}
190192

191193
ProcessorBridge create(
192194
Map<String, ProcessorBridge.Factory> registry,
193195
String processorTag,
194196
String description,
195197
Map<String, Object> config,
196-
ProjectId projectId
198+
ProjectIdBridge projectId
197199
) throws Exception;
198200

199201
static Factory fromInternal(final Processor.Factory delegate) {
@@ -218,10 +220,11 @@ public ProcessorBridge create(
218220
final String processorTag,
219221
final String description,
220222
final Map<String, Object> config,
221-
final ProjectId projectId
223+
final ProjectIdBridge bridgedProjectId
222224
) throws Exception {
223225
final Map<String, Processor.Factory> internalRegistry = StableBridgeAPI.toInternal(registry);
224226
final Processor.Factory internalFactory = toInternal();
227+
final ProjectId projectId = bridgedProjectId.toInternal();
225228
final Processor internalProcessor = internalFactory.create(internalRegistry, processorTag, description, config, projectId);
226229
return ProcessorBridge.fromInternal(internalProcessor);
227230
}
@@ -260,14 +263,15 @@ public Processor create(
260263
) throws Exception {
261264
final Map<String, ProcessorBridge.Factory> bridgedProcessorFactories = StableBridgeAPI.fromInternal(
262265
processorFactories,
263-
ProcessorBridge.Factory.ProxyInternal::new
266+
ProcessorBridge.Factory::fromInternal
264267
);
268+
final ProjectIdBridge bridgedProjectId = ProjectIdBridge.fromInternal(projectId);
265269
final ProcessorBridge bridgedProcessor = AbstractExternal.this.create(
266270
bridgedProcessorFactories,
267271
tag,
268272
description,
269273
config,
270-
projectId
274+
bridgedProjectId
271275
);
272276
return bridgedProcessor.toInternal();
273277
}

0 commit comments

Comments
 (0)