You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by km...@apache.org on 2013/07/10 21:02:14 UTC
git commit: KNOX-82: Support properties file format for topology
files. Specifically adds support for a Hadoop style XML format name/value
pair properties file.
Updated Branches:
refs/heads/master 21e6d1da3 -> 874d6fedf
KNOX-82: Support properties file format for topology files.
Specifically adds support for a Hadoop style XML format name/value pair properties file.
Project: http://git-wip-us.apache.org/repos/asf/incubator-knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-knox/commit/874d6fed
Tree: http://git-wip-us.apache.org/repos/asf/incubator-knox/tree/874d6fed
Diff: http://git-wip-us.apache.org/repos/asf/incubator-knox/diff/874d6fed
Branch: refs/heads/master
Commit: 874d6fedf1f73ec2e1f0e04d21999bf0311fba53
Parents: 21e6d1d
Author: Kevin Minder <ke...@hortonworks.com>
Authored: Wed Jul 10 15:02:08 2013 -0400
Committer: Kevin Minder <ke...@hortonworks.com>
Committed: Wed Jul 10 15:02:08 2013 -0400
----------------------------------------------------------------------
.../apache/hadoop/gateway/GatewayMessages.java | 3 +
.../apache/hadoop/gateway/GatewayResources.java | 18 +++
.../builder/BeanPropertyTopologyBuilder.java | 78 ++++++++++
.../builder/PropertyTopologyBuilder.java | 64 ++++++++
.../topology/builder/property/Property.java | 47 ++++++
.../interpreter/AbstractInterpreter.java | 22 +++
.../interpreter/GatewayPropertyInterpreter.java | 54 +++++++
.../interpreter/InterpretException.java | 36 +++++
.../property/interpreter/Interpreter.java | 22 +++
.../interpreter/PropertyInterpreter.java | 54 +++++++
.../ProviderParameterPropertyInterpreter.java | 50 ++++++
.../ProviderPropertyInterpreter.java | 88 +++++++++++
.../interpreter/ServicePropertyInterpreter.java | 81 ++++++++++
.../TopologyPropertyInterpreter.java | 62 ++++++++
.../topology/file/FileTopologyProvider.java | 12 +-
.../xml/AmbariFormatXmlTopologyRules.java | 37 +++++
.../xml/KnoxFormatXmlTopologyRules.java | 56 +++++++
.../gateway/topology/xml/XmlTopologyRules.java | 56 -------
.../builder/PropertyTopologyBuilderTest.java | 155 +++++++++++++++++++
.../topology/xml/TopologyRulesModuleTest.java | 69 ++++++++-
.../xml/simple-topology-ambari-format.xml | 75 +++++++++
.../xml/simple-topology-knox-format.xml | 68 ++++++++
.../gateway/topology/xml/simple-topology.xml | 68 --------
.../hadoop/gateway/topology/Topology.java | 20 +++
.../topology/builder/TopologyBuilder.java | 24 +++
25 files changed, 1188 insertions(+), 131 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
index 90befc7..3337b19 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
@@ -249,6 +249,9 @@ public interface GatewayMessages {
@Message( level = MessageLevel.ERROR, text = "Failed to establish connection to {0}: {1}" )
void failedToEstablishConnectionToUrl( String url, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
+ @Message( level = MessageLevel.ERROR, text = "Failed to interpret property \"{0}\": {1}")
+ void failedToInterpretProperty( String property, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
+
@Message( level = MessageLevel.ERROR, text = "Failed to instantiate the internal gateway services." )
void failedToInstantiateGatewayServices();
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayResources.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayResources.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayResources.java
index c05ef28..fe831b1 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayResources.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayResources.java
@@ -46,4 +46,22 @@ public interface GatewayResources {
@Resource( text="Display server version information." )
String versionHelpMessage();
+
+ @Resource( text="Topology is required." )
+ String topologyIsRequiredError();
+
+ @Resource( text="Provider is required." )
+ String providerIsRequiredError();
+
+ @Resource( text="Unsupported property's token: {0}" )
+ String unsupportedPropertyTokenError(String token);
+
+ @Resource( text="Failed to build topology: wrong data format." )
+ String wrongTopologyDataFormatError();
+
+ @Resource( text="Provider parameter name is required." )
+ String providerParameterNameIsRequiredError();
+
+ @Resource( text="Provider parameter value is required." )
+ String providerParameterValueIsRequiredError();
}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/BeanPropertyTopologyBuilder.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/BeanPropertyTopologyBuilder.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/BeanPropertyTopologyBuilder.java
new file mode 100644
index 0000000..e00e560
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/BeanPropertyTopologyBuilder.java
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.hadoop.gateway.topology.builder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hadoop.gateway.topology.Provider;
+import org.apache.hadoop.gateway.topology.Service;
+import org.apache.hadoop.gateway.topology.Topology;
+
+public class BeanPropertyTopologyBuilder implements TopologyBuilder {
+
+ private String name;
+ private List<Provider> providers;
+ private List<Service> services;
+
+ public BeanPropertyTopologyBuilder() {
+ providers = new ArrayList<Provider>();
+ services = new ArrayList<Service>();
+ }
+
+ public BeanPropertyTopologyBuilder name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public String name() {
+ return name;
+ }
+
+ public BeanPropertyTopologyBuilder addProvider(Provider provider) {
+ providers.add(provider);
+ return this;
+ }
+
+ public List<Provider> providers() {
+ return providers;
+ }
+
+ public BeanPropertyTopologyBuilder addService(Service service) {
+ services.add(service);
+ return this;
+ }
+
+ public List<Service> services() {
+ return services;
+ }
+
+ public Topology build() {
+ Topology topology = new Topology();
+ topology.setName(name);
+
+ for (Provider provider : providers) {
+ topology.addProvider(provider);
+ }
+
+ for (Service service : services) {
+ topology.addService(service);
+ }
+
+ return topology;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/PropertyTopologyBuilder.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/PropertyTopologyBuilder.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/PropertyTopologyBuilder.java
new file mode 100644
index 0000000..bfc83ba
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/PropertyTopologyBuilder.java
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.hadoop.gateway.topology.builder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hadoop.gateway.GatewayMessages;
+import org.apache.hadoop.gateway.GatewayResources;
+import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
+import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
+import org.apache.hadoop.gateway.topology.Topology;
+import org.apache.hadoop.gateway.topology.builder.property.Property;
+import org.apache.hadoop.gateway.topology.builder.property.interpreter.InterpretException;
+import org.apache.hadoop.gateway.topology.builder.property.interpreter.PropertyInterpreter;
+
+public class PropertyTopologyBuilder implements TopologyBuilder {
+
+ private static GatewayMessages log = MessagesFactory.get(GatewayMessages.class);
+ private static GatewayResources gatewayResources = ResourcesFactory.get(GatewayResources.class);
+
+ private List<Property> properties;
+
+ public PropertyTopologyBuilder() {
+ properties = new ArrayList<Property>();
+ }
+
+ public PropertyTopologyBuilder addProperty(Property property) {
+ properties.add(property);
+ return this;
+ }
+
+ public List<Property> properties() {
+ return properties;
+ }
+
+ public Topology build() {
+ Topology topology = new Topology();
+ PropertyInterpreter propertyInterpreter = new PropertyInterpreter(topology);
+ for (Property property : properties) {
+ try {
+ propertyInterpreter.interpret(property.getName(), property.getValue());
+ } catch (InterpretException ie) {
+ log.failedToInterpretProperty(property.getName(), ie);
+ throw new IllegalArgumentException(gatewayResources.wrongTopologyDataFormatError());
+ }
+ }
+ return topology;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/Property.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/Property.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/Property.java
new file mode 100644
index 0000000..7a38bfe
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/Property.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.hadoop.gateway.topology.builder.property;
+
+public class Property {
+
+ private String name;
+ private String value;
+
+ public Property(String name, String value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ public Property() {
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/AbstractInterpreter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/AbstractInterpreter.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/AbstractInterpreter.java
new file mode 100644
index 0000000..451060e
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/AbstractInterpreter.java
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.hadoop.gateway.topology.builder.property.interpreter;
+
+public abstract class AbstractInterpreter implements Interpreter {
+
+ public static final String DOT = ".";
+}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/GatewayPropertyInterpreter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/GatewayPropertyInterpreter.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/GatewayPropertyInterpreter.java
new file mode 100644
index 0000000..213aa60
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/GatewayPropertyInterpreter.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.hadoop.gateway.topology.builder.property.interpreter;
+
+import org.apache.hadoop.gateway.GatewayResources;
+import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
+import org.apache.hadoop.gateway.topology.Topology;
+
+public class GatewayPropertyInterpreter extends AbstractInterpreter {
+
+ private static final String AGGREGATOR_PROVIDER = "provider";
+
+ private static GatewayResources gatewayResources = ResourcesFactory.get(GatewayResources.class);
+
+ private Topology topology;
+
+ public GatewayPropertyInterpreter(Topology topology) {
+ if (topology == null) {
+ throw new IllegalArgumentException(gatewayResources.topologyIsRequiredError());
+ }
+ this.topology = topology;
+ }
+
+ @Override
+ public void interpret(String token, String value) throws InterpretException {
+ int firstDotPosition = token.indexOf(DOT);
+ if (firstDotPosition != -1) {
+ String aggregator = token.substring(0, firstDotPosition);
+ String nextToken = token.substring(firstDotPosition + 1);
+
+ if (AGGREGATOR_PROVIDER.equalsIgnoreCase(aggregator)) {
+ new ProviderPropertyInterpreter(topology).interpret(nextToken, value);
+ } else {
+ throw new InterpretException(gatewayResources.unsupportedPropertyTokenError(token));
+ }
+ } else {
+ throw new InterpretException(gatewayResources.unsupportedPropertyTokenError(token));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/InterpretException.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/InterpretException.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/InterpretException.java
new file mode 100644
index 0000000..212f7d0
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/InterpretException.java
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.hadoop.gateway.topology.builder.property.interpreter;
+
+public class InterpretException extends Exception {
+
+ public InterpretException() {
+ super();
+ }
+
+ public InterpretException(String message) {
+ super(message);
+ }
+
+ public InterpretException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InterpretException(Throwable cause) {
+ super(cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/Interpreter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/Interpreter.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/Interpreter.java
new file mode 100644
index 0000000..2378d53
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/Interpreter.java
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.hadoop.gateway.topology.builder.property.interpreter;
+
+public interface Interpreter {
+
+ void interpret(String token, String value) throws InterpretException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/PropertyInterpreter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/PropertyInterpreter.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/PropertyInterpreter.java
new file mode 100644
index 0000000..2339ec4
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/PropertyInterpreter.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.hadoop.gateway.topology.builder.property.interpreter;
+
+import org.apache.hadoop.gateway.GatewayResources;
+import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
+import org.apache.hadoop.gateway.topology.Topology;
+
+public class PropertyInterpreter extends AbstractInterpreter {
+
+ private static final String AGGREGATOR_TOPOLOGY = "topology";
+
+ private static GatewayResources gatewayResources = ResourcesFactory.get(GatewayResources.class);
+
+ private final Topology topology;
+
+ public PropertyInterpreter(Topology topology) {
+ if (topology == null) {
+ throw new IllegalArgumentException(gatewayResources.topologyIsRequiredError());
+ }
+ this.topology = topology;
+ }
+
+ @Override
+ public void interpret(String token, String value) throws InterpretException {
+ int firstDotPosition = token.indexOf(DOT);
+ if (firstDotPosition != -1) {
+ String aggregator = token.substring(0, firstDotPosition);
+ String nextToken = token.substring(firstDotPosition + 1);
+
+ if (AGGREGATOR_TOPOLOGY.equalsIgnoreCase(aggregator)) {
+ new TopologyPropertyInterpreter(topology).interpret(nextToken, value);
+ } else {
+ throw new InterpretException(gatewayResources.unsupportedPropertyTokenError(token));
+ }
+ } else {
+ throw new InterpretException(gatewayResources.unsupportedPropertyTokenError(token));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/ProviderParameterPropertyInterpreter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/ProviderParameterPropertyInterpreter.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/ProviderParameterPropertyInterpreter.java
new file mode 100644
index 0000000..be58b0d
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/ProviderParameterPropertyInterpreter.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.hadoop.gateway.topology.builder.property.interpreter;
+
+import org.apache.hadoop.gateway.GatewayResources;
+import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
+import org.apache.hadoop.gateway.topology.Provider;
+import org.apache.hadoop.gateway.topology.ProviderParam;
+
+public class ProviderParameterPropertyInterpreter extends AbstractInterpreter {
+
+ private static GatewayResources gatewayResources = ResourcesFactory.get(GatewayResources.class);
+
+ private Provider provider;
+
+ public ProviderParameterPropertyInterpreter(Provider provider) {
+ if (provider == null) {
+ throw new IllegalArgumentException(gatewayResources.providerIsRequiredError());
+ }
+ this.provider = provider;
+ }
+
+ @Override
+ public void interpret(String token, String value) throws InterpretException {
+ if (token == null || token.isEmpty()) {
+ throw new InterpretException(gatewayResources.providerParameterNameIsRequiredError());
+ }
+ if (value == null || value.isEmpty()) {
+ throw new InterpretException(gatewayResources.providerParameterValueIsRequiredError());
+ }
+ ProviderParam providerParam = new ProviderParam();
+ providerParam.setName(token);
+ providerParam.setValue(value);
+ provider.addParam(providerParam);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/ProviderPropertyInterpreter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/ProviderPropertyInterpreter.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/ProviderPropertyInterpreter.java
new file mode 100644
index 0000000..a62d913
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/ProviderPropertyInterpreter.java
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.hadoop.gateway.topology.builder.property.interpreter;
+
+import org.apache.hadoop.gateway.GatewayResources;
+import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
+import org.apache.hadoop.gateway.topology.Provider;
+import org.apache.hadoop.gateway.topology.Topology;
+
+public class ProviderPropertyInterpreter extends AbstractInterpreter {
+
+ private static final String PROVIDER_ENABLED = "enabled";
+ private static final String AGGREGATOR_PARAM = "param";
+
+ private static GatewayResources gatewayResources = ResourcesFactory.get(GatewayResources.class);
+
+ private Topology topology;
+
+ public ProviderPropertyInterpreter(Topology topology) {
+ if (topology == null) {
+ throw new IllegalArgumentException(gatewayResources.topologyIsRequiredError());
+ }
+ this.topology = topology;
+ }
+
+ @Override
+ public void interpret(String token, String value) throws InterpretException {
+ int dotPosition = token.indexOf(DOT);
+ if (dotPosition == -1) {
+ throw new InterpretException(gatewayResources.unsupportedPropertyTokenError(token));
+ }
+ String providerRole = token.substring(0, dotPosition);
+ if (providerRole != null && providerRole.isEmpty()) {
+ providerRole = null;
+ }
+ String nextToken = token.substring(dotPosition + 1);
+
+ dotPosition = nextToken.indexOf(DOT);
+ if (dotPosition == -1) {
+ throw new InterpretException(gatewayResources.unsupportedPropertyTokenError(token));
+ }
+ String providerName = nextToken.substring(0, dotPosition);
+ if (providerName != null && providerName.isEmpty()) {
+ providerName = null;
+ }
+ nextToken = nextToken.substring(dotPosition + 1);
+
+ Provider provider = topology.getProvider(providerRole, providerName);
+ if (provider == null) {
+ provider = new Provider();
+ provider.setName(providerName);
+ provider.setRole(providerRole);
+ topology.addProvider(provider);
+ }
+
+ if (PROVIDER_ENABLED.equalsIgnoreCase(nextToken)) {
+ provider.setEnabled(Boolean.valueOf(value));
+ } else {
+ dotPosition = nextToken.indexOf(DOT);
+ if (dotPosition != -1) {
+ String aggregator = nextToken.substring(0, dotPosition);
+ nextToken = nextToken.substring(dotPosition + 1);
+
+ if (AGGREGATOR_PARAM.equalsIgnoreCase(aggregator)) {
+ new ProviderParameterPropertyInterpreter(provider).interpret(nextToken, value);
+ } else {
+ throw new InterpretException(gatewayResources.unsupportedPropertyTokenError(token));
+ }
+ } else {
+ throw new InterpretException(gatewayResources.unsupportedPropertyTokenError(token));
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/ServicePropertyInterpreter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/ServicePropertyInterpreter.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/ServicePropertyInterpreter.java
new file mode 100644
index 0000000..b416d78
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/ServicePropertyInterpreter.java
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.hadoop.gateway.topology.builder.property.interpreter;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.hadoop.gateway.GatewayResources;
+import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
+import org.apache.hadoop.gateway.topology.Service;
+import org.apache.hadoop.gateway.topology.Topology;
+
+public class ServicePropertyInterpreter extends AbstractInterpreter {
+
+ private static final String SERVICE_URL = "url";
+
+ private static GatewayResources gatewayResources = ResourcesFactory.get(GatewayResources.class);
+
+ private Topology topology;
+
+ public ServicePropertyInterpreter(Topology topology) {
+ if (topology == null) {
+ throw new IllegalArgumentException(gatewayResources.topologyIsRequiredError());
+ }
+ this.topology = topology;
+ }
+
+ public void interpret(String token, String value) throws InterpretException {
+ int dotPosition = token.indexOf(DOT);
+ if (dotPosition == -1) {
+ throw new InterpretException(gatewayResources.unsupportedPropertyTokenError(token));
+ }
+ String serviceRole = token.substring(0, dotPosition);
+ if (serviceRole != null && serviceRole.isEmpty()) {
+ serviceRole = null;
+ }
+ String nextToken = token.substring(dotPosition + 1);
+
+ dotPosition = nextToken.indexOf(DOT);
+ if (dotPosition == -1) {
+ throw new InterpretException(gatewayResources.unsupportedPropertyTokenError(token));
+ }
+ String serviceName = nextToken.substring(0, dotPosition);
+ if (serviceName != null && serviceName.isEmpty()) {
+ serviceName = null;
+ }
+ nextToken = nextToken.substring(dotPosition + 1);
+
+ Service service = topology.getService(serviceRole, serviceName);
+ if (service == null) {
+ service = new Service();
+ service.setName(serviceName);
+ service.setRole(serviceRole);
+ topology.addService(service);
+ }
+
+ if (SERVICE_URL.equalsIgnoreCase(nextToken)) {
+ try {
+ service.setUrl(new URL(value));
+ } catch (MalformedURLException mue) {
+ throw new InterpretException(mue);
+ }
+ } else {
+ throw new InterpretException(gatewayResources.unsupportedPropertyTokenError(token));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/TopologyPropertyInterpreter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/TopologyPropertyInterpreter.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/TopologyPropertyInterpreter.java
new file mode 100644
index 0000000..9b61ead
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/TopologyPropertyInterpreter.java
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.hadoop.gateway.topology.builder.property.interpreter;
+
+import org.apache.hadoop.gateway.GatewayResources;
+import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
+import org.apache.hadoop.gateway.topology.Topology;
+
+public class TopologyPropertyInterpreter extends AbstractInterpreter {
+
+ private static final String TOPOLOGY_NAME = "name";
+ private static final String AGGREGATOR_GATEWAY = "gateway";
+ private static final String AGGREGATOR_SERVICE = "service";
+
+ private static GatewayResources gatewayResources = ResourcesFactory.get(GatewayResources.class);
+
+ private Topology topology;
+
+ public TopologyPropertyInterpreter(Topology topology) {
+ if (topology == null) {
+ throw new IllegalArgumentException(gatewayResources.topologyIsRequiredError());
+ }
+ this.topology = topology;
+ }
+
+ @Override
+ public void interpret(String token, String value) throws InterpretException {
+ if (TOPOLOGY_NAME.equalsIgnoreCase(token)) {
+ topology.setName(value);
+ } else {
+ int firstDotPosition = token.indexOf(DOT);
+ if (firstDotPosition != -1) {
+ String aggregator = token.substring(0, firstDotPosition);
+ String nextToken = token.substring(firstDotPosition + 1);
+
+ if (AGGREGATOR_GATEWAY.equals(aggregator)) {
+ new GatewayPropertyInterpreter(topology).interpret(nextToken, value);
+ } else if (AGGREGATOR_SERVICE.equals(aggregator)) {
+ new ServicePropertyInterpreter(topology).interpret(nextToken, value);
+ } else {
+ throw new InterpretException(gatewayResources.unsupportedPropertyTokenError(token));
+ }
+ } else {
+ throw new InterpretException(gatewayResources.unsupportedPropertyTokenError(token));
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/file/FileTopologyProvider.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/file/FileTopologyProvider.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/file/FileTopologyProvider.java
index 744784a..e199c51 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/file/FileTopologyProvider.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/file/FileTopologyProvider.java
@@ -35,7 +35,9 @@ import org.apache.hadoop.gateway.topology.TopologyEvent;
import org.apache.hadoop.gateway.topology.TopologyListener;
import org.apache.hadoop.gateway.topology.TopologyMonitor;
import org.apache.hadoop.gateway.topology.TopologyProvider;
-import org.apache.hadoop.gateway.topology.xml.XmlTopologyRules;
+import org.apache.hadoop.gateway.topology.builder.TopologyBuilder;
+import org.apache.hadoop.gateway.topology.xml.AmbariFormatXmlTopologyRules;
+import org.apache.hadoop.gateway.topology.xml.KnoxFormatXmlTopologyRules;
import org.xml.sax.SAXException;
import java.io.File;
@@ -56,7 +58,7 @@ import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
public class FileTopologyProvider implements TopologyProvider, TopologyMonitor, FileListener {
private static GatewayMessages log = MessagesFactory.get( GatewayMessages.class );
- private static DigesterLoader digesterLoader = newLoader( new XmlTopologyRules() );
+ private static DigesterLoader digesterLoader = newLoader( new KnoxFormatXmlTopologyRules(), new AmbariFormatXmlTopologyRules() );
private DefaultFileMonitor monitor;
private FileObject directory;
@@ -81,7 +83,8 @@ public class FileTopologyProvider implements TopologyProvider, TopologyMonitor,
log.loadingTopologyFile( file.getName().getFriendlyURI() );
Digester digester = digesterLoader.newDigester();
FileContent content = file.getContent();
- Topology topology = digester.parse( content.getInputStream() );
+ TopologyBuilder topologyBuilder = digester.parse( content.getInputStream() );
+ Topology topology = topologyBuilder.build();
topology.setName( FilenameUtils.removeExtension( file.getName().getBaseName() ) );
topology.setTimestamp( content.getLastModifiedTime() );
return topology;
@@ -100,6 +103,9 @@ public class FileTopologyProvider implements TopologyProvider, TopologyMonitor,
} catch( SAXException e ) {
// Maybe it makes sense to throw exception
log.failedToLoadTopology( file.getName().getFriendlyURI(), e );
+ } catch ( Exception e ) {
+ // Maybe it makes sense to throw exception
+ log.failedToLoadTopology( file.getName().getFriendlyURI(), e );
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/xml/AmbariFormatXmlTopologyRules.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/xml/AmbariFormatXmlTopologyRules.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/xml/AmbariFormatXmlTopologyRules.java
new file mode 100644
index 0000000..0b34740
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/xml/AmbariFormatXmlTopologyRules.java
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.hadoop.gateway.topology.xml;
+
+import org.apache.commons.digester3.binder.AbstractRulesModule;
+import org.apache.hadoop.gateway.topology.builder.PropertyTopologyBuilder;
+import org.apache.hadoop.gateway.topology.builder.property.Property;
+
+public class AmbariFormatXmlTopologyRules extends AbstractRulesModule {
+
+ private static final String ROOT_TAG = "configuration";
+ private static final String PROPERTY_TAG = "property";
+ private static final String NAME_TAG = "name";
+ private static final String VALUE_TAG = "value";
+
+ @Override
+ protected void configure() {
+ forPattern(ROOT_TAG).createObject().ofType(PropertyTopologyBuilder.class);
+ forPattern(ROOT_TAG + "/" + PROPERTY_TAG).createObject().ofType(Property.class).then().setNext("addProperty");
+ forPattern(ROOT_TAG + "/" + PROPERTY_TAG + "/" + NAME_TAG).setBeanProperty();
+ forPattern(ROOT_TAG + "/" + PROPERTY_TAG + "/" + VALUE_TAG).setBeanProperty();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/xml/KnoxFormatXmlTopologyRules.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/xml/KnoxFormatXmlTopologyRules.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/xml/KnoxFormatXmlTopologyRules.java
new file mode 100644
index 0000000..63a35be
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/xml/KnoxFormatXmlTopologyRules.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.hadoop.gateway.topology.xml;
+
+import org.apache.commons.digester3.binder.AbstractRulesModule;
+import org.apache.hadoop.gateway.topology.Provider;
+import org.apache.hadoop.gateway.topology.ProviderParam;
+import org.apache.hadoop.gateway.topology.Service;
+import org.apache.hadoop.gateway.topology.builder.BeanPropertyTopologyBuilder;
+
+public class KnoxFormatXmlTopologyRules extends AbstractRulesModule {
+
+ private static final String ROOT_TAG = "topology";
+ private static final String NAME_TAG = "name";
+ private static final String VERSION_TAG = "version";
+ private static final String SERVICE_TAG = "service";
+ private static final String ROLE_TAG = "role";
+ private static final String URL_TAG = "url";
+ private static final String PROVIDER_TAG = "gateway/provider";
+ private static final String ENABLED_TAG = "enabled";
+ private static final String PARAM_TAG = "param";
+ private static final String VALUE_TAG = "value";
+
+ @Override
+ protected void configure() {
+ forPattern( ROOT_TAG ).createObject().ofType( BeanPropertyTopologyBuilder.class );
+ forPattern( ROOT_TAG + "/" + NAME_TAG ).callMethod("name").usingElementBodyAsArgument();
+ forPattern( ROOT_TAG + "/" + VERSION_TAG ).callMethod("version").usingElementBodyAsArgument();
+ forPattern( ROOT_TAG + "/" + SERVICE_TAG ).createObject().ofType( Service.class ).then().setNext( "addService" );
+ forPattern( ROOT_TAG + "/" + SERVICE_TAG + "/" + ROLE_TAG ).setBeanProperty();
+ forPattern( ROOT_TAG + "/" + SERVICE_TAG + "/" + URL_TAG ).setBeanProperty();
+ forPattern( ROOT_TAG + "/" + PROVIDER_TAG ).createObject().ofType( Provider.class ).then().setNext( "addProvider" );
+ forPattern( ROOT_TAG + "/" + PROVIDER_TAG + "/" + ROLE_TAG ).setBeanProperty();
+ forPattern( ROOT_TAG + "/" + PROVIDER_TAG + "/" + ENABLED_TAG ).setBeanProperty();
+ forPattern( ROOT_TAG + "/" + PROVIDER_TAG + "/" + NAME_TAG ).setBeanProperty();
+ forPattern( ROOT_TAG + "/" + PROVIDER_TAG + "/" + PARAM_TAG ).createObject().ofType( ProviderParam.class ).then().setNext( "addParam" );
+ forPattern( ROOT_TAG + "/" + PROVIDER_TAG + "/" + PARAM_TAG + "/" + NAME_TAG ).setBeanProperty();
+ forPattern( ROOT_TAG + "/" + PROVIDER_TAG + "/" + PARAM_TAG + "/" + VALUE_TAG ).setBeanProperty();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/xml/XmlTopologyRules.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/xml/XmlTopologyRules.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/xml/XmlTopologyRules.java
deleted file mode 100644
index c6913d3..0000000
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/xml/XmlTopologyRules.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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.
- */
-package org.apache.hadoop.gateway.topology.xml;
-
-import org.apache.commons.digester3.binder.AbstractRulesModule;
-import org.apache.hadoop.gateway.topology.Provider;
-import org.apache.hadoop.gateway.topology.ProviderParam;
-import org.apache.hadoop.gateway.topology.Service;
-import org.apache.hadoop.gateway.topology.Topology;
-
-public class XmlTopologyRules extends AbstractRulesModule {
-
- private static final String ROOT_TAG = "topology";
- private static final String NAME_TAG = "name";
- private static final String VERSION_TAG = "version";
- private static final String SERVICE_TAG = "service";
- private static final String ROLE_TAG = "role";
- private static final String URL_TAG = "url";
- private static final String PROVIDER_TAG = "gateway/provider";
- private static final String ENABLED_TAG = "enabled";
- private static final String PARAM_TAG = "param";
- private static final String VALUE_TAG = "value";
-
- @Override
- protected void configure() {
- forPattern( ROOT_TAG ).createObject().ofType( Topology.class );
- forPattern( ROOT_TAG + "/" + NAME_TAG ).setBeanProperty();
- forPattern( ROOT_TAG + "/" + VERSION_TAG ).setBeanProperty();
- forPattern( ROOT_TAG + "/" + SERVICE_TAG ).createObject().ofType( Service.class ).then().setNext( "addService" );
- forPattern( ROOT_TAG + "/" + SERVICE_TAG + "/" + ROLE_TAG ).setBeanProperty();
- forPattern( ROOT_TAG + "/" + SERVICE_TAG + "/" + URL_TAG ).setBeanProperty();
- forPattern( ROOT_TAG + "/" + PROVIDER_TAG ).createObject().ofType( Provider.class ).then().setNext( "addProvider" );
- forPattern( ROOT_TAG + "/" + PROVIDER_TAG + "/" + ROLE_TAG ).setBeanProperty();
- forPattern( ROOT_TAG + "/" + PROVIDER_TAG + "/" + ENABLED_TAG ).setBeanProperty();
- forPattern( ROOT_TAG + "/" + PROVIDER_TAG + "/" + NAME_TAG ).setBeanProperty();
- forPattern( ROOT_TAG + "/" + PROVIDER_TAG + "/" + PARAM_TAG ).createObject().ofType( ProviderParam.class ).then().setNext( "addParam" );
- forPattern( ROOT_TAG + "/" + PROVIDER_TAG + "/" + PARAM_TAG + "/" + NAME_TAG ).setBeanProperty();
- forPattern( ROOT_TAG + "/" + PROVIDER_TAG + "/" + PARAM_TAG + "/" + VALUE_TAG ).setBeanProperty();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/test/java/org/apache/hadoop/gateway/topology/builder/PropertyTopologyBuilderTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/hadoop/gateway/topology/builder/PropertyTopologyBuilderTest.java b/gateway-server/src/test/java/org/apache/hadoop/gateway/topology/builder/PropertyTopologyBuilderTest.java
new file mode 100644
index 0000000..35dbcbe
--- /dev/null
+++ b/gateway-server/src/test/java/org/apache/hadoop/gateway/topology/builder/PropertyTopologyBuilderTest.java
@@ -0,0 +1,155 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.hadoop.gateway.topology.builder;
+
+import org.apache.hadoop.gateway.topology.Topology;
+import org.apache.hadoop.gateway.topology.builder.property.Property;
+import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+
+public class PropertyTopologyBuilderTest {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBuildFailedForWrongProperty() {
+ PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
+ propertyTopologyBuilder.addProperty(new Property("miss_prop", "value"));
+ propertyTopologyBuilder.build();
+ }
+
+ @Test
+ public void testBuildSuccessfulForTopologyProperty() {
+ PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
+ propertyTopologyBuilder.addProperty(new Property("topology.name", "topology"));
+ Topology topology = propertyTopologyBuilder.build();
+
+ assertThat(topology, notNullValue());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBuildFailedForWrongTopologyProperty() {
+ PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
+ propertyTopologyBuilder.addProperty(new Property("topology.miss_prop", "value"));
+ propertyTopologyBuilder.build();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBuildFailedForWrongGatewayToken() {
+ PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
+ propertyTopologyBuilder.addProperty(new Property("topology.gateway.miss_prop", "value"));
+ propertyTopologyBuilder.build();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBuildFailedForWrongProviderToken1() {
+ PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
+ propertyTopologyBuilder.addProperty(new Property("topology.gateway.provider", "value"));
+ propertyTopologyBuilder.build();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBuildFailedForWrongProviderToken2() {
+ PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
+ propertyTopologyBuilder.addProperty(new Property("topology.gateway.provider.authentication", "value"));
+ propertyTopologyBuilder.build();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBuildFailedForWrongProviderToken3() {
+ PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
+ propertyTopologyBuilder.addProperty(new Property("topology.gateway.provider.authentication.ShiroProvider", "value"));
+ propertyTopologyBuilder.build();
+ }
+
+ @Test
+ public void testBuildSuccessfulForProviderProperty() {
+ PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
+ propertyTopologyBuilder.addProperty(new Property("topology.gateway.provider.authentication.ShiroProvider.enabled", "value"));
+ Topology topology = propertyTopologyBuilder.build();
+
+ assertThat(topology, notNullValue());
+ assertThat(topology.getProviders().size(), is(1));
+ assertThat(topology.getProviders().iterator().next().isEnabled(), is(false));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBuildFailedForWrongProviderProperty() {
+ PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
+ propertyTopologyBuilder.addProperty(new Property("topology.gateway.provider.authentication.ShiroProvider.miss_prop", "value"));
+ propertyTopologyBuilder.build();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBuildFailedForWrongProviderParamToken1() {
+ PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
+ propertyTopologyBuilder.addProperty(new Property("topology.gateway.provider.authentication.ShiroProvider.param", "value"));
+ propertyTopologyBuilder.build();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBuildFailedForEmptyProviderParamName() {
+ PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
+ propertyTopologyBuilder.addProperty(new Property("topology.gateway.provider.authentication.ShiroProvider.param.", "value"));
+ propertyTopologyBuilder.build();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBuildFailedForEmptyProviderParamValue() {
+ PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
+ propertyTopologyBuilder.addProperty(new Property("topology.gateway.provider.authentication.ShiroProvider.param.name1", ""));
+ propertyTopologyBuilder.build();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBuildFailedForWrongServiceToken1() {
+ PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
+ propertyTopologyBuilder.addProperty(new Property("topology.gateway.service", "value"));
+ propertyTopologyBuilder.build();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBuildFailedForWrongServiceToken2() {
+ PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
+ propertyTopologyBuilder.addProperty(new Property("topology.gateway.service.NAMENODE", "value"));
+ propertyTopologyBuilder.build();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBuildFailedForWrongServiceToken3() {
+ PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
+ propertyTopologyBuilder.addProperty(new Property("topology.gateway.service.NAMENODE.", "value"));
+ propertyTopologyBuilder.build();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBuildSuccessfulForServiceProperty() {
+ PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
+ propertyTopologyBuilder.addProperty(new Property("topology.gateway.service.NAMENODE..url", "http://host:50070/webhdfs/v1"));
+ Topology topology = propertyTopologyBuilder.build();
+
+ assertThat(topology, notNullValue());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBuildFailedForWrongServiceProperty() {
+ PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
+ propertyTopologyBuilder.addProperty(new Property("topology.gateway.service.NAMENODE..miss_prop", "value"));
+ propertyTopologyBuilder.build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/test/java/org/apache/hadoop/gateway/topology/xml/TopologyRulesModuleTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/hadoop/gateway/topology/xml/TopologyRulesModuleTest.java b/gateway-server/src/test/java/org/apache/hadoop/gateway/topology/xml/TopologyRulesModuleTest.java
index 74ce10b..fd04b61 100644
--- a/gateway-server/src/test/java/org/apache/hadoop/gateway/topology/xml/TopologyRulesModuleTest.java
+++ b/gateway-server/src/test/java/org/apache/hadoop/gateway/topology/xml/TopologyRulesModuleTest.java
@@ -22,6 +22,7 @@ import org.apache.commons.digester3.binder.DigesterLoader;
import org.apache.hadoop.gateway.topology.Provider;
import org.apache.hadoop.gateway.topology.Service;
import org.apache.hadoop.gateway.topology.Topology;
+import org.apache.hadoop.gateway.topology.builder.TopologyBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -33,6 +34,7 @@ import java.net.URL;
import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
@@ -42,7 +44,7 @@ public class TopologyRulesModuleTest {
@Before
public void setUp() throws Exception {
- loader = newLoader( new XmlTopologyRules() );
+ loader = newLoader( new KnoxFormatXmlTopologyRules(), new AmbariFormatXmlTopologyRules() );
}
@After
@@ -50,13 +52,14 @@ public class TopologyRulesModuleTest {
}
@Test
- public void testParseSimpleTopologyXml() throws IOException, SAXException {
+ public void testParseSimpleTopologyXmlInKnoxFormat() throws IOException, SAXException {
Digester digester = loader.newDigester();
- String name = "org/apache/hadoop/gateway/topology/xml/simple-topology.xml";
+ String name = "org/apache/hadoop/gateway/topology/xml/simple-topology-knox-format.xml";
URL url = ClassLoader.getSystemResource( name );
assertThat( "Failed to find URL for resource " + name, url, notNullValue() );
File file = new File( url.getFile() );
- Topology topology = digester.parse( url );
+ TopologyBuilder topologyBuilder = digester.parse( url );
+ Topology topology = topologyBuilder.build();
assertThat( "Failed to parse resource " + name, topology, notNullValue() );
topology.setTimestamp( file.lastModified() );
@@ -76,4 +79,62 @@ public class TopologyRulesModuleTest {
assertThat( provider.getParams().size(), is(5));
}
+ @Test
+ public void testParseSimpleTopologyXmlInHadoopFormat() throws IOException, SAXException {
+ Digester digester = loader.newDigester();
+ String name = "org/apache/hadoop/gateway/topology/xml/simple-topology-ambari-format.xml";
+ URL url = ClassLoader.getSystemResource( name );
+ assertThat( "Failed to find URL for resource " + name, url, notNullValue() );
+ File file = new File( url.getFile() );
+ TopologyBuilder topologyBuilder = digester.parse( url );
+ Topology topology = topologyBuilder.build();
+ assertThat( "Failed to parse resource " + name, topology, notNullValue() );
+ topology.setTimestamp( file.lastModified() );
+
+ assertThat( topology.getName(), is( "topology2" ) );
+ assertThat( topology.getTimestamp(), is( file.lastModified() ) );
+ assertThat( topology.getServices().size(), is( 4 ) );
+ assertThat( topology.getProviders().size(), is( 2 ) );
+
+ Service namenodeService = topology.getService( "NAMENODE", null );
+ assertThat( namenodeService, notNullValue() );
+ assertThat( namenodeService.getRole(), is( "NAMENODE" ) );
+ assertThat( namenodeService.getName(), nullValue() );
+ assertThat( namenodeService.getUrl(), is( new URL( "http://host:50070/webhdfs/v1" ) ) );
+
+ Service templetonService = topology.getService( "TEMPLETON", null );
+ assertThat( templetonService, notNullValue() );
+ assertThat( templetonService.getRole(), is( "TEMPLETON" ) );
+ assertThat( templetonService.getName(), nullValue() );
+ assertThat( templetonService.getUrl(), is( new URL( "http://host:50111/templeton/v1" ) ) );
+
+ Service oozieService = topology.getService( "OOZIE", null );
+ assertThat( oozieService, notNullValue() );
+ assertThat( oozieService.getRole(), is( "OOZIE" ) );
+ assertThat( oozieService.getName(), nullValue() );
+ assertThat( oozieService.getUrl(), is( new URL( "http://host:11000/oozie" ) ) );
+
+ Service hiveService = topology.getService( "HIVE", null );
+ assertThat( hiveService, notNullValue() );
+ assertThat( hiveService.getRole(), is( "HIVE" ) );
+ assertThat( hiveService.getName(), nullValue() );
+ assertThat( hiveService.getUrl(), is( new URL( "http://host:10000" ) ) );
+
+ Provider authenticationProvider = topology.getProvider( "authentication", "ShiroProvider" );
+ assertThat( authenticationProvider, notNullValue() );
+ assertThat( authenticationProvider.isEnabled(), is( true ) );
+ assertThat( authenticationProvider.getRole(), is( "authentication" ) );
+ assertThat( authenticationProvider.getName(), is( "ShiroProvider" ) );
+ assertThat( authenticationProvider.getParams().size(), is( 5 ) );
+ assertThat( authenticationProvider.getParams().get("main.ldapRealm.contextFactory.url"), is( "ldap://localhost:33389" ) );
+
+ Provider identityAssertionProvider = topology.getProvider( "identity-assertion", "Pseudo" );
+ assertThat( identityAssertionProvider, notNullValue() );
+ assertThat( identityAssertionProvider.isEnabled(), is( false ) );
+ assertThat( identityAssertionProvider.getRole(), is( "identity-assertion" ) );
+ assertThat( identityAssertionProvider.getName(), is( "Pseudo" ) );
+ assertThat( identityAssertionProvider.getParams().size(), is( 2 ) );
+ assertThat( identityAssertionProvider.getParams().get("name"), is( "user.name" ) );
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/simple-topology-ambari-format.xml
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/simple-topology-ambari-format.xml b/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/simple-topology-ambari-format.xml
new file mode 100644
index 0000000..a112b80
--- /dev/null
+++ b/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/simple-topology-ambari-format.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ 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.
+-->
+<configuration>
+ <property>
+ <name>topology.name</name>
+ <value>topology2</value>
+ </property>
+ <property>
+ <name>topology.gateway.provider.authentication.ShiroProvider.enabled</name>
+ <value>true</value>
+ </property>
+ <property>
+ <name>topology.gateway.provider.authentication.ShiroProvider.param.main.ldapRealm</name>
+ <value>org.apache.shiro.realm.ldap.JndiLdapRealm</value>
+ </property>
+ <property>
+ <name>topology.gateway.provider.authentication.ShiroProvider.param.main.ldapRealm.userDnTemplate</name>
+ <value>uid={0},ou=people,dc=hadoop,dc=apache,dc=org</value>
+ </property>
+ <property>
+ <name>topology.gateway.provider.authentication.ShiroProvider.param.main.ldapRealm.contextFactory.url</name>
+ <value>ldap://localhost:33389</value>
+ </property>
+ <property>
+ <name>topology.gateway.provider.authentication.ShiroProvider.param.main.ldapRealm.contextFactory.authenticationMechanism</name>
+ <value>simple</value>
+ </property>
+ <property>
+ <name>topology.gateway.provider.authentication.ShiroProvider.param.urls./**</name>
+ <value>authcBasic</value>
+ </property>
+ <property>
+ <name>topology.gateway.provider.identity-assertion.Pseudo.enabled</name>
+ <value>false</value>
+ </property>
+ <property>
+ <name>topology.gateway.provider.identity-assertion.Pseudo.param.name</name>
+ <value>user.name</value>
+ </property>
+ <property>
+ <name>topology.gateway.provider.identity-assertion.Pseudo.param.principal.mapping</name>
+ <value>hdfs=lmccay;kminder=admin</value>
+ </property>
+ <property>
+ <name>topology.service.NAMENODE..url</name>
+ <value>http://host:50070/webhdfs/v1</value>
+ </property>
+ <property>
+ <name>topology.service.TEMPLETON..url</name>
+ <value>http://host:50111/templeton/v1</value>
+ </property>
+ <property>
+ <name>topology.service.OOZIE..url</name>
+ <value>http://host:11000/oozie</value>
+ </property>
+ <property>
+ <name>topology.service.HIVE..url</name>
+ <value>http://host:10000</value>
+ </property>
+</configuration>
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/simple-topology-knox-format.xml
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/simple-topology-knox-format.xml b/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/simple-topology-knox-format.xml
new file mode 100644
index 0000000..09bb39c
--- /dev/null
+++ b/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/simple-topology-knox-format.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ 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.
+-->
+<topology>
+ <name>topology</name>
+ <!--
+ <version>1.2.3</version>
+ -->
+ <gateway>
+ <provider>
+ <role>authentication</role>
+ <enabled>true</enabled>
+ <name>ShiroSecurity</name>
+ <param>
+ <name>main.ldapRealm</name>
+ <value>org.apache.shiro.realm.ldap.JndiLdapRealm</value>
+ </param>
+ <param>
+ <name>main.ldapRealm.userDnTemplate</name>
+ <value>uid={0},ou=people,dc=hadoop,dc=apache,dc=org</value>
+ </param>
+ <param>
+ <name>main.ldapRealm.contextFactory.url</name>
+ <value>ldap://localhost:33389</value>
+ </param>
+ <param>
+ <name>main.ldapRealm.contextFactory.authenticationMechanism</name>
+ <value>simple</value>
+ </param>
+ <param>
+ <name>urls./**</name>
+ <value>authcBasic</value>
+ </param>
+ </provider>
+ <provider>
+ <role>identity-assertion</role>
+ <enabled>true</enabled>
+ <name>Pseudo</name>
+ <param>
+ <name>name</name>
+ <value>user.name</value>
+ </param>
+ <param>
+ <name>principal.mapping</name>
+ <value>hdfs=lmccay;kminder=admin</value>
+ </param>
+ </provider>
+ </gateway>
+
+ <service>
+ <role>NAMENODE</role>
+ <url>http://host:80/webhdfs/v1</url>
+ </service>
+</topology>
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/simple-topology.xml
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/simple-topology.xml b/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/simple-topology.xml
deleted file mode 100644
index 09bb39c..0000000
--- a/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/simple-topology.xml
+++ /dev/null
@@ -1,68 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You 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
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- 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.
--->
-<topology>
- <name>topology</name>
- <!--
- <version>1.2.3</version>
- -->
- <gateway>
- <provider>
- <role>authentication</role>
- <enabled>true</enabled>
- <name>ShiroSecurity</name>
- <param>
- <name>main.ldapRealm</name>
- <value>org.apache.shiro.realm.ldap.JndiLdapRealm</value>
- </param>
- <param>
- <name>main.ldapRealm.userDnTemplate</name>
- <value>uid={0},ou=people,dc=hadoop,dc=apache,dc=org</value>
- </param>
- <param>
- <name>main.ldapRealm.contextFactory.url</name>
- <value>ldap://localhost:33389</value>
- </param>
- <param>
- <name>main.ldapRealm.contextFactory.authenticationMechanism</name>
- <value>simple</value>
- </param>
- <param>
- <name>urls./**</name>
- <value>authcBasic</value>
- </param>
- </provider>
- <provider>
- <role>identity-assertion</role>
- <enabled>true</enabled>
- <name>Pseudo</name>
- <param>
- <name>name</name>
- <value>user.name</value>
- </param>
- <param>
- <name>principal.mapping</name>
- <value>hdfs=lmccay;kminder=admin</value>
- </param>
- </provider>
- </gateway>
-
- <service>
- <role>NAMENODE</role>
- <url>http://host:80/webhdfs/v1</url>
- </service>
-</topology>
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Topology.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Topology.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Topology.java
index 2fb2595..9dd3514 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Topology.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Topology.java
@@ -30,6 +30,7 @@ public class Topology {
private List<Provider> providerList = new ArrayList<Provider>();
private Map<String,Map<String,Provider>> providerMap = new HashMap<String,Map<String,Provider>>();
private List<Service> services = new ArrayList<Service>();
+ private Map<String, Map<String, Service>> serviceMap = new HashMap<String, Map<String, Service>>();
public String getName() {
return name;
@@ -51,8 +52,27 @@ public class Topology {
return services;
}
+ public Service getService( String role, String name ) {
+ Service service = null;
+ Map<String, Service> nameMap = serviceMap.get( role );
+ if( nameMap != null) {
+ service = nameMap.get( name );
+ if ( service == null && !nameMap.values().isEmpty() ) {
+ service = (Service) nameMap.values().toArray()[0];
+ }
+ }
+ return service;
+ }
+
public void addService( Service service ) {
services.add( service );
+ String role = service.getRole();
+ Map<String, Service> nameMap = serviceMap.get( role );
+ if( nameMap == null ) {
+ nameMap = new HashMap<String, Service>();
+ serviceMap.put( role, nameMap );
+ }
+ nameMap.put( service.getName(), service );
}
public Collection<Provider> getProviders() {
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/874d6fed/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/builder/TopologyBuilder.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/builder/TopologyBuilder.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/builder/TopologyBuilder.java
new file mode 100644
index 0000000..4572607
--- /dev/null
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/builder/TopologyBuilder.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.hadoop.gateway.topology.builder;
+
+import org.apache.hadoop.gateway.topology.Topology;
+
+public interface TopologyBuilder {
+
+ Topology build();
+}