Author: bdelacretaz
Date: Fri Jun 12 16:23:05 2009
New Revision: 784180
URL: http://svn.apache.org/viewvc?rev=784180&view=rev
Log:
SLING-490 - systemstatus bundle added, dummy implementation for now
Added:
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/SystemStatus.java
(with props)
incubator/sling/trunk/bundles/extensions/systemstatus/ (with props)
incubator/sling/trunk/bundles/extensions/systemstatus/pom.xml (with props)
incubator/sling/trunk/bundles/extensions/systemstatus/src/
incubator/sling/trunk/bundles/extensions/systemstatus/src/main/
incubator/sling/trunk/bundles/extensions/systemstatus/src/main/java/
incubator/sling/trunk/bundles/extensions/systemstatus/src/main/java/org/
incubator/sling/trunk/bundles/extensions/systemstatus/src/main/java/org/apache/
incubator/sling/trunk/bundles/extensions/systemstatus/src/main/java/org/apache/sling/
incubator/sling/trunk/bundles/extensions/systemstatus/src/main/java/org/apache/sling/systemstatus/
incubator/sling/trunk/bundles/extensions/systemstatus/src/main/java/org/apache/sling/systemstatus/impl/
incubator/sling/trunk/bundles/extensions/systemstatus/src/main/java/org/apache/sling/systemstatus/impl/SystemStatusService.java
(with props)
Modified:
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
incubator/sling/trunk/launchpad/bundles/pom.xml
incubator/sling/trunk/pom.xml
Added:
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/SystemStatus.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/SystemStatus.java?rev=784180&view=auto
==============================================================================
---
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/SystemStatus.java
(added)
+++
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/SystemStatus.java
Fri Jun 12 16:23:05 2009
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+package org.apache.sling.engine;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+
+/**
+ * Provides information on the system status - mostly indicating if the system
+ * is ready, or why it is not.
+ */
+public interface SystemStatus {
+
+ @SuppressWarnings("serial")
+ static class StatusException extends Exception {
+ public StatusException(String reason, Throwable cause) {
+ super(reason, cause);
+ }
+ public StatusException(String reason) {
+ super(reason);
+ }
+ }
+
+ /**
+ * The SlingMainServlet provides status info if called with this path, and
+ * this is also the path under which scripts that define the system status
+ * are found.
+ */
+ String STATUS_PATH = "/system/sling/status";
+
+ /**
+ * Throw an exception if the system is not ready to process requests. The
+ * readyness state can be cached, and if it is {...@link #clear} clears it.
+ */
+ void checkSystemReady() throws Exception;
+
+ /** Clear any cached state */
+ void clear();
+
+ /**
+ * Execute the system readyness checking scripts and copy their output to
+ * the response
+ */
+ void doGet(SlingHttpServletRequest req, SlingHttpServletResponse resp)
+ throws Exception;
+}
Propchange:
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/SystemStatus.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/SystemStatus.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Modified:
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java?rev=784180&r1=784179&r2=784180&view=diff
==============================================================================
---
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
(original)
+++
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
Fri Jun 12 16:23:05 2009
@@ -60,6 +60,7 @@
import org.apache.sling.commons.mime.MimeTypeService;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.apache.sling.engine.ResponseUtil;
+import org.apache.sling.engine.SystemStatus;
import org.apache.sling.engine.impl.auth.MissingRepositoryException;
import org.apache.sling.engine.impl.auth.SlingAuthenticator;
import org.apache.sling.engine.impl.filter.RequestSlingFilterChain;
@@ -94,6 +95,7 @@
* @scr.reference name="Filter" interface="javax.servlet.Filter"
* cardinality="0..n" policy="dynamic"
*/
+...@suppresswarnings("serial")
public class SlingMainServlet extends GenericServlet implements ErrorHandler,
HttpContext {
@@ -105,7 +107,7 @@
/** default log */
private static final Logger log =
LoggerFactory.getLogger(SlingMainServlet.class);
-
+
/**
* The registration path for the SlingMainServlet is hard wired to always
* be the root, aka "<code>/</code>" (value is "/").
@@ -161,6 +163,9 @@
/** @scr.reference cardinality="0..1" policy="dynamic" */
private AdapterManager adapterManager;
+
+ /** @scr.reference cardinality="0..1" policy="dynamic" */
+ private SystemStatus systemStatus;
private SlingFilterChainHelper requestFilterChain = new
SlingFilterChainHelper();
@@ -244,8 +249,8 @@
// setting the Sling request and response
final RequestData requestData = new RequestData(this, servletRequest,
servletResponse);
- SlingHttpServletRequest request = requestData.getSlingRequest();
- SlingHttpServletResponse response = requestData.getSlingResponse();
+ final SlingHttpServletRequest request = requestData.getSlingRequest();
+ final SlingHttpServletResponse response =
requestData.getSlingResponse();
// request entry log
if (requestLogger != null) {
@@ -255,34 +260,46 @@
Session session = null;
try {
// check that we have all required services
- String missing = null;
+ String errorMessage = null;
+ final String serviceMissingSuffix = " service missing, cannot
service requests";
if (getResourceResolverFactory() == null) {
- missing = "ResourceResolverFactory";
+ errorMessage = "ResourceResolverFactory" +
serviceMissingSuffix;
} else if (getServletResolver() == null) {
- missing = "ServletResolver";
+ errorMessage = "ServletResolver" + serviceMissingSuffix;
} else if (mimeTypeService == null) {
- missing = "MimeTypeService";
- }
-
- if (missing != null) {
- final String err = missing
- + " service missing, cannot service requests";
- final int status = HttpServletResponse.SC_SERVICE_UNAVAILABLE;
- log.error("{} , sending status {}", err, status);
- sendError(status, err, null, servletRequest, servletResponse);
- return;
+ errorMessage = "MimeTypeService" + serviceMissingSuffix;
+ } else if(systemStatus == null) {
+ errorMessage = "SystemStatus" + serviceMissingSuffix;
}
// get JCR Session
session = (Session) servletRequest.getAttribute(SESSION);
if (session == null) {
- log.error("service: Cannot handle request: Missing JCR
Session");
- sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
- "Missing JCR Session", null, servletRequest,
- servletResponse);
+ errorMessage = "Missing JCR Session";
+ }
+
+ // system ready?
+ if(errorMessage == null) {
+ try {
+ systemStatus.checkSystemReady();
+ } catch(Exception e) {
+ errorMessage = e.toString();
+ }
+ }
+
+ if (errorMessage != null) {
+ final int status = HttpServletResponse.SC_SERVICE_UNAVAILABLE;
+ log.error("{} , sending status {}", errorMessage, status);
+ sendError(status, errorMessage, null, servletRequest,
servletResponse);
return;
}
+ // status request?
+ if(SystemStatus.STATUS_PATH.equals(request.getPathInfo())) {
+ systemStatus.doGet(request, response);
+ return;
+ }
+
// initialize the request data - resolve resource and servlet
ResourceResolver resolver =
getResourceResolverFactory().getResourceResolver(
session);
@@ -620,7 +637,6 @@
}
}
- @SuppressWarnings("unused")
protected void deactivate(ComponentContext componentContext) {
// first of all, we have to unregister
Propchange: incubator/sling/trunk/bundles/extensions/systemstatus/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Jun 12 16:23:05 2009
@@ -0,0 +1,5 @@
+.classpath
+.project
+.settings
+target
+
Added: incubator/sling/trunk/bundles/extensions/systemstatus/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/extensions/systemstatus/pom.xml?rev=784180&view=auto
==============================================================================
--- incubator/sling/trunk/bundles/extensions/systemstatus/pom.xml (added)
+++ incubator/sling/trunk/bundles/extensions/systemstatus/pom.xml Fri Jun 12
16:23:05 2009
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>5-incubator</version>
+ <relativePath>../../parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.sling.systemstatus</artifactId>
+ <packaging>bundle</packaging>
+ <version>2.0.5-incubator-SNAPSHOT</version>
+
+ <name>Apache Sling System Status Service</name>
+ <description>
+ Sling SystemStatus service, used to find out if
+ the system is ready to accept requests
+ </description>
+
+ <scm>
+
<connection>scm:svn:http://svn.apache.org/repos/asf/incubator/sling/trunk/bundles/extensions/systemstatus</connection>
+
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/incubator/sling/trunk/bundles/extensions/systemstatus</developerConnection>
+
<url>http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/extensions/systemstatus</url>
+ </scm>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Private-Package>
+ org.apache.sling.systemstatus.impl
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.api</artifactId>
+ <version>2.0.2-incubator</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.engine</artifactId>
+ <version>2.0.5-incubator-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Propchange: incubator/sling/trunk/bundles/extensions/systemstatus/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/sling/trunk/bundles/extensions/systemstatus/src/main/java/org/apache/sling/systemstatus/impl/SystemStatusService.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/extensions/systemstatus/src/main/java/org/apache/sling/systemstatus/impl/SystemStatusService.java?rev=784180&view=auto
==============================================================================
---
incubator/sling/trunk/bundles/extensions/systemstatus/src/main/java/org/apache/sling/systemstatus/impl/SystemStatusService.java
(added)
+++
incubator/sling/trunk/bundles/extensions/systemstatus/src/main/java/org/apache/sling/systemstatus/impl/SystemStatusService.java
Fri Jun 12 16:23:05 2009
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+
+package org.apache.sling.systemstatus.impl;
+
+import java.io.File;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.engine.SystemStatus;
+
+/** Default SystemStatus service - executes all scripts found
+ * under STATUS_PATH and considers system ready if none of
+ * them throws an Exception.
+ *
+ * @scr.component metatype="no" immediate="true"
+ * @scr.property name="service.vendor" value="The Apache Software Foundation"
+ * @scr.property name="service.description" value="Default SystemStatus
service"
+ * @scr.service
+ */
+public class SystemStatusService implements SystemStatus {
+
+ /** @inheritDoc */
+ public void checkSystemReady() throws Exception {
+ // TODO just a dummy implementation for now
+ final File dummyTest = new File("/tmp/SystemStatusService.foo");
+ if(dummyTest.exists()) {
+ throw new SystemStatus.StatusException(
+ "Simulating 'system not ready' condition as "
+ + dummyTest.getAbsolutePath() + " file exists"
+ );
+ }
+ }
+
+ /** @inheritDoc */
+ public void clear() {
+ }
+
+ /** @inheritDoc */
+ public void doGet(SlingHttpServletRequest req, SlingHttpServletResponse
resp) throws Exception {
+ // TODO just a dummy implementation for now
+ resp.setContentType("text/plain");
+ resp.setCharacterEncoding("UTF-8");
+ resp.getWriter().write("System status will come here, work in progress
- " + getClass().getName());
+ }
+
+}
\ No newline at end of file
Propchange:
incubator/sling/trunk/bundles/extensions/systemstatus/src/main/java/org/apache/sling/systemstatus/impl/SystemStatusService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/sling/trunk/bundles/extensions/systemstatus/src/main/java/org/apache/sling/systemstatus/impl/SystemStatusService.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Modified: incubator/sling/trunk/launchpad/bundles/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/bundles/pom.xml?rev=784180&r1=784179&r2=784180&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/bundles/pom.xml (original)
+++ incubator/sling/trunk/launchpad/bundles/pom.xml Fri Jun 12 16:23:05 2009
@@ -229,6 +229,12 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.systemstatus</artifactId>
+ <version>2.0.5-incubator-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.httpauth</artifactId>
<version>2.0.5-incubator-SNAPSHOT</version>
<scope>provided</scope>
@@ -437,7 +443,7 @@
</goals>
<configuration>
<includeArtifactIds>
-
org.apache.sling.api,org.apache.sling.engine,org.apache.sling.httpauth,org.apache.sling.adapter,org.apache.sling.servlets.resolver,org.apache.sling.servlets.get,org.apache.sling.servlets.post,org.apache.sling.commons.json,org.apache.sling.jcr.contentloader,org.apache.sling.jcr.resource,org.apache.sling.jcr.ocm,org.apache.sling.jcr.classloader,org.apache.sling.bundleresource.impl,org.apache.sling.launchpad.content,org.apache.sling.scripting.api,org.apache.sling.scripting.core,org.apache.sling.scripting.javascript,org.apache.sling.scripting.jsp,org.apache.sling.scripting.jsp.taglib,groovy-all
+
org.apache.sling.api,org.apache.sling.engine,org.apache.sling.systemstatus,org.apache.sling.httpauth,org.apache.sling.adapter,org.apache.sling.servlets.resolver,org.apache.sling.servlets.get,org.apache.sling.servlets.post,org.apache.sling.commons.json,org.apache.sling.jcr.contentloader,org.apache.sling.jcr.resource,org.apache.sling.jcr.ocm,org.apache.sling.jcr.classloader,org.apache.sling.bundleresource.impl,org.apache.sling.launchpad.content,org.apache.sling.scripting.api,org.apache.sling.scripting.core,org.apache.sling.scripting.javascript,org.apache.sling.scripting.jsp,org.apache.sling.scripting.jsp.taglib,groovy-all
</includeArtifactIds>
<excludeTransitive>true</excludeTransitive>
<outputDirectory>
Modified: incubator/sling/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/pom.xml?rev=784180&r1=784179&r2=784180&view=diff
==============================================================================
--- incubator/sling/trunk/pom.xml (original)
+++ incubator/sling/trunk/pom.xml Fri Jun 12 16:23:05 2009
@@ -112,6 +112,7 @@
<module>bundles/extensions/httpauth</module>
<module>bundles/extensions/openidauth</module>
<module>bundles/extensions/threaddump</module>
+ <module>bundles/extensions/systemstatus</module>
<!-- Launchpad -->
<module>launchpad/base</module>