-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #613 from woowacourse-teams/dev
feat: v1.2.0 배포
- Loading branch information
Showing
179 changed files
with
4,612 additions
and
1,030 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
.idea | ||
.DS_Store | ||
|
||
|
||
s3proxy/src/main/resources/static/docs/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
backend/src/main/java/com/woowacourse/zzimkkong/config/LogAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.woowacourse.zzimkkong.config; | ||
|
||
import com.woowacourse.zzimkkong.config.logaspect.LogMethodExecutionTime; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.reflect.MethodSignature; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static net.logstash.logback.argument.StructuredArguments.value; | ||
|
||
@Slf4j | ||
@Component | ||
@Aspect | ||
public class LogAspect { | ||
private static final String GROUP_NAME_OF_REPOSITORY = "repository"; | ||
|
||
@Around("@target(com.woowacourse.zzimkkong.config.logaspect.LogMethodExecutionTime) " + | ||
"&& execution(* com.woowacourse..*(..))") | ||
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable { | ||
|
||
long startTime = System.currentTimeMillis(); | ||
Object result = joinPoint.proceed(); | ||
long endTime = System.currentTimeMillis(); | ||
long timeTaken = endTime - startTime; | ||
|
||
String logGroup = getLogGroup(joinPoint); | ||
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); | ||
|
||
logExecutionInfo(methodSignature, timeTaken, logGroup); | ||
|
||
return result; | ||
} | ||
|
||
@Around("execution(public * org.springframework.data.repository.Repository+.*(..))") | ||
public Object logExecutionTimeOfRepository(ProceedingJoinPoint joinPoint) throws Throwable { | ||
|
||
long startTime = System.currentTimeMillis(); | ||
Object result = joinPoint.proceed(); | ||
long endTime = System.currentTimeMillis(); | ||
long timeTaken = endTime - startTime; | ||
|
||
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); | ||
|
||
logExecutionInfo(methodSignature, timeTaken, GROUP_NAME_OF_REPOSITORY); | ||
|
||
return result; | ||
} | ||
|
||
private String getLogGroup(ProceedingJoinPoint joinPoint) { | ||
Class<?> targetClass = joinPoint.getTarget().getClass(); | ||
return targetClass.getAnnotation(LogMethodExecutionTime.class).group(); | ||
} | ||
|
||
private void logExecutionInfo(MethodSignature methodSignature, long timeTaken, String logGroup) { | ||
log.info("{} took {} ms. (info group by '{}')", | ||
value("method", methodSignature.getDeclaringTypeName() + "." + methodSignature.getName() + "()"), | ||
value("execution_time", timeTaken), | ||
value("group", logGroup)); | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
backend/src/main/java/com/woowacourse/zzimkkong/config/StorageConfig.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
backend/src/main/java/com/woowacourse/zzimkkong/config/datasource/CircularList.java
This file was deleted.
Oops, something went wrong.
93 changes: 33 additions & 60 deletions
93
...end/src/main/java/com/woowacourse/zzimkkong/config/datasource/CustomDataSourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,62 @@ | ||
package com.woowacourse.zzimkkong.config.datasource; | ||
|
||
import com.woowacourse.zzimkkong.exception.infrastructure.NoMasterDataSourceException; | ||
import com.zaxxer.hikari.HikariDataSource; | ||
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties; | ||
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.jdbc.DataSourceBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy; | ||
import org.springframework.orm.jpa.JpaTransactionManager; | ||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||
import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter; | ||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
|
||
import javax.persistence.EntityManagerFactory; | ||
import javax.sql.DataSource; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.woowacourse.zzimkkong.config.datasource.ReplicationRoutingDataSource.DATASOURCE_KEY_MASTER; | ||
import static com.woowacourse.zzimkkong.config.datasource.ReplicationRoutingDataSource.DATASOURCE_KEY_SLAVE; | ||
|
||
@Configuration | ||
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class}) | ||
@EnableTransactionManagement | ||
@EnableJpaRepositories(basePackages = {"com.woowacourse.zzimkkong"}) | ||
@Profile("prod") | ||
public class CustomDataSourceConfig { | ||
public static final String MASTER = "master"; | ||
public static final String SLAVE = "slave"; | ||
private static final String PACKAGE_PATH = "com.woowacourse.zzimkkong"; | ||
private final List<HikariDataSource> hikariDataSources; | ||
private final JpaProperties jpaProperties; | ||
|
||
public CustomDataSourceConfig(final List<HikariDataSource> hikariDataSources, final JpaProperties jpaProperties) { | ||
this.hikariDataSources = hikariDataSources; | ||
this.jpaProperties = jpaProperties; | ||
} | ||
|
||
@Bean | ||
public DataSource dataSource() { | ||
return new LazyConnectionDataSourceProxy(routingDataSource()); | ||
@ConfigurationProperties(prefix = "spring.datasource.hikari.master") | ||
public DataSource masterDataSource() { | ||
return DataSourceBuilder.create().type(HikariDataSource.class).build(); | ||
} | ||
|
||
@Bean | ||
public DataSource routingDataSource() { | ||
final DataSource master = createMasterDataSource(); | ||
final Map<Object, Object> slaves = createSlaveDataSources(); | ||
slaves.put(MASTER, master); | ||
|
||
ReplicationRoutingDataSource replicationRoutingDataSource = new ReplicationRoutingDataSource(); | ||
replicationRoutingDataSource.setDefaultTargetDataSource(master); | ||
replicationRoutingDataSource.setTargetDataSources(slaves); | ||
return replicationRoutingDataSource; | ||
} | ||
|
||
private DataSource createMasterDataSource() { | ||
return hikariDataSources.stream() | ||
.filter(dataSource -> dataSource.getPoolName().startsWith(MASTER)) | ||
.findFirst() | ||
.orElseThrow(NoMasterDataSourceException::new); | ||
@ConfigurationProperties(prefix = "spring.datasource.hikari.slave") | ||
public DataSource slaveDataSource() { | ||
return DataSourceBuilder.create().type(HikariDataSource.class).build(); | ||
} | ||
|
||
private Map<Object, Object> createSlaveDataSources() { | ||
final List<HikariDataSource> slaveDataSources = hikariDataSources.stream() | ||
.filter(datasource -> Objects.nonNull(datasource.getPoolName()) && datasource.getPoolName().startsWith(SLAVE)) | ||
.collect(Collectors.toList()); | ||
@Bean | ||
public DataSource routingDataSource(@Qualifier("masterDataSource") DataSource master, | ||
@Qualifier("slaveDataSource") DataSource slave) { | ||
ReplicationRoutingDataSource routingDataSource = new ReplicationRoutingDataSource(); | ||
|
||
final Map<Object, Object> result = new HashMap<>(); | ||
for (final HikariDataSource slaveDataSource : slaveDataSources) { | ||
result.put(slaveDataSource.getPoolName(), slaveDataSource); | ||
} | ||
return result; | ||
} | ||
HashMap<Object, Object> sources = new HashMap<>(); | ||
sources.put(DATASOURCE_KEY_MASTER, master); | ||
sources.put(DATASOURCE_KEY_SLAVE, slave); | ||
|
||
@Bean | ||
public LocalContainerEntityManagerFactoryBean entityManagerFactory() { | ||
EntityManagerFactoryBuilder entityManagerFactoryBuilder = createEntityManagerFactoryBuilder(jpaProperties); | ||
return entityManagerFactoryBuilder.dataSource(dataSource()).packages(PACKAGE_PATH).build(); | ||
} | ||
routingDataSource.setTargetDataSources(sources); | ||
routingDataSource.setDefaultTargetDataSource(master); | ||
|
||
private EntityManagerFactoryBuilder createEntityManagerFactoryBuilder(JpaProperties jpaProperties) { | ||
AbstractJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); | ||
return new EntityManagerFactoryBuilder(vendorAdapter, jpaProperties.getProperties(), null); | ||
return routingDataSource; | ||
} | ||
|
||
@Primary | ||
@Bean | ||
public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) { | ||
JpaTransactionManager tm = new JpaTransactionManager(); | ||
tm.setEntityManagerFactory(entityManagerFactory); | ||
return tm; | ||
public DataSource dataSource(@Qualifier("routingDataSource") DataSource routingDataSource) { | ||
return new LazyConnectionDataSourceProxy(routingDataSource); | ||
} | ||
} |
Oops, something went wrong.