use of io.micronaut.discovery.cloud.ComputeInstanceMetadata 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;
}
use of io.micronaut.discovery.cloud.ComputeInstanceMetadata in project micronaut-grpc by micronaut-projects.
the class GrpcEmbeddedServer method start.
@Override
public EmbeddedServer start() {
if (running.compareAndSet(false, true)) {
try {
server.start();
eventPublisher.publishEvent(new ServerStartupEvent(this));
getApplicationConfiguration().getName().ifPresent(id -> {
Map<String, String> metadata = new LinkedHashMap<>();
if (computeInstanceMetadataResolver != null) {
final Optional<ComputeInstanceMetadata> cim = computeInstanceMetadataResolver.resolve(applicationContext.getEnvironment());
cim.ifPresent(computeInstanceMetadata -> metadata.putAll(computeInstanceMetadata.getMetadata()));
}
this.serviceInstance = new GrpcServerInstance(this, id, getURI(), metadata, metadataContributors, grpcConfiguration);
applicationContext.publishEvent(new ServiceReadyEvent(serviceInstance));
});
} catch (IOException e) {
throw new ApplicationStartupException("Unable to start GRPC server: " + e.getMessage(), e);
}
}
return this;
}
Aggregations