Skip to content

Commit

Permalink
Migrate to OpenSearch (#1)
Browse files Browse the repository at this point in the history
* Migrate to OpenSearch
  • Loading branch information
skkosuri-amzn authored Apr 16, 2021
1 parent ac7d3ad commit 46a2829
Show file tree
Hide file tree
Showing 30 changed files with 294 additions and 255 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Open Distro for Elasticsearch Job Scheduler
# OpenSearch Job Scheduler

Open Distro for Elasticsearch JobScheduler plugin provides a framework for Elasticsearch plugin
developers to schedule periodical jobs running within Elasticsearch nodes. You can schedule jobs
OpenSearch JobSchedule plugin provides a framework for OpenSearch plugin
developers to schedule periodical jobs running within OpenSearch nodes. You can schedule jobs
by specify an interval, or using Unix Cron expression to define more flexible schedule to execute
your job.

Elasticsearch plugin developers can easily extend JobScheduler plugin to schedule jobs like running
OpenSearch plugin developers can easily extend JobScheduler plugin to schedule jobs like running
aggregation query against raw data and save the aggregated data into a new index every hour, or keep
monitoring the shard allocation by calling Elasticsearch API and post the output to a Webhook.
monitoring the shard allocation by calling OpenSearch API and post the output to a Webhook.

## Build
The JobScheduler plugin uses the [Gradle](https://docs.gradle.org/4.10.2/userguide/userguide.html)
Expand All @@ -23,7 +23,7 @@ Once you have built the plugin from source code, run
```bash
elasticsearch-plugin install file://${PLUGIN_ZIP_FILE_PATH}
```
to install the JobScheduler plugin to your Elasticsearch.
to install the JobScheduler plugin to your OpenSearch.

## Develop a plugin that extends JobScheduler
JobScheduler plugin provides a SPI for other plugins to implement. Essentially, you need to
Expand Down
31 changes: 24 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@

buildscript {
ext {
es_version = System.getProperty("es.version", "7.10.2")
opensearch_version = System.getProperty("opensearch.version", "7.10.3")
}

repositories {
maven {
url = 's3://search-vemsarat/'
credentials(AwsCredentials) {
accessKey = System.env.AWS_ACCESS_KEY_ID ?: findProperty('aws_access_key_id')
secretKey = System.env.AWS_SECRET_ACCESS_KEY ?: findProperty('aws_secret_access_key')
}
}
mavenCentral()
}

dependencies {
classpath "org.elasticsearch.gradle:build-tools:${es_version}"
classpath "org.opensearch.gradle:build-tools:${opensearch_version}-SNAPSHOT"
}
}

Expand All @@ -37,9 +44,9 @@ ext {
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
}

apply plugin: 'elasticsearch.esplugin'
apply plugin: 'elasticsearch.testclusters'
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'opensearch.opensearchplugin'
apply plugin: 'opensearch.testclusters'
apply plugin: 'opensearch.java-rest-test'

ext {
projectSubstitutions = [:]
Expand All @@ -58,7 +65,7 @@ forbiddenApisTest.ignoreFailures = true
validateNebulaPom.enabled = false
loggerUsageCheck.enabled = false

esplugin {
opensearchplugin {
name 'opendistro-job-scheduler'
description 'Open Distro for Elasticsearch job schduler plugin'
classname 'com.amazon.opendistroforelasticsearch.jobscheduler.JobSchedulerPlugin'
Expand Down Expand Up @@ -89,6 +96,16 @@ allprojects {
}
}

repositories {
maven {
url = 's3://search-vemsarat/'
credentials(AwsCredentials) {
accessKey = System.env.AWS_ACCESS_KEY_ID ?: findProperty('aws_access_key_id')
secretKey = System.env.AWS_SECRET_ACCESS_KEY ?: findProperty('aws_secret_access_key')
}
}
}

dependencies {
compile project(path: ":${rootProject.name}-spi", configuration: 'shadow')
javaRestTestImplementation project.sourceSets.main.runtimeClasspath
Expand All @@ -106,7 +123,7 @@ afterEvaluate {

into '/usr/share/elasticsearch/plugins'
from(zipTree(bundlePlugin.archivePath)) {
into esplugin.name
into opensearchplugin.name
}

user 'root'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# permissions and limitations under the License.
#

version = 1.13.0
version = 1.15.0
20 changes: 16 additions & 4 deletions sample-extension-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
* permissions and limitations under the License.
*/

apply plugin: 'elasticsearch.esplugin'
apply plugin: 'elasticsearch.testclusters'
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'opensearch.opensearchplugin'
apply plugin: 'opensearch.testclusters'
apply plugin: 'opensearch.java-rest-test'

esplugin {

opensearchplugin {
name 'opendistro-job-scheduler-sample-extension'
description 'Sample plugin that extends OpenDistro JobSchedulerPlugin'
classname 'com.amazon.opendistroforelasticsearch.jobscheduler.sampleextension.SampleExtensionPlugin'
Expand All @@ -30,6 +31,17 @@ ext {
noticeFile = rootProject.file('NOTICE.txt')
}

repositories {
maven {
url = 's3://search-vemsarat/'
credentials(AwsCredentials) {
accessKey = System.env.AWS_ACCESS_KEY_ID ?: findProperty('aws_access_key_id')
secretKey = System.env.AWS_ACCESS_KEY_ID ?: findProperty('aws_secret_access_key')
}
}
mavenCentral()
}

dependencies {
compileOnly project(path: ":${rootProject.name}-spi", configuration: 'shadow')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@
import com.amazon.opendistroforelasticsearch.jobscheduler.spi.schedule.ScheduleParser;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParserUtils;
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.repositories.RepositoriesService;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.watcher.ResourceWatcherService;
import org.opensearch.client.Client;
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
import org.opensearch.cluster.node.DiscoveryNodes;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.io.stream.NamedWriteableRegistry;
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.xcontent.NamedXContentRegistry;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentParserUtils;
import org.opensearch.env.Environment;
import org.opensearch.env.NodeEnvironment;
import org.opensearch.plugins.ActionPlugin;
import org.opensearch.plugins.Plugin;
import org.opensearch.repositories.RepositoriesService;
import org.opensearch.rest.RestController;
import org.opensearch.rest.RestHandler;
import org.opensearch.script.ScriptService;
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.watcher.ResourceWatcherService;

import java.io.IOException;
import java.time.Instant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
package com.amazon.opendistroforelasticsearch.jobscheduler.sampleextension;

import com.amazon.opendistroforelasticsearch.jobscheduler.spi.schedule.IntervalSchedule;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.RestStatus;
import org.opensearch.action.ActionListener;
import org.opensearch.action.delete.DeleteRequest;
import org.opensearch.action.delete.DeleteResponse;
import org.opensearch.action.index.IndexRequest;
import org.opensearch.action.index.IndexResponse;
import org.opensearch.client.node.NodeClient;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.rest.BaseRestHandler;
import org.opensearch.rest.BytesRestResponse;
import org.opensearch.rest.RestRequest;
import org.opensearch.rest.RestResponse;
import org.opensearch.rest.RestStatus;

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

import com.amazon.opendistroforelasticsearch.jobscheduler.spi.ScheduledJobParameter;
import com.amazon.opendistroforelasticsearch.jobscheduler.spi.schedule.Schedule;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentBuilder;

import java.io.IOException;
import java.time.Instant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import com.amazon.opendistroforelasticsearch.jobscheduler.spi.utils.LockService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.threadpool.ThreadPool;
import org.opensearch.action.ActionListener;
import org.opensearch.cluster.routing.ShardRouting;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.plugins.Plugin;
import org.opensearch.threadpool.ThreadPool;

import java.util.List;

Expand All @@ -35,7 +35,7 @@
* The job runner should be a singleton class if it uses Elasticsearch client or other objects passed
* from Elasticsearch. Because when registering the job runner to JobScheduler plugin, Elasticsearch has
* not invoke plugins' createComponents() method. That is saying the plugin is not completely initalized,
* and the Elasticsearch {@link org.elasticsearch.client.Client}, {@link ClusterService} and other objects
* and the Elasticsearch {@link org.opensearch.client.Client}, {@link ClusterService} and other objects
* are not available to plugin and this job runner.
*
* So we have to move this job runner intialization to {@link Plugin} createComponents() method, and using
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@

package com.amazon.opendistroforelasticsearch.jobscheduler.smapleextension;

import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.plugins.PluginInfo;
import org.elasticsearch.test.ESIntegTestCase;
import org.opensearch.action.admin.cluster.health.ClusterHealthRequest;
import org.opensearch.action.admin.cluster.health.ClusterHealthResponse;
import org.opensearch.action.admin.cluster.node.info.NodesInfoRequest;
import org.opensearch.action.admin.cluster.node.info.NodesInfoResponse;
import org.opensearch.action.admin.cluster.node.info.PluginsAndModules;
import org.opensearch.cluster.health.ClusterHealthStatus;
import org.opensearch.plugins.PluginInfo;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.junit.Assert;

import java.util.List;

public class SampleExtensionPluginIT extends ESIntegTestCase {
public class SampleExtensionPluginIT extends OpenSearchIntegTestCase {

public void testPluginsAreInstalled() {
ClusterHealthRequest request = new ClusterHealthRequest();
ClusterHealthResponse response = ESIntegTestCase.client().admin().cluster().health(request).actionGet();
ClusterHealthResponse response = OpenSearchIntegTestCase.client().admin().cluster().health(request).actionGet();
Assert.assertEquals(ClusterHealthStatus.GREEN, response.getStatus());

NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
nodesInfoRequest.addMetric(NodesInfoRequest.Metric.PLUGINS.metricName());
NodesInfoResponse nodesInfoResponse = ESIntegTestCase.client().admin().cluster().nodesInfo(nodesInfoRequest)
NodesInfoResponse nodesInfoResponse = OpenSearchIntegTestCase.client().admin().cluster().nodesInfo(nodesInfoRequest)
.actionGet();
List<PluginInfo> pluginInfos = nodesInfoResponse.getNodes().get(0).getInfo(PluginsAndModules.class).getPluginInfos();
Assert.assertTrue(pluginInfos.stream().anyMatch(pluginInfo -> pluginInfo.getName()
Expand Down
24 changes: 17 additions & 7 deletions spi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* permissions and limitations under the License.
*/
import com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin
import org.elasticsearch.gradle.test.RestIntegTestTask
import org.opensearch.gradle.test.RestIntegTestTask

plugins {
id 'com.github.johnrengelman.shadow'
Expand All @@ -23,9 +23,19 @@ plugins {
id 'signing'
}

apply plugin: 'elasticsearch.java'
apply plugin: 'elasticsearch.testclusters'
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'opensearch.java'
apply plugin: 'opensearch.testclusters'
apply plugin: 'opensearch.java-rest-test'

repositories {
maven {
url = 's3://search-vemsarat/'
credentials(AwsCredentials) {
accessKey = System.env.AWS_ACCESS_KEY_ID ?: findProperty('aws_access_key_id')
secretKey = System.env.AWS_SECRET_ACCESS_KEY ?: findProperty('aws_secret_access_key')
}
}
}

ext {
projectSubstitutions = [:]
Expand All @@ -48,10 +58,10 @@ jacocoTestReport {
check.dependsOn jacocoTestReport

dependencies {
compileOnly "org.elasticsearch:elasticsearch:${es_version}"
compileOnly "org.opensearch:opensearch:${opensearch_version}-SNAPSHOT"
compile "com.cronutils:cron-utils:9.1.3"

testImplementation "org.elasticsearch.test:framework:${es_version}"
testImplementation "org.opensearch.test:framework:${opensearch_version}-SNAPSHOT"
testImplementation "org.apache.logging.log4j:log4j-core:${versions.log4j}"
}

Expand All @@ -74,7 +84,7 @@ test {
}

task integTest(type: RestIntegTestTask) {
description 'Run integ test with elasticsearch test framework'
description 'Run integ test with opensearch test framework'
group 'verification'
systemProperty 'tests.security.manager', 'false'
dependsOn test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

package com.amazon.opendistroforelasticsearch.jobscheduler.spi;

import org.elasticsearch.common.Strings;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParserUtils;
import org.elasticsearch.index.seqno.SequenceNumbers;
import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.ToXContentObject;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentParserUtils;
import org.opensearch.index.seqno.SequenceNumbers;

import java.io.IOException;
import java.time.Instant;
Expand Down Expand Up @@ -49,8 +49,8 @@ public final class LockModel implements ToXContentObject {
* Use this constructor to copy existing lock and update the seqNo and primaryTerm.
*
* @param copyLock JobSchedulerLockModel to copy from.
* @param seqNo sequence number from Elasticsearch document.
* @param primaryTerm primary term from Elasticsearch document.
* @param seqNo sequence number from OpenSearch document.
* @param primaryTerm primary term from OpenSearch document.
*/
public LockModel(final LockModel copyLock, long seqNo, long primaryTerm) {
this(copyLock.jobIndexName, copyLock.jobId, copyLock.lockTime, copyLock.lockDurationSeconds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.amazon.opendistroforelasticsearch.jobscheduler.spi;

import com.amazon.opendistroforelasticsearch.jobscheduler.spi.schedule.Schedule;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.opensearch.common.xcontent.ToXContentObject;

import java.time.Instant;

Expand Down
Loading

0 comments on commit 46a2829

Please sign in to comment.