From 253ed30582e5ac515bb7e679d8775c708a4ab534 Mon Sep 17 00:00:00 2001 From: Jan Stefl Date: Thu, 14 Mar 2019 15:08:57 +0100 Subject: [PATCH] Fix: FacingServerConfigurator, FacingServerNode, StatusWorkerOperation, JkConfiguratorTestIT --- .../configure/FacingServerConfigurator.groovy | 14 +-- .../noe/jk/configure/FacingServerNode.groovy | 4 +- .../jk/configure/StatusWorkerOperation.groovy | 96 ++++++++++++++----- .../noe/modjk/JkConfiguratorTestIT.groovy | 2 +- 4 files changed, 83 insertions(+), 33 deletions(-) diff --git a/core/src/main/groovy/noe/jk/configure/FacingServerConfigurator.groovy b/core/src/main/groovy/noe/jk/configure/FacingServerConfigurator.groovy index 2a1951d5..e1258fef 100644 --- a/core/src/main/groovy/noe/jk/configure/FacingServerConfigurator.groovy +++ b/core/src/main/groovy/noe/jk/configure/FacingServerConfigurator.groovy @@ -60,10 +60,10 @@ class FacingServerConfigurator implements Configurator } uriWorkerMapProperties - .setBalancers(balancers) - .setWorkers(jkScenario.getWorkerNodes()) - .setStatusWorkers(jkScenario.getStatusWorkerNodes()) - .setAdditionalUrlMaps(jkScenario.getAdditionalUrlMaps()) + .setBalancers(uriWorkerMapProperties.getBalancers() + balancers) + .setWorkers(uriWorkerMapProperties.getWorkers() + jkScenario.getWorkerNodes()) + .setStatusWorkers(uriWorkerMapProperties.getStatusWorkers() + jkScenario.getStatusWorkerNodes()) + .setAdditionalUrlMaps(uriWorkerMapProperties.getAdditionalUrlMaps() + jkScenario.getAdditionalUrlMaps()) configurators << uriWorkerMapProperties.configure() } @@ -78,9 +78,9 @@ class FacingServerConfigurator implements Configurator } workersProperties - .setBalancers(balancers) - .setWorkers(jkScenario.getWorkerNodes()) - .setStatusWorkers(jkScenario.getStatusWorkerNodes()) + .setBalancers(workersProperties.getBalancers() + balancers) + .setWorkers(workersProperties.getWorkers() + jkScenario.getWorkerNodes()) + .setStatusWorkers(workersProperties.getStatusWorkers() + jkScenario.getStatusWorkerNodes()) configurators << workersProperties.configure() } diff --git a/core/src/main/groovy/noe/jk/configure/FacingServerNode.groovy b/core/src/main/groovy/noe/jk/configure/FacingServerNode.groovy index 6f45781e..8ba446f7 100644 --- a/core/src/main/groovy/noe/jk/configure/FacingServerNode.groovy +++ b/core/src/main/groovy/noe/jk/configure/FacingServerNode.groovy @@ -55,7 +55,7 @@ class FacingServerNode { return uriWorkerMapProperties } - JkScenario setUriWorkerMapProperties(UriWorkerMapProperties uriWorkerMapProperties) { + FacingServerNode setUriWorkerMapProperties(UriWorkerMapProperties uriWorkerMapProperties) { this.uriWorkerMapProperties = uriWorkerMapProperties return this @@ -65,7 +65,7 @@ class FacingServerNode { return workersProperties } - JkScenario setWorkersProperties(WorkersProperties workersProperties) { + FacingServerNode setWorkersProperties(WorkersProperties workersProperties) { this.workersProperties = workersProperties return this diff --git a/core/src/main/groovy/noe/jk/configure/StatusWorkerOperation.groovy b/core/src/main/groovy/noe/jk/configure/StatusWorkerOperation.groovy index 6cbeca68..fa005917 100644 --- a/core/src/main/groovy/noe/jk/configure/StatusWorkerOperation.groovy +++ b/core/src/main/groovy/noe/jk/configure/StatusWorkerOperation.groovy @@ -11,7 +11,7 @@ import noe.common.utils.Library * Example: List balancer summary in text format * * new StatusWorkerOperation() - * .setAction(StatusWorkerOperation.Action.LIST) + * .setAction(new StatusWorkerOperation.List()) * .setOutputFormat(StatusWorkerOperation.OutputFormat.TEXT) * .setBalancerId(balancerId) * .setHost(facingServer.getHost()) @@ -26,30 +26,84 @@ class StatusWorkerOperation { * Chapter: Usage Patterns / Actions * @link https://tomcat.apache.org/connectors-doc/reference/status.html */ - enum Action { LIST, SHOW, EDIT, UPDATE, RESET, RECOVER, VERSION, DUMP } + interface Action { + String build() + } - /** - * Chapter: Usage Patterns / Output Format - * @link https://tomcat.apache.org/connectors-doc/reference/status.html - */ - enum OutputFormat { HTML, XML, PROPERTIES, TEXT } + static class List implements Action { + @Override + String build() { + return 'list' + } + } - /** - * Chapter: Request Parameters / Data Parameters for the standard Update Action - * @link https://tomcat.apache.org/connectors-doc/reference/status.html - */ - enum Parameters { + static class Show implements Action { + @Override + String build() { + return 'show' + } + } + + static class Reset implements Action { + @Override + String build() { + return 'reset' + } + } + + static class Recover implements Action { + @Override + String build() { + return 'recover' + } + } + + static class Version implements Action { + @Override + String build() { + return 'version' + } + } + + static class Dump implements Action { + @Override + String build() { + return 'dump' + } + } + + static class Update implements Action { + Map params = [:] + + @Override + String build() { + StringBuilder action = new StringBuilder("update") + + params.each {String name, String value -> + action.append("&${name.toLowerCase()}=${value}") + } + + return action.toString() + } - // load balancer workers - VLR, VLT, VLEE, VLX, VLS, VLF, VLM, VLL, + /** + * Chapter: Request Parameters / Data Parameters for the standard Update Action + * @link https://tomcat.apache.org/connectors-doc/reference/status.html + */ + Update addParameter(String name, String value) { + params.put(name, value) - // load balancer members - VWA, VWF, VWN, VWR, VWC, VWD, + return this + } - // ajp workers and ajp load balancer members - VAHST, VAPRT, VACPT, VACT, VAPT, VART, VAR, VARO, VABL, VAMPS } + /** + * Chapter: Usage Patterns / Output Format + * @link https://tomcat.apache.org/connectors-doc/reference/status.html + */ + enum OutputFormat { HTML, XML, PROPERTIES, TEXT } + Action action OutputFormat outputFormat = OutputFormat.PROPERTIES String host @@ -168,7 +222,7 @@ class StatusWorkerOperation { StringBuilder c = new StringBuilder("?") if (action != null) { - c.append("cmd=${transformAction(action)}&") + c.append("cmd=${action.build()}&") } if (outputFormat != null) { c.append("mime=${transformOutputType(outputFormat)}&") @@ -205,10 +259,6 @@ class StatusWorkerOperation { return this } - private String transformAction(Action action) { - return action.toString().toLowerCase() - } - private String transformOutputType(OutputFormat format) { switch (format){ case OutputFormat.TEXT: diff --git a/testsuite/src/test/groovy/noe/modjk/JkConfiguratorTestIT.groovy b/testsuite/src/test/groovy/noe/modjk/JkConfiguratorTestIT.groovy index 352eac99..6e23a644 100644 --- a/testsuite/src/test/groovy/noe/modjk/JkConfiguratorTestIT.groovy +++ b/testsuite/src/test/groovy/noe/modjk/JkConfiguratorTestIT.groovy @@ -237,7 +237,7 @@ class JkConfiguratorTestIT extends TestAbstract { ops.startAll() String res = new StatusWorkerOperation() - .setAction(StatusWorkerOperation.Action.LIST) + .setAction(new StatusWorkerOperation.List()) .setOutputFormat(StatusWorkerOperation.OutputFormat.TEXT) .setBalancerId(balancerId) .setAutomaticRefresh(1)