private boolean isReplicaAvailable(String url) { try { Application app = registry.getApplication(myAppName, false); if (app == null) { return false; } for (InstanceInfo info : app.getInstances()) { if (peerEurekaNodes.isInstanceURL(url, info)) { return true; } } } catch (Throwable e) { logger.error("Could not determine if the replica is available ", e); } return false; } }
@Override public void run() { boolean isEIPBound = false; try { isEIPBound = isEIPBound(); // If the EIP is not bound, the registry could be stale. First sync up the registry from the // neighboring node before trying to bind the EIP if (!isEIPBound) { registry.clearRegistry(); int count = registry.syncUp(); registry.openForTraffic(applicationInfoManager, count); } else { // An EIP is already bound return; } bindEIP(); } catch (Throwable e) { logger.error("Could not bind to EIP", e); } finally { if (isEIPBound) { timer.schedule(new EIPBindingTask(), serverConfig.getEIPBindingRetryIntervalMs()); } else { timer.schedule(new EIPBindingTask(), serverConfig.getEIPBindingRetryIntervalMsWhenUnbound()); } } } };
@Test public void testInvalidateWithRemoteRegion() throws Exception { ResponseCacheImpl cache = (ResponseCacheImpl) testRegistry.getResponseCache(); Key key = new Key( Key.EntityType.Application, REMOTE_REGION_APP_NAME, Key.KeyType.JSON, Version.V1, EurekaAccept.full, new String[]{REMOTE_REGION} ); Assert.assertNotNull("Cache get returned null.", cache.get(key, false)); testRegistry.cancel(REMOTE_REGION_APP_NAME, REMOTE_REGION_INSTANCE_1_HOSTNAME, true); Assert.assertNull("Cache after invalidate did not return null.", cache.get(key)); }
public Response updateMetadata(@Context UriInfo uriInfo) { try { InstanceInfo instanceInfo = registry.getInstanceByAppAndId(app.getName(), id); metadataMap.put(entry.getKey(), entry.getValue().get(0)); registry.register(instanceInfo, false); return Response.ok().build(); } catch (Throwable e) {
@QueryParam("lastDirtyTimestamp") String lastDirtyTimestamp) { try { if (registry.getInstanceByAppAndId(app.getName(), id) == null) { logger.warn("Instance not found: {}/{}", app.getName(), id); return Response.status(Status.NOT_FOUND).build(); boolean isSuccess = registry.deleteStatusOverride(app.getName(), id, newStatus, lastDirtyTimestamp, "true".equals(isReplication));
int registryCount = registry.syncUp(); registry.openForTraffic(applicationInfoManager, registryCount);
@Override @Before public void setUp() throws Exception { super.setUp(); // create a new registry that is sync'ed up with the default registry in the AbstractTester, // but disable transparent fetch to the remote for gets EurekaServerConfig serverConfig = spy(new DefaultEurekaServerConfig()); doReturn(true).when(serverConfig).disableTransparentFallbackToOtherRegion(); testRegistry = new PeerAwareInstanceRegistryImpl( serverConfig, new DefaultEurekaClientConfig(), new DefaultServerCodecs(serverConfig), client ); testRegistry.init(serverContext.getPeerEurekaNodes()); testRegistry.syncUp(); }
ApplicationResource(String appName, EurekaServerConfig serverConfig, PeerAwareInstanceRegistry registry) { this.appName = appName.toUpperCase(); this.serverConfig = serverConfig; this.registry = registry; this.responseCache = registry.getResponseCache(); }
/** * Get requests returns the information about the instance's * {@link InstanceInfo}. * * @return response containing information about the the instance's * {@link InstanceInfo}. */ @GET public Response getInstanceInfo() { InstanceInfo appInfo = registry .getInstanceByAppAndId(app.getName(), id); if (appInfo != null) { logger.debug("Found: {} - {}", app.getName(), id); return Response.ok(appInfo).build(); } else { logger.debug("Not Found: {} - {}", app.getName(), id); return Response.status(Status.NOT_FOUND).build(); } }
/** * Synchronize {@link InstanceInfo} information if the timestamp between * this node and the peer eureka nodes vary. */ private void syncInstancesIfTimestampDiffers(String appName, String id, InstanceInfo info, InstanceInfo infoFromPeer) { try { if (infoFromPeer != null) { logger.warn("Peer wants us to take the instance information from it, since the timestamp differs," + "Id : {} My Timestamp : {}, Peer's timestamp: {}", id, info.getLastDirtyTimestamp(), infoFromPeer.getLastDirtyTimestamp()); if (infoFromPeer.getOverriddenStatus() != null && !InstanceStatus.UNKNOWN.equals(infoFromPeer.getOverriddenStatus())) { logger.warn("Overridden Status info -id {}, mine {}, peer's {}", id, info.getOverriddenStatus(), infoFromPeer.getOverriddenStatus()); registry.storeOverriddenStatusIfRequired(appName, id, infoFromPeer.getOverriddenStatus()); } registry.register(infoFromPeer, true); } } catch (Throwable e) { logger.warn("Exception when trying to set information from peer :", e); } }
@QueryParam("lastDirtyTimestamp") String lastDirtyTimestamp) { try { if (registry.getInstanceByAppAndId(app.getName(), id) == null) { logger.warn("Instance not found: {}/{}", app.getName(), id); return Response.status(Status.NOT_FOUND).build(); boolean isSuccess = registry.statusUpdate(app.getName(), id, InstanceStatus.valueOf(newStatus), lastDirtyTimestamp, "true".equals(isReplication));
@Override public List<Snitch> getAll() { // @formatter:off return eurekaServerContext.getRegistry().getSortedApplications().stream() .map(Application::getInstances) .flatMap(Collection::stream) .map(instance -> new ServiceInstanceSnitch(objectMapper, new EurekaServiceInstance(instance))) .collect(Collectors.toList()); // @formatter:on }
@PostConstruct @Override public void initialize() { logger.info("Initializing ..."); peerEurekaNodes.start(); try { registry.init(peerEurekaNodes); } catch (Exception e) { throw new RuntimeException(e); } logger.info("Initialized"); }
registry.register(info, "true".equals(isReplication)); return Response.status(204).build(); // 204 to be backwards compatible
/** * Handles cancellation of leases for this particular instance. * * @param isReplication * a header parameter containing information whether this is * replicated from other nodes. * @return response indicating whether the operation was a success or * failure. */ @DELETE public Response cancelLease( @HeaderParam(PeerEurekaNode.HEADER_REPLICATION) String isReplication) { try { boolean isSuccess = registry.cancel(app.getName(), id, "true".equals(isReplication)); if (isSuccess) { logger.debug("Found (Cancel): {} - {}", app.getName(), id); return Response.ok().build(); } else { logger.info("Not Found (Cancel): {} - {}", app.getName(), id); return Response.status(Status.NOT_FOUND).build(); } } catch (Throwable e) { logger.error("Error (cancel): {} - {}", app.getName(), id, e); return Response.serverError().build(); } }
protected void initEurekaServerContext() throws Exception { // For backward compatibility JsonXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH); XmlXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH); if (isAws(this.applicationInfoManager.getInfo())) { this.awsBinder = new AwsBinderDelegate(this.eurekaServerConfig, this.eurekaClientConfig, this.registry, this.applicationInfoManager); this.awsBinder.start(); } EurekaServerContextHolder.initialize(this.serverContext); log.info("Initialized server context"); // Copy registry from neighboring eureka node int registryCount = this.registry.syncUp(); this.registry.openForTraffic(this.applicationInfoManager, registryCount); // Register all monitoring statistics. EurekaMonitors.registerAllStats(); }
public Response updateMetadata(@Context UriInfo uriInfo) { try { InstanceInfo instanceInfo = registry.getInstanceByAppAndId(app.getName(), id); metadataMap.put(entry.getKey(), entry.getValue().get(0)); registry.register(instanceInfo, false); return Response.ok().build(); } catch (Throwable e) {
AbstractVIPResource(EurekaServerContext server) { this.registry = server.getRegistry(); this.responseCache = registry.getResponseCache(); }
private Response validateDirtyTimestamp(Long lastDirtyTimestamp, boolean isReplication) { InstanceInfo appInfo = registry.getInstanceByAppAndId(app.getName(), id, false); if (appInfo != null) { if ((lastDirtyTimestamp != null) && (!lastDirtyTimestamp.equals(appInfo.getLastDirtyTimestamp()))) {
/** * Synchronize {@link InstanceInfo} information if the timestamp between * this node and the peer eureka nodes vary. */ private void syncInstancesIfTimestampDiffers(String appName, String id, InstanceInfo info, InstanceInfo infoFromPeer) { try { if (infoFromPeer != null) { logger.warn("Peer wants us to take the instance information from it, since the timestamp differs," + "Id : {} My Timestamp : {}, Peer's timestamp: {}", id, info.getLastDirtyTimestamp(), infoFromPeer.getLastDirtyTimestamp()); if (infoFromPeer.getOverriddenStatus() != null && !InstanceStatus.UNKNOWN.equals(infoFromPeer.getOverriddenStatus())) { logger.warn("Overridden Status info -id {}, mine {}, peer's {}", id, info.getOverriddenStatus(), infoFromPeer.getOverriddenStatus()); registry.storeOverriddenStatusIfRequired(appName, id, infoFromPeer.getOverriddenStatus()); } registry.register(infoFromPeer, true); } } catch (Throwable e) { logger.warn("Exception when trying to set information from peer :", e); } }