You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by pz...@apache.org on 2018/07/19 19:14:04 UTC
[2/4] knox git commit: KNOX-1386 - NiFi service discovery uses
properties which may have templates as values
KNOX-1386 - NiFi service discovery uses properties which may have templates as values
Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/9482351e
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/9482351e
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/9482351e
Branch: refs/heads/master
Commit: 9482351e75a34dc692ad7fbfb09e8711a6f8dc70
Parents: ed24bcd
Author: Phil Zampino <pz...@apache.org>
Authored: Wed Jul 11 17:24:44 2018 -0400
Committer: Phil Zampino <pz...@apache.org>
Committed: Thu Jul 12 08:58:24 2018 -0400
----------------------------------------------------------------------
.../ambari/AmbariServiceDiscovery.java | 5 +-
.../discovery/ambari/NiFiURLCreator.java | 84 ++++++++++++++++++++
....topology.discovery.ambari.ServiceURLCreator | 1 +
.../ambari-service-discovery-url-mappings.xml | 55 -------------
4 files changed, 89 insertions(+), 56 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/knox/blob/9482351e/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscovery.java b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscovery.java
index 821dc0e..04f3d58 100644
--- a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscovery.java
+++ b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscovery.java
@@ -283,7 +283,10 @@ class AmbariServiceDiscovery implements ServiceDiscovery {
if (!componentHostNames.containsKey(componentName)) {
componentHostNames.put(componentName, new ArrayList<>());
}
- componentHostNames.get(componentName).add(hostName);
+ // Avoid duplicates
+ if (!componentHostNames.get(componentName).contains(hostName)) {
+ componentHostNames.get(componentName).add(hostName);
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/knox/blob/9482351e/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/NiFiURLCreator.java
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/NiFiURLCreator.java b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/NiFiURLCreator.java
new file mode 100644
index 0000000..dacd883
--- /dev/null
+++ b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/NiFiURLCreator.java
@@ -0,0 +1,84 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.knox.gateway.topology.discovery.ambari;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class NiFiURLCreator implements ServiceURLCreator {
+
+ static final String COMPONENT_NAME = "NIFI_MASTER";
+ static final String CONFIG_SERVICE = "NIFI";
+ static final String CONFIG_TYPE = "nifi-ambari-config";
+ static final String CONFIG_TYPE_SSL = "nifi-ambari-ssl-config";
+
+ static final String SSL_ENABLED_PROPERTY = "nifi.node.ssl.isenabled";
+
+ static final String SCHEME_HTTP = "http";
+ static final String SCHEME_HTTPS = "https";
+
+ static final String PORT_PROPERTY = "nifi.node.port";
+ static final String SSL_PORT_PROPERTY = "nifi.node.ssl.port";
+
+
+ private AmbariCluster cluster = null;
+
+ @Override
+ public String getTargetService() {
+ return CONFIG_SERVICE ;
+ }
+
+ @Override
+ public void init(AmbariCluster cluster) {
+ this.cluster = cluster;
+ }
+
+ @Override
+ public List<String> create(String service, Map<String, String> serviceParams) {
+ List<String> urls = new ArrayList<>();
+
+ AmbariComponent component = cluster.getComponent(COMPONENT_NAME);
+ if (component != null) {
+ AmbariCluster.ServiceConfiguration sc = cluster.getServiceConfiguration(service, CONFIG_TYPE);
+ if (sc != null) {
+ Map<String, String> configProps = sc.getProperties();
+
+ boolean isSSLEnabled = isSSLEnabled(service);
+ String scheme = isSSLEnabled ? SCHEME_HTTPS : SCHEME_HTTP;
+ String port = isSSLEnabled ? configProps.get(SSL_PORT_PROPERTY) : configProps.get(PORT_PROPERTY);
+
+ for (String hostName : component.getHostNames()) {
+ urls.add(scheme + "://" + hostName + ":" + port);
+ }
+ }
+ }
+ return urls;
+ }
+
+ private boolean isSSLEnabled(String service) {
+ boolean isSSLEnabled = false;
+
+ AmbariCluster.ServiceConfiguration config = cluster.getServiceConfiguration(service, CONFIG_TYPE_SSL);
+ if (config != null) {
+ isSSLEnabled = Boolean.valueOf(config.getProperties().getOrDefault(SSL_ENABLED_PROPERTY, "false"));
+ }
+
+ return isSSLEnabled;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/9482351e/gateway-discovery-ambari/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.ambari.ServiceURLCreator
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.ambari.ServiceURLCreator b/gateway-discovery-ambari/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.ambari.ServiceURLCreator
index f385ae6..d1c6af0 100644
--- a/gateway-discovery-ambari/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.ambari.ServiceURLCreator
+++ b/gateway-discovery-ambari/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.ambari.ServiceURLCreator
@@ -25,3 +25,4 @@ org.apache.knox.gateway.topology.discovery.ambari.YarnUIV2URLCreator
org.apache.knox.gateway.topology.discovery.ambari.SparkHistoryUIServiceURLCreator
org.apache.knox.gateway.topology.discovery.ambari.LivyServiceURLCreator
org.apache.knox.gateway.topology.discovery.ambari.SparkThriftServerUIServiceURLCreator
+org.apache.knox.gateway.topology.discovery.ambari.NiFiURLCreator
http://git-wip-us.apache.org/repos/asf/knox/blob/9482351e/gateway-discovery-ambari/src/main/resources/ambari-service-discovery-url-mappings.xml
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/main/resources/ambari-service-discovery-url-mappings.xml b/gateway-discovery-ambari/src/main/resources/ambari-service-discovery-url-mappings.xml
index 5609de3..a41bbed 100644
--- a/gateway-discovery-ambari/src/main/resources/ambari-service-discovery-url-mappings.xml
+++ b/gateway-discovery-ambari/src/main/resources/ambari-service-discovery-url-mappings.xml
@@ -569,59 +569,4 @@
</properties>
</service>
- <service name="NIFI">
- <url-pattern>{SCHEME}://{HOST}:{PORT}</url-pattern>
- <properties>
- <property name="COMPONENT_HOST">
- <component>NIFI_MASTER</component>
- <hostname/>
- </property>
- <property name="HTTP_HOST">
- <component>NIFI_MASTER</component>
- <config-property>nifi.web.http.host</config-property>
- </property>
- <property name="HTTPS_HOST">
- <component>NIFI_MASTER</component>
- <config-property>nifi.web.https.host</config-property>
- </property>
- <property name="HTTP_PORT">
- <component>NIFI_MASTER</component>
- <config-property>nifi.web.http.port</config-property>
- </property>
- <property name="HTTPS_PORT">
- <component>NIFI_MASTER</component>
- <config-property>nifi.web.https.port</config-property>
- </property>
- <property name="SCHEME">
- <config-property>
- <if property="HTTPS_PORT">
- <then>https</then>
- <else>http</else>
- </if>
- </config-property>
- </property>
- <property name="HOST">
- <config-property>
- <if property="HTTPS_HOST">
- <then>HTTPS_HOST</then>
- <else>
- <if property="HTTP_HOST">
- <then>HTTP_HOST</then>
- <else>COMPONENT_HOST</else>
- </if>
- </else>
- </if>
- </config-property>
- </property>
- <property name="PORT">
- <config-property>
- <if property="SCHEME" value="https">
- <then>HTTPS_PORT</then>
- <else>HTTP_PORT</else>
- </if>
- </config-property>
- </property>
- </properties>
- </service>
-
</service-discovery-url-mappings>