You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2015/07/30 15:26:14 UTC
[1/2] jena git commit: JENA-869 : Delete configuration file when
deleting dataset service.
Repository: jena
Updated Branches:
refs/heads/master b71df5200 -> 4d1a7110f
JENA-869 : Delete configuration file when deleting dataset service.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/eafedda9
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/eafedda9
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/eafedda9
Branch: refs/heads/master
Commit: eafedda9ea48efcba6eb6b7ff47996d0ac61de0a
Parents: b71df52
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Jul 30 14:20:47 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Jul 30 14:20:47 2015 +0100
----------------------------------------------------------------------
.../apache/jena/fuseki/mgt/ActionDatasets.java | 166 ++++++++-----------
.../fuseki/server/DataAccessPointRegistry.java | 14 ++
2 files changed, 84 insertions(+), 96 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/eafedda9/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 00c4f12..dac1c7a 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
@@ -24,9 +24,10 @@ import java.io.IOException ;
import java.io.InputStream ;
import java.io.OutputStream ;
import java.io.StringReader ;
-import java.util.HashMap ;
-import java.util.Iterator ;
-import java.util.Map ;
+import java.nio.file.DirectoryStream ;
+import java.nio.file.Files ;
+import java.nio.file.Path ;
+import java.util.* ;
import javax.servlet.ServletOutputStream ;
import javax.servlet.http.HttpServletRequest ;
@@ -118,8 +119,8 @@ public class ActionDatasets extends ActionContainerItem {
boolean committed = false ;
// Also acts as a concurrency lock
system.begin(ReadWrite.WRITE) ;
- String filename1 = null ;
- String filename2 = null ;
+ String systemFileCopy = null ;
+ String configFile = null ;
try {
// Where to build the templated service/database.
@@ -136,8 +137,8 @@ public class ActionDatasets extends ActionContainerItem {
// ----
// Keep a persistent copy immediately. This is not used for
// anything other than being "for the record".
- filename1 = FusekiServer.dirFileArea.resolve(uuid.asString()).toString() ;
- try ( OutputStream outCopy = IO.openOutputFile(filename1) ) {
+ systemFileCopy = FusekiServer.dirFileArea.resolve(uuid.asString()).toString() ;
+ try ( OutputStream outCopy = IO.openOutputFile(systemFileCopy) ) {
RDFDataMgr.write(outCopy, model, Lang.TURTLE) ;
}
// ----
@@ -171,17 +172,14 @@ public class ActionDatasets extends ActionContainerItem {
if ( DataAccessPointRegistry.get().isRegistered(datasetPath) )
// And abort.
ServletOps.error(HttpSC.CONFLICT_409, "Name already registered "+datasetPath) ;
-
- // Copy to the configuration directory for server start up next time.
- filename2 = datasetPath.substring(1) ; // Without "/"
- filename2 = FusekiServer.dirConfiguration.resolve(filename2).toString()+".ttl" ;
- // If the file theer is a file already in the configuratin area even though
- // not currently in the DataAccessPointRegistry
- if ( FileOps.exists(filename2) )
- ServletOps.error(HttpSC.CONFLICT_409, "Configuration file of that name already exists "+filename2) ;
+
+ configFile = generateConfigurationFilename(datasetPath) ;
+ List<String> existing = existingConfigurationFile(datasetPath) ;
+ if ( ! existing.isEmpty() )
+ ServletOps.error(HttpSC.CONFLICT_409, "Configuration file for "+datasetPath+" already exists") ;
// Write to configuration directory.
- try ( OutputStream outCopy = IO.openOutputFile(filename2) ) {
+ try ( OutputStream outCopy = IO.openOutputFile(configFile) ) {
RDFDataMgr.write(outCopy, model, Lang.TURTLE) ;
}
@@ -203,8 +201,8 @@ public class ActionDatasets extends ActionContainerItem {
} catch (IOException ex) { IO.exception(ex); }
finally {
if ( ! committed ) {
- if ( filename1 != null ) FileOps.deleteSilent(filename1);
- if ( filename2 != null ) FileOps.deleteSilent(filename2);
+ if ( systemFileCopy != null ) FileOps.deleteSilent(systemFileCopy);
+ if ( configFile != null ) FileOps.deleteSilent(configFile);
system.abort() ;
}
system.end() ;
@@ -212,83 +210,6 @@ public class ActionDatasets extends ActionContainerItem {
return null ;
}
-// //@Override
-// // The system database version.
-// // Keep for easy replacement until comfortable new way is stable.
-// protected JsonValue execPostContainer1(HttpAction action) {
-// JenaUUID uuid = JenaUUID.generate() ;
-// String newURI = uuid.asURI() ;
-// Node gn = NodeFactory.createURI(newURI) ;
-//
-// ContentType ct = FusekiLib.getContentType(action) ;
-//
-// boolean committed = false ;
-// system.begin(ReadWrite.WRITE) ;
-// try {
-// Model model = system.getNamedModel(gn.getURI()) ;
-// StreamRDF dest = StreamRDFLib.graph(model.getGraph()) ;
-//
-// if ( WebContent.isHtmlForm(ct) )
-// assemblerFromForm(action, dest) ;
-// else if ( WebContent.isMultiPartForm(ct) )
-// assemblerFromUpload(action, dest) ;
-// else
-// assemblerFromBody(action, dest) ;
-//
-// // Keep a persistent copy.
-// String filename = FusekiServer.dirFileArea.resolve(uuid.asString()).toString() ;
-// try ( OutputStream outCopy = new FileOutputStream(filename) ) {
-// RDFDataMgr.write(outCopy, model, Lang.TURTLE) ;
-// }
-//
-// Statement stmt = getOne(model, null, pServiceName, null) ;
-// if ( stmt == null ) {
-// StmtIterator sIter = model.listStatements(null, pServiceName, (RDFNode)null ) ;
-// if ( ! sIter.hasNext() )
-// ServletOps.errorBadRequest("No name given in description of Fuseki service") ;
-// sIter.next() ;
-// if ( sIter.hasNext() )
-// ServletOps.errorBadRequest("Multiple names given in description of Fuseki service") ;
-// throw new InternalErrorException("Inconsistent: getOne didn't fail the second time") ;
-// }
-//
-// if ( ! stmt.getObject().isLiteral() )
-// ServletOps.errorBadRequest("Found "+FmtUtils.stringForRDFNode(stmt.getObject())+" : Service names are strings, then used to build the external URI") ;
-//
-// Resource subject = stmt.getSubject() ;
-// Literal object = stmt.getObject().asLiteral() ;
-//
-// if ( object.getDatatype() != null && ! object.getDatatype().equals(XSDDatatype.XSDstring) )
-// action.log.warn(format("[%d] Service name '%s' is not a string", action.id, FmtUtils.stringForRDFNode(object)));
-//
-// String datasetName = object.getLexicalForm() ;
-// String datasetPath = DataAccessPoint.canonical(datasetName) ;
-// action.log.info(format("[%d] Create database : name = %s", action.id, datasetPath)) ;
-//
-// if ( DataAccessPointRegistry.get().isRegistered(datasetPath) )
-// // And abort.
-// ServletOps.error(HttpSC.CONFLICT_409, "Name already registered "+datasetPath) ;
-//
-// model.removeAll(null, pStatus, null) ;
-// model.add(subject, pStatus, FusekiVocab.stateActive) ;
-//
-// // Need to be in Resource space at this point.
-// DataAccessPoint ref = Builder.buildDataAccessPoint(subject) ;
-// DataAccessPointRegistry.register(datasetPath, ref) ;
-// action.getResponse().setContentType(WebContent.contentTypeTextPlain);
-// ServletOutputStream out = action.getResponse().getOutputStream() ;
-// ServletOps.success(action) ;
-// system.commit();
-// committed = true ;
-//
-// } catch (IOException ex) { IO.exception(ex); }
-// finally {
-// if ( ! committed ) system.abort() ;
-// system.end() ;
-// }
-// return null ;
-// }
-
@Override
protected JsonValue execPostItem(HttpAction action) {
String name = action.getDatasetName() ;
@@ -377,7 +298,6 @@ public class ActionDatasets extends ActionContainerItem {
// ServletOps.errorBadRequest("DELETE only applies to a specific dataset.") ;
// return ;
// }
-
// Does not exist?
String name = action.getDatasetName() ;
if ( name == null )
@@ -401,6 +321,9 @@ public class ActionDatasets extends ActionContainerItem {
// Make it invisible to the outside.
DataAccessPointRegistry.get().remove(name) ;
+ // Delete configuration file.
+ // Shoudl be only one, undo damage if multiple.
+ existingConfigurationFile(name).stream().forEach(FileOps::deleteSilent);
// Find graph associated with this dataset name.
// (Statically configured databases aren't in the system database.)
@@ -421,6 +344,9 @@ public class ActionDatasets extends ActionContainerItem {
if ( ! committed ) systemDSG.abort() ;
systemDSG.end() ;
}
+
+ // Remove the configuration file (if any).
+ DataAccessPointRegistry.get().remove(name) ;
}
// Persistent state change.
@@ -474,6 +400,54 @@ public class ActionDatasets extends ActionContainerItem {
return stmt ;
}
+ /** Dataset set name to configuration file name. */
+ private String datasetNameToConfigurationFile(HttpAction action, String dsName) {
+ List<String> existing = existingConfigurationFile(dsName) ;
+ if ( ! existing.isEmpty() ) {
+ if ( existing.size() > 1 ) {
+ action.log.warn(format("[%d] Multiple existing configuration files for %s : %s",
+ action.id, dsName, existing));
+ ServletOps.errorBadRequest("Multiple existing configuration files for "+dsName);
+ return null ;
+ }
+ return existing.get(0) ;
+ }
+
+ return generateConfigurationFilename(dsName) ;
+ }
+
+
+ // TODO To a library place and use for all ref->filename
+ private String generateConfigurationFilename(String dsName) {
+ String filename = dsName ;
+ // Without "/"
+ if ( filename.startsWith("/"))
+ filename = filename.substring(1) ;
+ filename = FusekiServer.dirConfiguration.resolve(filename).toString()+".ttl" ;
+ return filename ;
+ }
+
+ /** Return the filenames of all matching files in the configuration directory */
+ private List<String> existingConfigurationFile(String baseFilename) {
+ // TODO To a library place and use for all ref->filename
+ try {
+ // Basename glob.
+ List<String> paths = new ArrayList<>() ;
+
+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(FusekiServer.dirConfiguration, baseFilename+"*") ) {
+ stream.forEach((p)-> paths.add(p.getFileName().toString())) ;
+ }
+// DirectoryStream.Filter<Path> matchingFiles = (entry) -> {
+// String fn = entry.getFileName().toString() ;
+// return fn.startsWith(baseFilename) ;
+// } ;
+// try (DirectoryStream<Path> stream = Files.newDirectoryStream(FusekiServer.dirConfiguration, matchingFiles)) {
+ return paths ;
+ } catch (IOException ex) {
+ throw new InternalErrorException("Failed to read configuration directory "+FusekiServer.dirConfiguration) ;
+ }
+ }
+
// XXX Merge with Upload.incomingData
private static void bodyAsGraph(HttpAction action, StreamRDF dest) {
http://git-wip-us.apache.org/repos/asf/jena/blob/eafedda9/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/DataAccessPointRegistry.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/DataAccessPointRegistry.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/DataAccessPointRegistry.java
index acd3e93..b9cbd5a 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/DataAccessPointRegistry.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/DataAccessPointRegistry.java
@@ -29,6 +29,20 @@ public class DataAccessPointRegistry extends Registry<String, DataAccessPoint>
get().put(name, accessPt);
}
+ // Debugging
+ public static void print(String string) {
+ System.out.flush() ;
+ if ( string == null )
+ string = "DataAccessPointRegistry" ;
+ System.err.println("== "+string) ;
+ DataAccessPointRegistry.get().keys().iterator().forEachRemaining((k) -> {
+ System.err.print(" (key="+k) ;
+ DataAccessPoint ref = DataAccessPointRegistry.get().get(k) ;
+ System.err.print(", ref="+ref.getName()) ;
+ System.err.println(")") ;
+ }) ;
+ }
+
private static DataAccessPointRegistry singleton = new DataAccessPointRegistry() ;
public static DataAccessPointRegistry get() { return singleton ; }
[2/2] jena git commit: Test for create-delete-create-delete
Posted by an...@apache.org.
Test for create-delete-create-delete
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/4d1a7110
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/4d1a7110
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/4d1a7110
Branch: refs/heads/master
Commit: 4d1a7110fad30979438ffc3bfe04ee814fea3092
Parents: eafedda
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Jul 30 14:26:01 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Jul 30 14:26:01 2015 +0100
----------------------------------------------------------------------
.../apache/jena/fuseki/mgt/ActionDatasets.java | 2 +-
.../java/org/apache/jena/fuseki/TestAdmin.java | 24 +++++++-------------
2 files changed, 9 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/4d1a7110/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 dac1c7a..7a972d9 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
@@ -322,7 +322,7 @@ public class ActionDatasets extends ActionContainerItem {
// Make it invisible to the outside.
DataAccessPointRegistry.get().remove(name) ;
// Delete configuration file.
- // Shoudl be only one, undo damage if multiple.
+ // Should be only one, undo damage if multiple.
existingConfigurationFile(name).stream().forEach(FileOps::deleteSilent);
// Find graph associated with this dataset name.
http://git-wip-us.apache.org/repos/asf/jena/blob/4d1a7110/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAdmin.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAdmin.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAdmin.java
index 8b836b7..e233120 100644
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAdmin.java
+++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAdmin.java
@@ -32,15 +32,10 @@ import static org.apache.jena.riot.web.HttpOp.execHttpPost ;
import java.io.File ;
import java.io.IOException ;
import java.io.InputStream ;
-import java.util.ArrayList ;
-import java.util.List ;
import org.apache.http.HttpEntity ;
import org.apache.http.HttpResponse ;
-import org.apache.http.NameValuePair ;
-import org.apache.http.client.entity.UrlEncodedFormEntity ;
import org.apache.http.entity.FileEntity ;
-import org.apache.http.message.BasicNameValuePair ;
import org.apache.jena.atlas.json.JSON ;
import org.apache.jena.atlas.json.JsonArray ;
import org.apache.jena.atlas.json.JsonObject ;
@@ -177,17 +172,14 @@ public class TestAdmin extends BaseTest {
}
@Test public void add_delete_dataset_3() throws Exception {
- String name = "MEMTEST" ;
- //String args = "dbType=mem&dbName="+name ;
-
- List<NameValuePair> args = new ArrayList<NameValuePair>() ;
- args.add(new BasicNameValuePair("dbType", "mem")) ;
- args.add(new BasicNameValuePair("dbName", name)) ;
-
- HttpEntity e = new UrlEncodedFormEntity(args) ;
- execHttpPost(ServerTest.urlRoot+"$/"+opDatasets, e) ;
- checkExists(name) ;
- deleteDataset(name) ;
+ checkNotThere(dsTest) ;
+ addTestDataset() ;
+ checkExists(dsTest) ;
+ deleteDataset(dsTest) ;
+ checkNotThere(dsTest) ;
+ addTestDataset() ;
+ checkExists(dsTest) ;
+ deleteDataset(dsTest) ;
}
@Test public void delete_dataset_1() {