use of org.springframework.cloud.client.ServiceInstance 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 org.springframework.cloud.client.ServiceInstance in project micro-service by Lovnx.
the class ComputeController method add.
// static{
// Timer timer = new Timer();
// timer.schedule(new TimerTask(){
// @Override
// public void run() {
// num.set(0);;
// }
// }, 0, timeRound);
// }
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String add(@RequestParam Integer a, @RequestParam Integer b) {
// num.incrementAndGet();
//
// if (num.get() <= flag) {
// ServiceInstance instance = client.getLocalServiceInstance();
// Integer r = a + b;
// logger.info("/add, host:" + instance.getHost() + ", service_id:" + instance.getServiceId() + ", result:" + r);
// return "From Service-B, Result is " + r+"\nPort:"+instance.getPort();
// }
// return "调用次数超限,一分钟内最多只能调用10次!";
InterfaceLimit limit = service.getEntityByPri(1);
Jedis jedis = RedisUtils.getJedis();
// redis存的超时时间
String timeRound_1 = jedis.get("timeRound_1");
// 如果不存在或者是不等于数据库设置值
if (timeRound_1 == null || !limit.getUnitTime().toString().equals(timeRound_1)) {
// 重新设置超时时间
jedis.set("timeRound_1", limit.getUnitTime().toString());
jedis.expire("num_1", limit.getUnitTime());
}
String num_1 = jedis.get("num_1");
if (num_1 == null) {
jedis.set("num_1", String.valueOf(0));
jedis.expire("num_1", limit.getUnitTime());
}
jedis.incr("num_1");
if (Integer.parseInt(jedis.get("num_1")) <= limit.getUnitNum()) {
ServiceInstance instance = client.getLocalServiceInstance();
Integer r = a + b;
logger.info("/add, host:" + instance.getHost() + ", service_id:" + instance.getServiceId() + ", result:" + r);
return "From Service-B, Result is " + r + "\nPort:" + instance.getPort();
}
return "调用次数超限!";
}
use of org.springframework.cloud.client.ServiceInstance in project spring-boot-admin by codecentric.
the class DefaultServiceInstanceConverterTest method should_convert_service_with_uri.
@Test
public void should_convert_service_with_uri() {
ServiceInstance service = new TestServiceInstance("test", URI.create("http://localhost/test"), Collections.emptyMap());
Registration registration = new DefaultServiceInstanceConverter().convert(service);
assertThat(registration.getName()).isEqualTo("test");
assertThat(registration.getServiceUrl()).isEqualTo("http://localhost/test");
assertThat(registration.getManagementUrl()).isEqualTo("http://localhost/test/actuator");
assertThat(registration.getHealthUrl()).isEqualTo("http://localhost/test/actuator/health");
assertThat(registration.getMetadata()).isEmpty();
}
use of org.springframework.cloud.client.ServiceInstance in project spring-boot-admin by codecentric.
the class DefaultServiceInstanceConverterTest method should_convert_with_defaults.
@Test
public void should_convert_with_defaults() {
ServiceInstance service = new DefaultServiceInstance("test-1", "test", "localhost", 80, false);
Registration registration = new DefaultServiceInstanceConverter().convert(service);
assertThat(registration.getName()).isEqualTo("test");
assertThat(registration.getServiceUrl()).isEqualTo("http://localhost:80");
assertThat(registration.getManagementUrl()).isEqualTo("http://localhost:80/actuator");
assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:80/actuator/health");
}
use of org.springframework.cloud.client.ServiceInstance in project spring-boot-admin by codecentric.
the class DefaultServiceInstanceConverterTest method should_convert_service_with_uri_and_custom_defaults.
@Test
public void should_convert_service_with_uri_and_custom_defaults() {
DefaultServiceInstanceConverter converter = new DefaultServiceInstanceConverter();
converter.setHealthEndpointPath("ping");
converter.setManagementContextPath("mgmt");
ServiceInstance service = new TestServiceInstance("test", URI.create("http://localhost/test"), Collections.emptyMap());
Registration registration = converter.convert(service);
assertThat(registration.getName()).isEqualTo("test");
assertThat(registration.getServiceUrl()).isEqualTo("http://localhost/test");
assertThat(registration.getManagementUrl()).isEqualTo("http://localhost/test/mgmt");
assertThat(registration.getHealthUrl()).isEqualTo("http://localhost/test/mgmt/ping");
}
Aggregations