Skip to content

Commit

Permalink
Change template load trigger
Browse files Browse the repository at this point in the history
Signed-off-by: Mohit Godwani <[email protected]>
  • Loading branch information
mgodwan committed Jul 11, 2024
1 parent 21f882a commit d4c6472
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
package org.opensearch.cluster.service;

import org.opensearch.cluster.ClusterManagerMetrics;
import org.opensearch.cluster.service.applicationtemplates.SystemTemplatesPlugin;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.common.settings.ClusterSettings;
import org.opensearch.common.settings.Settings;
import org.opensearch.threadpool.ThreadPool;

import java.util.List;

/**
* Main Cluster Manager Node Service
*
Expand All @@ -33,9 +30,8 @@ public ClusterManagerService(
Settings settings,
ClusterSettings clusterSettings,
ThreadPool threadPool,
ClusterManagerMetrics clusterManagerMetrics,
List<SystemTemplatesPlugin> systemTemplatesPlugins
ClusterManagerMetrics clusterManagerMetrics
) {
super(settings, clusterSettings, threadPool, clusterManagerMetrics, systemTemplatesPlugins);
super(settings, clusterSettings, threadPool, clusterManagerMetrics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.cluster.routing.OperationRouting;
import org.opensearch.cluster.routing.RerouteService;
import org.opensearch.cluster.service.applicationtemplates.SystemTemplatesPlugin;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.common.lifecycle.AbstractLifecycleComponent;
import org.opensearch.common.settings.ClusterSettings;
Expand All @@ -59,7 +58,6 @@
import org.opensearch.threadpool.ThreadPool;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
Expand Down Expand Up @@ -96,20 +94,19 @@ public class ClusterService extends AbstractLifecycleComponent {
private IndexingPressureService indexingPressureService;

public ClusterService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool) {
this(settings, clusterSettings, threadPool, new ClusterManagerMetrics(NoopMetricsRegistry.INSTANCE), null);
this(settings, clusterSettings, threadPool, new ClusterManagerMetrics(NoopMetricsRegistry.INSTANCE));
}

public ClusterService(
Settings settings,
ClusterSettings clusterSettings,
ThreadPool threadPool,
ClusterManagerMetrics clusterManagerMetrics,
List<SystemTemplatesPlugin> systemTemplatesPlugins
ClusterManagerMetrics clusterManagerMetrics
) {
this(
settings,
clusterSettings,
new ClusterManagerService(settings, clusterSettings, threadPool, clusterManagerMetrics, systemTemplatesPlugins),
new ClusterManagerService(settings, clusterSettings, threadPool, clusterManagerMetrics),
new ClusterApplierService(Node.NODE_NAME_SETTING.get(settings), settings, clusterSettings, threadPool, clusterManagerMetrics)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.cluster.node.DiscoveryNodes;
import org.opensearch.cluster.routing.RoutingTable;
import org.opensearch.cluster.service.applicationtemplates.SystemTemplatesPlugin;
import org.opensearch.cluster.service.applicationtemplates.SystemTemplatesService;
import org.opensearch.common.Nullable;
import org.opensearch.common.Priority;
import org.opensearch.common.annotation.DeprecatedApi;
Expand Down Expand Up @@ -142,18 +140,16 @@ public class MasterService extends AbstractLifecycleComponent {
private final ClusterManagerThrottlingStats throttlingStats;
private final ClusterStateStats stateStats;
private final ClusterManagerMetrics clusterManagerMetrics;
private final SystemTemplatesService systemTemplatesService;

public MasterService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool) {
this(settings, clusterSettings, threadPool, new ClusterManagerMetrics(NoopMetricsRegistry.INSTANCE), null);
this(settings, clusterSettings, threadPool, new ClusterManagerMetrics(NoopMetricsRegistry.INSTANCE));
}

public MasterService(
Settings settings,
ClusterSettings clusterSettings,
ThreadPool threadPool,
ClusterManagerMetrics clusterManagerMetrics,
List<SystemTemplatesPlugin> systemTemplatesPlugins
ClusterManagerMetrics clusterManagerMetrics
) {
this.nodeName = Objects.requireNonNull(Node.NODE_NAME_SETTING.get(settings));

Expand All @@ -173,7 +169,6 @@ public MasterService(
this.stateStats = new ClusterStateStats();
this.threadPool = threadPool;
this.clusterManagerMetrics = clusterManagerMetrics;
this.systemTemplatesService = new SystemTemplatesService(systemTemplatesPlugins, clusterSettings, settings);
}

private void setSlowTaskLoggingThreshold(TimeValue slowTaskLoggingThreshold) {
Expand Down Expand Up @@ -400,7 +395,6 @@ void onPublicationSuccess(ClusterChangedEvent clusterChangedEvent, TaskOutputs t

try {
taskOutputs.clusterStatePublished(clusterChangedEvent);
threadPool.executor(ThreadPool.Names.GENERIC).submit(() -> systemTemplatesService.refreshTemplates());
} catch (Exception e) {
logger.error(
() -> new ParameterizedMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.cluster.ClusterChangedEvent;
import org.opensearch.cluster.ClusterStateListener;
import org.opensearch.cluster.LocalNodeClusterManagerListener;
import org.opensearch.common.settings.ClusterSettings;
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
Expand All @@ -21,7 +24,7 @@
/**
* Service class to orchestrate execution around available templates' management.
*/
public class SystemTemplatesService {
public class SystemTemplatesService implements LocalNodeClusterManagerListener {

public static final int APPLICATION_BASED_CONFIGURATION_TEMPLATES_LOAD_DEFAULT_COUNT = 50;

Expand Down Expand Up @@ -52,10 +55,20 @@ public SystemTemplatesService(List<SystemTemplatesPlugin> systemTemplatesPluginL
this.settings = settings;
}

public void refreshTemplates() {
@Override
public void onClusterManager() {
refreshTemplates();
}

@Override
public void offClusterManager() {
// do nothing
}

private void refreshTemplates() {
if (loaded.compareAndSet(false, true)) {
if (SETTING_APPLICATION_BASED_CONFIGURATION_TEMPLATES_LOAD.get(settings) > 0) {
int countOfTemplatesToLoad = SETTING_APPLICATION_BASED_CONFIGURATION_TEMPLATES_LOAD.get(settings);
int countOfTemplatesToLoad = templatesToLoad;
int templatesLoaded = 0;
int failedLoadingTemplates = 0;
int failedLoadingRepositories = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import org.opensearch.cluster.service.ClusterManagerService;
import org.opensearch.cluster.service.ClusterManagerTaskThrottler;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.cluster.service.applicationtemplates.SystemTemplatesService;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.common.cache.CacheType;
import org.opensearch.common.cache.settings.CacheSettings;
Expand Down Expand Up @@ -758,7 +759,9 @@ public void apply(Settings value, Settings current, Settings previous) {
SearchService.CLUSTER_ALLOW_DERIVED_FIELD_SETTING,

// Composite index settings
CompositeIndexSettings.STAR_TREE_INDEX_ENABLED_SETTING
CompositeIndexSettings.STAR_TREE_INDEX_ENABLED_SETTING,

SystemTemplatesService.SETTING_APPLICATION_BASED_CONFIGURATION_TEMPLATES_LOAD
)
)
);
Expand Down
9 changes: 6 additions & 3 deletions server/src/main/java/org/opensearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import org.opensearch.cluster.routing.allocation.DiskThresholdMonitor;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.cluster.service.applicationtemplates.SystemTemplatesPlugin;
import org.opensearch.cluster.service.applicationtemplates.SystemTemplatesService;
import org.opensearch.common.SetOnce;
import org.opensearch.common.StopWatch;
import org.opensearch.common.cache.module.CacheModule;
Expand Down Expand Up @@ -664,18 +665,20 @@ protected Node(
settings,
settingsModule.getClusterSettings(),
threadPool,
clusterManagerMetrics,
pluginsService.filterPlugins(SystemTemplatesPlugin.class)
clusterManagerMetrics
);
clusterService.addStateApplier(scriptService);
resourcesToClose.add(clusterService);
final Set<Setting<?>> consistentSettings = settingsModule.getConsistentSettings();
if (consistentSettings.isEmpty() == false) {
clusterService.addLocalNodeMasterListener(
clusterService.addLocalNodeClusterManagerListener(
new ConsistentSettingsService(settings, clusterService, consistentSettings).newHashPublisher()
);
}

clusterService.addLocalNodeClusterManagerListener(new SystemTemplatesService(pluginsService.filterPlugins(SystemTemplatesPlugin.class),
clusterService.getClusterSettings(), settings));

final ClusterInfoService clusterInfoService = newClusterInfoService(settings, clusterService, threadPool, client);
final UsageService usageService = new UsageService();

Expand Down

0 comments on commit d4c6472

Please sign in to comment.