Search in sources :

Example 1 with ComputeInstanceMetadataResolver

use of io.micronaut.discovery.cloud.ComputeInstanceMetadataResolver in project micronaut-core by micronaut-projects.

the class NettyEmbeddedServerInstance method getMetadata.

@Override
public ConvertibleValues<String> getMetadata() {
    if (instanceMetadata == null) {
        Map<String, String> cloudMetadata = new HashMap<>();
        ComputeInstanceMetadata computeInstanceMetadata = beanLocator.findBean(ComputeInstanceMetadataResolver.class).flatMap(computeInstanceMetadataResolver -> computeInstanceMetadataResolver.resolve(environment)).orElse(null);
        if (computeInstanceMetadata != null) {
            cloudMetadata = computeInstanceMetadata.getMetadata();
        }
        if (CollectionUtils.isNotEmpty(metadataContributors)) {
            for (ServiceInstanceMetadataContributor metadataContributor : metadataContributors) {
                metadataContributor.contribute(this, cloudMetadata);
            }
        }
        Map<String, String> metadata = nettyHttpServer.getServerConfiguration().getApplicationConfiguration().getInstance().getMetadata();
        if (cloudMetadata != null) {
            cloudMetadata.putAll(metadata);
        }
        instanceMetadata = ConvertibleValues.of(cloudMetadata);
    }
    return instanceMetadata;
}
Also used : Environment(io.micronaut.context.env.Environment) ConvertibleValues(io.micronaut.core.convert.value.ConvertibleValues) Parameter(io.micronaut.context.annotation.Parameter) HashMap(java.util.HashMap) Internal(io.micronaut.core.annotation.Internal) ComputeInstanceMetadataResolver(io.micronaut.discovery.cloud.ComputeInstanceMetadataResolver) ComputeInstanceMetadata(io.micronaut.discovery.cloud.ComputeInstanceMetadata) List(java.util.List) CollectionUtils(io.micronaut.core.util.CollectionUtils) EmbeddedServer(io.micronaut.runtime.server.EmbeddedServer) Map(java.util.Map) Prototype(io.micronaut.context.annotation.Prototype) URI(java.net.URI) BeanLocator(io.micronaut.context.BeanLocator) ServiceInstanceMetadataContributor(io.micronaut.discovery.metadata.ServiceInstanceMetadataContributor) EmbeddedServerInstance(io.micronaut.discovery.EmbeddedServerInstance) HashMap(java.util.HashMap) ServiceInstanceMetadataContributor(io.micronaut.discovery.metadata.ServiceInstanceMetadataContributor) ComputeInstanceMetadata(io.micronaut.discovery.cloud.ComputeInstanceMetadata)

Aggregations

BeanLocator (io.micronaut.context.BeanLocator)1 Parameter (io.micronaut.context.annotation.Parameter)1 Prototype (io.micronaut.context.annotation.Prototype)1 Environment (io.micronaut.context.env.Environment)1 Internal (io.micronaut.core.annotation.Internal)1 ConvertibleValues (io.micronaut.core.convert.value.ConvertibleValues)1 CollectionUtils (io.micronaut.core.util.CollectionUtils)1 EmbeddedServerInstance (io.micronaut.discovery.EmbeddedServerInstance)1 ComputeInstanceMetadata (io.micronaut.discovery.cloud.ComputeInstanceMetadata)1 ComputeInstanceMetadataResolver (io.micronaut.discovery.cloud.ComputeInstanceMetadataResolver)1 ServiceInstanceMetadataContributor (io.micronaut.discovery.metadata.ServiceInstanceMetadataContributor)1 EmbeddedServer (io.micronaut.runtime.server.EmbeddedServer)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1