com.netflix.appinfo.InstanceInfo.InstanceStatus Java Examples
The following examples show how to use
com.netflix.appinfo.InstanceInfo.InstanceStatus.
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: EurekaHandlerTest.java From riposte with Apache License 2.0 | 6 votes |
@Before public void beforeMethod() { eurekaIsDisabledPropertySupplierMock = mock(Supplier.class); datacenterTypePropertySupplierMock = mock(Supplier.class); cloudInstanceConfigMock = mock(CloudInstanceConfig.class); doReturn(false).when(eurekaIsDisabledPropertySupplierMock).get(); doReturn(MyOwn.name()).when(datacenterTypePropertySupplierMock).get(); handlerSpy = spy(new EurekaHandler(eurekaIsDisabledPropertySupplierMock, datacenterTypePropertySupplierMock)); doNothing().when(handlerSpy).initDiscoveryManager(any(EurekaInstanceConfig.class), any(EurekaClientConfig.class)); doNothing().when(handlerSpy).shutdownDiscoveryManager(); doNothing().when(handlerSpy).setEurekaInstanceStatus(any(InstanceStatus.class)); doReturn(cloudInstanceConfigMock).when(handlerSpy).createCloudInstanceConfig(anyString()); }
Example #2
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 #3
Source File: EurekaContainerHealthServiceTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Test public void testEurekaUpdate() { jobManagerStub.moveTaskToState(taskId1, TaskState.Started); StepVerifier.create(healthService.events(false)) // Change state to UP .then(() -> registerAndRefresh(InstanceStatus.UP)) .assertNext(event -> assertContainerHealthAndEvent(event, healthService.getHealthStatus(taskId1), taskId1, ContainerHealthState.Healthy)) // Change state to DOWN .then(() -> registerAndRefresh(InstanceStatus.DOWN)) .assertNext(event -> assertContainerHealthAndEvent(event, healthService.getHealthStatus(taskId1), taskId1, ContainerHealthState.Unhealthy)) .thenCancel() .verify(Duration.ofSeconds(5)); }
Example #4
Source File: RestTemplateEurekaHttpClient.java From spring-cloud-netflix with Apache License 2.0 | 6 votes |
@Override public EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id, InstanceInfo info, InstanceStatus overriddenStatus) { String urlPath = serviceUrl + "apps/" + appName + '/' + id + "?status=" + info.getStatus().toString() + "&lastDirtyTimestamp=" + info.getLastDirtyTimestamp().toString() + (overriddenStatus != null ? "&overriddenstatus=" + overriddenStatus.name() : ""); ResponseEntity<InstanceInfo> response = restTemplate.exchange(urlPath, HttpMethod.PUT, null, InstanceInfo.class); EurekaHttpResponseBuilder<InstanceInfo> eurekaResponseBuilder = anEurekaHttpResponse( response.getStatusCodeValue(), InstanceInfo.class) .headers(headersOf(response)); if (response.hasBody()) { eurekaResponseBuilder.entity(response.getBody()); } return eurekaResponseBuilder.build(); }
Example #5
Source File: EurekaRegisterHandler.java From TarsJava with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public List<EndpointF> query(String name) { name = normalObjName(name); if (name == null) { return null; } Application application = client.getApplication(name); List<EndpointF> results = new ArrayList<EndpointF>(); if (application == null) { return results; } for (InstanceInfo instanceInfo : application.getInstances()) { if (instanceInfo.getStatus() != InstanceStatus.UP) { continue; } EndpointF endpoint = convert2Endpoint(instanceInfo); if (endpoint != null) { results.add(endpoint); } } return results; }
Example #6
Source File: WebClientEurekaHttpClient.java From spring-cloud-netflix with Apache License 2.0 | 6 votes |
@Override public EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id, InstanceInfo info, InstanceStatus overriddenStatus) { String urlPath = "apps/" + appName + '/' + id + "?status=" + info.getStatus().toString() + "&lastDirtyTimestamp=" + info.getLastDirtyTimestamp().toString() + (overriddenStatus != null ? "&overriddenstatus=" + overriddenStatus.name() : ""); ClientResponse response = webClient.put().uri(urlPath, InstanceInfo.class) .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE).exchange() .block(); EurekaHttpResponseBuilder<InstanceInfo> builder = anEurekaHttpResponse( statusCodeValueOf(response), InstanceInfo.class) .headers(headersOf(response)); InstanceInfo entity = response.toEntity(InstanceInfo.class).block().getBody(); if (entity != null) { builder.entity(entity); } return builder.build(); }
Example #7
Source File: EurekaAgentStatusMonitorTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Test public void testEurekaRegistrationChangesTriggerStatusUpdateInEventStream() { ExtTestSubscriber<AgentStatus> testSubscriber = new ExtTestSubscriber<>(); monitor.monitor().subscribe(testSubscriber); // UP mockStatusInEureka(instance, InstanceStatus.UP); assertThat(testSubscriber.takeNext().getStatusCode()).isEqualTo(AgentStatusCode.Healthy); // DOWN mockStatusInEureka(instance, InstanceStatus.DOWN); assertThat(testSubscriber.takeNext().getStatusCode()).isEqualTo(AgentStatusCode.Unhealthy); // Back to UP mockStatusInEureka(instance, InstanceStatus.UP); assertThat(testSubscriber.takeNext().getStatusCode()).isEqualTo(AgentStatusCode.Healthy); }
Example #8
Source File: ChassisConfiguration.java From chassis with Apache License 2.0 | 6 votes |
@Override public void onApplicationEvent(ApplicationEvent event) { //we only want to tell Eureka that the application is up //when the root application context (thisApplicationContext) has //been fully started. we want to ignore any ContextRefreshedEvent //from child application contexts. if (!event.getSource().equals(thisApplicationContext)) { return; } if (event instanceof ContextRefreshedEvent) { if (!disableEureka) { // tell Eureka the server UP which in turn starts the health checks and heartbeat ApplicationInfoManager.getInstance().setInstanceStatus(InstanceStatus.UP); } } else if (event instanceof ContextClosedEvent) { if (!disableEureka) { ApplicationInfoManager.getInstance().setInstanceStatus(InstanceStatus.DOWN); } } }
Example #9
Source File: EurekaContainerHealthServiceTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Test public void testJobManagerUpdate() { StepVerifier.create(healthService.events(false)) // Task launched, but not in Eureka yet. .then(() -> jobManagerStub.moveTaskToState(taskId1, TaskState.Launched)) .assertNext(event -> assertContainerHealthAndEvent(event, healthService.getHealthStatus(taskId1), taskId1, ContainerHealthState.Unknown)) // Task started and registered with Eureka .then(() -> { eurekaServer.register(newInstanceInfo(taskId1, InstanceStatus.UP)); jobManagerStub.moveTaskToState(taskId1, TaskState.Started); }) .assertNext(event -> assertContainerHealthAndEvent(event, healthService.getHealthStatus(taskId1), taskId1, ContainerHealthState.Healthy)) // Task terminated .then(() -> jobManagerStub.moveTaskToState(task1, TaskState.Finished)) .assertNext(event -> assertContainerHealthAndEvent(event, healthService.getHealthStatus(taskId1), taskId1, ContainerHealthState.Terminated)) .thenCancel() .verify(Duration.ofSeconds(5)); }
Example #10
Source File: EurekaContainerHealthServiceTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Test public void testEurekaReRegistration() { jobManagerStub.moveTaskToState(taskId1, TaskState.Started); StepVerifier.create(healthService.events(false)) // Change state to UP .then(() -> registerAndRefresh(InstanceStatus.UP)) .assertNext(event -> assertContainerHealthAndEvent(event, healthService.getHealthStatus(taskId1), taskId1, ContainerHealthState.Healthy)) // Unregister in Eureka .then(() -> { eurekaServer.unregister(taskId1); eurekaServer.triggerCacheRefreshUpdate(); }) .assertNext(event -> assertContainerHealthAndEvent(event, healthService.getHealthStatus(taskId1), taskId1, ContainerHealthState.Unknown)) // Register again .then(() -> registerAndRefresh(InstanceStatus.UP)) .assertNext(event -> assertContainerHealthAndEvent(event, healthService.getHealthStatus(taskId1), taskId1, ContainerHealthState.Healthy)) .thenCancel() .verify(Duration.ofSeconds(5)); }
Example #11
Source File: EurekaContainerHealthServiceTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Test public void testEurekaStaleDataCleanup() { jobManagerStub.moveTaskToState(taskId1, TaskState.Started); StepVerifier.create(healthService.events(false)) // Start the task and register with Eureka .then(() -> registerAndRefresh(InstanceStatus.UP)) .assertNext(event -> assertContainerHealthEvent(event, taskId1, ContainerHealthState.Healthy)) // Lose task .then(() -> { jobManagerStub.forget(task1); eurekaServer.triggerCacheRefreshUpdate(); }) .assertNext(event -> { assertContainerHealthEvent(event, taskId1, ContainerHealthState.Terminated); assertThat(healthService.findHealthStatus(taskId1)).isEmpty(); }) .thenCancel() .verify(Duration.ofSeconds(5)); }
Example #12
Source File: ArmeriaEurekaClientTest.java From armeria with Apache License 2.0 | 6 votes |
private static com.linecorp.armeria.internal.common.eureka.InstanceInfo convertInstanceInfo( InstanceInfo info) { final PortWrapper port = new PortWrapper(info.isPortEnabled(PortType.UNSECURE), info.getPort()); final PortWrapper securePort = new PortWrapper(info.isPortEnabled(PortType.SECURE), info.getSecurePort()); return new com.linecorp.armeria.internal.common.eureka.InstanceInfo( info.getInstanceId(), info.getAppName(), info.getAppGroupName(), info.getHostName(), info.getIPAddr(), info.getVIPAddress(), info.getSecureVipAddress(), port, securePort, com.linecorp.armeria.internal.common.eureka.InstanceInfo.InstanceStatus .toEnum(info.getStatus().name()), info.getHomePageUrl(), info.getStatusPageUrl(), info.getHealthCheckUrl(), info.getSecureHealthCheckUrl(), convertDataCenterInfo(info.getDataCenterInfo()), convertLeaseInfo(info.getLeaseInfo()), info.getMetadata()); }
Example #13
Source File: EurekaEndpointGroupTest.java From armeria with Apache License 2.0 | 6 votes |
@Override protected void configure(ServerBuilder sb) throws Exception { final AtomicInteger requestCounter = new AtomicInteger(); sb.service("/apps", (ctx, req) -> { final int count = requestCounter.getAndIncrement(); if (count == 0) { // This is for the test that EurekaUpdatingListener automatically retries when // RetryingClient is not used. return HttpResponse.of(HttpStatus.INTERNAL_SERVER_ERROR); } final Applications apps = InstanceInfoGenerator.newBuilder(6, 2).build().toApplications(); apps.getRegisteredApplications().get(0).getInstances().get(0).setStatus(InstanceStatus.DOWN); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); encoder.encode(apps, bos); return HttpResponse.of(HttpStatus.OK, MediaType.JSON_UTF_8, bos.toByteArray()); }); }
Example #14
Source File: ExtEurekaController.java From onetwo with Apache License 2.0 | 6 votes |
@RequestMapping(path="instance", method = RequestMethod.POST) public String instance(@RequestParam String instId, InstanceStatus status, Map<String, Object> model) { Optional<InstanceInfo> inst = InstanceInfoMeta.findInstanceInfoById(instId); if (!inst.isPresent()) { model.put("message", "找不到实例:" + instId); return "cloud/message"; } /* String url = buildRemoveUrl(inst.get()); StringDataResult result = this.restTemplate.post(url, null, MediaType.APPLICATION_JSON_UTF8, StringDataResult.class); if (result.isError()) { model.put("message", "移除实例错误:" + result.getMessage()); return "cloud/error"; }*/ inst.get().setStatus(status); model.put("message", "实例["+instId+"]上线成功!"); return admin(request, model); }
Example #15
Source File: EurekaHandlerTest.java From riposte with Apache License 2.0 | 6 votes |
@DataProvider(value = { "true", "false" }) @Test public void markAsUp_sets_instance_status_to_up_only_if_eureka_is_enabled( boolean eurekaDisabled ) { // given doReturn(eurekaDisabled).when(eurekaIsDisabledPropertySupplierMock).get(); // when handlerSpy.markAsUp(); // then if (eurekaDisabled) verify(handlerSpy, never()).setEurekaInstanceStatus(any(InstanceStatus.class)); else verify(handlerSpy).setEurekaInstanceStatus(InstanceStatus.UP); }
Example #16
Source File: EurekaHandlerTest.java From riposte with Apache License 2.0 | 6 votes |
@Test public void register_uses_createEurekaInstanceConfig_then_calls_initDiscoveryManager_with_it_and_sets_instance_status_UP() { // given EurekaInstanceConfig instanceConfigMock = mock(EurekaInstanceConfig.class); doReturn(instanceConfigMock).when(handlerSpy).createEurekaInstanceConfig(); assertThat(handlerSpy.registered.get()).isFalse(); // when handlerSpy.register(); // then assertThat(handlerSpy.registered.get()).isTrue(); verify(handlerSpy).createEurekaInstanceConfig(); ArgumentCaptor<EurekaClientConfig> clientConfigCaptor = ArgumentCaptor.forClass(EurekaClientConfig.class); verify(handlerSpy).initDiscoveryManager(eq(instanceConfigMock), clientConfigCaptor.capture()); EurekaClientConfig clientConfigUsed = clientConfigCaptor.getValue(); assertThat(clientConfigUsed).isInstanceOf(DefaultEurekaClientConfig.class); assertThat(Whitebox.getInternalState(clientConfigUsed, "namespace")).isEqualTo(handlerSpy.eurekaClientNamespace); verify(handlerSpy).setEurekaInstanceStatus(InstanceStatus.UP); }
Example #17
Source File: EurekaHealthCheckHandlerTests.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
@Test public void testAllUp() throws Exception { initialize(UpHealthConfiguration.class); InstanceStatus status = healthCheckHandler.getStatus(InstanceStatus.UNKNOWN); assertThat(status).isEqualTo(InstanceStatus.UP); }
Example #18
Source File: ArmeriaEurekaClientTest.java From armeria with Apache License 2.0 | 5 votes |
@Override public EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id, InstanceInfo info, @Nullable InstanceStatus overriddenStatus) { return convertResponse(delegate.sendHeartBeat( appName, id, convertInstanceInfo(info), overriddenStatus == null ? null : com.linecorp.armeria.internal.common.eureka.InstanceInfo.InstanceStatus .toEnum(overriddenStatus.name())), InstanceInfo.class); }
Example #19
Source File: EurekaHandlerTest.java From riposte with Apache License 2.0 | 5 votes |
@Test public void register_does_nothing_if_already_registered() { // given handlerSpy.registered.set(true); // when handlerSpy.register(); // then verify(handlerSpy, never()).createEurekaInstanceConfig(); verify(handlerSpy, never()).initDiscoveryManager(any(EurekaInstanceConfig.class), any(EurekaClientConfig.class)); verify(handlerSpy, never()).setEurekaInstanceStatus(any(InstanceStatus.class)); }
Example #20
Source File: RestTemplateEurekaHttpClient.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
@Override public EurekaHttpResponse<Void> statusUpdate(String appName, String id, InstanceStatus newStatus, InstanceInfo info) { String urlPath = serviceUrl + "apps/" + appName + '/' + id + "/status?value=" + newStatus.name() + "&lastDirtyTimestamp=" + info.getLastDirtyTimestamp().toString(); ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.PUT, null, Void.class); return anEurekaHttpResponse(response.getStatusCodeValue()) .headers(headersOf(response)).build(); }
Example #21
Source File: EurekaInterestManagerTest.java From ocelli with Apache License 2.0 | 5 votes |
InstanceInfo createInstance(int id) { return InstanceInfo.Builder.newBuilder() .setHostName("localhost:800" + id) .setAppName("foo") .setStatus(InstanceStatus.UP) .build(); }
Example #22
Source File: WebClientEurekaHttpClient.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
@Override public EurekaHttpResponse<Void> statusUpdate(String appName, String id, InstanceStatus newStatus, InstanceInfo info) { String urlPath = "apps/" + appName + '/' + id + "/status?value=" + newStatus.name() + "&lastDirtyTimestamp=" + info.getLastDirtyTimestamp().toString(); return webClient.put().uri(urlPath, Void.class) .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .exchange().map(response -> eurekaHttpResponse(response)).block(); }
Example #23
Source File: EurekaHostsSupplier.java From dyno with Apache License 2.0 | 5 votes |
private List<Host> getUpdateFromEureka() { if (discoveryClient == null) { Logger.error("Discovery client cannot be null"); throw new RuntimeException("EurekaHostsSupplier needs a non-null DiscoveryClient"); } Logger.info("Dyno fetching instance list for app: " + applicationName); Application app = discoveryClient.getApplication(applicationName); List<Host> hosts = new ArrayList<Host>(); if (app == null) { return hosts; } List<InstanceInfo> ins = app.getInstances(); if (ins == null || ins.isEmpty()) { return hosts; } hosts = Lists.newArrayList(Collections2.transform(ins, info -> { Host.Status status = info.getStatus() == InstanceStatus.UP ? Host.Status.Up : Host.Status.Down; String rack = null; try { if (info.getDataCenterInfo() instanceof AmazonInfo) { AmazonInfo amazonInfo = (AmazonInfo) info.getDataCenterInfo(); rack = amazonInfo.get(MetaDataKey.availabilityZone); } } catch (Throwable t) { Logger.error("Error getting rack for host " + info.getHostName(), t); } if (rack == null) { Logger.error("Rack wasn't found for host:" + info.getHostName() + " there may be issues matching it up to the token map"); } Host host = new HostBuilder().setHostname(info.getHostName()).setIpAddress(info.getIPAddr()).setRack(rack).setStatus(status).createHost(); return host; })); Logger.info("Dyno found hosts from eureka - num hosts: " + hosts.size()); return hosts; }
Example #24
Source File: EurekaHealthCheckHandlerTests.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
@Test public void testUnknown() throws Exception { initialize(FatalHealthConfiguration.class); InstanceStatus status = healthCheckHandler.getStatus(InstanceStatus.UNKNOWN); assertThat(status).isEqualTo(InstanceStatus.UNKNOWN); }
Example #25
Source File: EurekaStatusApplicationEventPublisher.java From spring-cloud-netflix-contrib with Apache License 2.0 | 5 votes |
@Scheduled(fixedDelay = 3000L) public void checkDiscovery() { InstanceStatus latestStatus = discoveryClient.getInstanceRemoteStatus(); if(!latestStatus.equals(currentStatus)) { this.currentStatus = latestStatus; publisher.publishEvent(new EurekaStatusChangedEvent(latestStatus)); } }
Example #26
Source File: EurekaHealthCheckHandlerTests.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
@Test @Ignore // FIXME: 3.0.0 public void testEurekaIgnored() throws Exception { initialize(EurekaDownHealthConfiguration.class); InstanceStatus status = healthCheckHandler.getStatus(InstanceStatus.UP); assertThat(status).isEqualTo(InstanceStatus.UP); }
Example #27
Source File: EurekaRegisterHandler.java From TarsJava with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void close() { if (applicationInfoManager.getInfo() != null) { applicationInfoManager.setInstanceStatus(InstanceStatus.DOWN); } if (client != null) { client.shutdown(); } client = null; }
Example #28
Source File: EurekaHandlerTest.java From riposte with Apache License 2.0 | 5 votes |
@Test public void register_does_nothing_if_eureka_is_disabled() { // given doReturn(true).when(eurekaIsDisabledPropertySupplierMock).get(); // when handlerSpy.register(); // then verify(handlerSpy, never()).createEurekaInstanceConfig(); verify(handlerSpy, never()).initDiscoveryManager(any(EurekaInstanceConfig.class), any(EurekaClientConfig.class)); verify(handlerSpy, never()).setEurekaInstanceStatus(any(InstanceStatus.class)); }
Example #29
Source File: EurekaInstanceConfigBeanTests.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
@Test public void testCustomInitialStatus() { TestPropertyValues.of("eureka.instance.initial-status:STARTING") .applyTo(this.context); setupContext(); assertThat(getInstanceConfig().getInitialStatus()).as("initialStatus wrong") .isEqualTo(InstanceStatus.STARTING); }
Example #30
Source File: EurekaHealthCheckHandlerTests.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
@Test public void testDown() throws Exception { initialize(UpHealthConfiguration.class, DownHealthConfiguration.class); InstanceStatus status = healthCheckHandler.getStatus(InstanceStatus.UNKNOWN); assertThat(status).isEqualTo(InstanceStatus.DOWN); }