Skip to content

Commit 5a160df

Browse files
committed
fixup! GH-4952 - Introduce FedXConfig overrides for FedXRepositoryConfig
1 parent 07ca160 commit 5a160df

6 files changed

Lines changed: 249 additions & 342 deletions

File tree

tools/federation/src/main/java/org/eclipse/rdf4j/federated/repository/FedXConfigParser.java

Lines changed: 0 additions & 129 deletions
This file was deleted.

tools/federation/src/main/java/org/eclipse/rdf4j/federated/repository/FedXRepositoryConfig.java

Lines changed: 105 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import org.eclipse.rdf4j.federated.FedXConfig;
1616
import org.eclipse.rdf4j.federated.util.Vocabulary.FEDX;
17+
import org.eclipse.rdf4j.model.BNode;
1718
import org.eclipse.rdf4j.model.IRI;
1819
import org.eclipse.rdf4j.model.Model;
1920
import org.eclipse.rdf4j.model.Resource;
@@ -23,6 +24,7 @@
2324
import org.eclipse.rdf4j.model.impl.TreeModel;
2425
import org.eclipse.rdf4j.model.util.ModelException;
2526
import org.eclipse.rdf4j.model.util.Models;
27+
import org.eclipse.rdf4j.model.util.Values;
2628
import org.eclipse.rdf4j.repository.config.AbstractRepositoryImplConfig;
2729
import org.eclipse.rdf4j.repository.config.RepositoryConfigException;
2830
import org.eclipse.rdf4j.repository.config.RepositoryImplConfig;
@@ -103,6 +105,36 @@ public class FedXRepositoryConfig extends AbstractRepositoryImplConfig {
103105
*/
104106
public static final IRI MEMBER = vf.createIRI(NAMESPACE, "member");
105107

108+
/**
109+
* IRI of the property populating {@link FedXConfig#getEnforceMaxQueryTime()}
110+
*/
111+
public static final IRI CONFIG_ENFORCE_MAX_QUERY_TIME = vf.createIRI(NAMESPACE, "enforceMaxQueryTime");
112+
113+
/**
114+
* IRI of the property populating {@link FedXConfig#isEnableMonitoring()}
115+
*/
116+
public static final IRI CONFIG_ENABLE_MONITORING = vf.createIRI(NAMESPACE, "enableMonitoring");
117+
118+
/**
119+
* IRI of the property populating {@link FedXConfig#isLogQueryPlan()}
120+
*/
121+
public static final IRI CONFIG_LOG_QUERY_PLAN = vf.createIRI(NAMESPACE, "logQueryPlan");
122+
123+
/**
124+
* IRI of the property populating {@link FedXConfig#isDebugQueryPlan()}
125+
*/
126+
public static final IRI CONFIG_DEBUG_QUERY_PLAN = vf.createIRI(NAMESPACE, "debugQueryPlan");
127+
128+
/**
129+
* IRI of the property populating {@link FedXConfig#isLogQueries()}
130+
*/
131+
public static final IRI CONFIG_LOG_QUERIES = vf.createIRI(NAMESPACE, "logQueries");
132+
133+
/**
134+
* IRI of the property populating {@link FedXConfig#getSourceSelectionCacheSpec()}
135+
*/
136+
public static final IRI CONFIG_SOURCE_SELECTION_CACHE_SPEC = vf.createIRI(NAMESPACE, "sourceSelectionCacheSpec");
137+
106138
/**
107139
* the location of the data configuration
108140
*/
@@ -163,10 +195,7 @@ public Resource export(Model m) {
163195
m.add(implNode, DATA_CONFIG, vf.createLiteral(getDataConfig()));
164196
}
165197

166-
if (getConfig() != null) {
167-
Resource confNode = FedXConfigParser.export(getConfig(), m);
168-
m.add(implNode, FEDX_CONFIG, confNode);
169-
}
198+
exportFedXConfig(m, implNode);
170199

171200
if (getMembers() != null) {
172201

@@ -203,13 +232,7 @@ public void parse(Model m, Resource implNode) throws RepositoryConfigException {
203232
Models.objectLiteral(m.getStatements(implNode, DATA_CONFIG, null))
204233
.ifPresent(value -> setDataConfig(value.stringValue()));
205234

206-
Models.objectResource(m.getStatements(implNode, FEDX_CONFIG, null))
207-
.ifPresent(res -> {
208-
if (getConfig() == null) {
209-
setConfig(new FedXConfig());
210-
}
211-
setConfig(FedXConfigParser.parse(getConfig(), m, res));
212-
});
235+
parseFedXConfig(m, implNode);
213236

214237
Set<Value> memberNodes = m.filter(implNode, MEMBER, null).objects();
215238
if (!memberNodes.isEmpty()) {
@@ -229,4 +252,75 @@ public void parse(Model m, Resource implNode) throws RepositoryConfigException {
229252
throw new RepositoryConfigException(e.getMessage(), e);
230253
}
231254
}
255+
256+
/**
257+
* Updates the container {@link FedXConfig} instance with properties from the supplied model. It is up to the caller
258+
* to retrieve configuration from {@link #FEDX_CONFIG} as well as to initialise the parsed configuration (via
259+
* {@link #setConfig(FedXConfig)}) since it can be null.
260+
*
261+
* @param m the model from which to read configuration properties
262+
* @param implNode the subject against which to expect the {@link #FEDX_CONFIG} property.
263+
*
264+
* @throws RepositoryConfigException if any of the overridden fields are deemed to be invalid
265+
*/
266+
protected void parseFedXConfig(Model m, Resource implNode) throws RepositoryConfigException {
267+
Models.objectResource(m.getStatements(implNode, FEDX_CONFIG, null))
268+
.ifPresent(res -> parseFedXConfigInternal(m, res));
269+
}
270+
271+
private void parseFedXConfigInternal(Model m, Resource confNode) throws RepositoryConfigException {
272+
if (getConfig() == null) {
273+
setConfig(new FedXConfig());
274+
}
275+
276+
Models.objectLiteral(m.getStatements(confNode, CONFIG_ENFORCE_MAX_QUERY_TIME, null))
277+
.ifPresent(value -> config.withEnforceMaxQueryTime(value.intValue()));
278+
279+
Models.objectLiteral(m.getStatements(confNode, CONFIG_ENABLE_MONITORING, null))
280+
.ifPresent(value -> config.withEnableMonitoring(value.booleanValue()));
281+
282+
Models.objectLiteral(m.getStatements(confNode, CONFIG_LOG_QUERY_PLAN, null))
283+
.ifPresent(value -> config.withLogQueryPlan(value.booleanValue()));
284+
285+
Models.objectLiteral(m.getStatements(confNode, CONFIG_DEBUG_QUERY_PLAN, null))
286+
.ifPresent(value -> config.withDebugQueryPlan(value.booleanValue()));
287+
288+
Models.objectLiteral(m.getStatements(confNode, CONFIG_LOG_QUERIES, null))
289+
.ifPresent(value -> config.withLogQueries(value.booleanValue()));
290+
291+
Models.objectLiteral(m.getStatements(confNode, CONFIG_SOURCE_SELECTION_CACHE_SPEC, null))
292+
.ifPresent(value -> config.withSourceSelectionCacheSpec(value.stringValue()));
293+
}
294+
295+
/**
296+
* Export the provided {@link FedXConfig} to its RDF representation. Note that {@link #getConfig()} could be null if
297+
* configuration has not been set yet.
298+
*
299+
* @param config the configuration to export
300+
* @param implNode the node to which to write the config reference (i.e. {@link #FEDX_CONFIG}) to
301+
*/
302+
protected void exportFedXConfig(Model model, Resource implNode) {
303+
if (getConfig() == null) {
304+
return;
305+
}
306+
307+
BNode confNode = Values.bnode();
308+
309+
model.add(confNode, CONFIG_ENFORCE_MAX_QUERY_TIME, vf.createLiteral(config.getEnforceMaxQueryTime()));
310+
311+
model.add(confNode, CONFIG_ENABLE_MONITORING, vf.createLiteral(config.isEnableMonitoring()));
312+
313+
model.add(confNode, CONFIG_LOG_QUERY_PLAN, vf.createLiteral(config.isLogQueryPlan()));
314+
315+
model.add(confNode, CONFIG_DEBUG_QUERY_PLAN, vf.createLiteral(config.isDebugQueryPlan()));
316+
317+
model.add(confNode, CONFIG_LOG_QUERIES, vf.createLiteral(config.isLogQueries()));
318+
319+
if (config.getSourceSelectionCacheSpec() != null) {
320+
model.add(confNode, CONFIG_SOURCE_SELECTION_CACHE_SPEC,
321+
vf.createLiteral(config.getSourceSelectionCacheSpec()));
322+
}
323+
324+
model.add(implNode, FEDX_CONFIG, confNode);
325+
}
232326
}

0 commit comments

Comments
 (0)