Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
637 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.idea | ||
*.iml | ||
target | ||
|
10
README.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
= Geronimo Microprofile Health Implementation | ||
|
||
[source,xml] | ||
---- | ||
<parent> | ||
<groupId>org.apache.geronimo</groupId> | ||
<artifactId>geronimo-health</artifactId> | ||
<version>${project.version}</version> | ||
</parent> | ||
---- |
220
pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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</groupId> | ||
<artifactId>apache</artifactId> | ||
<version>20</version> | ||
</parent> | ||
|
||
<groupId>org.apache.geronimo</groupId> | ||
<artifactId>geronimo-health</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<name>Geronimo Microprofile Health Implementation</name> | ||
|
||
<description> | ||
Apache Geronimo implementation of the Microprofile Health Specification | ||
</description> | ||
|
||
<scm> | ||
<connection>scm:git:https://gitbox.apache.org/repos/asf/geronimo-health.git</connection> | ||
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/geronimo-health.git</developerConnection> | ||
<url>https://gitbox.apache.org/repos/asf/geronimo-health.git</url> | ||
<tag>HEAD</tag> | ||
</scm> | ||
|
||
<properties> | ||
<spec.version>1.0</spec.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.microprofile.health</groupId> | ||
<artifactId>microprofile-health-api</artifactId> | ||
<version>${spec.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.tomcat</groupId> | ||
<artifactId>tomcat-servlet-api</artifactId> | ||
<version>9.0.7</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.geronimo.specs</groupId> | ||
<artifactId>geronimo-jaxrs_2.0_spec</artifactId> | ||
<version>1.0-alpha-1</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.geronimo.specs</groupId> | ||
<artifactId>geronimo-json_1.1_spec</artifactId> | ||
<version>1.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.geronimo.specs</groupId> | ||
<artifactId>geronimo-jsonb_1.0_spec</artifactId> | ||
<version>1.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.geronimo.specs</groupId> | ||
<artifactId>geronimo-interceptor_1.2_spec</artifactId> | ||
<version>1.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.geronimo.specs</groupId> | ||
<artifactId>geronimo-atinject_1.0_spec</artifactId> | ||
<version>1.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.geronimo.specs</groupId> | ||
<artifactId>geronimo-jcdi_2.0_spec</artifactId> | ||
<version>1.0.1</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.geronimo.specs</groupId> | ||
<artifactId>geronimo-annotation_1.3_spec</artifactId> | ||
<version>1.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.microprofile.config</groupId> | ||
<artifactId>microprofile-config-api</artifactId> | ||
<version>1.2</version> | ||
<scope>provided</scope> | ||
<optional>true</optional> | ||
</dependency> | ||
|
||
<dependency> <!-- issue with the cache key --> | ||
<groupId>org.apache.openwebbeans</groupId> | ||
<artifactId>openwebbeans-impl</artifactId> | ||
<version>2.0.5</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.geronimo.specs</groupId> | ||
<artifactId>geronimo-jacc_1.1_spec</artifactId> | ||
<version>1.0.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.arquillian.testng</groupId> | ||
<artifactId>arquillian-testng-container</artifactId> | ||
<version>1.1.13.Final</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<version>6.8.21</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.meecrowave</groupId> | ||
<artifactId>meecrowave-arquillian</artifactId> | ||
<version>1.2.1</version> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>javax.inject</groupId> | ||
<artifactId>javax.inject</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.microprofile.health</groupId> | ||
<artifactId>microprofile-health-tck</artifactId> | ||
<version>${spec.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.7.0</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.0</version> | ||
<configuration> | ||
<dependenciesToScan> | ||
<dependency>org.eclipse.microprofile.health:microprofile-health-tck</dependency> | ||
</dependenciesToScan> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.0.2</version> | ||
<configuration> | ||
<archive combine.children="append"> | ||
<manifestEntries> | ||
<Automatic-Module-Name>org.apache.geronimo.microprofile.health</Automatic-Module-Name> | ||
</manifestEntries> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<organization> | ||
<name>The Apache Software Foundation</name> | ||
<url>http://www.apache.org/</url> | ||
</organization> | ||
|
||
<inceptionYear>2018</inceptionYear> | ||
|
||
<licenses> | ||
<license> | ||
<name>Apache License, Version 2.0</name> | ||
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<developers> | ||
<developer> | ||
<name>Apache Geronimo Community</name> | ||
<url>https://geronimo.apache.org</url> | ||
<organization>Apache</organization> | ||
</developer> | ||
</developers> | ||
|
||
<issueManagement> | ||
<system>ASF JIRA</system> | ||
<url>https://issues.apache.org/jira/browse/GERONIMO</url> | ||
</issueManagement> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* 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.geronimo.microprofile.impl.health.cdi; | ||
|
||
import static java.util.stream.Collectors.toList; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import javax.enterprise.context.spi.CreationalContext; | ||
import javax.enterprise.event.Observes; | ||
import javax.enterprise.inject.spi.AfterDeploymentValidation; | ||
import javax.enterprise.inject.spi.Bean; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
import javax.enterprise.inject.spi.BeforeShutdown; | ||
import javax.enterprise.inject.spi.Extension; | ||
import javax.enterprise.inject.spi.ProcessBean; | ||
|
||
import org.eclipse.microprofile.health.Health; | ||
import org.eclipse.microprofile.health.HealthCheck; | ||
|
||
public class GeronimoHealthExtension implements Extension { | ||
private final Collection<Bean<?>> beans = new ArrayList<>(); | ||
private final Collection<CreationalContext<?>> contexts = new ArrayList<>(); | ||
private List<HealthCheck> checks; | ||
|
||
void findChecks(@Observes final ProcessBean<?> bean) { | ||
if (bean.getAnnotated().isAnnotationPresent(Health.class) && bean.getBean().getTypes().contains(HealthCheck.class)) { | ||
beans.add(bean.getBean()); | ||
} | ||
} | ||
|
||
void start(@Observes final AfterDeploymentValidation afterDeploymentValidation, final BeanManager beanManager) { | ||
checks = beans.stream() | ||
.map(it -> lookup(it, beanManager)) | ||
.collect(toList()); | ||
} | ||
|
||
void stop(@Observes final BeforeShutdown beforeShutdown) { | ||
final IllegalStateException ise = new IllegalStateException("Something went wrong releasing health checks"); | ||
contexts.forEach(c -> { | ||
try { | ||
c.release(); | ||
} catch (final RuntimeException re) { | ||
ise.addSuppressed(re); | ||
} | ||
}); | ||
final Throwable[] suppressed = ise.getSuppressed(); | ||
if (suppressed.length == 1) { | ||
throw RuntimeException.class.cast(suppressed[0]); | ||
} else if (suppressed.length > 1) { | ||
throw ise; | ||
} | ||
} | ||
|
||
public List<HealthCheck> getChecks() { | ||
return checks; | ||
} | ||
|
||
private HealthCheck lookup(final Bean<?> bean, final BeanManager manager) { | ||
final Class<?> type = bean.getBeanClass() == null ? HealthCheck.class : bean.getBeanClass(); | ||
final Set<Bean<?>> beans = manager.getBeans(type, bean.getQualifiers().toArray(new Annotation[bean.getQualifiers().size()])); | ||
final Bean<?> resolvedBean = manager.resolve(beans); | ||
final CreationalContext<Object> creationalContext = manager.createCreationalContext(null); | ||
if (!manager.isNormalScope(resolvedBean.getScope())) { | ||
contexts.add(creationalContext); | ||
} | ||
return HealthCheck.class.cast(manager.getReference(resolvedBean, HealthCheck.class, creationalContext)); | ||
} | ||
} |
Oops, something went wrong.