@Override public InstanceInfo.Builder call(HashSet<ServicePort> ports) { ports.add(new ServicePort(Names.EUREKA_HTTP, httpServer.serverPort(), false)); ports.add(new ServicePort(Names.REGISTRATION, registrationServer.serverPort(), false)); ports.add(new ServicePort(Names.REPLICATION, replicationServer.serverPort(), false)); ports.add(new ServicePort(Names.DISCOVERY, discoveryServer.serverPort(), false)); return new InstanceInfo.Builder().withPorts(ports); } })
protected Builder templateFor(String name) { HashSet<String> healthCheckUrls = new HashSet<>(); healthCheckUrls.add("http://eureka/healthCheck/" + name); healthCheckUrls.add("https://eureka/healthCheck/" + name); 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(ExtCollections.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()); }
@Inject public DashboardServerSelfInfoResolver(final EurekaCommonConfig config, final WebSocketServer webSocketServer) { SelfInfoResolverChain resolverChain = new SelfInfoResolverChain( new ConfigSelfInfoResolver(config), // dashboard server specific resolver new ChainableSelfInfoResolver(Observable.just(new HashSet<ServicePort>()) .map(new Func1<HashSet<ServicePort>, Builder>() { @Override public InstanceInfo.Builder call(HashSet<ServicePort> ports) { ports.add(new ServicePort(WEB_SOCKET_SERVICE, webSocketServer.serverPort(), false)); return new InstanceInfo.Builder().withPorts(ports); } }) ), new PeriodicDataCenterInfoResolver(config), // TODO override with more meaningful health check new ChainableSelfInfoResolver(Observable.just(new InstanceInfo.Builder().withStatus(InstanceInfo.Status.UP))) ); this.delegate = new CachingSelfInfoResolver(resolverChain); }
public void start() { final long startTime = scheduler.now(); final InstanceInfo taggedInstanceInfo = new InstanceInfo.Builder() .withInstanceInfo(selfInfo) .withMetaData(TopologyFunctions.TIME_STAMP_KEY, Long.toString(startTime))
InstanceInfo updatedInfo = new Builder().withInstanceInfo(SERVICE_A).withStatus(Status.DOWN).build(); infoSubject.onNext(updatedInfo); Thread.sleep(1000);
NetworkAddress publicAddress = publicAddresses.next(); NetworkAddress privateAddress = privateAddresses.next(); DataCenterInfo dataCenter = new AwsDataCenterInfo.Builder() .withAwsDataCenter(templateDataCenter) .withInstanceId(String.format("i-%s-%08d", baseName, cidx)) .withPrivateIPv4(privateAddress.getIpAddress()) .build(); return new InstanceInfo.Builder() .withId("id#" + name) .withApp(template.getApp())
@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) .withInstanceId(String.format("i-%s-%08d", baseName, cidx)) .withPublicHostName(publicAddress.getHostName()) .withPublicIPv4(publicAddress.getIpAddress()) .withPrivateHostName(privateAddress.getHostName()) .withPrivateIPv4(privateAddress.getIpAddress()) .build(); return new InstanceInfo.Builder() .withId("id#" + name) .withApp(template.getApp()) .withAppGroup(template.getAppGroup()) .withAsg(template.getAsg()) .withHealthCheckUrls(template.getHealthCheckUrls()) .withHomePageUrl(template.getHomePageUrl()) .withPorts(template.getPorts()) .withSecureVipAddress(template.getSecureVipAddress()) .withStatus(template.getStatus()) .withStatusPageUrl(template.getStatusPageUrl()) .withVipAddress(template.getVipAddress()) .withMetaData(template.getMetaData()) .withDataCenterInfo(dataCenter) .build(); }
public static Service createServiceOf(String serverId, Application application, DataCenterInfoGenerator dataCenterInfoGenerator) { String id = application.getServiceName(); HashSet<String> healthcheckURLs = new HashSet<>(); healthcheckURLs.add("TODO"); Map<String, String> metaData = new HashMap<>(); metaData.put("key1", "value1"); Builder builder = new Builder() .withId(id) .withApp(application.getName()) .withAppGroup(application.getName() + "_group") .withAsg(application.getName() + "_asg") .withDataCenterInfo(dataCenterInfoGenerator.next()) .withHealthCheckUrls(healthcheckURLs) .withHomePageUrl("TODO") .withMetaData(metaData) .withPorts(SampleServicePort.httpPorts()) .withVipAddress(application.getName() + "_vip") .withSecureVipAddress(application.getName() + "_secureVip") .withStatus(Status.UP) .withStatusPageUrl("TODO"); if (serverId != null) { builder.withMetaData(TopologyFunctions.SERVER_ID_KEY, serverId); } InstanceInfo selfInfo = builder.build(); return new Service(application, selfInfo); } }
@Inject public EurekaWriteServerSelfInfoResolver( final EurekaServerConfig config, final EurekaHttpServer httpServer, final TcpRegistrationServer registrationServer, final TcpReplicationServer replicationServer, final TcpDiscoveryServer discoveryServer) { SelfInfoResolverChain resolverChain = new SelfInfoResolverChain( new ConfigSelfInfoResolver(config), // write server specific resolver new ChainableSelfInfoResolver(Observable.just(new HashSet<ServicePort>()) .map(new Func1<HashSet<ServicePort>, InstanceInfo.Builder>() { @Override public InstanceInfo.Builder call(HashSet<ServicePort> ports) { ports.add(new ServicePort(Names.EUREKA_HTTP, httpServer.serverPort(), false)); ports.add(new ServicePort(Names.REGISTRATION, registrationServer.serverPort(), false)); ports.add(new ServicePort(Names.REPLICATION, replicationServer.serverPort(), false)); ports.add(new ServicePort(Names.DISCOVERY, discoveryServer.serverPort(), false)); return new InstanceInfo.Builder().withPorts(ports); } }) ), new PeriodicDataCenterInfoResolver(config), // TODO override with more meaningful health check new ChainableSelfInfoResolver(Observable.just(new InstanceInfo.Builder().withStatus(InstanceInfo.Status.UP))) ); delegate = new CachingSelfInfoResolver(resolverChain); }
@Inject public EurekaBridgeServerSelfInfoResolver( final EurekaServerConfig config, final TcpDiscoveryServer discoveryServer) { SelfInfoResolverChain resolverChain = new SelfInfoResolverChain( new ConfigSelfInfoResolver(config), // read server specific resolver new ChainableSelfInfoResolver(Observable.just(new HashSet<ServicePort>()) .map(new Func1<HashSet<ServicePort>, InstanceInfo.Builder>() { @Override public InstanceInfo.Builder call(HashSet<ServicePort> ports) { ports.add(new ServicePort(Names.DISCOVERY, discoveryServer.serverPort(), false)); return new InstanceInfo.Builder().withPorts(ports); } }) ), new PeriodicDataCenterInfoResolver(config), // TODO override with more meaningful health check new ChainableSelfInfoResolver(Observable.just(new InstanceInfo.Builder().withStatus(InstanceInfo.Status.UP))) ); delegate = new CachingSelfInfoResolver(resolverChain); }
@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(dataCenterFromV1(v1Info)); return builder.build(); }
@Override public InstanceInfo.Builder call(DataCenterInfo dataCenterInfo) { final String instanceId = config.getAppName() + '#' + UUID.randomUUID().toString();; String address = AddressSelector.selectBy().publicIp(true).or().any().returnNameOrIp(dataCenterInfo.getAddresses()); HashSet<String> healthCheckUrls = new HashSet<>(); healthCheckUrls.add("http://" + address + ':' + config.getWebAdminPort() + "/healthcheck"); return new InstanceInfo.Builder() .withId(instanceId) .withApp(config.getAppName()) .withVipAddress(config.getVipAddress()) .withHealthCheckUrls(healthCheckUrls) .withDataCenterInfo(dataCenterInfo) .withStatus(InstanceInfo.Status.STARTING); } })
private ChangeNotification<InstanceInfo> toChangeNotification(InterestSetNotification message) { if (message instanceof AddInstance) { return new ChangeNotification<>(Kind.Add, ((AddInstance) message).getInstanceInfo()); } if (message instanceof UpdateInstanceInfo) { InstanceInfo instanceInfo = new Builder().withId(((UpdateInstanceInfo) message).getDelta().getId()).build(); return new ChangeNotification<>(Kind.Modify, instanceInfo); } if (message instanceof DeleteInstance) { InstanceInfo instanceInfo = new Builder().withId(((DeleteInstance) message).getInstanceId()).build(); return new ChangeNotification<>(Kind.Delete, instanceInfo); } return null; } }
@Override public Builder call(HealthStatusUpdate<EurekaHealthStatusAggregator> statusUpdate) { return new InstanceInfo.Builder().withStatus(statusUpdate.getStatus()); } }));
@Override public InstanceInfo.Builder call(Object... args) { InstanceInfo.Builder seed = new InstanceInfo.Builder(); for (Object obj : args) { InstanceInfo.Builder builder = (InstanceInfo.Builder) obj; seed.withBuilder(new InstanceInfo.Builder().withBuilder(builder)); // clone at each step } return seed; } })
/** * Apply the delta instance to the current InstanceInfo * * @param delta the delta changes to applyTo * @return a new InstanceInfo with the deltas applied */ public InstanceInfo applyDelta(Delta delta) { if (!id.equals(delta.getId())) { throw new UnsupportedOperationException("Cannot apply delta to instanceInfo with non-matching id: " + delta.getId() + ", " + id); } InstanceInfo.Builder newInstanceInfoBuilder = new InstanceInfo.Builder().withInstanceInfo(this); return delta.applyTo(newInstanceInfoBuilder).build(); }
public static InstanceInfo addTimeStamp(InstanceInfo instanceInfo, long timeStamp) { return new InstanceInfo.Builder() .withInstanceInfo(instanceInfo) .withMetaData(TIME_STAMP_KEY, Long.toString(timeStamp)) .build(); }
@Override public InstanceInfo.Builder call(HashSet<ServicePort> ports) { ports.add(new ServicePort(Names.DISCOVERY, discoveryServer.serverPort(), false)); return new InstanceInfo.Builder().withPorts(ports); } })
@Override public InstanceInfo.Builder call(HashSet<ServicePort> ports) { ports.add(new ServicePort(WEB_SOCKET_SERVICE, webSocketServer.serverPort(), false)); return new InstanceInfo.Builder().withPorts(ports); } })
public static InstanceInfo addServerId(InstanceInfo instanceInfo, String serverId) { return new InstanceInfo.Builder() .withInstanceInfo(instanceInfo) .withMetaData(SERVER_ID_KEY, serverId) .build(); }