Skip to content

Commit

Permalink
[Backport 2.x] Update CircuitBreakerService and LifecycleComponent af…
Browse files Browse the repository at this point in the history
…ter core refactor in #9006 (#3089)

Manual backport of
#3082 and
#3050 to 2.x

---------

Signed-off-by: Craig Perkins <[email protected]>
Signed-off-by: Ryan Liang <[email protected]>
Co-authored-by: Ryan Liang <[email protected]>
  • Loading branch information
cwperks and RyanL1997 authored Aug 2, 2023
1 parent 2fb1802 commit 8205931
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private boolean handleLowLevel(RestRequest restRequest, RestChannel restChannel)
XPathExpressionException, ParserConfigurationException, SAXException, SettingsException {
try {

if (restRequest.getXContentType() != XContentType.JSON) {
if (restRequest.getMediaType() != XContentType.JSON) {
throw new OpenSearchSecurityException(
"/_opendistro/_security/api/authtoken expects content with type application/json",
RestStatus.UNSUPPORTED_MEDIA_TYPE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.cluster.node.DiscoveryNodes;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.component.Lifecycle.State;
import org.opensearch.common.component.LifecycleComponent;
import org.opensearch.common.component.LifecycleListener;
import org.opensearch.common.inject.Inject;
import org.opensearch.common.lifecycle.Lifecycle;
import org.opensearch.common.lifecycle.LifecycleComponent;
import org.opensearch.common.lifecycle.LifecycleListener;
import org.opensearch.core.common.io.stream.NamedWriteableRegistry;
import org.opensearch.common.logging.DeprecationLogger;
import org.opensearch.common.network.NetworkModule;
Expand All @@ -92,6 +92,7 @@
import org.opensearch.common.util.BigArrays;
import org.opensearch.common.util.PageCacheRecycler;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.core.indices.breaker.CircuitBreakerService;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.env.Environment;
import org.opensearch.env.NodeEnvironment;
Expand All @@ -103,7 +104,6 @@
import org.opensearch.index.cache.query.QueryCache;
import org.opensearch.indices.IndicesService;
import org.opensearch.indices.SystemIndexDescriptor;
import org.opensearch.indices.breaker.CircuitBreakerService;
import org.opensearch.plugins.ClusterPlugin;
import org.opensearch.plugins.MapperPlugin;
import org.opensearch.repositories.RepositoriesService;
Expand Down Expand Up @@ -1926,7 +1926,7 @@ public static ExtensionsManager getExtensionsManager() {
public void close() {}

@Override
public State lifecycleState() {
public Lifecycle.State lifecycleState() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.transport.TransportAddress;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.core.xcontent.NamedXContentRegistry;
Expand Down Expand Up @@ -656,7 +657,7 @@ public void logDocumentWritten(ShardId shardId, GetResult originalResult, Index
// originalResult.internalSourceRef()));

// current source, normally not null or empty
msg.addTupleToRequestBody(new Tuple<XContentType, BytesReference>(XContentType.JSON, currentIndex.source()));
msg.addTupleToRequestBody(new Tuple<MediaType, BytesReference>(XContentType.JSON, currentIndex.source()));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.opensearch.common.collect.Tuple;
import org.opensearch.common.transport.TransportAddress;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.core.common.Strings;
Expand Down Expand Up @@ -206,7 +207,7 @@ void addSecurityConfigWriteDiffSource(final String diff, final String id) {
// }
// }

public void addTupleToRequestBody(Tuple<XContentType, BytesReference> xContentTuple) {
public void addTupleToRequestBody(Tuple<MediaType, BytesReference> xContentTuple) {
if (xContentTuple != null) {
try {
auditInfo.put(REQUEST_BODY, XContentHelper.convertToJson(xContentTuple.v2(), false, xContentTuple.v1()));
Expand Down Expand Up @@ -378,7 +379,7 @@ void addRestRequestInfo(final RestRequest request, final AuditConfig.Filter filt
addRestMethod(request.method());
if (filter.shouldLogRequestBody() && request.hasContentOrSourceParam()) {
try {
final Tuple<XContentType, BytesReference> xContentTuple = request.contentOrSourceParam();
final Tuple<MediaType, BytesReference> xContentTuple = request.contentOrSourceParam();
final String requestBody = XContentHelper.convertToJson(xContentTuple.v2(), false, xContentTuple.v1());
if (path != null
&& requestBody != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.transport.TransportAddress;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.index.Index;
Expand Down Expand Up @@ -381,7 +382,7 @@ private static void addIndicesSourceSafe(
final String[] indices,
final IndexNameExpressionResolver resolver,
final ClusterService cs,
final XContentType xContentType,
final MediaType mediaType,
final Object source,
final Settings settings,
boolean resolveIndices,
Expand Down Expand Up @@ -423,27 +424,27 @@ private static void addIndicesSourceSafe(
if (sourceIsSensitive && source != null) {
if (!allIndicesMatcher.test(securityIndex)) {
if (source instanceof BytesReference) {
msg.addTupleToRequestBody(convertSource(xContentType, (BytesReference) source));
msg.addTupleToRequestBody(convertSource(mediaType, (BytesReference) source));
} else {
msg.addMapToRequestBody((Map) source);
}
}
} else if (source != null) {
if (source instanceof BytesReference) {
msg.addTupleToRequestBody(convertSource(xContentType, (BytesReference) source));
msg.addTupleToRequestBody(convertSource(mediaType, (BytesReference) source));
} else {
msg.addMapToRequestBody((Map) source);
}
}
}
}

private static Tuple<XContentType, BytesReference> convertSource(XContentType type, BytesReference bytes) {
private static Tuple<MediaType, BytesReference> convertSource(MediaType type, BytesReference bytes) {
if (type == null) {
type = XContentType.JSON;
}

return new Tuple<XContentType, BytesReference>(type, bytes);
return new Tuple<MediaType, BytesReference>(type, bytes);
}

private static String[] arrayOrEmpty(String[] array) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public PatchableResourceApiAction(
}

private void handlePatch(RestChannel channel, final RestRequest request, final Client client) throws IOException {
if (request.getXContentType() != XContentType.JSON) {
if (request.getMediaType() != XContentType.JSON) {
badRequestResponse(channel, "PATCH accepts only application/json");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@
import org.opensearch.common.util.BigArrays;
import org.opensearch.common.util.PageCacheRecycler;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.core.indices.breaker.CircuitBreakerService;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.env.Environment;
import org.opensearch.env.NodeEnvironment;
import org.opensearch.http.HttpServerTransport;
import org.opensearch.http.HttpServerTransport.Dispatcher;
import org.opensearch.indices.breaker.CircuitBreakerService;
import org.opensearch.plugins.NetworkPlugin;
import org.opensearch.plugins.Plugin;
import org.opensearch.plugins.SystemIndexPlugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import org.opensearch.common.network.NetworkService;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.PageCacheRecycler;
import org.opensearch.indices.breaker.CircuitBreakerService;
import org.opensearch.core.indices.breaker.CircuitBreakerService;
import org.opensearch.security.ssl.SecurityKeyStore;
import org.opensearch.security.ssl.SslExceptionHandler;
import org.opensearch.security.ssl.util.SSLConfigConstants;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import org.opensearch.core.common.bytes.BytesReference;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.rest.RestChannel;
import org.opensearch.rest.RestRequest;
Expand Down Expand Up @@ -992,7 +992,7 @@ public XContentBuilder newErrorBuilder() throws IOException {
}

@Override
public XContentBuilder newBuilder(XContentType xContentType, boolean useFiltering) throws IOException {
public XContentBuilder newBuilder(MediaType mediaType, boolean useFiltering) throws IOException {
return null;
}

Expand All @@ -1018,8 +1018,7 @@ public void sendResponse(RestResponse response) {
}

@Override
public XContentBuilder newBuilder(XContentType xContentType, XContentType responseContentType, boolean useFiltering)
throws IOException {
public XContentBuilder newBuilder(MediaType mediaType, MediaType responseContentType, boolean useFiltering) throws IOException {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
import org.opensearch.common.util.BigArrays;
import org.opensearch.common.util.PageCacheRecycler;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.core.indices.breaker.CircuitBreakerService;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.http.HttpServerTransport;
import org.opensearch.http.HttpServerTransport.Dispatcher;
import org.opensearch.http.netty4.Netty4HttpServerTransport;
import org.opensearch.indices.breaker.CircuitBreakerService;
import org.opensearch.plugins.NetworkPlugin;
import org.opensearch.plugins.Plugin;
import org.opensearch.rest.RestChannel;
Expand Down

0 comments on commit 8205931

Please sign in to comment.