Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 alerting/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ dependencies {
api project(":alerting-core")
implementation "com.github.seancfoley:ipaddress:5.3.3"

testImplementation "org.antlr:antlr4-runtime:${versions.antlr4}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why is this required?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This causes the integration tests to fail since its missing this dependency. This is because it is used by the Painless scripts and its caused by the BucketSelectorExtAggregator. I tried having this change in common-utils, but it wouldn't help.

testImplementation "org.jetbrains.kotlin:kotlin-test:${kotlin_version}"
testImplementation "org.mockito:mockito-core:${versions.mockito}"
testImplementation "org.opensearch.plugin:reindex-client:${opensearch_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.xcontent.ConstructingObjectParser;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.indices.breaker.CircuitBreakerService;
import org.opensearch.core.indices.breaker.NoneCircuitBreakerService;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.index.analysis.FieldNameAnalyzer;
import org.opensearch.index.fielddata.IndexFieldData;
import org.opensearch.index.fielddata.IndexFieldDataCache;
Expand All @@ -91,8 +94,6 @@
import org.opensearch.index.query.QueryShardContext;
import org.opensearch.index.query.QueryShardException;
import org.opensearch.index.query.Rewriteable;
import org.opensearch.indices.breaker.CircuitBreakerService;
import org.opensearch.indices.breaker.NoneCircuitBreakerService;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -128,7 +129,7 @@ public class PercolateQueryBuilderExt extends AbstractQueryBuilder<PercolateQuer
private final String field;
private String name;
private final List<BytesReference> documents;
private final XContentType documentXContentType;
private final MediaType documentXContentType;

private final String indexedDocumentIndex;
private final String indexedDocumentId;
Expand All @@ -155,7 +156,7 @@ public PercolateQueryBuilderExt(String field, BytesReference document, XContentT
* @param documents The binary blob containing document to percolate
* @param documentXContentType The content type of the binary blob containing the document to percolate
*/
public PercolateQueryBuilderExt(String field, List<BytesReference> documents, XContentType documentXContentType) {
public PercolateQueryBuilderExt(String field, List<BytesReference> documents, MediaType documentXContentType) {
if (field == null) {
throw new IllegalArgumentException("[field] is a required argument");
}
Expand Down Expand Up @@ -257,7 +258,11 @@ protected PercolateQueryBuilderExt(String field, Supplier<BytesReference> docume
}
documents = in.readList(StreamInput::readBytesReference);
if (documents.isEmpty() == false) {
documentXContentType = in.readEnum(XContentType.class);
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
documentXContentType = in.readMediaType();
} else {
documentXContentType = in.readEnum(XContentType.class);
}
} else {
documentXContentType = null;
}
Expand Down Expand Up @@ -303,7 +308,11 @@ protected void doWriteTo(StreamOutput out) throws IOException {
out.writeBytesReference(document);
}
if (documents.isEmpty() == false) {
out.writeEnum(documentXContentType);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
documentXContentType.writeTo(out);
} else {
out.writeEnum((XContentType) documentXContentType);
}
}
}

Expand Down Expand Up @@ -437,7 +446,7 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryShardContext) {
PercolateQueryBuilderExt rewritten = new PercolateQueryBuilderExt(
field,
Collections.singletonList(source),
XContentHelper.xContentType(source)
MediaTypeRegistry.xContentType(source)
);
if (name != null) {
rewritten.setName(name);
Expand Down Expand Up @@ -563,7 +572,7 @@ public List<BytesReference> getDocuments() {
}

// pkg-private for testing
XContentType getXContentType() {
MediaType getXContentType() {
return documentXContentType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import org.opensearch.alerting.workflow.CompositeWorkflowRunner
import org.opensearch.client.Client
import org.opensearch.cluster.metadata.IndexNameExpressionResolver
import org.opensearch.cluster.service.ClusterService
import org.opensearch.common.component.AbstractLifecycleComponent
import org.opensearch.common.lifecycle.AbstractLifecycleComponent
import org.opensearch.common.settings.Settings
import org.opensearch.commons.alerting.model.Alert
import org.opensearch.commons.alerting.model.Monitor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import org.opensearch.alerting.opensearchapi.suspendUntil
import org.opensearch.alerting.util.AlertingException
import org.opensearch.client.Client
import org.opensearch.common.xcontent.LoggingDeprecationHandler
import org.opensearch.common.xcontent.XContentFactory
import org.opensearch.common.xcontent.XContentType
import org.opensearch.commons.alerting.model.Finding
import org.opensearch.commons.alerting.model.Monitor
Expand Down Expand Up @@ -64,7 +63,7 @@ class WorkflowService(
// Get the findings docs
val findings = mutableListOf<Finding>()
for (hit in searchResponse.hits) {
val xcp = XContentFactory.xContent(XContentType.JSON)
val xcp = XContentType.JSON.xContent()
.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, hit.sourceAsString)
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp)
val finding = Finding.parse(xcp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import org.opensearch.common.Strings
import org.opensearch.common.inject.Inject
import org.opensearch.common.settings.Settings
import org.opensearch.common.xcontent.LoggingDeprecationHandler
import org.opensearch.common.xcontent.XContentFactory
import org.opensearch.common.xcontent.XContentType
import org.opensearch.commons.alerting.model.ScheduledJob
import org.opensearch.commons.authuser.User
Expand Down Expand Up @@ -149,7 +148,7 @@ class TransportGetDestinationsAction @Inject constructor(
val version = hit.version
val seqNo = hit.seqNo.toInt()
val primaryTerm = hit.primaryTerm.toInt()
val xcp = XContentFactory.xContent(XContentType.JSON)
val xcp = XContentType.JSON.xContent()
.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, hit.sourceAsString)
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp)
XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, xcp.nextToken(), xcp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import org.opensearch.common.Strings
import org.opensearch.common.inject.Inject
import org.opensearch.common.settings.Settings
import org.opensearch.common.xcontent.LoggingDeprecationHandler
import org.opensearch.common.xcontent.XContentFactory
import org.opensearch.common.xcontent.XContentType
import org.opensearch.commons.alerting.action.AlertingActions
import org.opensearch.commons.alerting.action.GetFindingsRequest
Expand Down Expand Up @@ -186,7 +185,7 @@ class TransportGetFindingsSearchAction @Inject constructor(
val findingsWithDocs = mutableListOf<FindingWithDocs>()
val findings = mutableListOf<Finding>()
for (hit in searchResponse.hits) {
val xcp = XContentFactory.xContent(XContentType.JSON)
val xcp = XContentType.JSON.xContent()
.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, hit.sourceAsString)
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp)
val finding = Finding.parse(xcp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.opensearch.client.node.NodeClient
import org.opensearch.cluster.ClusterChangedEvent
import org.opensearch.cluster.ClusterStateListener
import org.opensearch.cluster.service.ClusterService
import org.opensearch.common.component.LifecycleListener
import org.opensearch.common.lifecycle.LifecycleListener
import org.opensearch.common.unit.TimeValue
import org.opensearch.threadpool.Scheduler
import org.opensearch.threadpool.ThreadPool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import org.opensearch.alerting.util.use
import org.opensearch.client.node.NodeClient
import org.opensearch.common.Strings
import org.opensearch.common.xcontent.LoggingDeprecationHandler
import org.opensearch.common.xcontent.XContentFactory
import org.opensearch.common.xcontent.XContentType
import org.opensearch.commons.ConfigConstants
import org.opensearch.commons.alerting.model.ScheduledJob
Expand Down Expand Up @@ -175,7 +174,7 @@ class DestinationMigrationUtilService {
hasMoreResults = false
}
for (hit in response.hits) {
val xcp = XContentFactory.xContent(XContentType.JSON)
val xcp = XContentType.JSON.xContent()
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, hit.sourceAsString)
var notificationConfig: NotificationConfig? = null
var userStr = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import org.opensearch.client.RestClient
import org.opensearch.client.WarningsHandler
import org.opensearch.common.io.PathUtils
import org.opensearch.common.settings.Settings
import org.opensearch.common.xcontent.XContentType
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_ENABLED
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_FILEPATH
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_KEYPASSWORD
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_PASSWORD
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_PEMCERT_FILEPATH
import org.opensearch.commons.rest.SecureRestClientBuilder
import org.opensearch.core.xcontent.DeprecationHandler
import org.opensearch.core.xcontent.MediaType
import org.opensearch.core.xcontent.NamedXContentRegistry
import org.opensearch.test.rest.OpenSearchRestTestCase
import java.io.IOException
Expand Down Expand Up @@ -81,7 +81,7 @@ abstract class ODFERestTestCase : OpenSearchRestTestCase() {

val response = client().performRequest(Request("GET", "/_cat/indices?format=json&expand_wildcards=all"))

val xContentType = XContentType.fromMediaType(response.entity.contentType)
val xContentType = MediaType.fromMediaType(response.entity.contentType)
xContentType.xContent().createParser(
NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
response.entity.content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.opensearch.cluster.routing.IndexShardRoutingTable
import org.opensearch.cluster.routing.Murmur3HashFunction
import org.opensearch.cluster.service.ClusterService
import org.opensearch.common.Strings
import org.opensearch.common.component.LifecycleListener
import org.opensearch.common.lifecycle.LifecycleListener
import org.opensearch.common.logging.Loggers
import org.opensearch.common.lucene.uid.Versions
import org.opensearch.common.settings.Settings
Expand Down