Search in sources :

Example 1 with PeerEurekaNode

use of com.netflix.eureka.cluster.PeerEurekaNode in project eureka by Netflix.

the class StatusUtilTest method getMockNodes.

List<PeerEurekaNode> getMockNodes(int size) {
    List<PeerEurekaNode> nodes = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        PeerEurekaNode mockNode = mock(PeerEurekaNode.class);
        when(mockNode.getServiceUrl()).thenReturn(String.format("http://%d:8080/v2", i));
        nodes.add(mockNode);
    }
    return nodes;
}
Also used : PeerEurekaNode(com.netflix.eureka.cluster.PeerEurekaNode) ArrayList(java.util.ArrayList)

Example 2 with PeerEurekaNode

use of com.netflix.eureka.cluster.PeerEurekaNode in project nutzboot by nutzam.

the class EurekaServletStarter method populateNavbar.

private void populateNavbar(NutMap result) {
    List<NutMap> replicas = new ArrayList<>();
    List<PeerEurekaNode> list = getServerContext().getPeerEurekaNodes().getPeerNodesView();
    for (PeerEurekaNode node : list) {
        try {
            URI uri = new URI(node.getServiceUrl());
            String href = scrubBasicAuth(node.getServiceUrl());
            replicas.add(NutMap.NEW().setv("key", uri.getHost()).setv("value", href));
        } catch (Exception ex) {
        }
    }
    result.put("replicas", replicas);
}
Also used : PeerEurekaNode(com.netflix.eureka.cluster.PeerEurekaNode) ArrayList(java.util.ArrayList) URI(java.net.URI) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) NutMap(org.nutz.lang.util.NutMap)

Example 3 with PeerEurekaNode

use of com.netflix.eureka.cluster.PeerEurekaNode in project spring-cloud-netflix by spring-cloud.

the class EurekaController method populateNavbar.

private void populateNavbar(HttpServletRequest request, Map<String, Object> model) {
    Map<String, String> replicas = new LinkedHashMap<>();
    List<PeerEurekaNode> list = getServerContext().getPeerEurekaNodes().getPeerNodesView();
    for (PeerEurekaNode node : list) {
        try {
            URI uri = new URI(node.getServiceUrl());
            String href = scrubBasicAuth(node.getServiceUrl());
            replicas.put(uri.getHost(), href);
        } catch (Exception ex) {
        // ignore?
        }
    }
    model.put("replicas", replicas.entrySet());
}
Also used : PeerEurekaNode(com.netflix.eureka.cluster.PeerEurekaNode) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with PeerEurekaNode

use of com.netflix.eureka.cluster.PeerEurekaNode in project eureka by Netflix.

the class PeerAwareInstanceRegistryImpl method primeAwsReplicas.

/**
 * Prime connections for Aws replicas.
 * <p>
 * Sometimes when the eureka servers comes up, AWS firewall may not allow
 * the network connections immediately. This will cause the outbound
 * connections to fail, but the inbound connections continue to work. What
 * this means is the clients would have switched to this node (after EIP
 * binding) and so the other eureka nodes will expire all instances that
 * have been switched because of the lack of outgoing heartbeats from this
 * instance.
 * </p>
 * <p>
 * The best protection in this scenario is to block and wait until we are
 * able to ping all eureka nodes successfully atleast once. Until then we
 * won't open up the traffic.
 * </p>
 */
private void primeAwsReplicas(ApplicationInfoManager applicationInfoManager) {
    boolean areAllPeerNodesPrimed = false;
    while (!areAllPeerNodesPrimed) {
        String peerHostName = null;
        try {
            Application eurekaApps = this.getApplication(applicationInfoManager.getInfo().getAppName(), false);
            if (eurekaApps == null) {
                areAllPeerNodesPrimed = true;
                logger.info("No peers needed to prime.");
                return;
            }
            for (PeerEurekaNode node : peerEurekaNodes.getPeerEurekaNodes()) {
                for (InstanceInfo peerInstanceInfo : eurekaApps.getInstances()) {
                    LeaseInfo leaseInfo = peerInstanceInfo.getLeaseInfo();
                    // If the lease is expired - do not worry about priming
                    if (System.currentTimeMillis() > (leaseInfo.getRenewalTimestamp() + (leaseInfo.getDurationInSecs() * 1000)) + (2 * 60 * 1000)) {
                        continue;
                    }
                    peerHostName = peerInstanceInfo.getHostName();
                    logger.info("Trying to send heartbeat for the eureka server at {} to make sure the " + "network channels are open", peerHostName);
                    // the other instances may be legitimately down
                    if (peerHostName.equalsIgnoreCase(new URI(node.getServiceUrl()).getHost())) {
                        node.heartbeat(peerInstanceInfo.getAppName(), peerInstanceInfo.getId(), peerInstanceInfo, null, true);
                    }
                }
            }
            areAllPeerNodesPrimed = true;
        } catch (Throwable e) {
            logger.error("Could not contact {}", peerHostName, e);
            try {
                Thread.sleep(PRIME_PEER_NODES_RETRY_MS);
            } catch (InterruptedException e1) {
                logger.warn("Interrupted while priming : ", e1);
                areAllPeerNodesPrimed = true;
            }
        }
    }
}
Also used : PeerEurekaNode(com.netflix.eureka.cluster.PeerEurekaNode) LeaseInfo(com.netflix.appinfo.LeaseInfo) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo) URI(java.net.URI)

Example 5 with PeerEurekaNode

use of com.netflix.eureka.cluster.PeerEurekaNode in project eureka by Netflix.

the class StatusUtil method getStatusInfo.

public StatusInfo getStatusInfo() {
    StatusInfo.Builder builder = StatusInfo.Builder.newBuilder();
    // Add application level status
    int upReplicasCount = 0;
    StringBuilder upReplicas = new StringBuilder();
    StringBuilder downReplicas = new StringBuilder();
    StringBuilder replicaHostNames = new StringBuilder();
    for (PeerEurekaNode node : peerEurekaNodes.getPeerEurekaNodes()) {
        if (replicaHostNames.length() > 0) {
            replicaHostNames.append(", ");
        }
        replicaHostNames.append(node.getServiceUrl());
        if (isReplicaAvailable(node.getServiceUrl())) {
            upReplicas.append(node.getServiceUrl()).append(',');
            upReplicasCount++;
        } else {
            downReplicas.append(node.getServiceUrl()).append(',');
        }
    }
    builder.add("registered-replicas", replicaHostNames.toString());
    builder.add("available-replicas", upReplicas.toString());
    builder.add("unavailable-replicas", downReplicas.toString());
    // Only set the healthy flag if a threshold has been configured.
    if (peerEurekaNodes.getMinNumberOfAvailablePeers() > -1) {
        builder.isHealthy(upReplicasCount >= peerEurekaNodes.getMinNumberOfAvailablePeers());
    }
    builder.withInstanceInfo(this.instanceInfo);
    return builder.build();
}
Also used : PeerEurekaNode(com.netflix.eureka.cluster.PeerEurekaNode)

Aggregations

PeerEurekaNode (com.netflix.eureka.cluster.PeerEurekaNode)6 URI (java.net.URI)3 InstanceInfo (com.netflix.appinfo.InstanceInfo)2 Application (com.netflix.discovery.shared.Application)2 ArrayList (java.util.ArrayList)2 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)1 LeaseInfo (com.netflix.appinfo.LeaseInfo)1 EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)1 EurekaTransportConfig (com.netflix.discovery.shared.transport.EurekaTransportConfig)1 EurekaServerConfig (com.netflix.eureka.EurekaServerConfig)1 EurekaServerContext (com.netflix.eureka.EurekaServerContext)1 PeerEurekaNodes (com.netflix.eureka.cluster.PeerEurekaNodes)1 PeerAwareInstanceRegistry (com.netflix.eureka.registry.PeerAwareInstanceRegistry)1 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 ServletException (javax.servlet.ServletException)1 NutMap (org.nutz.lang.util.NutMap)1