com.netflix.discovery.EurekaEvent Java Examples

The following examples show how to use com.netflix.discovery.EurekaEvent. 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: EurekaContainerHealthService.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Inject
public EurekaContainerHealthService(ReadOnlyJobOperations jobOperations, EurekaClient eurekaClient, TitusRuntime titusRuntime) {
    this.jobOperations = jobOperations;
    this.eurekaClient = eurekaClient;
    this.titusRuntime = titusRuntime;

    Flux<EurekaEvent> eurekaCallbacks = ReactorExt.fromListener(
            EurekaEventListener.class,
            eurekaClient::registerEventListener,
            eurekaClient::unregisterEventListener
    );

    this.healthStatuses = Flux.defer(() -> {
        ConcurrentMap<String, ContainerHealthEvent> current = new ConcurrentHashMap<>();
        return Flux.merge(eurekaCallbacks, ReactorExt.toFlux(jobOperations.observeJobs()))
                .flatMap(event -> handleJobManagerOrEurekaStatusUpdate(event, current));
    }).share().compose(ReactorExt.badSubscriberHandler(logger));

}
 
Example #2
Source File: EurekaClientEventListener.java    From mPaaS with Apache License 2.0 5 votes vote down vote up
@Override
    public void onEvent(EurekaEvent event) {
//		if(event instanceof CacheRefreshedEvent) {
//			log.info("触发刷新缓存事件[{}]", ((CacheRefreshedEvent) event).getTimestamp());
//		}else if(event instanceof StatusChangeEvent) {
//			log.info("触发状态变更事件,之前状态[{}],当前状态[{}]", ((StatusChangeEvent) event).getPreviousStatus(), ((StatusChangeEvent) event).getStatus());
//		}else {
//			log.info("触发EurekaEvent事件[{}]", event.getClass());
//		}
    }
 
Example #3
Source File: EurekaClientEventListener.java    From summerframework with Apache License 2.0 5 votes vote down vote up
@Override
public void onEvent(EurekaEvent event) {
    if (event instanceof CacheRefreshedEvent) {
        publisher.publishEvent(new EurekaClientLocalCacheRefreshedEvent((CacheRefreshedEvent)event));
    } else if (event instanceof StatusChangeEvent) {
        publisher.publishEvent(new EurekaClientStatusChangeEvent((StatusChangeEvent)event));
    }
}
 
Example #4
Source File: ServiceCacheEvictor.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public synchronized void onEvent(EurekaEvent event) {
    if (event instanceof CacheRefreshedEvent) {
        if (!evictAll && toEvict.isEmpty()) return;
        if (evictAll) {
            serviceCacheEvicts.forEach(ServiceCacheEvict::evictCacheAllService);
            loadBalancerRegistry.values().forEach(DynamicServerListLoadBalancer::updateListOfServers);
            evictAll = false;
        } else {
            toEvict.forEach(ServiceRef::evict);
            toEvict.clear();
        }
        loadBalancerRegistry.values().forEach(DynamicServerListLoadBalancer::updateListOfServers);
    }
}
 
Example #5
Source File: RibbonMetadataProcessorTest.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Test
void givenMockedEvent_whenOnEvent_thenCallProcess() {
    EurekaEvent event = mock(EurekaEvent.class);
    MetadataProcessor metadataProcessor = new RibbonMetadataProcessor(mock(EurekaApplications.class));
    MetadataProcessor spyProcessor = spy(metadataProcessor);
    spyProcessor.onEvent(event);

    verify(spyProcessor, times(1)).process(any());
}
 
Example #6
Source File: EurekaContainerHealthService.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
private Flux<ContainerHealthEvent> handleJobManagerOrEurekaStatusUpdate(Object event, ConcurrentMap<String, ContainerHealthEvent> state) {
    if (event instanceof JobManagerEvent) {
        return handleJobManagerEvent((JobManagerEvent) event, state);
    }
    if (event instanceof EurekaEvent) {
        return handleEurekaEvent((EurekaEvent) event, state);
    }
    return Flux.empty();
}
 
Example #7
Source File: EurekaContainerHealthService.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
private Flux<ContainerHealthEvent> handleEurekaEvent(EurekaEvent event, ConcurrentMap<String, ContainerHealthEvent> state) {
    if (!(event instanceof CacheRefreshedEvent)) {
        return Flux.empty();
    }

    List<Pair<Job, List<Task>>> allJobsAndTasks = jobOperations.getJobsAndTasks();
    List<Task> allTasks = new ArrayList<>();
    List<ContainerHealthEvent> events = new ArrayList<>();

    allJobsAndTasks.forEach(jobAndTasks -> {
        jobAndTasks.getRight().forEach(task -> {
            handleTaskStateUpdate(jobAndTasks.getLeft(), task, state).ifPresent(events::add);
            allTasks.add(task);
        });
    });

    // Cleanup, in case we have stale entries.
    Set<String> unknownTaskIds = CollectionsExt.copyAndRemove(state.keySet(), allTasks.stream().map(Task::getId).collect(Collectors.toSet()));
    unknownTaskIds.forEach(taskId -> {
        state.remove(taskId);

        // Assume the task was terminated.
        ContainerHealthStatus terminatedStatus = ContainerHealthStatus.newBuilder()
                .withTaskId(taskId)
                .withTimestamp(titusRuntime.getClock().wallTime())
                .withState(ContainerHealthState.Terminated)
                .withReason("terminated")
                .build();

        events.add(ContainerHealthUpdateEvent.healthChanged(terminatedStatus));
    });

    return Flux.fromIterable(events);
}
 
Example #8
Source File: EurekaServerListProcessor.java    From spring-cloud-gray with Apache License 2.0 4 votes vote down vote up
@Override
public void onEvent(EurekaEvent event) {
    log.debug("接收到eureka事件:{}, 刷新缓存的server list", event);
    reload();
}
 
Example #9
Source File: MetadataProcessor.java    From api-layer with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void onEvent(EurekaEvent event) {
    process(getApplications());
}
 
Example #10
Source File: EurekaAgentStatusMonitor.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
@Override
public void onEvent(EurekaEvent event) {
    if (event instanceof CacheRefreshedEvent) {
        refreshAgentDiscoveryStatus();
    }
}
 
Example #11
Source File: EurekaHostCallerIdResolver.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
@Override
public void onEvent(EurekaEvent event) {
    if (event instanceof CacheRefreshedEvent) {
        refreshAddressCache();
    }
}
 
Example #12
Source File: SingleServiceLoadBalancer.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
@Override
public void onEvent(EurekaEvent event) {
    if (event instanceof CacheRefreshedEvent) {
        refresh();
    }
}
 
Example #13
Source File: RefreshEurekaServersListener.java    From onetwo with Apache License 2.0 4 votes vote down vote up
protected void refreshServerList(final EurekaEvent event) {
//        ReflectUtils.invokeMethod("fireEvent", discoveryClient, event);
    }