비동기 테스트 추가
This commit is contained in:
@@ -7,6 +7,20 @@ import com.eactive.testmaster.api.entity.MockCondition;
|
|||||||
import com.eactive.testmaster.api.entity.MockResponse;
|
import com.eactive.testmaster.api.entity.MockResponse;
|
||||||
import com.eactive.testmaster.api.entity.MockRoute;
|
import com.eactive.testmaster.api.entity.MockRoute;
|
||||||
import com.eactive.testmaster.api.service.MockRouteService;
|
import com.eactive.testmaster.api.service.MockRouteService;
|
||||||
|
import com.eactive.testmaster.config.HazelcastJSBridge;
|
||||||
|
import com.eactive.testmaster.loadtest.service.Console;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import javax.script.Bindings;
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
|
import javax.script.ScriptEngineManager;
|
||||||
|
import javax.script.ScriptException;
|
||||||
|
import javax.script.SimpleBindings;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -16,29 +30,46 @@ import org.springframework.http.ResponseEntity;
|
|||||||
import org.springframework.util.AntPathMatcher;
|
import org.springframework.util.AntPathMatcher;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class MockApiController {
|
public class MockApiController {
|
||||||
|
|
||||||
private final MockRouteService mockRouteService;
|
private final MockRouteService mockRouteService;
|
||||||
|
private final HazelcastJSBridge hazelcastJSBridge;
|
||||||
private final ConditionMatcherService conditionMatcherService;
|
private final ConditionMatcherService conditionMatcherService;
|
||||||
|
private final ScriptEngine scriptEngine; // Add ScriptEngine as a field
|
||||||
public MockApiController(MockRouteService mockRouteService, ConditionMatcherService conditionMatcherService) {
|
private final Console console; // Add Console as a field
|
||||||
this.mockRouteService = mockRouteService;
|
|
||||||
this.conditionMatcherService = conditionMatcherService;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(MockApiController.class);
|
private static final Logger logger = LoggerFactory.getLogger(MockApiController.class);
|
||||||
|
|
||||||
|
|
||||||
|
public MockApiController(MockRouteService mockRouteService, HazelcastJSBridge hazelcastJSBridge, ConditionMatcherService conditionMatcherService) {
|
||||||
|
this.mockRouteService = mockRouteService;
|
||||||
|
this.hazelcastJSBridge = hazelcastJSBridge;
|
||||||
|
this.conditionMatcherService = conditionMatcherService;
|
||||||
|
// Initialize ScriptEngine once
|
||||||
|
ScriptEngineManager manager = new ScriptEngineManager();
|
||||||
|
this.scriptEngine = manager.getEngineByName("nashorn");
|
||||||
|
this.hazelcastJSBridge.enhanceEngine(this.scriptEngine);
|
||||||
|
|
||||||
|
// Initialize Console once
|
||||||
|
this.console = new Console();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void executeScript(String script, MockRequest httpRequest) {
|
||||||
|
if (script != null && !script.isEmpty()) {
|
||||||
|
Bindings scriptBindings = new SimpleBindings();
|
||||||
|
scriptBindings.put("request", httpRequest);
|
||||||
|
scriptBindings.put("console", this.console);
|
||||||
|
try {
|
||||||
|
scriptEngine.eval(script, scriptBindings);
|
||||||
|
} catch (ScriptException e) {
|
||||||
|
logger.error("Error executing request script", e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ResponseEntity<String> handleRequest(HttpServletRequest httpRequest) throws IOException {
|
public ResponseEntity<String> handleRequest(HttpServletRequest httpRequest) throws IOException {
|
||||||
|
|
||||||
MockRequest request = new MockRequest(httpRequest);
|
MockRequest request = new MockRequest(httpRequest);
|
||||||
@@ -53,9 +84,13 @@ public class MockApiController {
|
|||||||
|
|
||||||
for (MockRoute mockRoute : mockRouteService.getAllRoutes()) {
|
for (MockRoute mockRoute : mockRouteService.getAllRoutes()) {
|
||||||
if (isRouteMatch(mockRoute, request)) {
|
if (isRouteMatch(mockRoute, request)) {
|
||||||
|
if (mockRoute.getRequestScript() != null && !mockRoute.getRequestScript().isEmpty()) {
|
||||||
|
executeScript(mockRoute.getRequestScript(), request);
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, String> pathVariables = pathMatcher.extractUriTemplateVariables(mockRoute.getPathPattern(), request.getUri());
|
Map<String, String> pathVariables = pathMatcher.extractUriTemplateVariables(mockRoute.getPathPattern(), request.getUri());
|
||||||
MockResponse matchingResponse = findMatchingResponse(mockRoute, request, pathVariables);
|
MockResponse matchingResponse = findMatchingResponse(mockRoute, request, pathVariables);
|
||||||
|
|
||||||
if (matchingResponse != null) {
|
if (matchingResponse != null) {
|
||||||
if (matchingResponse.getDelay() > 0) {
|
if (matchingResponse.getDelay() > 0) {
|
||||||
try {
|
try {
|
||||||
@@ -66,6 +101,9 @@ public class MockApiController {
|
|||||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error processing request due to interruption.");
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error processing request due to interruption.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
executeScript(matchingResponse.getResponseScript(), request);
|
||||||
|
|
||||||
HttpHeaders responseHeaders = new HttpHeaders();
|
HttpHeaders responseHeaders = new HttpHeaders();
|
||||||
matchingResponse.getHeaders().forEach(responseHeaders::set);
|
matchingResponse.getHeaders().forEach(responseHeaders::set);
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ public class MockRouteRegisterDTO {
|
|||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
private String requestScript;
|
||||||
|
|
||||||
@Size(min = 1, message = "Response must have at least one item")
|
@Size(min = 1, message = "Response must have at least one item")
|
||||||
private List<MockResponseDTO> responses = new ArrayList<>();
|
private List<MockResponseDTO> responses = new ArrayList<>();
|
||||||
|
|
||||||
@@ -72,4 +74,12 @@ public class MockRouteRegisterDTO {
|
|||||||
public void setResponses(List<MockResponseDTO> responses) {
|
public void setResponses(List<MockResponseDTO> responses) {
|
||||||
this.responses = responses;
|
this.responses = responses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRequestScript() {
|
||||||
|
return requestScript;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequestScript(String requestScript) {
|
||||||
|
this.requestScript = requestScript;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ public class MockRouteUpdateDTO {
|
|||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
private String requestScript;
|
||||||
|
|
||||||
|
|
||||||
@Size(min = 1, message = "Response must have at least one item")
|
@Size(min = 1, message = "Response must have at least one item")
|
||||||
private List<MockResponseDTO> responses = new ArrayList<>();
|
private List<MockResponseDTO> responses = new ArrayList<>();
|
||||||
|
|
||||||
@@ -70,4 +73,12 @@ public class MockRouteUpdateDTO {
|
|||||||
public void setResponses(List<MockResponseDTO> responses) {
|
public void setResponses(List<MockResponseDTO> responses) {
|
||||||
this.responses = responses;
|
this.responses = responses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRequestScript() {
|
||||||
|
return requestScript;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequestScript(String requestScript) {
|
||||||
|
this.requestScript = requestScript;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ public class MockResponse {
|
|||||||
|
|
||||||
private String encodingCharset;
|
private String encodingCharset;
|
||||||
|
|
||||||
|
@Lob
|
||||||
|
private String responseScript;
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -123,4 +126,12 @@ public class MockResponse {
|
|||||||
public void setEncodingCharset(String encodingCharset) {
|
public void setEncodingCharset(String encodingCharset) {
|
||||||
this.encodingCharset = encodingCharset;
|
this.encodingCharset = encodingCharset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getResponseScript() {
|
||||||
|
return responseScript;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResponseScript(String responseScript) {
|
||||||
|
this.responseScript = responseScript;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import javax.persistence.FetchType;
|
|||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import javax.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Lob;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@@ -28,6 +29,8 @@ public class MockRoute {
|
|||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
@Lob
|
||||||
|
private String requestScript;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "route", cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
|
@OneToMany(mappedBy = "route", cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
|
||||||
private List<MockResponse> responses = new ArrayList<>();
|
private List<MockResponse> responses = new ArrayList<>();
|
||||||
@@ -80,4 +83,12 @@ public class MockRoute {
|
|||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getRequestScript() {
|
||||||
|
return requestScript;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequestScript(String requestScript) {
|
||||||
|
this.requestScript = requestScript;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,8 +73,7 @@ public class MockRouteService {
|
|||||||
|
|
||||||
route.setName(updated.getName());
|
route.setName(updated.getName());
|
||||||
route.setDescription(updated.getDescription());
|
route.setDescription(updated.getDescription());
|
||||||
// route.setMethod(updated.getMethod());
|
route.setRequestScript(updated.getRequestScript());
|
||||||
// route.setPathPattern(updated.getPathPattern());
|
|
||||||
if (!route.getPathPattern().startsWith("/")) {
|
if (!route.getPathPattern().startsWith("/")) {
|
||||||
route.setPathPattern("/" + route.getPathPattern());
|
route.setPathPattern("/" + route.getPathPattern());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package com.eactive.testmaster.config;
|
||||||
|
|
||||||
|
import static javax.script.ScriptContext.GLOBAL_SCOPE;
|
||||||
|
|
||||||
|
import com.hazelcast.collection.IQueue;
|
||||||
|
import com.hazelcast.core.HazelcastInstance;
|
||||||
|
import com.hazelcast.scheduledexecutor.IScheduledExecutorService;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import javax.script.Bindings;
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
|
import javax.script.SimpleBindings;
|
||||||
|
import org.apache.commons.lang3.function.TriFunction;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class HazelcastJSBridge {
|
||||||
|
|
||||||
|
private final HazelcastInstance hazelcastInstance;
|
||||||
|
private final IScheduledExecutorService scheduledExecutor;
|
||||||
|
|
||||||
|
|
||||||
|
public HazelcastJSBridge(HazelcastInstance hazelcastInstance) {
|
||||||
|
this.hazelcastInstance = hazelcastInstance;
|
||||||
|
this.scheduledExecutor = hazelcastInstance.getScheduledExecutorService("delayed-queue-executor");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates bindings for Hazelcast operations that can be used in JavaScript
|
||||||
|
*/
|
||||||
|
public Bindings createHazelcastBindings() {
|
||||||
|
Bindings bindings = new SimpleBindings();
|
||||||
|
|
||||||
|
bindings.put("tmOfferToQueue", (java.util.function.BiFunction<String, Object, Boolean>)
|
||||||
|
(queueName, item) -> {
|
||||||
|
IQueue<Object> queue = hazelcastInstance.getQueue(queueName);
|
||||||
|
return queue.offer(item);
|
||||||
|
});
|
||||||
|
|
||||||
|
bindings.put("tmPollFromQueue", (java.util.function.Function<String, Object>)
|
||||||
|
queueName -> {
|
||||||
|
IQueue<Object> queue = hazelcastInstance.getQueue(queueName);
|
||||||
|
return queue.poll();
|
||||||
|
});
|
||||||
|
|
||||||
|
bindings.put("tmScheduleToQueue", (TriFunction<String, Object, Integer, Boolean>)
|
||||||
|
(queueName, item, delaySeconds) -> {
|
||||||
|
try {
|
||||||
|
scheduledExecutor.schedule(
|
||||||
|
() -> {
|
||||||
|
IQueue<Object> queue = hazelcastInstance.getQueue(queueName);
|
||||||
|
queue.offer(item);
|
||||||
|
},
|
||||||
|
delaySeconds,
|
||||||
|
TimeUnit.SECONDS
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Utility operations
|
||||||
|
bindings.put("tmGetDistributedObjects",
|
||||||
|
(java.util.function.Supplier<Collection<?>>)
|
||||||
|
() -> hazelcastInstance.getDistributedObjects());
|
||||||
|
|
||||||
|
return bindings;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enhances the JavaScript engine with Hazelcast capabilities
|
||||||
|
*/
|
||||||
|
public void enhanceEngine(ScriptEngine engine) {
|
||||||
|
engine.setBindings(createHazelcastBindings(), GLOBAL_SCOPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.eactive.testmaster.config;
|
||||||
|
|
||||||
|
|
||||||
|
import com.hazelcast.config.Config;
|
||||||
|
import com.hazelcast.config.NetworkConfig;
|
||||||
|
import com.hazelcast.config.QueueConfig;
|
||||||
|
import com.hazelcast.core.Hazelcast;
|
||||||
|
import com.hazelcast.core.HazelcastInstance;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class TestMasterHazelcastConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Config hazelcastConfig() {
|
||||||
|
Config config = new Config();
|
||||||
|
config.setInstanceName("hazelcast-instance");
|
||||||
|
|
||||||
|
// Configure network
|
||||||
|
NetworkConfig network = config.getNetworkConfig();
|
||||||
|
network.setPort(5701);
|
||||||
|
network.setPortAutoIncrement(true);
|
||||||
|
|
||||||
|
// Configure queue
|
||||||
|
QueueConfig queueConfig = new QueueConfig();
|
||||||
|
queueConfig.setName("taskQueue");
|
||||||
|
queueConfig.setMaxSize(1000);
|
||||||
|
queueConfig.setBackupCount(1);
|
||||||
|
config.addQueueConfig(queueConfig);
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public HazelcastInstance hazelcastInstance(Config config) {
|
||||||
|
return Hazelcast.newHazelcastInstance(config);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,9 +17,11 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import javax.script.Bindings;
|
||||||
import javax.script.ScriptEngine;
|
import javax.script.ScriptEngine;
|
||||||
import javax.script.ScriptEngineManager;
|
|
||||||
import javax.script.ScriptException;
|
import javax.script.ScriptException;
|
||||||
|
import javax.script.SimpleBindings;
|
||||||
|
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
|
||||||
import org.apache.commons.lang3.SerializationUtils;
|
import org.apache.commons.lang3.SerializationUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -28,7 +30,11 @@ public class VirtualUser implements Runnable {
|
|||||||
|
|
||||||
//logger
|
//logger
|
||||||
private static final Logger logger = LoggerFactory.getLogger(VirtualUser.class);
|
private static final Logger logger = LoggerFactory.getLogger(VirtualUser.class);
|
||||||
|
private ScriptEngine scriptEngine;
|
||||||
|
private Console console;
|
||||||
private final Object pauseLock = new Object();
|
private final Object pauseLock = new Object();
|
||||||
|
private final Object scriptLock = new Object(); // New lock for script execution
|
||||||
|
|
||||||
private boolean paused = false;
|
private boolean paused = false;
|
||||||
private volatile boolean running = true;
|
private volatile boolean running = true;
|
||||||
|
|
||||||
@@ -43,10 +49,9 @@ public class VirtualUser implements Runnable {
|
|||||||
private Map<String, String> variables = new ConcurrentHashMap<>();
|
private Map<String, String> variables = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private String testId;
|
private String testId;
|
||||||
|
|
||||||
private ScenarioNode scenario;
|
private ScenarioNode scenario;
|
||||||
|
private final ThreadLocal<Set<ScenarioNode>> visitedNodes = ThreadLocal.withInitial(HashSet::new);
|
||||||
|
|
||||||
private Set<ScenarioNode> visitedNodes = new HashSet<>();
|
|
||||||
|
|
||||||
private CountDownLatch latch;
|
private CountDownLatch latch;
|
||||||
|
|
||||||
@@ -57,11 +62,19 @@ public class VirtualUser implements Runnable {
|
|||||||
this.maxCount = maxCount;
|
this.maxCount = maxCount;
|
||||||
this.apiClientFactory = apiClientFactory;
|
this.apiClientFactory = apiClientFactory;
|
||||||
this.latch = latch;
|
this.latch = latch;
|
||||||
|
|
||||||
|
NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
|
||||||
|
this.scriptEngine = factory.getScriptEngine(new String[]{"--language=es5"});
|
||||||
|
this.console = new Console();
|
||||||
}
|
}
|
||||||
|
|
||||||
public VirtualUser(String testId, ApiClientFactory apiClientFactory) {
|
public VirtualUser(String testId, ApiClientFactory apiClientFactory) {
|
||||||
this.testId = testId;
|
this.testId = testId;
|
||||||
this.apiClientFactory = apiClientFactory;
|
this.apiClientFactory = apiClientFactory;
|
||||||
|
|
||||||
|
NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
|
||||||
|
this.scriptEngine = factory.getScriptEngine(new String[]{"--language=es5"});
|
||||||
|
this.console = new Console();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause() {
|
public void pause() {
|
||||||
@@ -80,9 +93,8 @@ public class VirtualUser implements Runnable {
|
|||||||
public void stop() {
|
public void stop() {
|
||||||
running = false;
|
running = false;
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
resume(); // To ensure the user exits if it's paused
|
resume();
|
||||||
if (runningThread != null) {
|
if (runningThread != null) {
|
||||||
logger.debug("Virtual User Interrupting thread");
|
|
||||||
runningThread.interrupt();
|
runningThread.interrupt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,8 +102,6 @@ public class VirtualUser implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
logger.debug("Virtual user started");
|
|
||||||
runningThread = Thread.currentThread();
|
runningThread = Thread.currentThread();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while (maxCount == 0 || running && count < maxCount) {
|
while (maxCount == 0 || running && count < maxCount) {
|
||||||
@@ -108,8 +118,6 @@ public class VirtualUser implements Runnable {
|
|||||||
if (!running) {
|
if (!running) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//clear visited nodes
|
|
||||||
visitedNodes.clear();
|
|
||||||
performAction();
|
performAction();
|
||||||
logger.debug("Count: " + (count + 1) + " of " + maxCount);
|
logger.debug("Count: " + (count + 1) + " of " + maxCount);
|
||||||
count++;
|
count++;
|
||||||
@@ -120,6 +128,8 @@ public class VirtualUser implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void performAction() {
|
private void performAction() {
|
||||||
|
Set<ScenarioNode> threadLocalVisited = visitedNodes.get();
|
||||||
|
threadLocalVisited.clear();
|
||||||
ScenarioNode currentNode = scenario;
|
ScenarioNode currentNode = scenario;
|
||||||
|
|
||||||
while (running) {
|
while (running) {
|
||||||
@@ -127,24 +137,23 @@ public class VirtualUser implements Runnable {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (currentNode != null) {
|
if (currentNode != null) {
|
||||||
if (visitedNodes.contains(currentNode)) {
|
if (threadLocalVisited.contains(currentNode)) {
|
||||||
logger.debug("Loop detected, stopping");
|
logger.debug("Loop detected, stopping");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
visitedNodes.add(currentNode);
|
threadLocalVisited.add(currentNode);
|
||||||
|
|
||||||
if (currentNode.getClassName().equalsIgnoreCase("api")) {
|
if (currentNode.getClassName().equalsIgnoreCase("api")) {
|
||||||
processApi(currentNode.getApiRequest());
|
processApi(currentNode.getApiRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentNode.getConnections() != null && !currentNode.getConnections().isEmpty()) {
|
if (currentNode.getConnections() != null && !currentNode.getConnections().isEmpty()) {
|
||||||
currentNode = currentNode.getConnections().get(0); //현재는 1개의 connection만 지원
|
currentNode = currentNode.getConnections().get(0);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.debug("Action performed or interrupted");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -193,38 +202,48 @@ public class VirtualUser implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executePreRequestScript(ApiRequestDTO apiRequest) {
|
private void executeScript(Map<String, Object> bindings, String script) {
|
||||||
ScriptEngineManager manager = new ScriptEngineManager();
|
if (script == null || script.isEmpty()) {
|
||||||
ScriptEngine engine = manager.getEngineByName("nashorn");
|
return;
|
||||||
engine.put("console", new Console());
|
}
|
||||||
engine.put("globals", globals);
|
|
||||||
engine.put("variables", variables);
|
synchronized (scriptLock) {
|
||||||
engine.put("request", apiRequest);
|
try {
|
||||||
try {
|
Bindings scriptBindings = new SimpleBindings();
|
||||||
if(apiRequest.getPreRequestScript() != null)
|
scriptBindings.put("console", console);
|
||||||
engine.eval(apiRequest.getPreRequestScript());
|
scriptBindings.put("globals", globals);
|
||||||
} catch (ScriptException e) {
|
scriptBindings.put("variables", variables);
|
||||||
logger.error("Error executing pre-request script", e);
|
|
||||||
e.printStackTrace();
|
if (bindings != null) {
|
||||||
|
scriptBindings.putAll(bindings);
|
||||||
|
}
|
||||||
|
scriptEngine.eval(script, scriptBindings);
|
||||||
|
} catch (ScriptException e) {
|
||||||
|
logger.error("Error executing script", e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executePostRequestScript(ApiRequestDTO apiRequest, ApiResponse response) {
|
private void executePreRequestScript(ApiRequestDTO apiRequest) {
|
||||||
ScriptEngineManager manager = new ScriptEngineManager();
|
if (apiRequest.getPreRequestScript() == null) {
|
||||||
ScriptEngine engine = manager.getEngineByName("nashorn");
|
return;
|
||||||
engine.put("console", new Console());
|
|
||||||
engine.put("globals", globals);
|
|
||||||
engine.put("variables", variables);
|
|
||||||
engine.put("request", apiRequest);
|
|
||||||
engine.put("response", response);
|
|
||||||
try {
|
|
||||||
if (apiRequest.getPostRequestScript() != null){
|
|
||||||
engine.eval(apiRequest.getPostRequestScript());
|
|
||||||
}
|
|
||||||
} catch (ScriptException e) {
|
|
||||||
logger.error("Error executing post-request script", e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, Object> bindings = new HashMap<>();
|
||||||
|
bindings.put("request", apiRequest);
|
||||||
|
executeScript(bindings, apiRequest.getPreRequestScript());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void executePostRequestScript(ApiRequestDTO apiRequest, ApiResponse response) {
|
||||||
|
if (apiRequest.getPostRequestScript() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> bindings = new HashMap<>();
|
||||||
|
bindings.put("request", apiRequest);
|
||||||
|
bindings.put("response", response);
|
||||||
|
executeScript(bindings, apiRequest.getPostRequestScript());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApiRequestDTO replacePlaceHoldersWithVariables(ApiRequestDTO apiRequest) {
|
private ApiRequestDTO replacePlaceHoldersWithVariables(ApiRequestDTO apiRequest) {
|
||||||
@@ -260,7 +279,7 @@ public class VirtualUser implements Runnable {
|
|||||||
if (apiRequest.getLayout() != null && apiRequest.getLayout().getLayoutItems() != null) {
|
if (apiRequest.getLayout() != null && apiRequest.getLayout().getLayoutItems() != null) {
|
||||||
apiRequest.getLayout().setLayoutItems(replaceInLayoutItems(apiRequest.getLayout().getLayoutItems(), placeholder, value));
|
apiRequest.getLayout().setLayoutItems(replaceInLayoutItems(apiRequest.getLayout().getLayoutItems(), placeholder, value));
|
||||||
}
|
}
|
||||||
if (apiRequest.getLayout() !=null && apiRequest.getLayout().getComputedLayoutItemRoot() !=null){
|
if (apiRequest.getLayout() != null && apiRequest.getLayout().getComputedLayoutItemRoot() != null) {
|
||||||
replaceLayoutItemTree(apiRequest.getLayout().getComputedLayoutItemRoot(), placeholder, value);
|
replaceLayoutItemTree(apiRequest.getLayout().getComputedLayoutItemRoot(), placeholder, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+149
@@ -0,0 +1,149 @@
|
|||||||
|
package com.eactive.testmaster.queue.controller;
|
||||||
|
|
||||||
|
import com.eactive.testmaster.queue.entity.QueueHandler;
|
||||||
|
import com.eactive.testmaster.queue.mapper.QueueHandlerMapper;
|
||||||
|
import com.eactive.testmaster.queue.service.DynamicQueueManager;
|
||||||
|
import com.eactive.testmaster.queue.service.QueueHandlerService;
|
||||||
|
import com.eactive.testmaster.queue.dto.QueueHandlerDTO;
|
||||||
|
import com.eactive.testmaster.queue.dto.QueueHandlerSearch;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.security.access.annotation.Secured;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.ModelMap;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
import org.springframework.validation.Validator;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/mgmt/queues")
|
||||||
|
public class QueueHandlerMgmtController {
|
||||||
|
|
||||||
|
private static final String QUEUE_HANDLER = "queueHandler";
|
||||||
|
private static final String QUEUE_HANDLER_EDIT = "page/queues/queueHandlerEdit";
|
||||||
|
private static final String QUEUE_HANDLER_LIST_VIEW = "redirect:/mgmt/queues/list_view.do";
|
||||||
|
|
||||||
|
private final QueueHandlerService queueHandlerService;
|
||||||
|
private final Validator validator;
|
||||||
|
private final QueueHandlerMapper queueHandlerMapper;
|
||||||
|
private final DynamicQueueManager dynamicQueueManager;
|
||||||
|
|
||||||
|
public QueueHandlerMgmtController(QueueHandlerService queueHandlerService, Validator validator, QueueHandlerMapper queueHandlerMapper, DynamicQueueManager dynamicQueueManager) {
|
||||||
|
this.queueHandlerService = queueHandlerService;
|
||||||
|
this.validator = validator;
|
||||||
|
this.queueHandlerMapper = queueHandlerMapper;
|
||||||
|
this.dynamicQueueManager = dynamicQueueManager;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
queueHandlerService.initAllQueues();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/list_view.do")
|
||||||
|
@Secured("ROLE_MANAGE_QUEUE")
|
||||||
|
public ModelAndView listView(@ModelAttribute("queueHandlerSearch") QueueHandlerSearch queueHandlerSearch,
|
||||||
|
Pageable pageable) {
|
||||||
|
ModelAndView mav = new ModelAndView("page/queues/queueHandlerList");
|
||||||
|
Page<QueueHandler> page = queueHandlerService.findAll(queueHandlerSearch.buildSpecification(), pageable);
|
||||||
|
mav.addObject("page", page);
|
||||||
|
mav.addObject("pageable", pageable);
|
||||||
|
mav.addObject("modelSearch", queueHandlerSearch);
|
||||||
|
return mav;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/create_view.do")
|
||||||
|
@Secured("ROLE_MANAGE_QUEUE")
|
||||||
|
public ModelAndView createView() {
|
||||||
|
ModelAndView mav = new ModelAndView(QUEUE_HANDLER_EDIT);
|
||||||
|
mav.addObject(QUEUE_HANDLER, new QueueHandlerDTO());
|
||||||
|
return mav;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/update_view.do")
|
||||||
|
@Secured("ROLE_MANAGE_QUEUE")
|
||||||
|
public ModelAndView updateView(@RequestParam("id") String id) {
|
||||||
|
ModelAndView mav = new ModelAndView(QUEUE_HANDLER_EDIT);
|
||||||
|
QueueHandler found = queueHandlerService.findById(id);
|
||||||
|
mav.addObject(QUEUE_HANDLER, found); // Assuming direct usage of entity, you might want to use a DTO mapper
|
||||||
|
return mav;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/register.do")
|
||||||
|
@Secured("ROLE_MANAGE_QUEUE")
|
||||||
|
public String register(@ModelAttribute("queueHandler") QueueHandlerDTO dto,
|
||||||
|
BindingResult bindingResult,
|
||||||
|
ModelMap model) {
|
||||||
|
|
||||||
|
if (dto == null) {
|
||||||
|
return "redirect:/mgmt/queues/create_view.do";
|
||||||
|
}
|
||||||
|
|
||||||
|
validator.validate(dto, bindingResult);
|
||||||
|
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
model.addAttribute(QUEUE_HANDLER, dto);
|
||||||
|
return QUEUE_HANDLER_EDIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
QueueHandler queueHandler = queueHandlerMapper.map(dto);
|
||||||
|
queueHandlerService.create(queueHandler);
|
||||||
|
queueHandlerService.initAllQueues();
|
||||||
|
return QUEUE_HANDLER_LIST_VIEW;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/update.do")
|
||||||
|
@Secured("ROLE_MANAGE_QUEUE")
|
||||||
|
public String update(@RequestParam("queueName") String queueName,
|
||||||
|
@ModelAttribute("queueHandler") QueueHandlerDTO dto,
|
||||||
|
BindingResult bindingResult,
|
||||||
|
ModelMap model) {
|
||||||
|
|
||||||
|
if (dto.getQueueName() == null) {
|
||||||
|
return QUEUE_HANDLER_LIST_VIEW;
|
||||||
|
}
|
||||||
|
|
||||||
|
validator.validate(dto, bindingResult);
|
||||||
|
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
model.addAttribute(QUEUE_HANDLER, dto);
|
||||||
|
return QUEUE_HANDLER_EDIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
QueueHandler queueHandler = queueHandlerMapper.map(dto);
|
||||||
|
queueHandlerService.update(dto.getQueueName(), queueHandler);
|
||||||
|
queueHandlerService.initAllQueues();
|
||||||
|
return QUEUE_HANDLER_LIST_VIEW;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/delete.do")
|
||||||
|
@Secured("ROLE_MANAGE_QUEUE")
|
||||||
|
public String delete(@RequestParam("checkedIdForDel") List<String> ids) {
|
||||||
|
for (String id : ids) {
|
||||||
|
queueHandlerService.deleteById(id);
|
||||||
|
}
|
||||||
|
queueHandlerService.initAllQueues();
|
||||||
|
return QUEUE_HANDLER_LIST_VIEW;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/start.do")
|
||||||
|
@Secured("ROLE_MANAGE_QUEUE")
|
||||||
|
public String startQueue(@RequestParam("id") String id) {
|
||||||
|
QueueHandler queueHandler = queueHandlerService.findById(id);
|
||||||
|
dynamicQueueManager.startQueueListener(queueHandler);
|
||||||
|
return QUEUE_HANDLER_LIST_VIEW;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/stop.do")
|
||||||
|
@Secured("ROLE_MANAGE_QUEUE")
|
||||||
|
public String stopQueue(@RequestParam("id") String id) {
|
||||||
|
QueueHandler queueHandler = queueHandlerService.findById(id);
|
||||||
|
dynamicQueueManager.stopQueueListener(queueHandler.getQueueName());
|
||||||
|
return QUEUE_HANDLER_LIST_VIEW;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.eactive.testmaster.queue.dto;
|
||||||
|
|
||||||
|
public class QueueHandlerDTO {
|
||||||
|
|
||||||
|
private String queueName;
|
||||||
|
|
||||||
|
private String handlerScript;
|
||||||
|
|
||||||
|
public String getQueueName() {
|
||||||
|
return queueName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQueueName(String queueName) {
|
||||||
|
this.queueName = queueName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHandlerScript() {
|
||||||
|
return handlerScript;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHandlerScript(String handlerScript) {
|
||||||
|
this.handlerScript = handlerScript;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.eactive.testmaster.queue.dto;
|
||||||
|
|
||||||
|
import com.eactive.testmaster.common.search.BaseSearch;
|
||||||
|
import com.eactive.testmaster.common.search.ColumnSearchModel;
|
||||||
|
import com.eactive.testmaster.common.search.SearchCondition;
|
||||||
|
import com.eactive.testmaster.common.search.SearchModel;
|
||||||
|
import com.eactive.testmaster.queue.entity.QueueHandler;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class QueueHandlerSearch implements BaseSearch<QueueHandler> {
|
||||||
|
|
||||||
|
private String queueName;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SearchModel> buildSearchCondition() {
|
||||||
|
List<SearchModel> models = new ArrayList<>();
|
||||||
|
models.add(new ColumnSearchModel("queueName", SearchCondition.LIKE, queueName));
|
||||||
|
return models;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getQueueName() {
|
||||||
|
return queueName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQueueName(String queueName) {
|
||||||
|
this.queueName = queueName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.eactive.testmaster.queue.entity;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Lob;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class QueueHandler {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private String queueName;
|
||||||
|
|
||||||
|
@Lob
|
||||||
|
private String handlerScript;
|
||||||
|
|
||||||
|
public String getQueueName() {
|
||||||
|
return queueName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQueueName(String queueName) {
|
||||||
|
this.queueName = queueName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHandlerScript() {
|
||||||
|
return handlerScript;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHandlerScript(String handlerScript) {
|
||||||
|
this.handlerScript = handlerScript;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.eactive.testmaster.queue.mapper;
|
||||||
|
|
||||||
|
import com.eactive.testmaster.common.mapper.CommonMapper;
|
||||||
|
import com.eactive.testmaster.queue.dto.QueueHandlerDTO;
|
||||||
|
import com.eactive.testmaster.queue.entity.QueueHandler;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.ReportingPolicy;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Mapper(componentModel = "spring",
|
||||||
|
uses = {CommonMapper.class},
|
||||||
|
unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||||
|
@Component
|
||||||
|
public abstract class QueueHandlerMapper {
|
||||||
|
|
||||||
|
public abstract QueueHandler map(QueueHandlerDTO queue);
|
||||||
|
|
||||||
|
public abstract QueueHandlerDTO map(QueueHandler queue);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.eactive.testmaster.queue.repository;
|
||||||
|
|
||||||
|
import com.eactive.testmaster.queue.entity.QueueHandler;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
|
||||||
|
public interface QueueHandlerRepository extends JpaRepository<QueueHandler, String>, JpaSpecificationExecutor<QueueHandler> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package com.eactive.testmaster.queue.service;
|
||||||
|
|
||||||
|
import com.eactive.testmaster.config.HazelcastJSBridge;
|
||||||
|
import com.eactive.testmaster.queue.entity.QueueHandler;
|
||||||
|
import com.hazelcast.core.HazelcastInstance;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DynamicQueueManager {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(DynamicQueueManager.class);
|
||||||
|
|
||||||
|
private final HazelcastInstance hazelcastInstance;
|
||||||
|
private final Map<String, QueueListenerService> queueListeners;
|
||||||
|
private final HazelcastJSBridge hazelcastJSBridge;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DynamicQueueManager(HazelcastInstance hazelcastInstance, HazelcastJSBridge hazelcastJSBridge) {
|
||||||
|
this.hazelcastInstance = hazelcastInstance;
|
||||||
|
this.hazelcastJSBridge = hazelcastJSBridge;
|
||||||
|
this.queueListeners = new ConcurrentHashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start a listener for the specified queue
|
||||||
|
*/
|
||||||
|
// public void startQueueListener(QueueHandler queueHandler) {
|
||||||
|
// if (!queueListeners.containsKey(queueHandler.getQueueName())) {
|
||||||
|
// QueueListenerService listener = new QueueListenerService(hazelcastInstance, hazelcastJSBridge);
|
||||||
|
// listener.setQueueHandler(queueHandler);
|
||||||
|
// queueListeners.put(queueHandler.getQueueName(), listener);
|
||||||
|
// listener.startListening();
|
||||||
|
// logger.info("Started listener for queue: {}", queueHandler.getQueueName());
|
||||||
|
// } else {
|
||||||
|
// logger.warn("Listener already exists for queue: {}", queueHandler.getQueueName());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
public void startQueueListener(QueueHandler queueHandler) {
|
||||||
|
QueueListenerService existingListener = queueListeners.get(queueHandler.getQueueName());
|
||||||
|
if (existingListener != null) {
|
||||||
|
// If exists but not running, remove it so we can start fresh
|
||||||
|
if (!existingListener.isRunning()) {
|
||||||
|
queueListeners.remove(queueHandler.getQueueName());
|
||||||
|
} else {
|
||||||
|
logger.warn("Listener already exists and running for queue: {}", queueHandler.getQueueName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QueueListenerService listener = new QueueListenerService(hazelcastInstance, hazelcastJSBridge);
|
||||||
|
listener.setQueueHandler(queueHandler);
|
||||||
|
queueListeners.put(queueHandler.getQueueName(), listener);
|
||||||
|
listener.startListening();
|
||||||
|
logger.info("Started listener for queue: {}", queueHandler.getQueueName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop a queue listener
|
||||||
|
*/
|
||||||
|
public void stopQueueListener(String queueName) {
|
||||||
|
QueueListenerService listener = queueListeners.remove(queueName);
|
||||||
|
if (listener != null) {
|
||||||
|
listener.stopListening();
|
||||||
|
logger.info("Stopped listener for queue: {}", queueName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.eactive.testmaster.queue.service;
|
||||||
|
|
||||||
|
import com.eactive.testmaster.queue.entity.QueueHandler;
|
||||||
|
import com.eactive.testmaster.queue.repository.QueueHandlerRepository;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional
|
||||||
|
public class QueueHandlerService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private QueueHandlerRepository queueHandlerRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DynamicQueueManager dynamicQueueManager;
|
||||||
|
|
||||||
|
public void initAllQueues() {
|
||||||
|
queueHandlerRepository.findAll().forEach(queueHandler -> {
|
||||||
|
dynamicQueueManager.startQueueListener(queueHandler);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Page<QueueHandler> findAll(Specification<QueueHandler> specification, Pageable pageable) {
|
||||||
|
return queueHandlerRepository.findAll(specification, pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueueHandler findById(String id) {
|
||||||
|
return queueHandlerRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new RuntimeException("Queue Handler not found with id: " + id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueueHandler create(QueueHandler queueHandler) {
|
||||||
|
return queueHandlerRepository.save(queueHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueueHandler update(String queueName, QueueHandler queueHandler) {
|
||||||
|
QueueHandler handler = queueHandlerRepository.findById(queueName).orElseThrow(() -> new IllegalArgumentException("Queue Handler not found with name: " + queueName));
|
||||||
|
handler.setHandlerScript(queueHandler.getHandlerScript());
|
||||||
|
return queueHandlerRepository.save(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteById(String id) {
|
||||||
|
queueHandlerRepository.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
package com.eactive.testmaster.queue.service;
|
||||||
|
|
||||||
|
import com.eactive.testmaster.config.HazelcastJSBridge;
|
||||||
|
import com.eactive.testmaster.loadtest.service.Console;
|
||||||
|
import com.eactive.testmaster.queue.entity.QueueHandler;
|
||||||
|
import com.hazelcast.collection.IQueue;
|
||||||
|
import com.hazelcast.core.HazelcastInstance;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
import javax.script.Bindings;
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
|
import javax.script.ScriptEngineManager;
|
||||||
|
import javax.script.ScriptException;
|
||||||
|
import javax.script.SimpleBindings;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class QueueListenerService {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(QueueListenerService.class);
|
||||||
|
|
||||||
|
private IQueue<Object> taskQueue;
|
||||||
|
private final ExecutorService executorService;
|
||||||
|
private final AtomicBoolean running;
|
||||||
|
private final HazelcastInstance hazelcastInstance;
|
||||||
|
private final HazelcastJSBridge hazelcastJSBridge;
|
||||||
|
private QueueHandler queueHandler;
|
||||||
|
private final ScriptEngine scriptEngine; // Add ScriptEngine as a field
|
||||||
|
private final Console console;
|
||||||
|
|
||||||
|
public void setQueueHandler(QueueHandler queueHandler) {
|
||||||
|
this.queueHandler = queueHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public QueueListenerService(HazelcastInstance hazelcastInstance, HazelcastJSBridge hazelcastJSBridge) {
|
||||||
|
this.hazelcastInstance = hazelcastInstance;
|
||||||
|
this.hazelcastJSBridge = hazelcastJSBridge;
|
||||||
|
|
||||||
|
ScriptEngineManager manager = new ScriptEngineManager();
|
||||||
|
this.scriptEngine = manager.getEngineByName("nashorn");
|
||||||
|
this.hazelcastJSBridge.enhanceEngine(this.scriptEngine);
|
||||||
|
this.executorService = Executors.newSingleThreadExecutor();
|
||||||
|
this.running = new AtomicBoolean(false);
|
||||||
|
this.console = new Console();
|
||||||
|
}
|
||||||
|
|
||||||
|
// @PostConstruct
|
||||||
|
// public void startListening() {
|
||||||
|
// if (queueHandler != null) {
|
||||||
|
// taskQueue = hazelcastInstance.getQueue(queueHandler.getQueueName());
|
||||||
|
// executorService.submit(this::processQueueItems);
|
||||||
|
// logger.info("Queue listener started");
|
||||||
|
// this.running.set(true);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// private void processQueueItems() {
|
||||||
|
// while (running.get()) {
|
||||||
|
// try {
|
||||||
|
// Object item = taskQueue.poll();
|
||||||
|
// if (item != null) {
|
||||||
|
// processItem(item);
|
||||||
|
// }
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// logger.error("Error processing queue item", e);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void startListening() {
|
||||||
|
if (queueHandler != null) {
|
||||||
|
// Set running flag BEFORE starting the processing
|
||||||
|
this.running.set(true);
|
||||||
|
taskQueue = hazelcastInstance.getQueue(queueHandler.getQueueName());
|
||||||
|
executorService.submit(this::processQueueItems);
|
||||||
|
logger.info("Queue listener started for queue: {}", queueHandler.getQueueName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processQueueItems() {
|
||||||
|
while (running.get()) {
|
||||||
|
try {
|
||||||
|
// Use take() instead of poll() to block until an item is available
|
||||||
|
Object item = taskQueue.take();
|
||||||
|
processItem(item);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// Handle interruption (likely from shutdown)
|
||||||
|
logger.info("Queue listener interrupted, ending processing");
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
break;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error processing queue item", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logger.info("Queue listener stopped processing items");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void processItem(Object message) {
|
||||||
|
|
||||||
|
String script = queueHandler.getHandlerScript();
|
||||||
|
if (script != null && !script.isEmpty()) {
|
||||||
|
Bindings scriptBindings = new SimpleBindings();
|
||||||
|
scriptBindings.put("console", this.console);
|
||||||
|
scriptBindings.put("message", message);
|
||||||
|
|
||||||
|
try {
|
||||||
|
scriptEngine.eval(script, scriptBindings);
|
||||||
|
} catch (ScriptException e) {
|
||||||
|
logger.error("Error executing request script", e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRunning() {
|
||||||
|
return running.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// @PreDestroy
|
||||||
|
// public void stopListening() {
|
||||||
|
// logger.info("Stopping queue listener...");
|
||||||
|
// running.set(false);
|
||||||
|
// executorService.shutdown();
|
||||||
|
// try {
|
||||||
|
// if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) {
|
||||||
|
// executorService.shutdownNow();
|
||||||
|
// }
|
||||||
|
// } catch (InterruptedException e) {
|
||||||
|
// Thread.currentThread().interrupt();
|
||||||
|
// executorService.shutdownNow();
|
||||||
|
// }
|
||||||
|
// logger.info("Queue listener stopped");
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
public void stopListening() {
|
||||||
|
logger.info("Stopping queue listener...");
|
||||||
|
running.set(false);
|
||||||
|
// Interrupt the blocking take() call
|
||||||
|
executorService.shutdownNow();
|
||||||
|
try {
|
||||||
|
if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) {
|
||||||
|
logger.warn("Queue listener did not terminate in time");
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
logger.info("Queue listener stopped");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -133,6 +133,7 @@ public abstract class User extends Auditable implements Serializable, UserDetail
|
|||||||
authorities.add(new SimpleGrantedAuthority((userSecurity == null || userSecurity.isEmpty())? "ROLE_USER" : userSecurity));
|
authorities.add(new SimpleGrantedAuthority((userSecurity == null || userSecurity.isEmpty())? "ROLE_USER" : userSecurity));
|
||||||
|
|
||||||
if (this.userSecurity.equals("ROLE_ADMIN")) {
|
if (this.userSecurity.equals("ROLE_ADMIN")) {
|
||||||
|
authorities.add(new SimpleGrantedAuthority("ROLE_MANAGE_QUEUE"));
|
||||||
authorities.add(new SimpleGrantedAuthority("ROLE_MANAGE_ROUTE"));
|
authorities.add(new SimpleGrantedAuthority("ROLE_MANAGE_ROUTE"));
|
||||||
authorities.add(new SimpleGrantedAuthority("ROLE_MANAGE_SERVER"));
|
authorities.add(new SimpleGrantedAuthority("ROLE_MANAGE_SERVER"));
|
||||||
authorities.add(new SimpleGrantedAuthority("ROLE_MANAGE_USER"));
|
authorities.add(new SimpleGrantedAuthority("ROLE_MANAGE_USER"));
|
||||||
|
|||||||
@@ -22,6 +22,9 @@
|
|||||||
<div class="text-center flex-fill" sec:authorize="isAuthenticated()">
|
<div class="text-center flex-fill" sec:authorize="isAuthenticated()">
|
||||||
<a class="nav-link" th:href="@{/mgmt/routes/list_view.do}">응답 관리</a>
|
<a class="nav-link" th:href="@{/mgmt/routes/list_view.do}">응답 관리</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="text-center flex-fill" sec:authorize="isAuthenticated()">
|
||||||
|
<a class="nav-link" th:href="@{/mgmt/queues/list_view.do}">큐 관리</a>
|
||||||
|
</div>
|
||||||
<div class="text-center flex-fill" sec:authorize="isAuthenticated()">
|
<div class="text-center flex-fill" sec:authorize="isAuthenticated()">
|
||||||
<a class="nav-link" th:href="@{/mgmt/api_tester.do}">요청 관리</a>
|
<a class="nav-link" th:href="@{/mgmt/api_tester.do}">요청 관리</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
|
||||||
|
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{layout/default_layout}">
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<section layout:fragment="contentFragment">
|
||||||
|
<script th:src="@{/plugins/vs/loader.js}"></script>
|
||||||
|
<script>
|
||||||
|
require.config({paths: {'vs': '[[@{/plugins/vs}]]'}});
|
||||||
|
</script>
|
||||||
|
<div class="container-fluid mt-2">
|
||||||
|
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true" style="position: absolute; top: 0; left: 0;">
|
||||||
|
<div class="toast-header">
|
||||||
|
<strong class="mr-auto">알림</strong>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="toast-body">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form name="queueHandlerForm" id="queueHandlerForm"
|
||||||
|
th:action="${queueHandler.queueName == null}?@{/mgmt/queues/register.do}:@{/mgmt/queues/update.do}"
|
||||||
|
th:object='${queueHandler}' method="post">
|
||||||
|
<div class="card col-md">
|
||||||
|
<div class="card-header">
|
||||||
|
<h3 th:if="${queueHandler.queueName == null}">Queue Handler 등록</h3>
|
||||||
|
<h3 th:if="${queueHandler.queueName != null}">Queue Handler 수정</h3>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}">
|
||||||
|
|
||||||
|
<!-- Queue Name field -->
|
||||||
|
<div class="form-floating mt-2">
|
||||||
|
<input type="text" class="form-control"
|
||||||
|
th:classappend="${#fields.hasErrors('queueName')}? 'is-invalid'"
|
||||||
|
th:field="*{queueName}" required/>
|
||||||
|
<label for="queueName" class="form-label must">Queue Name</label>
|
||||||
|
<th:block th:each="err : ${#fields.errors('queueName')}">
|
||||||
|
<div th:text="${err}" class="invalid-feedback"></div>
|
||||||
|
</th:block>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Handler Script -->
|
||||||
|
<div class="card mt-3">
|
||||||
|
<div class="card-header">Handler Script</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div id="handler_script_editor" style="width:100%;height:400px;border:1px solid grey;"></div>
|
||||||
|
<textarea class="form-control" style="display: none;"
|
||||||
|
th:field="*{handlerScript}" name="handlerScript"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="card-footer">
|
||||||
|
<button type="button" class="btn btn-primary btn_list">
|
||||||
|
<i class="fa-solid fa-list"></i> 목록
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn btn-primary btn_register">
|
||||||
|
<i class="fa-sharp fa-solid fa-floppy-disk"></i> 저장
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<th:block layout:fragment="contentScript">
|
||||||
|
<script>
|
||||||
|
$(function () {
|
||||||
|
let handlerScriptEditor;
|
||||||
|
|
||||||
|
// Initialize Monaco Editor
|
||||||
|
require(['vs/editor/editor.main'], function () {
|
||||||
|
handlerScriptEditor = monaco.editor.create(document.getElementById('handler_script_editor'), {
|
||||||
|
value: document.querySelector('textarea[name="handlerScript"]').value || '',
|
||||||
|
language: 'javascript',
|
||||||
|
theme: 'vs-light',
|
||||||
|
automaticLayout: true
|
||||||
|
});
|
||||||
|
|
||||||
|
handlerScriptEditor.onDidChangeModelContent(function (e) {
|
||||||
|
document.querySelector('textarea[name="handlerScript"]').value = handlerScriptEditor.getValue();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
let fnRegister = document.querySelector(".btn_register");
|
||||||
|
|
||||||
|
fnRegister.addEventListener("click", function (event) {
|
||||||
|
let form = document.getElementById("queueHandlerForm");
|
||||||
|
// Update the hidden textarea with current editor content
|
||||||
|
document.querySelector('textarea[name="handlerScript"]').value = handlerScriptEditor.getValue();
|
||||||
|
|
||||||
|
if (!form.checkValidity()) {
|
||||||
|
event.preventDefault()
|
||||||
|
event.stopPropagation()
|
||||||
|
} else {
|
||||||
|
form.submit();
|
||||||
|
}
|
||||||
|
form.classList.add('was-validated');
|
||||||
|
});
|
||||||
|
|
||||||
|
let fnList = document.querySelector(".btn_list");
|
||||||
|
|
||||||
|
fnList.addEventListener("click", function () {
|
||||||
|
location.href = "[[@{/mgmt/queues/list_view.do}]]";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</th:block>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,215 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
|
||||||
|
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{layout/default_layout}">
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<section layout:fragment="contentFragment">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="card mt-4">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5><span style="font-weight: bold">Queue Handler List</span></h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<form role="form" class="row g-3" name="searchForm" th:action="@{/mgmt/queues/list_view.do}" method="get" th:object="${queueHandlerSearch}">
|
||||||
|
<input name="page" type="hidden" value="1"/>
|
||||||
|
<div class="col-auto">
|
||||||
|
<input class="form-control" name="name" placeholder="Name" type="text" size="35" th:title="#{title.search}+ '' + #{input.input}"
|
||||||
|
th:value="${queueHandlerSearch.queueName}"
|
||||||
|
maxlength="255"/>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<button type="button" class="btn btn-primary btn_search" th:value="#{button.inquire}">
|
||||||
|
<i class="fa-sharp fa-solid fa-magnifying-glass"></i> [[#{title.inquire}]]
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<button type="button" class="btn btn-primary btn_delete">
|
||||||
|
<i class="fa-sharp fa-solid fa-trash"></i> [[#{title.delete}]]
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<button type="button" class="btn btn-primary btn_add">
|
||||||
|
<i class="fa-sharp fa-solid fa-plus"></i> [[#{button.create}]]
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card mt-4">
|
||||||
|
<div class="card-body">
|
||||||
|
<form name="listForm">
|
||||||
|
<input name="id" type="hidden"/>
|
||||||
|
<input name="checkedIdForDel" type="hidden"/>
|
||||||
|
<input id="csrf" type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}">
|
||||||
|
<table class="table table-hover pt-table">
|
||||||
|
<colgroup>
|
||||||
|
<col style="width: 5%;">
|
||||||
|
<col style="width: 20%;">
|
||||||
|
<col style="width: 55%;">
|
||||||
|
<col style="width: 20%;">
|
||||||
|
</colgroup>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><div class="text-center">No.</div></th>
|
||||||
|
<th>
|
||||||
|
<div class="text-center">
|
||||||
|
<input type="checkbox" name="checkAll" class="form-check-input" onclick="fncCheckAll()" th:title="#{input.selectAll.title}">
|
||||||
|
</div>
|
||||||
|
</th>
|
||||||
|
<th><div class="text-center">Queue Name</div></th>
|
||||||
|
<th><div class="text-center">Actions</div></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr th:each="row, status : ${page.content}">
|
||||||
|
<td class="text-center" th:text="${page.getNumber() * page.getSize() + status.count}"></td>
|
||||||
|
<td>
|
||||||
|
<div class="d-flex justify-content-center">
|
||||||
|
<input type="checkbox" name="checkField" class="form-check-input" title="Select"/>
|
||||||
|
<input name="checkId" type="hidden" th:value="${row.queueName}"/>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div class="d-flex justify-content-center">
|
||||||
|
<span th:text="${row.queueName}"></span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div class="d-flex justify-content-end">
|
||||||
|
<button type="button" class="btn btn-success btn-sm me-2" th:onclick="fnStartQueue([[${row.queueName}]])" title="Start Queue">
|
||||||
|
<i class="fa-sharp fa-solid fa-play"></i> Start
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn btn-warning btn-sm me-2" th:onclick="fnStopQueue([[${row.queueName}]])" title="Stop Queue">
|
||||||
|
<i class="fa-sharp fa-solid fa-stop"></i> Stop
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn btn-primary btn-sm me-2" th:onclick="fnSelectItem([[${row.queueName}]])" th:value="#{button.update}">
|
||||||
|
<i class="fa-sharp fa-solid fa-edit"></i> [[#{button.update}]]
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<!-- No data message -->
|
||||||
|
<tr th:if="${page.content.size() == 0 }">
|
||||||
|
<td colspan="6" th:text="#{common.nodata.msg}"></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer">
|
||||||
|
<div th:replace="~{fragment/pagination :: pagination(jsFunction='fn_select_page')}"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<th:block layout:fragment="contentScript">
|
||||||
|
<script>
|
||||||
|
|
||||||
|
function fnStartQueue(id) {
|
||||||
|
if (confirm("Are you sure you want to start this queue?")) {
|
||||||
|
let form = document.createElement('form');
|
||||||
|
form.method = 'POST';
|
||||||
|
form.action = '[[@{/mgmt/queues/start.do}]]';
|
||||||
|
|
||||||
|
let idInput = document.createElement('input');
|
||||||
|
idInput.type = 'hidden';
|
||||||
|
idInput.name = 'id';
|
||||||
|
idInput.value = id;
|
||||||
|
|
||||||
|
let csrfInput = document.createElement('input');
|
||||||
|
csrfInput.type = 'hidden';
|
||||||
|
csrfInput.name = document.getElementById('csrf').name;
|
||||||
|
csrfInput.value = document.getElementById('csrf').value;
|
||||||
|
|
||||||
|
form.appendChild(idInput);
|
||||||
|
form.appendChild(csrfInput);
|
||||||
|
document.body.appendChild(form);
|
||||||
|
form.submit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function fnStopQueue(id) {
|
||||||
|
if (confirm("Are you sure you want to stop this queue?")) {
|
||||||
|
let form = document.createElement('form');
|
||||||
|
form.method = 'POST';
|
||||||
|
form.action = '[[@{/mgmt/queues/stop.do}]]';
|
||||||
|
|
||||||
|
let idInput = document.createElement('input');
|
||||||
|
idInput.type = 'hidden';
|
||||||
|
idInput.name = 'id';
|
||||||
|
idInput.value = id;
|
||||||
|
|
||||||
|
let csrfInput = document.createElement('input');
|
||||||
|
csrfInput.type = 'hidden';
|
||||||
|
csrfInput.name = document.getElementById('csrf').name;
|
||||||
|
csrfInput.value = document.getElementById('csrf').value;
|
||||||
|
|
||||||
|
form.appendChild(idInput);
|
||||||
|
form.appendChild(csrfInput);
|
||||||
|
document.body.appendChild(form);
|
||||||
|
form.submit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function fn_select_page(pageNo) {
|
||||||
|
document.searchForm.page.value = pageNo;
|
||||||
|
document.searchForm.submit();
|
||||||
|
}
|
||||||
|
|
||||||
|
function fnSelectItem(id) {
|
||||||
|
location.href = "[[@{/mgmt/queues/update_view.do}]]" + "?id=" + id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$(function () {
|
||||||
|
let fnSearch = document.querySelector(".btn_search");
|
||||||
|
let fnDelete = document.querySelector(".btn_delete");
|
||||||
|
let fnAdd = document.querySelector(".btn_add");
|
||||||
|
|
||||||
|
fnSearch.addEventListener("click", function () {
|
||||||
|
document.searchForm.page.value = 1;
|
||||||
|
document.searchForm.submit();
|
||||||
|
});
|
||||||
|
|
||||||
|
fnDelete.addEventListener("click", function () {
|
||||||
|
var checkField = document.listForm.checkField;
|
||||||
|
var id = document.listForm.checkId;
|
||||||
|
var checkedIds = "";
|
||||||
|
var checkedCount = 0;
|
||||||
|
if (checkField) {
|
||||||
|
if (checkField.length > 1) {
|
||||||
|
for (var i = 0; i < checkField.length; i++) {
|
||||||
|
if (checkField[i].checked) {
|
||||||
|
checkedIds += ((checkedCount == 0 ? "" : ",") + id[i].value);
|
||||||
|
checkedCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (checkField.checked) {
|
||||||
|
checkedIds = id.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (checkedIds.length > 0) {
|
||||||
|
if (confirm("[[#{common.delete.msg}]]")) {
|
||||||
|
document.listForm.checkedIdForDel.value = checkedIds;
|
||||||
|
document.listForm.method = 'POST';
|
||||||
|
document.listForm.action = '[[@{/mgmt/queues/delete.do}]]';
|
||||||
|
document.listForm.submit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
fnAdd.addEventListener("click", function () {
|
||||||
|
location.href = '[[@{/mgmt/queues/create_view.do}]]';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</th:block>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -78,6 +78,15 @@
|
|||||||
<div th:text="${err}" class="invalid-feedback"></div>
|
<div th:text="${err}" class="invalid-feedback"></div>
|
||||||
</th:block>
|
</th:block>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="card mt-1">
|
||||||
|
<div class="card-header">요청 스크립트</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div id="request_script_editor" class="request_script_editor" style="width:100%;height:250px;border:1px solid grey;"></div>
|
||||||
|
<textarea class="form-control" style="display: none;" name="requestScript" th:field="*{requestScript}"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="responses" class="mt-1">
|
<div id="responses" class="mt-1">
|
||||||
<div class="row" th:each="response, status: *{responses}">
|
<div class="row" th:each="response, status: *{responses}">
|
||||||
<input type="number" th:field="*{responses[__${status.index}__].statusCode}" required/>
|
<input type="number" th:field="*{responses[__${status.index}__].statusCode}" required/>
|
||||||
@@ -240,12 +249,14 @@
|
|||||||
name: '',
|
name: '',
|
||||||
method: '',
|
method: '',
|
||||||
pathPattern: '',
|
pathPattern: '',
|
||||||
responses: []
|
requestScript: '',
|
||||||
|
responses: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
let view = {
|
let view = {
|
||||||
currentIdx: 0,
|
currentIdx: 0,
|
||||||
responseEditors : [],
|
responseEditors : [],
|
||||||
|
requestScriptEditor: null, // Add reference for request script editor
|
||||||
init: function () {
|
init: function () {
|
||||||
$('.btn_add_case').on('click', function () {
|
$('.btn_add_case').on('click', function () {
|
||||||
controller.addResponse();
|
controller.addResponse();
|
||||||
@@ -310,7 +321,23 @@
|
|||||||
response.headers.push(header);
|
response.headers.push(header);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#responses').empty();
|
$('#responses').empty();
|
||||||
|
|
||||||
|
require(['vs/editor/editor.main'], function () {
|
||||||
|
view.requestScriptEditor = monaco.editor.create(document.getElementById('request_script_editor'), {
|
||||||
|
value: $('textarea[name="requestScript"]').val() || '',
|
||||||
|
theme: 'vs-light',
|
||||||
|
language: 'javascript',
|
||||||
|
automaticLayout: true
|
||||||
|
});
|
||||||
|
|
||||||
|
view.requestScriptEditor.onDidChangeModelContent(function (e) {
|
||||||
|
model.requestScript = view.requestScriptEditor.getValue();
|
||||||
|
$('textarea[name="requestScript"]').val(view.requestScriptEditor.getValue());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
this.render();
|
this.render();
|
||||||
},
|
},
|
||||||
renderCondition: function(i) {
|
renderCondition: function(i) {
|
||||||
|
|||||||
Reference in New Issue
Block a user