Repository: knox Updated Branches: refs/heads/master 898e0a2d9 -> 11539a2e3
KNOX-1367 - Revert the previous schema changes, make a switch to enable strict topology validation, by default strict validation is false Project: http://git-wip-us.apache.org/repos/asf/knox/repo Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/11539a2e Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/11539a2e Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/11539a2e Branch: refs/heads/master Commit: 11539a2e3618eed2ba0f87ed5222eaa0dce591dc Parents: 898e0a2 Author: Sandeep More <m...@apache.org> Authored: Fri Jun 29 16:07:22 2018 -0400 Committer: Sandeep More <m...@apache.org> Committed: Fri Jun 29 16:08:03 2018 -0400 ---------------------------------------------------------------------- .../org/apache/knox/gateway/GatewayMessages.java | 4 ++++ .../gateway/config/impl/GatewayConfigImpl.java | 19 ++++++++++++++++--- .../topology/impl/DefaultTopologyService.java | 11 ++++++++++- .../src/main/resources/conf/topology-v1.xsd | 4 ++-- .../apache/knox/gateway/util/KnoxCLITest.java | 2 +- .../knox/gateway/config/GatewayConfig.java | 11 +++++++++++ .../apache/knox/gateway/GatewayTestConfig.java | 13 +++++++++++++ 7 files changed, 57 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/knox/blob/11539a2e/gateway-server/src/main/java/org/apache/knox/gateway/GatewayMessages.java ---------------------------------------------------------------------- diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/GatewayMessages.java b/gateway-server/src/main/java/org/apache/knox/gateway/GatewayMessages.java index 743b958..71c5396 100644 --- a/gateway-server/src/main/java/org/apache/knox/gateway/GatewayMessages.java +++ b/gateway-server/src/main/java/org/apache/knox/gateway/GatewayMessages.java @@ -114,6 +114,10 @@ public interface GatewayMessages { @Message( level = MessageLevel.ERROR, text = "Failed to undeploy topology {0}: {1}" ) void failedToUndeployTopology( String name, @StackTrace(level=MessageLevel.DEBUG) Exception e ); + @Message( level = MessageLevel.WARN, text = "Failed to validate topology {0} error {1}. Please " + + "consider using descriptors instead of topologies" ) + void failedToValidateTopology( String name, String cause ); + @Message( level = MessageLevel.INFO, text = "Deleting topology {0}" ) void deletingTopology( String topologyName ); http://git-wip-us.apache.org/repos/asf/knox/blob/11539a2e/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java ---------------------------------------------------------------------- diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java index 0ff8b22..51abba2 100644 --- a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java +++ b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java @@ -191,8 +191,8 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig { public static final String DEFAULT_DATA_DIR = "data"; private static final String PROVIDERCONFIG_DIR_NAME = "shared-providers"; private static final String DESCRIPTORS_DIR_NAME = "descriptors"; - public static final String REMOTE_ALIAS_SERVICE_ENABLED = GATEWAY_CONFIG_FILE_PREFIX + ".remote.alias.service.enabled"; + public static final String STRICT_TOPOLOGY_VALIDATION = GATEWAY_CONFIG_FILE_PREFIX + ".strict.topology.validation"; /** * Comma-separated list of topology names, which should be forcibly treated as read-only. @@ -212,9 +212,8 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig { public static final int DEFAULT_WEBSOCKET_IDLE_TIMEOUT = 300000; public static final boolean DEFAULT_GATEWAY_PORT_MAPPING_ENABLED = true; - public static final boolean DEFAULT_REMOTE_ALIAS_SERVICE_ENABLED = true; - + public static final boolean DEFAULT_STRICT_TOPOLOGY_VALIDATION = false; /** * Default list of MIME Type to be compressed. @@ -1110,4 +1109,18 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig { return result; } + /** + * Returns true when strict topology validation is enabled, in which case if + * topology validation fails Knox will throw a runtime exception. If false and + * topology validation fails Knox will log an ERROR and move on. + * + * @return + * @since 1.1.0 + */ + @Override + public boolean isTopologyValidationEnabled() { + final String result = get(STRICT_TOPOLOGY_VALIDATION, Boolean.toString(DEFAULT_STRICT_TOPOLOGY_VALIDATION)); + return Boolean.parseBoolean(result); + } + } http://git-wip-us.apache.org/repos/asf/knox/blob/11539a2e/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java ---------------------------------------------------------------------- diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java b/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java index d2f6ad0..fede61b 100644 --- a/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java +++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java @@ -115,6 +115,8 @@ public class DefaultTopologyService private RemoteConfigurationMonitor remoteMonitor = null; + private GatewayConfig config; + private Topology loadTopology(File file) throws IOException, SAXException, URISyntaxException, InterruptedException { final long TIMEOUT = 250; //ms final long DELAY = 50; //ms @@ -164,7 +166,13 @@ public class DefaultTopologyService TopologyValidator tv = new TopologyValidator(topology); if(!tv.validateTopology()) { - throw new SAXException(tv.getErrorString()); + if(config != null && config.isTopologyValidationEnabled()) { + /* If strict validation enabled we fail */ + throw new SAXException(tv.getErrorString()); + } else { + /* Log and move on */ + log.failedToValidateTopology(topology.getName(), tv.getErrorString()); + } } long start = System.currentTimeMillis(); @@ -606,6 +614,7 @@ public class DefaultTopologyService @Override public void init(GatewayConfig config, Map<String, String> options) throws ServiceLifecycleException { + this.config = config; String gatewayConfDir = config.getGatewayConfDir(); if (gatewayConfDir != null) { System.setProperty(ServiceDiscovery.CONFIG_DIR_PROPERTY, gatewayConfDir); http://git-wip-us.apache.org/repos/asf/knox/blob/11539a2e/gateway-server/src/main/resources/conf/topology-v1.xsd ---------------------------------------------------------------------- diff --git a/gateway-server/src/main/resources/conf/topology-v1.xsd b/gateway-server/src/main/resources/conf/topology-v1.xsd index db77156..722a365 100644 --- a/gateway-server/src/main/resources/conf/topology-v1.xsd +++ b/gateway-server/src/main/resources/conf/topology-v1.xsd @@ -30,7 +30,7 @@ limitations under the License. <h:element name="provider" maxOccurs="unbounded"> <h:complexType> - <h:choice minOccurs="1" maxOccurs="unbounded"> + <h:sequence> <h:element name="role" type="h:string" minOccurs="1" maxOccurs="1"/> <h:element name="name" type="h:string" minOccurs="1" maxOccurs="1"/> <h:element name="enabled" type="h:boolean" minOccurs="1" maxOccurs="1"/> @@ -45,7 +45,7 @@ limitations under the License. <h:attribute name="value" type="h:string" use="optional" /> </h:complexType> </h:element> - </h:choice> + </h:sequence> </h:complexType> </h:element> http://git-wip-us.apache.org/repos/asf/knox/blob/11539a2e/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java ---------------------------------------------------------------------- diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java b/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java index ae837df..116b8dd 100644 --- a/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java +++ b/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java @@ -1011,7 +1011,7 @@ public class KnoxCLITest { assertThat(outContent.toString(), containsString(config.getGatewayTopologyDir())); assertThat(outContent.toString(), containsString("test-cluster-bad")); assertThat(outContent.toString(), containsString("unsuccessful")); - //assertThat(outContent.toString(), containsString("Invalid content")); + assertThat(outContent.toString(), containsString("Invalid content")); assertThat(outContent.toString(), containsString("Line")); http://git-wip-us.apache.org/repos/asf/knox/blob/11539a2e/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java b/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java index c5e2337..7cce80d 100644 --- a/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java +++ b/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java @@ -433,5 +433,16 @@ public interface GatewayConfig { */ List<String> getDispatchWhitelistServices(); + /** + * Returns true when strict topology validation is enabled, + * in which case if topology validation fails Knox will throw + * a runtime exception. If false and topology validation fails + * Knox will log an ERROR and move on. + * + * @since 1.1.0 + * @return + */ + boolean isTopologyValidationEnabled(); + } http://git-wip-us.apache.org/repos/asf/knox/blob/11539a2e/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java ---------------------------------------------------------------------- diff --git a/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java b/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java index f8d4ec7..003e875 100644 --- a/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java +++ b/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java @@ -732,4 +732,17 @@ public class GatewayTestConfig extends Configuration implements GatewayConfig { return Collections.emptyList(); } + /** + * Returns true when strict topology validation is enabled, in which case if + * topology validation fails Knox will throw a runtime exception. If false and + * topology validation fails Knox will log an ERROR and move on. + * + * @return + * @since 1.1.0 + */ + @Override + public boolean isTopologyValidationEnabled() { + return false; + } + }