Details
-
Bug
-
Resolution: Unresolved
-
Neutral
-
None
-
1.0.0
-
None
-
Java 11, Magnolia 6.2.11, docker image in Azure cloud
Description
Magnolia creates a RestClient instance for each ES cluster configuration on start-up of the magnolia-query-manager module. This fails if magnolia is running in a cloud, where the CMS and the search service are in different containers.
To fix this, the info.magnolia.elasticsearch.ElasticsearchClient may be patched to lazily instantiate the rest clients when needed and not in advance.
@Override
public void start(ModuleLifecycleContext moduleLifecycleContext) {
try {
defaultElasticsearchVersion = Version.parseVersion(PropertyUtil.getString(
CommonFunctionality.getSession(SearchProviderConstants.Workspaces.CONFIG)
.getNode(SearchProviderConstants.NodePaths.ELASTIC_CONFIG_MODULE),
SearchProviderConstants.NodeProperties.DEFAULT_ELASTICSEARCH_VERSION_PROPERTY));
} catch (RepositoryException e) {
log.error("Unable to determine default API specification for Elasticsearch.", e);
}
if (!ClusterItemConfiguration.apiSpecExists(defaultElasticsearchVersion)) {
try {
ClusterItemConfiguration.createApiSpec(defaultElasticsearchVersion);
} catch (ElasticConfigurationException e) {
log.error("Unable to create default API specification for Elasticsearch.", e);
}
}
try {
//for mch we create the client when needed.
// ClusterItemConfiguration.getAllClusters().forEach((name, cluster) -> {
// try {
// addClient(name, cluster);
// } catch (ClusterConfigurationException e) {
// log.error("Unable to retrieve configuration for Elasticsearch.");
// }
// });
indexToServer = IndexItemConfiguration.getAllIndexToClusterMappings();
} catch (ElasticConfigurationException e) {
log.error("Unable to retrieve configuration for Elasticsearch.");
}
}
public RestClient getClient(String clusterName) { if(!clients.containsKey(clusterName)) { //somehow the client was not created try { var config = ClusterItemConfiguration.getAllClusters().get(clusterName); this.addClient(config); } catch (Exception e) { log.error("Could not create client for {}", clusterName, e); t hrow new RuntimeException("Could not create client for " + clusterName); } } return clients.get(clusterName); }
Checklists
Acceptance criteria