com.netflix.appinfo.LeaseInfo Java Examples
The following examples show how to use
com.netflix.appinfo.LeaseInfo.
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: ServiceDefinitionProcessor.java From api-layer with Eclipse Public License 2.0 | 6 votes |
private void setInstanceAttributes(InstanceInfo.Builder builder, Service service, String instanceId, String instanceBaseUrl, URL url, String ipAddress, CatalogUiTile tile) throws ServiceDefinitionException { String serviceId = service.getServiceId(); builder.setAppName(serviceId).setInstanceId(instanceId).setHostName(url.getHost()).setIPAddr(ipAddress) .setDataCenterInfo(DEFAULT_INFO).setVIPAddress(serviceId).setSecureVIPAddress(serviceId) .setLeaseInfo(LeaseInfo.Builder.newBuilder() .setRenewalIntervalInSecs(LeaseInfo.DEFAULT_LEASE_RENEWAL_INTERVAL) .setDurationInSecs(LeaseInfo.DEFAULT_LEASE_DURATION).build()) .setMetadata(createMetadata(service, url, tile)); if (service.getHomePageRelativeUrl() != null) { builder.setHomePageUrl(null, instanceBaseUrl + service.getHomePageRelativeUrl()); } if (service.getStatusPageRelativeUrl() != null) { builder.setStatusPageUrl(null, instanceBaseUrl + service.getStatusPageRelativeUrl()); } }
Example #2
Source File: InstanceRegistryTest.java From didi-eureka-server with MIT License | 6 votes |
@Test public void testRegister() throws Exception { // creating instance info final LeaseInfo leaseInfo = getLeaseInfo(); final InstanceInfo instanceInfo = getInstanceInfo(APP_NAME, HOST_NAME, INSTANCE_ID, PORT, leaseInfo); // calling tested method instanceRegistry.register(instanceInfo, false); // event of proper type is registered assertEquals(1, this.testEvents.applicationEvents.size()); assertTrue(this.testEvents.applicationEvents.get(0) instanceof EurekaInstanceRegisteredEvent); // event details are correct final EurekaInstanceRegisteredEvent registeredEvent = (EurekaInstanceRegisteredEvent) (this.testEvents.applicationEvents.get(0)); assertEquals(instanceInfo, registeredEvent.getInstanceInfo()); assertEquals(leaseInfo.getDurationInSecs(), registeredEvent.getLeaseDuration()); assertEquals(instanceRegistry, registeredEvent.getSource()); assertFalse(registeredEvent.isReplication()); }
Example #3
Source File: InstanceRegistryTests.java From spring-cloud-netflix with Apache License 2.0 | 6 votes |
@Test public void testRegister() throws Exception { // creating instance info final LeaseInfo leaseInfo = getLeaseInfo(); final InstanceInfo instanceInfo = getInstanceInfo(APP_NAME, HOST_NAME, INSTANCE_ID, PORT, leaseInfo); // calling tested method instanceRegistry.register(instanceInfo, false); // event of proper type is registered assertThat(this.testEvents.applicationEvents.size()).isEqualTo(1); assertThat(this.testEvents.applicationEvents .get(0) instanceof EurekaInstanceRegisteredEvent).isTrue(); // event details are correct final EurekaInstanceRegisteredEvent registeredEvent = (EurekaInstanceRegisteredEvent) (this.testEvents.applicationEvents .get(0)); assertThat(registeredEvent.getInstanceInfo()).isEqualTo(instanceInfo); assertThat(registeredEvent.getLeaseDuration()) .isEqualTo(leaseInfo.getDurationInSecs()); assertThat(registeredEvent.getSource()).isEqualTo(instanceRegistry); assertThat(registeredEvent.isReplication()).isFalse(); }
Example #4
Source File: NacosSyncToEurekaServiceImpl.java From nacos-sync with Apache License 2.0 | 5 votes |
private InstanceInfo buildSyncInstance(Instance instance, TaskDO taskDO) { DataCenterInfo dataCenterInfo = new MyDataCenterInfo(DataCenterInfo.Name.MyOwn); HashMap<String, String> metadata = new HashMap<>(16); 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()); String homePageUrl = "http://" + instance.getIp() + ":" + instance.getPort(); String serviceName = taskDO.getServiceName(); return new InstanceInfo( instance.getIp() + ":" + serviceName + ":" + instance.getPort(), serviceName, null, instance.getIp(), null, new InstanceInfo.PortWrapper(true, instance.getPort()), null, homePageUrl, homePageUrl + "/info", homePageUrl + "/health", null, serviceName, serviceName, 1, dataCenterInfo, instance.getIp(), InstanceInfo.InstanceStatus.UP, InstanceInfo.InstanceStatus.UNKNOWN, null, new LeaseInfo(30, 90, 0L, 0L, 0L, 0L, 0L), false, metadata, System.currentTimeMillis(), System.currentTimeMillis(), null, null ); }
Example #5
Source File: StaticServicesRegistrationService.java From api-layer with Eclipse Public License 2.0 | 5 votes |
private void startRenewalTimer() { renewalTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { renewInstances(); } }, LeaseInfo.DEFAULT_LEASE_RENEWAL_INTERVAL * 1000L, LeaseInfo.DEFAULT_LEASE_RENEWAL_INTERVAL * 1000L); }
Example #6
Source File: InstanceRegistryTest.java From didi-eureka-server with MIT License | 5 votes |
@Test public void testDefaultLeaseDurationRegisterEvent() throws Exception { // creating instance info final InstanceInfo instanceInfo = getInstanceInfo(APP_NAME, HOST_NAME, INSTANCE_ID, PORT, null); // calling tested method instanceRegistry.register(instanceInfo, false); // instance info duration is set to default final EurekaInstanceRegisteredEvent registeredEvent = (EurekaInstanceRegisteredEvent) (this.testEvents.applicationEvents.get(0)); assertEquals(LeaseInfo.DEFAULT_LEASE_DURATION, registeredEvent.getLeaseDuration()); }
Example #7
Source File: InstanceRegistryTest.java From didi-eureka-server with MIT License | 5 votes |
private InstanceInfo getInstanceInfo(String appName, String hostName, String instanceId, int port, LeaseInfo leaseInfo) { InstanceInfo.Builder builder = InstanceInfo.Builder.newBuilder(); builder.setAppName(appName); builder.setHostName(hostName); builder.setInstanceId(instanceId); builder.setPort(port); builder.setLeaseInfo(leaseInfo); return builder.build(); }
Example #8
Source File: ArmeriaEurekaClientTest.java From armeria with Apache License 2.0 | 5 votes |
private static com.linecorp.armeria.internal.common.eureka.LeaseInfo convertLeaseInfo( LeaseInfo leaseInfo) { return new com.linecorp.armeria.internal.common.eureka.LeaseInfo( leaseInfo.getRenewalIntervalInSecs(), leaseInfo.getDurationInSecs(), leaseInfo.getRegistrationTimestamp(), leaseInfo.getRenewalTimestamp(), leaseInfo.getEvictionTimestamp(), leaseInfo.getServiceUpTimestamp()); }
Example #9
Source File: InstanceRegistryTests.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
@Test public void testDefaultLeaseDurationRegisterEvent() throws Exception { // creating instance info final InstanceInfo instanceInfo = getInstanceInfo(APP_NAME, HOST_NAME, INSTANCE_ID, PORT, null); // calling tested method instanceRegistry.register(instanceInfo, false); // instance info duration is set to default final EurekaInstanceRegisteredEvent registeredEvent = (EurekaInstanceRegisteredEvent) (this.testEvents.applicationEvents .get(0)); assertThat(registeredEvent.getLeaseDuration()) .isEqualTo(LeaseInfo.DEFAULT_LEASE_DURATION); }
Example #10
Source File: InstanceRegistryTests.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
private InstanceInfo getInstanceInfo(String appName, String hostName, String instanceId, int port, LeaseInfo leaseInfo) { InstanceInfo.Builder builder = InstanceInfo.Builder.newBuilder(); builder.setAppName(appName); builder.setHostName(hostName); builder.setInstanceId(instanceId); builder.setPort(port); builder.setLeaseInfo(leaseInfo); return builder.build(); }
Example #11
Source File: CloudJacksonJson.java From didi-eureka-server with MIT License | 4 votes |
@SuppressWarnings("deprecation") public CloudJacksonCodec() { super(); ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); SimpleModule module = new SimpleModule("eureka1.x", VERSION); module.addSerializer(DataCenterInfo.class, new DataCenterInfoSerializer()); module.addSerializer(InstanceInfo.class, new CloudInstanceInfoSerializer()); module.addSerializer(Application.class, new ApplicationSerializer()); module.addSerializer(Applications.class, new ApplicationsSerializer( this.getVersionDeltaKey(), this.getAppHashCodeKey())); module.addDeserializer(DataCenterInfo.class, new DataCenterInfoDeserializer()); module.addDeserializer(LeaseInfo.class, new LeaseInfoDeserializer()); module.addDeserializer(InstanceInfo.class, new CloudInstanceInfoDeserializer(mapper)); module.addDeserializer(Application.class, new ApplicationDeserializer(mapper)); module.addDeserializer(Applications.class, new ApplicationsDeserializer( mapper, this.getVersionDeltaKey(), this.getAppHashCodeKey())); mapper.registerModule(module); HashMap<Class<?>, ObjectReader> readers = new HashMap<>(); readers.put(InstanceInfo.class, mapper.reader().withType(InstanceInfo.class) .withRootName("instance")); readers.put(Application.class, mapper.reader().withType(Application.class) .withRootName("application")); readers.put(Applications.class, mapper.reader().withType(Applications.class) .withRootName("applications")); setField("objectReaderByClass", readers); HashMap<Class<?>, ObjectWriter> writers = new HashMap<>(); writers.put(InstanceInfo.class, mapper.writer().withType(InstanceInfo.class) .withRootName("instance")); writers.put(Application.class, mapper.writer().withType(Application.class) .withRootName("application")); writers.put(Applications.class, mapper.writer().withType(Applications.class) .withRootName("applications")); setField("objectWriterByClass", writers); setField("mapper", mapper); }
Example #12
Source File: InstanceRegistryTest.java From didi-eureka-server with MIT License | 4 votes |
private LeaseInfo getLeaseInfo() { LeaseInfo.Builder leaseBuilder = LeaseInfo.Builder.newBuilder(); leaseBuilder.setRenewalIntervalInSecs(10); leaseBuilder.setDurationInSecs(15); return leaseBuilder.build(); }
Example #13
Source File: CloudJacksonJson.java From spring-cloud-netflix with Apache License 2.0 | 4 votes |
@SuppressWarnings("deprecation") CloudJacksonCodec() { super(); ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); SimpleModule module = new SimpleModule("eureka1.x", VERSION); module.addSerializer(DataCenterInfo.class, new DataCenterInfoSerializer()); module.addSerializer(InstanceInfo.class, new CloudInstanceInfoSerializer()); module.addSerializer(Application.class, new ApplicationSerializer()); module.addSerializer(Applications.class, new ApplicationsSerializer( this.getVersionDeltaKey(), this.getAppHashCodeKey())); // TODO: Watch if this causes problems // module.addDeserializer(DataCenterInfo.class, // new DataCenterInfoDeserializer()); module.addDeserializer(LeaseInfo.class, new LeaseInfoDeserializer()); module.addDeserializer(InstanceInfo.class, new CloudInstanceInfoDeserializer(mapper)); module.addDeserializer(Application.class, new ApplicationDeserializer(mapper)); module.addDeserializer(Applications.class, new ApplicationsDeserializer( mapper, this.getVersionDeltaKey(), this.getAppHashCodeKey())); mapper.registerModule(module); HashMap<Class<?>, Supplier<ObjectReader>> readers = new HashMap<>(); readers.put(InstanceInfo.class, () -> mapper.reader() .withType(InstanceInfo.class).withRootName("instance")); readers.put(Application.class, () -> mapper.reader() .withType(Application.class).withRootName("application")); readers.put(Applications.class, () -> mapper.reader() .withType(Applications.class).withRootName("applications")); setField("objectReaderByClass", readers); HashMap<Class<?>, ObjectWriter> writers = new HashMap<>(); writers.put(InstanceInfo.class, mapper.writer().withType(InstanceInfo.class) .withRootName("instance")); writers.put(Application.class, mapper.writer().withType(Application.class) .withRootName("application")); writers.put(Applications.class, mapper.writer().withType(Applications.class) .withRootName("applications")); setField("objectWriterByClass", writers); setField("mapper", mapper); }
Example #14
Source File: InstanceRegistryTests.java From spring-cloud-netflix with Apache License 2.0 | 4 votes |
private LeaseInfo getLeaseInfo() { LeaseInfo.Builder leaseBuilder = LeaseInfo.Builder.newBuilder(); leaseBuilder.setRenewalIntervalInSecs(10); leaseBuilder.setDurationInSecs(15); return leaseBuilder.build(); }
Example #15
Source File: InstanceInfoFactory.java From spring-cloud-netflix with Apache License 2.0 | 4 votes |
public InstanceInfo create(EurekaInstanceConfig config) { LeaseInfo.Builder leaseInfoBuilder = LeaseInfo.Builder.newBuilder() .setRenewalIntervalInSecs(config.getLeaseRenewalIntervalInSeconds()) .setDurationInSecs(config.getLeaseExpirationDurationInSeconds()); // Builder the instance information to be registered with eureka // server InstanceInfo.Builder builder = InstanceInfo.Builder.newBuilder(); String namespace = config.getNamespace(); if (!namespace.endsWith(".")) { namespace = namespace + "."; } builder.setNamespace(namespace).setAppName(config.getAppname()) .setInstanceId(config.getInstanceId()) .setAppGroupName(config.getAppGroupName()) .setDataCenterInfo(config.getDataCenterInfo()) .setIPAddr(config.getIpAddress()).setHostName(config.getHostName(false)) .setPort(config.getNonSecurePort()) .enablePort(InstanceInfo.PortType.UNSECURE, config.isNonSecurePortEnabled()) .setSecurePort(config.getSecurePort()) .enablePort(InstanceInfo.PortType.SECURE, config.getSecurePortEnabled()) .setVIPAddress(config.getVirtualHostName()) .setSecureVIPAddress(config.getSecureVirtualHostName()) .setHomePageUrl(config.getHomePageUrlPath(), config.getHomePageUrl()) .setStatusPageUrl(config.getStatusPageUrlPath(), config.getStatusPageUrl()) .setHealthCheckUrls(config.getHealthCheckUrlPath(), config.getHealthCheckUrl(), config.getSecureHealthCheckUrl()) .setASGName(config.getASGName()); // Start off with the STARTING state to avoid traffic if (!config.isInstanceEnabledOnit()) { InstanceInfo.InstanceStatus initialStatus = InstanceInfo.InstanceStatus.STARTING; if (log.isInfoEnabled()) { log.info("Setting initial instance status as: " + initialStatus); } builder.setStatus(initialStatus); } else { if (log.isInfoEnabled()) { log.info("Setting initial instance status as: " + InstanceInfo.InstanceStatus.UP + ". This may be too early for the instance to advertise itself as available. " + "You would instead want to control this via a healthcheck handler."); } } // Add any user-specific metadata information for (Map.Entry<String, String> mapEntry : config.getMetadataMap().entrySet()) { String key = mapEntry.getKey(); String value = mapEntry.getValue(); // only add the metadata if the value is present if (value != null && !value.isEmpty()) { builder.add(key, value); } } InstanceInfo instanceInfo = builder.build(); instanceInfo.setLeaseInfo(leaseInfoBuilder.build()); return instanceInfo; }