use of com.netflix.turbine.discovery.Instance in project spring-cloud-netflix by spring-cloud.
the class CommonsInstanceDiscoveryTests method testSecureCombineHostPort.
@Test
public void testSecureCombineHostPort() {
turbineProperties.setCombineHostPort(true);
CommonsInstanceDiscovery discovery = createDiscovery();
String appName = "testAppName";
int port = 8443;
String hostName = "myhost";
DefaultServiceInstance serviceInstance = new DefaultServiceInstance(appName, hostName, port, true);
Instance instance = discovery.marshall(serviceInstance);
assertEquals("port is wrong", String.valueOf(port), instance.getAttributes().get("port"));
assertEquals("securePort is wrong", String.valueOf(port), instance.getAttributes().get("securePort"));
String urlPath = SpringClusterMonitor.ClusterConfigBasedUrlClosure.getUrlPath(instance);
assertEquals("url is wrong", "https://" + hostName + ":" + port + "/actuator/hystrix.stream", urlPath);
}
use of com.netflix.turbine.discovery.Instance in project spring-cloud-netflix by spring-cloud.
the class CommonsInstanceDiscovery method marshall.
/**
* Private helper that marshals the information from each instance into something that
* Turbine can understand. Override this method for your own implementation.
* @param serviceInstance
* @return Instance
*/
Instance marshall(ServiceInstance serviceInstance) {
String hostname = serviceInstance.getHost();
String managementPort = serviceInstance.getMetadata().get("management.port");
String port = managementPort == null ? String.valueOf(serviceInstance.getPort()) : managementPort;
String cluster = getClusterName(serviceInstance);
// TODO: where to get?
Boolean status = Boolean.TRUE;
if (hostname != null && cluster != null && status != null) {
Instance instance = getInstance(hostname, port, cluster, status);
Map<String, String> metadata = serviceInstance.getMetadata();
boolean securePortEnabled = serviceInstance.isSecure();
addMetadata(instance, hostname, port, securePortEnabled, port, metadata);
return instance;
} else {
return null;
}
}
use of com.netflix.turbine.discovery.Instance in project spring-cloud-netflix by spring-cloud.
the class EurekaInstanceDiscovery method marshall.
/**
* Private helper that marshals the information from each instance into something that
* Turbine can understand. Override this method for your own implementation for
* parsing Eureka info.
* @param instanceInfo
* @return Instance
*/
Instance marshall(InstanceInfo instanceInfo) {
String hostname = instanceInfo.getHostName();
final String managementPort = instanceInfo.getMetadata().get("management.port");
String port = managementPort == null ? String.valueOf(instanceInfo.getPort()) : managementPort;
String cluster = getClusterName(instanceInfo);
Boolean status = parseInstanceStatus(instanceInfo.getStatus());
if (hostname != null && cluster != null && status != null) {
Instance instance = getInstance(hostname, port, cluster, status);
Map<String, String> metadata = instanceInfo.getMetadata();
boolean securePortEnabled = instanceInfo.isPortEnabled(InstanceInfo.PortType.SECURE);
String securePort = String.valueOf(instanceInfo.getSecurePort());
addMetadata(instance, hostname, port, securePortEnabled, securePort, metadata);
// add amazon metadata
String asgName = instanceInfo.getASGName();
if (asgName != null) {
instance.getAttributes().put(ASG_KEY, asgName);
}
DataCenterInfo dcInfo = instanceInfo.getDataCenterInfo();
if (dcInfo != null && dcInfo.getName().equals(DataCenterInfo.Name.Amazon)) {
AmazonInfo amznInfo = (AmazonInfo) dcInfo;
instance.getAttributes().putAll(amznInfo.getMetadata());
}
return instance;
} else {
return null;
}
}
use of com.netflix.turbine.discovery.Instance in project spring-cloud-netflix by spring-cloud.
the class EurekaInstanceDiscovery method getInstancesForApp.
/**
* Private helper that fetches the Instances for each application.
* @param serviceId
* @return List<Instance>
* @throws Exception
*/
@Override
protected List<Instance> getInstancesForApp(String serviceId) throws Exception {
List<Instance> instances = new ArrayList<>();
log.info("Fetching instances for app: " + serviceId);
Application app = eurekaClient.getApplication(serviceId);
if (app == null) {
log.warn("Eureka returned null for app: " + serviceId);
return instances;
}
try {
List<InstanceInfo> instancesForApp = app.getInstances();
if (instancesForApp != null) {
log.info("Received instance list for app: " + serviceId + ", size=" + instancesForApp.size());
for (InstanceInfo iInfo : instancesForApp) {
Instance instance = marshall(iInfo);
if (instance != null) {
instances.add(instance);
}
}
}
} catch (Exception e) {
log.warn("Failed to retrieve instances from Eureka", e);
}
return instances;
}
use of com.netflix.turbine.discovery.Instance in project spring-cloud-netflix by spring-cloud.
the class CommonsInstanceDiscoveryTests method testGetPort.
@Test
public void testGetPort() {
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("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);
}
Aggregations