knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kris...@apache.org
Subject [knox] branch master updated: KNOX-2013 - CM discovery - Add Phoenix to auto discovery (#148)
Date Mon, 23 Sep 2019 14:17:46 GMT
This is an automated email from the ASF dual-hosted git repository.

krisden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git


The following commit(s) were added to refs/heads/master by this push:
     new 854017d  KNOX-2013 - CM discovery - Add Phoenix to auto discovery (#148)
854017d is described below

commit 854017d8a7f29fc7e85bd1e3c020b41752e793c1
Author: Istvan Toth <stoty@users.noreply.github.com>
AuthorDate: Mon Sep 23 16:17:41 2019 +0200

    KNOX-2013 - CM discovery - Add Phoenix to auto discovery (#148)
---
 .../phoenix/PhoenixServiceModelGenerator.java      | 71 ++++++++++++++++++++++
 ...way.topology.discovery.cm.ServiceModelGenerator |  1 +
 .../cm/ClouderaManagerServiceDiscoveryTest.java    | 24 ++++++++
 3 files changed, 96 insertions(+)

diff --git a/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/model/phoenix/PhoenixServiceModelGenerator.java
b/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/model/phoenix/PhoenixServiceModelGenerator.java
new file mode 100644
index 0000000..cf9fdd7
--- /dev/null
+++ b/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/model/phoenix/PhoenixServiceModelGenerator.java
@@ -0,0 +1,71 @@
+/*
+ * 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.knox.gateway.topology.discovery.cm.model.phoenix;
+
+import com.cloudera.api.swagger.model.ApiConfigList;
+import com.cloudera.api.swagger.model.ApiRole;
+import com.cloudera.api.swagger.model.ApiService;
+import com.cloudera.api.swagger.model.ApiServiceConfig;
+import org.apache.knox.gateway.topology.discovery.cm.ServiceModel;
+import org.apache.knox.gateway.topology.discovery.cm.model.AbstractServiceModelGenerator;
+
+import java.util.Locale;
+
+public class PhoenixServiceModelGenerator extends AbstractServiceModelGenerator {
+
+  private static final String SERVICE = "AVATICA";
+  private static final String SERVICE_TYPE = "PHOENIX";
+  private static final String ROLE_TYPE = "PHOENIX_QUERY_SERVER";
+
+  @Override
+  public String getService() {
+    return SERVICE;
+  }
+
+  @Override
+  public String getServiceType() {
+    return SERVICE_TYPE;
+  }
+
+  @Override
+  public String getRoleType() {
+    return ROLE_TYPE;
+  }
+
+  @Override
+  public ServiceModel.Type getModelType() {
+    return ServiceModel.Type.API;
+  }
+
+  @Override
+  public boolean handles(ApiService service, ApiServiceConfig serviceConfig, ApiRole role,
ApiConfigList roleConfig) {
+    return getServiceType().equals(service.getType()) && getRoleType().equals(role.getType());
+  }
+
+  @Override
+  public ServiceModel generateService(ApiService       service,
+                                      ApiServiceConfig serviceConfig,
+                                      ApiRole          role,
+                                      ApiConfigList    roleConfig) {
+    String hostname = role.getHostRef().getHostname();
+    // Phoenix Query Server does not support https
+    String scheme = "http";
+    String port = getRoleConfigValue(roleConfig, "phoenix_query_server_port");
+    return createServiceModel(String.format(Locale.getDefault(), "%s://%s:%s", scheme, hostname,
port));
+  }
+
+}
diff --git a/gateway-discovery-cm/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.cm.ServiceModelGenerator
b/gateway-discovery-cm/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.cm.ServiceModelGenerator
index 61397a8..c37823a 100644
--- a/gateway-discovery-cm/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.cm.ServiceModelGenerator
+++ b/gateway-discovery-cm/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.cm.ServiceModelGenerator
@@ -31,6 +31,7 @@ org.apache.knox.gateway.topology.discovery.cm.model.yarn.JobTrackerServiceModelG
 org.apache.knox.gateway.topology.discovery.cm.model.livy.LivyServiceModelGenerator
 org.apache.knox.gateway.topology.discovery.cm.model.oozie.OozieServiceModelGenerator
 org.apache.knox.gateway.topology.discovery.cm.model.oozie.OozieUIServiceModelGenerator
+org.apache.knox.gateway.topology.discovery.cm.model.phoenix.PhoenixServiceModelGenerator
 org.apache.knox.gateway.topology.discovery.cm.model.ranger.RangerServiceModelGenerator
 org.apache.knox.gateway.topology.discovery.cm.model.ranger.RangerUIServiceModelGenerator
 org.apache.knox.gateway.topology.discovery.cm.model.solr.SolrServiceModelGenerator
diff --git a/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/ClouderaManagerServiceDiscoveryTest.java
b/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/ClouderaManagerServiceDiscoveryTest.java
index aa8d828..edee5dd 100644
--- a/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/ClouderaManagerServiceDiscoveryTest.java
+++ b/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/ClouderaManagerServiceDiscoveryTest.java
@@ -311,6 +311,17 @@ public class ClouderaManagerServiceDiscoveryTest {
     assertEquals("https://" + hostName + ":" + port, livyURLs.get(0));
   }
 
+  @Test
+  public void testPhoenixDiscovery() {
+    final String hostName    = "phoenix-host";
+    final String port        = "8765";
+    ServiceDiscovery.Cluster cluster = doTestPhoenixDiscovery(hostName, port, false);
+    assertNotNull(cluster);
+    List<String> phoenixURLs = cluster.getServiceURLs("AVATICA");
+    assertNotNull(phoenixURLs);
+    assertEquals(1, phoenixURLs.size());
+    assertEquals("http://" + hostName + ":" + port, phoenixURLs.get(0));
+  }
 
   @Test
   public void testOozieDiscovery() {
@@ -758,6 +769,19 @@ public class ClouderaManagerServiceDiscoveryTest {
   }
 
 
+  private ServiceDiscovery.Cluster doTestPhoenixDiscovery(final String hostName,
+                                                          final String port,
+                                                          final boolean isSSL) {
+      // Configure the role
+      Map<String, String> roleProperties = new HashMap<>();
+      roleProperties.put("phoenix_query_server_port", port);
+      roleProperties.put("ssl_enabled", String.valueOf(isSSL));
+
+      return doTestDiscovery(hostName, "PHOENIX-1", "PHOENIX", "PHOENIX-PHOENIX_QUERY_SERVER-1",
"PHOENIX_QUERY_SERVER", Collections.emptyMap(),
+              roleProperties);
+  }
+
+
   private ServiceDiscovery.Cluster doTestDiscovery(final String hostName,
                                                    final String serviceName,
                                                    final String serviceType,


Mime
View raw message