Search in sources :

Example 1 with Builder

use of com.netflix.appinfo.InstanceInfo.Builder in project eureka by Netflix.

the class InstanceInfoTest method testHealthCheckSetContainsValidUrlEntries.

@Test
public void testHealthCheckSetContainsValidUrlEntries() throws Exception {
    Builder builder = newBuilder().setAppName("test").setNamespace("eureka.").setHostName("localhost").setPort(80).setSecurePort(443).enablePort(PortType.SECURE, true);
    // No health check URLs
    InstanceInfo noHealtcheckInstanceInfo = builder.build();
    assertThat(noHealtcheckInstanceInfo.getHealthCheckUrls().size(), is(equalTo(0)));
    // Now when health check is defined
    InstanceInfo instanceInfo = builder.setHealthCheckUrls("/healthcheck", "http://${eureka.hostname}/healthcheck", "https://${eureka.hostname}/healthcheck").build();
    assertThat(instanceInfo.getHealthCheckUrls().size(), is(equalTo(2)));
}
Also used : Builder.newBuilder(com.netflix.appinfo.InstanceInfo.Builder.newBuilder) Builder(com.netflix.appinfo.InstanceInfo.Builder) Test(org.junit.Test)

Example 2 with Builder

use of com.netflix.appinfo.InstanceInfo.Builder 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 3 with Builder

use of com.netflix.appinfo.InstanceInfo.Builder in project ribbon by Netflix.

the class DefaultNIWSServerListFilterTest method createServer.

private DiscoveryEnabledServer createServer(String host, int port, String zone) {
    AmazonInfo amazonInfo = AmazonInfo.Builder.newBuilder().addMetadata(AmazonInfo.MetaDataKey.availabilityZone, zone).build();
    Builder builder = InstanceInfo.Builder.newBuilder();
    InstanceInfo info = builder.setAppName("l10nservicegeneral").setDataCenterInfo(amazonInfo).setHostName(host).setPort(port).build();
    DiscoveryEnabledServer server = new DiscoveryEnabledServer(info, false, false);
    server.setZone(zone);
    return server;
}
Also used : Builder(com.netflix.appinfo.InstanceInfo.Builder) AmazonInfo(com.netflix.appinfo.AmazonInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Aggregations

Builder (com.netflix.appinfo.InstanceInfo.Builder)3 AmazonInfo (com.netflix.appinfo.AmazonInfo)2 InstanceInfo (com.netflix.appinfo.InstanceInfo)1 Builder.newBuilder (com.netflix.appinfo.InstanceInfo.Builder.newBuilder)1 LeaseInfo (com.netflix.appinfo.LeaseInfo)1 Test (org.junit.Test)1