Skip to content

Commit

Permalink
KNOX-2963 - CM service discovery should work when legacy mode is turn…
Browse files Browse the repository at this point in the history
…ed off (#801)
  • Loading branch information
zeroflag authored Oct 11, 2023
1 parent ff6bcbc commit 838dcd8
Show file tree
Hide file tree
Showing 39 changed files with 162 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ private ClouderaManagerCluster discoverCluster(DiscoveryApiClient client, String
cmService.setType(CM_SERVICE_TYPE);
serviceList.add(cmService);

// if Legacy Cloudera Manager API Clients Compatibility is turned off, some HDFS settings are in CORE_SETTINGS
ApiServiceConfig coreSettingsConfig = coreSettingsConfig(client, servicesResourceApi, serviceList);

for (ApiService service : serviceList) {
final List<ServiceModelGenerator> modelGenerators = serviceModelGeneratorsHolder.getServiceModelGenerators(service.getType());
if (shouldSkipServiceDiscovery(modelGenerators, includedServices)) {
Expand Down Expand Up @@ -299,7 +302,7 @@ private ClouderaManagerCluster discoverCluster(DiscoveryApiClient client, String
ServiceModelGeneratorHandleResponse response = serviceModelGenerator.handles(service, serviceConfig, role, roleConfig);
if (response.handled()) {
serviceModelGenerator.setApiClient(client);
ServiceModel serviceModel = serviceModelGenerator.generateService(service, serviceConfig, role, roleConfig);
ServiceModel serviceModel = serviceModelGenerator.generateService(service, serviceConfig, role, roleConfig, coreSettingsConfig);
serviceModels.add(serviceModel);
} else if (!response.getConfigurationIssues().isEmpty()) {
log.serviceRoleHasConfigurationIssues(roleName, String.join(";", response.getConfigurationIssues()));
Expand All @@ -320,6 +323,15 @@ private ClouderaManagerCluster discoverCluster(DiscoveryApiClient client, String
return null;
}

private ApiServiceConfig coreSettingsConfig(DiscoveryApiClient client, ServicesResourceApi servicesResourceApi, List<ApiService> serviceList) throws ApiException {
for (ApiService service : serviceList) {
if (CORE_SETTINGS_TYPE.equals(service.getType())) {
return getServiceConfig(client.getConfig(), servicesResourceApi, service);
}
}
return null;
}

private boolean shouldSkipServiceDiscovery(List<ServiceModelGenerator> modelGenerators, Collection<String> includedServices) {
if (includedServices == null || includedServices.isEmpty()) {
// per the contract of org.apache.knox.gateway.topology.discovery.ServiceDiscovery.discover(GatewayConfig, ServiceDiscoveryConfig, String, Collection<String>):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@ public interface ServiceModelGenerator {

ServiceModelGeneratorHandleResponse handles(ApiService service, ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig);

ServiceModel generateService(ApiService service, ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig) throws ApiException;

ServiceModel generateService(ApiService service, ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig) throws ApiException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,15 @@ public ServiceModelGeneratorHandleResponse handles(ApiService service, ApiServic
return new ServiceModelGeneratorHandleResponse(getServiceType().equals(service.getType()) && getRoleType().equals(role.getType()));
}

protected String getCoreOrServiceConfig(ApiServiceConfig serviceConfig, ApiServiceConfig coreSettingsConfig, String configName) {
if (coreSettingsConfig != null) {
// in Legacy Cloudera Manager API Clients Compatibility certain configs,
// such as hdfs_hadoop_ssl_enabled are in the CORE_CONFIG
String configValue = getServiceConfigValue(coreSettingsConfig, configName);
if (configValue != null) {
return configValue;
}
}
return getServiceConfigValue(serviceConfig, configName); // Fall back to service config
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public ServiceModel.Type getModelType() {
}

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) throws ApiException {
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig) throws ApiException {
String hostname = role.getHostRef().getHostname();
String scheme;
String port;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ServiceModel.Type getModelType() {
*/
@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig)
ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig)
throws ApiException {

final String basePath = getClient().getBasePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Type getModelType() {
}

@Override
public ServiceModel generateService(ApiService service, ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig) throws ApiException {
public ServiceModel generateService(ApiService service, ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig) throws ApiException {
final String hostname = role.getHostRef().getHostname();
final String port = getRoleConfigValue(roleConfig, WEB_PORT);
final boolean sslEnabled = Boolean.parseBoolean(getRoleConfigValue(roleConfig, SSL_ENABLED));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public ServiceModel.Type getModelType() {
}

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) {
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig) {
String hostname = role.getHostRef().getHostname();
String scheme;
String port = getRoleConfigValue(roleConfig, MASTER_INFO_PORT); // TODO: Is there an SSL port, or is this property re-used?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public ServiceModel.Type getModelType() {
}

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) {
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig) {
String hostname = role.getHostRef().getHostname();
String scheme;
String port = getRoleConfigValue(roleConfig, REST_SERVER_PORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ public ServiceModel.Type getModelType() {
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) throws ApiException {
ApiConfigList roleConfig,
ApiServiceConfig coreSettingsConfig) throws ApiException {
String hostname = role.getHostRef().getHostname();
String scheme;
String port;
boolean sslEnabled = Boolean.parseBoolean(getServiceConfigValue(serviceConfig, SSL_ENABLED));
String sslEnabledConfig = getCoreOrServiceConfig(serviceConfig, coreSettingsConfig, SSL_ENABLED);
boolean sslEnabled = Boolean.parseBoolean(sslEnabledConfig);
if(sslEnabled) {
scheme = "https";
port = getRoleConfigValue(roleConfig, HTTPS_PORT);
Expand All @@ -62,11 +64,11 @@ public ServiceModel generateService(ApiService service,
String namenodeUrl = String.format(Locale.getDefault(), "%s://%s:%s", scheme, hostname, port);

ServiceModel model = createServiceModel(namenodeUrl);
model.addServiceProperty(SSL_ENABLED, getServiceConfigValue(serviceConfig, SSL_ENABLED));
model.addServiceProperty(SSL_ENABLED, sslEnabledConfig);
model.addRoleProperty(role.getType(), HTTPS_PORT, getRoleConfigValue(roleConfig, HTTPS_PORT));
model.addRoleProperty(role.getType(), HTTP_PORT, getRoleConfigValue(roleConfig, HTTP_PORT));

ServiceModel parent = super.generateService(service, serviceConfig, role, roleConfig);
ServiceModel parent = super.generateService(service, serviceConfig, role, roleConfig, coreSettingsConfig);
addParentModelMetadata(model, parent);

return model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public ServiceModel.Type getModelType() {
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) throws ApiException {
ApiConfigList roleConfig,
ApiServiceConfig coreSettingsConfig) throws ApiException {
boolean haEnabled = Boolean.parseBoolean(getRoleConfigValue(roleConfig, AUTOFAILOVER_ENABLED));
String serviceUrl;
if (haEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public ServiceModelGeneratorHandleResponse handles(ApiService service, ApiServic
}

@Override
public ServiceModel generateService(ApiService service, ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig) throws ApiException {
ServiceModel parent = super.generateService(service, serviceConfig, role, roleConfig);
public ServiceModel generateService(ApiService service, ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig) throws ApiException {
ServiceModel parent = super.generateService(service, serviceConfig, role, roleConfig, coreSettingsConfig);
String serviceUrl = parent.getServiceUrl() + WEBHDFS_SUFFIX;

ServiceModel model = createServiceModel(serviceUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ protected String getHttpPort(ApiConfigList roleConfig) {
}

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) throws ApiException {
ServiceModel model = super.generateService(service, serviceConfig, role, roleConfig);
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig) throws ApiException {
ServiceModel model = super.generateService(service, serviceConfig, role, roleConfig, coreSettingsConfig);
model.addRoleProperty(getRoleType(),
HIVEONTEZ_HTTP_PORT,
getRoleConfigValue(roleConfig, HIVEONTEZ_HTTP_PORT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public ServiceModelGeneratorHandleResponse handles(ApiService service, ApiServic
}

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) throws ApiException {
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig) throws ApiException {
String hostname = role.getHostRef().getHostname();
boolean sslEnabled = Boolean.parseBoolean(getServiceConfigValue(serviceConfig, SSL_ENABLED));
String scheme = sslEnabled ? "https" : "http";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public ServiceModel.Type getModelType() {
}

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) throws ApiException {
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig) throws ApiException {
String hostname = role.getHostRef().getHostname();
String port = getRoleConfigValue(roleConfig, WEBHCAT_PORT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public ServiceModel.Type getModelType() {
}

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) {
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig) {
String hostname = role.getHostRef().getHostname();
String scheme = "http";
String port = getRoleConfigValue(roleConfig, LISTEN_PORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public ServiceModel.Type getModelType() {
}

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) {
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig) {
String hostname = role.getHostRef().getHostname();
String scheme;
String port = getRoleConfigValue(roleConfig, HUE_HTTP_PORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public ServiceModelGeneratorHandleResponse handles(ApiService service, ApiServic
}

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) throws ApiException {
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig) throws ApiException {
String hostname = role.getHostRef().getHostname();

boolean sslEnabled = Boolean.parseBoolean(getServiceConfigValue(serviceConfig, SSL_ENABLED));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public ServiceModelGeneratorHandleResponse handles(ApiService service, ApiServic
}

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) throws ApiException {
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig) throws ApiException {
String hostname = role.getHostRef().getHostname();

String sslEnabled = getServiceConfigValue(serviceConfig, SSL_ENABLED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public ServiceModel.Type getModelType() {
}

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) throws ApiException {
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig) throws ApiException {
String hostname = role.getHostRef().getHostname();

String sslEnabled = getRoleConfigValue(roleConfig, SSL_ENABLED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public ServiceModel.Type getModelType() {
}

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) {
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig) {
String hostname = role.getHostRef().getHostname();
String scheme;
String port = getRoleConfigValue(roleConfig, LIVY_SERVER_PORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public ServiceModel.Type getModelType() {

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig)
ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig)
throws ApiException {
String hostname = role.getHostRef().getHostname();
String scheme;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public ServiceModel.Type getModelType() {

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig)
ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig)
throws ApiException {
String hostname = role.getHostRef().getHostname();
String scheme;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public ServiceModel.Type getModelType() {
}

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) {
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig, ApiServiceConfig coreSettingsConfig) {
String hostname = role.getHostRef().getHostname();
String scheme;
String port;
Expand Down
Loading

0 comments on commit 838dcd8

Please sign in to comment.