Skip to content

Commit

Permalink
Register settings in CommandManager main class
Browse files Browse the repository at this point in the history
  • Loading branch information
QU3B1M committed Jan 13, 2025
1 parent dc8ddc9 commit c94c182
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
import org.opensearch.cluster.node.DiscoveryNodes;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.UUIDs;
import org.opensearch.common.settings.ClusterSettings;
import org.opensearch.common.settings.IndexScopedSettings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsFilter;
import org.opensearch.common.settings.*;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.core.common.io.stream.NamedWriteableRegistry;
import org.opensearch.core.xcontent.NamedXContentRegistry;
Expand All @@ -50,6 +47,7 @@

import java.io.IOException;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -89,6 +87,7 @@ public class CommandManagerPlugin extends Plugin implements ActionPlugin, JobSch

private CommandIndex commandIndex;
private JobDocument jobDocument;
private String indexName;

@Override
public Collection<Object> createComponents(
Expand All @@ -111,6 +110,7 @@ public Collection<Object> createComponents(
// NOTE it's very likely that client and thread pool may not be required as the command
// index
// repository already use them. All queries to the index should be under this class.
this.indexName = PluginSettings.getInstance().getJobIndexName();
CommandManagerJobRunner.getInstance()
.setClient(client)
.setThreadPool(threadPool)
Expand Down Expand Up @@ -163,15 +163,30 @@ public List<RestHandler> getRestHandlers(
Supplier<DiscoveryNodes> nodesInCluster) {
return Collections.singletonList(new RestPostCommandAction(this.commandIndex));
}

@Override
public List<Setting<?>> getSettings() {
return Arrays.asList(
// Register API settings
PluginSettings.TIMEOUT,
PluginSettings.JOB_PAGE_SIZE,
PluginSettings.JOB_SCHEDULE,
PluginSettings.JOB_KEEP_ALIVE,
PluginSettings.JOB_INDEX_NAME,
PluginSettings.JOB_INDEX_TEMPLATE,
PluginSettings.API_PREFIX,
PluginSettings.API_ENDPOINT,
PluginSettings.INDEX_NAME,
PluginSettings.INDEX_TEMPLATE
);
}
@Override
public String getJobType() {
return CommandManagerPlugin.JOB_TYPE;
}

@Override
public String getJobIndex() {
return PluginSettings.getInstance().getJobIndexName();
return this.indexName;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.opensearch.jobscheduler.spi.ScheduledJobRunner;
import org.opensearch.threadpool.ThreadPool;

import com.wazuh.commandmanager.CommandManagerPlugin;
import com.wazuh.commandmanager.index.CommandIndex;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.util.annotation.NonNull;

public class PluginSettings {
Expand All @@ -20,6 +22,7 @@ public class PluginSettings {
// Command Manager Index settings
public static final Setting<String> INDEX_NAME = Setting.simpleString("command_manager.index.name", Setting.Property.NodeScope, Setting.Property.Filtered);
public static final Setting<String> INDEX_TEMPLATE = Setting.simpleString("command_manager.index.template", Setting.Property.NodeScope, Setting.Property.Filtered);
private static final Logger log = LoggerFactory.getLogger(PluginSettings.class);

private final Integer timeout;
private final String jobSchedule;
Expand All @@ -34,7 +37,7 @@ public class PluginSettings {
private final String apiCommandsUri;
private final String apiBaseUri;

private static volatile PluginSettings instance;
private static PluginSettings instance;

/** Private default constructor */
private PluginSettings(@NonNull final Settings settings) {
Expand All @@ -51,6 +54,19 @@ private PluginSettings(@NonNull final Settings settings) {

this.apiBaseUri = BASE_PLUGINS_URI + apiPrefix;
this.apiCommandsUri = apiBaseUri + apiEndpoint;

log.info("[SETTINGS] Timeout: {}", this.timeout);
log.info("[SETTINGS] Job Schedule: {}", this.jobSchedule);
log.info("[SETTINGS] Job Page Size: {}", this.jobPageSize);
log.info("[SETTINGS] Job Keep Alive: {}", this.jobKeepAlive);
log.info("[SETTINGS] Job Index Name: {}", this.jobIndexName);
log.info("[SETTINGS] Job Index Template: {}", this.jobIndexTemplate);
log.info("[SETTINGS] API Prefix: {}", this.apiPrefix);
log.info("[SETTINGS] API Endpoint: {}", this.apiEndpoint);
log.info("[SETTINGS] API Base URI: {}", this.apiBaseUri);
log.info("[SETTINGS] API Commands URI: {}", this.apiCommandsUri);
log.info("[SETTINGS] Index Name: {}", this.indexName);
log.info("[SETTINGS] Index Template: {}", this.indexTemplate);
}

/**
Expand Down

0 comments on commit c94c182

Please sign in to comment.