From d0894cb5d658ed20638c6824efecf90003cb50c5 Mon Sep 17 00:00:00 2001 From: Sarat Date: Tue, 13 Oct 2020 17:07:15 -0700 Subject: [PATCH 1/3] Adding User support for AD and ADJob --- build.gradle | 3 ++ libs/common-utils-1.10.1.0.jar | Bin 0 -> 16868 bytes .../ad/AnomalyDetectorJobRunner.java | 3 +- .../ad/model/AnomalyDetector.java | 33 +++++++++++++- .../ad/model/AnomalyDetectorJob.java | 32 ++++++++++++- .../IndexAnomalyDetectorActionHandler.java | 3 +- .../IndexAnomalyDetectorJobActionHandler.java | 9 ++-- .../ad/AnomalyDetectorJobRunnerTests.java | 3 +- .../ad/AnomalyDetectorRestTestCase.java | 6 ++- .../ad/TestHelpers.java | 25 ++++++++--- .../ad/model/AnomalyDetectorTests.java | 27 +++++++---- .../ad/rest/AnomalyDetectorRestApiIT.java | 42 +++++++++--------- 12 files changed, 139 insertions(+), 47 deletions(-) create mode 100644 libs/common-utils-1.10.1.0.jar diff --git a/build.gradle b/build.gradle index cf142b6a..45b856e0 100644 --- a/build.gradle +++ b/build.gradle @@ -298,6 +298,8 @@ dependencies { compile "org.elasticsearch:elasticsearch:${es_version}" compileOnly "org.elasticsearch.plugin:elasticsearch-scripting-painless-spi:${versions.elasticsearch}" compileOnly "com.amazon.opendistroforelasticsearch:opendistro-job-scheduler-spi:1.10.1.1" + // Will be moved to Maven Depedency when https://github.com/opendistro-for-elasticsearch/common-utils repo publishes a release + compile files('libs/common-utils-1.10.1.0.jar') compile group: 'com.google.guava', name: 'guava', version:'15.0' compile group: 'org.apache.commons', name: 'commons-math3', version: '3.6.1' compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5' @@ -306,6 +308,7 @@ dependencies { compile group: 'commons-lang', name: 'commons-lang', version: '2.6' compile 'software.amazon.randomcutforest:randomcutforest-core:1.0' compile 'software.amazon.randomcutforest:randomcutforest-serialization-json:1.0' + compile "org.elasticsearch.client:elasticsearch-rest-client:${es_version}" compile "org.jacoco:org.jacoco.agent:0.8.5" compile ("org.jacoco:org.jacoco.ant:0.8.5") { diff --git a/libs/common-utils-1.10.1.0.jar b/libs/common-utils-1.10.1.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..240e655bb6e12d3b5832a18b0a301a26fc95583c GIT binary patch literal 16868 zcmb_@18`>BwsmaVwr$(CZQI>p$4SSwZJQmdV>{_s9VdVK;+=c?y?5%rx8AJUyY^SL z));Gld(DNp=1`CZ27v+qfPetlv658;_%NVfw-1B-xMW3D1ZgGZ#OQ$m6#i7O?i0{C z_D2ECj|=5r3(5-0Ns5UotI)}c-N=rQ$w<@E&A>|2QcaFe)hjW4XWrW1*$4U;u(jV< zK|a8Y?QQ==_FnZUZ)WdgYGdf^VrlGbYUpHa z@s}uc|KBJdO}DkTbN)*-_J14A(ACAl)!EePzrk8DN#PxSd@wCA008Cx99HlHU-biD z$<)!+)Y(PI)zZeq)QQgc;}3GKRI!yu7DVtvgIdJ<@{KYtPXREO{>NiLxSGlaV`us;qvnG4iJA6 z3)DDuSDiH_41w)- zK%gLu;z~CLttvLV!NmBaY!#Y1M%^G;JQSP1t_wqeVn~A8rxh3CIhUwyF(g)oF$Twm z=QK4Z-jdiz)?_X@B6~7PNm-8MyVWv@9VS_}YPJ5J>X?dVOlr&iepTp29GziUu!~TY zWr~QwN0u>Gf?!wedC?io-IT9Jxj3W0U?PTG^p<<+SCjUiIGy&1!0zX4%91(meQ=q zcJ$?1dl9WY8Mzk@Na`})76o{clzEnA=+HMxSo)6sNwUzi%2tt@>;;Xn8zJo^&?da3 zt3DT#zJO!x3+e?~hu7INce!|8F$EDIBhDmK`M|F#4gkn|oQ?6J&mI8ZS%G_w?h)dn zuG8vdR1Ubk^jbR4Q|XVW5BT#wVfWijb~Z#&pKF{Ww@EAyRlYp)m%P?U!1eVa5Ju;q z=SvU^FED7f^1?8|g26dv^sx{&8x-l8qdDK&#}5-v-blQH{V}}#8f{>3`0hDi008Fk z000F4bHDoKQ~&THO-KWjdCWJxx)Bq0V1HPUe2G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1Lpo_7=o_qD)YWb@(TYy2mI5ME!QS`oIAVrOjOlVP%|yvNH^# zYNDQ1lEW0D$4Ja$Ks1FB46pW@lxJ3=vkhqzYQKbEy#1AJKiVikt0Ki-y19R5RX#Q^ zjBr=xaX8Ypl$|HNuDLW4N59I3BQ;pHb3IjLnUZTiOb2$W+F2pS&e7a-wJ`u>NXx}) zO^Yt09twM~IX1Qr>FQ`c3k zwX?yz7r1W*Fl1sr4K=5orl?()nMXR`6!mh~OL5s4moUd+0*J7^-ilG9A~lqI6gq9( z?ICWw_Q_h}TNfqFGkm1sozCVNl5hh7HJiH2B!dAP&;IwlXpS8_$s_E22(%qky-0C4t8y7q^L_xEbQYj}SZ{$&OJlppv1lK%dS zqW51Bei!Bb67K%pei6HUJpPjL{#A`%GTy)2uNr9|kH2dCL)80M70Lct?{Duo_~(j$ zA@Thy%wH1UzuT|IKm-1%F@J&iPr>hBVgC~R{(-IeZ)5+L{P%Z~-{rsmq$%*P`OiuI zN(}sa1Af;@{?Pyk(0}(I{I9qCLpAw3-S7F&f6!%rq>ubd@A?1uVE{K1~~;eY?$_xm41I=>VCzS#bQ(3tfHNWO#_@m3|BrQ# Xf;8yIw&K^=j{t!6@zlWm>(~DS@Gx>b literal 0 HcmV?d00001 diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorJobRunner.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorJobRunner.java index 28348bc4..bba4086d 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorJobRunner.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorJobRunner.java @@ -381,7 +381,8 @@ private void stopAdJob(String detectorId) { job.getEnabledTime(), Instant.now(), Instant.now(), - job.getLockDurationSeconds() + job.getLockDurationSeconds(), + job.getUser() ); IndexRequest indexRequest = new IndexRequest(AnomalyDetectorJob.ANOMALY_DETECTOR_JOB_INDEX) .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/model/AnomalyDetector.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/model/AnomalyDetector.java index 50083b02..bffed915 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/model/AnomalyDetector.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/model/AnomalyDetector.java @@ -45,6 +45,7 @@ import com.amazon.opendistroforelasticsearch.ad.annotation.Generated; import com.amazon.opendistroforelasticsearch.ad.util.ParseUtils; +import com.amazon.opendistroforelasticsearch.commons.authuser.User; import com.google.common.base.Objects; /** @@ -76,6 +77,7 @@ public class AnomalyDetector implements Writeable, ToXContentObject { private static final String SHINGLE_SIZE_FIELD = "shingle_size"; private static final String LAST_UPDATE_TIME_FIELD = "last_update_time"; public static final String UI_METADATA_FIELD = "ui_metadata"; + public static final String USER_FIELD = "user"; private final String detectorId; private final Long version; @@ -91,6 +93,7 @@ public class AnomalyDetector implements Writeable, ToXContentObject { private final Map uiMetadata; private final Integer schemaVersion; private final Instant lastUpdateTime; + private User user; /** * Constructor function. @@ -109,6 +112,7 @@ public class AnomalyDetector implements Writeable, ToXContentObject { * @param uiMetadata metadata used by Kibana * @param schemaVersion anomaly detector index mapping version * @param lastUpdateTime detector's last update time + * @param user user to which detector is associated */ public AnomalyDetector( String detectorId, @@ -124,7 +128,8 @@ public AnomalyDetector( Integer shingleSize, Map uiMetadata, Integer schemaVersion, - Instant lastUpdateTime + Instant lastUpdateTime, + User user ) { if (Strings.isBlank(name)) { throw new IllegalArgumentException("Detector name should be set"); @@ -155,6 +160,7 @@ public AnomalyDetector( this.uiMetadata = uiMetadata; this.schemaVersion = schemaVersion; this.lastUpdateTime = lastUpdateTime; + this.user = user; } public AnomalyDetector(StreamInput input) throws IOException { @@ -188,6 +194,11 @@ public AnomalyDetector(StreamInput input) throws IOException { uiMetadata = input.readMap(); schemaVersion = input.readInt(); lastUpdateTime = input.readInstant(); + if (input.readBoolean()) { + this.user = new User(input); + } else { + user = null; + } } public XContentBuilder toXContent(XContentBuilder builder) throws IOException { @@ -210,6 +221,12 @@ public void writeTo(StreamOutput output) throws IOException { output.writeMap(uiMetadata); output.writeInt(schemaVersion); output.writeInstant(lastUpdateTime); + if (user != null) { + output.writeBoolean(true); // user exists + user.writeTo(output); + } else { + output.writeBoolean(false); // user does not exist + } } @Override @@ -236,6 +253,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws if (lastUpdateTime != null) { xContentBuilder.timeField(LAST_UPDATE_TIME_FIELD, LAST_UPDATE_TIME_FIELD, lastUpdateTime.toEpochMilli()); } + if (user != null) { + xContentBuilder.field(USER_FIELD, user); + } return xContentBuilder.endObject(); } @@ -303,6 +323,7 @@ public static AnomalyDetector parse( int schemaVersion = 0; Map uiMetadata = null; Instant lastUpdateTime = null; + User user = null; ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation); while (parser.nextToken() != XContentParser.Token.END_OBJECT) { @@ -359,6 +380,9 @@ public static AnomalyDetector parse( case LAST_UPDATE_TIME_FIELD: lastUpdateTime = ParseUtils.toInstant(parser); break; + case USER_FIELD: + user = User.parse(parser); + break; default: parser.skipChildren(); break; @@ -378,7 +402,8 @@ public static AnomalyDetector parse( shingleSize, uiMetadata, schemaVersion, - lastUpdateTime + lastUpdateTime, + user ); } @@ -498,4 +523,8 @@ public Instant getLastUpdateTime() { return lastUpdateTime; } + public User getUser() { + return user; + } + } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/model/AnomalyDetectorJob.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/model/AnomalyDetectorJob.java index d430daf2..096c7256 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/model/AnomalyDetectorJob.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/model/AnomalyDetectorJob.java @@ -31,6 +31,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import com.amazon.opendistroforelasticsearch.ad.util.ParseUtils; +import com.amazon.opendistroforelasticsearch.commons.authuser.User; import com.amazon.opendistroforelasticsearch.jobscheduler.spi.ScheduledJobParameter; import com.amazon.opendistroforelasticsearch.jobscheduler.spi.schedule.CronSchedule; import com.amazon.opendistroforelasticsearch.jobscheduler.spi.schedule.IntervalSchedule; @@ -64,6 +65,7 @@ enum ScheduleType { private static final String IS_ENABLED_FIELD = "enabled"; private static final String ENABLED_TIME_FIELD = "enabled_time"; private static final String DISABLED_TIME_FIELD = "disabled_time"; + public static final String USER_FIELD = "user"; private final String name; private final Schedule schedule; @@ -73,6 +75,7 @@ enum ScheduleType { private final Instant disabledTime; private final Instant lastUpdateTime; private final Long lockDurationSeconds; + private final User user; public AnomalyDetectorJob( String name, @@ -82,7 +85,8 @@ public AnomalyDetectorJob( Instant enabledTime, Instant disabledTime, Instant lastUpdateTime, - Long lockDurationSeconds + Long lockDurationSeconds, + User user ) { this.name = name; this.schedule = schedule; @@ -92,6 +96,7 @@ public AnomalyDetectorJob( this.disabledTime = disabledTime; this.lastUpdateTime = lastUpdateTime; this.lockDurationSeconds = lockDurationSeconds; + this.user = user; } public AnomalyDetectorJob(StreamInput input) throws IOException { @@ -107,6 +112,11 @@ public AnomalyDetectorJob(StreamInput input) throws IOException { disabledTime = input.readInstant(); lastUpdateTime = input.readInstant(); lockDurationSeconds = input.readLong(); + if (input.readBoolean()) { + user = new User(input); + } else { + user = null; + } } @Override @@ -123,6 +133,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws if (disabledTime != null) { xContentBuilder.field(DISABLED_TIME_FIELD, disabledTime.toEpochMilli()); } + if (user != null) { + xContentBuilder.field(USER_FIELD, user); + } return xContentBuilder.endObject(); } @@ -140,6 +153,12 @@ public void writeTo(StreamOutput output) throws IOException { output.writeInstant(disabledTime); output.writeInstant(lastUpdateTime); output.writeLong(lockDurationSeconds); + if (user != null) { + output.writeBoolean(true); // user exists + user.writeTo(output); + } else { + output.writeBoolean(false); // user does not exist + } } public static AnomalyDetectorJob parse(XContentParser parser) throws IOException { @@ -152,6 +171,7 @@ public static AnomalyDetectorJob parse(XContentParser parser) throws IOException Instant disabledTime = null; Instant lastUpdateTime = null; Long lockDurationSeconds = DEFAULT_AD_JOB_LOC_DURATION_SECONDS; + User user = null; ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation); while (parser.nextToken() != XContentParser.Token.END_OBJECT) { @@ -183,6 +203,9 @@ public static AnomalyDetectorJob parse(XContentParser parser) throws IOException case LOCK_DURATION_SECONDS: lockDurationSeconds = parser.longValue(); break; + case USER_FIELD: + user = User.parse(parser); + break; default: parser.skipChildren(); break; @@ -196,7 +219,8 @@ public static AnomalyDetectorJob parse(XContentParser parser) throws IOException enabledTime, disabledTime, lastUpdateTime, - lockDurationSeconds + lockDurationSeconds, + user ); } @@ -258,4 +282,8 @@ public Instant getLastUpdateTime() { public Long getLockDurationSeconds() { return lockDurationSeconds; } + + public User getUser() { + return user; + } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/handler/IndexAnomalyDetectorActionHandler.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/handler/IndexAnomalyDetectorActionHandler.java index 942e9ae1..3d4ed289 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/handler/IndexAnomalyDetectorActionHandler.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/handler/IndexAnomalyDetectorActionHandler.java @@ -302,7 +302,8 @@ private void indexAnomalyDetector(String detectorId) throws IOException { anomalyDetector.getShingleSize(), anomalyDetector.getUiMetadata(), anomalyDetector.getSchemaVersion(), - Instant.now() + Instant.now(), + anomalyDetector.getUser() ); IndexRequest indexRequest = new IndexRequest(ANOMALY_DETECTORS_INDEX) .setRefreshPolicy(refreshPolicy) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/handler/IndexAnomalyDetectorJobActionHandler.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/handler/IndexAnomalyDetectorJobActionHandler.java index 4cf0894c..ce4db89e 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/handler/IndexAnomalyDetectorJobActionHandler.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/handler/IndexAnomalyDetectorJobActionHandler.java @@ -163,7 +163,8 @@ private void onGetAnomalyDetectorResponse(GetResponse response) throws IOExcepti Instant.now(), null, Instant.now(), - duration.getSeconds() + duration.getSeconds(), + detector.getUser() ); getAnomalyDetectorJobForWrite(job); @@ -201,7 +202,8 @@ private void onGetAnomalyDetectorJobForWrite(GetResponse response, AnomalyDetect Instant.now(), currentAdJob.getDisabledTime(), Instant.now(), - job.getLockDurationSeconds() + job.getLockDurationSeconds(), + job.getUser() ); indexAnomalyDetectorJob(newJob, null); } @@ -278,7 +280,8 @@ public void stopAnomalyDetectorJob(String detectorId) { job.getEnabledTime(), Instant.now(), Instant.now(), - job.getLockDurationSeconds() + job.getLockDurationSeconds(), + job.getUser() ); indexAnomalyDetectorJob( newJob, diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorJobRunnerTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorJobRunnerTests.java index 35dd8a65..66692584 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorJobRunnerTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorJobRunnerTests.java @@ -310,7 +310,8 @@ private void testRunAdJobWithEndRunExceptionNowAndStopAdJob(boolean jobExists, b Instant.now().minusSeconds(60), Instant.now(), Instant.now(), - 60L + 60L, + TestHelpers.randomUser() ).toXContent(TestHelpers.builder(), ToXContent.EMPTY_PARAMS) ), Collections.emptyMap(), diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorRestTestCase.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorRestTestCase.java index b6786968..17adb9d4 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorRestTestCase.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorRestTestCase.java @@ -106,7 +106,8 @@ protected AnomalyDetector createAnomalyDetector(AnomalyDetector detector, Boolea detector.getShingleSize(), detector.getUiMetadata(), detector.getSchemaVersion(), - detector.getLastUpdateTime() + detector.getLastUpdateTime(), + detector.getUser() ); } @@ -176,7 +177,8 @@ public ToXContentObject[] getAnomalyDetector(String detectorId, BasicHeader head detector.getShingleSize(), detector.getUiMetadata(), detector.getSchemaVersion(), - detector.getLastUpdateTime() + detector.getLastUpdateTime(), + detector.getUser() ), detectorJob }; } diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/TestHelpers.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/TestHelpers.java index d7c394b9..e1ffd58d 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/TestHelpers.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/TestHelpers.java @@ -105,6 +105,7 @@ import com.amazon.opendistroforelasticsearch.ad.model.FeatureData; import com.amazon.opendistroforelasticsearch.ad.model.IntervalTimeConfiguration; import com.amazon.opendistroforelasticsearch.ad.model.TimeConfiguration; +import com.amazon.opendistroforelasticsearch.commons.authuser.User; import com.amazon.opendistroforelasticsearch.jobscheduler.spi.schedule.IntervalSchedule; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -193,7 +194,8 @@ public static AnomalyDetector randomAnomalyDetector(List features, Map< randomIntBetween(1, 2000), uiMetadata, randomInt(), - lastUpdateTime + lastUpdateTime, + randomUser() ); } @@ -212,7 +214,8 @@ public static AnomalyDetector randomAnomalyDetector(List features) thro randomIntBetween(1, 2000), null, randomInt(), - Instant.now() + Instant.now(), + randomUser() ); } @@ -231,7 +234,8 @@ public static AnomalyDetector randomAnomalyDetectorWithEmptyFeature() throws IOE randomIntBetween(1, 2000), null, randomInt(), - Instant.now().truncatedTo(ChronoUnit.SECONDS) + Instant.now().truncatedTo(ChronoUnit.SECONDS), + randomUser() ); } @@ -250,7 +254,8 @@ public static AnomalyDetector randomAnomalyDetectorWithInterval(TimeConfiguratio randomIntBetween(1, 2000), null, randomInt(), - Instant.now().truncatedTo(ChronoUnit.SECONDS) + Instant.now().truncatedTo(ChronoUnit.SECONDS), + randomUser() ); } @@ -317,6 +322,15 @@ public static Feature randomFeature(String featureName, String aggregationName) return new Feature(randomAlphaOfLength(5), featureName, ESRestTestCase.randomBoolean(), testAggregation); } + public static User randomUser() { + return new User( + randomAlphaOfLength(8), + ImmutableList.of(randomAlphaOfLength(10)), + ImmutableList.of("all_access"), + ImmutableList.of("attribute=test") + ); + } + public static void assertFailWith(Class clazz, Callable callable) throws Exception { assertFailWith(clazz, null, callable); } @@ -378,7 +392,8 @@ public static AnomalyDetectorJob randomAnomalyDetectorJob(boolean enabled, Insta enabledTime, disabledTime, Instant.now().truncatedTo(ChronoUnit.SECONDS), - 60L + 60L, + randomUser() ); } diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/model/AnomalyDetectorTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/model/AnomalyDetectorTests.java index da3ddcd9..2247114c 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/model/AnomalyDetectorTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/model/AnomalyDetectorTests.java @@ -139,7 +139,8 @@ public void testInvalidShingleSize() throws Exception { 0, null, 1, - Instant.now() + Instant.now(), + TestHelpers.randomUser() ) ); } @@ -162,7 +163,8 @@ public void testNullDetectorName() throws Exception { AnomalyDetectorSettings.DEFAULT_SHINGLE_SIZE, null, 1, - Instant.now() + Instant.now(), + TestHelpers.randomUser() ) ); } @@ -185,7 +187,8 @@ public void testBlankDetectorName() throws Exception { AnomalyDetectorSettings.DEFAULT_SHINGLE_SIZE, null, 1, - Instant.now() + Instant.now(), + TestHelpers.randomUser() ) ); } @@ -208,7 +211,8 @@ public void testNullTimeField() throws Exception { AnomalyDetectorSettings.DEFAULT_SHINGLE_SIZE, null, 1, - Instant.now() + Instant.now(), + TestHelpers.randomUser() ) ); } @@ -231,7 +235,8 @@ public void testNullIndices() throws Exception { AnomalyDetectorSettings.DEFAULT_SHINGLE_SIZE, null, 1, - Instant.now() + Instant.now(), + TestHelpers.randomUser() ) ); } @@ -254,7 +259,8 @@ public void testEmptyIndices() throws Exception { AnomalyDetectorSettings.DEFAULT_SHINGLE_SIZE, null, 1, - Instant.now() + Instant.now(), + TestHelpers.randomUser() ) ); } @@ -277,7 +283,8 @@ public void testNullDetectionInterval() throws Exception { AnomalyDetectorSettings.DEFAULT_SHINGLE_SIZE, null, 1, - Instant.now() + Instant.now(), + TestHelpers.randomUser() ) ); } @@ -312,7 +319,8 @@ public void testGetShingleSize() throws IOException { 5, null, 1, - Instant.now() + Instant.now(), + TestHelpers.randomUser() ); assertEquals((int) anomalyDetector.getShingleSize(), 5); } @@ -332,7 +340,8 @@ public void testGetShingleSizeReturnsDefaultValue() throws IOException { null, null, 1, - Instant.now() + Instant.now(), + TestHelpers.randomUser() ); assertEquals((int) anomalyDetector.getShingleSize(), AnomalyDetectorSettings.DEFAULT_SHINGLE_SIZE); } diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/rest/AnomalyDetectorRestApiIT.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/rest/AnomalyDetectorRestApiIT.java index a51d4c8c..2c576299 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/rest/AnomalyDetectorRestApiIT.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/rest/AnomalyDetectorRestApiIT.java @@ -15,12 +15,6 @@ package com.amazon.opendistroforelasticsearch.ad.rest; -import static com.amazon.opendistroforelasticsearch.ad.TestHelpers.AD_BASE_PREVIEW_URI; -import static com.amazon.opendistroforelasticsearch.ad.TestHelpers.randomAnomalyDetectorWithEmptyFeature; -import static com.amazon.opendistroforelasticsearch.ad.TestHelpers.randomFeature; -import static com.amazon.opendistroforelasticsearch.ad.TestHelpers.randomIntervalTimeConfiguration; -import static com.amazon.opendistroforelasticsearch.ad.TestHelpers.randomQuery; -import static com.amazon.opendistroforelasticsearch.ad.TestHelpers.randomUiMetadata; import static org.hamcrest.Matchers.containsString; import java.io.IOException; @@ -93,14 +87,15 @@ public void testCreateAnomalyDetectorWithDuplicateName() throws Exception { randomAlphaOfLength(5), randomAlphaOfLength(5), detector.getIndices(), - ImmutableList.of(randomFeature()), - randomQuery(), - randomIntervalTimeConfiguration(), - randomIntervalTimeConfiguration(), + ImmutableList.of(TestHelpers.randomFeature()), + TestHelpers.randomQuery(), + TestHelpers.randomIntervalTimeConfiguration(), + TestHelpers.randomIntervalTimeConfiguration(), randomIntBetween(1, 2000), - randomUiMetadata(), + TestHelpers.randomUiMetadata(), randomInt(), - null + null, + TestHelpers.randomUser() ); TestHelpers @@ -182,7 +177,8 @@ public void testUpdateAnomalyDetectorA() throws Exception { detector.getShingleSize(), detector.getUiMetadata(), detector.getSchemaVersion(), - detector.getLastUpdateTime() + detector.getLastUpdateTime(), + detector.getUser() ); updateClusterSettings(EnabledSetting.AD_PLUGIN_ENABLED, false); @@ -242,7 +238,8 @@ public void testUpdateAnomalyDetectorNameToExisting() throws Exception { detector1.getShingleSize(), detector1.getUiMetadata(), detector1.getSchemaVersion(), - detector1.getLastUpdateTime() + detector1.getLastUpdateTime(), + detector1.getUser() ); TestHelpers @@ -278,7 +275,8 @@ public void testUpdateAnomalyDetectorNameToNew() throws Exception { detector.getShingleSize(), detector.getUiMetadata(), detector.getSchemaVersion(), - Instant.now() + Instant.now(), + detector.getUser() ); TestHelpers @@ -320,7 +318,8 @@ public void testUpdateAnomalyDetectorWithNotExistingIndex() throws Exception { detector.getShingleSize(), detector.getUiMetadata(), detector.getSchemaVersion(), - detector.getLastUpdateTime() + detector.getLastUpdateTime(), + detector.getUser() ); deleteIndex(AnomalyDetector.ANOMALY_DETECTORS_INDEX); @@ -408,7 +407,7 @@ public void testPreviewAnomalyDetector() throws Exception { .makeRequest( client(), "POST", - String.format(AD_BASE_PREVIEW_URI, input.getDetectorId()), + String.format(TestHelpers.AD_BASE_PREVIEW_URI, input.getDetectorId()), ImmutableMap.of(), toHttpEntity(input), null @@ -422,7 +421,7 @@ public void testPreviewAnomalyDetector() throws Exception { .makeRequest( client(), "POST", - String.format(AD_BASE_PREVIEW_URI, input.getDetectorId()), + String.format(TestHelpers.AD_BASE_PREVIEW_URI, input.getDetectorId()), ImmutableMap.of(), toHttpEntity(input), null @@ -487,7 +486,7 @@ public void testPreviewAnomalyDetectorWithDetector() throws Exception { .makeRequest( client(), "POST", - String.format(AD_BASE_PREVIEW_URI, input.getDetectorId()), + String.format(TestHelpers.AD_BASE_PREVIEW_URI, input.getDetectorId()), ImmutableMap.of(), toHttpEntity(input), null @@ -501,7 +500,7 @@ public void testPreviewAnomalyDetectorWithDetectorAndNoFeatures() throws Excepti detector.getDetectorId(), Instant.now().minusSeconds(60 * 10), Instant.now(), - randomAnomalyDetectorWithEmptyFeature() + TestHelpers.randomAnomalyDetectorWithEmptyFeature() ); TestHelpers .assertFailWith( @@ -702,7 +701,8 @@ public void testUpdateAnomalyDetectorWithRunningAdJob() throws Exception { detector.getShingleSize(), detector.getUiMetadata(), detector.getSchemaVersion(), - detector.getLastUpdateTime() + detector.getLastUpdateTime(), + detector.getUser() ); TestHelpers From ec266d0c419ce0acd696e84cad8fde89fdbffdc5 Mon Sep 17 00:00:00 2001 From: Sarat Date: Tue, 13 Oct 2020 18:54:20 -0700 Subject: [PATCH 2/3] Adding spotless recommended changes --- .../amazon/opendistroforelasticsearch/ad/TestHelpers.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/TestHelpers.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/TestHelpers.java index a7bd5751..da0e417b 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/TestHelpers.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/TestHelpers.java @@ -376,10 +376,10 @@ public static Feature randomFeature(String featureName, String aggregationName, public static User randomUser() { return new User( - randomAlphaOfLength(8), - ImmutableList.of(randomAlphaOfLength(10)), - ImmutableList.of("all_access"), - ImmutableList.of("attribute=test") + randomAlphaOfLength(8), + ImmutableList.of(randomAlphaOfLength(10)), + ImmutableList.of("all_access"), + ImmutableList.of("attribute=test") ); } From 010c88c43b52cce58a46630dda89115a1fe05375 Mon Sep 17 00:00:00 2001 From: Sarat Date: Wed, 14 Oct 2020 00:58:07 -0700 Subject: [PATCH 3/3] Updated AD and ADJob Mappings with User information --- .../mappings/anomaly-detector-jobs.json | 37 +++++++++++++++++++ .../resources/mappings/anomaly-detectors.json | 37 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/src/main/resources/mappings/anomaly-detector-jobs.json b/src/main/resources/mappings/anomaly-detector-jobs.json index ccd9d958..734b487a 100644 --- a/src/main/resources/mappings/anomaly-detector-jobs.json +++ b/src/main/resources/mappings/anomaly-detector-jobs.json @@ -59,6 +59,43 @@ }, "lock_duration_seconds": { "type": "long" + }, + "user": { + "properties": { + "name": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "backend_roles": { + "type" : "text", + "fields" : { + "keyword" : { + "type" : "keyword" + } + } + }, + "roles": { + "type" : "text", + "fields" : { + "keyword" : { + "type" : "keyword" + } + } + }, + "custom_attribute_names": { + "type" : "text", + "fields" : { + "keyword" : { + "type" : "keyword" + } + } + } + } } } } diff --git a/src/main/resources/mappings/anomaly-detectors.json b/src/main/resources/mappings/anomaly-detectors.json index 7fd79f4f..e9d701ee 100644 --- a/src/main/resources/mappings/anomaly-detectors.json +++ b/src/main/resources/mappings/anomaly-detectors.json @@ -103,6 +103,43 @@ "ui_metadata": { "type": "object", "enabled": false + }, + "user": { + "properties": { + "name": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "backend_roles": { + "type" : "text", + "fields" : { + "keyword" : { + "type" : "keyword" + } + } + }, + "roles": { + "type" : "text", + "fields" : { + "keyword" : { + "type" : "keyword" + } + } + }, + "custom_attribute_names": { + "type" : "text", + "fields" : { + "keyword" : { + "type" : "keyword" + } + } + } + } } } }