forked from helidon-io/helidon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Imds data retriever as a service provider (helidon-io#8928)
* Add Imds data retriever as a service provider * Refactor ImdsInstanceInfoProvider to reuse HelidoOci methods and update relevant readmes * Remove system.out.println * Remove maven compiler plugin that was erroneously added. * Update service provider readme to correct a wrong supplier example
- Loading branch information
Showing
10 changed files
with
494 additions
and
27 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
101 changes: 101 additions & 0 deletions
101
...grations/oci/oci/src/main/java/io/helidon/integrations/oci/ImdsInstanceInfoBlueprint.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,101 @@ | ||
/* | ||
* Copyright (c) 2024 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; | ||
|
||
import io.helidon.builder.api.Option; | ||
import io.helidon.builder.api.Prototype; | ||
|
||
import jakarta.json.JsonObject; | ||
|
||
/** | ||
* Information about the instance retrieved from Imds. | ||
*/ | ||
@Prototype.Blueprint | ||
@Prototype.Configured | ||
interface ImdsInstanceInfoBlueprint { | ||
/** | ||
* Display Name. | ||
* | ||
* @return Display Name of the Instance | ||
*/ | ||
@Option.Configured | ||
String displayName(); | ||
|
||
/** | ||
* Host Name. | ||
* | ||
* @return Host Name of the Instance | ||
*/ | ||
@Option.Configured | ||
String hostName(); | ||
|
||
/** | ||
* Canonical Region Name. | ||
* | ||
* @return Canonical Region Name of where the Instance exists | ||
*/ | ||
@Option.Configured | ||
String canonicalRegionName(); | ||
|
||
/** | ||
* Region Name. | ||
* | ||
* @return Short Region Name of where the Instance exists | ||
*/ | ||
@Option.Configured | ||
String region(); | ||
|
||
/** | ||
* Oci Availability Domain Name. | ||
* | ||
* @return Physical Availaibility Domain Name where the Instance exists | ||
*/ | ||
@Option.Configured | ||
String ociAdName(); | ||
|
||
/** | ||
* Fault Domain Name. | ||
* | ||
* @return Fault Domain Name where the Instance exists | ||
*/ | ||
@Option.Configured | ||
String faultDomain(); | ||
|
||
/** | ||
* Compartment Id. | ||
* | ||
* @return Compartment Id where the Instance was provisioned. | ||
*/ | ||
@Option.Configured | ||
String compartmentId(); | ||
|
||
/** | ||
* Tenant Id. | ||
* | ||
* @return Tenant Id where the Instance was provisioned. | ||
*/ | ||
@Option.Configured | ||
String tenantId(); | ||
|
||
/** | ||
* Instance Data. | ||
* | ||
* @return Full information about the Instance as a {@link jakarta.json.JsonObject} | ||
*/ | ||
@Option.Configured | ||
JsonObject jsonObject(); | ||
} |
72 changes: 72 additions & 0 deletions
72
integrations/oci/oci/src/main/java/io/helidon/integrations/oci/ImdsInstanceInfoProvider.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,72 @@ | ||
/* | ||
* Copyright (c) 2024 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; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
|
||
import io.helidon.common.LazyValue; | ||
import io.helidon.common.Weight; | ||
import io.helidon.common.Weighted; | ||
import io.helidon.service.registry.Service; | ||
|
||
import jakarta.json.JsonObject; | ||
|
||
// the type must be fully qualified, as it is code generated | ||
@Service.Provider | ||
@Weight(Weighted.DEFAULT_WEIGHT - 100) | ||
class ImdsInstanceInfoProvider implements Supplier<Optional<io.helidon.integrations.oci.ImdsInstanceInfo>> { | ||
|
||
// Commonly used key names for instance data that will be used for the getter methods | ||
static final String DISPLAY_NAME = "displayName"; | ||
static final String HOST_NAME = "hostname"; | ||
static final String CANONICAL_REGION_NAME = "canonicalRegionName"; | ||
static final String OCI_AD_NAME = "ociAdName"; | ||
static final String FAULT_DOMAIN = "faultDomain"; | ||
static final String REGION = "region"; | ||
static final String COMPARTMENT_ID = "compartmentId"; | ||
static final String TENANT_ID = "tenantId"; | ||
|
||
private LazyValue<Optional<ImdsInstanceInfo>> instanceInfo; | ||
|
||
ImdsInstanceInfoProvider(Supplier<OciConfig> config) { | ||
this.instanceInfo = LazyValue.create(() -> Optional.ofNullable(loadInstanceMetadata(config.get()))); | ||
} | ||
|
||
@Override | ||
public Optional<ImdsInstanceInfo> get() { | ||
return instanceInfo.get(); | ||
} | ||
|
||
ImdsInstanceInfo loadInstanceMetadata(OciConfig ociConfig) { | ||
JsonObject metadataJson = HelidonOci.imdsContent(ociConfig, HelidonOci.imdsUri(ociConfig)); | ||
if (metadataJson != null) { | ||
return ImdsInstanceInfo.builder() | ||
.displayName(metadataJson.getString(DISPLAY_NAME)) | ||
.hostName(metadataJson.getString(HOST_NAME)) | ||
.canonicalRegionName(metadataJson.getString(CANONICAL_REGION_NAME)) | ||
.region(metadataJson.getString(REGION)) | ||
.ociAdName(metadataJson.getString(OCI_AD_NAME)) | ||
.faultDomain(metadataJson.getString(FAULT_DOMAIN)) | ||
.compartmentId(metadataJson.getString(COMPARTMENT_ID)) | ||
.tenantId(metadataJson.getString(TENANT_ID)) | ||
.jsonObject(metadataJson) | ||
.build(); | ||
} | ||
return null; | ||
} | ||
} |
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
Oops, something went wrong.