From: <tho...@us...> - 2011-04-08 18:52:29
|
Revision: 4382 http://bigdata.svn.sourceforge.net/bigdata/?rev=4382&view=rev Author: thompsonbry Date: 2011-04-08 18:52:23 +0000 (Fri, 08 Apr 2011) Log Message: ----------- - The feature to control the size of the thread pool used to *run* the queries was dropped. This needs to be put back in. I've made comments in QueryServlet for this. It is used to control the query parallelism, which is different from the http connection parallelism. - I've taken out "-stop". It's just not necessary. - I've taken out the 'direct' API stuff. It was committed with that enabled and this is breaking our published API. - The status page needed to specify the mime type as text/html. - Perhaps the single best thing that we could add right now is a page with a FORM for typing in SPARQL queries so you can run them against the REST API. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataContext.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/JettySparqlServer.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/NanoSparqlServer.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/QueryServlet.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/StatusServlet.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestJettySparqlServer_StartStop.java Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataContext.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataContext.java 2011-04-08 13:02:36 UTC (rev 4381) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataContext.java 2011-04-08 18:52:23 UTC (rev 4382) @@ -211,11 +211,11 @@ */ public int queryThreadPoolSize = 8; - /** - * The capacity of the buffers for the pipe connecting the running query - * to the HTTP response. - */ - public int bufferCapacity = Bytes.kilobyte32 * 1; +// /** +// * The capacity of the buffers for the pipe connecting the running query +// * to the HTTP response. +// */ +// public int bufferCapacity = Bytes.kilobyte32 * 1; public String resourceBase = "."; Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/JettySparqlServer.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/JettySparqlServer.java 2011-04-08 13:02:36 UTC (rev 4381) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/JettySparqlServer.java 2011-04-08 18:52:23 UTC (rev 4382) @@ -38,7 +38,11 @@ static private final Logger log = Logger.getLogger(JettySparqlServer.class); - protected static final boolean directServletAccess = true; + /* + * Martyn, I took this out of the code because it was getting committed with + * the wrong value to run the published API! Bryan + */ +// protected static final boolean directServletAccess = false; int m_port = -1; // allow package visibility from JettySparqlCommand @@ -117,34 +121,35 @@ // embedded setup m_handlerMap.put("/status", new ServletHandler(new StatusServlet())); - if (directServletAccess) { - m_handlerMap.put("/query", new ServletHandler(new QueryServlet())); - m_handlerMap.put("/update", new ServletHandler(new UpdateServlet())); - m_handlerMap.put("/delete", new ServletHandler(new DeleteServlet())); - } else { +// if (directServletAccess) { +// m_handlerMap.put("/query", new ServletHandler(new QueryServlet())); +// m_handlerMap.put("/update", new ServletHandler(new UpdateServlet())); +// m_handlerMap.put("/delete", new ServletHandler(new DeleteServlet())); +// } else + { // create implementation servlets new QueryServlet(); new UpdateServlet(); - // still need delete endpoint for delete with body + // still need delete endpoint for delete with body m_handlerMap.put("/delete", new ServletHandler(new DeleteServlet())); } m_handlerMap.put("/", new ServletHandler(new RESTServlet())); - // the "stop" handler is only relevant for the embedded server - m_handlerMap.put("/stop", new AbstractHandler() { - public void handle(String arg0, Request arg1, HttpServletRequest arg2, HttpServletResponse resp) - throws IOException, ServletException { - try { - resp.getWriter().println("Server Stop request received"); - shutdownNow(); - } catch (InterruptedException e) { - // okay - } catch (Exception e) { - e.printStackTrace(); - } - } - }); +// // the "stop" handler is only relevant for the embedded server +// m_handlerMap.put("/stop", new AbstractHandler() { +// public void handle(String arg0, Request arg1, HttpServletRequest arg2, HttpServletResponse resp) +// throws IOException, ServletException { +// try { +// resp.getWriter().println("Server Stop request received"); +// shutdownNow(); +// } catch (InterruptedException e) { +// // okay +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// }); final HandlerList handlers = new HandlerList(); Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/NanoSparqlServer.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/NanoSparqlServer.java 2011-04-08 13:02:36 UTC (rev 4381) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/NanoSparqlServer.java 2011-04-08 18:52:23 UTC (rev 4382) @@ -12,22 +12,28 @@ import org.apache.log4j.Logger; -import com.bigdata.btree.BytesUtil; import com.bigdata.journal.IIndexManager; import com.bigdata.journal.ITransactionService; import com.bigdata.journal.ITx; import com.bigdata.journal.Journal; import com.bigdata.journal.TimestampUtility; -import com.bigdata.rawstore.Bytes; import com.bigdata.rdf.sail.BigdataSail; import com.bigdata.rdf.sail.webapp.BigdataContext.Config; import com.bigdata.service.AbstractDistributedFederation; import com.bigdata.service.IBigdataFederation; import com.bigdata.service.jini.JiniClient; +/** + * Utility class provides a simple SPARQL end point with a REST API. + * + * @author thompsonbry + * @author martyncutcher + * + * @see https://sourceforge.net/apps/mediawiki/bigdata/index.php?title=NanoSparqlServer + */ public class NanoSparqlServer { - static private final Logger log = Logger.getLogger(JettySparqlServer.class); + static private final Logger log = Logger.getLogger(NanoSparqlServer.class); /** * Run an httpd service exposing a SPARQL endpoint. The service will respond @@ -46,8 +52,6 @@ * * @param args * USAGE:<br/> - * To stop the server:<br/> - * <code>port -stop</code><br/> * To start the server:<br/> * <code>(options) <i>namespace</i> (propertyFile|configFile) )</code> * <p> @@ -84,14 +88,16 @@ * against the most recent commit point on the database. * Regardless, each query will be issued against a read-only * transaction.</dt> - * <dt>bufferCapacity [#bytes]</dt> - * <dd>Specify the capacity of the buffers used to decouple the - * query evaluation from the consumption of the HTTP response by - * the clinet. The capacity may be specified in bytes or - * kilobytes, e.g., <code>5k</code>.</dd> * </dl> * </p> */ +// * To stop the server:<br/> +// * <code>port -stop</code><br/> +// * <dt>bufferCapacity [#bytes]</dt> +// * <dd>Specify the capacity of the buffers used to decouple the +// * query evaluation from the consumption of the HTTP response by +// * the client. The capacity may be specified in bytes or +// * kilobytes, e.g., <code>5k</code>.</dd> static public void main(String[] args) throws Exception { // PropertyConfigurator.configure("C:/CT_Config/ct_test_log4j.properties"); @@ -108,29 +114,29 @@ JettySparqlServer server = null; try { - /* - * First, handle the [port -stop] command, where "port" is the port - * number of the service. This case is a bit different because the - * "-stop" option appears after the "port" argument. - */ - if (args.length == 2) { - if ("-stop".equals(args[1])) { - final int port; - try { - port = Integer.valueOf(args[0]); - } catch (NumberFormatException ex) { - usage(1/* status */, "Could not parse as port# : '" + args[0] + "'"); - // keep the compiler happy wrt [port] being bound. - throw new AssertionError(); - } - // Send stop to server. - sendStop(port); - // Normal exit. - System.exit(0); - } else { - usage(1/* status */, null/* msg */); - } - } +// /* +// * First, handle the [port -stop] command, where "port" is the port +// * number of the service. This case is a bit different because the +// * "-stop" option appears after the "port" argument. +// */ +// if (args.length == 2) { +// if ("-stop".equals(args[1])) { +// final int port; +// try { +// port = Integer.valueOf(args[0]); +// } catch (NumberFormatException ex) { +// usage(1/* status */, "Could not parse as port# : '" + args[0] + "'"); +// // keep the compiler happy wrt [port] being bound. +// throw new AssertionError(); +// } +// // Send stop to server. +// sendStop(port); +// // Normal exit. +// System.exit(0); +// } else { +// usage(1/* status */, null/* msg */); +// } +// } /* * Now that we have that case out of the way, handle all arguments @@ -151,16 +157,16 @@ if (config.queryThreadPoolSize < 0) { usage(1/* status */, "-nthreads must be non-negative, not: " + s); } - } else if (arg.equals("-bufferCapacity")) { - final String s = args[++i]; - final long tmp = BytesUtil.getByteCount(s); - if (tmp < 1) { - usage(1/* status */, "-bufferCapacity must be non-negative, not: " + s); - } - if (tmp > Bytes.kilobyte32 * 100) { - usage(1/* status */, "-bufferCapacity must be less than 100kb, not: " + s); - } - config.bufferCapacity = (int) tmp; +// } else if (arg.equals("-bufferCapacity")) { +// final String s = args[++i]; +// final long tmp = BytesUtil.getByteCount(s); +// if (tmp < 1) { +// usage(1/* status */, "-bufferCapacity must be non-negative, not: " + s); +// } +// if (tmp > Bytes.kilobyte32 * 100) { +// usage(1/* status */, "-bufferCapacity must be less than 100kb, not: " + s); +// } +// config.bufferCapacity = (int) tmp; } else if (arg.equals("-readLock")) { final String s = args[++i]; readLock = Long.valueOf(s); @@ -446,10 +452,10 @@ System.err.println("[options] port namespace (propertyFile|configFile)"); - System.err.println("-OR-"); +// System.err.println("-OR-"); +// +// System.err.println("port -stop"); - System.err.println("port -stop"); - System.exit(status); } Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/QueryServlet.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/QueryServlet.java 2011-04-08 13:02:36 UTC (rev 4381) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/QueryServlet.java 2011-04-08 18:52:23 UTC (rev 4382) @@ -96,6 +96,15 @@ if (log.isTraceEnabled()) log.trace("Running query: " + queryStr); + /* + * FIXME This needs to run on an ExecutorService with a configured + * thread pool size so we can avoid running too many queries + * concurrently. Please restore the logic for doing this with the + * thread pool scoped appropriately. All non-administrative REST Api + * tasks should adhere to this limit. The limit should not apply to + * normal http requests against non-API services. + */ + queryTask.call(); // Setup the response. Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/StatusServlet.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/StatusServlet.java 2011-04-08 13:02:36 UTC (rev 4381) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/StatusServlet.java 2011-04-08 18:52:23 UTC (rev 4382) @@ -193,7 +193,7 @@ doc.closeAll(current); - buildResponse(resp, HTTP_OK, MIME_TEXT_PLAIN, doc.toString()); + buildResponse(resp, HTTP_OK, MIME_TEXT_HTML, doc.toString()); } catch (IOException e) { throw new RuntimeException(e); } Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestJettySparqlServer_StartStop.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestJettySparqlServer_StartStop.java 2011-04-08 13:02:36 UTC (rev 4381) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestJettySparqlServer_StartStop.java 2011-04-08 18:52:23 UTC (rev 4382) @@ -661,7 +661,8 @@ * UPDATE should not be allowed with a GET request */ public void test_GETUPDATE_withBody_NTRIPLES() throws Exception { - if (JettySparqlServer.directServletAccess) { +// if (JettySparqlServer.directServletAccess) + if(false) { HttpURLConnection conn = null; final URL url = new URL(m_serviceURL + "/update?data=stuff"); conn = (HttpURLConnection) url.openConnection(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |