Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit 4c5a2b7

Browse files
authored
ODFE Release 1.8.0 (#124)
This PR made the following changes: 1. Update to JDK 14 2. Hack to overstep potential ES 7.7 bug when installing plugins for test cluster 3. Upgrade gradle, nebula and jacoco versions 4. Change how we register rest endpoint handler as required by ES 7.7 5. Impelement SystemIndexPlugin and register the descriptor according to elastic/elasticsearch#49959 6. added new version of job scheduler zip Testing done: 1. gralde build passes 2. Manually tested all public APIs
1 parent 16cef04 commit 4c5a2b7

15 files changed

+188
-84
lines changed

.github/workflows/test-workflow.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
build:
99
strategy:
1010
matrix:
11-
java: [13]
11+
java: [14]
1212
# Job name
1313
name: Build Anomaly detection with JDK ${{ matrix.java }}
1414
# This job runs on Linux

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Please see our [documentation](https://opendistro.github.io/for-elasticsearch-do
2222

2323
1. Checkout source code of this package from Github repo.
2424
1. Launch Intellij IDEA, Choose Import Project and select the settings.gradle file in the root of this package.
25-
1. To build from command line set JAVA_HOME to point to a JDK 13 before running ./gradlew
25+
1. To build from command line set JAVA_HOME to point to a JDK 14 before running ./gradlew
2626

2727
* Unix System
2828
* export JAVA_HOME=jdk-install-dir: Replace jdk-install-dir by the JAVA_HOME directory of your system.

build.gradle

+37-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616
buildscript {
1717
ext {
1818
es_group = "org.elasticsearch"
19-
es_version = '7.6.1'
19+
es_version = '7.7.0'
2020
}
2121

2222
repositories {
@@ -31,9 +31,10 @@ buildscript {
3131
}
3232

3333
plugins {
34-
id 'nebula.ospackage' version "8.2.0" apply false
34+
id 'nebula.ospackage' version "8.3.0" apply false
3535
id "com.diffplug.gradle.spotless" version "3.26.1"
3636
id 'java-library'
37+
id 'checkstyle'
3738
}
3839

3940
repositories {
@@ -43,7 +44,7 @@ repositories {
4344
}
4445

4546
ext {
46-
opendistroVersion = '1.7.0'
47+
opendistroVersion = '1.8.0'
4748
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
4849
}
4950

@@ -165,6 +166,30 @@ testClusters.integTest {
165166
}
166167
}
167168
plugin(fileTree("src/test/resources/job-scheduler").getSingleFile())
169+
170+
// As of ES 7.7.0 the opendistro-anomaly-detection plugin is being added to the list of plugins for the testCluster during build before
171+
// the opendistro-job-scheduler plugin, which is causing build failures. From the stack trace, this looks like a bug.
172+
//
173+
// Exception in thread "main" java.lang.IllegalArgumentException: Missing plugin [opendistro-job-scheduler], dependency of [opendistro-anomaly-detection]
174+
// at org.elasticsearch.plugins.PluginsService.addSortedBundle(PluginsService.java:452)
175+
//
176+
// One explanation is that ES build script sort plugins according to the natural ordering of their names.
177+
// opendistro-anomaly-detection comes before opendistro-job-scheduler.
178+
//
179+
// The following is a comparison of different plugin installation order:
180+
// Before 7.7:
181+
// ./bin/elasticsearch-plugin install --batch file:opendistro-anomaly-detection.zip file:opendistro-job-scheduler.zip
182+
//
183+
// After 7.7:
184+
// ./bin/elasticsearch-plugin install --batch file:opendistro-job-scheduler.zip file:opendistro-anomaly-detection.zip
185+
//
186+
// A temporary hack is to reorder the plugins list after evaluation but prior to task execution when the plugins are installed.
187+
nodes.each { node ->
188+
def plugins = node.plugins
189+
def firstPlugin = plugins.get(0)
190+
plugins.remove(0)
191+
plugins.add(firstPlugin)
192+
}
168193
}
169194

170195
run {
@@ -242,6 +267,10 @@ jacocoTestCoverageVerification {
242267
check.dependsOn jacocoTestCoverageVerification
243268
jacocoTestCoverageVerification.dependsOn jacocoTestReport
244269

270+
checkstyle {
271+
toolVersion = '8.20'
272+
}
273+
245274
dependencies {
246275
compile "org.elasticsearch:elasticsearch:${es_version}"
247276
compileOnly "org.elasticsearch.plugin:elasticsearch-scripting-painless-spi:${versions.elasticsearch}"
@@ -254,10 +283,10 @@ dependencies {
254283
compile group: 'com.yahoo.datasketches', name: 'memory', version: '0.12.2'
255284
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
256285

257-
compile "org.jacoco:org.jacoco.agent:0.8.3"
258-
compile "org.jacoco:org.jacoco.ant:0.8.3"
259-
compile "org.jacoco:org.jacoco.core:0.8.3"
260-
compile "org.jacoco:org.jacoco.report:0.8.3"
286+
compile "org.jacoco:org.jacoco.agent:0.8.5"
287+
compile "org.jacoco:org.jacoco.ant:0.8.5"
288+
compile "org.jacoco:org.jacoco.core:0.8.5"
289+
compile "org.jacoco:org.jacoco.report:0.8.5"
261290

262291
testCompile group: 'pl.pragmatists', name: 'JUnitParams', version: '1.1.1'
263292
testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.0.0'
+16-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1-
#Wed Mar 13 15:07:47 IST 2019
1+
/*
2+
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
216
distributionBase=GRADLE_USER_HOME
317
distributionPath=wrapper/dists
418
zipStoreBase=GRADLE_USER_HOME
519
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-bin.zip
20+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-all.zip

src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorPlugin.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@
104104
import org.elasticsearch.env.Environment;
105105
import org.elasticsearch.env.NodeEnvironment;
106106
import org.elasticsearch.monitor.jvm.JvmService;
107+
import org.elasticsearch.indices.SystemIndexDescriptor;
107108
import org.elasticsearch.plugins.ActionPlugin;
108109
import org.elasticsearch.plugins.Plugin;
109110
import org.elasticsearch.plugins.ScriptPlugin;
111+
import org.elasticsearch.plugins.SystemIndexPlugin;
110112
import org.elasticsearch.rest.RestController;
111113
import org.elasticsearch.rest.RestHandler;
112114
import org.elasticsearch.script.ScriptService;
@@ -130,7 +132,7 @@
130132
/**
131133
* Entry point of AD plugin.
132134
*/
133-
public class AnomalyDetectorPlugin extends Plugin implements ActionPlugin, ScriptPlugin, JobSchedulerExtension {
135+
public class AnomalyDetectorPlugin extends Plugin implements ActionPlugin, ScriptPlugin, JobSchedulerExtension, SystemIndexPlugin {
134136

135137
public static final String AD_BASE_URI = "/_opendistro/_anomaly_detection";
136138
public static final String AD_BASE_DETECTORS_URI = AD_BASE_URI + "/detectors";
@@ -241,7 +243,8 @@ public Collection<Object> createComponents(
241243
NamedXContentRegistry xContentRegistry,
242244
Environment environment,
243245
NodeEnvironment nodeEnvironment,
244-
NamedWriteableRegistry namedWriteableRegistry
246+
NamedWriteableRegistry namedWriteableRegistry,
247+
IndexNameExpressionResolver indexNameExpressionResolver
245248
) {
246249
this.client = client;
247250
this.threadPool = threadPool;
@@ -452,4 +455,17 @@ public ScheduledJobParser getJobParser() {
452455
};
453456
}
454457

458+
@Override
459+
public Collection<SystemIndexDescriptor> getSystemIndexDescriptors() {
460+
return Collections
461+
.unmodifiableList(
462+
Arrays
463+
.asList(
464+
new SystemIndexDescriptor(AnomalyDetectionIndices.ALL_AD_RESULTS_INDEX_PATTERN, "anomaly result"),
465+
new SystemIndexDescriptor(AnomalyDetector.ANOMALY_DETECTORS_INDEX, "detector definition"),
466+
new SystemIndexDescriptor(AnomalyDetectorJob.ANOMALY_DETECTOR_JOB_INDEX, "detector job"),
467+
new SystemIndexDescriptor(CommonName.CHECKPOINT_INDEX_NAME, "model checkpoint")
468+
)
469+
);
470+
}
455471
}

src/main/java/com/amazon/opendistroforelasticsearch/ad/ml/ModelManager.java

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public String getName() {
141141
* @param minPreviewSize minimum number of data points for preview
142142
* @param modelTtl time to live for hosted models
143143
* @param checkpointInterval interval between checkpoints
144+
* @param shingleSize required shingle size before RCF emitting anomaly scores
144145
*/
145146
public ModelManager(
146147
ClusterService clusterService,

src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/AbstractSearchAction.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package com.amazon.opendistroforelasticsearch.ad.rest;
1717

1818
import com.amazon.opendistroforelasticsearch.ad.model.AnomalyDetector;
19+
import com.google.common.collect.ImmutableList;
20+
1921
import org.apache.logging.log4j.LogManager;
2022
import org.apache.logging.log4j.Logger;
2123
import org.elasticsearch.action.search.SearchRequest;
@@ -39,6 +41,7 @@
3941
import org.elasticsearch.search.builder.SearchSourceBuilder;
4042

4143
import java.io.IOException;
44+
import java.util.List;
4245

4346
import static com.amazon.opendistroforelasticsearch.ad.util.RestHandlerUtils.getSourceContext;
4447
import static org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS;
@@ -52,14 +55,14 @@ public abstract class AbstractSearchAction<T extends ToXContentObject> extends B
5255

5356
private final String index;
5457
private final Class<T> clazz;
58+
private final String urlPath;
5559

5660
private final Logger logger = LogManager.getLogger(AbstractSearchAction.class);
5761

5862
public AbstractSearchAction(RestController controller, String urlPath, String index, Class<T> clazz) {
5963
this.index = index;
6064
this.clazz = clazz;
61-
controller.registerHandler(RestRequest.Method.POST, urlPath, this);
62-
controller.registerHandler(RestRequest.Method.GET, urlPath, this);
65+
this.urlPath = urlPath;
6366
}
6467

6568
@Override
@@ -102,4 +105,9 @@ public RestResponse buildResponse(SearchResponse response) throws Exception {
102105
}
103106
};
104107
}
108+
109+
@Override
110+
public List<Route> routes() {
111+
return ImmutableList.of(new Route(RestRequest.Method.POST, urlPath), new Route(RestRequest.Method.GET, urlPath));
112+
}
105113
}

src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestAnomalyDetectorJobAction.java

+20-16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import com.amazon.opendistroforelasticsearch.ad.AnomalyDetectorPlugin;
1919
import com.amazon.opendistroforelasticsearch.ad.indices.AnomalyDetectionIndices;
2020
import com.amazon.opendistroforelasticsearch.ad.rest.handler.IndexAnomalyDetectorJobActionHandler;
21+
import com.google.common.collect.ImmutableList;
22+
2123
import org.elasticsearch.action.support.WriteRequest;
2224
import org.elasticsearch.client.node.NodeClient;
2325
import org.elasticsearch.cluster.service.ClusterService;
@@ -29,6 +31,7 @@
2931
import org.elasticsearch.rest.RestRequest;
3032

3133
import java.io.IOException;
34+
import java.util.List;
3235
import java.util.Locale;
3336

3437
import static com.amazon.opendistroforelasticsearch.ad.settings.AnomalyDetectorSettings.REQUEST_TIMEOUT;
@@ -61,22 +64,6 @@ public RestAnomalyDetectorJobAction(
6164
this.requestTimeout = REQUEST_TIMEOUT.get(settings);
6265
this.clusterService = clusterService;
6366
clusterService.getClusterSettings().addSettingsUpdateConsumer(REQUEST_TIMEOUT, it -> requestTimeout = it);
64-
65-
// start AD job
66-
controller
67-
.registerHandler(
68-
RestRequest.Method.POST,
69-
String.format(Locale.ROOT, "%s/{%s}/%s", AnomalyDetectorPlugin.AD_BASE_DETECTORS_URI, DETECTOR_ID, START_JOB),
70-
this
71-
);
72-
73-
// stop AD job
74-
controller
75-
.registerHandler(
76-
RestRequest.Method.POST,
77-
String.format(Locale.ROOT, "%s/{%s}/%s", AnomalyDetectorPlugin.AD_BASE_DETECTORS_URI, DETECTOR_ID, STOP_JOB),
78-
this
79-
);
8067
}
8168

8269
@Override
@@ -116,4 +103,21 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
116103
}
117104
};
118105
}
106+
107+
@Override
108+
public List<Route> routes() {
109+
return ImmutableList
110+
.of(
111+
// start AD job
112+
new Route(
113+
RestRequest.Method.POST,
114+
String.format(Locale.ROOT, "%s/{%s}/%s", AnomalyDetectorPlugin.AD_BASE_DETECTORS_URI, DETECTOR_ID, START_JOB)
115+
),
116+
// stop AD job
117+
new Route(
118+
RestRequest.Method.POST,
119+
String.format(Locale.ROOT, "%s/{%s}/%s", AnomalyDetectorPlugin.AD_BASE_DETECTORS_URI, DETECTOR_ID, STOP_JOB)
120+
)
121+
);
122+
}
119123
}

src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestDeleteAnomalyDetectorAction.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.amazon.opendistroforelasticsearch.ad.model.AnomalyDetector;
1919
import com.amazon.opendistroforelasticsearch.ad.model.AnomalyDetectorJob;
2020
import com.amazon.opendistroforelasticsearch.ad.rest.handler.AnomalyDetectorActionHandler;
21+
import com.google.common.collect.ImmutableList;
2122
import com.amazon.opendistroforelasticsearch.ad.AnomalyDetectorPlugin;
2223
import org.apache.logging.log4j.LogManager;
2324
import org.apache.logging.log4j.Logger;
@@ -36,6 +37,7 @@
3637
import org.elasticsearch.rest.action.RestStatusToXContentListener;
3738

3839
import java.io.IOException;
40+
import java.util.List;
3941
import java.util.Locale;
4042

4143
import static com.amazon.opendistroforelasticsearch.ad.util.RestHandlerUtils.DETECTOR_ID;
@@ -53,13 +55,6 @@ public class RestDeleteAnomalyDetectorAction extends BaseRestHandler {
5355

5456
public RestDeleteAnomalyDetectorAction(RestController controller, ClusterService clusterService) {
5557
this.clusterService = clusterService;
56-
// delete anomaly detector document
57-
controller
58-
.registerHandler(
59-
RestRequest.Method.DELETE,
60-
String.format(Locale.ROOT, "%s/{%s}", AnomalyDetectorPlugin.AD_BASE_DETECTORS_URI, DETECTOR_ID),
61-
this
62-
);
6358
}
6459

6560
@Override
@@ -115,4 +110,15 @@ private void deleteAnomalyDetectorDoc(NodeClient client, String detectorId, Rest
115110
client.delete(deleteRequest, new RestStatusToXContentListener<>(channel));
116111
}
117112

113+
@Override
114+
public List<Route> routes() {
115+
return ImmutableList
116+
.of(
117+
// delete anomaly detector document
118+
new Route(
119+
RestRequest.Method.DELETE,
120+
String.format(Locale.ROOT, "%s/{%s}", AnomalyDetectorPlugin.AD_BASE_DETECTORS_URI, DETECTOR_ID)
121+
)
122+
);
123+
}
118124
}

0 commit comments

Comments
 (0)