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