Skip to content

Commit

Permalink
React Deploy And WebConfig Setting
Browse files Browse the repository at this point in the history
  • Loading branch information
akageun committed Jul 18, 2024
1 parent 78dc3dd commit 4054d4c
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -26,34 +20,38 @@
*/
@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<String, String> map = db
ConcurrentMap<String, String> map = mapDb
.hashMap("cluster", Serializer.STRING, Serializer.STRING)
.createOrOpen();

String clusterId = IdGenerator.makeId();

map.put(clusterId, Jsons.toJson(args.makeClusterInfo(clusterId)));

db.commit();
mapDb.commit();
}

public void update(String clusterId, ClusterInfoArgs args) {
ConcurrentMap<String, String> map = db
ConcurrentMap<String, String> map = mapDb
.hashMap("cluster", Serializer.STRING, Serializer.STRING)
.createOrOpen();

map.put(clusterId, Jsons.toJson(args.makeClusterInfo(clusterId)));

db.commit();
mapDb.commit();
}

public List<ClusterInfo> findAll() {
ConcurrentMap<String, String> map = db
ConcurrentMap<String, String> map = mapDb
.hashMap("cluster", Serializer.STRING, Serializer.STRING)
.createOrOpen();

Expand All @@ -64,7 +62,7 @@ public List<ClusterInfo> findAll() {

//TODO : Cache
public ClusterInfo findById(String clusterId) {
ConcurrentMap<String, String> map = db
ConcurrentMap<String, String> map = mapDb
.hashMap("cluster", Serializer.STRING, Serializer.STRING)
.createOrOpen();

Expand All @@ -78,49 +76,13 @@ public ClusterInfo findById(String clusterId) {
}

public void deleteById(String clusterId) {
ConcurrentMap<String, String> map = db
ConcurrentMap<String, String> 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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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();
}

}
52 changes: 28 additions & 24 deletions cassdio-web/frontend.build.gradle
Original file line number Diff line number Diff line change
@@ -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" }

}

0 comments on commit 4054d4c

Please sign in to comment.