Java Code Examples for com.netflix.appinfo.InstanceInfo#getMetadata()
The following examples show how to use
com.netflix.appinfo.InstanceInfo#getMetadata() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EurekaDubboRegistry.java From spring-cloud-dubbo with Apache License 2.0 | 6 votes |
private void addOrDeleteMetadata(URL url, String category, boolean isAdd) { InstanceInfo instanceInfo = eurekaClient.getApplicationInfoManager().getInfo(); Map<String, String> metadata = instanceInfo.getMetadata(); String metadataCategory = metadata.get(category); try { TreeSet<String> values = StringUtils.isEmpty(metadataCategory) ? new TreeSet<>() : objectMapper.readValue(metadataCategory, stringListTypeReference); if (isAdd) { values.add(url.toString()); } else { values.remove(url.toString()); } metadata.put(category, objectMapper.writeValueAsString(values)); eurekaClient.getApplicationInfoManager().registerAppMetadata(metadata); } catch (IOException e) { e.printStackTrace(); } }
Example 2
Source File: EurekaInstanceRegisteredListener.java From api-layer with Eclipse Public License 2.0 | 6 votes |
/** * Translates service instance Eureka metadata from older versions to the current version */ @EventListener public void listen(EurekaInstanceRegisteredEvent event) { final InstanceInfo instanceInfo = event.getInstanceInfo(); final Map<String, String> metadata = instanceInfo.getMetadata(); final String serviceId = EurekaUtils.getServiceIdFromInstanceId(instanceInfo.getInstanceId()); metadataTranslationService.translateMetadata(serviceId, metadata); metadataDefaultsService.updateMetadata(serviceId, metadata); if (StringUtils.equalsIgnoreCase(GatewayNotifier.GATEWAY_SERVICE_ID, serviceId)) { /** * meanwhile gateway was down, another Gateway could receive logout, those invalidated credentials should * be distributed to this new Gateway */ gatewayNotifier.distributeInvalidatedCredentials(instanceInfo.getInstanceId()); } // ie. new instance can have different authentication (than other one), this is reason to evict caches on gateway gatewayNotifier.serviceUpdated(serviceId, instanceInfo.getInstanceId()); }
Example 3
Source File: CachedProductFamilyService.java From api-layer with Eclipse Public License 2.0 | 6 votes |
/** * Create a new container based on information in a new instance * * @param productFamilyId parent id * @param instanceInfo instance * @return a new container */ private APIContainer createNewContainerFromService(String productFamilyId, InstanceInfo instanceInfo) { Map<String, String> instanceInfoMetadata = instanceInfo.getMetadata(); String title = instanceInfoMetadata.get(CATALOG_TITLE); String description = instanceInfoMetadata.get(CATALOG_DESCRIPTION); String version = instanceInfoMetadata.get(CATALOG_VERSION); APIContainer container = new APIContainer(); container.setStatus("UP"); container.setId(productFamilyId); container.setDescription(description); container.setTitle(title); container.setVersion(version); log.debug("updated Container cache with product family: " + productFamilyId + ": " + title); // create API Service from instance and update container last changed date container.addService(createAPIServiceFromInstance(instanceInfo)); products.put(productFamilyId, container); return container; }
Example 4
Source File: ArmeriaEurekaClientTest.java From armeria with Apache License 2.0 | 6 votes |
private static com.linecorp.armeria.internal.common.eureka.InstanceInfo convertInstanceInfo( InstanceInfo info) { final PortWrapper port = new PortWrapper(info.isPortEnabled(PortType.UNSECURE), info.getPort()); final PortWrapper securePort = new PortWrapper(info.isPortEnabled(PortType.SECURE), info.getSecurePort()); return new com.linecorp.armeria.internal.common.eureka.InstanceInfo( info.getInstanceId(), info.getAppName(), info.getAppGroupName(), info.getHostName(), info.getIPAddr(), info.getVIPAddress(), info.getSecureVipAddress(), port, securePort, com.linecorp.armeria.internal.common.eureka.InstanceInfo.InstanceStatus .toEnum(info.getStatus().name()), info.getHomePageUrl(), info.getStatusPageUrl(), info.getHealthCheckUrl(), info.getSecureHealthCheckUrl(), convertDataCenterInfo(info.getDataCenterInfo()), convertLeaseInfo(info.getLeaseInfo()), info.getMetadata()); }
Example 5
Source File: EurekaSyncToNacosServiceImpl.java From nacos-sync with Apache License 2.0 | 5 votes |
private Instance buildSyncInstance(InstanceInfo instance, TaskDO taskDO) { Instance temp = new Instance(); temp.setIp(instance.getIPAddr()); temp.setPort(instance.getPort()); temp.setServiceName(instance.getAppName()); temp.setHealthy(true); Map<String, String> metaData = new HashMap<>(instance.getMetadata()); metaData.put(SkyWalkerConstants.DEST_CLUSTERID_KEY, taskDO.getDestClusterId()); metaData.put(SkyWalkerConstants.SYNC_SOURCE_KEY, skyWalkerCacheServices.getClusterType(taskDO.getSourceClusterId()).getCode()); metaData.put(SkyWalkerConstants.SOURCE_CLUSTERID_KEY, taskDO.getSourceClusterId()); temp.setMetadata(metaData); return temp; }
Example 6
Source File: ServiceAuthenticationServiceImpl.java From api-layer with Eclipse Public License 2.0 | 5 votes |
public Authentication getAuthentication(InstanceInfo instanceInfo) { final Map<String, String> metadata = instanceInfo.getMetadata(); final Authentication out = new Authentication(); out.setApplid(metadata.get(AUTHENTICATION_APPLID)); out.setScheme(AuthenticationScheme.fromScheme(metadata.get(AUTHENTICATION_SCHEME))); return out; }
Example 7
Source File: CorsMetadataProcessor.java From api-layer with Eclipse Public License 2.0 | 5 votes |
protected void checkInstanceInfo(InstanceInfo instanceInfo) { Map<String, String> metadata = instanceInfo.getMetadata(); if (metadata != null && corsEnabled) { String serviceId = instanceInfo.getVIPAddress(); setCorsConfiguration(serviceId, metadata); } }
Example 8
Source File: RibbonMetadataProcessor.java From api-layer with Eclipse Public License 2.0 | 5 votes |
protected void checkInstanceInfo(InstanceInfo instanceInfo) { String serviceId = instanceInfo.getVIPAddress(); Map<String, String> metadata = instanceInfo.getMetadata(); if (metadata != null) { setIfExistsAndIsNumeric(serviceId + ".ribbon.ConnectTimeout", metadata.get("apiml.connectTimeout")); setIfExistsAndIsNumeric(serviceId + ".ribbon.ReadTimeout", metadata.get("apiml.readTimeout")); setIfExistsAndIsNumeric(serviceId + ".ribbon.ConnectionManagerTimeout", metadata.get("apiml.connectionManagerTimeout")); setIfExists(serviceId + ".ribbon.OkToRetryOnAllOperations", metadata.get("apiml.okToRetryOnAllOperations")); } }
Example 9
Source File: CloudJacksonJson.java From didi-eureka-server with MIT License | 5 votes |
static InstanceInfo updateIfNeeded(final InstanceInfo info) { if (info.getInstanceId() == null && info.getMetadata() != null) { String instanceId = info.getMetadata().get("instanceId"); if (StringUtils.hasText(instanceId)) { // backwards compatibility for Angel if (StringUtils.hasText(info.getHostName()) && !instanceId.startsWith(info.getHostName())) { instanceId = info.getHostName()+":"+instanceId; } return new InstanceInfo.Builder(info).setInstanceId(instanceId).build(); } } return info; }
Example 10
Source File: CloudJacksonJson.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
static InstanceInfo updateIfNeeded(final InstanceInfo info) { if (info.getInstanceId() == null && info.getMetadata() != null) { String instanceId = info.getMetadata().get("instanceId"); if (StringUtils.hasText(instanceId)) { // backwards compatibility for Angel if (StringUtils.hasText(info.getHostName()) && !instanceId.startsWith(info.getHostName())) { instanceId = info.getHostName() + ":" + instanceId; } return new InstanceInfo.Builder(info).setInstanceId(instanceId).build(); } } return info; }
Example 11
Source File: EurekaClientWrapper.java From summerframework with Apache License 2.0 | 4 votes |
private List<InstanceInfo> filterInstance(List<InstanceInfo> instanceList) { List<InstanceInfo> filteredInsantce = Lists.newArrayList(); List<InstanceInfo> toDeleteInstance = Lists.newArrayList(); for (InstanceInfo insaceInfo : instanceList) { final String serviceId = insaceInfo.getVIPAddress(); final String instanceIpAddr = insaceInfo.getIPAddr(); final Map<String, String> instanceMeta = insaceInfo.getMetadata(); String reference = environment.getProperty(Constants.CONSUMER_INSTANCE_REFERENCE); if (this.reference != null && reference != null) { if (!this.reference.equals(reference)) { this.initReferenceCache(); this.reference = reference; } } Pair<String, String> groupVersion = this.getGroupVersion(serviceId); if (groupVersion != null) { String group = instanceMeta.get(Constants.EUREKA_METADATA_GROUP); String version = instanceMeta.get(Constants.EUREKA_METADATA_VERSION); if (group != null && version != null) { boolean groupEqual = StringUtils.equals(groupVersion.getLeft(), group); boolean versionEqual = StringUtils.equals(groupVersion.getRight(), version); if (groupEqual && versionEqual) { filteredInsantce.add(insaceInfo); } } else { filteredInsantce.add(insaceInfo); } } else { filteredInsantce.add(insaceInfo); } String ipAddress = eurekaRuleCache.get(serviceId); if (StringUtils.isNotEmpty(ipAddress)) { List<String> ipAddressList = Arrays.asList(StringUtils.split(ipAddress, ",")); if (ipAddressList.contains(instanceIpAddr)) { toDeleteInstance.add(insaceInfo); } } } if (toDeleteInstance.size() != 0) { @SuppressWarnings("unchecked") Collection<InstanceInfo> remainList = CollectionUtils.removeAll(filteredInsantce, toDeleteInstance); return Lists.newArrayList(remainList); } else { return filteredInsantce; } }