From 4054d4c016c63c6f3f6eeadf88eb0ae5ef630473 Mon Sep 17 00:00:00 2001 From: akageun Date: Fri, 19 Jul 2024 00:50:41 +0900 Subject: [PATCH] React Deploy And WebConfig Setting --- .../domain/cluster/info/ClusterManager.java | 66 ++++--------------- .../cassdio/core/support/MapDBConfig.java | 45 +++++++++++++ .../cassdio/core/support/MapDBConfigTest.java | 26 ++++++++ cassdio-web/frontend.build.gradle | 52 ++++++++------- 4 files changed, 113 insertions(+), 76 deletions(-) create mode 100644 cassdio-core/src/main/java/kr/hakdang/cassdio/core/support/MapDBConfig.java create mode 100644 cassdio-core/src/test/java/kr/hakdang/cassdio/core/support/MapDBConfigTest.java diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/info/ClusterManager.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/info/ClusterManager.java index 606c93a3..9989d6f7 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/info/ClusterManager.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/info/ClusterManager.java @@ -4,18 +4,12 @@ import io.micrometer.common.util.StringUtils; import kr.hakdang.cassdio.common.utils.IdGenerator; import kr.hakdang.cassdio.common.utils.Jsons; -import kr.hakdang.cassdio.core.domain.cluster.ClusterUtils; import lombok.extern.slf4j.Slf4j; import org.mapdb.DB; -import org.mapdb.DBMaker; import org.mapdb.Serializer; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.InitializingBean; import org.springframework.stereotype.Service; -import java.io.File; import java.util.List; -import java.util.Map; import java.util.concurrent.ConcurrentMap; /** @@ -26,12 +20,16 @@ */ @Slf4j @Service -public class ClusterManager implements InitializingBean, DisposableBean { +public class ClusterManager { - private static DB db; + private final DB mapDb; + + public ClusterManager(DB mapDb) { + this.mapDb = mapDb; + } public void register(ClusterInfoArgs args) { - ConcurrentMap map = db + ConcurrentMap map = mapDb .hashMap("cluster", Serializer.STRING, Serializer.STRING) .createOrOpen(); @@ -39,21 +37,21 @@ public void register(ClusterInfoArgs args) { map.put(clusterId, Jsons.toJson(args.makeClusterInfo(clusterId))); - db.commit(); + mapDb.commit(); } public void update(String clusterId, ClusterInfoArgs args) { - ConcurrentMap map = db + ConcurrentMap map = mapDb .hashMap("cluster", Serializer.STRING, Serializer.STRING) .createOrOpen(); map.put(clusterId, Jsons.toJson(args.makeClusterInfo(clusterId))); - db.commit(); + mapDb.commit(); } public List findAll() { - ConcurrentMap map = db + ConcurrentMap map = mapDb .hashMap("cluster", Serializer.STRING, Serializer.STRING) .createOrOpen(); @@ -64,7 +62,7 @@ public List findAll() { //TODO : Cache public ClusterInfo findById(String clusterId) { - ConcurrentMap map = db + ConcurrentMap map = mapDb .hashMap("cluster", Serializer.STRING, Serializer.STRING) .createOrOpen(); @@ -78,49 +76,13 @@ public ClusterInfo findById(String clusterId) { } public void deleteById(String clusterId) { - ConcurrentMap map = db + ConcurrentMap map = mapDb .hashMap("cluster", Serializer.STRING, Serializer.STRING) .createOrOpen(); map.remove(clusterId); - db.commit(); - } - - private DB makeDB() { - - File file = new File(System.getProperty("user.home") + "/.cassdio"); - if(!file.exists()){ - file.mkdir(); - } - - DBMaker.Maker maker = DBMaker - //TODO : 추후 프로퍼티 받아서 주입할 수 있도록 변경 예정 - .fileDB(System.getProperty("user.home") + "/.cassdio/cassdio_v1.db") - .fileMmapEnable() // Always enable mmap - .fileMmapEnableIfSupported() // Only enable mmap on supported platforms - .fileMmapPreclearDisable() // Make mmap file faster - .transactionEnable() - // Unmap (release resources) file when its closed. - // That can cause JVM crash if file is accessed after it was unmapped - // (there is possible race condition). - .cleanerHackEnable(); - - return maker.make(); + mapDb.commit(); } - @Override - public void afterPropertiesSet() throws Exception { - if (db == null) { - db = makeDB(); - } - - } - - @Override - public void destroy() throws Exception { - if (db != null) { - db.close(); - } - } } diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/support/MapDBConfig.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/support/MapDBConfig.java new file mode 100644 index 00000000..b733b542 --- /dev/null +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/support/MapDBConfig.java @@ -0,0 +1,45 @@ +package kr.hakdang.cassdio.core.support; + +import lombok.extern.slf4j.Slf4j; +import org.mapdb.DB; +import org.mapdb.DBMaker; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +import java.io.File; + +/** + * MapDBConfig + * + * @author akageun + * @since 2024-07-19 + */ +@Slf4j +@Configuration +public class MapDBConfig { + + @Bean(name = "mapDb", destroyMethod = "close") + public DB mapDb() { + File file = new File(System.getProperty("user.home") + "/.cassdio"); + if (!file.exists()) { + file.mkdir(); + } + + DBMaker.Maker maker = DBMaker + //TODO : 추후 프로퍼티 받아서 주입할 수 있도록 변경 예정 + .fileDB(System.getProperty("user.home") + "/.cassdio/cassdio_v1.db") + .fileMmapEnable() // Always enable mmap + .fileMmapEnableIfSupported() // Only enable mmap on supported platforms + .fileMmapPreclearDisable() // Make mmap file faster + .transactionEnable() + .fileLockDisable() + // Unmap (release resources) file when its closed. + // That can cause JVM crash if file is accessed after it was unmapped + // (there is possible race condition). + .cleanerHackEnable(); + + return maker.make(); + } + +} diff --git a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/support/MapDBConfigTest.java b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/support/MapDBConfigTest.java new file mode 100644 index 00000000..31bbd579 --- /dev/null +++ b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/support/MapDBConfigTest.java @@ -0,0 +1,26 @@ +package kr.hakdang.cassdio.core.support; + +import org.mapdb.DB; +import org.mapdb.DBMaker; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Profile; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.*; + +@TestConfiguration +class MapDBConfigTest { + + + @Bean(name = "mapDb") + public DB mapDb() { + DBMaker.Maker maker = DBMaker + .memoryDB(); + + + return maker.make(); + } + +} diff --git a/cassdio-web/frontend.build.gradle b/cassdio-web/frontend.build.gradle index 6260bd07..6c382de7 100644 --- a/cassdio-web/frontend.build.gradle +++ b/cassdio-web/frontend.build.gradle @@ -1,34 +1,38 @@ -apply plugin: "com.github.node-gradle.node" +def frontend = project.findProperty('frontend') ?: false +if (frontend.toBoolean()) { -def projectDir = file("${project.rootDir}/cassdio-web/src/main/webapp") + apply plugin: "com.github.node-gradle.node" -node { - version = '20.15.1' - npmVersion = '9.8.0' - download = true + def projectDir = file("${project.rootDir}/cassdio-web/src/main/webapp") - nodeProjectDir.set(projectDir) -} + node { + version = '20.15.1' + npmVersion = '9.8.0' + download = true -task npmInstall2(type: NpmTask) { - args = ['install'] -} + nodeProjectDir.set(projectDir) + } -task npmBuild(type: NpmTask, dependsOn: npmInstall2) { - args = ['run', 'build'] -} + task npmInstall2(type: NpmTask) { + args = ['install'] + } -task copyDist(type: Copy, dependsOn: npmBuild) { - from("${projectDir}/build") { - include '**/*' + task npmBuild(type: NpmTask, dependsOn: npmInstall2) { + args = ['run', 'build'] } - into "${project.rootDir}/cassdio-web/src/main/resources/static" - includeEmptyDirs = true -} -task deleteDist(type: Delete, dependsOn: copyDist) { - delete "${projectDir}/build" -} + task copyDist(type: Copy, dependsOn: npmBuild) { + from("${projectDir}/build") { + include '**/*' + } + into "${project.rootDir}/cassdio-web/src/main/resources/static" + includeEmptyDirs = true + } -processResources { dependsOn "deleteDist" } + task deleteDist(type: Delete, dependsOn: copyDist) { + delete "${projectDir}/build" + } + processResources { dependsOn "deleteDist" } + +}