Search in sources :

Example 11 with ApplicationInfoManager

use of com.netflix.appinfo.ApplicationInfoManager in project eureka by Netflix.

the class BackUpRegistryTest method setUp.

public void setUp(boolean enableRemote) throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("eureka.client.refresh.interval", CLIENT_REFRESH_RATE);
    ConfigurationManager.getConfigInstance().setProperty("eureka.registration.enabled", "false");
    if (enableRemote) {
        ConfigurationManager.getConfigInstance().setProperty("eureka.fetchRemoteRegionsRegistry", REMOTE_REGION);
    }
    ConfigurationManager.getConfigInstance().setProperty("eureka.myregion.availabilityZones", REMOTE_ZONE);
    ConfigurationManager.getConfigInstance().setProperty("eureka.backupregistry", MockBackupRegistry.class.getName());
    ConfigurationManager.getConfigInstance().setProperty("eureka.serviceUrl.default", "http://localhost:" + NOT_AVAILABLE_EUREKA_PORT + MockRemoteEurekaServer.EUREKA_API_BASE_PATH);
    InstanceInfo.Builder builder = InstanceInfo.Builder.newBuilder();
    builder.setIPAddr("10.10.101.00");
    builder.setHostName("Hosttt");
    builder.setAppName("EurekaTestApp-" + UUID.randomUUID());
    builder.setDataCenterInfo(new DataCenterInfo() {

        @Override
        public Name getName() {
            return Name.MyOwn;
        }
    });
    ApplicationInfoManager applicationInfoManager = new ApplicationInfoManager(new MyDataCenterInstanceConfig(), builder.build());
    backupRegistry = new MockBackupRegistry();
    setupBackupMock();
    client = new DiscoveryClient(applicationInfoManager, new DefaultEurekaClientConfig(), null, Providers.of((BackupRegistry) backupRegistry));
}
Also used : MyDataCenterInstanceConfig(com.netflix.appinfo.MyDataCenterInstanceConfig) DataCenterInfo(com.netflix.appinfo.DataCenterInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager)

Example 12 with ApplicationInfoManager

use of com.netflix.appinfo.ApplicationInfoManager in project eureka by Netflix.

the class AbstractTester method setUp.

@Before
public void setUp() throws Exception {
    ConfigurationManager.getConfigInstance().clearProperty("eureka.remoteRegion.global.appWhiteList");
    ConfigurationManager.getConfigInstance().setProperty("eureka.responseCacheAutoExpirationInSeconds", "10");
    ConfigurationManager.getConfigInstance().clearProperty("eureka.remoteRegion." + REMOTE_REGION_NAME + ".appWhiteList");
    ConfigurationManager.getConfigInstance().setProperty("eureka.deltaRetentionTimerIntervalInMs", "600000");
    ConfigurationManager.getConfigInstance().setProperty("eureka.remoteRegion.registryFetchIntervalInSeconds", "5");
    populateRemoteRegistryAtStartup();
    mockRemoteEurekaServer = newMockRemoteServer();
    mockRemoteEurekaServer.start();
    ConfigurationManager.getConfigInstance().setProperty("eureka.remoteRegionUrlsWithName", REMOTE_REGION_NAME + ";http://localhost:" + mockRemoteEurekaServer.getPort() + MockRemoteEurekaServer.EUREKA_API_BASE_PATH);
    serverConfig = spy(new DefaultEurekaServerConfig());
    InstanceInfo.Builder builder = InstanceInfo.Builder.newBuilder();
    builder.setIPAddr("10.10.101.00");
    builder.setHostName("Hosttt");
    builder.setAppName("EurekaTestApp-" + UUID.randomUUID());
    builder.setLeaseInfo(LeaseInfo.Builder.newBuilder().build());
    builder.setDataCenterInfo(getDataCenterInfo());
    ConfigurationManager.getConfigInstance().setProperty("eureka.serviceUrl.default", "http://localhost:" + mockRemoteEurekaServer.getPort() + MockRemoteEurekaServer.EUREKA_API_BASE_PATH);
    DefaultEurekaClientConfig clientConfig = new DefaultEurekaClientConfig();
    // setup config in advance, used in initialize converter
    ApplicationInfoManager applicationInfoManager = new ApplicationInfoManager(new MyDataCenterInstanceConfig(), builder.build());
    client = new DiscoveryClient(applicationInfoManager, clientConfig);
    ServerCodecs serverCodecs = new DefaultServerCodecs(serverConfig);
    registry = makePeerAwareInstanceRegistry(serverConfig, clientConfig, serverCodecs, client);
    serverContext = new DefaultEurekaServerContext(serverConfig, serverCodecs, registry, mock(PeerEurekaNodes.class), applicationInfoManager);
    serverContext.initialize();
}
Also used : DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) MyDataCenterInstanceConfig(com.netflix.appinfo.MyDataCenterInstanceConfig) DiscoveryClient(com.netflix.discovery.DiscoveryClient) DefaultServerCodecs(com.netflix.eureka.resources.DefaultServerCodecs) InstanceInfo(com.netflix.appinfo.InstanceInfo) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager) DefaultServerCodecs(com.netflix.eureka.resources.DefaultServerCodecs) ServerCodecs(com.netflix.eureka.resources.ServerCodecs) Before(org.junit.Before)

Example 13 with ApplicationInfoManager

use of com.netflix.appinfo.ApplicationInfoManager in project eureka by Netflix.

the class ExampleEurekaClient method main.

public static void main(String[] args) {
    ExampleEurekaClient sampleClient = new ExampleEurekaClient();
    // create the client
    ApplicationInfoManager applicationInfoManager = initializeApplicationInfoManager(new MyDataCenterInstanceConfig());
    EurekaClient client = initializeEurekaClient(applicationInfoManager, new DefaultEurekaClientConfig());
    // use the client
    sampleClient.sendRequestToServiceUsingEureka(client);
    // shutdown the client
    eurekaClient.shutdown();
}
Also used : DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) MyDataCenterInstanceConfig(com.netflix.appinfo.MyDataCenterInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager)

Example 14 with ApplicationInfoManager

use of com.netflix.appinfo.ApplicationInfoManager in project eureka by Netflix.

the class ExampleEurekaClient method initializeApplicationInfoManager.

private static synchronized ApplicationInfoManager initializeApplicationInfoManager(EurekaInstanceConfig instanceConfig) {
    if (applicationInfoManager == null) {
        InstanceInfo instanceInfo = new EurekaConfigBasedInstanceInfoProvider(instanceConfig).get();
        applicationInfoManager = new ApplicationInfoManager(instanceConfig, instanceInfo);
    }
    return applicationInfoManager;
}
Also used : EurekaConfigBasedInstanceInfoProvider(com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider) InstanceInfo(com.netflix.appinfo.InstanceInfo) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager)

Example 15 with ApplicationInfoManager

use of com.netflix.appinfo.ApplicationInfoManager 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

ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)16 MyDataCenterInstanceConfig (com.netflix.appinfo.MyDataCenterInstanceConfig)10 InstanceInfo (com.netflix.appinfo.InstanceInfo)9 DefaultEurekaClientConfig (com.netflix.discovery.DefaultEurekaClientConfig)6 DiscoveryClient (com.netflix.discovery.DiscoveryClient)6 EurekaInstanceConfig (com.netflix.appinfo.EurekaInstanceConfig)5 EurekaClient (com.netflix.discovery.EurekaClient)5 EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)4 Before (org.junit.Before)4 EurekaConfigBasedInstanceInfoProvider (com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider)3 PeerAwareInstanceRegistry (com.netflix.eureka.registry.PeerAwareInstanceRegistry)3 Test (org.junit.Test)3 AmazonInfo (com.netflix.appinfo.AmazonInfo)2 DataCenterInfo (com.netflix.appinfo.DataCenterInfo)2 Archaius2VipAddressResolver (com.netflix.appinfo.providers.Archaius2VipAddressResolver)2 VipAddressResolver (com.netflix.appinfo.providers.VipAddressResolver)2 EurekaServerConfig (com.netflix.eureka.EurekaServerConfig)2 PeerEurekaNodes (com.netflix.eureka.cluster.PeerEurekaNodes)2 DefaultServerCodecs (com.netflix.eureka.resources.DefaultServerCodecs)2 ServerCodecs (com.netflix.eureka.resources.ServerCodecs)2