Author: bdelacretaz
Date: Wed Jul 31 12:05:43 2013
New Revision: 1508827
URL: http://svn.apache.org/r1508827
Log:
SLING-2987 - removing tons of code ;-)
Added:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/Constants.java
(with props)
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/HealthCheck.java
(with props)
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/Result.java
(with props)
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/ResultLog.java
(with props)
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/util/NumericValueChecker.java
(with props)
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/api/ResultLogTest.java
(with props)
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/api/ResultTest.java
(with props)
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/NumericValueCheckerTest.java
(with props)
Removed:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/EvaluationResult.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/Evaluator.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/HealthCheckFacade.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/Rule.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/RuleBuilder.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/RuleFilter.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/RuleLogger.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/RulesEngine.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/SystemAttribute.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/Activator.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/DefaultRuleBuilder.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/OSGiHealthCheckFacadeImpl.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/RuleLoggerImpl.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/RulesEngineImpl.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/TextRulesParser.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/util/DefaultEvaluator.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/util/TaggedRuleFilter.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/api/RuleInfoTest.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/api/RuleTagsTest.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/DefaultEvaluatorTest.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/RuleTest.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/RulesEngineTest.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/TextRulesParserTest.java
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/util/
Modified:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/pom.xml
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/util/RuleDynamicMBean.java
Modified: sling/branches/SLING-2987-healthcheck-redesign/hc-core/pom.xml
URL:
http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/pom.xml?rev=1508827&r1=1508826&r2=1508827&view=diff
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/hc-core/pom.xml (original)
+++ sling/branches/SLING-2987-healthcheck-redesign/hc-core/pom.xml Wed Jul 31
12:05:43 2013
@@ -33,15 +33,13 @@
<extensions>true</extensions>
<configuration>
<instructions>
- <Bundle-Activator>
- org.apache.sling.hc.impl.Activator
- </Bundle-Activator>
<Export-Package>
org.apache.sling.hc.api,
- org.apache.sling.hc.util
</Export-Package>
<Private-Package>
org.apache.sling.hc.impl.*
+ org.apache.sling.hc.util.*
+ org.apache.sling.hc.deprecated.*
</Private-Package>
</instructions>
</configuration>
Added:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/Constants.java
URL:
http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/Constants.java?rev=1508827&view=auto
==============================================================================
---
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/Constants.java
(added)
+++
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/Constants.java
Wed Jul 31 12:05:43 2013
@@ -0,0 +1,26 @@
+/*
+ * 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 SF 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.hc.api;
+
+public interface Constants {
+ /** info property name: the name of a health check */
+ String HC_NAME = "hc.name";
+
+ /** info property name: description of a health check */
+ String HC_DESCRIPTION = "hc.description";
+}
Propchange:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/Constants.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/Constants.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/HealthCheck.java
URL:
http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/HealthCheck.java?rev=1508827&view=auto
==============================================================================
---
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/HealthCheck.java
(added)
+++
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/HealthCheck.java
Wed Jul 31 12:05:43 2013
@@ -0,0 +1,38 @@
+/*
+ * 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 SF 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.hc.api;
+
+import java.util.Map;
+
+/** Health Check services can be executed and
+ * return an execution Result */
+public interface HealthCheck {
+
+ /** Execute this health check.
+ * @param log Any messages written to that log at or above the
+ * {@link ResultLog.MIN_LEVEL_TO_REPORT} level mean
+ * that the health check failed.
+ */
+ public Result execute(ResultLog log);
+
+ /** Additional (static) information about
+ * this check. {@link Constants} defines
+ * some well-known property names.
+ */
+ public Map<String, String> getInfo();
+}
Propchange:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/HealthCheck.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/HealthCheck.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/Result.java
URL:
http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/Result.java?rev=1508827&view=auto
==============================================================================
---
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/Result.java
(added)
+++
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/Result.java
Wed Jul 31 12:05:43 2013
@@ -0,0 +1,48 @@
+/*
+ * 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 SF 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.hc.api;
+
+import java.util.List;
+
+/** The result of executing a {@link HealthCheck} */
+public class Result {
+
+ private final HealthCheck healthCheck;
+ private final ResultLog log;
+
+ public Result(HealthCheck hc, ResultLog log) {
+ healthCheck = hc;
+ this.log = log;
+ }
+
+ public HealthCheck getHealthCheck() {
+ return healthCheck;
+ }
+
+ public List<ResultLog.Entry> getLogEntries() {
+ return log.getEntries();
+ }
+
+ public boolean isOk() {
+ return log.getMaxLevel().ordinal() <
ResultLog.MIN_LEVEL_TO_REPORT.ordinal();
+ }
+
+ public ResultLog.Level getStatus() {
+ return isOk() ? ResultLog.Level.OK : log.getMaxLevel();
+ }
+}
Propchange:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/Result.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/Result.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/ResultLog.java
URL:
http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/ResultLog.java?rev=1508827&view=auto
==============================================================================
---
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/ResultLog.java
(added)
+++
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/ResultLog.java
Wed Jul 31 12:05:43 2013
@@ -0,0 +1,446 @@
+/*
+ * 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 SF 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.hc.api;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.Marker;
+import org.slf4j.helpers.MessageFormatter;
+
+/** Wraps an slf4 Logger to save its messages,
+ * to make the log of {@link HealthCheck} executions
+ * available as part of the {@link Result}.
+ **/
+public class ResultLog implements Logger {
+
+ private final Logger wrappedLogger;
+ private Level maxLevel = Level.DEBUG;
+ private final List<Entry> entries;
+
+ /** Log messages at or above this level change the {@link Result's status}
*/
+ public static final Level MIN_LEVEL_TO_REPORT = Level.WARN;
+
+ /** The log level of our entries */
+ public enum Level {
+ OK,
+ TRACE,
+ DEBUG,
+ INFO,
+ WARN,
+ ERROR
+ }
+
+ /** An entry in our mini-log */
+ public static class Entry {
+ private final Level level;
+ private final String message;
+
+ Entry(Level level, String message) {
+ this.level = level;
+ this.message = message;
+ }
+
+ public String toString() {
+ return level + ": " + message;
+ }
+
+ public Level getLevel() {
+ return level;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+ }
+
+ public ResultLog(Logger wrappedLogger) {
+ this.wrappedLogger = wrappedLogger;
+ entries = new LinkedList<Entry>();
+ }
+
+ public Level getMaxLevel() {
+ return maxLevel;
+ }
+
+ public List<Entry> getEntries() {
+ return Collections.unmodifiableList(entries);
+ }
+
+ private void storeMessage(ResultLog.Level level, String message) {
+ maxLevel = level.ordinal() > maxLevel.ordinal() ? level : maxLevel;
+ entries.add(new ResultLog.Entry(level, message));
+ }
+
+ @Override
+ public String getName() {
+ return getClass().getName();
+ }
+
+ @Override
+ public void debug(Marker arg0, String arg1, Object arg2, Object arg3) {
+ storeMessage(Level.DEBUG, MessageFormatter.format(arg1, arg2,
arg3).getMessage());
+ wrappedLogger.debug(arg0, arg1, arg2, arg3);
+ }
+
+ @Override
+ public void debug(Marker arg0, String arg1, Object arg2) {
+ storeMessage(Level.DEBUG, MessageFormatter.format(arg1,
arg2).getMessage());
+ wrappedLogger.debug(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void debug(Marker arg0, String arg1, Object[] arg2) {
+ storeMessage(Level.DEBUG, MessageFormatter.arrayFormat(arg1,
arg2).getMessage());
+ wrappedLogger.debug(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void debug(Marker arg0, String arg1, Throwable arg2) {
+ storeMessage(Level.DEBUG, MessageFormatter.format(arg1,
arg2).getMessage());
+ wrappedLogger.debug(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void debug(Marker arg0, String arg1) {
+ storeMessage(Level.DEBUG, arg1);
+ wrappedLogger.debug(arg0, arg1);
+ }
+
+ @Override
+ public void debug(String arg0, Object arg1, Object arg2) {
+ storeMessage(Level.DEBUG, MessageFormatter.format(arg0, arg1,
arg2).getMessage());
+ wrappedLogger.debug(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void debug(String arg0, Object arg1) {
+ storeMessage(Level.DEBUG, MessageFormatter.format(arg0,
arg1).getMessage());
+ wrappedLogger.debug(arg0, arg1);
+ }
+
+ @Override
+ public void debug(String arg0, Object[] arg1) {
+ storeMessage(Level.DEBUG, MessageFormatter.arrayFormat(arg0,
arg1).getMessage());
+ wrappedLogger.debug(arg0, arg1);
+ }
+
+ @Override
+ public void debug(String arg0, Throwable arg1) {
+ storeMessage(Level.DEBUG, MessageFormatter.format(arg0,
arg1).getMessage());
+ wrappedLogger.debug(arg0, arg1);
+ }
+
+ @Override
+ public void debug(String arg0) {
+ storeMessage(Level.DEBUG, arg0);
+ wrappedLogger.debug(arg0);
+ }
+
+ @Override
+ public boolean isDebugEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isDebugEnabled(Marker arg0) {
+ return true;
+ }
+
+ @Override
+ public void info(Marker arg0, String arg1, Object arg2, Object arg3) {
+ storeMessage(Level.INFO, MessageFormatter.format(arg1, arg2,
arg3).getMessage());
+ wrappedLogger.info(arg0, arg1, arg2, arg3);
+ }
+
+ @Override
+ public void info(Marker arg0, String arg1, Object arg2) {
+ storeMessage(Level.INFO, MessageFormatter.format(arg1,
arg2).getMessage());
+ wrappedLogger.info(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void info(Marker arg0, String arg1, Object[] arg2) {
+ storeMessage(Level.INFO, MessageFormatter.arrayFormat(arg1,
arg2).getMessage());
+ wrappedLogger.info(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void info(Marker arg0, String arg1, Throwable arg2) {
+ storeMessage(Level.INFO, MessageFormatter.format(arg1,
arg2).getMessage());
+ wrappedLogger.info(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void info(Marker arg0, String arg1) {
+ storeMessage(Level.INFO, arg1);
+ wrappedLogger.info(arg0, arg1);
+ }
+
+ @Override
+ public void info(String arg0, Object arg1, Object arg2) {
+ storeMessage(Level.INFO, MessageFormatter.format(arg0, arg1,
arg2).getMessage());
+ wrappedLogger.info(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void info(String arg0, Object arg1) {
+ storeMessage(Level.INFO, MessageFormatter.format(arg0,
arg1).getMessage());
+ wrappedLogger.info(arg0, arg1);
+ }
+
+ @Override
+ public void info(String arg0, Object[] arg1) {
+ storeMessage(Level.INFO, MessageFormatter.arrayFormat(arg0,
arg1).getMessage());
+ wrappedLogger.info(arg0, arg1);
+ }
+
+ @Override
+ public void info(String arg0, Throwable arg1) {
+ storeMessage(Level.INFO, MessageFormatter.format(arg0,
arg1).getMessage());
+ wrappedLogger.info(arg0, arg1);
+ }
+
+ @Override
+ public void info(String arg0) {
+ storeMessage(Level.INFO, arg0);
+ wrappedLogger.info(arg0);
+ }
+
+ @Override
+ public boolean isInfoEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isInfoEnabled(Marker arg0) {
+ return true;
+ }
+
+ @Override
+ public void warn(Marker arg0, String arg1, Object arg2, Object arg3) {
+ storeMessage(Level.WARN, MessageFormatter.format(arg1, arg2,
arg3).getMessage());
+ wrappedLogger.warn(arg0, arg1, arg2, arg3);
+ }
+
+ @Override
+ public void warn(Marker arg0, String arg1, Object arg2) {
+ storeMessage(Level.WARN, MessageFormatter.format(arg1,
arg2).getMessage());
+ wrappedLogger.warn(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void warn(Marker arg0, String arg1, Object[] arg2) {
+ storeMessage(Level.WARN, MessageFormatter.arrayFormat(arg1,
arg2).getMessage());
+ wrappedLogger.warn(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void warn(Marker arg0, String arg1, Throwable arg2) {
+ storeMessage(Level.WARN, MessageFormatter.format(arg1,
arg2).getMessage());
+ wrappedLogger.warn(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void warn(Marker arg0, String arg1) {
+ storeMessage(Level.WARN, arg1);
+ wrappedLogger.warn(arg0, arg1);
+ }
+
+ @Override
+ public void warn(String arg0, Object arg1, Object arg2) {
+ storeMessage(Level.WARN, MessageFormatter.format(arg0, arg1,
arg2).getMessage());
+ wrappedLogger.warn(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void warn(String arg0, Object arg1) {
+ storeMessage(Level.WARN, MessageFormatter.format(arg0,
arg1).getMessage());
+ wrappedLogger.warn(arg0, arg1);
+ }
+
+ @Override
+ public void warn(String arg0, Object[] arg1) {
+ storeMessage(Level.WARN, MessageFormatter.arrayFormat(arg0,
arg1).getMessage());
+ wrappedLogger.warn(arg0, arg1);
+ }
+
+ @Override
+ public void warn(String arg0, Throwable arg1) {
+ storeMessage(Level.WARN, MessageFormatter.format(arg0,
arg1).getMessage());
+ wrappedLogger.warn(arg0, arg1);
+ }
+
+ @Override
+ public void warn(String arg0) {
+ storeMessage(Level.WARN, arg0);
+ wrappedLogger.warn(arg0);
+ }
+
+ @Override
+ public boolean isWarnEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isWarnEnabled(Marker arg0) {
+ return true;
+ }
+
+ @Override
+ public void error(Marker arg0, String arg1, Object arg2, Object arg3) {
+ storeMessage(Level.ERROR, MessageFormatter.format(arg1, arg2,
arg3).getMessage());
+ wrappedLogger.error(arg0, arg1, arg2, arg3);
+ }
+
+ @Override
+ public void error(Marker arg0, String arg1, Object arg2) {
+ storeMessage(Level.ERROR, MessageFormatter.format(arg1,
arg2).getMessage());
+ wrappedLogger.error(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void error(Marker arg0, String arg1, Object[] arg2) {
+ storeMessage(Level.ERROR, MessageFormatter.arrayFormat(arg1,
arg2).getMessage());
+ wrappedLogger.error(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void error(Marker arg0, String arg1, Throwable arg2) {
+ storeMessage(Level.ERROR, MessageFormatter.format(arg1,
arg2).getMessage());
+ wrappedLogger.error(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void error(Marker arg0, String arg1) {
+ storeMessage(Level.ERROR, arg1);
+ wrappedLogger.error(arg0, arg1);
+ }
+
+ @Override
+ public void error(String arg0, Object arg1, Object arg2) {
+ storeMessage(Level.ERROR, MessageFormatter.format(arg0, arg1,
arg2).getMessage());
+ wrappedLogger.error(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void error(String arg0, Object arg1) {
+ storeMessage(Level.ERROR, MessageFormatter.format(arg0,
arg1).getMessage());
+ wrappedLogger.error(arg0, arg1);
+ }
+
+ @Override
+ public void error(String arg0, Object[] arg1) {
+ storeMessage(Level.ERROR, MessageFormatter.arrayFormat(arg0,
arg1).getMessage());
+ wrappedLogger.error(arg0, arg1);
+ }
+
+ @Override
+ public void error(String arg0, Throwable arg1) {
+ storeMessage(Level.ERROR, MessageFormatter.format(arg0,
arg1).getMessage());
+ wrappedLogger.error(arg0, arg1);
+ }
+
+ @Override
+ public void error(String arg0) {
+ storeMessage(Level.ERROR, arg0);
+ wrappedLogger.error(arg0);
+ }
+
+ @Override
+ public boolean isErrorEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isErrorEnabled(Marker arg0) {
+ return true;
+ }
+
+ @Override
+ public void trace(Marker arg0, String arg1, Object arg2, Object arg3) {
+ storeMessage(Level.TRACE, MessageFormatter.format(arg1, arg2,
arg3).getMessage());
+ wrappedLogger.trace(arg0, arg1, arg2, arg3);
+ }
+
+ @Override
+ public void trace(Marker arg0, String arg1, Object arg2) {
+ storeMessage(Level.TRACE, MessageFormatter.format(arg1,
arg2).getMessage());
+ wrappedLogger.trace(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void trace(Marker arg0, String arg1, Object[] arg2) {
+ storeMessage(Level.TRACE, MessageFormatter.arrayFormat(arg1,
arg2).getMessage());
+ wrappedLogger.trace(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void trace(Marker arg0, String arg1, Throwable arg2) {
+ storeMessage(Level.TRACE, MessageFormatter.format(arg1,
arg2).getMessage());
+ wrappedLogger.trace(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void trace(Marker arg0, String arg1) {
+ storeMessage(Level.TRACE, arg1);
+ wrappedLogger.trace(arg0, arg1);
+ }
+
+ @Override
+ public void trace(String arg0, Object arg1, Object arg2) {
+ storeMessage(Level.TRACE, MessageFormatter.format(arg0, arg1,
arg2).getMessage());
+ wrappedLogger.trace(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void trace(String arg0, Object arg1) {
+ storeMessage(Level.TRACE, MessageFormatter.format(arg0,
arg1).getMessage());
+ wrappedLogger.trace(arg0, arg1);
+ }
+
+ @Override
+ public void trace(String arg0, Object[] arg1) {
+ storeMessage(Level.TRACE, MessageFormatter.arrayFormat(arg0,
arg1).getMessage());
+ wrappedLogger.trace(arg0, arg1);
+ }
+
+ @Override
+ public void trace(String arg0, Throwable arg1) {
+ storeMessage(Level.TRACE, MessageFormatter.format(arg0,
arg1).getMessage());
+ wrappedLogger.trace(arg0, arg1);
+ }
+
+ @Override
+ public void trace(String arg0) {
+ storeMessage(Level.TRACE, arg0);
+ wrappedLogger.trace(arg0);
+ }
+
+ @Override
+ public boolean isTraceEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isTraceEnabled(Marker arg0) {
+ return true;
+ }
+}
Propchange:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/ResultLog.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/api/ResultLog.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/util/NumericValueChecker.java
URL:
http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/util/NumericValueChecker.java?rev=1508827&view=auto
==============================================================================
---
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/util/NumericValueChecker.java
(added)
+++
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/util/NumericValueChecker.java
Wed Jul 31 12:05:43 2013
@@ -0,0 +1,66 @@
+/*
+ * 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 SF 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.hc.util;
+
+import org.slf4j.Logger;
+
+/** Simple check of numeric values against expressions
+ * like < N, > N, between two values etc.
+ * See {@link NumericValueCheckerTest} for examples.
+ */
+public class NumericValueChecker {
+
+ /** Check value against expression and report to logger */
+ public void check(Object inputValue, String expression, Logger logger) {
+
+ final String stringValue = inputValue == null ? "" :
inputValue.toString();
+
+ if(expression == null || expression.trim().length() == 0) {
+ // No expression, result will be based on a.getValue() logging only
+ return;
+ }
+
+ final String [] parts = expression.split(" ");
+ boolean matches = false;
+ try {
+ if(expression.startsWith(">") && parts.length == 2) {
+ final int value = Integer.valueOf(stringValue).intValue();
+ matches = value > Integer.valueOf(parts[1]);
+
+ } else if(expression.startsWith("<") && parts.length == 2) {
+ final int value = Integer.valueOf(stringValue).intValue();
+ matches = value < Integer.valueOf(parts[1]);
+
+ } else if(parts.length == 4 &&
"between".equalsIgnoreCase(parts[0]) && "and".equalsIgnoreCase(parts[2]) ) {
+ final int value = Integer.valueOf(stringValue).intValue();
+ final int lowerBound = Integer.valueOf(parts[1]);
+ final int upperBound = Integer.valueOf(parts[3]);
+ matches = value > lowerBound && value < upperBound;
+
+ } else {
+ matches = expression.equals(stringValue);
+ }
+ } catch(NumberFormatException nfe) {
+ logger.warn("Invalid numeric value [{}] while evaluating {}",
inputValue, expression);
+ }
+
+ if(!matches) {
+ logger.warn("Value [{}] does not match expression [{}]",
stringValue, expression);
+ }
+ }
+}
\ No newline at end of file
Propchange:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/util/NumericValueChecker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/util/NumericValueChecker.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Modified:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/util/RuleDynamicMBean.java
URL:
http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/util/RuleDynamicMBean.java?rev=1508827&r1=1508826&r2=1508827&view=diff
==============================================================================
---
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/util/RuleDynamicMBean.java
(original)
+++
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/util/RuleDynamicMBean.java
Wed Jul 31 12:05:43 2013
@@ -17,42 +17,21 @@
*/
package org.apache.sling.hc.util;
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.management.Attribute;
-import javax.management.AttributeList;
-import javax.management.AttributeNotFoundException;
import javax.management.DynamicMBean;
-import javax.management.InvalidAttributeValueException;
-import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanException;
-import javax.management.MBeanInfo;
-import javax.management.ReflectionException;
-import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeType;
-import javax.management.openmbean.OpenDataException;
-import javax.management.openmbean.OpenMBeanAttributeInfoSupport;
import javax.management.openmbean.OpenType;
import javax.management.openmbean.SimpleType;
-import javax.management.openmbean.TabularData;
-import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.TabularType;
-import org.apache.sling.hc.api.EvaluationResult;
-import org.apache.sling.hc.api.Rule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** A {@link DynamicMBean} that gives access to a {@link Rule}'s data */
-public class RuleDynamicMBean implements DynamicMBean, Serializable {
+public class RuleDynamicMBean { //implements DynamicMBean, Serializable {
private static final long serialVersionUID = -90745301105975287L;
private static final Logger logger =
LoggerFactory.getLogger(RuleDynamicMBean.class);
- private final String beanName;
- private final Rule rule;
+ //private final String beanName;
public static final String RULE_OK_ATTRIBUTE_NAME = "ok";
public static final String LOG_ATTRIBUTE_NAME = "log";
@@ -81,7 +60,7 @@ public class RuleDynamicMBean implements
}
}
-
+ /*
public RuleDynamicMBean(Rule r) {
beanName = r.toString();
rule = r;
@@ -103,10 +82,10 @@ public class RuleDynamicMBean implements
}
}
- private TabularData logData(EvaluationResult er) {
+ private TabularData logData(Result er) {
final TabularDataSupport result = new
TabularDataSupport(LOG_TABLE_TYPE);
int i=1;
- for(EvaluationResult.LogMessage msg : er.getLogMessages()) {
+ for(Result.LogMessage msg : er.getLogMessages()) {
final Map<String, Object> data = new HashMap<String, Object>();
data.put(INDEX_COLUMN, i++);
data.put(LEVEL_COLUMN, msg.getLevel().toString());
@@ -164,4 +143,5 @@ public class RuleDynamicMBean implements
public AttributeList setAttributes(AttributeList attributes) {
throw new UnsupportedOperationException(getClass().getSimpleName() + "
does not support setting Rules attributes");
}
+ */
}
\ No newline at end of file
Added:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/api/ResultLogTest.java
URL:
http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/api/ResultLogTest.java?rev=1508827&view=auto
==============================================================================
---
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/api/ResultLogTest.java
(added)
+++
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/api/ResultLogTest.java
Wed Jul 31 12:05:43 2013
@@ -0,0 +1,44 @@
+/*
+ * 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 SF 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.hc.api;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.LoggerFactory;
+
+public class ResultLogTest {
+ private ResultLog resultLog;
+
+ @Before
+ public void setup() {
+ resultLog = new ResultLog(LoggerFactory.getLogger(getClass()));
+ }
+
+ @Test
+ public void testMaxLevel() {
+ assertEquals(ResultLog.Level.DEBUG, resultLog.getMaxLevel());
+ resultLog.debug("something");
+ assertEquals(ResultLog.Level.DEBUG, resultLog.getMaxLevel());
+ resultLog.info("something");
+ assertEquals(ResultLog.Level.INFO, resultLog.getMaxLevel());
+ resultLog.warn("something");
+ assertEquals(ResultLog.Level.WARN, resultLog.getMaxLevel());
+ }
+}
Propchange:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/api/ResultLogTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/api/ResultLogTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/api/ResultTest.java
URL:
http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/api/ResultTest.java?rev=1508827&view=auto
==============================================================================
---
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/api/ResultTest.java
(added)
+++
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/api/ResultTest.java
Wed Jul 31 12:05:43 2013
@@ -0,0 +1,65 @@
+/*
+ * 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 SF 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.hc.api;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.LoggerFactory;
+
+public class ResultTest {
+ private ResultLog resultLog;
+ private Result result;
+
+ @Before
+ public void setup() {
+ resultLog = new ResultLog(LoggerFactory.getLogger(getClass()));
+ result = new Result(null, resultLog);
+ }
+
+ @Test
+ public void testInitiallyOk() {
+ assertTrue(result.isOk());
+ }
+
+ @Test
+ public void testDebugOk() {
+ resultLog.debug("something");
+ assertTrue(result.isOk());
+ }
+
+ @Test
+ public void testInfoOk() {
+ resultLog.info("something");
+ assertTrue(result.isOk());
+ }
+
+ @Test
+ public void testWarnNotOk() {
+ resultLog.warn("something");
+ assertFalse(result.isOk());
+ }
+
+ @Test
+ public void testErrorNotOk() {
+ resultLog.error("something");
+ assertFalse(result.isOk());
+ }
+}
Propchange:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/api/ResultTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/api/ResultTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/NumericValueCheckerTest.java
URL:
http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/NumericValueCheckerTest.java?rev=1508827&view=auto
==============================================================================
---
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/NumericValueCheckerTest.java
(added)
+++
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/NumericValueCheckerTest.java
Wed Jul 31 12:05:43 2013
@@ -0,0 +1,152 @@
+/*
+ * 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 SF 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.hc.impl;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.sling.hc.api.Result;
+import org.apache.sling.hc.api.ResultLog;
+import org.apache.sling.hc.util.NumericValueChecker;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.LoggerFactory;
+
+public class NumericValueCheckerTest {
+ private ResultLog resultLog;
+ private Result result;
+
+ private final NumericValueChecker checker = new NumericValueChecker();
+
+ @Before
+ public void setup() {
+ resultLog = new ResultLog(LoggerFactory.getLogger(getClass()));
+ result = new Result(null, resultLog);
+ }
+
+ @Test
+ public void testStringEquals() {
+ final String s = "test_" + System.currentTimeMillis();
+ checker.check(s, s, resultLog);
+ assertTrue(result.isOk());
+ }
+
+ @Test
+ public void testStringNotEquals() {
+ final String s = "test_" + System.currentTimeMillis();
+ checker.check(s, "something else", resultLog);
+ assertFalse(result.isOk());
+ }
+
+ @Test
+ public void testFiveEquals() {
+ final String s = "5";
+ checker.check(s, s, resultLog);
+ assertTrue(result.isOk());
+ }
+
+ @Test
+ public void testIntTwelveEquals() {
+ checker.check(12, "12", resultLog);
+ assertTrue(result.isOk());
+ }
+
+ @Test
+ public void testIntTwelveGreaterThan() {
+ checker.check(12, "> 11", resultLog);
+ assertTrue(result.isOk());
+ }
+
+ @Test
+ public void testFiveNotEquals() {
+ checker.check("5", "foo", resultLog);
+ assertFalse(result.isOk());
+ }
+
+ @Test
+ public void testNullNotEquals() {
+ checker.check(null, "foo", resultLog);
+ assertFalse(result.isOk());
+ }
+
+ @Test
+ public void testNullNotGreater() {
+ checker.check(null, "> 2", resultLog);
+ assertFalse(result.isOk());
+ }
+
+ @Test
+ public void testGreaterThanTrue() {
+ checker.check("5", "> 2", resultLog);
+ assertTrue(result.isOk());
+ }
+
+ @Test
+ public void testGreaterThanFalse() {
+ checker.check("5", "> 12", resultLog);
+ assertFalse(result.isOk());
+ }
+
+ @Test
+ public void testLessThanTrue() {
+ checker.check("5", "< 12", resultLog);
+ assertTrue(result.isOk());
+ }
+
+ @Test
+ public void testLessThanFalse() {
+ checker.check("5", "< 2", resultLog);
+ assertFalse(result.isOk());
+ }
+
+ @Test
+ public void testBetweenA() {
+ checker.check("5", "between 2 and 6", resultLog);
+ assertTrue(result.isOk());
+ }
+
+ @Test
+ public void testBetweenB() {
+ checker.check("5", "between 12 and 16", resultLog);
+ assertFalse(result.isOk());
+ }
+
+ @Test
+ public void testBetweenC() {
+ checker.check(5L, "between 12 and 16", resultLog);
+ assertFalse(result.isOk());
+ }
+
+ @Test
+ public void testBetweenD() {
+ checker.check(5L, "between 4 and 16", resultLog);
+ assertTrue(result.isOk());
+ }
+
+ @Test
+ public void testBetweenE() {
+ checker.check(5L, "betWEEN 4 aND 16", resultLog);
+ assertTrue(result.isOk());
+ }
+
+ @Test
+ public void testNotAnInteger() {
+ checker.check("foo", "between 12 and 16", resultLog);
+ assertFalse(result.isOk());
+ }
+}
Propchange:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/NumericValueCheckerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/NumericValueCheckerTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL