Skip to content

Commit

Permalink
Fails locally. Hope it works on the cloud .. said no one
Browse files Browse the repository at this point in the history
  • Loading branch information
pvepamb1 committed Sep 27, 2019
1 parent 77fa233 commit 3f3ce0f
Show file tree
Hide file tree
Showing 19 changed files with 229 additions and 37 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ jobs:
api_key: $GITHUB_OAUTH_TOKEN
file:
- "applications/tripit/build/libs/tripit-1.0-SNAPSHOT.war"
- "applications/hotels-ms/build/libs/hotels-ms-1.0-SNAPSHOT.jar"
- "applications/flights/build/libs/flights-ms-1.0-SNAPSHOT.jar"
skip_cleanup: true
- stage: deploy to test
language: java
script:
- echo "Downloading $RELEASE_TAG"
- wget -P applications/tripit/build/libs https://github.com/$GITHUB_USERNAME/pcf-training-final/releases/download/$RELEASE_TAG/tripit-1.0-SNAPSHOT.war
- wget -P applications/hotels-ms/build/libs https://github.com/$GITHUB_USERNAME/pcf-training-final/releases/download/$RELEASE_TAG/hotels-ms-1.0-SNAPSHOT.jar
- wget -P applications/flights-ms/build/libs https://github.com/$GITHUB_USERNAME/pcf-training-final/releases/download/$RELEASE_TAG/flights-ms-1.0-SNAPSHOT.jar
before_deploy:
- echo "Deploying $RELEASE_TAG to test"
deploy:
Expand Down
10 changes: 5 additions & 5 deletions applications/flights-ms/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ description 'Flights Mircoservice'

dependencyManagement {
imports {
//mavenBom("org.springframework.cloud:spring-cloud-dependencies:$SCVersion")
//mavenBom("io.pivotal.spring.cloud:spring-cloud-services-dependencies:$SCSClientStartersVersion")
mavenBom("org.springframework.cloud:spring-cloud-dependencies:$SCVersion")
mavenBom("io.pivotal.spring.cloud:spring-cloud-services-dependencies:$SCSClientStartersVersion")
}
}

Expand All @@ -21,7 +21,7 @@ dependencies {
compile('org.springframework.boot:spring-boot-starter-tomcat')
compile('mysql:mysql-connector-java:5.1.46')
compile('commons-lang:commons-lang:2.4')
//compile('io.pivotal.spring.cloud:spring-cloud-services-starter-service-registry')
//compile('org.springframework.cloud:spring-cloud-starter-oauth2')
//compile("io.pivotal.spring.cloud:spring-cloud-sso-connector:$SCSSOVersion")
compile('io.pivotal.spring.cloud:spring-cloud-services-starter-service-registry')
compile('org.springframework.cloud:spring-cloud-starter-oauth2')
compile("io.pivotal.spring.cloud:spring-cloud-sso-connector:$SCSSOVersion")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.pcf.tripit.flights;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@EnableWebSecurity
@Configuration
@ConditionalOnProperty(value="enable-oauth", havingValue = "false")
public class DisableSecurityConfiguration extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll().and().csrf().disable();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.pcf.tripit.flights;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;

@EnableResourceServer
@Configuration
@ConditionalOnProperty(value = "enable-oauth", matchIfMissing = true)
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class EnableSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated();
}
}

10 changes: 5 additions & 5 deletions applications/hotels-ms/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ description 'Hotels Mircoservice'

dependencyManagement {
imports {
//mavenBom("org.springframework.cloud:spring-cloud-dependencies:$SCVersion")
//mavenBom("io.pivotal.spring.cloud:spring-cloud-services-dependencies:$SCSClientStartersVersion")
mavenBom("org.springframework.cloud:spring-cloud-dependencies:$SCVersion")
mavenBom("io.pivotal.spring.cloud:spring-cloud-services-dependencies:$SCSClientStartersVersion")
}
}

Expand All @@ -21,7 +21,7 @@ dependencies {
compile('org.springframework.boot:spring-boot-starter-tomcat')
compile('mysql:mysql-connector-java:5.1.46')
compile('commons-lang:commons-lang:2.4')
//compile('io.pivotal.spring.cloud:spring-cloud-services-starter-service-registry')
//compile('org.springframework.cloud:spring-cloud-starter-oauth2')
//compile("io.pivotal.spring.cloud:spring-cloud-sso-connector:$SCSSOVersion")
compile('io.pivotal.spring.cloud:spring-cloud-services-starter-service-registry')
compile('org.springframework.cloud:spring-cloud-starter-oauth2')
compile("io.pivotal.spring.cloud:spring-cloud-sso-connector:$SCSSOVersion")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.pcf.tripit.hotels;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@EnableWebSecurity
@Configuration
@ConditionalOnProperty(value="enable-oauth", havingValue = "false")
public class DisableSecurityConfiguration extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll().and().csrf().disable();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.pcf.tripit.hotels;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;

@EnableResourceServer
@Configuration
@ConditionalOnProperty(value = "enable-oauth", matchIfMissing = true)
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class EnableSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated();
}
}

8 changes: 6 additions & 2 deletions applications/tripit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ version = '1.0-SNAPSHOT'

dependencyManagement {
imports {
//mavenBom("org.springframework.cloud:spring-cloud-dependencies:$SCVersion")
//mavenBom("io.pivotal.spring.cloud:spring-cloud-services-dependencies:$SCSClientStartersVersion")
mavenBom("org.springframework.cloud:spring-cloud-dependencies:$SCVersion")
mavenBom("io.pivotal.spring.cloud:spring-cloud-services-dependencies:$SCSClientStartersVersion")
}
}

Expand All @@ -22,4 +22,8 @@ dependencies {
compile('org.apache.tomcat.embed:tomcat-embed-jasper:8.5.6')
compile('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile('io.pivotal.spring.cloud:spring-cloud-services-starter-service-registry')
compile('io.pivotal.spring.cloud:spring-cloud-services-starter-circuit-breaker')
compile('org.springframework.cloud:spring-cloud-starter-oauth2')
compile("io.pivotal.spring.cloud:spring-cloud-sso-connector:$SCSSOVersion")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.pcf.tripit;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;

@EnableWebSecurity
@Configuration
@ConditionalOnProperty(value="enable-oauth", havingValue = "false")
public class DisableSecurityConfiguration extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll().and().csrf().disable();
}

@LoadBalanced
@Bean
public RestOperations restOperations() {
return new RestTemplate();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.pcf.tripit;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails;
import org.springframework.web.client.RestOperations;

@EnableOAuth2Sso
@Configuration
@ConditionalOnProperty(value = "enable-oauth", matchIfMissing = true)
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class EnableSecurityConfiguration extends WebSecurityConfigurerAdapter {

@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated();
}

@LoadBalanced
@Bean
public RestOperations restOperations(OAuth2ProtectedResourceDetails resourceDetails, OAuth2ClientContext oauth2ClientContext) {
return new OAuth2RestTemplate(resourceDetails, oauth2ClientContext);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@

import com.pcf.tripit.flightui.FlightClient;
import com.pcf.tripit.hotelui.HotelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;

@EnableEurekaClient
@EnableCircuitBreaker
@SpringBootApplication
public class TripitApplication {

@Value("${hotels.ms.url}")
private String hotelUrl;
@Value("${flights.ms.url}")
private String flightUrl;

public static void main(String[] args) {
SpringApplication.run(TripitApplication.class, args);
}
Expand All @@ -27,12 +25,12 @@ public static void main(String[] args) {

@Bean
public FlightClient flightClient(RestOperations restOperations){
return new FlightClient(flightUrl, restOperations);
return new FlightClient("//flights-ms/flights", restOperations);
}

@Bean
public HotelClient hotelClient(RestOperations restOperations) {
return new HotelClient(hotelUrl, restOperations);
return new HotelClient("//hotels-ms/hotels", restOperations);
}

@Bean
Expand Down
4 changes: 0 additions & 4 deletions applications/tripit/src/main/resources/application.properties

This file was deleted.

20 changes: 20 additions & 0 deletions applications/tripit/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
spring:

application:
name: tripit

mvc.view:
prefix: /WEB-INF/
suffix: .jsp

logging.level:
root: WARN
com.pcf.tripit.hotelui.HotelUI: DEBUG

hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 5000
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public FlightController(FlightRepository flightRepository) {
@GetMapping("/filter")
public Iterable<Flight> getFlights(@RequestParam String to, @RequestParam String from, @RequestParam String date) throws ParseException {
LOGGER.info("In filter");
if(to.equals("")||from.equals("")||date.equals("")) return flightRepository.findAll();
LOGGER.info("Before parsing date is {}", date);
Date date1 = new SimpleDateFormat("yyyy-MM-dd").parse(date);
LOGGER.info("After parsing date is {}", date1);
Expand Down
2 changes: 1 addition & 1 deletion components/ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ apply from: "../../common.gradle"
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:$springBootVersion")
compile('commons-lang:commons-lang:2.4')
//compile("io.pivotal.spring.cloud:spring-cloud-services-starter-circuit-breaker:$SCSClientStartersVersion")
compile("io.pivotal.spring.cloud:spring-cloud-services-starter-circuit-breaker:$SCSClientStartersVersion")
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class MainController {
private FlightClient flightClient;
private FlightInitialList flightInitialList;

@Autowired
public MainController(HotelInitialList hotelInitialList, HotelClient hotelClient, FlightClient flightClient, FlightInitialList flightInitialList) {
this.hotelInitialList = hotelInitialList;
this.hotelClient = hotelClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pcf.tripit.flightui;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.ParameterizedTypeReference;
Expand Down Expand Up @@ -33,9 +35,9 @@ public void create(FlightUI flightUI) {
restOperations.postForEntity(flightURL, flightUI, FlightUI.class);
}

// @HystrixCommand(fallbackMethod="getAllFallback",commandProperties = {
// @HystrixProperty(name="execution.isolation.strategy", value="SEMAPHORE")
//})
@HystrixCommand(fallbackMethod="getAllFallback",commandProperties = {
@HystrixProperty(name="execution.isolation.strategy", value="SEMAPHORE")
})
public List<FlightUI> getAll() {
List<FlightUI> read = restOperations.exchange(flightURL, HttpMethod.GET, null, flightListType).getBody();
log.debug("Read {} flights from {}", read.size(), flightURL);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.pcf.tripit.hotelui;

//import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
//import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.ParameterizedTypeReference;
Expand Down Expand Up @@ -34,18 +33,20 @@ public HotelClient(String hotelURL, RestOperations restOperations) {
}

public void create(HotelUI hotel) {
log.debug("Url is {}",hotelURL);
System.out.println(hotelURL);
restOperations.postForEntity(hotelURL, hotel, HotelUI.class);
}

// @HystrixCommand(fallbackMethod="getAllFallback",commandProperties = {
// @HystrixProperty(name="execution.isolation.strategy", value="SEMAPHORE")
//})
@HystrixCommand(fallbackMethod="getAllFallback",commandProperties = {
@HystrixProperty(name="execution.isolation.strategy", value="SEMAPHORE")
})
public List<HotelUI> getAll() {
List<HotelUI> read = restOperations.exchange(hotelURL, HttpMethod.GET, null, hotelListType).getBody();
log.debug("Read {} podcasts from {}", read.size(), hotelURL);

lastRead.clear();
int copyCount = (read.size() < CACHE_SIZE) ? read.size() : CACHE_SIZE;
int copyCount = Math.min(read.size(), CACHE_SIZE);
for (int i =0; i < copyCount; i++)
lastRead.add(read.get(i));
log.debug("Copied {} hotels into the cache", copyCount);
Expand Down
Loading

0 comments on commit 3f3ce0f

Please sign in to comment.