use of org.springframework.cloud.client.ServiceInstance in project spring-cloud-config by spring-cloud.
the class DiscoveryClientConfigServiceBootstrapConfiguration method refresh.
private void refresh() {
try {
String serviceId = this.config.getDiscovery().getServiceId();
ServiceInstance server = this.instanceProvider.getConfigServerInstance(serviceId);
String url = getHomePage(server);
if (server.getMetadata().containsKey("password")) {
String user = server.getMetadata().get("user");
user = user == null ? "user" : user;
this.config.setUsername(user);
String password = server.getMetadata().get("password");
this.config.setPassword(password);
}
if (server.getMetadata().containsKey("configPath")) {
String path = server.getMetadata().get("configPath");
if (url.endsWith("/") && path.startsWith("/")) {
url = url.substring(0, url.length() - 1);
}
url = url + path;
}
this.config.setUri(url);
} catch (Exception ex) {
if (config.isFailFast()) {
throw ex;
} else {
logger.warn("Could not locate configserver via discovery", ex);
}
}
}
use of org.springframework.cloud.client.ServiceInstance in project spring-cloud-config by spring-cloud.
the class ConfigServerInstanceProvider method getConfigServerInstance.
@Retryable(interceptor = "configServerRetryInterceptor")
public ServiceInstance getConfigServerInstance(String serviceId) {
logger.debug("Locating configserver (" + serviceId + ") via discovery");
List<ServiceInstance> instances = this.client.getInstances(serviceId);
if (instances.isEmpty()) {
throw new IllegalStateException("No instances found of configserver (" + serviceId + ")");
}
ServiceInstance instance = instances.get(0);
logger.debug("Located configserver (" + serviceId + ") via discovery: " + instance);
return instance;
}
use of org.springframework.cloud.client.ServiceInstance in project tutorials by eugenp.
the class CacheConfiguration method hazelcastInstance.
@Bean
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
log.debug("Configuring Hazelcast");
Config config = new Config();
config.setInstanceName("carapp");
// The serviceId is by default the application's name, see Spring Boot's eureka.instance.appname property
String serviceId = discoveryClient.getLocalServiceInstance().getServiceId();
log.debug("Configuring Hazelcast clustering for instanceId: {}", serviceId);
// In development, everything goes through 127.0.0.1, with a different port
if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) {
log.debug("Application is running with the \"dev\" profile, Hazelcast " + "cluster will only work with localhost instances");
System.setProperty("hazelcast.local.localAddress", "127.0.0.1");
config.getNetworkConfig().setPort(serverProperties.getPort() + 5701);
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(true);
for (ServiceInstance instance : discoveryClient.getInstances(serviceId)) {
String clusterMember = "127.0.0.1:" + (instance.getPort() + 5701);
log.debug("Adding Hazelcast (dev) cluster member " + clusterMember);
config.getNetworkConfig().getJoin().getTcpIpConfig().addMember(clusterMember);
}
} else {
// Production configuration, one host per instance all using port 5701
config.getNetworkConfig().setPort(5701);
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(true);
for (ServiceInstance instance : discoveryClient.getInstances(serviceId)) {
String clusterMember = instance.getHost() + ":5701";
log.debug("Adding Hazelcast (prod) cluster member " + clusterMember);
config.getNetworkConfig().getJoin().getTcpIpConfig().addMember(clusterMember);
}
}
config.getMapConfigs().put("default", initializeDefaultMapConfig());
config.getMapConfigs().put("com.car.app.domain.*", initializeDomainMapConfig(jHipsterProperties));
return Hazelcast.newHazelcastInstance(config);
}
use of org.springframework.cloud.client.ServiceInstance in project spring-cloud-netflix by spring-cloud.
the class RibbonLoadBalancerClientTests method testReconstructURI.
private void testReconstructURI(String scheme) throws Exception {
RibbonServer server = getRibbonServer();
RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server);
ServiceInstance serviceInstance = client.choose(server.getServiceId());
URI uri = client.reconstructURI(serviceInstance, new URL(scheme + "://" + server.getServiceId()).toURI());
assertThat(uri).hasScheme(scheme).hasHost(serviceInstance.getHost()).hasPort(serviceInstance.getPort());
}
use of org.springframework.cloud.client.ServiceInstance in project spring-cloud-netflix by spring-cloud.
the class RibbonLoadBalancerClientTests method testReconstructHonorsRibbonServerScheme.
@Test
public void testReconstructHonorsRibbonServerScheme() {
RibbonServer server = new RibbonServer("testService", new Server("ws", "myhost", 9080), false, Collections.singletonMap("mykey", "myvalue"));
IClientConfig config = mock(IClientConfig.class);
when(config.get(CommonClientConfigKey.IsSecure)).thenReturn(false);
when(clientFactory.getClientConfig(server.getServiceId())).thenReturn(config);
RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server);
ServiceInstance serviceInstance = client.choose(server.getServiceId());
URI uri = client.reconstructURI(serviceInstance, URI.create("http://testService"));
assertThat(uri).hasScheme("ws").hasHost("myhost").hasPort(9080);
}
Aggregations