From b855e0f4bbe58724ffb0358edd246d5b52ed94fe Mon Sep 17 00:00:00 2001 From: Sandor Molnar Date: Mon, 29 Jan 2024 11:22:03 +0100 Subject: [PATCH] KNOX-3004 - Building a valid JDBC URL for Impala (#837) --- .../gateway/service/metadata/ServiceModel.java | 4 ++++ .../service/metadata/ServiceModelTest.java | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/ServiceModel.java b/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/ServiceModel.java index d4b08d0882..5e35d27ff3 100644 --- a/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/ServiceModel.java +++ b/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/ServiceModel.java @@ -48,6 +48,8 @@ public class ServiceModel implements Comparable { static final String CURL_SAMPLE_TEMPLATE = "curl -iv -X %s \"%s%s\""; static final String HIVE_SERVICE_NAME = "HIVE"; static final String HIVE_SERVICE_URL_TEMPLATE = "jdbc:hive2://%s:%d/;ssl=true;transportMode=http;httpPath=%s/%s/hive"; + static final String IMPALA_SERVICE_NAME = "IMPALA"; + static final String IMPALA_SERVICE_URL_TEMPLATE = "jdbc:impala://%s:%d/;ssl=1;transportMode=http;httpPath=%s/%s/impala;AuthMech=3"; public enum Type { API, UI, API_AND_UI, UNKNOWN @@ -127,6 +129,8 @@ public String getServiceUrl() { String context = getContext(); if (HIVE_SERVICE_NAME.equals(getServiceName())) { return String.format(Locale.ROOT, HIVE_SERVICE_URL_TEMPLATE, request.getServerName(), request.getServerPort(), gatewayPath, topologyName); + } else if (IMPALA_SERVICE_NAME.equals(getServiceName())) { + return String.format(Locale.ROOT, IMPALA_SERVICE_URL_TEMPLATE, request.getServerName(), request.getServerPort(), gatewayPath, topologyName); } else { return getServiceUrl(context); } diff --git a/gateway-service-metadata/src/test/java/org/apache/knox/gateway/service/metadata/ServiceModelTest.java b/gateway-service-metadata/src/test/java/org/apache/knox/gateway/service/metadata/ServiceModelTest.java index 4058ee2f60..77ff7c3e2e 100644 --- a/gateway-service-metadata/src/test/java/org/apache/knox/gateway/service/metadata/ServiceModelTest.java +++ b/gateway-service-metadata/src/test/java/org/apache/knox/gateway/service/metadata/ServiceModelTest.java @@ -19,6 +19,8 @@ import static org.apache.knox.gateway.service.metadata.ServiceModel.HIVE_SERVICE_NAME; import static org.apache.knox.gateway.service.metadata.ServiceModel.HIVE_SERVICE_URL_TEMPLATE; +import static org.apache.knox.gateway.service.metadata.ServiceModel.IMPALA_SERVICE_NAME; +import static org.apache.knox.gateway.service.metadata.ServiceModel.IMPALA_SERVICE_URL_TEMPLATE; import static org.apache.knox.gateway.service.metadata.ServiceModel.SERVICE_URL_TEMPLATE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -159,6 +161,21 @@ public void shouldReturnProperHiveServiceUrl() throws Exception { assertEquals(String.format(Locale.ROOT, HIVE_SERVICE_URL_TEMPLATE, SERVER_NAME, SERVER_PORT, gatewayPath, topologyName), serviceModel.getServiceUrl()); } + @Test + public void shouldReturnProperImpalaServiceUrl() throws Exception { + final ServiceModel serviceModel = new ServiceModel(); + final String gatewayPath = "gateway"; + final String topologyName = "sandbox"; + serviceModel.setGatewayPath(gatewayPath); + serviceModel.setTopologyName(topologyName); + serviceModel.setRequest(setUpHttpRequestMock()); + final Service service = EasyMock.createNiceMock(Service.class); + serviceModel.setService(service); + EasyMock.expect(service.getRole()).andReturn(IMPALA_SERVICE_NAME).anyTimes(); + EasyMock.replay(service); + assertEquals(String.format(Locale.ROOT, IMPALA_SERVICE_URL_TEMPLATE, SERVER_NAME, SERVER_PORT, gatewayPath, topologyName), serviceModel.getServiceUrl()); + } + public HttpServletRequest setUpHttpRequestMock() { final HttpServletRequest httpServletRequestMock = EasyMock.createNiceMock(HttpServletRequest.class); EasyMock.expect(httpServletRequestMock.getScheme()).andReturn(SERVER_SCHEME).anyTimes();