Formatting changes
This commit is contained in:
parent
ea3fe7aab9
commit
4fece2266e
@ -9,7 +9,6 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
@EnableCircuitBreaker
|
@EnableCircuitBreaker
|
||||||
@ -18,7 +17,7 @@ public class Application {
|
|||||||
|
|
||||||
@LoadBalanced
|
@LoadBalanced
|
||||||
@Bean
|
@Bean
|
||||||
RestTemplate restTemplate(){
|
RestTemplate restTemplate() {
|
||||||
return new RestTemplate();
|
return new RestTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,13 +31,11 @@ public class ClientController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public String load() throws UnknownHostException {
|
public String load() {
|
||||||
|
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
String resourceUrl
|
String resourceUrl = "http://travel-agency-service:8080";
|
||||||
= "http://travel-agency-service:8080";
|
ResponseEntity<String> response = restTemplate.getForEntity(resourceUrl, String.class);
|
||||||
ResponseEntity<String> response
|
|
||||||
= restTemplate.getForEntity(resourceUrl, String.class);
|
|
||||||
|
|
||||||
String serviceList = "";
|
String serviceList = "";
|
||||||
if (discoveryClient != null) {
|
if (discoveryClient != null) {
|
||||||
@ -45,13 +43,12 @@ public class ClientController {
|
|||||||
|
|
||||||
for (String service : services) {
|
for (String service : services) {
|
||||||
|
|
||||||
List<ServiceInstance> instances = this.discoveryClient
|
List<ServiceInstance> instances = this.discoveryClient.getInstances(service);
|
||||||
.getInstances(service);
|
|
||||||
|
|
||||||
serviceList += ("[" + service + " : " + ((!CollectionUtils.isEmpty(instances))?instances.size():0)+ " instances ]");
|
serviceList += ("[" + service + " : " + ((!CollectionUtils.isEmpty(instances)) ? instances.size() : 0) + " instances ]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return String.format(config.getMessage(), response.getBody(),serviceList);
|
return String.format(config.getMessage(), response.getBody(), serviceList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,8 @@ public class TravelAgencyService {
|
|||||||
this.restTemplate = restTemplate;
|
this.restTemplate = restTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@HystrixCommand(fallbackMethod = "getFallbackName", commandProperties = {
|
@HystrixCommand(fallbackMethod = "getFallbackName", commandProperties =
|
||||||
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000")
|
{ @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000") })
|
||||||
})
|
|
||||||
public String getDeals() {
|
public String getDeals() {
|
||||||
return this.restTemplate.getForObject("http://travel-agency-service:8080/deals", String.class);
|
return this.restTemplate.getForObject("http://travel-agency-service:8080/deals", String.class);
|
||||||
}
|
}
|
||||||
|
@ -14,5 +14,4 @@ public class SpringContextIntegrationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void contextLoads() {
|
public void contextLoads() {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,8 @@ public class TravelAgencyController {
|
|||||||
List<TravelDeal> travelDealList = travelDealRepository.findAll();
|
List<TravelDeal> travelDealList = travelDealRepository.findAll();
|
||||||
if (!travelDealList.isEmpty()) {
|
if (!travelDealList.isEmpty()) {
|
||||||
int randomDeal = new Random().nextInt(travelDealList.size());
|
int randomDeal = new Random().nextInt(travelDealList.size());
|
||||||
return travelDealList.get(randomDeal).toString();
|
return travelDealList.get(randomDeal)
|
||||||
|
.toString();
|
||||||
} else {
|
} else {
|
||||||
return "NO DEALS";
|
return "NO DEALS";
|
||||||
}
|
}
|
||||||
@ -38,9 +39,17 @@ public class TravelAgencyController {
|
|||||||
public String get() throws UnknownHostException {
|
public String get() throws UnknownHostException {
|
||||||
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
stringBuilder.append("Host: ").append(InetAddress.getLocalHost().getHostName()).append("<br/>");
|
stringBuilder.append("Host: ")
|
||||||
stringBuilder.append("IP: ").append(InetAddress.getLocalHost().getHostAddress()).append("<br/>");
|
.append(InetAddress.getLocalHost()
|
||||||
stringBuilder.append("Type: ").append("Travel Agency").append("<br/>");
|
.getHostName())
|
||||||
|
.append("<br/>");
|
||||||
|
stringBuilder.append("IP: ")
|
||||||
|
.append(InetAddress.getLocalHost()
|
||||||
|
.getHostAddress())
|
||||||
|
.append("<br/>");
|
||||||
|
stringBuilder.append("Type: ")
|
||||||
|
.append("Travel Agency")
|
||||||
|
.append("<br/>");
|
||||||
return stringBuilder.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,14 +87,6 @@ public class TravelDeal {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "TravelDeal{" +
|
return "TravelDeal{" + "id=" + id + ", destination='" + destination + '\'' + ", description='" + description + '\'' + ", dealPrice=" + dealPrice + ", oldPrice=" + oldPrice + ", departureDate=" + departureDate + ", arrivalDate=" + arrivalDate + '}';
|
||||||
"id=" + id +
|
|
||||||
", destination='" + destination + '\'' +
|
|
||||||
", description='" + description + '\'' +
|
|
||||||
", dealPrice=" + dealPrice +
|
|
||||||
", oldPrice=" + oldPrice +
|
|
||||||
", departureDate=" + departureDate +
|
|
||||||
", arrivalDate=" + arrivalDate +
|
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,5 +9,4 @@ public interface TravelDealRepository extends MongoRepository<TravelDeal, String
|
|||||||
|
|
||||||
public List<TravelDeal> findByDestination(String destination);
|
public List<TravelDeal> findByDestination(String destination);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user