-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2130 from AxonFramework/feature/1964
[#1964] Include `AxonServerHealthIndicator`
- Loading branch information
Showing
21 changed files
with
559 additions
and
81 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
39 changes: 39 additions & 0 deletions
39
...ver-connector/src/main/java/org/axonframework/axonserver/connector/ConnectionManager.java
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,39 @@ | ||
/* | ||
* Copyright (c) 2010-2022. Axon Framework | ||
* | ||
* Licensed 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.axonframework.axonserver.connector; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Interface describing functionality for connection managers. A connection manager typically deals with a collection of | ||
* connections per context the application is wired with. | ||
* | ||
* @author Steven van Beelen | ||
* @author Milan Savic | ||
* @author Sara Pelligrini | ||
* @since 4.6.0 | ||
*/ | ||
public interface ConnectionManager { | ||
|
||
/** | ||
* Return the connections this instances manages. Consists of key-value pairs where the key resembles the context | ||
* name and the value describes whether the connection is active at this moment. | ||
* | ||
* @return Return the connections this instances manages. | ||
*/ | ||
Map<String, Boolean> connections(); | ||
} |
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
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
38 changes: 38 additions & 0 deletions
38
spring-boot-autoconfigure/src/main/java/org/axonframework/actuator/HealthStatus.java
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,38 @@ | ||
/* | ||
* Copyright (c) 2010-2022. Axon Framework | ||
* | ||
* Licensed 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.axonframework.actuator; | ||
|
||
import org.springframework.boot.actuate.health.Status; | ||
|
||
/** | ||
* Utility class holding additional {@link Status} instances. | ||
* | ||
* @author Steven van Beelen | ||
* @author Marc Gathier | ||
* @since 4.6.0 | ||
*/ | ||
public abstract class HealthStatus { | ||
|
||
/** | ||
* A {@link Status} suggesting the connection is still working but not at full capacity. | ||
*/ | ||
public static final Status WARN = new Status("WARN"); | ||
|
||
private HealthStatus() { | ||
// Utility class | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...figure/src/main/java/org/axonframework/actuator/axonserver/AxonServerHealthIndicator.java
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,78 @@ | ||
/* | ||
* Copyright (c) 2010-2022. Axon Framework | ||
* | ||
* Licensed 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.axonframework.actuator.axonserver; | ||
|
||
import org.axonframework.actuator.HealthStatus; | ||
import org.axonframework.axonserver.connector.AxonServerConnectionManager; | ||
import org.springframework.boot.actuate.health.AbstractHealthIndicator; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.boot.actuate.health.Status; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
/** | ||
* An {@link AbstractHealthIndicator} implementation exposing the health of the connections made through the {@link | ||
* AxonServerConnectionManager}. This status is exposed through the {@code "axonServer"} component. | ||
* <p> | ||
* The status is regarded as {@link Status#UP} if <b>all</b> {@link AxonServerConnectionManager#connections()} are up. | ||
* If one of them is down, the status is {@link HealthStatus#WARN}. If all of them are down the status will be {@link | ||
* Status#DOWN}. This {@link org.springframework.boot.actuate.health.HealthIndicator} also shares connection details per | ||
* context under {@code "{context-name}.connection.active"}. | ||
* | ||
* @author Steven van Beelen | ||
* @since 4.6.0 | ||
*/ | ||
public class AxonServerHealthIndicator extends AbstractHealthIndicator { | ||
|
||
private static final String CONNECTION = "%s.connection.active"; | ||
|
||
private final AxonServerConnectionManager connectionManager; | ||
|
||
/** | ||
* Constructs this health indicator, extracting health information from the given {@code connectionManager}. | ||
* | ||
* @param connectionManager The Axon Server connection manager to extract health information from. | ||
*/ | ||
public AxonServerHealthIndicator(AxonServerConnectionManager connectionManager) { | ||
this.connectionManager = connectionManager; | ||
} | ||
|
||
@Override | ||
protected void doHealthCheck(Health.Builder builder) { | ||
builder.up(); | ||
|
||
AtomicBoolean anyConnectionUp = new AtomicBoolean(false); | ||
Map<String, Boolean> connections = connectionManager.connections(); | ||
|
||
connections.forEach((context, connectionStatus) -> { | ||
String contextStatusCode; | ||
if (Boolean.FALSE.equals(connectionStatus)) { | ||
contextStatusCode = Status.DOWN.getCode(); | ||
builder.status(HealthStatus.WARN); | ||
} else { | ||
contextStatusCode = Status.UP.getCode(); | ||
anyConnectionUp.compareAndSet(false, true); | ||
} | ||
builder.withDetail(String.format(CONNECTION, context), contextStatusCode); | ||
}); | ||
|
||
if (!connections.isEmpty() && !anyConnectionUp.get()) { | ||
builder.down(); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...igure/src/main/java/org/axonframework/actuator/axonserver/AxonServerStatusAggregator.java
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,40 @@ | ||
/* | ||
* Copyright (c) 2010-2022. Axon Framework | ||
* | ||
* Licensed 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.axonframework.actuator.axonserver; | ||
|
||
import org.axonframework.actuator.HealthStatus; | ||
import org.springframework.boot.actuate.health.SimpleStatusAggregator; | ||
import org.springframework.boot.actuate.health.Status; | ||
|
||
/** | ||
* A {@link SimpleStatusAggregator} implementation determining the overall health of an Axon Framework application using | ||
* Axon Server. Adds the {@link HealthStatus#WARN} status to the regular set of {@link Status statuses}. | ||
* | ||
* @author Steven van Beelen | ||
* @author Marc Gathier | ||
* @since 4.6.0 | ||
*/ | ||
public class AxonServerStatusAggregator extends SimpleStatusAggregator { | ||
|
||
/** | ||
* Constructs a default Axon Server specific {@link SimpleStatusAggregator}. Adds the {@link HealthStatus#WARN} | ||
* after {@link Status#OUT_OF_SERVICE} and before {@link Status#UP}. | ||
*/ | ||
public AxonServerStatusAggregator() { | ||
super(Status.DOWN, Status.OUT_OF_SERVICE, HealthStatus.WARN, Status.UP, Status.UNKNOWN); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ain/java/org/axonframework/springboot/autoconfig/AxonServerActuatorAutoConfiguration.java
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,50 @@ | ||
/* | ||
* Copyright (c) 2010-2022. Axon Framework | ||
* | ||
* Licensed 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.axonframework.springboot.autoconfig; | ||
|
||
import org.axonframework.actuator.axonserver.AxonServerHealthIndicator; | ||
import org.axonframework.actuator.axonserver.AxonServerStatusAggregator; | ||
import org.axonframework.axonserver.connector.AxonServerConnectionManager; | ||
import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* Autoconfiguration class for Spring Boot Actuator monitoring tools around Axon Server. | ||
* | ||
* @author Steven van Beelen | ||
* @since 4.6.0 | ||
*/ | ||
@Configuration | ||
@AutoConfigureAfter(AxonServerAutoConfiguration.class) | ||
@ConditionalOnClass(name = {"org.springframework.boot.actuate.health.AbstractHealthIndicator"}) | ||
@ConditionalOnProperty(name = "axon.axonserver.enabled", matchIfMissing = true) | ||
public class AxonServerActuatorAutoConfiguration { | ||
|
||
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") | ||
@Bean | ||
public AxonServerHealthIndicator axonServerHealthIndicator(AxonServerConnectionManager connectionManager) { | ||
return new AxonServerHealthIndicator(connectionManager); | ||
} | ||
|
||
@Bean | ||
public AxonServerStatusAggregator axonServerStatusAggregator() { | ||
return new AxonServerStatusAggregator(); | ||
} | ||
} |
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
Oops, something went wrong.