Skip to content

Commit

Permalink
KNOX-2573 - Service discovery should support HiveServer2 transport mo…
Browse files Browse the repository at this point in the history
…de all (apache#431)
  • Loading branch information
pzampino authored Apr 7, 2021
1 parent bcce97b commit 4a34946
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ public String getServiceType() {
@Override
protected void checkHiveServer2HTTPMode(ApiConfigList roleConfig, ServiceModelGeneratorHandleResponse response) {
final String hiveServer2TransportMode = getRoleConfigValue(roleConfig, HIVEONTEZ_TRANSPORT_MODE);
if (hiveServer2TransportMode == null) {
response.addConfigurationIssue("Missing configuration: " + HIVEONTEZ_TRANSPORT_MODE);
} else if (!TRANSPORT_MODE_HTTP.equals(hiveServer2TransportMode)) {
response.addConfigurationIssue("Invalid configuration: " + HIVEONTEZ_TRANSPORT_MODE + ". Expected=" + TRANSPORT_MODE_HTTP + "; Found=" + hiveServer2TransportMode);
}
validateTransportMode(HIVEONTEZ_TRANSPORT_MODE, hiveServer2TransportMode, response);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class HiveServiceModelGenerator extends AbstractServiceModelGenerator {
public static final String ROLE_TYPE = "HIVESERVER2";

static final String TRANSPORT_MODE_HTTP = "http";
static final String TRANSPORT_MODE_ALL = "all";

static final String SAFETY_VALVE = "hive_hs2_config_safety_valve";
static final String SSL_ENABLED = "hive.server2.use.SSL";
Expand Down Expand Up @@ -114,12 +115,19 @@ protected String getHttpPath(ApiConfigList roleConfig) {

protected void checkHiveServer2HTTPMode(ApiConfigList roleConfig, ServiceModelGeneratorHandleResponse response) {
final String hiveServer2SafetyValve = getRoleConfigValue(roleConfig, SAFETY_VALVE);
final String hiveServer2TransportMode = hiveServer2SafetyValve == null ? null : getSafetyValveValue(hiveServer2SafetyValve, TRANSPORT_MODE);
if (hiveServer2TransportMode == null ) {
response.addConfigurationIssue("Missing configuration: " + TRANSPORT_MODE);
} else if (!TRANSPORT_MODE_HTTP.equals(hiveServer2TransportMode)) {
response.addConfigurationIssue("Invalid configuration: " + TRANSPORT_MODE + ". Expected=" + TRANSPORT_MODE_HTTP + "; Found=" + hiveServer2TransportMode);
}
final String hiveServer2TransportMode =
hiveServer2SafetyValve == null ? null : getSafetyValveValue(hiveServer2SafetyValve, TRANSPORT_MODE);
validateTransportMode(TRANSPORT_MODE, hiveServer2TransportMode, response);
}

protected void validateTransportMode(final String configPropName,
final String transportMode,
final ServiceModelGeneratorHandleResponse response) {
if (transportMode == null ) {
response.addConfigurationIssue("Missing configuration: " + configPropName);
} else if (!TRANSPORT_MODE_HTTP.equalsIgnoreCase(transportMode) && !TRANSPORT_MODE_ALL.equalsIgnoreCase(transportMode)) {
response.addConfigurationIssue("Invalid configuration: " + configPropName +
". Expected=" + TRANSPORT_MODE_HTTP + " or " + TRANSPORT_MODE_ALL +"; Found=" + transportMode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public void testHandles() {
assertTrue(doTestHandles(newGenerator(), getServiceType(), Collections.emptyMap(), getRoleType(), roleConfig));
}

@Test
public void testHandlesTransportModeAll() {
Map<String, String> roleConfig = new HashMap<>();
roleConfig.put(HiveOnTezServiceModelGenerator.HIVEONTEZ_TRANSPORT_MODE,
HiveOnTezServiceModelGenerator.TRANSPORT_MODE_ALL);
assertTrue(doTestHandles(newGenerator(), getServiceType(), Collections.emptyMap(), getRoleType(), roleConfig));
}

@Test
public void testHandlesWhenTransportModeIsBinary() {
Map<String, String> roleConfig = new HashMap<>();
Expand All @@ -59,6 +67,20 @@ public void testServiceModelMetadata() {
validateServiceModel(createServiceModel(serviceConfig, roleConfig), serviceConfig, roleConfig);
}

@Test
public void testServiceModelMetadataTransportModeAll() {
final Map<String, String> serviceConfig = Collections.emptyMap();

final Map<String, String> roleConfig = new HashMap<>();
roleConfig.put(HiveOnTezServiceModelGenerator.SSL_ENABLED, "false");
roleConfig.put(HiveOnTezServiceModelGenerator.HIVEONTEZ_TRANSPORT_MODE,
HiveOnTezServiceModelGenerator.TRANSPORT_MODE_ALL);
roleConfig.put(HiveOnTezServiceModelGenerator.HIVEONTEZ_HTTP_PORT, "12345");
roleConfig.put(HiveOnTezServiceModelGenerator.SAFETY_VALVE, "null");

validateServiceModel(createServiceModel(serviceConfig, roleConfig), serviceConfig, roleConfig);
}

@Override
protected String getServiceType() {
return HiveOnTezServiceModelGenerator.SERVICE_TYPE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public void testHandles() {
assertTrue(doTestHandles(newGenerator(), getServiceType(), Collections.emptyMap(), getRoleType(), roleConfig));
}

@Test
public void testHandlesTransportModeAll() {
Map<String, String> roleConfig = new HashMap<>();
roleConfig.put(HiveServiceModelGenerator.SAFETY_VALVE,
getSafetyValveConfig(HiveServiceModelGenerator.TRANSPORT_MODE_ALL));
assertTrue(doTestHandles(newGenerator(), getServiceType(), Collections.emptyMap(), getRoleType(), roleConfig));
}

@Test
public void testHandlesWhenTransportModeIsBinary() {
Map<String, String> roleConfig = new HashMap<>();
Expand All @@ -57,6 +65,18 @@ public void testServiceModelMetadata() {
validateServiceModel(createServiceModel(serviceConfig, roleConfig), serviceConfig, roleConfig);
}

@Test
public void testServiceModelMetadataTransportModeAll() {
final Map<String, String> serviceConfig = Collections.emptyMap();

final Map<String, String> roleConfig = new HashMap<>();
roleConfig.put(HiveServiceModelGenerator.SSL_ENABLED, "false");
roleConfig.put(HiveServiceModelGenerator.SAFETY_VALVE,
getSafetyValveConfig(HiveServiceModelGenerator.TRANSPORT_MODE_ALL));

validateServiceModel(createServiceModel(serviceConfig, roleConfig), serviceConfig, roleConfig);
}

@Override
protected String getServiceType() {
return HiveServiceModelGenerator.SERVICE_TYPE;
Expand Down

0 comments on commit 4a34946

Please sign in to comment.