|
38 | 38 | @EnableAutoConfiguration |
39 | 39 | @Profile("pgsql") |
40 | 40 | public class RdsWebConfig { |
41 | | - private static final Logger logger = LoggerFactory.getLogger(WebConfig.class); |
| 41 | + private static final Logger logger = LoggerFactory.getLogger(WebConfig.class); |
42 | 42 |
|
43 | | - @Bean |
44 | | - public Filter TracingFilter() { |
45 | | - return new AWSXRayServletFilter("Scorekeep"); |
46 | | - } |
| 43 | + @Bean |
| 44 | + public Filter TracingFilter() { |
| 45 | + return new AWSXRayServletFilter("Scorekeep"); |
| 46 | + } |
47 | 47 |
|
48 | | - @Bean |
49 | | - public Filter SimpleCORSFilter() { |
50 | | - return new SimpleCORSFilter(); |
51 | | - } |
| 48 | + @Bean |
| 49 | + public Filter SimpleCORSFilter() { |
| 50 | + return new SimpleCORSFilter(); |
| 51 | + } |
52 | 52 |
|
53 | | - @Bean |
54 | | - @ConfigurationProperties(prefix = "spring.datasource") |
55 | | - public DataSource dataSource() { |
56 | | - logger.info("Initializing PostgreSQL datasource"); |
57 | | - return DataSourceBuilder.create() |
58 | | - .driverClassName("org.postgresql.Driver") |
59 | | - .url("jdbc:postgresql://" + System.getenv("RDS_HOSTNAME") + ":" + System.getenv("RDS_PORT") + "/ebdb") |
60 | | - .username(System.getenv("RDS_USERNAME")) |
61 | | - .password(System.getenv("RDS_PASSWORD")) |
62 | | - .build(); |
63 | | - } |
| 53 | + @Bean |
| 54 | + @ConfigurationProperties(prefix = "spring.datasource") |
| 55 | + public DataSource dataSource() { |
| 56 | + logger.info("Initializing PostgreSQL datasource"); |
| 57 | + return DataSourceBuilder.create() |
| 58 | + .driverClassName("org.postgresql.Driver") |
| 59 | + .url("jdbc:postgresql://" + System.getenv("RDS_HOSTNAME") + ":" + System.getenv("RDS_PORT") + "/ebdb") |
| 60 | + .username(System.getenv("RDS_USERNAME")) |
| 61 | + .password(System.getenv("RDS_PASSWORD")) |
| 62 | + .build(); |
| 63 | + } |
64 | 64 |
|
65 | | - @Bean |
66 | | - public GameHistoryModel gameHistoryModel() { |
67 | | - return new GameHistoryModel(); |
68 | | - } |
| 65 | + @Bean |
| 66 | + public GameHistoryModel gameHistoryModel() { |
| 67 | + return new GameHistoryModel(); |
| 68 | + } |
69 | 69 |
|
70 | | - @Autowired |
71 | | - LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean; |
| 70 | + @Autowired |
| 71 | + LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean; |
72 | 72 |
|
73 | | - @PostConstruct |
74 | | - public void schemaExport() { |
75 | | - EntityManagerFactoryImpl entityManagerFactoryImpl = (EntityManagerFactoryImpl) localContainerEntityManagerFactoryBean.getNativeEntityManagerFactory(); |
76 | | - SessionFactoryImplementor sessionFactoryImplementor = entityManagerFactoryImpl.getSessionFactory(); |
77 | | - StandardServiceRegistry standardServiceRegistry = sessionFactoryImplementor.getSessionFactoryOptions().getServiceRegistry(); |
78 | | - MetadataSources metadataSources = new MetadataSources(new BootstrapServiceRegistryBuilder().build()); |
79 | | - metadataSources.addAnnotatedClass(GameHistory.class); |
80 | | - MetadataImplementor metadataImplementor = (MetadataImplementor) metadataSources.buildMetadata(standardServiceRegistry); |
81 | | - SchemaExport schemaExport = new SchemaExport(standardServiceRegistry, metadataImplementor); |
| 73 | + @PostConstruct |
| 74 | + public void schemaExport() { |
| 75 | + EntityManagerFactoryImpl entityManagerFactoryImpl = (EntityManagerFactoryImpl) localContainerEntityManagerFactoryBean.getNativeEntityManagerFactory(); |
| 76 | + SessionFactoryImplementor sessionFactoryImplementor = entityManagerFactoryImpl.getSessionFactory(); |
| 77 | + StandardServiceRegistry standardServiceRegistry = sessionFactoryImplementor.getSessionFactoryOptions().getServiceRegistry(); |
| 78 | + MetadataSources metadataSources = new MetadataSources(new BootstrapServiceRegistryBuilder().build()); |
| 79 | + metadataSources.addAnnotatedClass(GameHistory.class); |
| 80 | + MetadataImplementor metadataImplementor = (MetadataImplementor) metadataSources.buildMetadata(standardServiceRegistry); |
| 81 | + SchemaExport schemaExport = new SchemaExport(standardServiceRegistry, metadataImplementor); |
82 | 82 |
|
83 | | - AWSXRay.beginSegment("Scorekeep-init"); |
84 | | - schemaExport.create(true, true); |
85 | | - AWSXRay.endSegment(); |
86 | | - } |
| 83 | + AWSXRay.beginSegment("Scorekeep-init"); |
| 84 | + schemaExport.create(true, true); |
| 85 | + AWSXRay.endSegment(); |
| 86 | + } |
87 | 87 |
|
88 | | - static { |
89 | | - AWSXRayRecorderBuilder builder = AWSXRayRecorderBuilder.standard().withPlugin(new EC2Plugin()).withPlugin(new ElasticBeanstalkPlugin()); |
90 | | - URL ruleFile = WebConfig.class.getResource("/sampling-rules.json"); |
91 | | - builder.withSamplingStrategy(new LocalizedSamplingStrategy(ruleFile)); |
92 | | - AWSXRay.setGlobalRecorder(builder.build()); |
93 | | - AWSXRay.beginSegment("Scorekeep-init"); |
94 | | - if ( System.getenv("NOTIFICATION_EMAIL") != null ){ |
95 | | - try { Sns.createSubscription(); } |
96 | | - catch (Exception e ) { |
97 | | - logger.warn("Failed to create subscription for email "+ System.getenv("NOTIFICATION_EMAIL")); |
98 | | - } |
99 | | - } |
100 | | - AWSXRay.endSegment(); |
| 88 | + static { |
| 89 | + AWSXRayRecorderBuilder builder = AWSXRayRecorderBuilder.standard().withPlugin(new EC2Plugin()).withPlugin(new ElasticBeanstalkPlugin()); |
| 90 | + URL ruleFile = WebConfig.class.getResource("/sampling-rules.json"); |
| 91 | + builder.withSamplingStrategy(new LocalizedSamplingStrategy(ruleFile)); |
| 92 | + AWSXRay.setGlobalRecorder(builder.build()); |
| 93 | + AWSXRay.beginSegment("Scorekeep-init"); |
| 94 | + if ( System.getenv("NOTIFICATION_EMAIL") != null ){ |
| 95 | + try { Sns.createSubscription(); } |
| 96 | + catch (Exception e ) { |
| 97 | + logger.warn("Failed to create subscription for email "+ System.getenv("NOTIFICATION_EMAIL")); |
| 98 | + } |
101 | 99 | } |
| 100 | + AWSXRay.endSegment(); |
| 101 | + } |
102 | 102 | } |
0 commit comments