-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial version of health check for single OCI vault. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Some improvement to vault healthcheck. Updated CDI sample to use it. * Updated reactive vault example. Some other changes to support the reactive case. * Updated pom project name. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Fixed checkstyle. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
- Loading branch information
Showing
12 changed files
with
362 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
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
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
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
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,84 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2021 Oracle and/or its affiliates. | ||
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. | ||
--> | ||
|
||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.helidon.integrations.oci</groupId> | ||
<artifactId>helidon-integrations-oci-project</artifactId> | ||
<version>2.4.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>helidon-integrations-oci-vault-health</artifactId> | ||
<name>Helidon Integrations OCI Vault Health Check</name> | ||
|
||
<description>OCI Vault Health Support</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.helidon.integrations.oci</groupId> | ||
<artifactId>helidon-integrations-oci-vault</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.common</groupId> | ||
<artifactId>helidon-common</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.config</groupId> | ||
<artifactId>helidon-config</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.health</groupId> | ||
<artifactId>helidon-health</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.health</groupId> | ||
<artifactId>helidon-health-common</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.config</groupId> | ||
<artifactId>helidon-config-yaml</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<!-- only needed for compilation, not required in runtime --> | ||
<groupId>jakarta.enterprise</groupId> | ||
<artifactId>jakarta.enterprise.cdi-api</artifactId> | ||
<scope>provided</scope> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<!-- only needed for compilation, not required in runtime --> | ||
<groupId>org.eclipse.microprofile.config</groupId> | ||
<artifactId>microprofile-config-api</artifactId> | ||
<scope>provided</scope> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-all</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
165 changes: 165 additions & 0 deletions
165
...lt-health/src/main/java/io/helidon/integrations/oci/vault/health/OciVaultHealthCheck.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,165 @@ | ||
/* | ||
* Copyright (c) 2021 Oracle and/or its affiliates. | ||
* | ||
* 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 io.helidon.integrations.oci.vault.health; | ||
|
||
import java.util.Objects; | ||
import java.util.logging.Logger; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
import io.helidon.config.Config; | ||
import io.helidon.health.common.BuiltInHealthCheck; | ||
import io.helidon.integrations.common.rest.ApiOptionalResponse; | ||
import io.helidon.integrations.oci.vault.GetVault; | ||
import io.helidon.integrations.oci.vault.OciVault; | ||
import io.helidon.integrations.oci.vault.OciVaultRx; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.eclipse.microprofile.health.HealthCheck; | ||
import org.eclipse.microprofile.health.HealthCheckResponse; | ||
import org.eclipse.microprofile.health.HealthCheckResponseBuilder; | ||
import org.eclipse.microprofile.health.Liveness; | ||
|
||
import static io.helidon.common.http.Http.Status.OK_200; | ||
|
||
/** | ||
* Liveness check for an OCI's Vault. Reads OCI properties from '~/.oci/config'. | ||
*/ | ||
@Liveness | ||
@ApplicationScoped // this will be ignored if not within CDI | ||
@BuiltInHealthCheck | ||
public final class OciVaultHealthCheck implements HealthCheck { | ||
private static final Logger LOGGER = Logger.getLogger(OciVaultHealthCheck.class.getName()); | ||
|
||
private final String vaultId; | ||
private final OciVault ociVault; | ||
|
||
@Inject | ||
OciVaultHealthCheck(@ConfigProperty(name = "oci.vault.vault-ocid") String vaultId, | ||
OciVault ociVault) { | ||
this.vaultId = vaultId; | ||
this.ociVault = ociVault; | ||
} | ||
|
||
private OciVaultHealthCheck(Builder builder) { | ||
this.vaultId = builder.vaultId; | ||
this.ociVault = builder.vault; | ||
} | ||
|
||
/** | ||
* Create a new fluent API builder to configure a new health check. | ||
* | ||
* @return builder instance | ||
*/ | ||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
/** | ||
* Create an instance. | ||
* | ||
* @param config the config. | ||
* @return an instance. | ||
*/ | ||
public static OciVaultHealthCheck create(Config config) { | ||
return builder().config(config).build(); | ||
} | ||
|
||
/** | ||
* Checks that the OCI vault is accessible, if defined. Will report error only if not | ||
* defined or not accessible. Can block since all health checks are called asynchronously. | ||
* | ||
* @return a response | ||
*/ | ||
@Override | ||
public HealthCheckResponse call() { | ||
HealthCheckResponseBuilder builder = HealthCheckResponse.named("vault"); | ||
builder.withData("vaultId", vaultId); | ||
try { | ||
ApiOptionalResponse<GetVault.Response> r = ociVault.getVault(GetVault.Request.builder().vaultId(vaultId)); | ||
builder.state(r.status().equals(OK_200)); | ||
r.entity().ifPresent(e -> { | ||
builder.withData("compartmentId", e.compartmentId()); | ||
builder.withData("displayName", e.displayName()); | ||
}); | ||
LOGGER.fine(() -> "OCI vault health check " + vaultId + " returned status code " + r.status().code()); | ||
} catch (Throwable t) { | ||
builder.down() | ||
.withData("Error", t.getClass().getName()) | ||
.withData("Message", t.getMessage()); | ||
LOGGER.fine(() -> "OCI vault health check " + vaultId + " exception " + t.getMessage()); | ||
} | ||
return builder.build(); | ||
} | ||
|
||
/** | ||
* Fluent API builder for {@link OciVaultHealthCheck}. | ||
*/ | ||
public static final class Builder implements io.helidon.common.Builder<OciVaultHealthCheck> { | ||
|
||
private String vaultId; | ||
private OciVaultRx vaultRx; | ||
private OciVault vault; | ||
|
||
private Builder() { | ||
} | ||
|
||
@Override | ||
public OciVaultHealthCheck build() { | ||
Objects.requireNonNull(vaultId); | ||
if (vaultRx == null) { | ||
vaultRx = OciVaultRx.create(); | ||
} | ||
this.vault = OciVault.create(vaultRx); | ||
return new OciVaultHealthCheck(this); | ||
} | ||
|
||
/** | ||
* Set up this builder using config. | ||
* | ||
* @param config the config. | ||
* @return the builder. | ||
*/ | ||
public Builder config(Config config) { | ||
config.get("oci.vault.vault-ocid").asString().ifPresent(this::vaultId); | ||
return this; | ||
} | ||
|
||
/** | ||
* Set the vault's OCID. | ||
* | ||
* @param vaultId vault ID. | ||
* @return the builder. | ||
*/ | ||
public Builder vaultId(String vaultId) { | ||
this.vaultId = vaultId; | ||
return this; | ||
} | ||
|
||
/** | ||
* Set the vault client. | ||
* | ||
* @param vaultRx vault client. | ||
* @return the builder. | ||
*/ | ||
public Builder ociVault(OciVaultRx vaultRx) { | ||
this.vaultRx = vaultRx; | ||
return this; | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...oci/vault-health/src/main/java/io/helidon/integrations/oci/vault/health/package-info.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,20 @@ | ||
/* | ||
* Copyright (c) 2021 Oracle and/or its affiliates. | ||
* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* OCI Vault Health. | ||
*/ | ||
package io.helidon.integrations.oci.vault.health; |
37 changes: 37 additions & 0 deletions
37
integrations/oci/vault-health/src/main/java/module-info.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,37 @@ | ||
/* | ||
* Copyright (c) 2021 Oracle and/or its affiliates. | ||
* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* OCI Vault Health. | ||
*/ | ||
module io.helidon.integrations.oci.vault.health { | ||
requires java.logging; | ||
requires io.helidon.integrations.oci.connect; | ||
requires io.helidon.common; | ||
|
||
requires transitive io.helidon.health; | ||
requires transitive io.helidon.health.common; | ||
requires transitive io.helidon.config; | ||
requires transitive io.helidon.integrations.oci.vault; | ||
|
||
requires static microprofile.config.api; | ||
requires static jakarta.enterprise.cdi.api; | ||
requires static jakarta.inject.api; | ||
|
||
exports io.helidon.integrations.oci.vault.health; | ||
|
||
opens io.helidon.integrations.oci.vault.health to weld.core.impl, io.helidon.microprofile.cdi; | ||
} |
Oops, something went wrong.