From 094e019901329aeeb700647dfe33ebde52118943 Mon Sep 17 00:00:00 2001 From: leedonggyu Date: Thu, 8 Oct 2020 09:31:23 +0900 Subject: [PATCH 01/38] Fix case unintended reset of followers at login --- .../NGrinderAuthenticationProvider.java | 4 +-- .../ngrinder/user/service/UserService.java | 29 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationProvider.java b/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationProvider.java index 2c0f3f9325..14c1018a0a 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationProvider.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationProvider.java @@ -123,8 +123,8 @@ protected void additionalAuthenticationChecks(UserDetails userDetails, addNewUserIntoLocal(user); LOG.info("{} is saved by password {}", user.getUser().getUserId(), user.getUser().getPassword()); } else { - // update user information - userService.saveWithoutPasswordEncoding(user.getUser()); + // update user information without followers + userService.saveWithoutFollowers(user.getUser()); } } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java b/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java index 949fb2d19e..3fd4e5e6d1 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java @@ -43,6 +43,7 @@ import java.util.Date; import java.util.List; +import static org.apache.commons.lang.StringUtils.isBlank; import static org.hibernate.Hibernate.initialize; import static org.ngrinder.common.constant.CacheConstants.CACHE_USERS; import static org.ngrinder.common.constant.CacheConstants.CACHE_USER_ENTITY; @@ -114,7 +115,6 @@ public User getOneWithFollowers(String userId) { return one; } - /** * Encoding given user's password. * @@ -127,7 +127,6 @@ public void encodePassword(User user) { } } - /** * Save user. * @@ -154,7 +153,22 @@ public User save(User user) { public User saveWithoutPasswordEncoding(User user) { final List followers = getFollowers(user.getFollowersStr()); user.setFollowers(followers); - if (user.getPassword() != null && StringUtils.isBlank(user.getPassword())) { + + User savedUser = saveWithoutFollowers(user); + + // Then expires new followers so that new followers info can be loaded. + for (User eachFollower : followers) { + userCache.evict(eachFollower.getUserId()); + userModelCache.evict(eachFollower.getId()); + } + prepareUserEnv(savedUser); + return savedUser; + } + + @Transactional + @CachePut(value = CACHE_USERS, key = "#user.userId") + public User saveWithoutFollowers(User user) { + if (user.getPassword() != null && isBlank(user.getPassword())) { user.setPassword(null); } final User existing = userRepository.findOneByUserId(user.getUserId()); @@ -169,14 +183,7 @@ public User saveWithoutPasswordEncoding(User user) { } user = existing.merge(user); } - User createdUser = userRepository.save(user); - // Then expires new followers so that new followers info can be loaded. - for (User eachFollower : followers) { - userCache.evict(eachFollower.getUserId()); - userModelCache.evict(eachFollower.getId()); - } - prepareUserEnv(createdUser); - return createdUser; + return userRepository.save(user); } private void prepareUserEnv(User user) { From c565dbc0be8451e9aea6581180b4a91150fae8e1 Mon Sep 17 00:00:00 2001 From: leedonggyu Date: Thu, 8 Oct 2020 11:09:26 +0900 Subject: [PATCH 02/38] Move cache of recently used agents to distribution map --- .../java/org/ngrinder/agent/service/AgentService.java | 4 ++-- .../java/org/ngrinder/common/constant/CacheConstants.java | 2 +- .../org/ngrinder/infra/config/DynamicCacheConfig.java | 2 +- .../java/org/ngrinder/agent/service/AgentServiceTest.java | 8 ++++---- .../java/org/ngrinder/agent/service/MockAgentService.java | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ngrinder-controller/src/main/java/org/ngrinder/agent/service/AgentService.java b/ngrinder-controller/src/main/java/org/ngrinder/agent/service/AgentService.java index b91e723bd5..b47f5ef764 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/agent/service/AgentService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/agent/service/AgentService.java @@ -357,7 +357,7 @@ public synchronized void runAgent(User user, final SingleConsole singleConsole, "\nPlease restart perftest after few minutes."); } - hazelcastService.put(CACHE_RECENTLY_USED_AGENTS, user.getUserId(), necessaryAgents); + hazelcastService.put(DIST_MAP_CACHE_RECENTLY_USED_AGENTS, user.getUserId(), necessaryAgents); LOGGER.info("{} agents are starting for user {}", agentCount, user.getUserId()); for (AgentInfo agentInfo : necessaryAgents) { @@ -386,7 +386,7 @@ private boolean hasOldVersionAgent(Set agentInfos) { * @return selected agents. */ Set selectAgent(User user, Set allFreeAgents, int agentCount) { - Set recentlyUsedAgents = hazelcastService.getOrDefault(CACHE_RECENTLY_USED_AGENTS, user.getUserId(), emptySet()); + Set recentlyUsedAgents = hazelcastService.getOrDefault(DIST_MAP_CACHE_RECENTLY_USED_AGENTS, user.getUserId(), emptySet()); Comparator recentlyUsedPriorityComparator = (agent1, agent2) -> { if (recentlyUsedAgents.contains(agent1)) { diff --git a/ngrinder-controller/src/main/java/org/ngrinder/common/constant/CacheConstants.java b/ngrinder-controller/src/main/java/org/ngrinder/common/constant/CacheConstants.java index e0971b7e02..c6f288d2d3 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/common/constant/CacheConstants.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/common/constant/CacheConstants.java @@ -23,6 +23,7 @@ public interface CacheConstants { String DIST_MAP_NAME_SAMPLING = "sampling"; String DIST_MAP_NAME_MONITORING = "monitoring"; String DIST_MAP_NAME_AGENT = "agent"; + String DIST_MAP_CACHE_RECENTLY_USED_AGENTS = "recently_used_agents"; String CACHE_USERS = "users"; String CACHE_FILE_ENTRIES = "file_entries"; @@ -30,7 +31,6 @@ public interface CacheConstants { String CACHE_RIGHT_PANEL_ENTRIES = "right_panel_entries"; String CACHE_LEFT_PANEL_ENTRIES = "left_panel_entries"; String CACHE_CURRENT_PERFTEST_STATISTICS = "current_perftest_statistics"; - String CACHE_RECENTLY_USED_AGENTS = "recently_used_agents"; String REGION_ATTR_KEY = "region"; String REGION_EXECUTOR_SERVICE_NAME = "region_executor"; diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/config/DynamicCacheConfig.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/config/DynamicCacheConfig.java index 2e5c6ea52f..c345bc9bb1 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/config/DynamicCacheConfig.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/config/DynamicCacheConfig.java @@ -149,6 +149,7 @@ public CacheConfigHolder cacheConfigMap() { cm.addDistMap(DIST_MAP_NAME_SAMPLING, 15); cm.addDistMap(DIST_MAP_NAME_MONITORING, 15); cm.addDistMap(DIST_MAP_NAME_AGENT, 10); + cm.addDistMap(DIST_MAP_CACHE_RECENTLY_USED_AGENTS, 1 * DAY); cm.addDistCache(CACHE_USERS, 30, 300); cm.addDistCache(CACHE_FILE_ENTRIES, 1 * HOUR + 40 * MIN, 300); @@ -158,7 +159,6 @@ public CacheConfigHolder cacheConfigMap() { cm.addLocalCache(CACHE_LEFT_PANEL_ENTRIES, 1 * DAY, 1); cm.addLocalCache(CACHE_CURRENT_PERFTEST_STATISTICS, 5, 1); cm.addLocalCache(CACHE_GITHUB_IS_MAVEN_GROOVY, 5 * MIN, 300); - cm.addLocalCache(CACHE_RECENTLY_USED_AGENTS, 1 * DAY, 100); return cm; } diff --git a/ngrinder-controller/src/test/java/org/ngrinder/agent/service/AgentServiceTest.java b/ngrinder-controller/src/test/java/org/ngrinder/agent/service/AgentServiceTest.java index a552834f20..08c4efb432 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/agent/service/AgentServiceTest.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/agent/service/AgentServiceTest.java @@ -14,7 +14,7 @@ import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.ngrinder.common.constant.CacheConstants.CACHE_RECENTLY_USED_AGENTS; +import static org.ngrinder.common.constant.CacheConstants.DIST_MAP_CACHE_RECENTLY_USED_AGENTS; import static org.ngrinder.common.util.CollectionUtils.newHashSet; public class AgentServiceTest extends AbstractNGrinderTransactionalTest { @@ -39,7 +39,7 @@ public class AgentServiceTest extends AbstractNGrinderTransactionalTest { @Test public void selectAgentsTest() { Set recentlyUsedAgents = getRecentlyUsedAgents(); - hazelcastService.put(CACHE_RECENTLY_USED_AGENTS, TEST_USER_ID, recentlyUsedAgents); + hazelcastService.put(DIST_MAP_CACHE_RECENTLY_USED_AGENTS, TEST_USER_ID, recentlyUsedAgents); User testUser = new User(); testUser.setUserId(TEST_USER_ID); @@ -65,7 +65,7 @@ public void selectAgentsTest() { recentlyUsedAgents.add(createAgentInfo("test-agent-11", "test-region_owned_test-user")); recentlyUsedAgents.add(createAgentInfo("test-agent-14", "test-region_owned_test-user")); - hazelcastService.put(CACHE_RECENTLY_USED_AGENTS, TEST_USER_ID, recentlyUsedAgents); + hazelcastService.put(DIST_MAP_CACHE_RECENTLY_USED_AGENTS, TEST_USER_ID, recentlyUsedAgents); // Add owned agents for another test. allFreeAgents.add(createAgentInfo("test-agent-8", "test-region_owned_test-user")); @@ -85,7 +85,7 @@ public void selectAgentsTest() { assertTrue(selectedAgents.contains(createAgentInfo("test-agent-11", "test-region_owned_test-user"))); assertTrue(selectedAgents.contains(createAgentInfo("test-agent-14", "test-region_owned_test-user"))); - hazelcastService.delete(CACHE_RECENTLY_USED_AGENTS, TEST_USER_ID); + hazelcastService.delete(DIST_MAP_CACHE_RECENTLY_USED_AGENTS, TEST_USER_ID); } private Set getRecentlyUsedAgents() { diff --git a/ngrinder-controller/src/test/java/org/ngrinder/agent/service/MockAgentService.java b/ngrinder-controller/src/test/java/org/ngrinder/agent/service/MockAgentService.java index 485151756a..64b21880ce 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/agent/service/MockAgentService.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/agent/service/MockAgentService.java @@ -18,7 +18,7 @@ import java.util.Set; -import static org.ngrinder.common.constant.CacheConstants.CACHE_RECENTLY_USED_AGENTS; +import static org.ngrinder.common.constant.CacheConstants.DIST_MAP_CACHE_RECENTLY_USED_AGENTS; @Profile("unit-test") @Service @@ -44,7 +44,7 @@ public synchronized void runAgent(User user, final SingleConsole singleConsole, final Set allFreeAgents = getAllAttachedFreeApprovedAgentsForUser(user.getUserId()); final Set necessaryAgents = selectAgent(user, allFreeAgents, agentCount); - hazelcastService.put(CACHE_RECENTLY_USED_AGENTS, user.getUserId(), necessaryAgents); + hazelcastService.put(DIST_MAP_CACHE_RECENTLY_USED_AGENTS, user.getUserId(), necessaryAgents); LOGGER.info("{} agents are starting for user {}", agentCount, user.getUserId()); for (AgentInfo agentInfo : necessaryAgents) { From 63b671176bacb3ec707ee1ab45301bab9908ac2d Mon Sep 17 00:00:00 2001 From: leedonggyu Date: Wed, 14 Oct 2020 08:48:26 +0900 Subject: [PATCH 03/38] Rename cache --- .../org/ngrinder/agent/service/AgentService.java | 4 ++-- .../ngrinder/common/constant/CacheConstants.java | 16 ++++++++-------- .../org/ngrinder/home/service/HomeService.java | 8 ++++---- .../infra/config/DynamicCacheConfig.java | 16 ++++++++-------- .../perftest/service/PerfTestService.java | 2 +- .../script/service/FileEntryService.java | 6 +++--- .../script/service/GitHubFileEntryService.java | 12 ++++++------ .../org/ngrinder/user/service/UserService.java | 16 ++++++++-------- 8 files changed, 40 insertions(+), 40 deletions(-) diff --git a/ngrinder-controller/src/main/java/org/ngrinder/agent/service/AgentService.java b/ngrinder-controller/src/main/java/org/ngrinder/agent/service/AgentService.java index b47f5ef764..fd3de67886 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/agent/service/AgentService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/agent/service/AgentService.java @@ -357,7 +357,7 @@ public synchronized void runAgent(User user, final SingleConsole singleConsole, "\nPlease restart perftest after few minutes."); } - hazelcastService.put(DIST_MAP_CACHE_RECENTLY_USED_AGENTS, user.getUserId(), necessaryAgents); + hazelcastService.put(DIST_MAP_NAME_RECENTLY_USED_AGENTS, user.getUserId(), necessaryAgents); LOGGER.info("{} agents are starting for user {}", agentCount, user.getUserId()); for (AgentInfo agentInfo : necessaryAgents) { @@ -386,7 +386,7 @@ private boolean hasOldVersionAgent(Set agentInfos) { * @return selected agents. */ Set selectAgent(User user, Set allFreeAgents, int agentCount) { - Set recentlyUsedAgents = hazelcastService.getOrDefault(DIST_MAP_CACHE_RECENTLY_USED_AGENTS, user.getUserId(), emptySet()); + Set recentlyUsedAgents = hazelcastService.getOrDefault(DIST_MAP_NAME_RECENTLY_USED_AGENTS, user.getUserId(), emptySet()); Comparator recentlyUsedPriorityComparator = (agent1, agent2) -> { if (recentlyUsedAgents.contains(agent1)) { diff --git a/ngrinder-controller/src/main/java/org/ngrinder/common/constant/CacheConstants.java b/ngrinder-controller/src/main/java/org/ngrinder/common/constant/CacheConstants.java index c6f288d2d3..4eeec65297 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/common/constant/CacheConstants.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/common/constant/CacheConstants.java @@ -23,14 +23,14 @@ public interface CacheConstants { String DIST_MAP_NAME_SAMPLING = "sampling"; String DIST_MAP_NAME_MONITORING = "monitoring"; String DIST_MAP_NAME_AGENT = "agent"; - String DIST_MAP_CACHE_RECENTLY_USED_AGENTS = "recently_used_agents"; + String DIST_MAP_NAME_RECENTLY_USED_AGENTS = "recently_used_agents"; - String CACHE_USERS = "users"; - String CACHE_FILE_ENTRIES = "file_entries"; + String DIST_CACHE_USERS = "users"; + String DIST_CACHE_FILE_ENTRIES = "file_entries"; - String CACHE_RIGHT_PANEL_ENTRIES = "right_panel_entries"; - String CACHE_LEFT_PANEL_ENTRIES = "left_panel_entries"; - String CACHE_CURRENT_PERFTEST_STATISTICS = "current_perftest_statistics"; + String LOCAL_CACHE_RIGHT_PANEL_ENTRIES = "right_panel_entries"; + String LOCAL_CACHE_LEFT_PANEL_ENTRIES = "left_panel_entries"; + String LOCAL_CACHE_CURRENT_PERFTEST_STATISTICS = "current_perftest_statistics"; String REGION_ATTR_KEY = "region"; String REGION_EXECUTOR_SERVICE_NAME = "region_executor"; @@ -41,8 +41,8 @@ public interface CacheConstants { String CACHE_USER_ENTITY = "org.ngrinder.model.User"; - String CACHE_GITHUB_SCRIPTS = "github_scripts"; - String CACHE_GITHUB_IS_MAVEN_GROOVY = "github_is_maven_groovy"; + String LOCAL_CACHE_GITHUB_SCRIPTS = "github_scripts"; + String LOCAL_CACHE_GITHUB_IS_MAVEN_GROOVY = "github_is_maven_groovy"; int REGION_CACHE_TIME_TO_LIVE_SECONDS = 20; } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/home/service/HomeService.java b/ngrinder-controller/src/main/java/org/ngrinder/home/service/HomeService.java index 398999a2df..bfc4a85f6e 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/home/service/HomeService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/home/service/HomeService.java @@ -31,8 +31,8 @@ import java.net.URL; import java.util.*; -import static org.ngrinder.common.constant.CacheConstants.CACHE_LEFT_PANEL_ENTRIES; -import static org.ngrinder.common.constant.CacheConstants.CACHE_RIGHT_PANEL_ENTRIES; +import static org.ngrinder.common.constant.CacheConstants.LOCAL_CACHE_LEFT_PANEL_ENTRIES; +import static org.ngrinder.common.constant.CacheConstants.LOCAL_CACHE_RIGHT_PANEL_ENTRIES; import static org.ngrinder.common.util.TypeConvertUtils.cast; /** @@ -56,7 +56,7 @@ public class HomeService { * @return the list of {@link PanelEntry} */ @SuppressWarnings("unchecked") - @Cacheable(CACHE_LEFT_PANEL_ENTRIES) + @Cacheable(LOCAL_CACHE_LEFT_PANEL_ENTRIES) public List getLeftPanelEntries(String feedURL) { return getPanelEntries(feedURL, PANEL_ENTRY_SIZE, false); } @@ -68,7 +68,7 @@ public List getLeftPanelEntries(String feedURL) { * @param feedURL rss url message * @return {@link PanelEntry} list */ - @Cacheable(CACHE_RIGHT_PANEL_ENTRIES) + @Cacheable(LOCAL_CACHE_RIGHT_PANEL_ENTRIES) public List getRightPanelEntries(String feedURL) { return getPanelEntries(feedURL, PANEL_ENTRY_SIZE, true); } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/config/DynamicCacheConfig.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/config/DynamicCacheConfig.java index c345bc9bb1..163ae96ac3 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/config/DynamicCacheConfig.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/config/DynamicCacheConfig.java @@ -149,16 +149,16 @@ public CacheConfigHolder cacheConfigMap() { cm.addDistMap(DIST_MAP_NAME_SAMPLING, 15); cm.addDistMap(DIST_MAP_NAME_MONITORING, 15); cm.addDistMap(DIST_MAP_NAME_AGENT, 10); - cm.addDistMap(DIST_MAP_CACHE_RECENTLY_USED_AGENTS, 1 * DAY); + cm.addDistMap(DIST_MAP_NAME_RECENTLY_USED_AGENTS, 1 * DAY); - cm.addDistCache(CACHE_USERS, 30, 300); - cm.addDistCache(CACHE_FILE_ENTRIES, 1 * HOUR + 40 * MIN, 300); + cm.addDistCache(DIST_CACHE_USERS, 30, 300); + cm.addDistCache(DIST_CACHE_FILE_ENTRIES, 1 * HOUR + 40 * MIN, 300); - cm.addLocalCache(CACHE_GITHUB_SCRIPTS, 5 * MIN, 300); - cm.addLocalCache(CACHE_RIGHT_PANEL_ENTRIES, 1 * DAY, 1); - cm.addLocalCache(CACHE_LEFT_PANEL_ENTRIES, 1 * DAY, 1); - cm.addLocalCache(CACHE_CURRENT_PERFTEST_STATISTICS, 5, 1); - cm.addLocalCache(CACHE_GITHUB_IS_MAVEN_GROOVY, 5 * MIN, 300); + cm.addLocalCache(LOCAL_CACHE_GITHUB_SCRIPTS, 5 * MIN, 300); + cm.addLocalCache(LOCAL_CACHE_RIGHT_PANEL_ENTRIES, 1 * DAY, 1); + cm.addLocalCache(LOCAL_CACHE_LEFT_PANEL_ENTRIES, 1 * DAY, 1); + cm.addLocalCache(LOCAL_CACHE_CURRENT_PERFTEST_STATISTICS, 5, 1); + cm.addLocalCache(LOCAL_CACHE_GITHUB_IS_MAVEN_GROOVY, 5 * MIN, 300); return cm; } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestService.java b/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestService.java index 86c470fd6d..fbc13dfca6 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestService.java @@ -1079,7 +1079,7 @@ public void addCommentOn(User user, Long testId, String testComment, String tagS * * @return PerfTestStatisticsList PerfTestStatistics list */ - @Cacheable(CACHE_CURRENT_PERFTEST_STATISTICS) + @Cacheable(LOCAL_CACHE_CURRENT_PERFTEST_STATISTICS) @Transactional public Collection getCurrentPerfTestStatistics() { Map perfTestPerUser = newHashMap(); diff --git a/ngrinder-controller/src/main/java/org/ngrinder/script/service/FileEntryService.java b/ngrinder-controller/src/main/java/org/ngrinder/script/service/FileEntryService.java index 0b6ee9f52d..4a8704e2c6 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/script/service/FileEntryService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/script/service/FileEntryService.java @@ -48,7 +48,7 @@ import static com.google.common.collect.Lists.newArrayList; import static java.util.Collections.unmodifiableList; import static org.apache.commons.compress.utils.CharsetNames.UTF_8; -import static org.ngrinder.common.constant.CacheConstants.CACHE_FILE_ENTRIES; +import static org.ngrinder.common.constant.CacheConstants.DIST_CACHE_FILE_ENTRIES; import static org.ngrinder.common.util.CollectionUtils.buildMap; import static org.ngrinder.common.util.CollectionUtils.newHashMap; import static org.ngrinder.common.util.ExceptionUtils.processException; @@ -97,7 +97,7 @@ public void init() { } }); svnClientManager = fileEntityRepository.getSVNClientManager(); - fileEntryCache = cacheManager.getCache(CACHE_FILE_ENTRIES); + fileEntryCache = cacheManager.getCache(DIST_CACHE_FILE_ENTRIES); } /** @@ -162,7 +162,7 @@ private File getUserRepoDirectory(User user) { * @param user user * @return cached {@link FileEntry} list */ - @Cacheable(value = CACHE_FILE_ENTRIES, key = "#user.userId") + @Cacheable(value = DIST_CACHE_FILE_ENTRIES, key = "#user.userId") public List getAll(User user) { prepare(user); List allFileEntries; diff --git a/ngrinder-controller/src/main/java/org/ngrinder/script/service/GitHubFileEntryService.java b/ngrinder-controller/src/main/java/org/ngrinder/script/service/GitHubFileEntryService.java index 0858b1b534..445a015ac1 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/script/service/GitHubFileEntryService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/script/service/GitHubFileEntryService.java @@ -42,8 +42,8 @@ import static org.apache.commons.io.FilenameUtils.getName; import static org.apache.commons.lang.StringUtils.isEmpty; import static org.apache.commons.lang.StringUtils.isNotEmpty; -import static org.ngrinder.common.constant.CacheConstants.CACHE_GITHUB_IS_MAVEN_GROOVY; -import static org.ngrinder.common.constant.CacheConstants.CACHE_GITHUB_SCRIPTS; +import static org.ngrinder.common.constant.CacheConstants.LOCAL_CACHE_GITHUB_IS_MAVEN_GROOVY; +import static org.ngrinder.common.constant.CacheConstants.LOCAL_CACHE_GITHUB_SCRIPTS; import static org.ngrinder.common.constant.ControllerConstants.PROP_CONTROLLER_GITHUB_BASE_URL; import static org.ngrinder.common.util.AopUtils.proxy; import static org.ngrinder.common.util.CollectionUtils.buildMap; @@ -185,7 +185,7 @@ private boolean isSvnWorkingCopyDir(File directory) { return new File(directory.getPath() + "/.svn").exists(); } - @Cacheable(value = CACHE_GITHUB_IS_MAVEN_GROOVY, key = "#ghRepository.svnUrl + #scriptPath + #activeBranch") + @Cacheable(value = LOCAL_CACHE_GITHUB_IS_MAVEN_GROOVY, key = "#ghRepository.svnUrl + #scriptPath + #activeBranch") public boolean isGroovyMavenProject(GHRepository ghRepository, String scriptPath, String activeBranch) { if (!groovyMavenProjectScriptHandler.isGroovyMavenPath(scriptPath)) { return false; @@ -331,7 +331,7 @@ private Map parseGitHubConfigurationErrorMessage(String errorMes * * @since 3.5.0 */ - @Cacheable(value = CACHE_GITHUB_SCRIPTS, key = "#user.userId") + @Cacheable(value = LOCAL_CACHE_GITHUB_SCRIPTS, key = "#user.userId") public Map> getScripts(User user) throws FileNotFoundException { Map> scriptMap = new HashMap<>(); getAllGitHubConfig(user).forEach(gitHubConfig -> { @@ -424,12 +424,12 @@ private String getGitHubBaseUrl(GitHubConfig gitHubConfig) { return (!configuredGitHubBaseUrl.isEmpty()) ? configuredGitHubBaseUrl : config.getControllerProperties().getProperty(PROP_CONTROLLER_GITHUB_BASE_URL); } - @CacheEvict(value = CACHE_GITHUB_SCRIPTS, key = "#user.userId") + @CacheEvict(value = LOCAL_CACHE_GITHUB_SCRIPTS, key = "#user.userId") public void evictGitHubScriptCache(User user) { noOp(); } - @CacheEvict(value = CACHE_GITHUB_IS_MAVEN_GROOVY, key = "#ghRepository.svnUrl + #scriptPath + #activeBranch") + @CacheEvict(value = LOCAL_CACHE_GITHUB_IS_MAVEN_GROOVY, key = "#ghRepository.svnUrl + #scriptPath + #activeBranch") public void evictGitHubMavenGroovyCache(GHRepository ghRepository, String scriptPath, String activeBranch) { noOp(); } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java b/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java index 3fd4e5e6d1..ad3241986e 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java @@ -45,7 +45,7 @@ import static org.apache.commons.lang.StringUtils.isBlank; import static org.hibernate.Hibernate.initialize; -import static org.ngrinder.common.constant.CacheConstants.CACHE_USERS; +import static org.ngrinder.common.constant.CacheConstants.DIST_CACHE_USERS; import static org.ngrinder.common.constant.CacheConstants.CACHE_USER_ENTITY; import static org.springframework.data.domain.Sort.Direction.*; import static org.springframework.data.domain.Sort.by; @@ -81,7 +81,7 @@ public UserService(UserRepository userRepository, PerfTestService perfTestServic @PostConstruct public void init() { - userCache = cacheManager.getCache(CACHE_USERS); + userCache = cacheManager.getCache(DIST_CACHE_USERS); userModelCache = cacheManager.getCache(CACHE_USER_ENTITY); } @@ -92,7 +92,7 @@ public void init() { * @return user */ @Transactional - @Cacheable(value = CACHE_USERS, key = "#userId") + @Cacheable(value = DIST_CACHE_USERS, key = "#userId") @Override public User getOne(String userId) { User user = userRepository.findOneByUserId(userId); @@ -134,7 +134,7 @@ public void encodePassword(User user) { * @return User */ @Transactional - @CachePut(value = CACHE_USERS, key = "#user.userId") + @CachePut(value = DIST_CACHE_USERS, key = "#user.userId") @Override public User save(User user) { encodePassword(user); @@ -148,7 +148,7 @@ public User save(User user) { * @return User */ @Transactional - @CachePut(value = CACHE_USERS, key = "#user.userId") + @CachePut(value = DIST_CACHE_USERS, key = "#user.userId") @Override public User saveWithoutPasswordEncoding(User user) { final List followers = getFollowers(user.getFollowersStr()); @@ -166,7 +166,7 @@ public User saveWithoutPasswordEncoding(User user) { } @Transactional - @CachePut(value = CACHE_USERS, key = "#user.userId") + @CachePut(value = DIST_CACHE_USERS, key = "#user.userId") public User saveWithoutFollowers(User user) { if (user.getPassword() != null && isBlank(user.getPassword())) { user.setPassword(null); @@ -210,7 +210,7 @@ private List getFollowers(String followersStr) { */ @SuppressWarnings("SpringElInspection") @Transactional - @CacheEvict(value = CACHE_USERS, key = "#userId") + @CacheEvict(value = DIST_CACHE_USERS, key = "#userId") public void delete(String userId) { User user = getOne(userId); List deletePerfTests = perfTestService.deleteAll(user); @@ -282,7 +282,7 @@ public Page getPagedAll(String keyword, Pageable pageable) { * @return User */ @Transactional - @CachePut(value = CACHE_USERS, key = "#user.userId") + @CachePut(value = DIST_CACHE_USERS, key = "#user.userId") @Override public User createUser(User user) { encodePassword(user); From d21e1e69aa6b63a3aa9fbdf1a8a45656faad8ec6 Mon Sep 17 00:00:00 2001 From: leedonggyu Date: Thu, 15 Oct 2020 11:50:55 +0900 Subject: [PATCH 04/38] Make the modified file distribution handler to be loaded first --- .../distribution/FileDistributionHandlerImplementation.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {ngrinder-core => ngrinder-controller}/src/main/java/net/grinder/console/distribution/FileDistributionHandlerImplementation.java (100%) diff --git a/ngrinder-core/src/main/java/net/grinder/console/distribution/FileDistributionHandlerImplementation.java b/ngrinder-controller/src/main/java/net/grinder/console/distribution/FileDistributionHandlerImplementation.java similarity index 100% rename from ngrinder-core/src/main/java/net/grinder/console/distribution/FileDistributionHandlerImplementation.java rename to ngrinder-controller/src/main/java/net/grinder/console/distribution/FileDistributionHandlerImplementation.java From 319feb4620c876994becb419310a0039dca29bb2 Mon Sep 17 00:00:00 2001 From: leedonggyu Date: Fri, 16 Oct 2020 10:48:49 +0900 Subject: [PATCH 05/38] Add .gitattributes --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..4cab1f4d26 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto From 4d37b16bbe720010bc34e6482f250793888e5433 Mon Sep 17 00:00:00 2001 From: leedonggyu Date: Sat, 17 Oct 2020 08:50:45 +0900 Subject: [PATCH 06/38] Make the H2 console optionally available --- .../main/java/org/ngrinder/infra/config/SecurityConfig.java | 4 +++- ngrinder-controller/src/main/resources/application.yml | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/config/SecurityConfig.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/config/SecurityConfig.java index 738399df91..9968b742c6 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/config/SecurityConfig.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/config/SecurityConfig.java @@ -171,7 +171,9 @@ protected void configure(HttpSecurity http) throws Exception { .key("ngrinder") .userDetailsService(ngrinderUserDetailsService) .and() - .csrf().disable().exceptionHandling().authenticationEntryPoint(delegatingAuthenticationEntryPoint()); + .csrf().disable().exceptionHandling().authenticationEntryPoint(delegatingAuthenticationEntryPoint()) + .and() + .headers().frameOptions().sameOrigin(); } /** diff --git a/ngrinder-controller/src/main/resources/application.yml b/ngrinder-controller/src/main/resources/application.yml index de3cbe0f6c..cea94c9fc5 100644 --- a/ngrinder-controller/src/main/resources/application.yml +++ b/ngrinder-controller/src/main/resources/application.yml @@ -33,3 +33,7 @@ spring: multipart: max-file-size: 100MB max-request-size: 100MB + h2: + console: + enabled: false + path: /h2-console From 5ef4511b298041a1fd67b992e405ed3b6665da25 Mon Sep 17 00:00:00 2001 From: leedonggyu Date: Thu, 8 Oct 2020 18:14:22 +0900 Subject: [PATCH 07/38] Prevent lazy initialize exception in spring security authentication object --- .../UserHandlerMethodArgumentResolver.java | 6 +++--- .../org/ngrinder/security/SecuredUser.java | 2 +- .../security/UserSwitchPermissionVoter.java | 10 ++++++++-- .../user/controller/UserApiController.java | 4 ++-- .../ngrinder/user/service/UserService.java | 19 +++++++++---------- .../main/java/org/ngrinder/model/User.java | 1 - 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/spring/UserHandlerMethodArgumentResolver.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/spring/UserHandlerMethodArgumentResolver.java index 7cf32d96ad..751e3b803f 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/spring/UserHandlerMethodArgumentResolver.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/spring/UserHandlerMethodArgumentResolver.java @@ -50,7 +50,7 @@ public boolean supportsParameter(MethodParameter parameter) { @Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) { User currentUser = getUserContext().getCurrentUser(); String userParam = webRequest.getParameter("ownerId"); @@ -71,11 +71,11 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m } // Let this can be done with parameter as well. switchUser = StringUtils.defaultIfBlank(webRequest.getParameter("switchUser"), switchUser); - + if (currentUser.getUserId().equals(switchUser)) { currentUser.setOwnerUser(null); } else if (StringUtils.isNotEmpty(switchUser)) { - User ownerUser = getUserService().getOne(switchUser); + User ownerUser = getUserService().getOneWithEagerFetch(switchUser); // CurrentUser should remember whose status he used if (currentUser.getRole().hasPermission(Permission.SWITCH_TO_ANYONE) || (ownerUser.getFollowers() != null && ownerUser.getFollowers().contains(currentUser))) { diff --git a/ngrinder-controller/src/main/java/org/ngrinder/security/SecuredUser.java b/ngrinder-controller/src/main/java/org/ngrinder/security/SecuredUser.java index 8f206263a6..c7ba3289f1 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/security/SecuredUser.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/security/SecuredUser.java @@ -52,7 +52,7 @@ public class SecuredUser implements UserDetails { * @param userInfoProviderClass class name who provides the user info */ public SecuredUser(User user, String userInfoProviderClass) { - this.setUser(user); + this.user = user; this.userInfoProviderClass = userInfoProviderClass; } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/security/UserSwitchPermissionVoter.java b/ngrinder-controller/src/main/java/org/ngrinder/security/UserSwitchPermissionVoter.java index d2e7e7348f..d7330d328c 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/security/UserSwitchPermissionVoter.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/security/UserSwitchPermissionVoter.java @@ -18,9 +18,11 @@ import java.util.Collection; import java.util.List; +import lombok.AllArgsConstructor; import org.apache.commons.lang.StringUtils; import org.ngrinder.model.Role; import org.ngrinder.model.User; +import org.ngrinder.user.service.UserService; import org.springframework.security.access.AccessDecisionVoter; import org.springframework.security.access.ConfigAttribute; import org.springframework.security.core.Authentication; @@ -33,8 +35,11 @@ * @since 3.2 */ @Component("userSwitchPermissionVoter") +@AllArgsConstructor public class UserSwitchPermissionVoter implements AccessDecisionVoter { + private final UserService userService; + @Override public boolean supports(ConfigAttribute attribute) { return true; @@ -54,8 +59,8 @@ public int vote(Authentication authentication, FilterInvocation filter, Collecti return ACCESS_DENIED; } SecuredUser secureUser = cast(authentication.getPrincipal()); - User user = secureUser.getUser(); - if (user.getRole() == Role.ADMIN) { + User loginUser = secureUser.getUser(); + if (loginUser.getRole() == Role.ADMIN) { return ACCESS_GRANTED; } @@ -63,6 +68,7 @@ public int vote(Authentication authentication, FilterInvocation filter, Collecti if (secureUser.getUsername().equals(realm)) { return ACCESS_GRANTED; } else { + User user = userService.getOneWithEagerFetch(loginUser.getUserId()); List owners = user.getOwners(); for (User each : owners) { if (realm.equals(each.getUserId())) { diff --git a/ngrinder-controller/src/main/java/org/ngrinder/user/controller/UserApiController.java b/ngrinder-controller/src/main/java/org/ngrinder/user/controller/UserApiController.java index 89c81e478d..4283073094 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/user/controller/UserApiController.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/user/controller/UserApiController.java @@ -66,7 +66,7 @@ public List switchOptions(User user, @RequestParam(defaultValue = "") fina @GetMapping("/profile") public Map getOne(User user) { checkNotEmpty(user.getUserId(), "UserID should not be NULL!"); - User one = userService.getOneWithFollowers(user.getUserId()); + User one = userService.getOneWithEagerFetch(user.getUserId()); Map viewConfig = new HashMap<>(); viewConfig.put("allowPasswordChange", !config.isDemo()); @@ -117,7 +117,7 @@ public Map openForm(User user) { @GetMapping("/{userId}/detail") @PreAuthorize("hasAnyRole('A')") public Map getOneDetail(@PathVariable final String userId) { - User one = userService.getOneWithFollowers(userId); + User one = userService.getOneWithEagerFetch(userId); Map viewConfig = new HashMap<>(); viewConfig.put("allowPasswordChange", true); diff --git a/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java b/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java index ad3241986e..57e06d9da0 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java @@ -95,24 +95,23 @@ public void init() { @Cacheable(value = DIST_CACHE_USERS, key = "#userId") @Override public User getOne(String userId) { - User user = userRepository.findOneByUserId(userId); - if (user != null) { - initialize(user.getFollowers()); - } - return user; + return userRepository.findOneByUserId(userId); } /** - * Get user by user id with followers. + * Get user by user id with eager fetch. * * @param userId user id * @return user */ @Transactional - public User getOneWithFollowers(String userId) { - User one = userRepository.findOneByUserId(userId); - one.getFollowers().size(); - return one; + public User getOneWithEagerFetch(String userId) { + User user = userRepository.findOneByUserId(userId); + if (user != null) { + initialize(user.getOwners()); + initialize(user.getFollowers()); + } + return user; } /** diff --git a/ngrinder-core/src/main/java/org/ngrinder/model/User.java b/ngrinder-core/src/main/java/org/ngrinder/model/User.java index 62792419e8..48a9ca0ef9 100644 --- a/ngrinder-core/src/main/java/org/ngrinder/model/User.java +++ b/ngrinder-core/src/main/java/org/ngrinder/model/User.java @@ -24,7 +24,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import com.fasterxml.jackson.databind.ser.std.StdSerializer; -import org.apache.commons.lang.StringUtils; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.Type; From cae2f5242f7f0c5d6e6353fce3bfdf75c2442571 Mon Sep 17 00:00:00 2001 From: leedonggyu Date: Thu, 22 Oct 2020 21:56:42 +0900 Subject: [PATCH 08/38] Fix failed unit test --- .../agent/service/AgentServiceTest.java | 8 ++++---- .../agent/service/MockAgentService.java | 4 ++-- .../engine/agent/PropertyBuilderTest.java | 18 +++++++++--------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ngrinder-controller/src/test/java/org/ngrinder/agent/service/AgentServiceTest.java b/ngrinder-controller/src/test/java/org/ngrinder/agent/service/AgentServiceTest.java index 08c4efb432..e28b474301 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/agent/service/AgentServiceTest.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/agent/service/AgentServiceTest.java @@ -14,7 +14,7 @@ import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.ngrinder.common.constant.CacheConstants.DIST_MAP_CACHE_RECENTLY_USED_AGENTS; +import static org.ngrinder.common.constant.CacheConstants.DIST_MAP_NAME_RECENTLY_USED_AGENTS; import static org.ngrinder.common.util.CollectionUtils.newHashSet; public class AgentServiceTest extends AbstractNGrinderTransactionalTest { @@ -39,7 +39,7 @@ public class AgentServiceTest extends AbstractNGrinderTransactionalTest { @Test public void selectAgentsTest() { Set recentlyUsedAgents = getRecentlyUsedAgents(); - hazelcastService.put(DIST_MAP_CACHE_RECENTLY_USED_AGENTS, TEST_USER_ID, recentlyUsedAgents); + hazelcastService.put(DIST_MAP_NAME_RECENTLY_USED_AGENTS, TEST_USER_ID, recentlyUsedAgents); User testUser = new User(); testUser.setUserId(TEST_USER_ID); @@ -65,7 +65,7 @@ public void selectAgentsTest() { recentlyUsedAgents.add(createAgentInfo("test-agent-11", "test-region_owned_test-user")); recentlyUsedAgents.add(createAgentInfo("test-agent-14", "test-region_owned_test-user")); - hazelcastService.put(DIST_MAP_CACHE_RECENTLY_USED_AGENTS, TEST_USER_ID, recentlyUsedAgents); + hazelcastService.put(DIST_MAP_NAME_RECENTLY_USED_AGENTS, TEST_USER_ID, recentlyUsedAgents); // Add owned agents for another test. allFreeAgents.add(createAgentInfo("test-agent-8", "test-region_owned_test-user")); @@ -85,7 +85,7 @@ public void selectAgentsTest() { assertTrue(selectedAgents.contains(createAgentInfo("test-agent-11", "test-region_owned_test-user"))); assertTrue(selectedAgents.contains(createAgentInfo("test-agent-14", "test-region_owned_test-user"))); - hazelcastService.delete(DIST_MAP_CACHE_RECENTLY_USED_AGENTS, TEST_USER_ID); + hazelcastService.delete(DIST_MAP_NAME_RECENTLY_USED_AGENTS, TEST_USER_ID); } private Set getRecentlyUsedAgents() { diff --git a/ngrinder-controller/src/test/java/org/ngrinder/agent/service/MockAgentService.java b/ngrinder-controller/src/test/java/org/ngrinder/agent/service/MockAgentService.java index 64b21880ce..10cc0372e7 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/agent/service/MockAgentService.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/agent/service/MockAgentService.java @@ -18,7 +18,7 @@ import java.util.Set; -import static org.ngrinder.common.constant.CacheConstants.DIST_MAP_CACHE_RECENTLY_USED_AGENTS; +import static org.ngrinder.common.constant.CacheConstants.DIST_MAP_NAME_RECENTLY_USED_AGENTS; @Profile("unit-test") @Service @@ -44,7 +44,7 @@ public synchronized void runAgent(User user, final SingleConsole singleConsole, final Set allFreeAgents = getAllAttachedFreeApprovedAgentsForUser(user.getUserId()); final Set necessaryAgents = selectAgent(user, allFreeAgents, agentCount); - hazelcastService.put(DIST_MAP_CACHE_RECENTLY_USED_AGENTS, user.getUserId(), necessaryAgents); + hazelcastService.put(DIST_MAP_NAME_RECENTLY_USED_AGENTS, user.getUserId(), necessaryAgents); LOGGER.info("{} agents are starting for user {}", agentCount, user.getUserId()); for (AgentInfo agentInfo : necessaryAgents) { diff --git a/ngrinder-core/src/test/java/net/grinder/engine/agent/PropertyBuilderTest.java b/ngrinder-core/src/test/java/net/grinder/engine/agent/PropertyBuilderTest.java index b500b8a4ab..167705a4bd 100644 --- a/ngrinder-core/src/test/java/net/grinder/engine/agent/PropertyBuilderTest.java +++ b/ngrinder-core/src/test/java/net/grinder/engine/agent/PropertyBuilderTest.java @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -9,7 +9,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package net.grinder.engine.agent; @@ -32,17 +32,17 @@ public void testPropertyBuilder() throws DirectoryException { System.setProperty("java.library.path", System.getProperty("java.library.path") + File.pathSeparator + new File("./native_lib").getAbsolutePath()); - PropertyBuilder propertyBuilder = createPropertyBuilder("www.samples.com,:127.0.0.1"); - assertTrue(propertyBuilder.rebaseHostString("www.samples.com,:127.0.0.1") - .matches("www.samples.com:.*,:127.0.0.1")); - assertThat(propertyBuilder.rebaseHostString("www.samples.com:74.125.128.99"), - is("www.samples.com:74.125.128.99")); + PropertyBuilder propertyBuilder = createPropertyBuilder("www.sample.com,:127.0.0.1"); + assertTrue(propertyBuilder.rebaseHostString("www.sample.com,:127.0.0.1") + .matches("www.sample.com:.*,:127.0.0.1")); + assertThat(propertyBuilder.rebaseHostString("www.sample.com:74.125.128.99"), + is("www.sample.com:74.125.128.99")); assertThat(propertyBuilder.rebaseHostString(":127.0.0.1"), is(":127.0.0.1")); } @Test public void testDnsServerResolver() throws DirectoryException { - PropertyBuilder propertyBuilder = createPropertyBuilder("www.samples.com,:127.0.0.1"); + PropertyBuilder propertyBuilder = createPropertyBuilder("www.sample.com,:127.0.0.1"); StringBuilder builder = new StringBuilder(); propertyBuilder.addDnsIP(builder); assertThat(builder.toString(), containsString("ngrinder.dns.ip=")); @@ -54,7 +54,7 @@ public void testPropertyBuilderMemSize() throws DirectoryException { System.setProperty("java.library.path", System.getProperty("java.library.path") + File.pathSeparator + new File("./native_lib").getAbsolutePath()); - PropertyBuilder propertyBuilder = createPropertyBuilder("www.samples.com,:127.0.0.1"); + PropertyBuilder propertyBuilder = createPropertyBuilder("www.sample.com,:127.0.0.1"); propertyBuilder.addProperties("grinder.processes", "10"); String buildJVMArgument = propertyBuilder.buildJVMArgument(); assertThat(buildJVMArgument, containsString("-Xmx")); From 92109fb539d358445c0e51908c4eac28c6e365aa Mon Sep 17 00:00:00 2001 From: leedonggyu Date: Tue, 20 Oct 2020 02:02:42 +0900 Subject: [PATCH 09/38] Support UTC --- .../ngrinder/common/service/ModelAspect.java | 5 +-- .../ngrinder/infra/config/JacksonConfig.java | 13 +++++--- .../java/org/ngrinder/infra/init/DBInit.java | 5 +-- .../ngrinder/infra/webhook/model/Event.java | 3 +- .../webhook/model/WebhookActivation.java | 4 +-- .../infra/webhook/model/WebhookConfig.java | 10 +++--- .../webhook/service/WebhookConfigService.java | 4 +-- .../infra/webhook/service/WebhookService.java | 4 +-- .../perftest/service/PerfTestRunnable.java | 24 +++++++------- .../perftest/service/PerfTestService.java | 3 +- .../ngrinder/perftest/service/TagService.java | 4 ++- .../repository/FileEntryRepository.java | 8 ++--- ...NGrinderAuthenticationPreAuthProvider.java | 5 +-- .../NGrinderAuthenticationProvider.java | 5 ++- .../ngrinder/user/service/UserService.java | 4 +-- .../common/service/ModelAspectTest.java | 6 ++-- .../controller/PerfTestControllerTest.java | 32 +++++++++---------- .../AbstractPerfTestTransactionalTest.java | 13 +++++--- .../perftest/service/PerfTestServiceTest.java | 24 +++++++------- .../perftest/service/TagServiceTest.java | 5 +-- .../user/controller/UserControllerTest.java | 4 +-- .../org/ngrinder/user/model/UserTest.java | 27 +++++++++------- .../java/org/ngrinder/model/BaseModel.java | 6 ++-- .../java/org/ngrinder/model/PerfTest.java | 18 ++++++----- .../js/components/perftest/detail/Detail.vue | 2 +- 25 files changed, 130 insertions(+), 108 deletions(-) diff --git a/ngrinder-controller/src/main/java/org/ngrinder/common/service/ModelAspect.java b/ngrinder-controller/src/main/java/org/ngrinder/common/service/ModelAspect.java index 8303a9f6d6..5f47084d67 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/common/service/ModelAspect.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/common/service/ModelAspect.java @@ -25,8 +25,9 @@ import org.ngrinder.user.service.UserContext; import org.springframework.stereotype.Service; -import java.util.Date; +import java.time.Instant; +import static java.time.Instant.now; import static org.ngrinder.user.repository.UserSpecification.idEqual; /** @@ -61,7 +62,7 @@ public void beforeSave(JoinPoint joinPoint) { if (object instanceof BaseModel && (springContext.isAuthenticationContext() || springContext.isUnitTestContext())) { BaseModel model = (BaseModel) object; - Date lastModifiedDate = new Date(); + Instant lastModifiedDate = now(); model.setLastModifiedDate(lastModifiedDate); User currentUser = userContext.getCurrentUser(); diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/config/JacksonConfig.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/config/JacksonConfig.java index 79e5836c67..94a80c939e 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/config/JacksonConfig.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/config/JacksonConfig.java @@ -21,22 +21,27 @@ package org.ngrinder.infra.config; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import java.text.SimpleDateFormat; - @Configuration public class JacksonConfig { + @Bean public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() { return customizer -> { customizer.serializationInclusion(JsonInclude.Include.NON_NULL); customizer.indentOutput(true); - customizer.timeZone("GMT"); - customizer.dateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")); customizer.modules(new NumberModule()); + customizer.modules(new JavaTimeModule()); + + customizer.featuresToEnable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + customizer.featuresToDisable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS); + customizer.featuresToDisable(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS); }; } } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/init/DBInit.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/init/DBInit.java index 76131207e6..5f485ab996 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/init/DBInit.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/init/DBInit.java @@ -22,8 +22,9 @@ import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; -import java.util.Date; +import java.time.Instant; +import static java.time.Instant.now; import static org.ngrinder.common.constant.ControllerConstants.PROP_CONTROLLER_ADMIN_PASSWORD_RESET; import static org.ngrinder.model.Role.*; @@ -89,7 +90,7 @@ private void createUser(String userId, String password, Role role, String userNa user.setUserName(userName); user.setEmail(email); - Date now = new Date(); + Instant now = now(); user.setCreatedDate(now); user.setLastModifiedDate(now); user.setCreatedUser(user); diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/Event.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/Event.java index bef5fc0622..b0008ba6d8 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/Event.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/Event.java @@ -26,10 +26,11 @@ import org.ngrinder.model.Status; import org.ngrinder.model.User; +import java.time.Instant; import java.util.Map; import java.util.function.Function; -import static java.time.LocalDateTime.now; +import static java.time.Instant.now; import static org.ngrinder.common.util.AccessUtils.getSafe; import static org.ngrinder.common.util.CollectionUtils.newHashMap; import static org.ngrinder.model.Status.UNKNOWN; diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/WebhookActivation.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/WebhookActivation.java index b16e2ce252..4cfccbb4d3 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/WebhookActivation.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/WebhookActivation.java @@ -29,7 +29,7 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import java.util.Date; +import java.time.Instant; /** * Webhook activation model. @@ -48,7 +48,7 @@ public class WebhookActivation extends BaseEntity { private String createdUserId; @Column(name = "created_time") - private Date createdTime; + private Instant createdTime; private String request; diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/WebhookConfig.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/WebhookConfig.java index d93c5df0f6..683dfeaf56 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/WebhookConfig.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/WebhookConfig.java @@ -24,11 +24,11 @@ import org.ngrinder.model.BaseEntity; import javax.persistence.*; -import java.util.Date; +import java.time.Instant; import java.util.Set; +import static java.time.Instant.now; import static org.apache.commons.lang.StringUtils.isEmpty; -import static org.ngrinder.common.util.AccessUtils.getSafe; import static org.ngrinder.common.util.CollectionUtils.newHashSet; /** @@ -59,10 +59,10 @@ public class WebhookConfig extends BaseEntity { private String events; @Column(name = "created_time") - private Date createdTime; + private Instant createdTime; @Column(name = "last_modified_time") - private Date lastModifiedTime; + private Instant lastModifiedTime; @Transient @Getter(value = AccessLevel.NONE) @@ -70,7 +70,7 @@ public class WebhookConfig extends BaseEntity { @PreUpdate public void preUpdate() { - this.lastModifiedTime = new Date(); + this.lastModifiedTime = now(); } public Set getEvents() { diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookConfigService.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookConfigService.java index b63022e702..dd5d7b188a 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookConfigService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookConfigService.java @@ -27,9 +27,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Date; import java.util.Optional; +import static java.time.Instant.now; import static org.ngrinder.common.util.Preconditions.checkNotNull; import static org.ngrinder.infra.webhook.repository.WebhookConfigSpecification.createdUserIdEqual; @@ -49,7 +49,7 @@ public void save(WebhookConfig webhookConfig) { existingWebhookConfig.update(webhookConfig); return; } - webhookConfig.setCreatedTime(new Date()); + webhookConfig.setCreatedTime(now()); webhookConfigRepository.save(webhookConfig); } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookService.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookService.java index 9e1f7c08cf..0ee8710070 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookService.java @@ -33,11 +33,11 @@ import org.springframework.stereotype.Service; import reactor.core.publisher.Mono; -import java.util.Date; import java.util.Map; import java.util.UUID; import static java.time.Duration.ofSeconds; +import static java.time.Instant.now; import static org.ngrinder.common.util.AccessUtils.getSafe; import static org.ngrinder.common.util.CollectionUtils.newHashMap; import static org.springframework.http.HttpStatus.BAD_REQUEST; @@ -103,7 +103,7 @@ private void saveWebhookActivation(PerfTest perfTest, } catch (JsonProcessingException e) { webhookActivation.setResponse(response.toString()); } - webhookActivation.setCreatedTime(new Date()); + webhookActivation.setCreatedTime(now()); webhookActivationService.save(webhookActivation); } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestRunnable.java b/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestRunnable.java index ebe05775f1..6ca4fdd6e7 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestRunnable.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestRunnable.java @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -9,7 +9,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package org.ngrinder.perftest.service; @@ -25,7 +25,6 @@ import net.grinder.util.ListenerSupport; import net.grinder.util.UnitUtils; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.time.DateUtils; import org.ngrinder.agent.service.AgentService; import org.ngrinder.common.constant.ControllerConstants; import org.ngrinder.common.exception.PerfTestPrepareException; @@ -51,11 +50,13 @@ import javax.annotation.PreDestroy; import java.io.File; import java.io.IOException; -import java.util.Calendar; -import java.util.Date; +import java.time.Instant; import java.util.List; import java.util.Set; +import static java.time.Instant.now; +import static java.time.Instant.ofEpochSecond; +import static java.time.temporal.ChronoUnit.MINUTES; import static java.util.Arrays.asList; import static java.util.stream.Collectors.toSet; import static net.grinder.util.FileUtils.*; @@ -64,6 +65,7 @@ import static org.ngrinder.common.constant.CacheConstants.DIST_MAP_NAME_SAMPLING; import static org.ngrinder.common.constant.ClusterConstants.PROP_CLUSTER_SAFE_DIST; import static org.ngrinder.common.util.AccessUtils.getSafe; +import static org.ngrinder.common.util.TypeConvertUtils.cast; import static org.ngrinder.model.Status.*; /** @@ -174,10 +176,9 @@ private boolean canExecuteMore() { } private boolean isScheduledNow(PerfTest test) { - Date current = new Date(); - Date scheduledDate = DateUtils - .truncate((Date) defaultIfNull(test.getScheduledTime(), current), Calendar.MINUTE); - return current.after(scheduledDate); + Instant now = now(); + Instant scheduledTime = cast(defaultIfNull(test.getScheduledTime(), now)); + return (now.truncatedTo(MINUTES).getEpochSecond() - scheduledTime.truncatedTo(MINUTES).getEpochSecond()) >= 0; } /** @@ -403,11 +404,10 @@ public void readyToStop(StopReason stopReason) { } }); long startTime = singleConsole.startTest(grinderProperties); - perfTest.setStartTime(new Date(startTime)); + perfTest.setStartTime(ofEpochSecond(startTime / 1000)); addSamplingListeners(perfTest, singleConsole); perfTestService.markStatusAndProgress(perfTest, TESTING, "The test is started."); singleConsole.startSampling(); - } protected void addSamplingListeners(final PerfTest perfTest, final SingleConsole singleConsole) { @@ -415,7 +415,7 @@ protected void addSamplingListeners(final PerfTest perfTest, final SingleConsole singleConsole.addSamplingLifeCycleListener(new PerfTestSamplingCollectorListener(singleConsole, perfTest.getId(), perfTestService, scheduledTaskService)); singleConsole.addSamplingLifeCycleListener(new AgentLostDetectionListener(singleConsole, perfTest, - perfTestService, scheduledTaskService));; + perfTestService, scheduledTaskService)); List testSamplingPlugins = pluginManager.getEnabledModulesByClass (OnTestSamplingRunnable.class, asList(new MonitorCollectorPlugin(config, scheduledTaskService, perfTestService, perfTest.getId()), new TooManyErrorCheckPlugin())); diff --git a/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestService.java b/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestService.java index fbc13dfca6..d2b04ff0cb 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestService.java @@ -73,6 +73,7 @@ import java.util.Map.Entry; import static java.lang.Long.valueOf; +import static java.time.Instant.now; import static java.util.stream.Collectors.toList; import static org.apache.commons.io.FileUtils.deleteQuietly; import static java.util.Arrays.asList; @@ -376,7 +377,7 @@ public PerfTest markProgressAndStatus(PerfTest perfTest, Status status, String m */ @Transactional public PerfTest markProgressAndStatusAndFinishTimeAndStatistics(PerfTest perfTest, Status status, String message) { - perfTest.setFinishTime(new Date()); + perfTest.setFinishTime(now()); updatePerfTestAfterTestFinish(perfTest); return markProgressAndStatus(perfTest, status, message); } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/TagService.java b/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/TagService.java index 22302a03ce..670e93f153 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/TagService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/TagService.java @@ -24,8 +24,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.Instant; import java.util.*; +import static java.time.Instant.now; import static java.util.stream.Collectors.toList; import static org.ngrinder.perftest.repository.TagSpecification.*; @@ -112,7 +114,7 @@ public List getAllTagStrings(User user, String query) { * @return saved {@link Tag} instance */ public Tag saveTag(User user, Tag tag) { - Date createdDate = new Date(); + Instant createdDate = now(); if (tag.getCreatedUser() == null) { tag.setCreatedUser(user); tag.setCreatedDate(createdDate); diff --git a/ngrinder-controller/src/main/java/org/ngrinder/script/repository/FileEntryRepository.java b/ngrinder-controller/src/main/java/org/ngrinder/script/repository/FileEntryRepository.java index db0dfd2ec8..b1b2f88e1d 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/script/repository/FileEntryRepository.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/script/repository/FileEntryRepository.java @@ -142,8 +142,8 @@ public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException { return; } script.setPath(FilenameUtils.normalize(path + "/" + dirEntry.getRelativePath(), true)); - script.setCreatedDate(dirEntry.getDate()); - script.setLastModifiedDate(dirEntry.getDate()); + script.setCreatedDate(dirEntry.getDate().toInstant()); + script.setLastModifiedDate(dirEntry.getDate().toInstant()); script.setDescription(dirEntry.getCommitMessage()); script.setRevision(dirEntry.getRevision()); if (dirEntry.getKind() == SVNNodeKind.DIR) { @@ -183,8 +183,8 @@ public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException { if (StringUtils.isBlank(relativePath)) { return; } - script.setCreatedDate(dirEntry.getDate()); - script.setLastModifiedDate(dirEntry.getDate()); + script.setCreatedDate(dirEntry.getDate().toInstant()); + script.setLastModifiedDate(dirEntry.getDate().toInstant()); script.setPath(relativePath); script.setDescription(dirEntry.getCommitMessage()); long reversion = dirEntry.getRevision(); diff --git a/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationPreAuthProvider.java b/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationPreAuthProvider.java index 14ec0c753c..1ad87220e6 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationPreAuthProvider.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationPreAuthProvider.java @@ -13,7 +13,6 @@ */ package org.ngrinder.security; -import java.util.Date; import java.util.HashMap; import org.ngrinder.model.Role; @@ -27,6 +26,8 @@ import lombok.Setter; +import static java.time.Instant.now; + /** * nGrinder {@link PreAuthenticatedAuthenticationProvider}. * @@ -91,7 +92,7 @@ public Authentication authenticate(Authentication authentication) { public void addNewUserIntoLocal(SecuredUser securedUser) { User user = securedUser.getUser(); user.setAuthProviderClass(securedUser.getUserInfoProviderClass()); - user.setCreatedDate(new Date()); + user.setCreatedDate(now()); User findOneByUserId = userService.getOne(user.getUserId()); if (findOneByUserId != null) { user = findOneByUserId.merge(user); diff --git a/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationProvider.java b/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationProvider.java index 14c1018a0a..5a6a6318a6 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationProvider.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationProvider.java @@ -38,8 +38,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; -import java.util.Date; - +import static java.time.Instant.now; import static java.util.Arrays.asList; /** @@ -137,7 +136,7 @@ protected void additionalAuthenticationChecks(UserDetails userDetails, public void addNewUserIntoLocal(SecuredUser securedUser) { User user = securedUser.getUser(); user.setAuthProviderClass(securedUser.getUserInfoProviderClass()); - user.setCreatedDate(new Date()); + user.setCreatedDate(now()); User newUser = userService.getOne(user.getUserId()); if (newUser != null) { user = newUser.merge(user); diff --git a/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java b/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java index 57e06d9da0..73d75b8997 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java @@ -39,8 +39,8 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.PostConstruct; +import java.time.Instant; import java.util.ArrayList; -import java.util.Date; import java.util.List; import static org.apache.commons.lang.StringUtils.isBlank; @@ -285,7 +285,7 @@ public Page getPagedAll(String keyword, Pageable pageable) { @Override public User createUser(User user) { encodePassword(user); - Date createdDate = new Date(); + Instant createdDate = Instant.now(); user.setCreatedDate(createdDate); user.setLastModifiedDate(createdDate); User createdUser = getOne(ControllerConstants.NGRINDER_INITIAL_ADMIN_USERID); diff --git a/ngrinder-controller/src/test/java/org/ngrinder/common/service/ModelAspectTest.java b/ngrinder-controller/src/test/java/org/ngrinder/common/service/ModelAspectTest.java index d2290af575..a42806bb67 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/common/service/ModelAspectTest.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/common/service/ModelAspectTest.java @@ -21,7 +21,7 @@ import org.ngrinder.model.BaseModel; import org.springframework.beans.factory.annotation.Autowired; -import java.util.Date; +import java.time.Instant; import static org.hamcrest.Matchers.is; import static org.mockito.Matchers.any; @@ -44,7 +44,7 @@ public void testModelAspect() { BaseModel baseModel = mock(BaseModel.class); when(joinPoint.getArgs()).thenReturn(new Object[] { baseModel }); modelAspect.beforeSave(joinPoint); - verify(baseModel, times(1)).setCreatedDate(any(Date.class)); + verify(baseModel, times(1)).setCreatedDate(any(Instant.class)); } @Test @@ -58,6 +58,6 @@ public void testModelAspectOnServletContext() { when(joinPoint.getArgs()).thenReturn(new Object[] { baseModel }); setField(modelAspect, "springContext", springContext); modelAspect.beforeSave(joinPoint); - verify(baseModel, times(1)).setLastModifiedDate(any(Date.class)); + verify(baseModel, times(1)).setLastModifiedDate(any(Instant.class)); } } diff --git a/ngrinder-controller/src/test/java/org/ngrinder/perftest/controller/PerfTestControllerTest.java b/ngrinder-controller/src/test/java/org/ngrinder/perftest/controller/PerfTestControllerTest.java index b90933321e..d022e96222 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/perftest/controller/PerfTestControllerTest.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/perftest/controller/PerfTestControllerTest.java @@ -13,6 +13,7 @@ */ package org.ngrinder.perftest.controller; +import static java.time.Instant.now; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; import static org.ngrinder.common.constant.WebConstants.PARAM_TEST; @@ -42,7 +43,6 @@ import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -87,7 +87,7 @@ public void testInvalidPerfTest() { @Test public void testGetPerfTestDetail() { - PerfTest createPerfTest = createPerfTest("hello", Status.READY, new Date()); + PerfTest createPerfTest = createPerfTest("hello", Status.READY, now()); Map response = perfTestApiController.getOneDetail(getTestUser(), createPerfTest.getId()); assertNotNull(response.get(PARAM_TEST)); } @@ -104,11 +104,11 @@ public void testGetResourcesOnScriptFolder() throws IOException { @Test public void testDeleteTests() { String testName = "test1"; - PerfTest test = createPerfTest(testName, Status.READY, new Date()); + PerfTest test = createPerfTest(testName, Status.READY, now()); perfTestApiController.delete(getTestUser(), String.valueOf(test.getId())); - PerfTest test1 = createPerfTest(testName, Status.READY, new Date()); - PerfTest test2 = createPerfTest(testName, Status.READY, new Date()); + PerfTest test1 = createPerfTest(testName, Status.READY, now()); + PerfTest test2 = createPerfTest(testName, Status.READY, now()); Function, PerfTest> perfTestOf = map -> (PerfTest) map.get(PARAM_TEST); @@ -160,7 +160,7 @@ public void testSavePerfTestCloneAndLeaveCommentAndStop() { public void testSavePerfTestExist() { String testName = "test1"; String newName = "new test1"; - PerfTest test = createPerfTest(testName, Status.READY, new Date()); + PerfTest test = createPerfTest(testName, Status.READY, now()); test.setTestName(newName); PerfTest newTest = new PerfTest(); @@ -205,7 +205,7 @@ public void testSavePerfTestExist() { @Test public void testGetTestList() { - createPerfTest("new test1", Status.READY, new Date()); + createPerfTest("new test1", Status.READY, now()); Map response = perfTestApiController.getAllList(getTestUser(), null, null, null, PageRequest.of(0, 10)); assertThat(((List) response.get("tests")).size(), is(1)); } @@ -213,7 +213,7 @@ public void testGetTestList() { @Test public void testGetTestListByAdmin() { String testName = "new test1"; - createPerfTest(testName, Status.READY, new Date()); + createPerfTest(testName, Status.READY, now()); User testAdmin = new User(); testAdmin.setUserId("testAdmin"); testAdmin.setPassword("testAdmin"); @@ -229,7 +229,7 @@ public void testGetTestListByAdmin() { @Test public void testGetTestListByOtherUser() { String testName = "new test1"; - PerfTest test = createPerfTest(testName, Status.READY, new Date()); + PerfTest test = createPerfTest(testName, Status.READY, now()); User otherTestUser = new User(); otherTestUser.setUserId("testUser"); @@ -253,7 +253,7 @@ public void testGetTestListByOtherUser() { @Test public void testGetTestListByKeyWord() { String strangeName = "DJJHG^%R&*^%^565(^%&^%(^%(^"; - createPerfTest(strangeName, Status.READY, new Date()); + createPerfTest(strangeName, Status.READY, now()); Sort sort = Sort.by(Sort.Direction.ASC, "testName"); Pageable pageable = PageRequest.of(0, 10, sort); @@ -267,7 +267,7 @@ public void testGetTestListByKeyWord() { @Test public void testGetReportData() { String testName = "test1"; - PerfTest test = createPerfTest(testName, Status.FINISHED, new Date()); + PerfTest test = createPerfTest(testName, Status.FINISHED, now()); controller.getReport(test.getId()); perfTestApiController.getPerfGraph(test.getId(), "TPS,mean_time(ms)", true, 0); @@ -278,7 +278,7 @@ public void testGetReportData() { @Test public void testGetMonitorData() { String testName = "test1"; - PerfTest test = createPerfTest(testName, Status.FINISHED, new Date()); + PerfTest test = createPerfTest(testName, Status.FINISHED, now()); perfTestApiController.getMonitorGraph(test.getId(), "127.0.0.1", 0); long testId = 123456L; @@ -288,7 +288,7 @@ public void testGetMonitorData() { @Test public void testDownloadReportData() { String testName = "test1"; - PerfTest test = createPerfTest(testName, Status.FINISHED, new Date()); + PerfTest test = createPerfTest(testName, Status.FINISHED, now()); HttpServletResponse resp = new MockHttpServletResponse(); try { controller.downloadCSV(getTestUser(), test.getId(), resp); @@ -304,7 +304,7 @@ public void testDownloadReportData() { public void testRefreshTestRunning() { String testName = "test1"; // it is not a running test, can not test get statistic data. - PerfTest test = createPerfTest(testName, Status.TESTING, new Date()); + PerfTest test = createPerfTest(testName, Status.TESTING, now()); test.setPort(11011); try { perfTestApiController.refreshTestRunning(getTestUser(), test.getId()); @@ -316,9 +316,9 @@ public void testRefreshTestRunning() { @Test public void testUpdateStatus() { String testName = "test1"; - PerfTest test = createPerfTest(testName, Status.TESTING, new Date()); + PerfTest test = createPerfTest(testName, Status.TESTING, now()); String testName2 = "test1"; - PerfTest test2 = createPerfTest(testName2, Status.START_AGENTS, new Date()); + PerfTest test2 = createPerfTest(testName2, Status.START_AGENTS, now()); String ids = test.getId() + "," + test2.getId(); Map response = perfTestApiController.getStatuses(getTestUser(), ids); diff --git a/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/AbstractPerfTestTransactionalTest.java b/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/AbstractPerfTestTransactionalTest.java index a77935f14d..4d9e2acc49 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/AbstractPerfTestTransactionalTest.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/AbstractPerfTestTransactionalTest.java @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -9,7 +9,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package org.ngrinder.perftest.service; @@ -23,9 +23,12 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import java.time.Instant; import java.util.Date; import java.util.List; +import static org.ngrinder.common.util.ObjectUtils.defaultIfNull; + /** * In addition {@link org.ngrinder.AbstractNGrinderTransactionalTest}, this class provides basic function to * create {@link org.ngrinder.model.PerfTest} and run the test. @@ -61,7 +64,7 @@ public void clearAllPerfTest() { tagRepository.flush(); } - public PerfTest newPerfTest(String testName, Status status, Date scheduledTime) { + public PerfTest newPerfTest(String testName, Status status, Instant scheduledTime) { PerfTest test = new PerfTest(); test.setTestName(testName); test.setThreshold("D"); @@ -78,14 +81,14 @@ public PerfTest newPerfTest(String testName, Status status, Date scheduledTime) test.setRampUpInitSleepTime(0); test.setRampUpIncrementInterval(1000); test.setStatus(status); - test.setCreatedUser(getTestUser()); + test.setCreatedBy(getTestUser()); test.setRegion(config.getRegion()); test.setSamplingInterval(1); test.setScm("svn"); return test; } - public PerfTest createPerfTest(String testName, Status status, Date scheduledTime) { + public PerfTest createPerfTest(String testName, Status status, Instant scheduledTime) { PerfTest perftest = newPerfTest(testName, status, scheduledTime); return createPerfTest(perftest); } diff --git a/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/PerfTestServiceTest.java b/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/PerfTestServiceTest.java index 0c697efff6..a2b0218f68 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/PerfTestServiceTest.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/PerfTestServiceTest.java @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -9,7 +9,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package org.ngrinder.perftest.service; @@ -35,9 +35,11 @@ import java.io.File; import java.io.IOException; +import java.time.Instant; import java.util.*; import java.util.function.Predicate; +import static java.time.Instant.now; import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; @@ -63,8 +65,8 @@ public void clearPerfTest() { @Test public void testGetTestListAll() { - createPerfTest("new Test1", Status.TESTING, new Date()); - createPerfTest("new Test2", Status.FINISHED, new Date()); + createPerfTest("new Test1", Status.TESTING, now()); + createPerfTest("new Test2", Status.FINISHED, now()); PerfTest candidate = testService.getNextRunnablePerfTestPerfTestCandidate(); assertThat(candidate, nullValue()); @@ -85,12 +87,12 @@ public void testGetTestListAll() { assertThat(list.size(), is(1)); for (PerfTest test : list) { - long systemTimeMills = System.currentTimeMillis(); - test.setStartTime(new Date(systemTimeMills)); + Instant now = now(); + test.setStartTime(now); PerfTest testTemp = testService.getOne(getTestUser(), test.getId()); assertThat(testTemp.getId(), is(test.getId())); - assertThat(testTemp.getStartTime().getTime(), is(systemTimeMills)); + assertThat(testTemp.getStartTime(), is(now)); testService.markAbnormalTermination(testTemp, StopReason.CANCEL_BY_USER); testService.markProgress(testTemp, "this test will be TESTING again"); @@ -107,18 +109,18 @@ public void testGetTestListAll() { } - createPerfTest("new Test2", Status.getProcessingOrTestingTestStatus()[0], new Date()); + createPerfTest("new Test2", Status.getProcessingOrTestingTestStatus()[0], now()); list = testService.getCurrentlyRunningTest(); assertThat(list.size(), is(2)); - PerfTest finishedTest = createPerfTest("new Test3", Status.ABNORMAL_TESTING, new Date()); + PerfTest finishedTest = createPerfTest("new Test3", Status.ABNORMAL_TESTING, now()); finishedTest.setPort(0); // need port number for finishing list = testService.getAllAbnormalTesting(); assertThat(list.size(), is(1)); testService.updatePerfTestAfterTestFinish(finishedTest); - createPerfTest("new Test3", Status.START_AGENTS, new Date()); + createPerfTest("new Test3", Status.START_AGENTS, now()); List errorList = testService.getAll(getTestUser(), new Status[]{Status.START_AGENTS}); assertThat(errorList.size(), is(1)); @@ -130,7 +132,7 @@ public void testTestScriptAll() { int maxConcurrent = testService.getMaximumConcurrentTestCount(); assertThat(maxConcurrent, is(10)); - PerfTest testScript = createPerfTest("new TestScript", Status.READY, new Date()); + PerfTest testScript = createPerfTest("new TestScript", Status.READY, now()); testService.addCommentOn(getTestUser(), testScript.getId(), "this is TestScript method", ""); PerfTest testing = testService.markProgressAndStatus(testScript, Status.TESTING, "It is testing from ready"); diff --git a/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/TagServiceTest.java b/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/TagServiceTest.java index 84ecb9280c..f738530938 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/TagServiceTest.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/TagServiceTest.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Set; +import static java.time.Instant.now; import static java.util.Arrays.asList; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; @@ -82,7 +83,7 @@ public void testTagService() { @Test public void testTagging() { - PerfTest newPerfTest = newPerfTest("hello", Status.SAVED, new Date()); + PerfTest newPerfTest = newPerfTest("hello", Status.SAVED, now()); newPerfTest.setTagString("HELLO,world"); createPerfTest(newPerfTest); newPerfTest.setTagString("HELLO,WORLD"); @@ -98,7 +99,7 @@ public void testTagging() { public void testGetAllTagStrings() { String[] tags = new String[]{"aaaa", "AAA", "a123", "bbbb", "a12312", "a999", "a777"}; tagService.addTags(getTestUser(), tags); - PerfTest newPerfTest = newPerfTest("hello", Status.SAVED, new Date()); + PerfTest newPerfTest = newPerfTest("hello", Status.SAVED, now()); newPerfTest.setTagString(String.join(",", tags)); perfTestService.save(getTestUser(), newPerfTest); diff --git a/ngrinder-controller/src/test/java/org/ngrinder/user/controller/UserControllerTest.java b/ngrinder-controller/src/test/java/org/ngrinder/user/controller/UserControllerTest.java index 5a5b08c93b..ada6d6c012 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/user/controller/UserControllerTest.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/user/controller/UserControllerTest.java @@ -13,6 +13,7 @@ */ package org.ngrinder.user.controller; +import static java.time.Instant.now; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; @@ -29,7 +30,6 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; -import java.util.Date; import java.util.List; import java.util.Map; @@ -120,7 +120,7 @@ private void saveTestUser(String userId, String userName) { newUser.setUserName(userName); newUser.setEmail("junoyoon@gmail.com"); newUser.setCreatedUser(getTestUser()); - newUser.setCreatedDate(new Date()); + newUser.setCreatedDate(now()); newUser.setRole(Role.USER); userApiController.save(getAdminUser(), newUser); } diff --git a/ngrinder-controller/src/test/java/org/ngrinder/user/model/UserTest.java b/ngrinder-controller/src/test/java/org/ngrinder/user/model/UserTest.java index 66498dd549..ae658558e5 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/user/model/UserTest.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/user/model/UserTest.java @@ -26,10 +26,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.domain.Specification; +import java.time.Instant; import java.util.ArrayList; -import java.util.Date; import java.util.List; +import static java.time.Instant.now; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; @@ -44,7 +45,7 @@ public class UserTest extends AbstractNGrinderTransactionalTest { @Autowired private TagRepository tagRepository; - + @Before public void before() { List findAll = perfTestRepository.findAll(); @@ -59,17 +60,18 @@ public void before() { userRepository.deleteAll(); userRepository.flush(); } - + @Test public void testShareUser() { List sharedUsers = new ArrayList<>(); List shareUsers = new ArrayList<>(); + Instant now = now(); User user = new User(); user.setUserName("MyName1"); user.setEmail("junoyoon@gmail.com"); user.setCreatedUser(getUser("user")); - user.setCreatedDate(new Date()); + user.setCreatedDate(now); user.setUserId("hello"); user.setRole(Role.USER); user = userRepository.save(user); @@ -78,25 +80,25 @@ public void testShareUser() { user2.setUserName("MyName2"); user2.setEmail("junoyoon2@paran.com"); user2.setCreatedUser(getUser("user")); - user2.setCreatedDate(new Date()); + user2.setCreatedDate(now); user2.setRole(Role.USER); userRepository.save(user2); - + User user3 = new User(); user3.setUserId("hello3"); user3.setUserName("MyName3"); user3.setEmail("junoyoon3@paran.com"); user3.setCreatedUser(getUser("user")); - user3.setCreatedDate(new Date()); + user3.setCreatedDate(now); user3.setRole(Role.USER); userRepository.save(user3); - + User user4 = new User(); user4.setUserId("hello4"); user4.setUserName("MyName4"); user4.setEmail("junoyoon4@paran.com"); user4.setCreatedUser(getUser("user")); - user4.setCreatedDate(new Date()); + user4.setCreatedDate(now); user4.setRole(Role.USER); sharedUsers.add(user3); sharedUsers.add(user2); @@ -110,15 +112,16 @@ public void testShareUser() { List sh = sharedUser.getFollowers(); LOG.debug("sharedUser.getFollowers:{}", sh); } - + @Test public void testUser() { + Instant now = now(); User user = new User(); user.setUserName("MyName1"); user.setEmail("junoyoon@gmail.com"); user.setCreatedUser(getUser("user")); - user.setCreatedDate(new Date()); + user.setCreatedDate(now); user.setUserId("hello"); user.setRole(Role.USER); user = userRepository.save(user); @@ -127,7 +130,7 @@ public void testUser() { user2.setUserName("MyName2"); user2.setEmail("junoyoon@paran.com"); user2.setCreatedUser(getUser("user")); - user2.setCreatedDate(new Date()); + user2.setCreatedDate(now); user2.setRole(Role.USER); userRepository.save(user2); diff --git a/ngrinder-core/src/main/java/org/ngrinder/model/BaseModel.java b/ngrinder-core/src/main/java/org/ngrinder/model/BaseModel.java index 80b4c06e9c..1d39b2bb82 100644 --- a/ngrinder-core/src/main/java/org/ngrinder/model/BaseModel.java +++ b/ngrinder-core/src/main/java/org/ngrinder/model/BaseModel.java @@ -22,7 +22,7 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.MappedSuperclass; -import java.util.Date; +import java.time.Instant; import lombok.Getter; import lombok.Setter; @@ -41,7 +41,7 @@ public class BaseModel extends BaseEntity { private static final long serialVersionUID = -3876339828833595694L; @Column(name = "created_date", insertable = true, updatable = false) - private Date createdDate; + private Instant createdDate; @JsonSerialize(using = User.UserReferenceSerializer.class) @ManyToOne @@ -51,7 +51,7 @@ public class BaseModel extends BaseEntity { private User createdUser; @Column(name = "last_modified_date", insertable = true, updatable = true) - private Date lastModifiedDate; + private Instant lastModifiedDate; @JsonSerialize(using = User.UserReferenceSerializer.class) @ManyToOne diff --git a/ngrinder-core/src/main/java/org/ngrinder/model/PerfTest.java b/ngrinder-core/src/main/java/org/ngrinder/model/PerfTest.java index 0ce74f48b2..430d11e6ff 100644 --- a/ngrinder-core/src/main/java/org/ngrinder/model/PerfTest.java +++ b/ngrinder-core/src/main/java/org/ngrinder/model/PerfTest.java @@ -24,17 +24,19 @@ import org.hibernate.annotations.Index; import org.hibernate.annotations.SortNatural; import org.hibernate.annotations.Type; -import org.ngrinder.common.util.DateUtils; import javax.persistence.*; +import java.time.Instant; import java.util.ArrayList; -import java.util.Date; import java.util.List; import java.util.SortedSet; import static com.sun.jmx.mbeanserver.Util.cast; +import static java.util.Date.from; import static org.apache.commons.lang.ObjectUtils.defaultIfNull; import static org.ngrinder.common.util.AccessUtils.getSafe; +import static org.ngrinder.common.util.DateUtils.dateToString; +import static org.ngrinder.common.util.DateUtils.ms2Time; /** * Performance Test Entity. @@ -95,15 +97,15 @@ public PerfTest(User createdUser) { /** the scheduled time of this test. */ @Column(name = "scheduled_time") @Index(name = "scheduled_time_index") - private Date scheduledTime; + private Instant scheduledTime; /** the start time of this test. */ @Column(name = "start_time") - private Date startTime; + private Instant startTime; /** the finish time of this test. */ @Column(name = "finish_time") - private Date finishTime; + private Instant finishTime; /** * the target host to test. @@ -340,7 +342,7 @@ public String getDescription() { @JsonIgnore public String getLastModifiedDateToStr() { - return DateUtils.dateToString(getLastModifiedDate()); + return dateToString(from(getLastModifiedDate())); } /** @@ -386,8 +388,8 @@ public boolean isStopRequest() { */ @JsonProperty("runtime") public String getRuntimeStr() { - long ms = (this.finishTime == null || this.startTime == null) ? 0 : this.finishTime.getTime() - this.startTime.getTime(); - return DateUtils.ms2Time(ms); + long runtimeSecond = (this.finishTime == null || this.startTime == null) ? 0 : this.finishTime.getEpochSecond() - this.startTime.getEpochSecond(); + return ms2Time(runtimeSecond * 1000); } @Override diff --git a/ngrinder-frontend/src/js/components/perftest/detail/Detail.vue b/ngrinder-frontend/src/js/components/perftest/detail/Detail.vue index 580dc99800..44cd291527 100644 --- a/ngrinder-frontend/src/js/components/perftest/detail/Detail.vue +++ b/ngrinder-frontend/src/js/components/perftest/detail/Detail.vue @@ -492,7 +492,7 @@ runPerftest(scheduledTime) { this.$refs.scheduleModal.hide(); this.test.status.name = 'READY'; - this.test.scheduledTime = scheduledTime; + this.test.scheduledTime = scheduledTime ? scheduledTime.getTime() : scheduledTime; this.$nextTick(() => { this.$http.post(`/perftest/api/save?isClone=${this.isClone}`, PerfTestSerializer.serialize(this.test)) From d9926d383cd88dd52610f9236f53bcc3de4a6dc8 Mon Sep 17 00:00:00 2001 From: leedonggyu Date: Thu, 22 Oct 2020 22:26:23 +0900 Subject: [PATCH 10/38] Rename column - created_date -> created_at - last_modified_date -> last_modified_at - created_user -> created_by - last_modified_user -> last_modified_by - created_user_id -> creator_id --- .../ngrinder/common/service/ModelAspect.java | 16 +++--- .../org/ngrinder/infra/config/Database.java | 6 +-- .../java/org/ngrinder/infra/init/DBInit.java | 12 ++--- .../controller/WebhookApiController.java | 4 +- .../ngrinder/infra/webhook/model/Event.java | 8 +-- .../webhook/model/WebhookActivation.java | 8 +-- .../infra/webhook/model/WebhookConfig.java | 14 ++--- .../webhook/plugin/NGrinderWebhookPlugin.java | 3 +- .../WebhookActivationSpecification.java | 4 +- .../WebhookConfigSpecification.java | 4 +- .../service/WebhookActivationService.java | 6 +-- .../webhook/service/WebhookConfigService.java | 10 ++-- .../infra/webhook/service/WebhookService.java | 6 +-- .../controller/PerfTestApiController.java | 8 +-- .../controller/PerfTestController.java | 2 +- .../repository/PerfTestRepository.java | 8 +-- .../repository/PerfTestSpecification.java | 6 +-- .../perftest/repository/TagSpecification.java | 8 +-- .../perftest/service/PerfTestRunnable.java | 9 ++-- .../perftest/service/PerfTestService.java | 24 ++++----- .../ngrinder/perftest/service/TagService.java | 32 ++++++------ .../controller/FileEntryApiController.java | 2 +- .../GroovyMavenProjectScriptHandler.java | 4 +- .../org/ngrinder/script/model/FileEntry.java | 11 +++- .../repository/FileEntryRepository.java | 13 ++--- ...NGrinderAuthenticationPreAuthProvider.java | 20 +++---- .../NGrinderAuthenticationProvider.java | 12 ++--- .../ngrinder/user/service/UserService.java | 13 ++--- .../db.changelog.xml | 1 + .../db.changelog_schema_31.xml | 52 +++++++++++++++++++ .../common/service/ModelAspectTest.java | 8 +-- .../service/MockPerfTestRunnable.java | 2 +- .../perftest/service/TagServiceTest.java | 9 ++-- .../GroovyMavenProjectScriptHandlerTest.java | 2 +- .../handler/ScriptHandlerFactoryTest.java | 2 +- .../user/controller/UserControllerTest.java | 4 +- .../org/ngrinder/user/model/UserTest.java | 28 +++++----- .../java/org/ngrinder/model/BaseModel.java | 20 +++---- .../java/org/ngrinder/model/PerfTest.java | 10 ++-- .../js/components/perftest/detail/Config.vue | 2 +- .../js/components/perftest/detail/Detail.vue | 14 ++--- .../src/js/components/perftest/list/List.vue | 14 ++--- .../src/js/components/script/List.vue | 4 +- .../components/script/mixin/TableConfig.vue | 4 +- .../components/settings/WebhookSettings.vue | 8 +-- .../src/js/components/user/List.vue | 4 +- .../js/components/user/mixin/TableConfig.vue | 4 +- 47 files changed, 263 insertions(+), 202 deletions(-) create mode 100644 ngrinder-controller/src/main/resources/ngrinder_datachange_logfile/db.changelog_schema_31.xml diff --git a/ngrinder-controller/src/main/java/org/ngrinder/common/service/ModelAspect.java b/ngrinder-controller/src/main/java/org/ngrinder/common/service/ModelAspect.java index 5f47084d67..8adbb7203c 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/common/service/ModelAspect.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/common/service/ModelAspect.java @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -9,7 +9,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package org.ngrinder.common.service; @@ -62,19 +62,19 @@ public void beforeSave(JoinPoint joinPoint) { if (object instanceof BaseModel && (springContext.isAuthenticationContext() || springContext.isUnitTestContext())) { BaseModel model = (BaseModel) object; - Instant lastModifiedDate = now(); - model.setLastModifiedDate(lastModifiedDate); + Instant lastModifiedAt = now(); + model.setLastModifiedAt(lastModifiedAt); User currentUser = userContext.getCurrentUser(); long currentUserId = currentUser.getId(); - model.setLastModifiedUser(userRepository.findOne(idEqual(currentUserId)) + model.setLastModifiedBy(userRepository.findOne(idEqual(currentUserId)) .orElseThrow(() -> new IllegalArgumentException("No user found with id : " + currentUserId))); - if (!model.exist() || model.getCreatedUser() == null) { + if (!model.exist() || model.getCreatedBy() == null) { long factualUserId = currentUser.getFactualUser().getId(); - model.setCreatedDate(lastModifiedDate); - model.setCreatedUser(userRepository.findOne(idEqual(factualUserId)) + model.setCreatedAt(lastModifiedAt); + model.setCreatedBy(userRepository.findOne(idEqual(factualUserId)) .orElseThrow(() -> new IllegalArgumentException("No user found with id : " + factualUserId))); } } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/config/Database.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/config/Database.java index 1499c427d4..2c93a2199b 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/config/Database.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/config/Database.java @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -9,7 +9,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package org.ngrinder.infra.config; @@ -38,7 +38,7 @@ public enum Database { /** * MYSQL. */ - mysql(com.mysql.cj.jdbc.Driver.class, MYSQLExDialect.class, "jdbc:mysql://%s?characterEncoding=utf8&serverTimezone=%s&%s") { + mysql(com.mysql.cj.jdbc.Driver.class, MYSQLExDialect.class, "jdbc:mysql://%s?characterEncoding=utf8&allowMultiQueries=true&serverTimezone=%s&%s") { @Override protected void setupVariants(BasicDataSource dataSource, PropertiesWrapper databaseProperties) { String databaseUrlOption = databaseProperties.getProperty(DatabaseConfig.PROP_DATABASE_URL_OPTION); diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/init/DBInit.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/init/DBInit.java index 5f485ab996..0aa25c6f99 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/init/DBInit.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/init/DBInit.java @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -9,7 +9,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package org.ngrinder.infra.init; @@ -91,10 +91,10 @@ private void createUser(String userId, String password, Role role, String userNa user.setEmail(email); Instant now = now(); - user.setCreatedDate(now); - user.setLastModifiedDate(now); - user.setCreatedUser(user); - user.setLastModifiedUser(user); + user.setCreatedAt(now); + user.setLastModifiedAt(now); + user.setCreatedBy(user); + user.setLastModifiedBy(user); user = userRepository.save(user); fileEntryService.prepare(user); diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/controller/WebhookApiController.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/controller/WebhookApiController.java index 4a2bfb3e14..3582275046 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/controller/WebhookApiController.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/controller/WebhookApiController.java @@ -62,8 +62,8 @@ public WebhookConfig getOne(User user) { } @GetMapping("/activation") - public List getActivations(@RequestParam String createdUserId, + public List getActivations(@RequestParam String creatorId, @PageableDefault Pageable pageable) { - return webhookActivationService.findAll(createdUserId, pageable); + return webhookActivationService.findAll(creatorId, pageable); } } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/Event.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/Event.java index b0008ba6d8..b71e2d11d2 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/Event.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/Event.java @@ -47,7 +47,7 @@ public enum Event { START(perfTest -> { Map payload = createBasePayload(perfTest); payload.put("eventType", "START"); - payload.put("startTime", now().toString()); + payload.put("startTime", now()); return payload; }), @@ -59,7 +59,7 @@ public enum Event { Status status = getSafe(finishedPerfTest.getStatus(), UNKNOWN); payload.put("eventType", "FINISH"); - payload.put("finishTime", now().toString()); + payload.put("finishTime", now()); payload.put("peakTPS", getSafe(finishedPerfTest.getPeakTps(), 0.0)); payload.put("TPS", getSafe(finishedPerfTest.getTps(), 0.0)); payload.put("errors", errors); @@ -79,9 +79,9 @@ private static Map createBasePayload(PerfTest perfTest) { int vuserPerAgent = getSafe(perfTest.getVuserPerAgent(), 0); int agentCount = getSafe(perfTest.getAgentCount(), 0); - User createdUser = getSafe(perfTest.getCreatedUser(), new User()); + User createdBy = getSafe(perfTest.getCreatedBy(), new User()); - payload.put("createdUserId", getSafe(createdUser.getUserId(), "")); + payload.put("createdBy", getSafe(createdBy.getUserId(), "")); payload.put("testId", getSafe(perfTest.getId(), 0L)); payload.put("testName", getSafe(perfTest.getTestName(), "")); payload.put("scriptName", getSafe(perfTest.getScriptName(), "")); diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/WebhookActivation.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/WebhookActivation.java index 4cfccbb4d3..c28e9821ab 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/WebhookActivation.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/WebhookActivation.java @@ -44,11 +44,11 @@ @Table(name = "WEBHOOK_ACTIVATION") public class WebhookActivation extends BaseEntity { - @Column(name = "created_user_id") - private String createdUserId; + @Column(name = "creator_id") + private String creatorId; - @Column(name = "created_time") - private Instant createdTime; + @Column(name = "created_at") + private Instant createdAt; private String request; diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/WebhookConfig.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/WebhookConfig.java index 683dfeaf56..c28f7f9583 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/WebhookConfig.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/model/WebhookConfig.java @@ -44,8 +44,8 @@ @Table(name = "WEBHOOK_CONFIG") public class WebhookConfig extends BaseEntity { - @Column(name = "created_user_id") - private String createdUserId; + @Column(name = "creator_id") + private String creatorId; private boolean active; @@ -58,11 +58,11 @@ public class WebhookConfig extends BaseEntity { private String events; - @Column(name = "created_time") - private Instant createdTime; + @Column(name = "created_at") + private Instant createdAt; - @Column(name = "last_modified_time") - private Instant lastModifiedTime; + @Column(name = "last_modified_at") + private Instant lastModifiedAt; @Transient @Getter(value = AccessLevel.NONE) @@ -70,7 +70,7 @@ public class WebhookConfig extends BaseEntity { @PreUpdate public void preUpdate() { - this.lastModifiedTime = now(); + this.lastModifiedAt = now(); } public Set getEvents() { diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/plugin/NGrinderWebhookPlugin.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/plugin/NGrinderWebhookPlugin.java index 29fa61b3f3..e8bc406fd9 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/plugin/NGrinderWebhookPlugin.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/plugin/NGrinderWebhookPlugin.java @@ -38,7 +38,6 @@ * * @since 3.5.2 */ -@SuppressWarnings("DuplicatedCode") @Slf4j @AllArgsConstructor public class NGrinderWebhookPlugin implements OnTestLifeCycleRunnable { @@ -67,7 +66,7 @@ public void finish(PerfTest perfTest, String stopReason, IPerfTestService perfTe } private void sendWebhookRequest(PerfTest perfTest, Event event) { - WebhookConfig webhookConfig = webhookConfigService.getOne(perfTest.getCreatedUser().getUserId()); + WebhookConfig webhookConfig = webhookConfigService.getOne(perfTest.getCreatedBy().getUserId()); if (webhookConfig == null) { return; diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/repository/WebhookActivationSpecification.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/repository/WebhookActivationSpecification.java index c5b0dcc814..429e2a1f42 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/repository/WebhookActivationSpecification.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/repository/WebhookActivationSpecification.java @@ -30,7 +30,7 @@ */ public abstract class WebhookActivationSpecification { - public static Specification createdUserIdEqual(String createdUerId) { - return (Specification) (root, query, cb) -> cb.equal(root.get("createdUserId"), createdUerId); + public static Specification creatorIdEqual(String creatorId) { + return (Specification) (root, query, cb) -> cb.equal(root.get("creatorId"), creatorId); } } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/repository/WebhookConfigSpecification.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/repository/WebhookConfigSpecification.java index 0d8f05e6ad..57e9ac508c 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/repository/WebhookConfigSpecification.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/repository/WebhookConfigSpecification.java @@ -30,7 +30,7 @@ */ public abstract class WebhookConfigSpecification { - public static Specification createdUserIdEqual(String createdUerId) { - return (Specification) (root, query, cb) -> cb.equal(root.get("createdUserId"), createdUerId); + public static Specification creatorIdEqual(String creatorId) { + return (Specification) (root, query, cb) -> cb.equal(root.get("creatorId"), creatorId); } } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookActivationService.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookActivationService.java index f5cc541da8..736c374c1b 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookActivationService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookActivationService.java @@ -31,7 +31,7 @@ import java.util.List; import static org.ngrinder.common.util.Preconditions.checkNotNull; -import static org.ngrinder.infra.webhook.repository.WebhookActivationSpecification.createdUserIdEqual; +import static org.ngrinder.infra.webhook.repository.WebhookActivationSpecification.creatorIdEqual; @Slf4j @Service @@ -40,8 +40,8 @@ public class WebhookActivationService { private final WebhookActivationRepository webhookActivationRepository; - public List findAll(String createdUserId, Pageable pageable) { - Page webhookActivation = webhookActivationRepository.findAll(createdUserIdEqual(createdUserId), pageable); + public List findAll(String creatorId, Pageable pageable) { + Page webhookActivation = webhookActivationRepository.findAll(creatorIdEqual(creatorId), pageable); return webhookActivation.getContent(); } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookConfigService.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookConfigService.java index dd5d7b188a..b058b4f7c6 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookConfigService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookConfigService.java @@ -31,7 +31,7 @@ import static java.time.Instant.now; import static org.ngrinder.common.util.Preconditions.checkNotNull; -import static org.ngrinder.infra.webhook.repository.WebhookConfigSpecification.createdUserIdEqual; +import static org.ngrinder.infra.webhook.repository.WebhookConfigSpecification.creatorIdEqual; @Slf4j @Service @@ -43,18 +43,18 @@ public class WebhookConfigService { @Transactional public void save(WebhookConfig webhookConfig) { checkNotNull(webhookConfig); - Optional findOne = webhookConfigRepository.findOne(createdUserIdEqual(webhookConfig.getCreatedUserId())); + Optional findOne = webhookConfigRepository.findOne(creatorIdEqual(webhookConfig.getCreatorId())); if (findOne.isPresent()) { WebhookConfig existingWebhookConfig = findOne.get(); existingWebhookConfig.update(webhookConfig); return; } - webhookConfig.setCreatedTime(now()); + webhookConfig.setCreatedAt(now()); webhookConfigRepository.save(webhookConfig); } - public WebhookConfig getOne(String createdUserId) { - Optional webhookConfig = webhookConfigRepository.findOne(createdUserIdEqual(createdUserId)); + public WebhookConfig getOne(String createdBy) { + Optional webhookConfig = webhookConfigRepository.findOne(creatorIdEqual(createdBy)); return webhookConfig.orElse(null); } } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookService.java b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookService.java index 0ee8710070..0035f6997b 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/infra/webhook/service/WebhookService.java @@ -73,7 +73,7 @@ public void sendWebhookRequest(PerfTest perfTest, public void sendDummyWebhookRequest(User user, WebhookConfig webhookConfig, Event event) { PerfTest perfTest = new PerfTest(); - perfTest.setCreatedUser(user); + perfTest.setCreatedBy(user); sendWebhookRequest(perfTest, webhookConfig, event); } @@ -89,7 +89,7 @@ private void saveWebhookActivation(PerfTest perfTest, } WebhookActivation webhookActivation = new WebhookActivation(); - webhookActivation.setCreatedUserId(perfTest.getCreatedUser().getUserId()); + webhookActivation.setCreatorId(perfTest.getCreatedBy().getUserId()); webhookActivation.setUuid(UUID.randomUUID().toString()); try { @@ -103,7 +103,7 @@ private void saveWebhookActivation(PerfTest perfTest, } catch (JsonProcessingException e) { webhookActivation.setResponse(response.toString()); } - webhookActivation.setCreatedTime(now()); + webhookActivation.setCreatedAt(now()); webhookActivationService.save(webhookActivation); } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/perftest/controller/PerfTestApiController.java b/ngrinder-controller/src/main/java/org/ngrinder/perftest/controller/PerfTestApiController.java index e7c8599149..83afc09276 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/perftest/controller/PerfTestApiController.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/perftest/controller/PerfTestApiController.java @@ -127,7 +127,7 @@ public Map getAllList(User user, result.put("size", tests.getSize()); result.put("queryFilter", queryFilter); result.put("query", query); - result.put("createdUserId", user.getUserId()); + result.put("createdBy", user.getUserId()); result.put("tests", tests.getContent()); putPageIntoModelMap(result, pageable); return result; @@ -290,7 +290,7 @@ public Map getOneDetail(User user, @PathVariable Long id) { // Retrieve the agent count map based on create user, if the test is // created by the others. - user = test.getCreatedUser(); + user = test.getCreatedBy(); result.putAll(getDefaultAttributes(user)); return result; } @@ -402,7 +402,7 @@ private PerfTest getOneWithPermissionCheck(User user, Long id, boolean withTag) if (user.getRole().equals(Role.ADMIN) || user.getRole().equals(Role.SUPER_USER)) { return perfTest; } - if (perfTest != null && !user.equals(perfTest.getCreatedUser())) { + if (perfTest != null && !user.equals(perfTest.getCreatedBy())) { throw processException("User " + user.getUserId() + " has no right on PerfTest " + id); } return perfTest; @@ -472,7 +472,7 @@ private String getStatusMessage(PerfTest perfTest) { message += progressMessage + "
"; } message += "" + perfTest.getLastProgressMessage() + "
"; - message += perfTest.getLastModifiedDateToStr(); + message += perfTest.getLastModifiedAtToStr(); return replace(message, "\n", "
"); } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/perftest/controller/PerfTestController.java b/ngrinder-controller/src/main/java/org/ngrinder/perftest/controller/PerfTestController.java index b3eac268ba..a93c5d5ac6 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/perftest/controller/PerfTestController.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/perftest/controller/PerfTestController.java @@ -207,7 +207,7 @@ private PerfTest getOneWithPermissionCheck(User user, Long id, boolean withTag) if (user.getRole().equals(Role.ADMIN) || user.getRole().equals(Role.SUPER_USER)) { return perfTest; } - if (perfTest != null && !user.equals(perfTest.getCreatedUser())) { + if (perfTest != null && !user.equals(perfTest.getCreatedBy())) { throw processException("User " + user.getUserId() + " has no right on PerfTest " + id); } return perfTest; diff --git a/ngrinder-controller/src/main/java/org/ngrinder/perftest/repository/PerfTestRepository.java b/ngrinder-controller/src/main/java/org/ngrinder/perftest/repository/PerfTestRepository.java index 50920ee408..f81eb1fd09 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/perftest/repository/PerfTestRepository.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/perftest/repository/PerfTestRepository.java @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -9,7 +9,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package org.ngrinder.perftest.repository; @@ -69,7 +69,7 @@ public interface PerfTestRepository extends JpaRepository, JpaSp * @return {@link PerfTest} list */ @Query("select p from PerfTest p where p.startTime between ?1 and ?2 and region=?3") - List findAllByCreatedTimeAndRegion(Date start, Date end, String region); + List findAllByCreatedAtAndRegion(Date start, Date end, String region); /** * Find all {@link PerfTest} created between the given start and end dates. @@ -79,5 +79,5 @@ public interface PerfTestRepository extends JpaRepository, JpaSp * @return {@link PerfTest} list */ @Query("select p from PerfTest p where p.startTime between ?1 and ?2") - List findAllByCreatedTime(Date start, Date end); + List findAllByCreatedAt(Date start, Date end); } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/perftest/repository/PerfTestSpecification.java b/ngrinder-controller/src/main/java/org/ngrinder/perftest/repository/PerfTestSpecification.java index 4ff0fbc1e0..c55ddf2960 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/perftest/repository/PerfTestSpecification.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/perftest/repository/PerfTestSpecification.java @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -9,7 +9,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package org.ngrinder.perftest.repository; @@ -127,7 +127,7 @@ public static Specification likeTestNameOrDescription(final String que * @return {@link Specification} */ public static Specification createdBy(final User user) { - return (Specification) (root, query, cb) -> cb.or(cb.equal(root.get("createdUser"), user)); + return (Specification) (root, query, cb) -> cb.or(cb.equal(root.get("createdBy"), user)); } } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/perftest/repository/TagSpecification.java b/ngrinder-controller/src/main/java/org/ngrinder/perftest/repository/TagSpecification.java index b4d72cc7c8..2d6db85927 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/perftest/repository/TagSpecification.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/perftest/repository/TagSpecification.java @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -9,7 +9,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package org.ngrinder.perftest.repository; @@ -44,14 +44,14 @@ public static Specification valueIn(final String[] values) { } /** - * Get lastModifiedUser and createBy {@link Specification} to get the {@link Tag} whose creator or last modifier is + * Get lastModifiedBy and createBy {@link Specification} to get the {@link Tag} whose creator or last modifier is * the given user. * * @param user user * @return {@link Specification} */ public static Specification lastModifiedOrCreatedBy(final User user) { - return (Specification) (root, query, cb) -> cb.or(cb.equal(root.get("lastModifiedUser"), user), cb.equal(root.get("createdUser"), user)); + return (Specification) (root, query, cb) -> cb.or(cb.equal(root.get("lastModifiedBy"), user), cb.equal(root.get("createdBy"), user)); } /** diff --git a/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestRunnable.java b/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestRunnable.java index 6ca4fdd6e7..e410586d2d 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestRunnable.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestRunnable.java @@ -54,8 +54,7 @@ import java.util.List; import java.util.Set; -import static java.time.Instant.now; -import static java.time.Instant.ofEpochSecond; +import static java.time.Instant.*; import static java.time.temporal.ChronoUnit.MINUTES; import static java.util.Arrays.asList; import static java.util.stream.Collectors.toSet; @@ -188,7 +187,7 @@ private boolean isScheduledNow(PerfTest test) { * @return true if enough agents */ protected boolean hasEnoughFreeAgents(PerfTest test) { - int size = agentService.getAllAttachedFreeApprovedAgentsForUser(test.getCreatedUser().getUserId()).size(); + int size = agentService.getAllAttachedFreeApprovedAgentsForUser(test.getCreatedBy().getUserId()).size(); if (test.getAgentCount() != null && test.getAgentCount() > size) { perfTestService.markProgress(test, "The test is tried to execute but there is not enough free agents." + "\n- Current free agent count : " + size + " / Requested : " + test.getAgentCount() + "\n"); @@ -373,7 +372,7 @@ void startAgentsOn(PerfTest perfTest, GrinderProperties grinderProperties, Singl int agentCount = perfTest.getAgentCount(); perfTestService.markStatusAndProgress(perfTest, START_AGENTS, getSafe(agentCount) + " agents are starting."); - agentService.runAgent(perfTest.getCreatedUser(), singleConsole, grinderProperties, getSafe(agentCount)); + agentService.runAgent(perfTest.getCreatedBy(), singleConsole, grinderProperties, getSafe(agentCount)); singleConsole.waitUntilAgentPrepared(agentCount); perfTestService.markStatusAndProgress(perfTest, START_AGENTS_FINISHED, getSafe(agentCount) + " agents are ready."); @@ -404,7 +403,7 @@ public void readyToStop(StopReason stopReason) { } }); long startTime = singleConsole.startTest(grinderProperties); - perfTest.setStartTime(ofEpochSecond(startTime / 1000)); + perfTest.setStartTime(ofEpochMilli(startTime)); addSamplingListeners(perfTest, singleConsole); perfTestService.markStatusAndProgress(perfTest, TESTING, "The test is started."); singleConsole.startSampling(); diff --git a/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestService.java b/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestService.java index d2b04ff0cb..7c234a17db 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/PerfTestService.java @@ -447,10 +447,10 @@ protected List filterCurrentlyRunningTestUsersTest(List perf List currentlyRunningTests = getCurrentlyRunningTest(); final Set currentlyRunningTestOwners = newHashSet(); for (PerfTest each : currentlyRunningTests) { - currentlyRunningTestOwners.add(each.getCreatedUser()); + currentlyRunningTestOwners.add(each.getCreatedBy()); } return perfTestLists.stream() - .filter(perfTest -> !currentlyRunningTestOwners.contains(perfTest.getCreatedUser())) + .filter(perfTest -> !currentlyRunningTestOwners.contains(perfTest.getCreatedBy())) .collect(toList()); } @@ -561,7 +561,7 @@ public GrinderProperties getGrinderProperties(PerfTest perfTest, ScriptHandler s // Use default properties first GrinderProperties grinderProperties = new GrinderProperties(config.getHome().getDefaultGrinderProperties()); - User user = perfTest.getCreatedUser(); + User user = perfTest.getCreatedBy(); // Get all files in the script path String scriptName = perfTest.getScriptName(); @@ -608,7 +608,7 @@ public GrinderProperties getGrinderProperties(PerfTest perfTest, ScriptHandler s grinderProperties.setInt(GRINDER_PROP_PROCESS_INCREMENT, 0); } grinderProperties.setInt(GRINDER_PROP_REPORT_TO_CONSOLE, 500); - grinderProperties.setProperty(GRINDER_PROP_USER, perfTest.getCreatedUser().getUserId()); + grinderProperties.setProperty(GRINDER_PROP_USER, perfTest.getCreatedBy().getUserId()); grinderProperties.setProperty(GRINDER_PROP_JVM_USER_LIBRARY_CLASSPATH, geUserLibraryClassPath(perfTest)); grinderProperties.setInt(GRINDER_PROP_IGNORE_SAMPLE_COUNT, getSafe(perfTest.getIgnoreSampleCount())); grinderProperties.setBoolean(GRINDER_PROP_SECURITY, config.isSecurityEnabled()); @@ -643,7 +643,7 @@ public GrinderProperties getGrinderProperties(PerfTest perfTest, ScriptHandler s */ public ScriptHandler prepareDistribution(PerfTest perfTest) throws IOException { File perfTestDistDirectory = getDistributionPath(perfTest); - User user = perfTest.getCreatedUser(); + User user = perfTest.getCreatedBy(); String scm = perfTest.getScm(); FileEntry scriptEntry; @@ -1045,7 +1045,7 @@ public void stop(User user, Long id) { * @return true if it has */ public boolean hasPermission(PerfTest perfTest, User user, Permission type) { - return perfTest != null && (user.getRole().hasPermission(type) || user.equals(perfTest.getCreatedUser())); + return perfTest != null && (user.getRole().hasPermission(type) || user.equals(perfTest.getCreatedBy())); } /* @@ -1085,11 +1085,11 @@ public void addCommentOn(User user, Long testId, String testComment, String tagS public Collection getCurrentPerfTestStatistics() { Map perfTestPerUser = newHashMap(); for (PerfTest each : getAll(null, getProcessingOrTestingTestStatus())) { - User lastModifiedUser = each.getCreatedUser().getUserBaseInfo(); - PerfTestStatistics perfTestStatistics = perfTestPerUser.get(lastModifiedUser); + User lastModifiedBy = each.getCreatedBy().getUserBaseInfo(); + PerfTestStatistics perfTestStatistics = perfTestPerUser.get(lastModifiedBy); if (perfTestStatistics == null) { - perfTestStatistics = new PerfTestStatistics(lastModifiedUser); - perfTestPerUser.put(lastModifiedUser, perfTestStatistics); + perfTestStatistics = new PerfTestStatistics(lastModifiedBy); + perfTestPerUser.put(lastModifiedBy, perfTestStatistics); } perfTestStatistics.addPerfTest(each); } @@ -1524,7 +1524,7 @@ private List getFileDataAsList(File targetFile, int interval) { */ @Override public List getAll(Date start, Date end) { - return perfTestRepository.findAllByCreatedTime(start, end); + return perfTestRepository.findAllByCreatedAt(start, end); } /* @@ -1534,7 +1534,7 @@ public List getAll(Date start, Date end) { */ @Override public List getAll(Date start, Date end, String region) { - return perfTestRepository.findAllByCreatedTimeAndRegion(start, end, region); + return perfTestRepository.findAllByCreatedAtAndRegion(start, end, region); } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/TagService.java b/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/TagService.java index 670e93f153..ede4dfb73c 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/TagService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/perftest/service/TagService.java @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -9,7 +9,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package org.ngrinder.perftest.service; @@ -35,9 +35,9 @@ /** * Tag Service. Tag support which is used to categorize {@link PerfTest} - * + * * @since 3.0 - * + * */ @Service @RequiredArgsConstructor @@ -49,7 +49,7 @@ public class TagService { /** * Add tags. - * + * * @param user user * @param tags tag string list * @return inserted tags @@ -77,7 +77,7 @@ public SortedSet addTags(User user, String[] tags) { /** * Get all tags which belongs to given user and start with given string. - * + * * @param user user * @param startWith string * @return found tags @@ -93,7 +93,7 @@ public List getAllTags(User user, String startWith) { /** * Get all tags which belongs to given user and start with given string. - * + * * @param user user * @param query query string * @return found tag string lists @@ -108,25 +108,25 @@ public List getAllTagStrings(User user, String query) { /** * Save Tag. Because this method can be called in {@link TagService} internally, so created user * / data should be set directly. - * + * * @param user user * @param tag tag * @return saved {@link Tag} instance */ public Tag saveTag(User user, Tag tag) { - Instant createdDate = now(); - if (tag.getCreatedUser() == null) { - tag.setCreatedUser(user); - tag.setCreatedDate(createdDate); + Instant createdAt = now(); + if (tag.getCreatedBy() == null) { + tag.setCreatedBy(user); + tag.setCreatedAt(createdAt); } - tag.setLastModifiedUser(user); - tag.setLastModifiedDate(createdDate); + tag.setLastModifiedBy(user); + tag.setLastModifiedAt(createdAt); return tagRepository.save(tag); } /** * Delete a tag. - * + * * @param user user * @param tag tag */ @@ -141,7 +141,7 @@ public void deleteTag(User user, Tag tag) { /** * Delete all tags belonging to given user. - * + * * @param user user */ @Transactional diff --git a/ngrinder-controller/src/main/java/org/ngrinder/script/controller/FileEntryApiController.java b/ngrinder-controller/src/main/java/org/ngrinder/script/controller/FileEntryApiController.java index 6d54ee2c06..6fd3c73e4b 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/script/controller/FileEntryApiController.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/script/controller/FileEntryApiController.java @@ -388,7 +388,7 @@ public void deleteOne(User user, @RemainedPath String path) { @PostMapping("/validate") public String validate(User user, @RequestBody ScriptValidationParams scriptValidationParams) { FileEntry fileEntry = scriptValidationParams.getFileEntry(); - fileEntry.setCreatedUser(user); + fileEntry.setCreatedBy(user); return scriptValidationService.validate(user, fileEntry, false, scriptValidationParams.getHostString()); } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/script/handler/GroovyMavenProjectScriptHandler.java b/ngrinder-controller/src/main/java/org/ngrinder/script/handler/GroovyMavenProjectScriptHandler.java index 202e606443..c2ed2e1355 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/script/handler/GroovyMavenProjectScriptHandler.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/script/handler/GroovyMavenProjectScriptHandler.java @@ -78,10 +78,10 @@ public boolean canHandle(FileEntry fileEntry) { if (isGitHubFileEntry(fileEntry)) { return StringUtils.equals(fileEntry.getProperties().get("type"), "groovy-maven"); } else { - if (fileEntry.getCreatedUser() == null) { + if (fileEntry.getCreatedBy() == null) { return false; } - return getFileEntryRepository().hasOne(fileEntry.getCreatedUser(), getBasePath(path) + "pom.xml"); + return getFileEntryRepository().hasOne(fileEntry.getCreatedBy(), getBasePath(path) + "pom.xml"); } } diff --git a/ngrinder-controller/src/main/java/org/ngrinder/script/model/FileEntry.java b/ngrinder-controller/src/main/java/org/ngrinder/script/model/FileEntry.java index 38d60cadd4..bc3a8aa377 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/script/model/FileEntry.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/script/model/FileEntry.java @@ -22,9 +22,9 @@ import lombok.Setter; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.math.NumberUtils; -import org.ngrinder.common.util.PathUtils; import org.ngrinder.model.BaseModel; import org.ngrinder.model.IFileEntry; +import org.ngrinder.model.User; import java.io.IOException; import java.util.HashMap; @@ -136,6 +136,15 @@ public int getValidated() { } } + /** + * For backward compatibility. + * */ + @Override + @JsonSerialize(using = User.UserReferenceSerializer.class) + public User getCreatedUser() { + return getCreatedBy(); + } + private static class UnixPathSerializer extends StdSerializer { @SuppressWarnings("unused") UnixPathSerializer() { diff --git a/ngrinder-controller/src/main/java/org/ngrinder/script/repository/FileEntryRepository.java b/ngrinder-controller/src/main/java/org/ngrinder/script/repository/FileEntryRepository.java index b1b2f88e1d..1d922b54df 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/script/repository/FileEntryRepository.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/script/repository/FileEntryRepository.java @@ -26,7 +26,6 @@ import org.ngrinder.script.model.FileCategory; import org.ngrinder.script.model.FileEntry; import org.ngrinder.script.model.FileType; -import org.ngrinder.user.repository.UserRepository; import org.ngrinder.user.service.UserContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,6 +47,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; +import java.time.Instant; import java.util.EmptyStackException; import java.util.List; import java.util.Map.Entry; @@ -142,8 +142,8 @@ public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException { return; } script.setPath(FilenameUtils.normalize(path + "/" + dirEntry.getRelativePath(), true)); - script.setCreatedDate(dirEntry.getDate().toInstant()); - script.setLastModifiedDate(dirEntry.getDate().toInstant()); + script.setCreatedAt(dirEntry.getDate().toInstant()); + script.setLastModifiedAt(dirEntry.getDate().toInstant()); script.setDescription(dirEntry.getCommitMessage()); script.setRevision(dirEntry.getRevision()); if (dirEntry.getKind() == SVNNodeKind.DIR) { @@ -183,8 +183,9 @@ public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException { if (StringUtils.isBlank(relativePath)) { return; } - script.setCreatedDate(dirEntry.getDate().toInstant()); - script.setLastModifiedDate(dirEntry.getDate().toInstant()); + Instant lastModifiedAt = dirEntry.getDate().toInstant(); + script.setCreatedAt(lastModifiedAt); + script.setLastModifiedAt(lastModifiedAt); script.setPath(relativePath); script.setDescription(dirEntry.getCommitMessage()); long reversion = dirEntry.getRevision(); @@ -255,7 +256,7 @@ public FileEntry findOne(User user, String path, SVNRevision revision) { script.setDescription(info.getCommitMessage()); script.setRevision(revisionNumber); script.setLastRevision(lastRevisionNumber); - script.setCreatedUser(user); + script.setCreatedBy(user); } catch (Exception e) { LOG.error("Error while fetching a file from SVN {}", user.getUserId() + "_" + path, e); return null; diff --git a/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationPreAuthProvider.java b/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationPreAuthProvider.java index 1ad87220e6..df189be574 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationPreAuthProvider.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationPreAuthProvider.java @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -9,7 +9,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package org.ngrinder.security; @@ -30,17 +30,17 @@ /** * nGrinder {@link PreAuthenticatedAuthenticationProvider}. - * + * * Some SSO system like SiteMinder doesn't need nGrinder login page. If the user info is resolved by plugins * implementing {@link javax.servlet.Filter} which stores the {@link Authentication} by following code, - * + * * * SecurityContextHolder.getContext().setAuthentication(authenticate); * - * + * * {@link NGrinderAuthenticationPreAuthProvider} will take this Authentication Object and handles user language and * timezone settings and user save - * + * * @since 3.0 */ public class NGrinderAuthenticationPreAuthProvider extends PreAuthenticatedAuthenticationProvider { @@ -52,10 +52,10 @@ public class NGrinderAuthenticationPreAuthProvider extends PreAuthenticatedAuthe /** * Authenticate the given PreAuthenticatedAuthenticationToken. - * + * * If the principal contained in the authentication object is null, the request will be ignored to allow other * providers to authenticate it. - * + * * @param authentication * authentication * @return authorized {@link Authentication} @@ -84,7 +84,7 @@ public Authentication authenticate(Authentication authentication) { /** * Add new user into local db. - * + * * @param securedUser * user */ @@ -92,7 +92,7 @@ public Authentication authenticate(Authentication authentication) { public void addNewUserIntoLocal(SecuredUser securedUser) { User user = securedUser.getUser(); user.setAuthProviderClass(securedUser.getUserInfoProviderClass()); - user.setCreatedDate(now()); + user.setCreatedAt(now()); User findOneByUserId = userService.getOne(user.getUserId()); if (findOneByUserId != null) { user = findOneByUserId.merge(user); diff --git a/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationProvider.java b/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationProvider.java index 5a6a6318a6..4f6e0d14e3 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationProvider.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/security/NGrinderAuthenticationProvider.java @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -9,7 +9,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package org.ngrinder.security; @@ -43,11 +43,11 @@ /** * nGrinder UserDetailsAuthenticationProvider. - * + * * This class validates the user provided ID / Password from login page. Internally it uses the plugins implementing * {@link OnLoginRunnable}. If you want to extend user authentification, please create the plugin implementing * {@link OnLoginRunnable} interface. - * + * * @since 3.0 */ @SuppressWarnings("UnusedDeclaration") @@ -129,14 +129,14 @@ protected void additionalAuthenticationChecks(UserDetails userDetails, /** * Add new user into local db. - * + * * @param securedUser user */ @Transactional public void addNewUserIntoLocal(SecuredUser securedUser) { User user = securedUser.getUser(); user.setAuthProviderClass(securedUser.getUserInfoProviderClass()); - user.setCreatedDate(now()); + user.setCreatedAt(now()); User newUser = userService.getOne(user.getUserId()); if (newUser != null) { user = newUser.merge(user); diff --git a/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java b/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java index 73d75b8997..302f12cfca 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/user/service/UserService.java @@ -43,6 +43,7 @@ import java.util.ArrayList; import java.util.List; +import static java.time.Instant.now; import static org.apache.commons.lang.StringUtils.isBlank; import static org.hibernate.Hibernate.initialize; import static org.ngrinder.common.constant.CacheConstants.DIST_CACHE_USERS; @@ -285,12 +286,12 @@ public Page getPagedAll(String keyword, Pageable pageable) { @Override public User createUser(User user) { encodePassword(user); - Instant createdDate = Instant.now(); - user.setCreatedDate(createdDate); - user.setLastModifiedDate(createdDate); - User createdUser = getOne(ControllerConstants.NGRINDER_INITIAL_ADMIN_USERID); - user.setCreatedUser(createdUser); - user.setLastModifiedUser(createdUser); + Instant createdAt = now(); + user.setCreatedAt(createdAt); + user.setLastModifiedAt(createdAt); + User createdBy = getOne(ControllerConstants.NGRINDER_INITIAL_ADMIN_USERID); + user.setCreatedBy(createdBy); + user.setLastModifiedBy(createdBy); return saveWithoutPasswordEncoding(user); } diff --git a/ngrinder-controller/src/main/resources/ngrinder_datachange_logfile/db.changelog.xml b/ngrinder-controller/src/main/resources/ngrinder_datachange_logfile/db.changelog.xml index d92d335696..919829ade2 100644 --- a/ngrinder-controller/src/main/resources/ngrinder_datachange_logfile/db.changelog.xml +++ b/ngrinder-controller/src/main/resources/ngrinder_datachange_logfile/db.changelog.xml @@ -40,4 +40,5 @@ + diff --git a/ngrinder-controller/src/main/resources/ngrinder_datachange_logfile/db.changelog_schema_31.xml b/ngrinder-controller/src/main/resources/ngrinder_datachange_logfile/db.changelog_schema_31.xml new file mode 100644 index 0000000000..4ab70f1cbd --- /dev/null +++ b/ngrinder-controller/src/main/resources/ngrinder_datachange_logfile/db.changelog_schema_31.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + alter table PERF_TEST rename index created_user_index to created_by_index; + alter table PERF_TEST rename index last_modified_user_index to last_modified_by_index; + alter table NUSER rename index created_user_index to created_by_index; + alter table NUSER rename index last_modified_user_index to last_modified_by_index; + alter table TAG rename index created_user_index to created_by_index; + alter table TAG rename index last_modified_user_index to last_modified_by_index; + + + + + + alter index created_user_index rename to created_by_index_NUSER; + alter index last_modified_user_index_NUSER rename to last_modified_by_index_NUSER; + alter index created_user_index_PERF_TEST rename to created_by_index_PERF_TEST; + alter index last_modified_user_index_PERF_TEST rename to last_modified_by_index_PERF_TEST; + alter index created_user_index_TAG rename to created_by_index_TAG; + alter index last_modified_user_index_TAG rename to last_modified_by_index_TAG; + + + diff --git a/ngrinder-controller/src/test/java/org/ngrinder/common/service/ModelAspectTest.java b/ngrinder-controller/src/test/java/org/ngrinder/common/service/ModelAspectTest.java index a42806bb67..f75a76b0bd 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/common/service/ModelAspectTest.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/common/service/ModelAspectTest.java @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -9,7 +9,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package org.ngrinder.common.service; @@ -44,7 +44,7 @@ public void testModelAspect() { BaseModel baseModel = mock(BaseModel.class); when(joinPoint.getArgs()).thenReturn(new Object[] { baseModel }); modelAspect.beforeSave(joinPoint); - verify(baseModel, times(1)).setCreatedDate(any(Instant.class)); + verify(baseModel, times(1)).setCreatedAt(any(Instant.class)); } @Test @@ -58,6 +58,6 @@ public void testModelAspectOnServletContext() { when(joinPoint.getArgs()).thenReturn(new Object[] { baseModel }); setField(modelAspect, "springContext", springContext); modelAspect.beforeSave(joinPoint); - verify(baseModel, times(1)).setLastModifiedDate(any(Instant.class)); + verify(baseModel, times(1)).setLastModifiedAt(any(Instant.class)); } } diff --git a/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/MockPerfTestRunnable.java b/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/MockPerfTestRunnable.java index 5b2e706eb3..afea749ab0 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/MockPerfTestRunnable.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/MockPerfTestRunnable.java @@ -49,7 +49,7 @@ public MockPerfTestRunnable(PerfTestService perfTestService, AgentManager agentM void startAgentsOn(PerfTest perfTest, GrinderProperties grinderProperties, SingleConsole singleConsole) { getPerfTestService().markStatusAndProgress(perfTest, START_AGENTS, perfTest.getAgentCount() + " agents are starting."); - getAgentService().runAgent(perfTest.getLastModifiedUser(), singleConsole, grinderProperties, + getAgentService().runAgent(perfTest.getLastModifiedBy(), singleConsole, grinderProperties, perfTest.getAgentCount()); getPerfTestService().markStatusAndProgress(perfTest, START_AGENTS_FINISHED, perfTest.getAgentCount() + " agents are started."); diff --git a/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/TagServiceTest.java b/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/TagServiceTest.java index f738530938..e47e92d8d4 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/TagServiceTest.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/perftest/service/TagServiceTest.java @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -9,7 +9,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package org.ngrinder.perftest.service; @@ -22,7 +22,6 @@ import org.ngrinder.perftest.repository.TagRepository; import org.springframework.beans.factory.annotation.Autowired; -import java.util.Date; import java.util.List; import java.util.Set; @@ -62,8 +61,8 @@ public void beforeTag() { @Test public void testTagService() { Tag entity = new Tag("HELLO"); - entity.setLastModifiedUser(getTestUser()); - entity.setCreatedUser(getTestUser()); + entity.setLastModifiedBy(getTestUser()); + entity.setCreatedBy(getTestUser()); tagRepository.save(entity); Set addTags = tagService.addTags(getTestUser(), new String[]{"HELLO", "WORLD"}); assertThat(addTags.size(), is(2)); diff --git a/ngrinder-controller/src/test/java/org/ngrinder/script/handler/GroovyMavenProjectScriptHandlerTest.java b/ngrinder-controller/src/test/java/org/ngrinder/script/handler/GroovyMavenProjectScriptHandlerTest.java index f1f3f61de5..b04860d634 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/script/handler/GroovyMavenProjectScriptHandlerTest.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/script/handler/GroovyMavenProjectScriptHandlerTest.java @@ -24,7 +24,7 @@ public void testHandlerMatching() { FileEntry entry = new FileEntry(); entry.setPath("/hello/world/src/main/java/wow/Global.groovy"); - entry.setCreatedUser(user); + entry.setCreatedBy(user); assertThat(handler.canHandle(entry)).isTrue(); entry.setPath("/hello/world/src/main/wow/Global.groovy"); diff --git a/ngrinder-controller/src/test/java/org/ngrinder/script/handler/ScriptHandlerFactoryTest.java b/ngrinder-controller/src/test/java/org/ngrinder/script/handler/ScriptHandlerFactoryTest.java index 8eaf045ece..6bad47d701 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/script/handler/ScriptHandlerFactoryTest.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/script/handler/ScriptHandlerFactoryTest.java @@ -15,7 +15,7 @@ public class ScriptHandlerFactoryTest extends AbstractNGrinderTransactionalTest public void testFactoryCreation() { FileEntry fileEntry = new FileEntry(); fileEntry.setPath("/hello/world.groovy"); - fileEntry.setCreatedUser(getTestUser()); + fileEntry.setCreatedBy(getTestUser()); assertThat(factory.getHandler(fileEntry)).isInstanceOf(GroovyScriptHandler.class); fileEntry.setPath("/hello/world.py"); assertThat(factory.getHandler(fileEntry)).isInstanceOf(JythonScriptHandler.class); diff --git a/ngrinder-controller/src/test/java/org/ngrinder/user/controller/UserControllerTest.java b/ngrinder-controller/src/test/java/org/ngrinder/user/controller/UserControllerTest.java index ada6d6c012..be543e3e93 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/user/controller/UserControllerTest.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/user/controller/UserControllerTest.java @@ -119,8 +119,8 @@ private void saveTestUser(String userId, String userName) { newUser.setUserId(userId); newUser.setUserName(userName); newUser.setEmail("junoyoon@gmail.com"); - newUser.setCreatedUser(getTestUser()); - newUser.setCreatedDate(now()); + newUser.setCreatedBy(getTestUser()); + newUser.setCreatedAt(now()); newUser.setRole(Role.USER); userApiController.save(getAdminUser(), newUser); } diff --git a/ngrinder-controller/src/test/java/org/ngrinder/user/model/UserTest.java b/ngrinder-controller/src/test/java/org/ngrinder/user/model/UserTest.java index ae658558e5..8e85724a16 100644 --- a/ngrinder-controller/src/test/java/org/ngrinder/user/model/UserTest.java +++ b/ngrinder-controller/src/test/java/org/ngrinder/user/model/UserTest.java @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -9,7 +9,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package org.ngrinder.user.model; @@ -70,8 +70,8 @@ public void testShareUser() { User user = new User(); user.setUserName("MyName1"); user.setEmail("junoyoon@gmail.com"); - user.setCreatedUser(getUser("user")); - user.setCreatedDate(now); + user.setCreatedBy(getUser("user")); + user.setCreatedAt(now); user.setUserId("hello"); user.setRole(Role.USER); user = userRepository.save(user); @@ -79,8 +79,8 @@ public void testShareUser() { user2.setUserId("hello2"); user2.setUserName("MyName2"); user2.setEmail("junoyoon2@paran.com"); - user2.setCreatedUser(getUser("user")); - user2.setCreatedDate(now); + user2.setCreatedBy(getUser("user")); + user2.setCreatedAt(now); user2.setRole(Role.USER); userRepository.save(user2); @@ -88,8 +88,8 @@ public void testShareUser() { user3.setUserId("hello3"); user3.setUserName("MyName3"); user3.setEmail("junoyoon3@paran.com"); - user3.setCreatedUser(getUser("user")); - user3.setCreatedDate(now); + user3.setCreatedBy(getUser("user")); + user3.setCreatedAt(now); user3.setRole(Role.USER); userRepository.save(user3); @@ -97,8 +97,8 @@ public void testShareUser() { user4.setUserId("hello4"); user4.setUserName("MyName4"); user4.setEmail("junoyoon4@paran.com"); - user4.setCreatedUser(getUser("user")); - user4.setCreatedDate(now); + user4.setCreatedBy(getUser("user")); + user4.setCreatedAt(now); user4.setRole(Role.USER); sharedUsers.add(user3); sharedUsers.add(user2); @@ -120,8 +120,8 @@ public void testUser() { User user = new User(); user.setUserName("MyName1"); user.setEmail("junoyoon@gmail.com"); - user.setCreatedUser(getUser("user")); - user.setCreatedDate(now); + user.setCreatedBy(getUser("user")); + user.setCreatedAt(now); user.setUserId("hello"); user.setRole(Role.USER); user = userRepository.save(user); @@ -129,8 +129,8 @@ public void testUser() { user2.setUserId("hello2"); user2.setUserName("MyName2"); user2.setEmail("junoyoon@paran.com"); - user2.setCreatedUser(getUser("user")); - user2.setCreatedDate(now); + user2.setCreatedBy(getUser("user")); + user2.setCreatedAt(now); user2.setRole(Role.USER); userRepository.save(user2); diff --git a/ngrinder-core/src/main/java/org/ngrinder/model/BaseModel.java b/ngrinder-core/src/main/java/org/ngrinder/model/BaseModel.java index 1d39b2bb82..df11cc52d1 100644 --- a/ngrinder-core/src/main/java/org/ngrinder/model/BaseModel.java +++ b/ngrinder-core/src/main/java/org/ngrinder/model/BaseModel.java @@ -40,24 +40,24 @@ public class BaseModel extends BaseEntity { private static final long serialVersionUID = -3876339828833595694L; - @Column(name = "created_date", insertable = true, updatable = false) - private Instant createdDate; + @Column(name = "created_at", insertable = true, updatable = false) + private Instant createdAt; @JsonSerialize(using = User.UserReferenceSerializer.class) @ManyToOne - @JoinColumn(name = "created_user", insertable = true, updatable = false) - @Index(name = "created_user_index") + @JoinColumn(name = "created_by", insertable = true, updatable = false) + @Index(name = "created_by_index") @NotFound(action = NotFoundAction.IGNORE) - private User createdUser; + private User createdBy; - @Column(name = "last_modified_date", insertable = true, updatable = true) - private Instant lastModifiedDate; + @Column(name = "last_modified_at", insertable = true, updatable = true) + private Instant lastModifiedAt; @JsonSerialize(using = User.UserReferenceSerializer.class) @ManyToOne - @JoinColumn(name = "last_modified_user", insertable = true, updatable = true) - @Index(name = "last_modified_user_index") + @JoinColumn(name = "last_modified_By", insertable = true, updatable = true) + @Index(name = "last_modified_by_index") @NotFound(action = NotFoundAction.IGNORE) - private User lastModifiedUser; + private User lastModifiedBy; } diff --git a/ngrinder-core/src/main/java/org/ngrinder/model/PerfTest.java b/ngrinder-core/src/main/java/org/ngrinder/model/PerfTest.java index 430d11e6ff..b1f3a495f4 100644 --- a/ngrinder-core/src/main/java/org/ngrinder/model/PerfTest.java +++ b/ngrinder-core/src/main/java/org/ngrinder/model/PerfTest.java @@ -69,8 +69,8 @@ public PerfTest() { * @param createdUser crested user. */ public PerfTest(User createdUser) { - this.setCreatedUser(createdUser); - this.setLastModifiedUser(createdUser); + this.setCreatedBy(createdUser); + this.setLastModifiedBy(createdUser); } @Cloneable @@ -322,7 +322,7 @@ public void init() { @JsonIgnore public String getTestIdentifier() { - return "perftest_" + getId() + "_" + getLastModifiedUser().getUserId(); + return "perftest_" + getId() + "_" + getLastModifiedBy().getUserId(); } /** @@ -341,8 +341,8 @@ public String getDescription() { } @JsonIgnore - public String getLastModifiedDateToStr() { - return dateToString(from(getLastModifiedDate())); + public String getLastModifiedAtToStr() { + return dateToString(from(getLastModifiedAt())); } /** diff --git a/ngrinder-frontend/src/js/components/perftest/detail/Config.vue b/ngrinder-frontend/src/js/components/perftest/detail/Config.vue index 97d24151a8..861c5eeec6 100644 --- a/ngrinder-frontend/src/js/components/perftest/detail/Config.vue +++ b/ngrinder-frontend/src/js/components/perftest/detail/Config.vue @@ -577,7 +577,7 @@ showScript() { let showScriptUrl = `${this.contextPath}/script/detail/${this.test.config.scriptName}?r=${this.test.config.scriptRevision}`; if (this.isAdmin || this.isSuperUser) { - showScriptUrl += `&ownerId=${this.test.createdUser.userId}`; + showScriptUrl += `&ownerId=${this.test.createdBy.userId}`; } const openedWindow = window.open(showScriptUrl, 'scriptSource'); openedWindow.focus(); diff --git a/ngrinder-frontend/src/js/components/perftest/detail/Detail.vue b/ngrinder-frontend/src/js/components/perftest/detail/Detail.vue index 44cd291527..316d0a79ab 100644 --- a/ngrinder-frontend/src/js/components/perftest/detail/Detail.vue +++ b/ngrinder-frontend/src/js/components/perftest/detail/Detail.vue @@ -76,7 +76,7 @@ - +
@@ -110,7 +110,7 @@ import PopoverMixin from '../../common/mixin/PopoverMixin.vue'; import CommonMixin from '../mixin/CommonMixin.vue'; import Utils from '../../../utils.js'; - import { TipType } from "../../../constants"; + import { TipType } from '../../../constants'; class PerfTestSerializer { static serialize(test) { @@ -155,7 +155,7 @@ static deserialize(test) { return { id: test.id, - createdUser: test.createdUser, + createdBy: test.createdBy, progressMessage: test.progressMessage, lastProgressMessage: test.lastProgressMessage, testName: test.testName, @@ -286,9 +286,9 @@ } static prepareSvnScripts(route) { - let apiUrl = `/perftest/api/script`; + let apiUrl = '/perftest/api/script'; if (route.params.isAdmin) { - apiUrl += `?ownerId=${route.params.test.createdUser.userId}`; + apiUrl += `?ownerId=${route.params.test.createdBy.userId}`; } return Base.prototype.$http.get(apiUrl) .then(res => route.params.scriptsMap.svn = res.data); @@ -513,11 +513,11 @@ } get switchUserTitle() { - return `${this.i18n('perfTest.list.owner')} : ${this.test.createdUser.userName} (${this.test.createdUser.userId})`; + return `${this.i18n('perfTest.list.owner')} : ${this.test.createdBy.userName} (${this.test.createdBy.userId})`; } get disabled() { - return this.test.createdUser.userId !== this.ngrinder.currentUser.factualUser.id; + return this.test.createdBy.userId !== this.ngrinder.currentUser.factualUser.id; } } diff --git a/ngrinder-frontend/src/js/components/perftest/list/List.vue b/ngrinder-frontend/src/js/components/perftest/list/List.vue index bec5eb4758..1ab3ee9d6c 100644 --- a/ngrinder-frontend/src/js/components/perftest/list/List.vue +++ b/ngrinder-frontend/src/js/components/perftest/list/List.vue @@ -43,7 +43,7 @@