protected Builder templateFor(String name) { HashSet<String> healthCheckUrls = new HashSet<>(); healthCheckUrls.add("http://eureka/healthCheck/" + name + "1"); healthCheckUrls.add("http://eureka/healthCheck/" + name + "2"); HashSet<Integer> ports = new HashSet<>(); ports.add(80); ports.add(8080); HashSet<Integer> securePorts = new HashSet<>(); securePorts.add(443); securePorts.add(8443); return new Builder() .withId("id#" + name + "_" + UUID.randomUUID().toString()) .withApp("app#" + name) .withAppGroup("group#" + name) .withAsg("asg#" + name) .withHealthCheckUrls(healthCheckUrls) .withHomePageUrl("http://eureka/home/" + name) .withPorts(Sets.asSet(new ServicePort(7200, false), new ServicePort(7210, true))) .withSecureVipAddress("vipSecure#" + name) .withStatus(Status.UP) .withStatusPageUrl("http://eureka/status/" + name) .withVipAddress("vip#" + name) .withMetaData("optionA", "valueA") .withMetaData("optionB", "valueB") .withDataCenterInfo(SampleAwsDataCenterInfo.UsEast1a.build()); }
@Override public InstanceInfo next() { int cidx = idx.incrementAndGet(); String name = baseName + '_' + cidx; NetworkAddress publicAddress = publicAddresses.next(); NetworkAddress privateAddress = privateAddresses.next(); DataCenterInfo dataCenter = new AwsDataCenterInfo.Builder() .withAwsDataCenter(templateDataCenter) .withPublicHostName(publicAddress.getHostName()) .withPublicIPv4(publicAddress.getIpAddress()) .withPrivateHostName(privateAddress.getHostName()) .withPrivateIPv4(privateAddress.getIpAddress()) .build(); return new InstanceInfo.Builder() .withId("id#" + name) .withApp("app#" + baseName) .withAppGroup("group#" + baseName) .withAsg("asg#" + baseName) .withHealthCheckUrls(template.getHealthCheckUrls()) .withHomePageUrl(template.getHomePageUrl()) .withPorts(template.getPorts()) .withSecureVipAddress("vipSecure#" + name) .withStatus(template.getStatus()) .withStatusPageUrl(template.getStatusPageUrl()) .withVipAddress("vip#" + baseName) .withMetaData(template.getMetaData()) .withDataCenterInfo(dataCenter) .build(); }
@Override public InstanceInfo fromV1(com.netflix.appinfo.InstanceInfo v1Info) { InstanceInfo.Builder builder = new InstanceInfo.Builder() .withId(v1Info.getAppName() + "_" + v1Info.getId()) // instanceId is not unique for v1Data .withAppGroup(v1Info.getAppGroupName()) .withApp(v1Info.getAppName()) .withAsg(v1Info.getASGName()) .withVipAddress(v1Info.getVIPAddress()) .withSecureVipAddress(v1Info.getSecureVipAddress()) .withPorts(toSet(new ServicePort(v1Info.getPort(), false), new ServicePort(v1Info.getSecurePort(), true))) .withStatus(fromV1(v1Info.getStatus())) .withHomePageUrl(v1Info.getHomePageUrl()) .withStatusPageUrl(v1Info.getStatusPageUrl()) .withHealthCheckUrls(new HashSet<>(v1Info.getHealthCheckUrls())) .withMetaData(v1Info.getMetadata()) .withDataCenterInfo(fromV1(v1Info.getDataCenterInfo())); return builder.build(); }
@Override public Builder builder() { Builder builder = templateFor(this.name()); builder.withPorts(Sets.asSet( SampleServicePort.EurekaDiscoveryPort.build() )); return builder; } };
protected InstanceInfo buildClientInfo(String name) { return new Builder() .withId("id#" + name) .withApp("app#" + name) .withAppGroup("appGroup#" + name) .withVipAddress("vip#" + name) .withStatus(Status.UP) .withPorts(SampleServicePort.httpPorts()) .withDataCenterInfo(SampleAwsDataCenterInfo.UsEast1a.build()) .build(); } }
protected Builder eurekaWriteTemplate(int idx) { Builder builder = templateFor(this.name() + '#' + idx); builder.withPorts(Sets.asSet( SampleServicePort.EurekaRegistrationPort.build(), SampleServicePort.EurekaDiscoveryPort.build(), SampleServicePort.EurekaReplicationPort.build() )); return builder; }