Skip to content

Implement Content Updater JobScheduler #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 60 commits into
base: 6.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
db04746
Implement JobScheduler boilerplate
QU3B1M Apr 28, 2025
0905525
Add JobScheduler plugin to build.gradle
QU3B1M Apr 28, 2025
9b69a07
Update build.gradle to avoid duplicated plugins IDs
QU3B1M Apr 29, 2025
e0b66d9
Implement unit tests for ContentUpdaterJobParameters
QU3B1M Apr 29, 2025
742ac9f
Implement minimal required functionality to ContentUpdaterJobRunner
QU3B1M Apr 30, 2025
e0291fb
Add content manager logic
f-galland May 5, 2025
b4f847f
Load job-scheduler in tests
f-galland May 6, 2025
9f9f13e
Add plugin workflow logic to runnable
f-galland May 6, 2025
b5e50b2
Add streaming download method
f-galland May 6, 2025
8e2e56b
Include debug config in gradle
f-galland May 12, 2025
ee67948
Refactor to give CTIClient privileges
f-galland May 12, 2025
9c4779c
Move jvmArgs to bottom of method
f-galland May 13, 2025
5c2a358
Merge branch 'main' into enhancement/366-content-manager-job-scheduler
f-galland May 13, 2025
3870f65
Cleanup code after main merge
f-galland May 13, 2025
cf6a10e
Remove unneeded parameters
f-galland May 13, 2025
8e5acdd
Fix privileged
f-galland May 14, 2025
f56f321
Centralize offset comparisons to Runnable class
f-galland May 14, 2025
412ebe6
Fix singleton
f-galland May 15, 2025
0fd09ab
Fix context index creation upon initialization
f-galland May 15, 2025
d1924fe
Create indices for dev environments
f-galland May 15, 2025
60affcd
Use dev env variable
f-galland May 15, 2025
b56b85b
Fix tests
f-galland May 15, 2025
af28834
Fix SnapshotManager tests
f-galland May 16, 2025
6aa8b38
Fix link checker
f-galland May 16, 2025
8cbcd82
Merge branch '6.0.0' into enhancement/366-content-manager-job-scheduler
f-galland May 16, 2025
8615b85
Fix merge issues
f-galland May 16, 2025
71efeca
Fix gradle check after merge
f-galland May 16, 2025
41e9d91
Add ARCHIVE distribution to build.gradle
f-galland May 16, 2025
00d5ebc
Fix gradle check yet again
f-galland May 16, 2025
9508475
Add init tests
f-galland May 16, 2025
49d873f
Add tests
f-galland May 19, 2025
311ea8a
Add more tests
f-galland May 19, 2025
a5e04a7
Fix gradle check
f-galland May 20, 2025
9a60f7a
Add missing verify()
f-galland May 20, 2025
9617a84
Add missing javadocs
f-galland May 20, 2025
b9076e8
Add jobRunner tests
f-galland May 20, 2025
3d04131
Make CommandManagerClient injectable
f-galland May 20, 2025
e9b490a
Fix tests
f-galland May 20, 2025
3c9b656
Merge branch '6.0.0' into enhancement/366-content-manager-job-scheduler
f-galland May 20, 2025
63794f9
Merge changes from 6.0.0
f-galland May 20, 2025
a60869c
Fix tests after merge
f-galland May 20, 2025
b3a96f5
Delete old download method
f-galland May 21, 2025
7068691
Merge branch '6.0.0' into enhancement/366-content-manager-job-scheduler
AlexRuiz7 May 26, 2025
81930bb
Fix after merge
f-galland May 27, 2025
9b4f925
Use download()
f-galland May 27, 2025
1447817
Remove create()
f-galland May 27, 2025
095e57f
Switch to OpenSearchStatusException
f-galland May 27, 2025
3fba343
Fix tests
f-galland May 27, 2025
01e6f0c
Delete unused get() method
f-galland May 27, 2025
5d03a2d
Delete unused methods
f-galland May 27, 2025
6259c76
Make ContentUpdaterJobRunner a pseudo-builder
f-galland May 28, 2025
f4c723d
Make ContentUpdaterRunnable a pseudo-builder
f-galland May 28, 2025
7cbfce9
Remove unused wrapper
f-galland May 28, 2025
3b3dc0f
Remove privileged wrappers
f-galland May 28, 2025
a5f2134
Remove redundant constructor
f-galland May 28, 2025
ed59528
Fix links
f-galland May 28, 2025
a283c64
Merge branch '6.0.0' into enhancement/366-content-manager-job-scheduler
f-galland May 28, 2025
39adfe6
Merge branch '6.0.0' into enhancement/366-content-manager-job-scheduler
f-galland May 28, 2025
2fa23d8
Merge 6.0.0
f-galland May 28, 2025
c73b9a3
Fix after merge
f-galland May 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Implement RBAC "refresh" command [(#370)](https://github.com/wazuh/wazuh-indexer-plugins/pull/370)
- Implement content update using Json Patch operations [(#362)](https://github.com/wazuh/wazuh-indexer-plugins/pull/362)
- Implement CTI API client rate limit and enhanced response handling [(#363)](https://github.com/wazuh/wazuh-indexer-plugins/pull/363)
- Implement Content Updater JobScheduler [(#387)](https://github.com/wazuh/wazuh-indexer-plugins/pull/387)
- Add custom action to list modified plugins [(#388)](https://github.com/wazuh/wazuh-indexer-plugins/pull/388)
- Expose settings for the Content Manager plugin [(#395)](https://github.com/wazuh/wazuh-indexer-plugins/pull/395)
- Add content update to to the Content Manager init process [(#421)](https://github.com/wazuh/wazuh-indexer-plugins/pull/421)
Expand Down
2 changes: 1 addition & 1 deletion docs/ref/modules/command-manager/api-reference.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# API reference

Check the OpenAPI spec [here](https://github.com/wazuh/wazuh-indexer-plugins/blob/6.0.0/plugins/command-manager/openapi.yml).
Check the OpenAPI spec [here](https://github.com/wazuh/wazuh-indexer-plugins/blob/6.0.0/plugins/command-manager/openapi.yml).
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.action.index.IndexResponse;
import org.opensearch.transport.client.Client;
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
import org.opensearch.cluster.node.DiscoveryNodes;
import org.opensearch.cluster.service.ClusterService;
Expand All @@ -42,6 +41,7 @@
import org.opensearch.rest.*;
import org.opensearch.script.ScriptService;
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.transport.client.Client;
import org.opensearch.watcher.ResourceWatcherService;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import org.apache.logging.log4j.Logger;
import org.opensearch.action.bulk.BulkRequest;
import org.opensearch.action.index.IndexRequest;
import org.opensearch.transport.client.Client;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.index.shard.IndexingOperationListener;
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.transport.client.Client;

import java.io.IOException;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.transport.client.Client;
import org.opensearch.jobscheduler.spi.JobExecutionContext;
import org.opensearch.jobscheduler.spi.ScheduledJobParameter;
import org.opensearch.jobscheduler.spi.ScheduledJobRunner;
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.transport.client.Client;

import com.wazuh.commandmanager.index.CommandIndex;
import com.wazuh.commandmanager.settings.PluginSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.OpenSearchTimeoutException;
import org.opensearch.transport.client.Client;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.index.reindex.BulkByScrollResponse;
import org.opensearch.index.reindex.UpdateByQueryAction;
import org.opensearch.index.reindex.UpdateByQueryRequestBuilder;
import org.opensearch.script.Script;
import org.opensearch.script.ScriptType;
import org.opensearch.transport.client.Client;

import java.util.Collections;
import java.util.Locale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import org.apache.logging.log4j.Logger;
import org.opensearch.action.index.IndexRequest;
import org.opensearch.action.index.IndexResponse;
import org.opensearch.transport.client.Client;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule;
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.transport.client.Client;

import java.io.IOException;
import java.time.Instant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.transport.client.node.NodeClient;
import org.opensearch.core.xcontent.ToXContentObject;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.search.SearchHit;
import org.opensearch.search.SearchHits;
import org.opensearch.transport.client.node.NodeClient;

import java.io.IOException;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.transport.client.node.NodeClient;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.rest.BaseRestHandler;
import org.opensearch.rest.BytesRestResponse;
import org.opensearch.rest.RestRequest;
import org.opensearch.transport.client.node.NodeClient;

import java.io.IOException;
import java.util.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import org.apache.logging.log4j.Logger;
import org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequest;
import org.opensearch.action.support.clustermanager.AcknowledgedResponse;
import org.opensearch.transport.client.Client;
import org.opensearch.cluster.metadata.IndexTemplateMetadata;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.core.xcontent.DeprecationHandler;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.transport.client.Client;

import java.io.IOException;
import java.io.InputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import org.apache.logging.log4j.Logger;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.transport.client.support.AbstractClient;
import org.opensearch.core.action.ActionListener;
import org.opensearch.index.query.BoolQueryBuilder;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.search.SearchHits;
import org.opensearch.search.builder.SearchSourceBuilder;
import org.opensearch.transport.client.support.AbstractClient;

import java.util.*;
import java.util.concurrent.CountDownLatch;
Expand Down
56 changes: 31 additions & 25 deletions plugins/content-manager/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ buildscript {
ext {
opensearch_version = System.getProperty("opensearch.version", "3.0.0-SNAPSHOT")
opensearch_build = opensearch_version.replace("-SNAPSHOT","") + ".0"
job_scheduler_version = System.getProperty("job_scheduler.version", opensearch_build)
wazuh_version = System.getProperty("version", "6.0.0")
revision = System.getProperty("revision", "0")
}
Expand All @@ -26,7 +27,7 @@ apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'opensearch.opensearchplugin'
apply plugin: 'opensearch.yaml-rest-test'
apply plugin: 'opensearch.rest-test'
apply plugin: 'opensearch.pluginzip'
apply plugin: 'opensearch.java-agent'

Expand Down Expand Up @@ -70,6 +71,7 @@ opensearchplugin {
name pluginName
description pluginDescription
classname "${projectPath}.${pathToPlugin}.${pluginClassName}"
extendedPlugins = ['opensearch-job-scheduler']
licenseFile rootProject.file('LICENSE.txt')
noticeFile rootProject.file('NOTICE.txt')
}
Expand All @@ -90,6 +92,7 @@ dependencies {
// Uncomment this line to load the command-manager plugin from the local Maven repository.
// Keep it commented to allow GitHub Workflows to run the tests.
// zipArchive group: 'com.wazuh', name:'wazuh-indexer-command-manager', version: "${wazuh_version}.${revision}"
compileOnly "org.opensearch:opensearch-job-scheduler-spi:${job_scheduler_version}"
}

// No need to validate license headers since spotless checks and applies it
Expand Down Expand Up @@ -122,41 +125,44 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.9'
}

task integTest(type: RestIntegTestTask) {
description = "Run tests against a cluster"
testClassesDirs = sourceSets.test.output.classesDirs
classpath = sourceSets.test.runtimeClasspath
}
tasks.named("check").configure { dependsOn(integTest) }

integTest {
// The --debug-jvm command-line option makes the cluster debuggable; this makes the tests debuggable
if (System.getProperty("test.debug") != null) {
jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005'
}
environment "IS_DEV", System.getenv("IS_DEV") ?: "false"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the required indices are managed by the setup plugin I needed a way to enable creation of the indices only on development environments.

}

testClusters.integTest {
// add customized keystore
keystore 'indexer.username', 'admin'
keystore 'indexer.password', 'admin'
// Installs all registered zipArchive dependencies on integTest cluster nodes
configurations.zipArchive.asFileTree.each {
plugin(provider(new Callable<RegularFile>(){
@Override
RegularFile call() throws Exception {
return new RegularFile() {
@Override
File getAsFile() {
return it
}
testDistribution = "ARCHIVE"
// add customized keystore
keystore 'indexer.username', 'admin'
keystore 'indexer.password', 'admin'
// Installs all registered zipArchive dependencies on integTest cluster nodes
configurations.zipArchive.asFileTree.each {
plugin(provider(new Callable<RegularFile>(){
@Override
RegularFile call() throws Exception {
return new RegularFile() {
@Override
File getAsFile() {
return it
}
}
}))
}
}))
}
// This installs our plugin into the testClusters
plugin(project.tasks.bundlePlugin.archiveFile)
if (System.getProperty("cluster.debug") != null) {
def debugPort = 5005
nodes.forEach { node ->
node.jvmArgs("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:${debugPort}")
println "Debugging ${node.name} on port ${debugPort} — waiting for debugger to attach..."
debugPort += 1
}
testDistribution = "ARCHIVE"
// This installs our plugin into the testClusters
plugin(project.tasks.bundlePlugin.archiveFile)
}
environment "IS_DEV", System.getenv("IS_DEV") ?: "false"
}

run {
Expand Down
Loading