Search in sources :

Example 6 with DiscoveryClient

use of com.netflix.discovery.DiscoveryClient in project eureka by Netflix.

the class DiscoveryClientResource method setupInjector.

public static EurekaClient setupInjector(InstanceInfo clientInstanceInfo) {
    DefaultEurekaClientConfig config = new DefaultEurekaClientConfig();
    // setup config in advance, used in initialize converter
    DiscoveryManager.getInstance().setEurekaClientConfig(config);
    EurekaClient client = new DiscoveryClient(clientInstanceInfo, config);
    ApplicationInfoManager.getInstance().initComponent(new MyDataCenterInstanceConfig());
    return client;
}
Also used : DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) MyDataCenterInstanceConfig(com.netflix.appinfo.MyDataCenterInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) DiscoveryClient(com.netflix.discovery.DiscoveryClient)

Example 7 with DiscoveryClient

use of com.netflix.discovery.DiscoveryClient in project eureka by Netflix.

the class DiscoveryClientResource method getClient.

public EurekaClient getClient() {
    if (client == null) {
        try {
            applicationInfoManager = createApplicationManager();
            EurekaClientConfig clientConfig = createEurekaClientConfig();
            Jersey1DiscoveryClientOptionalArgs optionalArgs = new Jersey1DiscoveryClientOptionalArgs();
            eventBus = new EventBusImpl();
            optionalArgs.setEventBus(eventBus);
            client = new DiscoveryClient(applicationInfoManager, clientConfig, optionalArgs);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return client;
}
Also used : DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) EventBusImpl(com.netflix.eventbus.impl.EventBusImpl) DiscoveryClient(com.netflix.discovery.DiscoveryClient) InvalidSubscriberException(com.netflix.eventbus.spi.InvalidSubscriberException) Jersey1DiscoveryClientOptionalArgs(com.netflix.discovery.shared.transport.jersey.Jersey1DiscoveryClientOptionalArgs)

Example 8 with DiscoveryClient

use of com.netflix.discovery.DiscoveryClient in project ribbon by Netflix.

the class DiscoveryEnabledLoadBalancerSupportsPortOverrideTest method setupMock.

@Before
public void setupMock() {
    List<InstanceInfo> dummyII = getDummyInstanceInfo("dummy", "http://www.host.com", "1.1.1.1", 8001);
    List<InstanceInfo> secureDummyII = getDummyInstanceInfo("secureDummy", "http://www.host.com", "1.1.1.1", 8002);
    PowerMock.mockStatic(DiscoveryManager.class);
    PowerMock.mockStatic(DiscoveryClient.class);
    DiscoveryClient mockedDiscoveryClient = createMock(DiscoveryClient.class);
    DiscoveryManager mockedDiscoveryManager = createMock(DiscoveryManager.class);
    expect(DiscoveryClient.getZone((InstanceInfo) EasyMock.anyObject())).andReturn("dummyZone").anyTimes();
    expect(DiscoveryManager.getInstance()).andReturn(mockedDiscoveryManager).anyTimes();
    expect(mockedDiscoveryManager.getDiscoveryClient()).andReturn(mockedDiscoveryClient).anyTimes();
    expect(mockedDiscoveryClient.getInstancesByVipAddress("dummy", false, "region")).andReturn(dummyII).anyTimes();
    expect(mockedDiscoveryClient.getInstancesByVipAddress("secureDummy", true, "region")).andReturn(secureDummyII).anyTimes();
    replay(DiscoveryManager.class);
    replay(DiscoveryClient.class);
    replay(mockedDiscoveryManager);
    replay(mockedDiscoveryClient);
}
Also used : DiscoveryManager(com.netflix.discovery.DiscoveryManager) DiscoveryClient(com.netflix.discovery.DiscoveryClient) InstanceInfo(com.netflix.appinfo.InstanceInfo) Before(org.junit.Before)

Example 9 with DiscoveryClient

use of com.netflix.discovery.DiscoveryClient in project chassis by Kixeye.

the class ChassisEurekaRegistrationTest method testServiceRegistration.

@Test
public void testServiceRegistration() throws InterruptedException {
    // Registers "chasis-default-name" with a Eurkea server running on local host.
    //   http://localhost:8184/v2/apps/chassis-default-name
    // tell eureka the service is up which causes a registration
    ApplicationInfoManager.getInstance().setInstanceStatus(InstanceInfo.InstanceStatus.UP);
    // get application registration from Eureka
    DiscoveryClient client = DiscoveryManager.getInstance().getDiscoveryClient();
    InstanceInfo instanceInfo = null;
    for (int i = 0; (instanceInfo == null) && (i < 50); i++) {
        Thread.sleep(5000);
        try {
            instanceInfo = client.getNextServerFromEureka("default-service", false);
        } catch (RuntimeException e) {
        // eat not found runtime exception
        }
    }
    Assert.assertNotNull(instanceInfo);
    Assert.assertEquals(InstanceStatus.UP, instanceInfo.getStatus());
    System.out.println("done");
}
Also used : DiscoveryClient(com.netflix.discovery.DiscoveryClient) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 10 with DiscoveryClient

use of com.netflix.discovery.DiscoveryClient in project SimianArmy by Netflix.

the class BasicJanitorMonkeyContext method getASGJanitor.

private ASGJanitor getASGJanitor() {
    JanitorRuleEngine ruleEngine = createJanitorRuleEngine();
    boolean discoveryEnabled = configuration().getBoolOrElse("simianarmy.janitor.Eureka.enabled", false);
    ASGInstanceValidator instanceValidator;
    if (discoveryEnabled) {
        LOGGER.info("Initializing Discovery client.");
        Injector injector = Guice.createInjector(new EurekaModule());
        DiscoveryClient discoveryClient = injector.getInstance(DiscoveryClient.class);
        instanceValidator = new DiscoveryASGInstanceValidator(discoveryClient);
    } else {
        LOGGER.info("Discovery/Eureka is not enabled, use the dummy instance validator.");
        instanceValidator = new DummyASGInstanceValidator();
    }
    if (configuration().getBoolOrElse("simianarmy.janitor.rule.oldEmptyASGRule.enabled", false)) {
        ruleEngine.addRule(new OldEmptyASGRule(monkeyCalendar, (int) configuration().getNumOrElse("simianarmy.janitor.rule.oldEmptyASGRule.launchConfigAgeThreshold", 50), (int) configuration().getNumOrElse("simianarmy.janitor.rule.oldEmptyASGRule.retentionDays", 10), instanceValidator));
    }
    if (configuration().getBoolOrElse("simianarmy.janitor.rule.suspendedASGRule.enabled", false)) {
        ruleEngine.addRule(new SuspendedASGRule(monkeyCalendar, (int) configuration().getNumOrElse("simianarmy.janitor.rule.suspendedASGRule.suspensionAgeThreshold", 2), (int) configuration().getNumOrElse("simianarmy.janitor.rule.suspendedASGRule.retentionDays", 5), instanceValidator));
    }
    if (configuration().getBoolOrElse("simianarmy.janitor.rule.untaggedRule.enabled", false) && getUntaggedRuleResourceSet().contains("ASG")) {
        ruleEngine.addRule(new UntaggedRule(monkeyCalendar, getPropertySet("simianarmy.janitor.rule.untaggedRule.requiredTags"), (int) configuration().getNumOrElse("simianarmy.janitor.rule.untaggedRule.retentionDaysWithOwner", 3), (int) configuration().getNumOrElse("simianarmy.janitor.rule.untaggedRule.retentionDaysWithoutOwner", 8)));
    }
    JanitorCrawler crawler;
    if (configuration().getBoolOrElse("simianarmy.janitor.edda.enabled", false)) {
        crawler = new EddaASGJanitorCrawler(createEddaClient(), awsClient().region());
    } else {
        crawler = new ASGJanitorCrawler(awsClient());
    }
    BasicJanitorContext asgJanitorCtx = new BasicJanitorContext(monkeyRegion, ruleEngine, crawler, janitorResourceTracker, monkeyCalendar, configuration(), recorder());
    return new ASGJanitor(awsClient(), asgJanitorCtx);
}
Also used : EurekaModule(com.netflix.discovery.guice.EurekaModule) UntaggedRule(com.netflix.simianarmy.aws.janitor.rule.generic.UntaggedRule) Injector(com.google.inject.Injector) DiscoveryClient(com.netflix.discovery.DiscoveryClient)

Aggregations

DiscoveryClient (com.netflix.discovery.DiscoveryClient)15 InstanceInfo (com.netflix.appinfo.InstanceInfo)10 EurekaClient (com.netflix.discovery.EurekaClient)6 EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)6 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)5 EurekaInstanceConfig (com.netflix.appinfo.EurekaInstanceConfig)5 DefaultEurekaClientConfig (com.netflix.discovery.DefaultEurekaClientConfig)5 Before (org.junit.Before)5 Test (org.junit.Test)5 MyDataCenterInstanceConfig (com.netflix.appinfo.MyDataCenterInstanceConfig)4 DiscoveryManager (com.netflix.discovery.DiscoveryManager)4 Archaius2VipAddressResolver (com.netflix.appinfo.providers.Archaius2VipAddressResolver)2 VipAddressResolver (com.netflix.appinfo.providers.VipAddressResolver)2 TransportClientFactories (com.netflix.discovery.shared.transport.jersey.TransportClientFactories)2 DefaultServerCodecs (com.netflix.eureka.resources.DefaultServerCodecs)2 ServerCodecs (com.netflix.eureka.resources.ServerCodecs)2 Injector (com.google.inject.Injector)1 AmazonInfo (com.netflix.appinfo.AmazonInfo)1 CloudInstanceConfig (com.netflix.appinfo.CloudInstanceConfig)1 Ec2EurekaArchaius2InstanceConfig (com.netflix.appinfo.Ec2EurekaArchaius2InstanceConfig)1