use of com.netflix.turbine.discovery.Instance in project spring-cloud-netflix by spring-cloud.
the class CommonsInstanceDiscovery method getInstancesForApp.
/**
* helper that fetches the Instances for each application from DiscoveryClient.
* @param serviceId
* @return List<Instance>
* @throws Exception
*/
protected List<Instance> getInstancesForApp(String serviceId) throws Exception {
List<Instance> instances = new ArrayList<>();
log.info("Fetching instances for app: " + serviceId);
List<ServiceInstance> serviceInstances = discoveryClient.getInstances(serviceId);
if (serviceInstances == null || serviceInstances.isEmpty()) {
log.warn("DiscoveryClient returned null or empty for service: " + serviceId);
return instances;
}
try {
log.info("Received instance list for service: " + serviceId + ", size=" + serviceInstances.size());
for (ServiceInstance serviceInstance : serviceInstances) {
Instance instance = marshall(serviceInstance);
if (instance != null) {
instances.add(instance);
}
}
} catch (Exception e) {
log.warn("Failed to retrieve instances from DiscoveryClient", e);
}
return instances;
}
use of com.netflix.turbine.discovery.Instance in project spring-cloud-netflix by spring-cloud.
the class EurekaInstanceDiscoveryTests method testSecureCombineHostPort.
@Test
public void testSecureCombineHostPort() {
turbineProperties.setCombineHostPort(true);
EurekaInstanceDiscovery discovery = new EurekaInstanceDiscovery(turbineProperties, eurekaClient);
String appName = "testAppName";
int port = 8080;
int securePort = 8443;
String hostName = "myhost";
InstanceInfo instanceInfo = builder.setAppName(appName).setHostName(hostName).setPort(port).setSecurePort(securePort).enablePort(InstanceInfo.PortType.SECURE, true).build();
Instance instance = discovery.marshall(instanceInfo);
assertEquals("port is wrong", String.valueOf(port), instance.getAttributes().get("port"));
assertEquals("securePort is wrong", String.valueOf(securePort), instance.getAttributes().get("securePort"));
String urlPath = SpringClusterMonitor.ClusterConfigBasedUrlClosure.getUrlPath(instance);
assertEquals("url is wrong", "https://" + hostName + ":" + securePort + "/actuator/hystrix.stream", urlPath);
}
use of com.netflix.turbine.discovery.Instance in project spring-cloud-netflix by spring-cloud.
the class EurekaInstanceDiscoveryTests method testGetSecurePort.
@Test
public void testGetSecurePort() {
EurekaInstanceDiscovery discovery = new EurekaInstanceDiscovery(turbineProperties, eurekaClient);
String appName = "testAppName";
int port = 8080;
int securePort = 8443;
String hostName = "myhost";
InstanceInfo instanceInfo = builder.setAppName(appName).setHostName(hostName).setPort(port).setSecurePort(securePort).enablePort(InstanceInfo.PortType.SECURE, true).build();
Instance instance = discovery.marshall(instanceInfo);
assertEquals("port is wrong", String.valueOf(port), instance.getAttributes().get("port"));
assertEquals("securePort is wrong", String.valueOf(securePort), instance.getAttributes().get("securePort"));
String urlPath = SpringClusterMonitor.ClusterConfigBasedUrlClosure.getUrlPath(instance);
assertEquals("url is wrong", "https://" + hostName + ":" + securePort + "/actuator/hystrix.stream", urlPath);
}
use of com.netflix.turbine.discovery.Instance in project spring-cloud-netflix by spring-cloud.
the class CommonsInstanceDiscoveryTests method testCombineHostPort.
@Test
public void testCombineHostPort() {
turbineProperties.setCombineHostPort(true);
CommonsInstanceDiscovery discovery = createDiscovery();
String appName = "testAppName";
int port = 8080;
String hostName = "myhost";
DefaultServiceInstance serviceInstance = new DefaultServiceInstance(appName, hostName, port, false);
Instance instance = discovery.marshall(serviceInstance);
assertEquals("hostname is wrong", hostName + ":" + port, instance.getHostname());
assertEquals("port is wrong", String.valueOf(port), instance.getAttributes().get("port"));
String urlPath = SpringClusterMonitor.ClusterConfigBasedUrlClosure.getUrlPath(instance);
assertEquals("url is wrong", "http://" + hostName + ":" + port + "/actuator/hystrix.stream", urlPath);
String clusterName = discovery.getClusterName(serviceInstance);
assertEquals("clusterName is wrong", appName, clusterName);
}
use of com.netflix.turbine.discovery.Instance in project spring-cloud-netflix by spring-cloud.
the class CommonsInstanceDiscoveryTests method testUseManagementPortFromMetadata.
@Test
public void testUseManagementPortFromMetadata() {
CommonsInstanceDiscovery discovery = createDiscovery();
String appName = "testAppName";
int port = 8080;
int managementPort = 8081;
String hostName = "myhost";
DefaultServiceInstance serviceInstance = new DefaultServiceInstance(appName, hostName, port, false);
serviceInstance.getMetadata().put("management.port", String.valueOf(managementPort));
Instance instance = discovery.marshall(serviceInstance);
assertEquals("port is wrong", String.valueOf(managementPort), instance.getAttributes().get("port"));
String urlPath = SpringClusterMonitor.ClusterConfigBasedUrlClosure.getUrlPath(instance);
assertEquals("url is wrong", "http://" + hostName + ":" + managementPort + "/actuator/hystrix.stream", urlPath);
}
Aggregations