Skip to content

Commit

Permalink
KNOX-3004 - Building a valid JDBC URL for Impala (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
smolnar82 authored Jan 29, 2024
1 parent 6047ea7 commit b855e0f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class ServiceModel implements Comparable<ServiceModel> {
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
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit b855e0f

Please sign in to comment.