Skip to content

Commit

Permalink
apacheGH-2902: FusekiServerCtl - Code for server on-disk state
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Dec 23, 2024
1 parent 371d3f2 commit 00ca131
Show file tree
Hide file tree
Showing 34 changed files with 346 additions and 313 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import io.micrometer.core.instrument.MeterRegistry;
import org.apache.jena.fuseki.Fuseki;
import org.apache.jena.fuseki.metrics.prometheus.PrometheusMetricsProvider;
import org.apache.jena.fuseki.server.DataAccessPointRegistry;

public class MetricsProviderRegistry {
Expand Down Expand Up @@ -65,4 +66,8 @@ public static void dataAccessPointMetrics(DataAccessPointRegistry dapRegistry) {
Fuseki.configLog.error("Failed to bind all data access points to Prometheus", th);
}
}

public static void reset() {
set(new PrometheusMetricsProvider());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class InitPrometheus implements JenaSubsystemLifecycle {

@Override
public void start() {
MetricsProviderRegistry.set(new PrometheusMetricsProvider());
MetricsProviderRegistry.reset();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static UploadDetails incomingData(HttpAction action, StreamRDF dest) {

// Previously, Jena has used HttpServletRequests.getParts.
// Each application server (Tomcat and Jetty) has special configuration.
// Use Apache Commons FileUpload as the mulipart parser as it is portable.
// Use Apache Commons FileUpload as the multipart parser as it is portable.

/**
* Process an HTTP upload of RDF files (triples or quads) with content type
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,11 @@ protected void processModulesAndArgs() {

private void processStdArguments(Logger log) {

// ---- Definition type
// ---- Command line definition of setup
// One dataset
// or a config file
// or a "standard setup" e.g.SPARQLer
// or empty allowed
int numDefinitions = 0;
SetupType setup = UNSET;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package org.apache.jena.fuseki.main.cmds;

import org.apache.jena.fuseki.run.FusekiModServer;
import org.apache.jena.fuseki.mod.FusekiModServer;
import org.apache.jena.fuseki.system.FusekiLogging;

/** Fuseki command that runs a Fuseki server with the admin UI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ private void setDiscovery() {
* This step does not create the module objects.
*/
private ServiceLoader<FusekiAutoModule> discover() {
// Look for the 4.8.0 name (FusekiModule) which (4.9.0) is split into
// FusekiModule (interface) and FusekiAutoModule (this is loaded by ServiceLoader)
// Remove sometime!
discoveryWarnLegacy();

Class<FusekiAutoModule> moduleClass = FusekiAutoModule.class;
ServiceLoader<FusekiAutoModule> newServiceLoader = null;
synchronized (this) {
Expand All @@ -168,18 +163,6 @@ private ServiceLoader<FusekiAutoModule> discover() {
return newServiceLoader;
}

private void discoveryWarnLegacy() {
Class<FusekiModule> moduleClass = FusekiModule.class;
try {
ServiceLoader<FusekiModule> newServiceLoader = ServiceLoader.load(moduleClass, this.getClass().getClassLoader());
newServiceLoader.stream().forEach(provider->{
FmtLog.warn(FusekiAutoModules.class, "Ignored: \"%s\" : legacy use of interface FusekiModule which has changed to FusekiAutoModule", provider.type().getSimpleName());
});
} catch (ServiceConfigurationError ex) {
// Ignore - we were only checking.
}
}

/**
* Instantiate modules found using the ServiceLoader.
* Each call to {@code load()} creates a new object for the FusekiModule.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public void execute(HttpAction action) {
};

private JsonValue description(HttpAction action) {
if ( ! Files.isDirectory(FusekiApp.dirBackups) )
ServletOps.errorOccurred(format("[%d] Backup area '%s' is not a directory", action.id, FusekiApp.dirBackups));
if ( ! Files.isDirectory(FusekiServerCtl.dirBackups) )
ServletOps.errorOccurred(format("[%d] Backup area '%s' is not a directory", action.id, FusekiServerCtl.dirBackups));

List<Path> paths = new ArrayList<>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(FusekiApp.dirBackups, filterVisibleFiles)) {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(FusekiServerCtl.dirBackups, filterVisibleFiles)) {
stream.forEach(paths::add);
} catch (IOException ex) {
action.log.error(format("[%d] Backup file list :: IOException :: %s", action.id, ex.getMessage()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ else if ( WebContent.isMultiPartForm(ct) )
// ----
// Keep a persistent copy immediately. This is not used for
// anything other than being "for the record".
systemFileCopy = FusekiApp.dirSystemFileArea.resolve(uuid.toString()).toString();
systemFileCopy = FusekiServerCtl.dirSystemFileArea.resolve(uuid.toString()).toString();
try ( OutputStream outCopy = IO.openOutputFile(systemFileCopy) ) {
RDFDataMgr.write(outCopy, descriptionModel, Lang.TURTLE);
}
Expand Down Expand Up @@ -186,8 +186,8 @@ else if ( WebContent.isMultiPartForm(ct) )

action.log.info(format("[%d] Create database : name = %s", action.id, datasetPath));

configFile = FusekiApp.generateConfigurationFilename(datasetPath);
List<String> existing = FusekiApp.existingConfigurationFile(datasetPath);
configFile = FusekiServerCtl.generateConfigurationFilename(datasetPath);
List<String> existing = FusekiServerCtl.existingConfigurationFile(datasetPath);
if ( ! existing.isEmpty() )
ServletOps.error(HttpSC.CONFLICT_409, "Configuration file for '"+datasetPath+"' already exists");

Expand Down Expand Up @@ -318,7 +318,7 @@ protected void execDeleteItem(HttpAction action) {

// Find the configuration.
String filename = name.startsWith("/") ? name.substring(1) : name;
List<String> configurationFiles = FusekiApp.existingConfigurationFile(filename);
List<String> configurationFiles = FusekiServerCtl.existingConfigurationFile(filename);

if ( configurationFiles.isEmpty() ) {
// ---- Unmanaged
Expand Down Expand Up @@ -352,7 +352,7 @@ protected void execDeleteItem(HttpAction action) {
boolean isTDB1 = org.apache.jena.tdb1.sys.TDBInternal.isTDB1(dataService.getDataset());
boolean isTDB2 = org.apache.jena.tdb2.sys.TDBInternal.isTDB2(dataService.getDataset());

// TODO This occasionally fails in tests due to outstanding transactions.
// This occasionally fails in tests due to outstanding transactions.
try {
dataService.shutdown();
} catch (JenaException ex) {
Expand All @@ -363,7 +363,7 @@ protected void execDeleteItem(HttpAction action) {
// Delete databases created by the UI, or the admin operation, which are
// in predictable, unshared location on disk.
// There may not be any database files, the in-memory case.
Path pDatabase = FusekiApp.dirDatabases.resolve(filename);
Path pDatabase = FusekiServerCtl.dirDatabases.resolve(filename);
if ( Files.exists(pDatabase)) {
try {
if ( Files.isSymbolicLink(pDatabase)) {
Expand Down Expand Up @@ -411,7 +411,7 @@ private static void assemblerFromForm(HttpAction action, StreamRDF dest) {
params.put(Template.NAME, dbName.substring(1));
else
params.put(Template.NAME, dbName);
FusekiApp.addGlobals(params);
FusekiServerCtl.addGlobals(params);

//action.log.info(format("[%d] Create database : name = %s, type = %s", action.id, dbName, dbType ));

Expand All @@ -430,36 +430,6 @@ private static void assemblerFromUpload(HttpAction action, StreamRDF dest) {
DataUploader.incomingData(action, dest);
}

// [ADMIN]
// // Persistent state change.
// private static void setDatasetState(String name, Resource newState) {
// boolean committed = false;
// system.begin(ReadWrite.WRITE);
// try {
// String dbName = name;
// if ( dbName.startsWith("/") )
// dbName = dbName.substring(1);
//
// String update = StrUtils.strjoinNL
// (PREFIXES,
// "DELETE { GRAPH ?g { ?s fu:status ?state } }",
// "INSERT { GRAPH ?g { ?s fu:status "+FmtUtils.stringForRDFNode(newState)+" } }",
// "WHERE {",
// " GRAPH ?g { ?s fu:name '"+dbName+"'; ",
// " fu:status ?state .",
// " }",
// "}"
// );
// UpdateRequest req = UpdateFactory.create(update);
// UpdateAction.execute(req, system);
// system.commit();
// committed = true;
// } finally {
// if ( ! committed ) system.abort();
// system.end();
// }
// }

// ---- Auxiliary functions

private static Quad getOne(DatasetGraph dsg, Node g, Node s, Node p, Node o) {
Expand All @@ -482,8 +452,6 @@ private static Statement getOne(Model m, Resource s, Property p, RDFNode o) {
return stmt;
}

// TODO Merge with Upload.incomingData

private static void bodyAsGraph(HttpAction action, StreamRDF dest) {
HttpServletRequest request = action.getRequest();
String base = ActionLib.wholeRequestURL(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static String chooseFileName(String dsName) {

String timestamp = DateTimeUtils.nowAsString("yyyy-MM-dd_HH-mm-ss");
String filename = ds + "_" + timestamp;
filename = FusekiApp.dirBackups.resolve(filename).toString();
filename = FusekiServerCtl.dirBackups.resolve(filename).toString();
return filename;
}

Expand Down
Loading

0 comments on commit 00ca131

Please sign in to comment.