com.netflix.eureka.registry.PeerAwareInstanceRegistry Java Examples

The following examples show how to use com.netflix.eureka.registry.PeerAwareInstanceRegistry. 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: AbstractDocumentationTests.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@Bean
public EurekaServerContext testEurekaServerContext(ServerCodecs serverCodecs,
		PeerAwareInstanceRegistry registry, PeerEurekaNodes peerEurekaNodes,
		ApplicationInfoManager applicationInfoManager,
		EurekaServerConfig eurekaServerConfig) {
	return new DefaultEurekaServerContext(eurekaServerConfig, serverCodecs,
			registry, peerEurekaNodes, applicationInfoManager) {
		@Override
		public void shutdown() {
			logger.info(
					"Shutting down (except ServoControl and EurekaMonitors)..");
			registry.shutdown();
			peerEurekaNodes.shutdown();
			// ServoControl.shutdown();
			// EurekaMonitors.shutdown();
			logger.info("Shut down");
		}
	};
}
 
Example #2
Source File: EurekaResource.java    From flair-registry with Apache License 2.0 6 votes vote down vote up
private Map<String, Object> getEurekaStatus() {

        Map<String, Object> stats = new HashMap<>();
        stats.put("time", new Date());
        stats.put("currentTime", StatusResource.getCurrentTimeAsString());
        stats.put("upTime", StatusInfo.getUpTime());
        stats.put("environment", ConfigurationManager.getDeploymentContext()
            .getDeploymentEnvironment());
        stats.put("datacenter", ConfigurationManager.getDeploymentContext()
            .getDeploymentDatacenter());

        PeerAwareInstanceRegistry registry = getRegistry();

        stats.put("isBelowRenewThreshold", registry.isBelowRenewThresold() == 1);

        populateInstanceInfo(stats);

        return stats;
    }
 
Example #3
Source File: EurekaController.java    From didi-eureka-server with MIT License 6 votes vote down vote up
private void populateHeader(Map<String, Object> model) {
	model.put("currentTime", StatusResource.getCurrentTimeAsString());
	model.put("upTime", StatusInfo.getUpTime());
	model.put("environment", ConfigurationManager.getDeploymentContext()
			.getDeploymentEnvironment());
	model.put("datacenter", ConfigurationManager.getDeploymentContext()
			.getDeploymentDatacenter());
	PeerAwareInstanceRegistry registry = getRegistry();
	model.put("registry", registry);
	model.put("isBelowRenewThresold", registry.isBelowRenewThresold() == 1);
	DataCenterInfo info = applicationInfoManager.getInfo().getDataCenterInfo();
	if (info.getName() == DataCenterInfo.Name.Amazon) {
		AmazonInfo amazonInfo = (AmazonInfo) info;
		model.put("amazonInfo", amazonInfo);
		model.put("amiId", amazonInfo.get(AmazonInfo.MetaDataKey.amiId));
		model.put("availabilityZone",
				amazonInfo.get(AmazonInfo.MetaDataKey.availabilityZone));
		model.put("instanceId", amazonInfo.get(AmazonInfo.MetaDataKey.instanceId));
	}
}
 
Example #4
Source File: StaticServicesRegistrationService.java    From api-layer with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Reloads all statically defined APIs in locations specified by configuration
 * by reading the definitions again.
 */
public synchronized StaticRegistrationResult reloadServices() {
    List<InstanceInfo> oldStaticInstances = new ArrayList<>(staticInstances);

    staticInstances.clear();
    StaticRegistrationResult result = registerServices(staticApiDefinitionsDirectories);

    PeerAwareInstanceRegistry registry = getRegistry();
    for (InstanceInfo info: oldStaticInstances) {
        if (!result.getRegisteredServices().contains(info.getInstanceId())) {
            log.info("Instance {} is not defined in the new static API definitions. It will be removed", info.getInstanceId());
            registry.cancel(info.getAppName(), info.getId(), false);
        }
    }

    return result;
}
 
Example #5
Source File: StaticServicesRegistrationService.java    From api-layer with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Registers all statically defined APIs in a directory.
 */
StaticRegistrationResult registerServices(String staticApiDefinitionsDirectories) {
    PeerAwareInstanceRegistry registry = getRegistry();
    StaticRegistrationResult result = serviceDefinitionProcessor.findStaticServicesData(staticApiDefinitionsDirectories);

    // at first register service additional data, becase static could be also updated
    final Map<String, ServiceOverrideData> additionalServiceMetadata = result.getAdditionalServiceMetadata();
    metadataDefaultsService.setAdditionalServiceMetadata(additionalServiceMetadata);

    // register static services
    for (InstanceInfo instanceInfo : result.getInstances()) {
        result.getRegisteredServices().add(instanceInfo.getInstanceId());
        staticInstances.add(instanceInfo);
        registry.register(instanceInfo, false);
    }

    return result;
}
 
Example #6
Source File: EurekaResource.java    From jhipster-microservices-example with Apache License 2.0 6 votes vote down vote up
private Map<String, Object> getEurekaStatus() {

        Map<String, Object> stats = new HashMap<>();
        stats.put("time", new Date());
        stats.put("currentTime", StatusResource.getCurrentTimeAsString());
        stats.put("upTime", StatusInfo.getUpTime());
        stats.put("environment", ConfigurationManager.getDeploymentContext()
            .getDeploymentEnvironment());
        stats.put("datacenter", ConfigurationManager.getDeploymentContext()
            .getDeploymentDatacenter());

        PeerAwareInstanceRegistry registry = getRegistry();

        stats.put("isBelowRenewThreshold", registry.isBelowRenewThresold() == 1);

        populateInstanceInfo(stats);

        return stats;
    }
 
Example #7
Source File: EurekaResource.java    From jhipster-registry with Apache License 2.0 6 votes vote down vote up
private Map<String, Object> getEurekaStatus() {

        Map<String, Object> stats = new HashMap<>();
        stats.put("time", new Date());
        stats.put("currentTime", StatusResource.getCurrentTimeAsString());
        stats.put("upTime", StatusInfo.getUpTime());
        stats.put("environment", ConfigurationManager.getDeploymentContext()
            .getDeploymentEnvironment());
        stats.put("datacenter", ConfigurationManager.getDeploymentContext()
            .getDeploymentDatacenter());

        PeerAwareInstanceRegistry registry = getRegistry();

        stats.put("isBelowRenewThreshold", registry.isBelowRenewThresold() == 1);

        populateInstanceInfo(stats);

        return stats;
    }
 
Example #8
Source File: EurekaController.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
private void populateHeader(Map<String, Object> model) {
	model.put("currentTime", StatusResource.getCurrentTimeAsString());
	model.put("upTime", StatusInfo.getUpTime());
	model.put("environment", "N/A"); // FIXME:
	model.put("datacenter", "N/A"); // FIXME:
	PeerAwareInstanceRegistry registry = getRegistry();
	model.put("registry", registry);
	model.put("isBelowRenewThresold", registry.isBelowRenewThresold() == 1);
	DataCenterInfo info = applicationInfoManager.getInfo().getDataCenterInfo();
	if (info.getName() == DataCenterInfo.Name.Amazon) {
		AmazonInfo amazonInfo = (AmazonInfo) info;
		model.put("amazonInfo", amazonInfo);
		model.put("amiId", amazonInfo.get(AmazonInfo.MetaDataKey.amiId));
		model.put("availabilityZone",
				amazonInfo.get(AmazonInfo.MetaDataKey.availabilityZone));
		model.put("instanceId", amazonInfo.get(AmazonInfo.MetaDataKey.instanceId));
	}
}
 
Example #9
Source File: EurekaServerAutoConfiguration.java    From didi-eureka-server with MIT License 5 votes vote down vote up
@Bean
public EurekaServerBootstrap eurekaServerBootstrap(PeerAwareInstanceRegistry registry,
		EurekaServerContext serverContext) {
	return new EurekaServerBootstrap(this.applicationInfoManager,
			this.eurekaClientConfig, this.eurekaServerConfig, registry,
			serverContext);
}
 
Example #10
Source File: EurekaServerAutoConfiguration.java    From didi-eureka-server with MIT License 5 votes vote down vote up
@Bean
public PeerAwareInstanceRegistry peerAwareInstanceRegistry(
		ServerCodecs serverCodecs) {
	this.eurekaClient.getApplications(); // force initialization
	return new InstanceRegistry(this.eurekaServerConfig, this.eurekaClientConfig,
			serverCodecs, this.eurekaClient,
			this.instanceRegistryProperties.getExpectedNumberOfRenewsPerMin(),
			this.instanceRegistryProperties.getDefaultOpenForTrafficCount());
}
 
Example #11
Source File: EurekaControllerTest.java    From didi-eureka-server with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
	PeerEurekaNodes peerEurekaNodes = mock(PeerEurekaNodes.class);
	when(peerEurekaNodes.getPeerNodesView()).thenReturn(Collections.<PeerEurekaNode>emptyList());

	InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder()
			.setAppName("test")
			.setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn))
			.build();

	this.infoManager = mock(ApplicationInfoManager.class);
	this.original = ApplicationInfoManager.getInstance();
	setInstance(this.infoManager);
	when(this.infoManager.getInfo()).thenReturn(instanceInfo);

	Application myapp = new Application("myapp");
	myapp.addInstance(InstanceInfo.Builder.newBuilder()
			.setAppName("myapp")
			.setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn))
			.setInstanceId("myapp:1")
			.build());

	ArrayList<Application> applications = new ArrayList<>();
	applications.add(myapp);

	PeerAwareInstanceRegistry registry = mock(PeerAwareInstanceRegistry.class);
	when(registry.getSortedApplications()).thenReturn(applications);

	EurekaServerContext serverContext = mock(EurekaServerContext.class);
	EurekaServerContextHolder.initialize(serverContext);
	when(serverContext.getRegistry()).thenReturn(registry);
	when(serverContext.getPeerEurekaNodes()).thenReturn(peerEurekaNodes);
	when(serverContext.getApplicationInfoManager()).thenReturn(this.infoManager);

}
 
Example #12
Source File: EurekaCustomPeerNodesTest.java    From didi-eureka-server with MIT License 5 votes vote down vote up
@Bean
public PeerEurekaNodes myPeerEurekaNodes(PeerAwareInstanceRegistry registry,
		EurekaServerConfig eurekaServerConfig,
		EurekaClientConfig eurekaClientConfig, ServerCodecs serverCodecs,
		ApplicationInfoManager applicationInfoManager) {
	return new CustomEurekaPeerNodes(registry, eurekaServerConfig,
			eurekaClientConfig, serverCodecs, applicationInfoManager);
}
 
Example #13
Source File: EurekaCustomPeerNodesTest.java    From didi-eureka-server with MIT License 5 votes vote down vote up
public CustomEurekaPeerNodes(PeerAwareInstanceRegistry registry,
		EurekaServerConfig serverConfig, EurekaClientConfig clientConfig,
		ServerCodecs serverCodecs,
		ApplicationInfoManager applicationInfoManager) {
	super(registry, serverConfig, clientConfig, serverCodecs,
			applicationInfoManager);
}
 
Example #14
Source File: EurekaServerBootstrap.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
public EurekaServerBootstrap(ApplicationInfoManager applicationInfoManager,
		EurekaClientConfig eurekaClientConfig, EurekaServerConfig eurekaServerConfig,
		PeerAwareInstanceRegistry registry, EurekaServerContext serverContext) {
	this.applicationInfoManager = applicationInfoManager;
	this.eurekaClientConfig = eurekaClientConfig;
	this.eurekaServerConfig = eurekaServerConfig;
	this.registry = registry;
	this.serverContext = serverContext;
}
 
Example #15
Source File: EurekaServerAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Bean
public PeerAwareInstanceRegistry peerAwareInstanceRegistry(
		ServerCodecs serverCodecs) {
	this.eurekaClient.getApplications(); // force initialization
	return new InstanceRegistry(this.eurekaServerConfig, this.eurekaClientConfig,
			serverCodecs, this.eurekaClient,
			this.instanceRegistryProperties.getExpectedNumberOfClientsSendingRenews(),
			this.instanceRegistryProperties.getDefaultOpenForTrafficCount());
}
 
Example #16
Source File: EurekaServerAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public PeerEurekaNodes peerEurekaNodes(PeerAwareInstanceRegistry registry,
		ServerCodecs serverCodecs,
		ReplicationClientAdditionalFilters replicationClientAdditionalFilters) {
	return new RefreshablePeerEurekaNodes(registry, this.eurekaServerConfig,
			this.eurekaClientConfig, serverCodecs, this.applicationInfoManager,
			replicationClientAdditionalFilters);
}
 
Example #17
Source File: EurekaServerAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public EurekaServerContext eurekaServerContext(ServerCodecs serverCodecs,
		PeerAwareInstanceRegistry registry, PeerEurekaNodes peerEurekaNodes) {
	return new DefaultEurekaServerContext(this.eurekaServerConfig, serverCodecs,
			registry, peerEurekaNodes, this.applicationInfoManager);
}
 
Example #18
Source File: EurekaServerAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Bean
public EurekaServerBootstrap eurekaServerBootstrap(PeerAwareInstanceRegistry registry,
		EurekaServerContext serverContext) {
	return new EurekaServerBootstrap(this.applicationInfoManager,
			this.eurekaClientConfig, this.eurekaServerConfig, registry,
			serverContext);
}
 
Example #19
Source File: EurekaServerAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
RefreshablePeerEurekaNodes(final PeerAwareInstanceRegistry registry,
		final EurekaServerConfig serverConfig,
		final EurekaClientConfig clientConfig, final ServerCodecs serverCodecs,
		final ApplicationInfoManager applicationInfoManager,
		final ReplicationClientAdditionalFilters replicationClientAdditionalFilters) {
	super(registry, serverConfig, clientConfig, serverCodecs,
			applicationInfoManager);
	this.replicationClientAdditionalFilters = replicationClientAdditionalFilters;
}
 
Example #20
Source File: EurekaCustomPeerNodesTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Bean
public PeerEurekaNodes myPeerEurekaNodes(PeerAwareInstanceRegistry registry,
		EurekaServerConfig eurekaServerConfig,
		EurekaClientConfig eurekaClientConfig, ServerCodecs serverCodecs,
		ApplicationInfoManager applicationInfoManager) {
	return new CustomEurekaPeerNodes(registry, eurekaServerConfig,
			eurekaClientConfig, serverCodecs, applicationInfoManager);
}
 
Example #21
Source File: EurekaCustomPeerNodesTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
CustomEurekaPeerNodes(PeerAwareInstanceRegistry registry,
		EurekaServerConfig serverConfig, EurekaClientConfig clientConfig,
		ServerCodecs serverCodecs,
		ApplicationInfoManager applicationInfoManager) {
	super(registry, serverConfig, clientConfig, serverCodecs,
			applicationInfoManager);
}
 
Example #22
Source File: EurekaControllerTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
	PeerEurekaNodes peerEurekaNodes = mock(PeerEurekaNodes.class);
	when(peerEurekaNodes.getPeerNodesView())
			.thenReturn(Collections.<PeerEurekaNode>emptyList());

	InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("test")
			.setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn))
			.build();

	this.infoManager = mock(ApplicationInfoManager.class);
	this.original = ApplicationInfoManager.getInstance();
	setInstance(this.infoManager);
	when(this.infoManager.getInfo()).thenReturn(instanceInfo);

	Application myapp = new Application("myapp");
	myapp.addInstance(InstanceInfo.Builder.newBuilder().setAppName("myapp")
			.setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn))
			.setInstanceId("myapp:1").build());

	ArrayList<Application> applications = new ArrayList<>();
	applications.add(myapp);

	PeerAwareInstanceRegistry registry = mock(PeerAwareInstanceRegistry.class);
	when(registry.getSortedApplications()).thenReturn(applications);

	EurekaServerContext serverContext = mock(EurekaServerContext.class);
	EurekaServerContextHolder.initialize(serverContext);
	when(serverContext.getRegistry()).thenReturn(registry);
	when(serverContext.getPeerEurekaNodes()).thenReturn(peerEurekaNodes);
	when(serverContext.getApplicationInfoManager()).thenReturn(this.infoManager);

}
 
Example #23
Source File: EurekaServerAutoConfiguration.java    From didi-eureka-server with MIT License 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public PeerEurekaNodes peerEurekaNodes(PeerAwareInstanceRegistry registry,
		ServerCodecs serverCodecs) {
	return new PeerEurekaNodes(registry, this.eurekaServerConfig,
			this.eurekaClientConfig, serverCodecs, this.applicationInfoManager);
}
 
Example #24
Source File: EurekaUtil.java    From RCT with Apache License 2.0 5 votes vote down vote up
/**
 * 获取eureka注册节点
 * 
 * @return List<AnalyzeInstance>
 */
public static List<AnalyzeInstance> getRegisterNodes() {
	PeerAwareInstanceRegistry registry = EurekaServerContextHolder.getInstance().getServerContext().getRegistry();
	Applications applications = registry.getApplications();
	List<AnalyzeInstance> analyzes = new ArrayList<>();
	applications.getRegisteredApplications().forEach((registeredApplication) -> {
		registeredApplication.getInstances().forEach((instance) -> {
			AnalyzeInstance analyzeInstance = new AnalyzeInstance(instance.getIPAddr(), instance.getPort());
			analyzes.add(analyzeInstance);
		});
	});

	return analyzes;
}
 
Example #25
Source File: EurekaServerBootstrap.java    From didi-eureka-server with MIT License 5 votes vote down vote up
public EurekaServerBootstrap(ApplicationInfoManager applicationInfoManager,
		EurekaClientConfig eurekaClientConfig, EurekaServerConfig eurekaServerConfig,
		PeerAwareInstanceRegistry registry, EurekaServerContext serverContext) {
	this.applicationInfoManager = applicationInfoManager;
	this.eurekaClientConfig = eurekaClientConfig;
	this.eurekaServerConfig = eurekaServerConfig;
	this.registry = registry;
	this.serverContext = serverContext;
}
 
Example #26
Source File: DiscoveryServerConfig.java    From mPaaS with Apache License 2.0 5 votes vote down vote up
public CustomRefreshablePeerEurekaNodes(
        final PeerAwareInstanceRegistry registry,
        final EurekaServerConfig serverConfig,
        final EurekaClientConfig clientConfig,
        final ServerCodecs serverCodecs,
        final ApplicationInfoManager applicationInfoManager) {
    super(registry, serverConfig, clientConfig, serverCodecs, applicationInfoManager);
}
 
Example #27
Source File: EurekaUtil.java    From redis-manager with Apache License 2.0 5 votes vote down vote up
/**
 * 获取eureka注册节点
 * 
 * @return List<AnalyzeInstance>
 */
public static List<AnalyzeInstance> getRegisterNodes() {
	PeerAwareInstanceRegistry registry = EurekaServerContextHolder.getInstance().getServerContext().getRegistry();
	Applications applications = registry.getApplications();
	List<AnalyzeInstance> analyzes = new ArrayList<>();
	applications.getRegisteredApplications().forEach((registeredApplication) -> {
		registeredApplication.getInstances().forEach((instance) -> {
			AnalyzeInstance analyzeInstance = new AnalyzeInstance(instance.getIPAddr(), instance.getPort());
			analyzes.add(analyzeInstance);
		});
	});

	return analyzes;
}
 
Example #28
Source File: EurekaStore.java    From qconfig with MIT License 5 votes vote down vote up
protected PeerEurekaNodes getPeerEurekaNodes(PeerAwareInstanceRegistry registry, EurekaServerConfig eurekaServerConfig, EurekaClientConfig eurekaClientConfig, ServerCodecs serverCodecs, ApplicationInfoManager applicationInfoManager) {
    return new PeerEurekaNodes(
            registry,
            eurekaServerConfig,
            eurekaClientConfig,
            serverCodecs,
            applicationInfoManager
    );
}
 
Example #29
Source File: EurekaConsulAdapterConfig.java    From eureka-consul-adapter with MIT License 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public RegistrationService registrationService(PeerAwareInstanceRegistry peerAwareInstanceRegistry) {
    Assert.isTrue(peerAwareInstanceRegistry instanceof RegistrationEventInstanceRegistry,
            "Instance Registry must be of type" + RegistrationEventInstanceRegistry.class.getName());
    return new RegistrationService(peerAwareInstanceRegistry, serviceChangeDetector());
}
 
Example #30
Source File: StaticServicesRegistrationService.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
synchronized void renewInstances() {
    log.debug("Renewing static instances");
    PeerAwareInstanceRegistry registry = getRegistry();
    for (InstanceInfo instance : getStaticInstances()) {
        registry.renew(instance.getAppName(), instance.getId(), false);
    }
}