Search in sources :

Example 6 with DataCenterInfo

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

the class DiscoveryClientResource method newInstanceInfoBuilder.

public static InstanceInfo.Builder newInstanceInfoBuilder(int renewalIntervalInSecs) {
    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;
        }
    });
    builder.setLeaseInfo(LeaseInfo.Builder.newBuilder().setRenewalIntervalInSecs(renewalIntervalInSecs).build());
    return builder;
}
Also used : DataCenterInfo(com.netflix.appinfo.DataCenterInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 7 with DataCenterInfo

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

the class ApplicationResourceTest method testBadRegistration.

@Test
public void testBadRegistration() throws Exception {
    InstanceInfo instanceInfo = spy(InstanceInfoGenerator.takeOne());
    when(instanceInfo.getId()).thenReturn(null);
    Response response = applicationResource.addInstance(instanceInfo, false + "");
    assertThat(response.getStatus(), is(400));
    instanceInfo = spy(InstanceInfoGenerator.takeOne());
    when(instanceInfo.getHostName()).thenReturn(null);
    response = applicationResource.addInstance(instanceInfo, false + "");
    assertThat(response.getStatus(), is(400));
    instanceInfo = spy(InstanceInfoGenerator.takeOne());
    when(instanceInfo.getAppName()).thenReturn("");
    response = applicationResource.addInstance(instanceInfo, false + "");
    assertThat(response.getStatus(), is(400));
    instanceInfo = spy(InstanceInfoGenerator.takeOne());
    when(instanceInfo.getAppName()).thenReturn(applicationResource.getName() + "extraExtra");
    response = applicationResource.addInstance(instanceInfo, false + "");
    assertThat(response.getStatus(), is(400));
    instanceInfo = spy(InstanceInfoGenerator.takeOne());
    when(instanceInfo.getDataCenterInfo()).thenReturn(null);
    response = applicationResource.addInstance(instanceInfo, false + "");
    assertThat(response.getStatus(), is(400));
    instanceInfo = spy(InstanceInfoGenerator.takeOne());
    when(instanceInfo.getDataCenterInfo()).thenReturn(new DataCenterInfo() {

        @Override
        public Name getName() {
            return null;
        }
    });
    response = applicationResource.addInstance(instanceInfo, false + "");
    assertThat(response.getStatus(), is(400));
}
Also used : Response(javax.ws.rs.core.Response) DataCenterInfo(com.netflix.appinfo.DataCenterInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 8 with DataCenterInfo

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

the class EurekaConfigBasedInstanceInfoProvider method get.

@Override
public synchronized InstanceInfo get() {
    if (instanceInfo == null) {
        // Build the lease information to be passed to the server based on config
        LeaseInfo.Builder leaseInfoBuilder = LeaseInfo.Builder.newBuilder().setRenewalIntervalInSecs(config.getLeaseRenewalIntervalInSeconds()).setDurationInSecs(config.getLeaseExpirationDurationInSeconds());
        if (vipAddressResolver == null) {
            vipAddressResolver = new Archaius1VipAddressResolver();
        }
        // Builder the instance information to be registered with eureka server
        InstanceInfo.Builder builder = InstanceInfo.Builder.newBuilder(vipAddressResolver);
        // set the appropriate id for the InstanceInfo, falling back to datacenter Id if applicable, else hostname
        String instanceId = config.getInstanceId();
        DataCenterInfo dataCenterInfo = config.getDataCenterInfo();
        if (instanceId == null || instanceId.isEmpty()) {
            if (dataCenterInfo instanceof UniqueIdentifier) {
                instanceId = ((UniqueIdentifier) dataCenterInfo).getId();
            } else {
                instanceId = config.getHostName(false);
            }
        }
        String defaultAddress;
        if (config instanceof RefreshableInstanceConfig) {
            // Refresh AWS data center info, and return up to date address
            defaultAddress = ((RefreshableInstanceConfig) config).resolveDefaultAddress(false);
        } else {
            defaultAddress = config.getHostName(false);
        }
        // fail safe
        if (defaultAddress == null || defaultAddress.isEmpty()) {
            defaultAddress = config.getIpAddress();
        }
        builder.setNamespace(config.getNamespace()).setInstanceId(instanceId).setAppName(config.getAppname()).setAppGroupName(config.getAppGroupName()).setDataCenterInfo(config.getDataCenterInfo()).setIPAddr(config.getIpAddress()).setHostName(defaultAddress).setPort(config.getNonSecurePort()).enablePort(PortType.UNSECURE, config.isNonSecurePortEnabled()).setSecurePort(config.getSecurePort()).enablePort(PortType.SECURE, config.getSecurePortEnabled()).setVIPAddress(config.getVirtualHostName()).setSecureVIPAddress(config.getSecureVirtualHostName()).setHomePageUrl(config.getHomePageUrlPath(), config.getHomePageUrl()).setStatusPageUrl(config.getStatusPageUrlPath(), config.getStatusPageUrl()).setASGName(config.getASGName()).setHealthCheckUrls(config.getHealthCheckUrlPath(), config.getHealthCheckUrl(), config.getSecureHealthCheckUrl());
        // Start off with the STARTING state to avoid traffic
        if (!config.isInstanceEnabledOnit()) {
            InstanceStatus initialStatus = InstanceStatus.STARTING;
            LOG.info("Setting initial instance status as: " + initialStatus);
            builder.setStatus(initialStatus);
        } else {
            LOG.info("Setting initial instance status as: {}. This may be too early for the instance to advertise " + "itself as available. You would instead want to control this via a healthcheck handler.", InstanceStatus.UP);
        }
        // Add any user-specific metadata information
        for (Map.Entry<String, String> mapEntry : config.getMetadataMap().entrySet()) {
            String key = mapEntry.getKey();
            String value = mapEntry.getValue();
            builder.add(key, value);
        }
        instanceInfo = builder.build();
        instanceInfo.setLeaseInfo(leaseInfoBuilder.build());
    }
    return instanceInfo;
}
Also used : UniqueIdentifier(com.netflix.appinfo.UniqueIdentifier) InstanceStatus(com.netflix.appinfo.InstanceInfo.InstanceStatus) DataCenterInfo(com.netflix.appinfo.DataCenterInfo) RefreshableInstanceConfig(com.netflix.appinfo.RefreshableInstanceConfig) LeaseInfo(com.netflix.appinfo.LeaseInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) Map(java.util.Map)

Example 9 with DataCenterInfo

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

the class InstanceInfoReplicatorTest method setUp.

@Before
public void setUp() throws Exception {
    discoveryClient = mock(DiscoveryClient.class);
    HealthCheckHandler healthCheckHandler = mock(HealthCheckHandler.class);
    when(discoveryClient.getHealthCheckHandler()).thenReturn(healthCheckHandler);
    when(healthCheckHandler.getStatus(any(InstanceInfo.InstanceStatus.class))).thenReturn(null);
    InstanceInfo.Builder builder = InstanceInfo.Builder.newBuilder().setIPAddr("10.10.101.00").setHostName("Hosttt").setAppName("EurekaTestApp-" + UUID.randomUUID()).setDataCenterInfo(new DataCenterInfo() {

        @Override
        public Name getName() {
            return Name.MyOwn;
        }
    }).setLeaseInfo(LeaseInfo.Builder.newBuilder().setRenewalIntervalInSecs(30).build());
    InstanceInfo instanceInfo = builder.build();
    instanceInfo.setStatus(InstanceInfo.InstanceStatus.DOWN);
    this.replicator = new InstanceInfoReplicator(discoveryClient, instanceInfo, refreshRateSeconds, burstSize);
}
Also used : DataCenterInfo(com.netflix.appinfo.DataCenterInfo) HealthCheckHandler(com.netflix.appinfo.HealthCheckHandler) InstanceInfo(com.netflix.appinfo.InstanceInfo) Before(org.junit.Before)

Example 10 with DataCenterInfo

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

Aggregations

DataCenterInfo (com.netflix.appinfo.DataCenterInfo)16 InstanceInfo (com.netflix.appinfo.InstanceInfo)10 AmazonInfo (com.netflix.appinfo.AmazonInfo)5 Test (org.junit.Test)5 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)2 MyDataCenterInstanceConfig (com.netflix.appinfo.MyDataCenterInstanceConfig)2 UniqueIdentifier (com.netflix.appinfo.UniqueIdentifier)2 Before (org.junit.Before)2 HealthCheckHandler (com.netflix.appinfo.HealthCheckHandler)1 InstanceStatus (com.netflix.appinfo.InstanceInfo.InstanceStatus)1 LeaseInfo (com.netflix.appinfo.LeaseInfo)1 RefreshableInstanceConfig (com.netflix.appinfo.RefreshableInstanceConfig)1 Applications (com.netflix.discovery.shared.Applications)1 AwsEndpoint (com.netflix.discovery.shared.resolver.aws.AwsEndpoint)1 EurekaEntityFunctions.copyApplications (com.netflix.discovery.util.EurekaEntityFunctions.copyApplications)1 EurekaEntityFunctions.mergeApplications (com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications)1 EurekaEntityFunctions.toApplications (com.netflix.discovery.util.EurekaEntityFunctions.toApplications)1 InstanceInfoGenerator (com.netflix.discovery.util.InstanceInfoGenerator)1 Map (java.util.Map)1 Consumes (javax.ws.rs.Consumes)1