Search in sources :

Example 1 with LeaseInfo

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

the class InstanceInfoGenerator method generateInstanceInfo.

// useInstanceId to false to generate older InstanceInfo types that does not use instanceId field for instance id.
private InstanceInfo generateInstanceInfo(int appIndex, int appInstanceId, boolean useInstanceId) {
    String appName = appNames[appIndex];
    String hostName = "instance" + appInstanceId + '.' + appName + ".com";
    String privateHostname = "ip-10.0" + appIndex + "." + appInstanceId + ".compute.internal";
    String publicIp = "20.0." + appIndex + '.' + appInstanceId;
    String privateIp = "192.168." + appIndex + '.' + appInstanceId;
    String instanceId = String.format("i-%04d%04d", appIndex, appInstanceId);
    if (taggedId) {
        instanceId = instanceId + '_' + appName;
    }
    AmazonInfo dataCenterInfo = AmazonInfo.Builder.newBuilder().addMetadata(MetaDataKey.accountId, "testAccountId").addMetadata(MetaDataKey.amiId, String.format("ami-%04d%04d", appIndex, appInstanceId)).addMetadata(MetaDataKey.availabilityZone, zone).addMetadata(MetaDataKey.instanceId, instanceId).addMetadata(MetaDataKey.instanceType, "m2.xlarge").addMetadata(MetaDataKey.localHostname, privateHostname).addMetadata(MetaDataKey.localIpv4, privateIp).addMetadata(MetaDataKey.publicHostname, hostName).addMetadata(MetaDataKey.publicIpv4, publicIp).build();
    String unsecureURL = "http://" + hostName + ":8080";
    String secureURL = "https://" + hostName + ":8081";
    long now = System.currentTimeMillis();
    LeaseInfo leaseInfo = LeaseInfo.Builder.newBuilder().setDurationInSecs(3 * RENEW_INTERVAL).setRenewalIntervalInSecs(RENEW_INTERVAL).setServiceUpTimestamp(now - RENEW_INTERVAL).setRegistrationTimestamp(now).setEvictionTimestamp(now + 3 * RENEW_INTERVAL).setRenewalTimestamp(now + RENEW_INTERVAL).build();
    Builder builder = useInstanceId ? InstanceInfo.Builder.newBuilder().setInstanceId(instanceId) : InstanceInfo.Builder.newBuilder();
    builder.setActionType(ActionType.ADDED).setAppGroupName(appName + "Group").setAppName(appName).setHostName(hostName).setIPAddr(publicIp).setPort(8080).setSecurePort(8081).enablePort(PortType.SECURE, true).setHealthCheckUrls("/healthcheck", unsecureURL + "/healthcheck", secureURL + "/healthcheck").setHomePageUrl("/homepage", unsecureURL + "/homepage").setStatusPageUrl("/status", unsecureURL + "/status").setLeaseInfo(leaseInfo).setStatus(InstanceStatus.UP).setVIPAddress(appName + ":8080").setSecureVIPAddress(appName + ":8081").setDataCenterInfo(dataCenterInfo).setLastUpdatedTimestamp(System.currentTimeMillis() - 100).setLastDirtyTimestamp(System.currentTimeMillis() - 100).setIsCoordinatingDiscoveryServer(true).enablePort(PortType.UNSECURE, true);
    if (includeAsg) {
        builder.setASGName(appName + "ASG");
    }
    if (withMetaData) {
        builder.add("appKey" + appIndex, Integer.toString(appInstanceId));
    }
    return builder.build();
}
Also used : Builder(com.netflix.appinfo.InstanceInfo.Builder) LeaseInfo(com.netflix.appinfo.LeaseInfo) AmazonInfo(com.netflix.appinfo.AmazonInfo)

Example 2 with LeaseInfo

use of com.netflix.appinfo.LeaseInfo in project spring-cloud-netflix by spring-cloud.

the class InstanceRegistryTests method testRegister.

@Test
public void testRegister() throws Exception {
    // creating instance info
    final LeaseInfo leaseInfo = getLeaseInfo();
    final InstanceInfo instanceInfo = getInstanceInfo(APP_NAME, HOST_NAME, INSTANCE_ID, PORT, leaseInfo);
    // calling tested method
    instanceRegistry.register(instanceInfo, false);
    // event of proper type is registered
    assertEquals(1, this.testEvents.applicationEvents.size());
    assertTrue(this.testEvents.applicationEvents.get(0) instanceof EurekaInstanceRegisteredEvent);
    // event details are correct
    final EurekaInstanceRegisteredEvent registeredEvent = (EurekaInstanceRegisteredEvent) (this.testEvents.applicationEvents.get(0));
    assertEquals(instanceInfo, registeredEvent.getInstanceInfo());
    assertEquals(leaseInfo.getDurationInSecs(), registeredEvent.getLeaseDuration());
    assertEquals(instanceRegistry, registeredEvent.getSource());
    assertFalse(registeredEvent.isReplication());
}
Also used : LeaseInfo(com.netflix.appinfo.LeaseInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) EurekaInstanceRegisteredEvent(org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRegisteredEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with LeaseInfo

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

the class InstanceInfoGenerator method generateInstanceInfo.

// useInstanceId to false to generate older InstanceInfo types that does not use instanceId field for instance id.
private InstanceInfo generateInstanceInfo(int appIndex, int appInstanceId, boolean useInstanceId, ActionType actionType) {
    String appName = appNames[appIndex];
    String hostName = "instance" + appInstanceId + '.' + appName + ".com";
    String privateHostname = "ip-10.0" + appIndex + "." + appInstanceId + ".compute.internal";
    String publicIp = "20.0." + appIndex + '.' + appInstanceId;
    String privateIp = "192.168." + appIndex + '.' + appInstanceId;
    String ipv6 = "::FFFF:" + publicIp;
    String instanceId = String.format("i-%04d%04d", appIndex, appInstanceId);
    if (taggedId) {
        instanceId = instanceId + '_' + appName;
    }
    AmazonInfo dataCenterInfo = AmazonInfo.Builder.newBuilder().addMetadata(MetaDataKey.accountId, "testAccountId").addMetadata(MetaDataKey.amiId, String.format("ami-%04d%04d", appIndex, appInstanceId)).addMetadata(MetaDataKey.availabilityZone, zone).addMetadata(MetaDataKey.instanceId, instanceId).addMetadata(MetaDataKey.instanceType, "m2.xlarge").addMetadata(MetaDataKey.localHostname, privateHostname).addMetadata(MetaDataKey.localIpv4, privateIp).addMetadata(MetaDataKey.publicHostname, hostName).addMetadata(MetaDataKey.publicIpv4, publicIp).addMetadata(MetaDataKey.ipv6, ipv6).build();
    String unsecureURL = "http://" + hostName + ":8080";
    String secureURL = "https://" + hostName + ":8081";
    long now = System.currentTimeMillis();
    LeaseInfo leaseInfo = LeaseInfo.Builder.newBuilder().setDurationInSecs(3 * RENEW_INTERVAL).setRenewalIntervalInSecs(RENEW_INTERVAL).setServiceUpTimestamp(now - RENEW_INTERVAL).setRegistrationTimestamp(now).setEvictionTimestamp(now + 3 * RENEW_INTERVAL).setRenewalTimestamp(now + RENEW_INTERVAL).build();
    Builder builder = useInstanceId ? InstanceInfo.Builder.newBuilder().setInstanceId(instanceId) : InstanceInfo.Builder.newBuilder();
    builder.setActionType(actionType).setAppGroupName(appName + "Group").setAppName(appName).setHostName(hostName).setIPAddr(publicIp).setPort(8080).setSecurePort(8081).enablePort(PortType.SECURE, true).setHealthCheckUrls("/healthcheck", unsecureURL + "/healthcheck", secureURL + "/healthcheck").setHomePageUrl("/homepage", unsecureURL + "/homepage").setStatusPageUrl("/status", unsecureURL + "/status").setLeaseInfo(leaseInfo).setStatus(InstanceStatus.UP).setVIPAddress(appName + ":8080").setSecureVIPAddress(appName + ":8081").setDataCenterInfo(dataCenterInfo).setLastUpdatedTimestamp(System.currentTimeMillis() - 100).setLastDirtyTimestamp(System.currentTimeMillis() - 100).setIsCoordinatingDiscoveryServer(true).enablePort(PortType.UNSECURE, true);
    if (includeAsg) {
        builder.setASGName(appName + "ASG");
    }
    if (withMetaData) {
        builder.add("appKey" + appIndex, Integer.toString(appInstanceId));
    }
    return builder.build();
}
Also used : Builder(com.netflix.appinfo.InstanceInfo.Builder) LeaseInfo(com.netflix.appinfo.LeaseInfo) AmazonInfo(com.netflix.appinfo.AmazonInfo)

Example 4 with LeaseInfo

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

the class DiscoveryClientRegisterUpdateTest method setUp.

@Before
public void setUp() throws Exception {
    mockLocalEurekaServer = new MockRemoteEurekaServer();
    mockLocalEurekaServer.start();
    ConfigurationManager.getConfigInstance().setProperty("eureka.name", "EurekaTestApp-" + UUID.randomUUID());
    ConfigurationManager.getConfigInstance().setProperty("eureka.registration.enabled", "true");
    ConfigurationManager.getConfigInstance().setProperty("eureka.appinfo.replicate.interval", 4);
    ConfigurationManager.getConfigInstance().setProperty("eureka.shouldFetchRegistry", "false");
    ConfigurationManager.getConfigInstance().setProperty("eureka.serviceUrl.default", "http://localhost:" + mockLocalEurekaServer.getPort() + MockRemoteEurekaServer.EUREKA_API_BASE_PATH);
    InstanceInfo seed = InstanceInfoGenerator.takeOne();
    LeaseInfo leaseSeed = seed.getLeaseInfo();
    LeaseInfo leaseInfo = LeaseInfo.Builder.newBuilder().setDurationInSecs(leaseSeed.getDurationInSecs()).setEvictionTimestamp(leaseSeed.getEvictionTimestamp()).setRegistrationTimestamp(leaseSeed.getRegistrationTimestamp()).setServiceUpTimestamp(leaseSeed.getServiceUpTimestamp()).setRenewalTimestamp(leaseSeed.getRenewalTimestamp()).setRenewalIntervalInSecs(// make this more frequent for testing
    4).build();
    InstanceInfo instanceInfo = new InstanceInfo.Builder(seed).setStatus(InstanceInfo.InstanceStatus.STARTING).setLeaseInfo(leaseInfo).build();
    applicationInfoManager = new TestApplicationInfoManager(instanceInfo);
    client = Mockito.spy(new TestClient(applicationInfoManager, new DefaultEurekaClientConfig()));
    // force the initial registration to eagerly run
    InstanceInfoReplicator instanceInfoReplicator = ((DiscoveryClient) client).getInstanceInfoReplicator();
    instanceInfoReplicator.run();
    // give some execution time for the initial registration to process
    expectStatus(InstanceInfo.InstanceStatus.STARTING, 4000, TimeUnit.MILLISECONDS);
    // and then clear the validation list
    mockLocalEurekaServer.registrationStatuses.clear();
    mockLocalEurekaServer.registerCount.set(0l);
}
Also used : LeaseInfo(com.netflix.appinfo.LeaseInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) Before(org.junit.Before)

Example 5 with LeaseInfo

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

the class EurekaJsonAndXmlJacksonCodecTest method doLeaseInfoEncodeDecode.

private void doLeaseInfoEncodeDecode(AbstractEurekaJacksonCodec codec) throws Exception {
    LeaseInfo leaseInfo = infoIterator.next().getLeaseInfo();
    String encodedString = codec.getObjectMapper(LeaseInfo.class).writeValueAsString(leaseInfo);
    LeaseInfo decodedValue = codec.getObjectMapper(LeaseInfo.class).readValue(encodedString, LeaseInfo.class);
    assertThat(EurekaEntityComparators.equal(leaseInfo, decodedValue), is(true));
}
Also used : LeaseInfo(com.netflix.appinfo.LeaseInfo)

Aggregations

LeaseInfo (com.netflix.appinfo.LeaseInfo)6 InstanceInfo (com.netflix.appinfo.InstanceInfo)3 AmazonInfo (com.netflix.appinfo.AmazonInfo)2 Builder (com.netflix.appinfo.InstanceInfo.Builder)2 Application (com.netflix.discovery.shared.Application)1 PeerEurekaNode (com.netflix.eureka.cluster.PeerEurekaNode)1 URI (java.net.URI)1 Before (org.junit.Before)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 EurekaInstanceRegisteredEvent (org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRegisteredEvent)1