jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [6/8] jena git commit: JENA-1464: Refactor Fuseki configuration processing.
Date Sat, 13 Jan 2018 10:52:51 GMT
JENA-1464: Refactor Fuseki configuration processing.


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/64fe8bd9
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/64fe8bd9
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/64fe8bd9

Branch: refs/heads/master
Commit: 64fe8bd9161bed88150e330d8808ed45ce35d957
Parents: 65d4295
Author: Andy Seaborne <andy@apache.org>
Authored: Fri Jan 12 15:18:43 2018 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Fri Jan 12 16:01:38 2018 +0000

----------------------------------------------------------------------
 .../jena/sparql/util/graph/GraphUtils.java      |  9 ++--
 .../apache/jena/fuseki/build/FusekiConfig.java  | 51 ++++++--------------
 .../apache/jena/fuseki/mgt/ActionDatasets.java  |  2 +-
 .../apache/jena/fuseki/server/FusekiSystem.java | 29 +++--------
 .../jena/fuseki/embedded/FusekiServer.java      | 28 ++++++++---
 5 files changed, 51 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/64fe8bd9/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/GraphUtils.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/GraphUtils.java b/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/GraphUtils.java
index d82dfeb..ce0243e 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/GraphUtils.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/GraphUtils.java
@@ -173,13 +173,16 @@ public class GraphUtils {
             return null ;
         return s.getResource() ;
     }
+    
+    public static List<Resource> listResourcesByType(Model model, Resource type) {
+        return Iter.toList(model.listSubjectsWithProperty(RDF.type, type)) ;
+    }
 
     public static Resource getResourceByType(Model model, Resource type) {
-        // See also
-        StmtIterator sIter = model.listStatements(null, RDF.type, type) ;
+        ResIterator sIter = model.listSubjectsWithProperty(RDF.type, type) ;
         if ( !sIter.hasNext() )
             return null ;
-        Resource r = sIter.nextStatement().getSubject() ;
+        Resource r = sIter.next();
         if ( sIter.hasNext() )
             throw new TypeNotUniqueException(r) ;
         return r ;

http://git-wip-us.apache.org/repos/asf/jena/blob/64fe8bd9/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/build/FusekiConfig.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/build/FusekiConfig.java
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/build/FusekiConfig.java
index 6e64632..614b721 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/build/FusekiConfig.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/build/FusekiConfig.java
@@ -33,7 +33,6 @@ import java.util.Collections ;
 import java.util.List ;
 
 import org.apache.jena.assembler.JA ;
-import org.apache.jena.atlas.iterator.Iter ;
 import org.apache.jena.atlas.lib.IRILib ;
 import org.apache.jena.atlas.lib.StrUtils ;
 import org.apache.jena.fuseki.Fuseki ;
@@ -47,7 +46,7 @@ import org.apache.jena.query.ResultSet ;
 import org.apache.jena.rdf.model.* ;
 import org.apache.jena.riot.Lang;
 import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
-import org.apache.jena.vocabulary.RDF ;
+import org.apache.jena.sparql.util.graph.GraphUtils;
 import org.slf4j.Logger ;
 
 public class FusekiConfig {
@@ -55,19 +54,13 @@ public class FusekiConfig {
     
     private static Logger log = Fuseki.configLog ;
     
-    /** Has side effects in server setup */
-    public static List<DataAccessPoint> readServerConfigFile(String filename) {
-        // Old-style config file.
-        Model model = readAssemblerFile(filename) ;
-        if ( model.size() == 0 )
-            return Collections.emptyList() ;
-        server(model) ;
-        return servicesAndDatasets(model) ;
-    }
-
-    private static void server(Model model) {
+    /** Process the server section, if any, of a configuration file.
+     * This includes setting global context and ja:loadClass.
+     * It does not include services - see {@link #servicesAndDatasets}
+     */ 
+    public static void processServerConfig(Model model) {
         // Find one server.
-        List<Resource> servers = getByType(FusekiVocab.tServer, model) ;
+        List<Resource> servers = GraphUtils.listResourcesByType(model, FusekiVocab.tServer)
;
         if ( servers.size() == 0 )
             return ; 
         if ( servers.size() > 1 )
@@ -106,9 +99,13 @@ public class FusekiConfig {
         }
     }
     
-    private static List<DataAccessPoint> servicesAndDatasets(Model model) {
+    /** Find and process datasets and services in a configuration file.
+     * This can be a Fuseki server configuration file or a services-only configuration file.
+     * It looks {@code fuseki:services ( .... )} then, if not found, all {@code rtdf:type
fuseki:services}. 
+     */
+    public static List<DataAccessPoint> servicesAndDatasets(Model model) {
         // Old style configuration file : server to services.
-        DatasetDescriptionRegistry dsDescMap = FusekiSystem.registryForBuild() ;
+        DatasetDescriptionRegistry dsDescMap = new DatasetDescriptionRegistry();
         // ---- Services
         ResultSet rs = FusekiLib.query("SELECT * { ?s fu:services [ list:member ?service
] }", model) ;
         List<DataAccessPoint> accessPoints = new ArrayList<>() ;
@@ -124,7 +121,6 @@ public class FusekiConfig {
             DataAccessPoint acc = FusekiBuilder.buildDataAccessPoint(svc, dsDescMap) ;
             accessPoints.add(acc) ;
         }
-        
         return accessPoints ;
     }
     
@@ -147,12 +143,6 @@ public class FusekiConfig {
         return AssemblerUtils.readAssemblerFile(filename) ;
     }
     
-    // XXX Move to a library
-    private static List<Resource> getByType(Resource type, Model m) {
-        ResIterator rIter = m.listSubjectsWithProperty(RDF.type, type) ;
-        return Iter.toList(rIter) ;
-    }
-    
     // ---- Directory of assemblers
     
     /** Read service descriptions in the given directory */ 
@@ -177,7 +167,7 @@ public class FusekiConfig {
         List<DataAccessPoint> dataServiceRef = new ArrayList<>() ;
         try (DirectoryStream<Path> stream = Files.newDirectoryStream(pDir, filter))
{
             for ( Path p : stream ) {
-                DatasetDescriptionRegistry dsDescMap = FusekiSystem.registryForBuild() ;
+                DatasetDescriptionRegistry dsDescMap = new DatasetDescriptionRegistry() ;
                 String fn = IRILib.filenameToIRI(p.toString()) ;
                 log.info("Load configuration: "+fn);
                 Model m = readAssemblerFile(fn) ;
@@ -189,21 +179,12 @@ public class FusekiConfig {
         return dataServiceRef ;
     }
 
-    /** Read and process one file */ 
-    public static  List<DataAccessPoint> readConfigurationFile(String fn) {
-        List<DataAccessPoint> acc = new ArrayList<>() ;
-        Model m = readAssemblerFile(fn) ;
-        DatasetDescriptionRegistry dsDescMap = new DatasetDescriptionRegistry() ;
-        readConfiguration(m, dsDescMap, acc) ;
-        return acc ;
-    }
-    
     /** Read a configuration in a model.
      * Allow dataset descriptions to be carried over from another place.
      * Add to a list. 
      */
     private static void readConfiguration(Model m, DatasetDescriptionRegistry dsDescMap,
List<DataAccessPoint> dataServiceRef) {
-        List<Resource> services = getByType(FusekiVocab.fusekiService, m) ; 
+        List<Resource> services = GraphUtils.listResourcesByType(m, FusekiVocab.fusekiService)
; 
 
         if ( services.size() == 0 ) {
             log.error("No services found") ;
@@ -219,7 +200,7 @@ public class FusekiConfig {
     // ---- System database
     /** Read the system database */
     public static List<DataAccessPoint> readSystemDatabase(Dataset ds) {
-        DatasetDescriptionRegistry dsDescMap = FusekiSystem.registryForBuild() ;
+        DatasetDescriptionRegistry dsDescMap = new DatasetDescriptionRegistry() ;
         String qs = StrUtils.strjoinNL
             (SystemState.PREFIXES ,
              "SELECT * {" ,

http://git-wip-us.apache.org/repos/asf/jena/blob/64fe8bd9/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
index d59ea66..85e84af 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
@@ -111,7 +111,7 @@ public class ActionDatasets extends ActionContainerItem {
     @Override
     protected JsonValue execPostContainer(HttpAction action) {
         JenaUUID uuid = JenaUUID.generate() ;
-        DatasetDescriptionRegistry registry = FusekiSystem.registryForBuild() ;
+        DatasetDescriptionRegistry registry = new DatasetDescriptionRegistry() ;
         
         ContentType ct = FusekiLib.getContentType(action) ;
         

http://git-wip-us.apache.org/repos/asf/jena/blob/64fe8bd9/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiSystem.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiSystem.java
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiSystem.java
index 78f6490..105f20a 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiSystem.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiSystem.java
@@ -45,6 +45,7 @@ import org.apache.jena.riot.Lang ;
 import org.apache.jena.riot.RDFDataMgr ;
 import org.apache.jena.riot.RDFLanguages ;
 import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.sparql.core.assembler.AssemblerUtils;
 import org.apache.jena.tdb.sys.Names ;
 
 public class FusekiSystem
@@ -257,12 +258,17 @@ public class FusekiSystem
             return Collections.emptyList(); 
         }
         Fuseki.configLog.info("Configuration file: " + configFilename) ;
-        return FusekiConfig.readServerConfigFile(configFilename) ;
+        //return FusekiConfig.readServerConfigFile(configFilename);
+        Model model = AssemblerUtils.readAssemblerFile(configFilename) ;
+        if ( model.size() == 0 )
+            return Collections.emptyList() ;
+        FusekiConfig.processServerConfig(model);
+        return FusekiConfig.servicesAndDatasets(model) ;
     }
     
     private static DataAccessPoint configFromTemplate(String templateFile, String datasetPath,

                                                       boolean allowUpdate, Map<String,
String> params) {
-        DatasetDescriptionRegistry registry = FusekiSystem.registryForBuild() ; 
+        DatasetDescriptionRegistry registry = new DatasetDescriptionRegistry() ; 
         // ---- Setup
         if ( params == null ) {
             params = new HashMap<>() ;
@@ -404,25 +410,6 @@ public class FusekiSystem
     }
 
     /**
-     * <ul>
-     * <li>GLOBAL: sharing across all descriptions
-     * <li>FILE: sharing within files but not across files.
-     * </ul>
-     */
-    enum DatasetDescriptionScope { GLOBAL, FILE }
-    private static DatasetDescriptionRegistry globalDatasets = new DatasetDescriptionRegistry()
;
-    private static DatasetDescriptionScope policyDatasetDescriptionScope = DatasetDescriptionScope.FILE
;
-    
-    /** Call this once per configuration file. */
-    public static DatasetDescriptionRegistry registryForBuild() {
-        switch (policyDatasetDescriptionScope) {
-            case FILE :     return new DatasetDescriptionRegistry() ;
-            case GLOBAL :   return globalDatasets ;
-            default:        throw new InternalErrorException() ;
-        }
-    }
-    
-    /**
      * Dataset set name to configuration file name. Return a configuration file name -
      * existing one or ".ttl" form if new
      */

http://git-wip-us.apache.org/repos/asf/jena/blob/64fe8bd9/jena-fuseki2/jena-fuseki-embedded/src/main/java/org/apache/jena/fuseki/embedded/FusekiServer.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-embedded/src/main/java/org/apache/jena/fuseki/embedded/FusekiServer.java
b/jena-fuseki2/jena-fuseki-embedded/src/main/java/org/apache/jena/fuseki/embedded/FusekiServer.java
index 5bc9102..c88509e 100644
--- a/jena-fuseki2/jena-fuseki-embedded/src/main/java/org/apache/jena/fuseki/embedded/FusekiServer.java
+++ b/jena-fuseki2/jena-fuseki-embedded/src/main/java/org/apache/jena/fuseki/embedded/FusekiServer.java
@@ -18,9 +18,12 @@
 
 package org.apache.jena.fuseki.embedded;
 
-import java.util.*;
 import static java.util.Objects.requireNonNull;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServlet;
 
@@ -32,16 +35,17 @@ import org.apache.jena.fuseki.build.FusekiBuilder;
 import org.apache.jena.fuseki.build.FusekiConfig;
 import org.apache.jena.fuseki.jetty.FusekiErrorHandler1;
 import org.apache.jena.fuseki.mgt.ActionStats;
-import org.apache.jena.fuseki.server.DataAccessPoint;
-import org.apache.jena.fuseki.server.DataAccessPointRegistry;
-import org.apache.jena.fuseki.server.DataService;
-import org.apache.jena.fuseki.server.Operation;
-import org.apache.jena.fuseki.servlets.ServiceDispatchRegistry;
+import org.apache.jena.fuseki.server.*;
 import org.apache.jena.fuseki.servlets.ActionService;
 import org.apache.jena.fuseki.servlets.FusekiFilter;
+import org.apache.jena.fuseki.servlets.ServiceDispatchRegistry;
 import org.apache.jena.query.Dataset;
+import org.apache.jena.rdf.model.Model;
+import org.apache.jena.rdf.model.Resource;
 import org.apache.jena.riot.WebContent;
 import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.sparql.core.assembler.AssemblerUtils;
+import org.apache.jena.sparql.util.graph.GraphUtils;
 import org.eclipse.jetty.http.MimeTypes;
 import org.eclipse.jetty.security.SecurityHandler;
 import org.eclipse.jetty.server.HttpConnectionFactory;
@@ -297,9 +301,17 @@ public class FusekiServer {
          */
         public Builder parseConfigFile(String filename) {
             requireNonNull(filename, "filename");
-            List<DataAccessPoint> x = FusekiConfig.readConfigurationFile(filename);
+            Model model = AssemblerUtils.readAssemblerFile(filename);
+            
+            // Process server context
+            Resource server = GraphUtils.getResourceByType(model, FusekiVocab.tServer);
+            if ( server != null )
+                AssemblerUtils.setContext(server, Fuseki.getContext()) ;
+
+            // Process services, whether via server ja:services or, if absent, by finding
by type. 
+            List<DataAccessPoint> x = FusekiConfig.servicesAndDatasets(model);
             // Unbundle so that they accumulate.
-            x.forEach(dap-> add(dap.getName(), dap.getDataService()));
+            x.forEach(dap->add(dap.getName(), dap.getDataService()));
             return this;
         }
 


Mime
View raw message