com.netflix.eureka.EurekaServerContext Java Examples

The following examples show how to use com.netflix.eureka.EurekaServerContext. 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: 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 #3
Source File: EurekaServerBootstrap.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
public void contextInitialized(ServletContext context) {
	try {
		initEurekaEnvironment();
		initEurekaServerContext();

		context.setAttribute(EurekaServerContext.class.getName(), this.serverContext);
	}
	catch (Throwable e) {
		log.error("Cannot bootstrap eureka server :", e);
		throw new RuntimeException("Cannot bootstrap eureka server :", e);
	}
}
 
Example #4
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 #5
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 #6
Source File: EurekaServerBootstrap.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
public void contextDestroyed(ServletContext context) {
	try {
		log.info("Shutting down Eureka Server..");
		context.removeAttribute(EurekaServerContext.class.getName());

		destroyEurekaServerContext();
		destroyEurekaEnvironment();

	}
	catch (Throwable e) {
		log.error("Error shutting down eureka", e);
	}
	log.info("Eureka Service is now shutdown...");
}
 
Example #7
Source File: EurekaServerBootstrap.java    From didi-eureka-server with MIT License 5 votes vote down vote up
public void contextDestroyed(ServletContext context) {
	try {
		log.info("Shutting down Eureka Server..");
		context.removeAttribute(EurekaServerContext.class.getName());

		destroyEurekaServerContext();
		destroyEurekaEnvironment();

	}
	catch (Throwable e) {
		log.error("Error shutting down eureka", e);
	}
	log.info("Eureka Service is now shutdown...");
}
 
Example #8
Source File: EurekaServerBootstrap.java    From didi-eureka-server with MIT License 5 votes vote down vote up
public void contextInitialized(ServletContext context) {
	try {
		initEurekaEnvironment();
		initEurekaServerContext();

		context.setAttribute(EurekaServerContext.class.getName(), this.serverContext);
	}
	catch (Throwable e) {
		log.error("Cannot bootstrap eureka server :", e);
		throw new RuntimeException("Cannot bootstrap eureka server :", e);
	}
}
 
Example #9
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 #10
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 #11
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 #12
Source File: GatewayNotifierTest.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    EurekaServerContext context = mock(EurekaServerContext.class);
    registry = mock(AwsInstanceRegistry.class);
    when(context.getRegistry()).thenReturn(registry);
    EurekaServerContextHolder.initialize(context);

    restTemplate = mock(RestTemplate.class);
    messageService = mock(MessageService.class);
    gatewayNotifierSync = new GatewayNotifierSync(restTemplate, messageService);
}
 
Example #13
Source File: MetadataDefaultsServiceTest.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    mockRegistry = mock(PeerAwareInstanceRegistry.class);
    doAnswer(x -> {
        EurekaInstanceRegisteredEvent event = mock(EurekaInstanceRegisteredEvent.class);
        when(event.getInstanceInfo()).thenReturn(x.getArgument(0));
        eurekaInstanceRegisteredListener.listen(event);
        return mockRegistry;
    }).when(mockRegistry).register(any(), anyBoolean());
    EurekaServerContext mockEurekaServerContext = mock(EurekaServerContext.class);
    when(mockEurekaServerContext.getRegistry()).thenReturn(mockRegistry);
    EurekaServerContextHolder.initialize(mockEurekaServerContext);
}
 
Example #14
Source File: StaticServicesRegistrationServiceTest.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testFindServicesInDirectoryNoFiles() {
    EurekaServerContext mockEurekaServerContext = mock(EurekaServerContext.class);
    EurekaServerContextHolder.initialize(mockEurekaServerContext);
    ServiceDefinitionProcessor serviceDefinitionProcessor = new ServiceDefinitionProcessor();

    StaticServicesRegistrationService registrationService = new StaticServicesRegistrationService(serviceDefinitionProcessor, new MetadataDefaultsService());
    StaticRegistrationResult result = registrationService.registerServices(folder.getRoot().getAbsolutePath());
    assertEquals(0, result.getInstances().size());
}
 
Example #15
Source File: StaticServicesRegistrationServiceTest.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    mockRegistry = mock(PeerAwareInstanceRegistry.class);
    EurekaServerContext mockEurekaServerContext = mock(EurekaServerContext.class);
    when(mockEurekaServerContext.getRegistry()).thenReturn(mockRegistry);
    EurekaServerContextHolder.initialize(mockEurekaServerContext);
}
 
Example #16
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 #17
Source File: EurekaServerAutoConfiguration.java    From didi-eureka-server with MIT License 4 votes vote down vote up
@Bean
public EurekaServerContext eurekaServerContext(ServerCodecs serverCodecs,
		PeerAwareInstanceRegistry registry, PeerEurekaNodes peerEurekaNodes) {
	return new DefaultEurekaServerContext(this.eurekaServerConfig, serverCodecs,
			registry, peerEurekaNodes, this.applicationInfoManager);
}
 
Example #18
Source File: EurekaController.java    From spring-cloud-netflix with Apache License 2.0 4 votes vote down vote up
private EurekaServerContext getServerContext() {
	return EurekaServerContextHolder.getInstance().getServerContext();
}
 
Example #19
Source File: InstanceInfoMeta.java    From onetwo with Apache License 2.0 4 votes vote down vote up
static public EurekaServerContext getEurekaServerContext() {
	return EurekaServerContextHolder.getInstance().getServerContext();
}
 
Example #20
Source File: EurekaResource.java    From jhipster-registry with Apache License 2.0 4 votes vote down vote up
private EurekaServerContext getServerContext() {
    return EurekaServerContextHolder.getInstance().getServerContext();
}
 
Example #21
Source File: EurekaResource.java    From flair-registry with Apache License 2.0 4 votes vote down vote up
private EurekaServerContext getServerContext() {
    return EurekaServerContextHolder.getInstance().getServerContext();
}
 
Example #22
Source File: EurekaController.java    From didi-eureka-server with MIT License 4 votes vote down vote up
private EurekaServerContext getServerContext() {
	return EurekaServerContextHolder.getInstance().getServerContext();
}
 
Example #23
Source File: EurekaResource.java    From jhipster-microservices-example with Apache License 2.0 4 votes vote down vote up
private EurekaServerContext getServerContext() {
    return EurekaServerContextHolder.getInstance().getServerContext();
}
 
Example #24
Source File: GatewayNotifier.java    From api-layer with Eclipse Public License 2.0 4 votes vote down vote up
private EurekaServerContext getServerContext() {
    return EurekaServerContextHolder.getInstance().getServerContext();
}
 
Example #25
Source File: StaticServicesRegistrationService.java    From api-layer with Eclipse Public License 2.0 4 votes vote down vote up
private EurekaServerContext getServerContext() {
    return EurekaServerContextHolder.getInstance().getServerContext();
}