com.netflix.discovery.DiscoveryManager Java Examples
The following examples show how to use
com.netflix.discovery.DiscoveryManager.
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: DiscoveryEnabledLoadBalancerSupportsUseIpAddrTest.java From ribbon with Apache License 2.0 | 6 votes |
@Before public void setupMock(){ List<InstanceInfo> servers = LoadBalancerTestUtils.getDummyInstanceInfo("dummy", HOST1, IP1, 8080); List<InstanceInfo> servers2 = LoadBalancerTestUtils.getDummyInstanceInfo("dummy", HOST2, IP2, 8080); servers.addAll(servers2); PowerMock.mockStatic(DiscoveryManager.class); PowerMock.mockStatic(DiscoveryClient.class); DiscoveryClient mockedDiscoveryClient = LoadBalancerTestUtils.mockDiscoveryClient(); DiscoveryManager mockedDiscoveryManager = createMock(DiscoveryManager.class); expect(DiscoveryManager.getInstance()).andReturn(mockedDiscoveryManager).anyTimes(); expect(mockedDiscoveryManager.getDiscoveryClient()).andReturn(mockedDiscoveryClient).anyTimes(); expect(mockedDiscoveryClient.getInstancesByVipAddress("dummy", false, "region")).andReturn(servers).anyTimes(); replay(DiscoveryManager.class); replay(DiscoveryClient.class); replay(mockedDiscoveryManager); replay(mockedDiscoveryClient); }
Example #2
Source File: EurekaResource.java From karyon with Apache License 2.0 | 6 votes |
@GET public Response getEurekaDetails() { List<EurekaInstanceInfo> instanceInfoList = new ArrayList<EurekaInstanceInfo>(); DiscoveryClient discoveryClient = DiscoveryManager.getInstance().getDiscoveryClient(); if (null != discoveryClient) { Applications apps = discoveryClient.getApplications(); for (Application app : apps.getRegisteredApplications()) { for (InstanceInfo inst : app.getInstances()) { instanceInfoList.add(new EurekaInstanceInfo(inst.getAppName(), inst.getId(), inst.getStatus().name(), inst.getIPAddr(), inst.getHostName())); } } } GsonBuilder gsonBuilder = new GsonBuilder().serializeNulls(); Gson gson = gsonBuilder.create(); String response = gson.toJson(new KaryonAdminResponse(instanceInfoList)); return Response.ok(response).build(); }
Example #3
Source File: EurekaModule.java From staash with Apache License 2.0 | 6 votes |
@Override protected void configure() { LOG.info("Configuring EurekaModule"); // Initialize eureka // TODO: Move this to a bootstrap thingy DiscoveryManager.getInstance().initComponent( new CloudInstanceConfig(), new DefaultEurekaClientConfig()); // Eureka - Astyanax integration MapBinder<String, HostSupplierProvider> hostSuppliers = MapBinder.newMapBinder(binder(), String.class, HostSupplierProvider.class); hostSuppliers.addBinding("eureka").to(EurekaAstyanaxHostSupplier.class); //bind(ClusterDiscoveryService.class).to(EurekaClusterDiscoveryService.class).asEagerSingleton(); }
Example #4
Source File: MockedDiscoveryServerListTest.java From ribbon with Apache License 2.0 | 6 votes |
@Before public void setupMock(){ List<InstanceInfo> instances = getDummyInstanceInfo("dummy", getMockServerList()); PowerMock.mockStatic(DiscoveryManager.class); PowerMock.mockStatic(DiscoveryClient.class); DiscoveryClient mockedDiscoveryClient = createMock(DiscoveryClient.class); DiscoveryManager mockedDiscoveryManager = createMock(DiscoveryManager.class); expect(mockedDiscoveryClient.getEurekaClientConfig()).andReturn(new DefaultEurekaClientConfig()).anyTimes(); expect(DiscoveryManager.getInstance()).andReturn(mockedDiscoveryManager).anyTimes(); expect(mockedDiscoveryManager.getDiscoveryClient()).andReturn(mockedDiscoveryClient).anyTimes(); expect(mockedDiscoveryClient.getInstancesByVipAddress(getVipAddress(), false, null)).andReturn(instances).anyTimes(); replay(DiscoveryManager.class); replay(DiscoveryClient.class); replay(mockedDiscoveryManager); replay(mockedDiscoveryClient); }
Example #5
Source File: LBBuilderTest.java From ribbon with Apache License 2.0 | 6 votes |
@Before public void setupMock(){ List<InstanceInfo> instances = LoadBalancerTestUtils.getDummyInstanceInfo("dummy", expected.getHost(), "127.0.0.1", expected.getPort()); PowerMock.mockStatic(DiscoveryManager.class); PowerMock.mockStatic(DiscoveryClient.class); DiscoveryClient mockedDiscoveryClient = LoadBalancerTestUtils.mockDiscoveryClient(); DiscoveryManager mockedDiscoveryManager = createMock(DiscoveryManager.class); expect(DiscoveryManager.getInstance()).andReturn(mockedDiscoveryManager).anyTimes(); expect(mockedDiscoveryManager.getDiscoveryClient()).andReturn(mockedDiscoveryClient).anyTimes(); expect(mockedDiscoveryClient.getInstancesByVipAddress("dummy:7001", false, null)).andReturn(instances).anyTimes(); replay(DiscoveryManager.class); replay(DiscoveryClient.class); replay(mockedDiscoveryManager); replay(mockedDiscoveryClient); }
Example #6
Source File: ChassisEurekaRegistrationTest.java From chassis with Apache License 2.0 | 6 votes |
@Test public void testServiceRegistration() throws InterruptedException { // Registers "chasis-default-name" with a Eurkea server running on local host. // http://localhost:8184/v2/apps/chassis-default-name // tell eureka the service is up which causes a registration ApplicationInfoManager.getInstance().setInstanceStatus(InstanceInfo.InstanceStatus.UP); // get application registration from Eureka DiscoveryClient client = DiscoveryManager.getInstance().getDiscoveryClient(); InstanceInfo instanceInfo = null; for (int i = 0; (instanceInfo == null) && (i < 50); i++) { Thread.sleep(5000); try { instanceInfo = client.getNextServerFromEureka("default-service", false); } catch (RuntimeException e) { // eat not found runtime exception } } Assert.assertNotNull(instanceInfo); Assert.assertEquals(InstanceStatus.UP, instanceInfo.getStatus()); System.out.println("done"); }
Example #7
Source File: EurekaStore.java From qconfig with MIT License | 6 votes |
/** * Handles Eureka cleanup, including shutting down all monitors and yielding all EIPs. * * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent) */ @PreDestroy public void destroy() { try { logger.info("{} Shutting down Eureka Server..", new Date().toString()); ServletContext sc = context.getServletContext(); sc.removeAttribute(EurekaServerContext.class.getName()); DiscoveryManager.getInstance().shutdownComponent(); destroyEurekaServerContext(); destroyEurekaEnvironment(); } catch (Throwable e) { logger.error("Error shutting down eureka", e); } logger.info("{} Eureka Service is now shutdown...", new Date().toString()); }
Example #8
Source File: HealthMonitor.java From Raigad with Apache License 2.0 | 5 votes |
@Inject public HealthMonitor(IConfiguration config, InstanceManager instanceManager, HttpModule httpModule) { super(config); this.instanceManager = instanceManager; this.httpModule = httpModule; healthReporter = new Elasticsearch_HealthReporter(); discoveryClient = DiscoveryManager.getInstance().getDiscoveryClient(); Monitors.registerObject(healthReporter); }
Example #9
Source File: ChassisConfiguration.java From chassis with Apache License 2.0 | 5 votes |
/** * Initializes the health check registry * * @return health check registry bean */ @Bean public HealthCheckRegistry healthCheckRegistry(ApplicationContext context, DiscoveryManager eureka) { final HealthCheckRegistry bean = new HealthCheckRegistry(); // auto-register beans implementing health checks Map<String, HealthCheck> healthChecks = context.getBeansOfType(HealthCheck.class); for (HealthCheck check : healthChecks.values()) { bean.register(check.getClass().getName(), check); } // connect health checks into Eureka if (!disableEureka) { eureka.getDiscoveryClient().registerHealthCheckCallback( new HealthCheckCallback() { @Override public boolean isHealthy() { for (Entry<String, HealthCheck.Result> entry : bean.runHealthChecks().entrySet()) { if (!entry.getValue().isHealthy()) { return false; } } return true; } }); } return bean; }
Example #10
Source File: InitializeServletListener.java From s2g-zuul with MIT License | 5 votes |
private void registerEureka() { DynamicBooleanProperty eurekaEnabled = DynamicPropertyFactory.getInstance().getBooleanProperty("eureka.enabled", true); if (!eurekaEnabled.get()) return; EurekaInstanceConfig eurekaInstanceConfig = new PropertiesInstanceConfig() { }; ConfigurationManager.getConfigInstance().setProperty("eureka.statusPageUrl","http://"+ getTurbineInstance()); DiscoveryManager.getInstance().initComponent(eurekaInstanceConfig, new DefaultEurekaClientConfig()); final DynamicStringProperty serverStatus = DynamicPropertyFactory.getInstance() .getStringProperty("server." + IPUtil.getLocalIP() + ".status", "up"); DiscoveryManager.getInstance().getDiscoveryClient().registerHealthCheckCallback(new HealthCheckCallback() { @Override public boolean isHealthy() { return serverStatus.get().toLowerCase().equals("up"); } }); String version = String.valueOf(System.currentTimeMillis()); String group = ConfigurationManager.getConfigInstance().getString("server.group", "default"); String dataCenter = ConfigurationManager.getConfigInstance().getString("server.data-center", "default"); Map<String, String> metadata = new HashMap<String, String>(); metadata.put("version", version); metadata.put("group", group); metadata.put("dataCenter", dataCenter); String turbineInstance = getTurbineInstance(); if (turbineInstance != null) { metadata.put("turbine.instance", turbineInstance); } ApplicationInfoManager.getInstance().registerAppMetadata(metadata); }
Example #11
Source File: LegacyEurekaClientProvider.java From ribbon with Apache License 2.0 | 5 votes |
@Override public synchronized EurekaClient get() { if (eurekaClient == null) { eurekaClient = DiscoveryManager.getInstance().getDiscoveryClient(); } return eurekaClient; }
Example #12
Source File: DefaultServerStore.java From qconfig with MIT License | 5 votes |
@Override public List<QConfigServer> getAvailableServers() { DiscoveryClient client = DiscoveryManager.getInstance().getDiscoveryClient(); Application application = client.getApplication("eureka"); if (application == null) { logger.warn("eureka application is null"); return emptyServers(); } List<InstanceInfo> instances = application.getInstances(); if (instances == null || instances.isEmpty()) { logger.warn("eureka instance is empty"); return emptyServers(); } List<QConfigServer> servers = Lists.newArrayListWithCapacity(instances.size()); for (InstanceInfo instance : instances) { logger.debug("eureka qconfig server instance {}:{}", instance.getIPAddr(), instance.getPort()); try { String ip = instance.getIPAddr(); if ("127.0.0.1".equals(ip)) { logger.warn("illegal qconfig server ip 127.0.0.1"); Monitor.serverLocalIpError.inc(); continue; } servers.add(new QConfigServer(ip, instance.getPort(), getRoom(ip))); } catch (Exception e) { // get room info error continue; } } if (servers.isEmpty()) { logger.warn("no legal eureka servers"); return emptyServers(); } return servers; }
Example #13
Source File: EurekaClusterDiscoveryService.java From staash with Apache License 2.0 | 5 votes |
@PreDestroy public void shutdown() { // TODO: Move this somewhere else LOG.info("Shutting down Eureka client"); DiscoveryManager.getInstance().shutdownComponent(); client = null; }
Example #14
Source File: EurekaModule.java From staash with Apache License 2.0 | 5 votes |
@Override protected void configure() { LOG.info("Configuring EurekaModule"); DiscoveryManager.getInstance().initComponent( new CloudInstanceConfig(), new DefaultEurekaClientConfig()); // Eureka - Astyanax integration MapBinder<String, HostSupplierProvider> hostSuppliers = MapBinder.newMapBinder(binder(), String.class, HostSupplierProvider.class); hostSuppliers.addBinding("eureka").to(EurekaAstyanaxHostSupplier.class).asEagerSingleton(); //bind(ClusterDiscoveryService.class).to(EurekaClusterDiscoveryService.class).asEagerSingleton(); }
Example #15
Source File: RibbonZuulCommon.java From s2g-zuul with MIT License | 5 votes |
protected RestClient getRestClient() throws ZuulException { Application application = DiscoveryManager.getInstance().getDiscoveryClient().getApplication(serviceName); if (application == null) { throw new ZuulException( "Service-NotFoud",HttpServletResponse.SC_NOT_FOUND, serviceName + "服务未找到"); } List<DiscoveryEnabledServer> instances = Lists.newArrayList(); for (InstanceInfo info : application.getInstances()) { if (info.getStatus() == InstanceStatus.UP) { instances.add(new DiscoveryEnabledServer(info, false, false)); } } RestClient client = (RestClient) ClientFactory.getNamedClient(serviceName); ZoneAwareLoadBalancer loadbalancer = (ZoneAwareLoadBalancer) client.getLoadBalancer(); // //loadbalancer.setServersList(instances); // IRule rule = new RandomRule(); // int ruleLoad = ZuulCommandHelper.getLoadBalanceRule(commandGroup, commandKey); // if (ruleLoad == 2) { // rule = new ClientConfigEnabledRoundRobinRule(); // } else if (ruleLoad == 3) { // rule=new AvailabilityFilteringRule(); // } else if (ruleLoad == 3) { // rule=new ZoneAvoidanceRule(); // } else if (ruleLoad == 4) { // rule=new RetryRule(); // } else if (ruleLoad == 5) { // rule=new RoundRobinRule(); // }else if (ruleLoad == 6) { // rule=new ResponseTimeWeightedRule(); // }else if (ruleLoad == 7) { // rule=new WeightedResponseTimeRule(); // } // loadbalancer.setRule(rule); // client.setLoadBalancer(loadbalancer); return client; }
Example #16
Source File: DiscoveryEnabledLoadBalancerSupportsPortOverrideTest.java From ribbon with Apache License 2.0 | 4 votes |
@After public void afterMock(){ verify(DiscoveryManager.class); verify(DiscoveryClient.class); }
Example #17
Source File: EurekaAstyanaxHostSupplier.java From staash with Apache License 2.0 | 4 votes |
public EurekaAstyanaxHostSupplier() { this.eurekaClient = DiscoveryManager.getInstance().getDiscoveryClient(); Preconditions.checkNotNull(this.eurekaClient); }
Example #18
Source File: EurekaClusterDiscoveryService.java From staash with Apache License 2.0 | 4 votes |
@PostConstruct public void initialize() { LOG.info("Initializing Eureka client"); client = DiscoveryManager.getInstance().getDiscoveryClient(); }
Example #19
Source File: EurekaAstyanaxHostSupplier.java From staash with Apache License 2.0 | 4 votes |
public EurekaAstyanaxHostSupplier() { this.eurekaClient = DiscoveryManager.getInstance().getDiscoveryClient(); Preconditions.checkNotNull(this.eurekaClient); }
Example #20
Source File: DiscoveryServerList.java From s2g-zuul with MIT License | 4 votes |
private List<DiscoveryEnabledServer> obtainServersViaDiscovery() { List<DiscoveryEnabledServer> serverList = new ArrayList<DiscoveryEnabledServer>(); DiscoveryClient discoveryClient = DiscoveryManager.getInstance().getDiscoveryClient(); if (discoveryClient == null) { return new ArrayList<DiscoveryEnabledServer>(); } // if (vipAddresses != null) { // for (String vipAddress : vipAddresses.split(",")) { // // if targetRegion is null, it will be interpreted as the same // // region of client // List<InstanceInfo> listOfinstanceInfo = // discoveryClient.getInstancesByVipAddress(vipAddress, isSecure, // targetRegion); // for (InstanceInfo ii : listOfinstanceInfo) { // if (ii.getStatus().equals(InstanceStatus.UP)) { // // if (shouldUseOverridePort) { // if (logger.isDebugEnabled()) { // logger.debug("Overriding port on client name: " + clientName + " to " // + overridePort); // } // // // copy is necessary since the InstanceInfo builder // // just uses the original reference, // // and we don't want to corrupt the global eureka // // copy of the object which may be // // used by other clients in our system // InstanceInfo copy = new InstanceInfo(ii); // // if (isSecure) { // ii = new // InstanceInfo.Builder(copy).setSecurePort(overridePort).build(); // } else { // ii = new InstanceInfo.Builder(copy).setPort(overridePort).build(); // } // } // // DiscoveryEnabledServer des = new DiscoveryEnabledServer(ii, isSecure, // shouldUseIpAddr); // des.setZone(DiscoveryClient.getZone(ii)); // serverList.add(des); // } // } // if (serverList.size() > 0 && prioritizeVipAddressBasedServers) { // break; // if the current vipAddress has servers, we dont use // // subsequent vipAddress based servers // } // } // } Application application = discoveryClient.getApplication(clientName); if (application == null) { logger.error(clientName + "服务未找到"); } else { for (InstanceInfo ii : application.getInstances()) { if (ii.getStatus() == InstanceStatus.UP) { if (shouldUseOverridePort) { if (logger.isDebugEnabled()) { logger.debug("Overriding port on client name: " + clientName + " to " + overridePort); } // copy is necessary since the InstanceInfo builder // just uses the original reference, // and we don't want to corrupt the global eureka // copy of the object which may be // used by other clients in our system InstanceInfo copy = new InstanceInfo(ii); if (isSecure) { ii = new InstanceInfo.Builder(copy).setSecurePort(overridePort).build(); } else { ii = new InstanceInfo.Builder(copy).setPort(overridePort).build(); } } DiscoveryEnabledServer des = new DiscoveryEnabledServer(ii, isSecure, shouldUseIpAddr); des.setZone(DiscoveryClient.getZone(ii)); serverList.add(des); } } } return serverList; }
Example #21
Source File: EurekaHandler.java From riposte with Apache License 2.0 | 4 votes |
@SuppressWarnings("deprecation") protected void shutdownDiscoveryManager() { DiscoveryManager.getInstance().shutdownComponent(); }
Example #22
Source File: DiscoveryEnabledLoadBalancerSupportsPortOverrideTest.java From ribbon with Apache License 2.0 | 4 votes |
@Before public void setupMock(){ List<InstanceInfo> dummyII = LoadBalancerTestUtils.getDummyInstanceInfo("dummy", "http://www.host.com", "1.1.1.1", 8001); List<InstanceInfo> secureDummyII = LoadBalancerTestUtils.getDummyInstanceInfo("secureDummy", "http://www.host.com", "1.1.1.1", 8002); PowerMock.mockStatic(DiscoveryManager.class); PowerMock.mockStatic(DiscoveryClient.class); DiscoveryClient mockedDiscoveryClient = LoadBalancerTestUtils.mockDiscoveryClient(); DiscoveryManager mockedDiscoveryManager = createMock(DiscoveryManager.class); expect(DiscoveryManager.getInstance()).andReturn(mockedDiscoveryManager).anyTimes(); expect(mockedDiscoveryManager.getDiscoveryClient()).andReturn(mockedDiscoveryClient).anyTimes(); expect(mockedDiscoveryClient.getInstancesByVipAddress("dummy", false, "region")).andReturn(dummyII).anyTimes(); expect(mockedDiscoveryClient.getInstancesByVipAddress("secureDummy", true, "region")).andReturn(secureDummyII).anyTimes(); replay(DiscoveryManager.class); replay(DiscoveryClient.class); replay(mockedDiscoveryManager); replay(mockedDiscoveryClient); }
Example #23
Source File: DiscoveryEnabledLoadBalancerSupportsUseIpAddrTest.java From ribbon with Apache License 2.0 | 4 votes |
@After public void afterMock(){ verify(DiscoveryManager.class); verify(DiscoveryClient.class); }
Example #24
Source File: EurekaHandler.java From riposte with Apache License 2.0 | 4 votes |
@SuppressWarnings("deprecation") protected void initDiscoveryManager(EurekaInstanceConfig eurekaInstanceConfig, EurekaClientConfig eurekaClientConfig) { DiscoveryManager.getInstance().initComponent(eurekaInstanceConfig, eurekaClientConfig); }
Example #25
Source File: EurekaConfiguration.java From chassis with Apache License 2.0 | 4 votes |
/*** * Initializes Eureka Client Library (aka DiscoveryManager) * * @return discovery manager bean */ @Bean(destroyMethod = "shutdownComponent") public DiscoveryManager eurekaDiscoveryManager(MetadataCollector metadataCollector) { final DiscoveryManager bean = DiscoveryManager.getInstance(); if (!disableEureka) { // set eureka.port via http.port if not already set int httpPort = ConfigurationManager.getConfigInstance().getInt("http.port",-1); int httpsPort = ConfigurationManager.getConfigInstance().getInt("https.port",-1); int eurekaPort = ConfigurationManager.getConfigInstance().getInt("eureka.port",-1); int eurekaSecurePort = ConfigurationManager.getConfigInstance().getInt("eureka.securePort",-1); boolean httpPortEnabled = ConfigurationManager.getConfigInstance().getBoolean("http.enabled", false); boolean httpsPortEnabled = ConfigurationManager.getConfigInstance().getBoolean("https.enabled", false); if (httpPort != -1 && eurekaPort == -1) { ConfigurationManager.getConfigInstance().setProperty("eureka.port", httpPort); ConfigurationManager.getConfigInstance().setProperty("eureka.port.enabled", httpPortEnabled); } if(httpsPort != -1 && eurekaSecurePort == -1){ ConfigurationManager.getConfigInstance().setProperty("eureka.securePort", httpsPort); ConfigurationManager.getConfigInstance().setProperty("eureka.securePort.enabled", httpsPortEnabled); } // set eureka.name and eureka.vipAddress with @SpringApp name if not already set String appName = ConfigurationManager.getConfigInstance().getString("app.name",null); String eurekaName = ConfigurationManager.getConfigInstance().getString("eureka.name",null); String eurekaVip = ConfigurationManager.getConfigInstance().getString("eureka.vipAddress",null); String eurekaSecureVipAddress = ConfigurationManager.getConfigInstance().getString("eureka.secureVipAddress",null); if (appName != null && eurekaName == null) { ConfigurationManager.getConfigInstance().setProperty("eureka.name", appName); } if (appName != null && eurekaVip == null) { ConfigurationManager.getConfigInstance().setProperty("eureka.vipAddress", appName); } if (appName != null && eurekaSecureVipAddress == null) { ConfigurationManager.getConfigInstance().setProperty("eureka.secureVipAddress", appName); } // initialize DiscoveryManager if it hasn't already been done if (ApplicationInfoManager.getInstance().getInfo() == null) { EurekaInstanceConfig config; switch (datacenter.toLowerCase()) { case "amazon": case "cloud": config = new KixeyeCloudInstanceConfig(metadataCollector); break; default: config = new KixeyeMyDataCenterInstanceConfig(metadataCollector); break; } bean.initComponent(config, new DefaultEurekaClientConfig()); } } return bean; }
Example #26
Source File: SampleEurekaRibbonClient.java From hippo with Apache License 2.0 | 4 votes |
public void unRegisterWithEureka() { DiscoveryManager.getInstance().shutdownComponent(); }