com.netflix.eureka.cluster.PeerEurekaNode Java Examples

The following examples show how to use com.netflix.eureka.cluster.PeerEurekaNode. 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: EurekaController.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
private void populateNavbar(HttpServletRequest request, Map<String, Object> model) {
	Map<String, String> replicas = new LinkedHashMap<>();
	List<PeerEurekaNode> list = getServerContext().getPeerEurekaNodes()
			.getPeerNodesView();
	for (PeerEurekaNode node : list) {
		try {
			URI uri = new URI(node.getServiceUrl());
			String href = scrubBasicAuth(node.getServiceUrl());
			replicas.put(uri.getHost(), href);
		}
		catch (Exception ex) {
			// ignore?
		}
	}
	model.put("replicas", replicas.entrySet());
}
 
Example #2
Source File: EurekaServerAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@Override
protected PeerEurekaNode createPeerEurekaNode(String peerEurekaNodeUrl) {
	JerseyReplicationClient replicationClient = JerseyReplicationClient
			.createReplicationClient(serverConfig, serverCodecs,
					peerEurekaNodeUrl);

	this.replicationClientAdditionalFilters.getFilters()
			.forEach(replicationClient::addReplicationClientFilter);

	String targetHost = hostFromUrl(peerEurekaNodeUrl);
	if (targetHost == null) {
		targetHost = "host";
	}
	return new PeerEurekaNode(registry, targetHost, peerEurekaNodeUrl,
			replicationClient, serverConfig);
}
 
Example #3
Source File: DiscoveryServerConfig.java    From mPaaS with Apache License 2.0 5 votes vote down vote up
@Override
protected PeerEurekaNode createPeerEurekaNode(String peerEurekaNodeUrl) {
    HttpReplicationClient replicationClient = createReplicationClient(serverConfig, serverCodecs, peerEurekaNodeUrl);
    String targetHost = hostFromUrl(peerEurekaNodeUrl);
    if (targetHost == null) {
        targetHost = "host";
    }
    return new PeerEurekaNode(registry, targetHost, peerEurekaNodeUrl, replicationClient, serverConfig);
}
 
Example #4
Source File: EurekaController.java    From didi-eureka-server with MIT License 5 votes vote down vote up
private void populateNavbar(HttpServletRequest request, Map<String, Object> model) {
	Map<String, String> replicas = new LinkedHashMap<>();
	List<PeerEurekaNode> list = getServerContext().getPeerEurekaNodes().getPeerNodesView();
	for (PeerEurekaNode node : list) {
		try {
			URI uri = new URI(node.getServiceUrl());
			String href = scrubBasicAuth(node.getServiceUrl());
			replicas.put(uri.getHost(), href);
		}
		catch (Exception ex) {
			// ignore?
		}
	}
	model.put("replicas", replicas.entrySet());
}
 
Example #5
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 #6
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);

}