Skip to content
Permalink
Browse files
GERONIMO-6649 extract the common part of the project in a common module
  • Loading branch information
rmannibucau committed Oct 19, 2018
1 parent 9f8bb13 commit 6601d8ec0213dcf4b1751219d90725e733418c49
Showing 15 changed files with 271 additions and 104 deletions.
@@ -0,0 +1,36 @@
<?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/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.apache.geronimo</groupId>
<artifactId>geronimo-health-parent</artifactId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>geronimo-health-common</artifactId>
<name>Geronimo Health :: Common</name>

<properties>
<geronimo-health.Automatic-Module-Name>org.apache.geronimo.microprofile.health.common</geronimo-health.Automatic-Module-Name>
</properties>
</project>
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.impl.health.impl;
package org.apache.geronimo.microprofile.common.impl;

import java.util.HashMap;
import java.util.Map;
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.impl.health.impl;
package org.apache.geronimo.microprofile.common.impl;

import java.util.Map;
import java.util.Optional;
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.impl.health.impl;
package org.apache.geronimo.microprofile.common.impl;

import org.eclipse.microprofile.health.HealthCheckResponseBuilder;
import org.eclipse.microprofile.health.spi.HealthCheckResponseProvider;
@@ -14,35 +14,40 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.impl.health.jaxrs;
package org.apache.geronimo.microprofile.common.jaxrs;

import static java.util.stream.Collectors.toList;

import java.util.Collection;
import java.util.List;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.geronimo.microprofile.impl.health.cdi.GeronimoHealthExtension;
import org.apache.geronimo.microprofile.common.registry.HealthChecksRegistry;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;

@Path("health")
@ApplicationScoped
// @ApplicationScoped
public class HealthChecksEndpoint {
@Inject
private GeronimoHealthExtension extension;
private HealthChecksRegistry registry;

public void setRegistry(final HealthChecksRegistry registry) {
this.registry = registry;
}

@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getChecks() {
final List<HealthCheckResponse> checks = extension.getChecks()
if (registry == null) {
registry = HealthChecksRegistry.load();
}

final List<HealthCheckResponse> checks = registry.getChecks()
.stream()
.map(HealthCheck::call)
.collect(toList());
@@ -0,0 +1,35 @@
/**
* 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.common.registry;

import java.util.Collection;
import java.util.Iterator;
import java.util.ServiceLoader;

import org.eclipse.microprofile.health.HealthCheck;

public interface HealthChecksRegistry {
Collection<HealthCheck> getChecks();

static HealthChecksRegistry load() {
final Iterator<HealthChecksRegistry> iterator = ServiceLoader.load(HealthChecksRegistry.class).iterator();
if (iterator.hasNext()) {
return iterator.next();
}
throw new IllegalStateException("No implementation of HealthChecksRegistry found");
}
}
@@ -0,0 +1,127 @@
<?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>
<artifactId>geronimo-health-parent</artifactId>
<groupId>org.apache.geronimo</groupId>
<version>1.0.1-SNAPSHOT</version>
</parent>

<artifactId>geronimo-health</artifactId>
<version>1.0.1-SNAPSHOT</version>
<name>Geronimo Health :: Microprofile</name>

<properties>
<geronimo-health.Automatic-Module-Name>org.apache.geronimo.microprofile.health</geronimo-health.Automatic-Module-Name>
</properties>

<dependencies>
<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>
<groupId>org.apache.geronimo</groupId>
<artifactId>geronimo-health-common</artifactId>
<version>${project.version}</version>
</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.3</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-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<dependenciesToScan>
<dependency>org.eclipse.microprofile.health:microprofile-health-tck</dependency>
</dependenciesToScan>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,36 @@
/**
* 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 javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.Path;

import org.apache.geronimo.microprofile.common.jaxrs.HealthChecksEndpoint;

@Path("health")
@ApplicationScoped
public class CdiHealthChecksEndpoint extends HealthChecksEndpoint {
@Inject
private GeronimoHealthExtension extension;

@PostConstruct
private void init() {
setRegistry(extension);
}
}
@@ -33,10 +33,11 @@
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.ProcessBean;

import org.apache.geronimo.microprofile.common.registry.HealthChecksRegistry;
import org.eclipse.microprofile.health.Health;
import org.eclipse.microprofile.health.HealthCheck;

public class GeronimoHealthExtension implements Extension {
public class GeronimoHealthExtension implements Extension, HealthChecksRegistry {
private final Collection<Bean<?>> beans = new ArrayList<>();
private final Collection<CreationalContext<?>> contexts = new ArrayList<>();
private List<HealthCheck> checks;
@@ -70,6 +71,7 @@ void stop(@Observes final BeforeShutdown beforeShutdown) {
}
}

@Override
public List<HealthCheck> getChecks() {
return checks;
}
File renamed without changes.
@@ -0,0 +1 @@
org.apache.geronimo.microprofile.common.impl.HealthCheckResponseProviderImpl
File renamed without changes.

0 comments on commit 6601d8e

Please sign in to comment.