Search in sources :

Example 1 with PeerEurekaNodes

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

the class EurekaBootStrap method initEurekaServerContext.

/**
     * init hook for server context. Override for custom logic.
     */
protected void initEurekaServerContext() throws Exception {
    EurekaServerConfig eurekaServerConfig = new DefaultEurekaServerConfig();
    // For backward compatibility
    JsonXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH);
    XmlXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH);
    logger.info("Initializing the eureka client...");
    logger.info(eurekaServerConfig.getJsonCodecName());
    ServerCodecs serverCodecs = new DefaultServerCodecs(eurekaServerConfig);
    ApplicationInfoManager applicationInfoManager = null;
    if (eurekaClient == null) {
        EurekaInstanceConfig instanceConfig = isCloud(ConfigurationManager.getDeploymentContext()) ? new CloudInstanceConfig() : new MyDataCenterInstanceConfig();
        applicationInfoManager = new ApplicationInfoManager(instanceConfig, new EurekaConfigBasedInstanceInfoProvider(instanceConfig).get());
        EurekaClientConfig eurekaClientConfig = new DefaultEurekaClientConfig();
        eurekaClient = new DiscoveryClient(applicationInfoManager, eurekaClientConfig);
    } else {
        applicationInfoManager = eurekaClient.getApplicationInfoManager();
    }
    PeerAwareInstanceRegistry registry;
    if (isAws(applicationInfoManager.getInfo())) {
        registry = new AwsInstanceRegistry(eurekaServerConfig, eurekaClient.getEurekaClientConfig(), serverCodecs, eurekaClient);
        awsBinder = new AwsBinderDelegate(eurekaServerConfig, eurekaClient.getEurekaClientConfig(), registry, applicationInfoManager);
        awsBinder.start();
    } else {
        registry = new PeerAwareInstanceRegistryImpl(eurekaServerConfig, eurekaClient.getEurekaClientConfig(), serverCodecs, eurekaClient);
    }
    PeerEurekaNodes peerEurekaNodes = getPeerEurekaNodes(registry, eurekaServerConfig, eurekaClient.getEurekaClientConfig(), serverCodecs, applicationInfoManager);
    serverContext = new DefaultEurekaServerContext(eurekaServerConfig, serverCodecs, registry, peerEurekaNodes, applicationInfoManager);
    EurekaServerContextHolder.initialize(serverContext);
    serverContext.initialize();
    logger.info("Initialized server context");
    // Copy registry from neighboring eureka node
    int registryCount = registry.syncUp();
    registry.openForTraffic(applicationInfoManager, registryCount);
    // Register all monitoring statistics.
    EurekaMonitors.registerAllStats();
}
Also used : DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) PeerAwareInstanceRegistryImpl(com.netflix.eureka.registry.PeerAwareInstanceRegistryImpl) CloudInstanceConfig(com.netflix.appinfo.CloudInstanceConfig) DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) EurekaConfigBasedInstanceInfoProvider(com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider) DefaultServerCodecs(com.netflix.eureka.resources.DefaultServerCodecs) DefaultServerCodecs(com.netflix.eureka.resources.DefaultServerCodecs) ServerCodecs(com.netflix.eureka.resources.ServerCodecs) PeerAwareInstanceRegistry(com.netflix.eureka.registry.PeerAwareInstanceRegistry) PeerEurekaNodes(com.netflix.eureka.cluster.PeerEurekaNodes) AwsBinderDelegate(com.netflix.eureka.aws.AwsBinderDelegate) MyDataCenterInstanceConfig(com.netflix.appinfo.MyDataCenterInstanceConfig) DiscoveryClient(com.netflix.discovery.DiscoveryClient) AwsInstanceRegistry(com.netflix.eureka.registry.AwsInstanceRegistry) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager)

Example 2 with PeerEurekaNodes

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

the class ReplicationConcurrencyTest method setUp.

@Before
public void setUp() throws Exception {
    InstanceInfo seed = InstanceInfoGenerator.takeOne();
    id = seed.getId();
    appName = seed.getAppName();
    // set up test instances
    instance1 = InstanceInfo.Builder.newBuilder().setInstanceId(id).setAppName(appName).setHostName(seed.getHostName()).setIPAddr(seed.getIPAddr()).setDataCenterInfo(seed.getDataCenterInfo()).setStatus(InstanceInfo.InstanceStatus.STARTING).setLastDirtyTimestamp(11111l).build();
    instance2 = new InstanceInfo.Builder(seed).setInstanceId(id).setAppName(appName).setHostName(seed.getHostName()).setIPAddr(seed.getIPAddr()).setDataCenterInfo(seed.getDataCenterInfo()).setStatus(InstanceInfo.InstanceStatus.UP).setLastDirtyTimestamp(22222l).build();
    assertThat(instance1.getStatus(), not(equalTo(instance2.getStatus())));
    // set up server1 with no replication anywhere
    PeerEurekaNodes server1Peers = Mockito.mock(PeerEurekaNodes.class);
    Mockito.when(server1Peers.getPeerEurekaNodes()).thenReturn(Collections.<PeerEurekaNode>emptyList());
    server1 = new MockServer(appName, server1Peers);
    // set up server2
    PeerEurekaNodes server2Peers = Mockito.mock(PeerEurekaNodes.class);
    Mockito.when(server2Peers.getPeerEurekaNodes()).thenReturn(Collections.<PeerEurekaNode>emptyList());
    server2 = new MockServer(appName, server2Peers);
    // register with server1
    // STARTING
    server1.applicationResource.addInstance(instance1, "false");
    server1Sees = server1.registry.getInstanceByAppAndId(appName, id);
    assertThat(server1Sees, equalTo(instance1));
    // update (via a register) with server2
    // UP
    server2.applicationResource.addInstance(instance2, "false");
    server2Sees = server2.registry.getInstanceByAppAndId(appName, id);
    assertThat(server2Sees, equalTo(instance2));
    // make sure data in server 1 is "older"
    assertThat(server2Sees.getLastDirtyTimestamp() > server1Sees.getLastDirtyTimestamp(), is(true));
}
Also used : PeerEurekaNodes(com.netflix.eureka.cluster.PeerEurekaNodes) InstanceInfo(com.netflix.appinfo.InstanceInfo) Before(org.junit.Before)

Example 3 with PeerEurekaNodes

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

the class StatusUtilTest method getStatusUtil.

/**
     * @param replicas the number of replicas to mock
     * @param instances the number of instances to mock
     * @param minimum the minimum number of peers
     * @return the status utility with the mocked replicas/instances
     */
private StatusUtil getStatusUtil(int replicas, int instances, int minimum) {
    EurekaServerContext mockEurekaServerContext = mock(EurekaServerContext.class);
    List<InstanceInfo> mockInstanceInfos = getMockInstanceInfos(instances);
    Application mockApplication = mock(Application.class);
    when(mockApplication.getInstances()).thenReturn(mockInstanceInfos);
    ApplicationInfoManager mockAppInfoManager = mock(ApplicationInfoManager.class);
    when(mockAppInfoManager.getInfo()).thenReturn(mockInstanceInfos.get(0));
    when(mockEurekaServerContext.getApplicationInfoManager()).thenReturn(mockAppInfoManager);
    PeerAwareInstanceRegistry mockRegistry = mock(PeerAwareInstanceRegistry.class);
    when(mockRegistry.getApplication("stuff", false)).thenReturn(mockApplication);
    when(mockEurekaServerContext.getRegistry()).thenReturn(mockRegistry);
    List<PeerEurekaNode> mockNodes = getMockNodes(replicas);
    EurekaTransportConfig mockTransportConfig = mock(EurekaTransportConfig.class);
    when(mockTransportConfig.applicationsResolverUseIp()).thenReturn(false);
    EurekaClientConfig mockClientConfig = mock(EurekaClientConfig.class);
    when(mockClientConfig.getTransportConfig()).thenReturn(mockTransportConfig);
    EurekaServerConfig mockServerConfig = mock(EurekaServerConfig.class);
    when(mockServerConfig.getHealthStatusMinNumberOfAvailablePeers()).thenReturn(minimum);
    PeerEurekaNodes peerEurekaNodes = new PeerEurekaNodes(mockRegistry, mockServerConfig, mockClientConfig, null, mockAppInfoManager);
    PeerEurekaNodes spyPeerEurekaNodes = spy(peerEurekaNodes);
    when(spyPeerEurekaNodes.getPeerEurekaNodes()).thenReturn(mockNodes);
    when(mockEurekaServerContext.getPeerEurekaNodes()).thenReturn(spyPeerEurekaNodes);
    return new StatusUtil(mockEurekaServerContext);
}
Also used : EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) InstanceInfo(com.netflix.appinfo.InstanceInfo) PeerAwareInstanceRegistry(com.netflix.eureka.registry.PeerAwareInstanceRegistry) EurekaServerContext(com.netflix.eureka.EurekaServerContext) PeerEurekaNode(com.netflix.eureka.cluster.PeerEurekaNode) PeerEurekaNodes(com.netflix.eureka.cluster.PeerEurekaNodes) EurekaServerConfig(com.netflix.eureka.EurekaServerConfig) EurekaTransportConfig(com.netflix.discovery.shared.transport.EurekaTransportConfig) Application(com.netflix.discovery.shared.Application) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager)

Aggregations

PeerEurekaNodes (com.netflix.eureka.cluster.PeerEurekaNodes)3 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)2 InstanceInfo (com.netflix.appinfo.InstanceInfo)2 EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)2 PeerAwareInstanceRegistry (com.netflix.eureka.registry.PeerAwareInstanceRegistry)2 CloudInstanceConfig (com.netflix.appinfo.CloudInstanceConfig)1 EurekaInstanceConfig (com.netflix.appinfo.EurekaInstanceConfig)1 MyDataCenterInstanceConfig (com.netflix.appinfo.MyDataCenterInstanceConfig)1 EurekaConfigBasedInstanceInfoProvider (com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider)1 DefaultEurekaClientConfig (com.netflix.discovery.DefaultEurekaClientConfig)1 DiscoveryClient (com.netflix.discovery.DiscoveryClient)1 Application (com.netflix.discovery.shared.Application)1 EurekaTransportConfig (com.netflix.discovery.shared.transport.EurekaTransportConfig)1 EurekaServerConfig (com.netflix.eureka.EurekaServerConfig)1 EurekaServerContext (com.netflix.eureka.EurekaServerContext)1 AwsBinderDelegate (com.netflix.eureka.aws.AwsBinderDelegate)1 PeerEurekaNode (com.netflix.eureka.cluster.PeerEurekaNode)1 AwsInstanceRegistry (com.netflix.eureka.registry.AwsInstanceRegistry)1 PeerAwareInstanceRegistryImpl (com.netflix.eureka.registry.PeerAwareInstanceRegistryImpl)1 DefaultServerCodecs (com.netflix.eureka.resources.DefaultServerCodecs)1