You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by al...@apache.org on 2012/08/09 13:23:35 UTC

svn commit: r1371167 - in /incubator/stanbol/trunk/ontologymanager: ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/ web/src/main/java/org/apache/stanb...

Author: alexdma
Date: Thu Aug  9 11:23:34 2012
New Revision: 1371167

URL: http://svn.apache.org/viewvc?rev=1371167&view=rev
Log:
* Made scope and session rebuilding more fault-tolerant for missing ontologies (STANBOL-571)
* Started updating the RESTful API specification for scopes

Added:
    incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/ScopeResource/restapi.ftl
Modified:
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionManagerImpl.java
    incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeResource.java
    incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/imports/inc_scope.ftl
    incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/ScopeResource/index.ftl

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java?rev=1371167&r1=1371166&r2=1371167&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java Thu Aug  9 11:23:34 2012
@@ -42,6 +42,7 @@ import org.apache.stanbol.ontologymanage
 import org.apache.stanbol.ontologymanager.ontonet.api.OfflineConfiguration;
 import org.apache.stanbol.ontologymanager.ontonet.api.OntologyNetworkConfiguration;
 import org.apache.stanbol.ontologymanager.ontonet.api.collector.DuplicateIDException;
+import org.apache.stanbol.ontologymanager.ontonet.api.collector.MissingOntologyException;
 import org.apache.stanbol.ontologymanager.ontonet.api.collector.UnmodifiableOntologyCollectorException;
 import org.apache.stanbol.ontologymanager.ontonet.api.io.BlankOntologySource;
 import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
@@ -523,18 +524,28 @@ public class ONManagerImpl extends Scope
                 scope = createOntologyScope(scopeId, srcs);
             } catch (DuplicateIDException e) {
                 String dupe = e.getDuplicateID();
-                log.warn("Tried to rebuild existing scope \"{}\". Reusing.", dupe);
+                log.warn("Scope \"{}\" already exists and will be reused.", dupe);
                 scope = getScope(dupe);
             }
             OntologySpace custom = scope.getCustomSpace();
             // Register even if some ontologies were to fail to be restored afterwards.
             scopeMap.put(scopeId, scope);
-            for (OWLOntologyID key : struct.getCustomOntologyKeysForScope(scopeId)) {
-                log.debug("Custom ontology key : {}", key);
-                custom.addOntology(Origin.create(key)
-                // new GraphSource(key)
-                );
-            }
+            for (OWLOntologyID key : struct.getCustomOntologyKeysForScope(scopeId))
+                try {
+                    log.debug("Custom ontology key : {}", key);
+                    custom.addOntology(Origin.create(key)
+                    // new GraphSource(key)
+                    );
+                } catch (MissingOntologyException ex) {
+                    log.error(
+                        "Could not find an ontology with public key {} to be managed by scope \"{}\". Proceeding to next ontology.",
+                        key, scopeId);
+                    continue;
+                } catch (Exception ex) {
+                    log.error("Exception caught while trying to add ontology with public key " + key
+                              + " to rebuilt scope \"" + scopeId + "\". proceeding to next ontology", ex);
+                    continue;
+                }
             log.info("Scope \"{}\" rebuilt in {} ms.", scopeId, System.currentTimeMillis() - before);
         }
     }

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionManagerImpl.java?rev=1371167&r1=1371166&r2=1371167&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionManagerImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionManagerImpl.java Thu Aug  9 11:23:34 2012
@@ -34,6 +34,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
 import org.apache.stanbol.ontologymanager.ontonet.api.OfflineConfiguration;
 import org.apache.stanbol.ontologymanager.ontonet.api.OntologyNetworkConfiguration;
+import org.apache.stanbol.ontologymanager.ontonet.api.collector.MissingOntologyException;
 import org.apache.stanbol.ontologymanager.ontonet.api.collector.OntologyCollectorListener;
 import org.apache.stanbol.ontologymanager.ontonet.api.io.Origin;
 import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyNetworkMultiplexer;
@@ -364,32 +365,46 @@ public class SessionManagerImpl implemen
         }
         OntologyNetworkConfiguration struct = ontologyProvider.getOntologyNetworkConfiguration();
         for (String sessionId : struct.getSessionIDs()) {
+            long before = System.currentTimeMillis();
+            log.debug("Rebuilding session with ID \"{}\"", sessionId);
             Session session;
             try {
                 session = createSession(sessionId);
-                // Register even if some ontologies were to fail to be restored afterwards.
-                sessionsByID.put(sessionId, session);
-                session.setActive(false); // Restored sessions are inactive at first.
-                for (OWLOntologyID key : struct.getOntologyKeysForSession(sessionId)) {
-                    session.addOntology(
-                    // new GraphSource(key)
-                    Origin.create(key)); // TODO use the public key instead!
-                }
-                for (String scopeId : struct.getAttachedScopes(sessionId)) {
-                    /*
-                     * The scope is attached by reference, so we won't have to bother checking if the scope
-                     * has been rebuilt by then (which could not happen if the SessionManager is being
-                     * activated first).
-                     */
-                    session.attachScope(scopeId);
-                }
             } catch (DuplicateSessionIDException e) {
                 log.warn("Session \"{}\" already exists and will be reused.", sessionId);
                 session = getSession(sessionId);
             } catch (SessionLimitException e) {
                 log.error("Cannot create session {}. Session limit of {} reached.", sessionId,
                     getActiveSessionLimit());
+                break;
+            }
+            // Register even if some ontologies were to fail to be restored afterwards.
+            sessionsByID.put(sessionId, session);
+            session.setActive(false); // Restored sessions are inactive at first.
+            for (OWLOntologyID key : struct.getOntologyKeysForSession(sessionId))
+                try {
+                    session.addOntology(
+                    // new GraphSource(key)
+                    Origin.create(key));
+                } catch (MissingOntologyException ex) {
+                    log.error(
+                        "Could not find an ontology with public key {} to be managed by session \"{}\". Proceeding to next ontology.",
+                        key, sessionId);
+                    continue;
+                } catch (Exception ex) {
+                    log.error("Exception caught while trying to add ontology with public key " + key
+                              + " to rebuilt session \"" + sessionId + "\". Proceeding to next ontology.", ex);
+                    continue;
+                }
+            for (String scopeId : struct.getAttachedScopes(sessionId)) {
+                /*
+                 * The scope is attached by reference, so we won't have to bother checking if the scope has
+                 * been rebuilt by then (which could not happen if the SessionManager is being activated
+                 * first).
+                 */
+                session.attachScope(scopeId);
             }
+            log.info("Session \"{}\" rebuilt in {} ms.", sessionId, System.currentTimeMillis() - before);
         }
     }
 

Modified: incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeResource.java?rev=1371167&r1=1371166&r2=1371167&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeResource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeResource.java Thu Aug  9 11:23:34 2012
@@ -555,8 +555,8 @@ public class ScopeResource extends BaseS
             // FIXME ugly but will have to do for the time being
             log.debug("SUCCESS parse with media type {}.", mt);
             String uri = // key.split("::")[1];
-                    OntologyUtils.encode(key);
-//            uri = uri.substring((ontologyProvider.getGraphPrefix() + "::").length());
+            OntologyUtils.encode(key);
+            // uri = uri.substring((ontologyProvider.getGraphPrefix() + "::").length());
             URI created = null;
             if (uri != null && !uri.isEmpty()) {
                 created = getCreatedResource(uri);
@@ -587,15 +587,18 @@ public class ScopeResource extends BaseS
     @POST
     @Consumes(value = MediaType.TEXT_PLAIN)
     public Response manageOntology(String iri, @Context HttpHeaders headers) {
-        if (scope == null) return Response.status(NOT_FOUND).build();
-        try {
-            scope.getCustomSpace().addOntology(new RootOntologyIRISource(IRI.create(iri)));
+        ResponseBuilder rb;
+        if (scope == null) rb = Response.status(NOT_FOUND);
+        else try {
+            OWLOntologyID key = scope.getCustomSpace()
+                    .addOntology(new RootOntologyIRISource(IRI.create(iri)));
+            URI created = getCreatedResource(OntologyUtils.encode(key));
+            rb = Response.created(created);
         } catch (UnmodifiableOntologyCollectorException e) {
             throw new WebApplicationException(e, FORBIDDEN);
         } catch (OWLOntologyCreationException e) {
             throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
         }
-        ResponseBuilder rb = Response.ok();
         addCORSOrigin(servletContext, rb, headers);
         return rb.build();
     }
@@ -693,8 +696,8 @@ public class ScopeResource extends BaseS
                 if (key == null || key.isAnonymous()) throw new WebApplicationException(INTERNAL_SERVER_ERROR);
                 // FIXME ugly but will have to do for the time being
                 String uri = // key.split("::")[1];
-               OntologyUtils.encode(key);
-//                        uri =  uri.substring((ontologyProvider.getGraphPrefix() + "::").length());
+                OntologyUtils.encode(key);
+                // uri = uri.substring((ontologyProvider.getGraphPrefix() + "::").length());
                 if (uri != null && !uri.isEmpty()) {
                     rb = Response.seeOther(URI.create("/ontonet/ontology/" + scope.getID() + "/" + uri)/*
                                                                                                         * getCreatedResource

Modified: incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/imports/inc_scope.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/imports/inc_scope.ftl?rev=1371167&r1=1371166&r2=1371167&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/imports/inc_scope.ftl (original)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/imports/inc_scope.ftl Thu Aug  9 11:23:34 2012
@@ -53,28 +53,87 @@
 <table>
   <tbody>
     <tr>
-      <th>Description</th>
+      <th valign="top">Description</th>
       <td>Service to load an ontology into the custom space of the scope.</td>
     </tr>
     <tr>
-      <th>Request</th>
-      <td>POST <code>/ontonet/ontology/</code>{scopeName}</td>
+      <th valign="top">Request</th>
+      <td>POST <code>/ontonet/ontology/</code>{scopeName}
+        <br/>
+        Content types :
+        <ul>
+          <li><code>application/owl+xml</code></li>
+          <li><code>application/rdf+json</code></li>
+          <li><code>application/rdf+xml</code></li>
+          <li><code>application/x-turtle</code></li>
+          <li><code>multipart/form-data</code></li>
+          <li><code>text/owl-functional</code></li>
+          <li><code>text/owl-manchester</code></li>
+          <li><code>text/plain</code></li>
+          <li><code>text/rdf+n3</code></li>
+          <li><code>text/rdf+nt</code></li>
+          <li><code>text/turtle</code></li> 
+        </ul>
+      </td>
     </tr>
     <tr>
-      <th>Parameters</th>
-      <td><code>location</code>: the physical URL of the ontology to be loaded. 
+      <th valign="top">Parameters</th>
+      <td>
+      For <code>multipart/form-data</code> content:<br/>
+      <ul>
+        <li><code>file</code>: the physical URL of the ontology to be loaded. </li>
+        <li><code>format</code>: combined with <code>file</code>, the format of the submitted file. 
+      If not supplied, all known parsers will be tried until one succeeds or all fail. </li>
+        <li><code>library</code>: the identifier of the ontology library whose ontologies have to be loaded. 
+      The available libraries are shown on the /ontonet/registry endpoint.</li>
+        <li><code>stored</code>: the public key of the ontology to be loaded, if already stored in Stanbol.</li>
+        <li><code>url</code>: the physical URL of the ontology to be loaded.</li>
+      </ul>
+      <br/>
+      For <code>text/plain</code> content: will be interpreted as <code>url</code>.
+      <br/>
+      <br/>
+      For any other content type: will be interpreted as <code>file</code>.
+      <br/>
+      <br/>
+      Limitations:
+      <ul>
+        <li>Only one of <code>file</code>, <code>library</code> or <code>url</code> 
+        can be specified in a single POST.
+        <li>Only one <i>value</i> for <code>file</code>, <code>library</code> or <code>url</code> per POST is accepted.
+        <li><code>stored</code> can have multiple values and can be used in combination with the above parameters.
+      </ul>
       </td>
     </tr>
     <tr>
-      <th>Produces</th>
-      <td>Nothing. Returns Status 200 if successful.</td>
+      <th valign="top">Response</th>
+      <td>
+        <ul>
+          <li><code>201 Created</code> if ontology loading was successful.</li> 
+          <li><code>303 See Other</code> if ontology loading was successful (for <code>multipart/form-data</code> content).</li> 
+          <li><code>400 Bad Request</code> if no proper content or parameters were supplied, 
+          or if <code>library</code> or <code>url</code> are not well-formed or do not match an existing resource.</li> 
+          <li><code>403 Forbidden</code> if the scope is locked and cannot be modified.</li> 
+          <li><code>404 Not Found</code> if no such scope was registered.</li> 
+          <li><code>409 Conflict</code> if the supplied ontology was found to have the same ID as one already loaded.</li>          
+          <li><code>500 Internal Server Error</code> if ontology loading failed for some other reason.</li> 
+        </ul>
+     </td>
     </tr>
   </tbody>
 </table>
 
-<h5>Example</h5>
-
-<pre>curl -X POST "${it.publicBaseUri}ontonet/ontology/User</pre>
+<h5>Examples</h5>
+Load and store the SKOS thesaurus of ISO 3166-1 country codes into a scope that manages Geographical content, without knowing the ontology format.
+<pre>curl -X POST -F "url=http://eulersharp.sourceforge.net/2003/03swap/countries" ${it.publicBaseUri}ontonet/ontology/Geographical</pre>
+  or
+<pre>curl -H "Content-type: text/plain" -d http://eulersharp.sourceforge.net/2003/03swap/countries ${it.publicBaseUri}ontonet/ontology/Geographical</pre>
+<br/>
+Load and store an ontology from a local file called <tt>acme-hierarchy.owl</tt> in the scope about the ACME organization, knowing the file is in RDF/XML format.
+<pre>curl -X POST -F file=@acme-hierarchy.owl -F format=application/rdf+xml ${it.publicBaseUri}ontonet/ontology/ACME</pre>
+  or
+<pre>curl -H "Content-type: application/rdf+xml" -d @acme-hierarchy.owl ${it.publicBaseUri}ontonet/ontology/ACME
+</pre>
 
 <!-- 
   ============= PUT =============
@@ -83,15 +142,15 @@
 <table>
   <tbody>
     <tr>
-      <th>Description</th>
+      <th valign="top">Description</th>
       <td>Service to get the root ontology of the scope.</td>
     </tr>
     <tr>
-      <th>Request</th>
+      <th valign="top">Request</th>
       <td>PUT <code>/ontonet/ontology/</code>{scopeName}</td>
     </tr>
     <tr>
-      <th>Parameters</th>
+      <th valign="top">Parameters</th>
       <td><code>corereg</code>: the physical URL of the registry that points to the ontologies to be loaded into the core space. 
         <br/>
         This parameter overrides <code>coreont</code> if both are specified.
@@ -106,28 +165,18 @@
     </tr>
     <tr>
       <th></th>
-      <td><code>customreg</code>: the physical URL of the registry that points to the ontologies to be loaded into the custom space. 
-        <br/>
-        This parameter is optional. Overrides <code>customont</code> if both are specified.
-      </td>
-    </tr>
-    <tr>
-      <th></th>
-      <td><code>customont</code>: the physical URL of the top ontology to be loaded into the custom space. 
-        <br/>
-        This parameter is optional. Ignored if <code>customreg</code> is specified.
-      </td>
-    </tr>
-    <tr>
-      <th></th>
       <td><code>activate</code>: If <code>true</code>, the ontology scope will be set as active upon creation.
         <br/>
         This parameter is optional, default is <code>false</code>.<
       /td>
     </tr>
     <tr>
-      <th>Produces</th>
-      <td>Nothing. Returns Status 200 if successful, 500 otherwise.</td>
+      <th>Response</th>
+      <td>
+        <ul>
+          <li><code>201 Created</code></li>
+        </ul>
+     </td>
     </tr>
   </tbody>
 </table>
@@ -144,7 +193,8 @@
   <tbody>
     <tr>
       <th>Description</th>
-      <td>Service to unregister the ontology scope and unload its resources.</td>
+      <td>Unregisters the ontology scope and unloads its resources, 
+      but does not necessarily delete its ontologies.</td>
     </tr>
     <tr>
       <th>Request</th>
@@ -157,12 +207,18 @@
       </td>
     </tr>
     <tr>
-      <th>Produces</th>
-      <td>Nothing. Returns Status 200 if successful, 500 otherwise.</td>
+      <th>Response</th>
+      <td>
+        <ul>
+          <li><code>200 OK</code> if deletion was successful.</li>
+          <li><code>404 Not Found</code> if no such scope was registered.</li>
+          <li><code>500 Internal Server Error</code> if the scope was found but deletion failed for some other reason.</li>
+        </ul>
+     </td>
     </tr>
   </tbody>
 </table>
 
 <h5>Example</h5>
 
-<pre>curl -X PUT "${it.publicBaseUri}ontonet/ontology/User?corereg=[registry_location]&customont=[ontology_location]</pre>
\ No newline at end of file
+<pre>curl -X DELETE "${it.publicBaseUri}ontonet/ontology/Users</pre>
\ No newline at end of file

Modified: incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/ScopeResource/index.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/ScopeResource/index.ftl?rev=1371167&r1=1371166&r2=1371167&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/ScopeResource/index.ftl (original)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/ScopeResource/index.ftl Thu Aug  9 11:23:34 2012
@@ -17,7 +17,7 @@
 <#import "/imports/common.ftl" as common>
 
 <#escape x as x?html>
-  <@common.page title="${it.scope.ID} : Apache Stanbol OntoNet scope" hasrestapi=false>
+  <@common.page title="${it.scope.ID} : Apache Stanbol OntoNet scope" hasrestapi=true>
 	
 	<a href="${it.publicBaseUri}ontonet/ontology">Scope Manager</a> &gt; Scope <tt>${it.scope.ID}</tt>
 	
@@ -145,6 +145,8 @@
   </div>
   
     </div> <!-- web view -->
+    
+    <#include "restapi.ftl"> <!-- REST API-->
 
   <script language="JavaScript">
     

Added: incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/ScopeResource/restapi.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/ScopeResource/restapi.ftl?rev=1371167&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/ScopeResource/restapi.ftl (added)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/ScopeResource/restapi.ftl Thu Aug  9 11:23:34 2012
@@ -0,0 +1,21 @@
+<#--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+  <div class="panel" id="restapi" style="display: none;">
+    <h3>Service Endpoints</h3>
+    <#include "/imports/inc_scope.ftl">
+  </div>
\ No newline at end of file