You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2020/09/04 13:29:16 UTC

[sling-whiteboard] branch feature/new-modules created (now 9d8f1e5)

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a change to branch feature/new-modules
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git.


      at 9d8f1e5  Add instance-stopper to the reactor

This branch includes the following new commits:

     new ba32190  Add the hc-resource module
     new 03ef861  Add hc-resource to the reactor
     new 0f8a7ca  Add an instance-stopper module
     new 9d8f1e5  Add instance-stopper to the reactor

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[sling-whiteboard] 02/04: Add hc-resource to the reactor

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch feature/new-modules
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git

commit 03ef86131836164354ed196c0bc93c406ea94a2f
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri Sep 4 15:27:44 2020 +0200

    Add hc-resource to the reactor
---
 pom.xml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/pom.xml b/pom.xml
index 929b709..2d75e14 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,6 +48,7 @@
           <module>metrics-prometheus</module>
           <module>saml-handler</module>
           <module>saml-example</module>
+          <module>hc-resource</module>
     </modules>
 
 </project>


[sling-whiteboard] 04/04: Add instance-stopper to the reactor

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch feature/new-modules
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git

commit 9d8f1e587b608298fe0cbf90205b52d90b049bae
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri Sep 4 15:28:51 2020 +0200

    Add instance-stopper to the reactor
---
 pom.xml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/pom.xml b/pom.xml
index 2d75e14..bbd4023 100644
--- a/pom.xml
+++ b/pom.xml
@@ -49,6 +49,7 @@
           <module>saml-handler</module>
           <module>saml-example</module>
           <module>hc-resource</module>
+          <module>instance-stopper</module>
     </modules>
 
 </project>


[sling-whiteboard] 03/04: Add an instance-stopper module

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch feature/new-modules
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git

commit 0f8a7cae79e91e456638f3cd5ad5bbcdeb49acdc
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri Sep 4 15:28:31 2020 +0200

    Add an instance-stopper module
---
 instance-stopper/README.md                         | 14 ++++++
 instance-stopper/pom.xml                           | 58 ++++++++++++++++++++++
 .../sling/is/impl/SystemReadyInstanceStopper.java  | 46 +++++++++++++++++
 3 files changed, 118 insertions(+)

diff --git a/instance-stopper/README.md b/instance-stopper/README.md
new file mode 100644
index 0000000..33f5e52
--- /dev/null
+++ b/instance-stopper/README.md
@@ -0,0 +1,14 @@
+[<img src="https://sling.apache.org/res/logos/sling.png"/>](https://sling.apache.org)
+
+# Apache Sling Instance Stopper
+
+This module is part of the [Apache Sling](https://sling.apache.org) project.
+
+The instance stopper allows an instance to the shut down as soon as it is considered ready.
+The main scenario is part of the tooling for setting up a [CompositeNodeStore](https://jackrabbit.apache.org/oak/docs/nodestore/compositens.html).
+
+The readiness check is delegated to the [Felix HealthChecks](https://github.com/apache/felix-dev/tree/master/healthcheck).
+
+## Usage
+
+Include the bundle in your deployment.
diff --git a/instance-stopper/pom.xml b/instance-stopper/pom.xml
new file mode 100644
index 0000000..1907c03
--- /dev/null
+++ b/instance-stopper/pom.xml
@@ -0,0 +1,58 @@
+<?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-bundle-parent</artifactId>
+        <version>39</version>
+        <relativePath />
+    </parent>
+    <artifactId>org.apache.sling.instance-stopper</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <name>Apache Sling Instance Stopper</name>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>biz.aQute.bnd</groupId>
+                <artifactId>bnd-maven-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>biz.aQute.bnd</groupId>
+                <artifactId>bnd-baseline-maven-plugin</artifactId>
+                <configuration>
+                    <failOnMissing>false</failOnMissing>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.cmpn</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.healthcheck.api</artifactId>
+            <version>2.0.4</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/instance-stopper/src/main/java/org/apache/sling/is/impl/SystemReadyInstanceStopper.java b/instance-stopper/src/main/java/org/apache/sling/is/impl/SystemReadyInstanceStopper.java
new file mode 100644
index 0000000..e4adae5
--- /dev/null
+++ b/instance-stopper/src/main/java/org/apache/sling/is/impl/SystemReadyInstanceStopper.java
@@ -0,0 +1,46 @@
+/*-
+ * 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.is.impl;
+
+import org.apache.felix.hc.api.condition.SystemReady;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.launch.Framework;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+/**
+ * Component that shuts down the system as soon as it is ready
+ *
+ */
+@Component
+public class SystemReadyInstanceStopper {
+    
+    @Reference
+    private SystemReady systemReady;
+    
+    public void activate(BundleContext ctx) throws BundleException {
+        
+        ctx.getBundle(Constants.SYSTEM_BUNDLE_ID)
+            .adapt(Framework.class)
+            .stop();
+    }
+    
+}


[sling-whiteboard] 01/04: Add the hc-resource module

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch feature/new-modules
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git

commit ba32190bfdff2837876f7fc839ca8bb20507cc84
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri Sep 4 15:27:30 2020 +0200

    Add the hc-resource module
---
 hc-resource/README.md                              | 20 +++++
 hc-resource/pom.xml                                | 64 ++++++++++++++++
 .../hc/resource/impl/ResourceHealthCheck.java      | 89 ++++++++++++++++++++++
 3 files changed, 173 insertions(+)

diff --git a/hc-resource/README.md b/hc-resource/README.md
new file mode 100644
index 0000000..547a5d9
--- /dev/null
+++ b/hc-resource/README.md
@@ -0,0 +1,20 @@
+# Apache Sling Markdown Resource Provider
+
+This module is part of the [Apache Sling](https://sling.apache.org) project.
+
+This module contains [Health Checks](https://github.com/apache/felix-dev/tree/master/healthcheck) that use
+the Sling Resource API.
+
+## Usage
+
+```
+"org.apache.sling.hc.resource.impl.ResourceHealthCheck~slingshot": {
+    "hc.tags":[
+        "systemalive"
+    ],
+    "resources": [
+        "/content/slingshot",
+        "/libs/slingshot/Home/html.jsp"
+    ]
+}
+```
diff --git a/hc-resource/pom.xml b/hc-resource/pom.xml
new file mode 100644
index 0000000..630672a
--- /dev/null
+++ b/hc-resource/pom.xml
@@ -0,0 +1,64 @@
+<?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-bundle-parent</artifactId>
+        <version>39</version>
+        <relativePath />
+    </parent>
+    <artifactId>org.apache.sling.hc.resource</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <name>Apache Sling Health Check Resource</name>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>biz.aQute.bnd</groupId>
+                <artifactId>bnd-maven-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>biz.aQute.bnd</groupId>
+                <artifactId>bnd-baseline-maven-plugin</artifactId>
+                <configuration>
+                    <failOnMissing>false</failOnMissing>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.cmpn</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.healthcheck.api</artifactId>
+            <version>2.0.4</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.api</artifactId>
+            <version>2.20.0</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/hc-resource/src/main/java/org/apache/sling/hc/resource/impl/ResourceHealthCheck.java b/hc-resource/src/main/java/org/apache/sling/hc/resource/impl/ResourceHealthCheck.java
new file mode 100644
index 0000000..d76fe10
--- /dev/null
+++ b/hc-resource/src/main/java/org/apache/sling/hc/resource/impl/ResourceHealthCheck.java
@@ -0,0 +1,89 @@
+/*
+ * 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.hc.resource.impl;
+
+import org.apache.felix.hc.api.FormattingResultLog;
+import org.apache.felix.hc.api.HealthCheck;
+import org.apache.felix.hc.api.Result;
+import org.apache.sling.api.resource.LoginException;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.ConfigurationPolicy;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+
+@Component(configurationPolicy = ConfigurationPolicy.REQUIRE)
+@Designate(ocd = ResourceHealthCheck.Config.class, factory = true)
+public class ResourceHealthCheck implements HealthCheck {
+    
+    @ObjectClassDefinition(name = "Health Check: Resources Present", description = "Checks the configured path(s) against the given thresholds")
+    public @interface Config {
+        @AttributeDefinition(name = "Name", description = "Name of this health check")
+        String hc_name() default "Resources Present";
+
+        @AttributeDefinition(name = "Tags", description = "List of tags for this health check, used to select subsets of health checks for execution e.g. by a composite health check.")
+        String[] hc_tags() default {};
+        
+        @AttributeDefinition(name = "Resources", description = "List of resources to check for existence")
+        String[] resources() default {};
+
+        @AttributeDefinition
+        String webconsole_configurationFactory_nameHint() default "Resources present: {resources}";
+    }
+    
+    @Reference
+    private ResourceResolverFactory resolverFactory;
+    private Config cfg;
+    
+    @Activate
+    protected void activate(Config cfg) {
+        this.cfg = cfg;
+    }
+    
+    @Override
+    public Result execute() {
+        FormattingResultLog result = new FormattingResultLog();
+        
+        try ( ResourceResolver resolver = resolverFactory.getServiceResourceResolver(null) ) {
+            for (String resource : cfg.resources() )
+                checkResource(result, resolver, resource);
+        } catch (LoginException e) {
+            result.critical("Error obtaining a resource resolver", e);
+        }
+        
+        return new Result(result);
+    }
+
+    private void checkResource(FormattingResultLog result, ResourceResolver resolver, String resourcePath) {
+        
+        result.debug("Checking for resource at {}", resourcePath);
+        Resource resource = resolver.getResource(resourcePath);
+        
+        if ( resource == null )
+            result.critical("Resource at {} does not exist", resourcePath);
+        else
+            result.info("Resource {} exists", resourcePath);
+    }
+
+}