You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Karyon server metadata are useful by different components of karyon 3.x. For example karyon3-eureka needs metadata for registration, and karyon3-admin can expose similar metadata for admin purposes.
It would be nice if karyon 3.x exposed a common way to define and store these metadata, and also be able to translate the metadata to other formats for different components to consume.
Some example code below:
/** * Marker interface for specific context implementations. This interface explicitly * sets no restrictions on what actual implementations should contain. * Any implementers of an actual context should also need to implement * {@link KaryonContextConverter}s to the necessary components. */publicinterfaceKaryonContext {
}
/** * A converter definition to translate karyon contexts to other formats for component use */publicabstractclassKaryonContextConverter<CextendsKaryonContext, T> {
protectedfinalCcontext;
protectedKaryonContextConverter(Ccontext) {
this.context = context;
}
/** * @return the context mapped to and instance of type T */publicabstractTconvert();
}
importcom.netflix.archaius.annotations.Configuration;
importcom.netflix.archaius.annotations.DefaultValue;
importcom.netflix.karyon.context.KaryonContext;
/** * An implementation of karyon context based on archaius2 property loading */@Configuration(prefix="karyon.context")
publicinterfaceArchaiusKaryonContextextendsKaryonContext {
StringgetAppName();
@DefaultValue("localhost")
StringgetHostname();
@DefaultValue("8080")
intgetPort();
}
importcom.netflix.appinfo.InstanceInfo;
importcom.netflix.karyon.archaius.context.ArchaiusKaryonContext;
importcom.netflix.karyon.context.KaryonContextConverter;
/** * An example converter for karyon3-eureka to convert karyon context to an instanceInfo builder */publicclassArchaiusKaryonContextConverterextendsKaryonContextConverter<ArchaiusKaryonContext, InstanceInfo.Builder> {
protectedArchaiusKaryonContextConverter(ArchaiusKaryonContextcontext) {
super(context);
}
@OverridepublicInstanceInfo.Builderconvert() {
returnInstanceInfo.Builder.newBuilder()
.setAppName(context.getAppName())
.setHostName(context.getHostname())
.setPort(context.getPort());
}
}
importcom.netflix.appinfo.EurekaInstanceConfig;
importcom.netflix.appinfo.InstanceInfo;
importcom.netflix.appinfo.LeaseInfo;
importcom.netflix.karyon.eureka.context.ArchaiusKaryonContextConverter;
importorg.slf4j.Logger;
importorg.slf4j.LoggerFactory;
importjavax.inject.Inject;
importjavax.inject.Provider;
importjava.util.Map;
/** * An example eureka InstanceInfo provider that merges data from karyon context as well as eurekaInstanceConfig * to resolve the final server InstanceInfo for registration. * * @author David Liu */publicclassKaryonInstanceInfoProviderimplementsProvider<InstanceInfo> {
privatestaticfinalLoggerlogger = LoggerFactory.getLogger(KaryonInstanceInfoProvider.class);
privatefinalArchaiusKaryonContextConvertercontext;
privatefinalEurekaInstanceConfigeurekaInstanceConfig;
privateInstanceInfoinstanceInfo;
@InjectpublicKaryonInstanceInfoProvider(ArchaiusKaryonContextConvertercontext, EurekaInstanceConfigeurekaInstanceConfig) {
this.context = context;
this.eurekaInstanceConfig = eurekaInstanceConfig;
}
@OverridepublicsynchronizedInstanceInfoget() {
if (instanceInfo == null) {
// Build the lease information to be passed to the server based// on configLeaseInfo.BuilderleaseInfoBuilder = LeaseInfo.Builder
.newBuilder()
.setRenewalIntervalInSecs(eurekaInstanceConfig.getLeaseRenewalIntervalInSeconds())
.setDurationInSecs(eurekaInstanceConfig.getLeaseExpirationDurationInSeconds());
InstanceInfo.Builderbuilder = context.convert()
.setNamespace(eurekaInstanceConfig.getNamespace())
.setAppGroupName(eurekaInstanceConfig.getAppGroupName())
.setDataCenterInfo(eurekaInstanceConfig.getDataCenterInfo())
.setIPAddr(eurekaInstanceConfig.getIpAddress())
.enablePort(InstanceInfo.PortType.UNSECURE, eurekaInstanceConfig.isNonSecurePortEnabled())
.setSecurePort(eurekaInstanceConfig.getSecurePort())
.enablePort(InstanceInfo.PortType.SECURE, eurekaInstanceConfig.getSecurePortEnabled())
.setVIPAddress(eurekaInstanceConfig.getVirtualHostName())
.setSecureVIPAddress(eurekaInstanceConfig.getSecureVirtualHostName())
.setHomePageUrl(eurekaInstanceConfig.getHomePageUrlPath(), eurekaInstanceConfig.getHomePageUrl())
.setStatusPageUrl(eurekaInstanceConfig.getStatusPageUrlPath(), eurekaInstanceConfig.getStatusPageUrl())
.setHealthCheckUrls(eurekaInstanceConfig.getHealthCheckUrlPath(), eurekaInstanceConfig.getHealthCheckUrl(), eurekaInstanceConfig.getSecureHealthCheckUrl())
.setASGName(eurekaInstanceConfig.getASGName());
// Start off with the STARTING state to avoid trafficif (!eurekaInstanceConfig.isInstanceEnabledOnit()) {
InstanceInfo.InstanceStatusinitialStatus = InstanceInfo.InstanceStatus.STARTING;
logger.info("Setting initial instance status as: " + initialStatus);
builder.setStatus(initialStatus);
} else {
logger.info("Setting initial instance status as: {}. This may be too early for the instance to advertise itself as available. "
+ "You would instead want to control this via a healthcheck handler.", InstanceInfo.InstanceStatus.UP);
}
// Add any user-specific metadata informationfor (Map.Entry<String, String> mapEntry : eurekaInstanceConfig.getMetadataMap().entrySet()) {
Stringkey = mapEntry.getKey();
Stringvalue = mapEntry.getValue();
builder.add(key, value);
}
instanceInfo = builder.build();
instanceInfo.setLeaseInfo(leaseInfoBuilder.build());
}
returninstanceInfo;
}
}
The text was updated successfully, but these errors were encountered:
Karyon server metadata are useful by different components of karyon 3.x. For example karyon3-eureka needs metadata for registration, and karyon3-admin can expose similar metadata for admin purposes.
It would be nice if karyon 3.x exposed a common way to define and store these metadata, and also be able to translate the metadata to other formats for different components to consume.
Some example code below:
The text was updated successfully, but these errors were encountered: