Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monkey-patching NodeRole class to avoid role parsing bug. #18648

Merged
merged 10 commits into from
Mar 18, 2024
22 changes: 21 additions & 1 deletion graylog-storage-opensearch2/assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
<scope>runtime</scope>
<useProjectArtifact>true</useProjectArtifact>
<useTransitiveDependencies>true</useTransitiveDependencies>
<useStrictFiltering>true</useStrictFiltering>
<includes>
<include>org.opensearch.client:opensearch-java</include>
</includes>
<unpackOptions>
<excludes>
<!-- exclude NodeInfoAction since it was monkey-patched in
https://github.com/Graylog2/graylog2-server/pull/18658 .
Should be removed after the bug has been fixed and the patch removed. -->
<exclude>org/opensearch/client/opensearch/nodes/info/NodeInfoAction.class</exclude>
<exclude>org/opensearch/client/opensearch/nodes/info/NodeInfoBootstrap.class</exclude>
<exclude>org/opensearch/client/opensearch/_types/NodeRole.class</exclude>
</excludes>
</unpackOptions>
</dependencySet>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
Expand All @@ -19,7 +40,6 @@
<include>org.graylog:graylog-storage-opensearch2</include>
<include>org.graylog.shaded:opensearch2-rest-high-level-client</include>
<include>org.graylog.shaded:opensearch2-rest-client-sniffer</include>
<include>org.opensearch.client:opensearch-java</include>
<include>org.opensearch.client:opensearch-rest-client</include>
<include>org.opensearch.client:opensearch-rest-client-sniffer</include>
<include>org.apache.httpcomponents:httpasyncclient</include>
Expand Down
3 changes: 2 additions & 1 deletion graylog-storage-opensearch2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@
<descriptors>assembly.xml</descriptors>
<archive>
<manifestEntries>
<Graylog-Plugin-Properties-Path>${project.groupId}.${project.artifactId}</Graylog-Plugin-Properties-Path>
<Graylog-Plugin-Properties-Path>${project.groupId}.${project.artifactId}
</Graylog-Plugin-Properties-Path>
</manifestEntries>
</archive>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ private NodeInfo createNodeInfo(org.opensearch.client.opensearch.nodes.info.Node
return NodeInfo.builder()
.version(nodeInfo.version())
.os(nodeInfo.os())
.allocatedProcessors(nodeInfo.os().allocatedProcessors())
.roles(nodeInfo.roles().stream().map(Enum::toString).toList())
.jvmMemHeapMaxInBytes(nodeInfo.jvm().mem().heapMaxInBytes())
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.client.opensearch._types;

import org.opensearch.client.json.JsonEnum;
import org.opensearch.client.json.JsonpDeserializable;

@JsonpDeserializable
public enum NodeRole implements JsonEnum {
@Deprecated
Master("master"),

ClusterManager("cluster_manager"),

Data("data"),

DataCold("data_cold"),

DataContent("data_content"),

DataFrozen("data_frozen"),

DataHot("data_hot"),

DataWarm("data_warm"),

Client("client"),

Ingest("ingest"),

Ml("ml"),

VotingOnly("voting_only"),

Transform("transform"),

RemoteClusterClient("remote_cluster_client"),

CoordinatingOnly("coordinating_only"),

Search("search"),

;

private final String jsonValue;

NodeRole(String jsonValue) {
this.jsonValue = jsonValue;
}

public String jsonValue() {
return this.jsonValue;
}

public static final JsonEnum.Deserializer<NodeRole> _DESERIALIZER = new JsonEnum.Deserializer<>(NodeRole.values());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
package org.opensearch.client.opensearch.nodes.info;

import jakarta.json.stream.JsonGenerator;
import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.JsonpSerializable;
import org.opensearch.client.json.ObjectBuilderDeserializer;
import org.opensearch.client.json.ObjectDeserializer;
import org.opensearch.client.util.ApiTypeHelper;
import org.opensearch.client.util.MissingRequiredPropertyException;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;

import java.util.function.Function;

// typedef: nodes.info.NodeInfoAction

@JsonpDeserializable
public class NodeInfoAction implements JsonpSerializable {
private final String destructiveRequiresName;

// ---------------------------------------------------------------------------------------------

private NodeInfoAction(Builder builder) {

String destructiveRequiresNameSetting;
try {
destructiveRequiresNameSetting = ApiTypeHelper.requireNonNull(builder.destructiveRequiresName, this, "destructiveRequiresName");
} catch (MissingRequiredPropertyException e) {
destructiveRequiresNameSetting = "true";
}
this.destructiveRequiresName = destructiveRequiresNameSetting;

}

public static NodeInfoAction of(Function<Builder, ObjectBuilder<NodeInfoAction>> fn) {
return fn.apply(new Builder()).build();
}

/**
* Required - API name: {@code destructive_requires_name}
*/
public final String destructiveRequiresName() {
return this.destructiveRequiresName;
}

/**
* Serialize this object to JSON.
*/
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
generator.writeStartObject();
serializeInternal(generator, mapper);
generator.writeEnd();
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

generator.writeKey("destructive_requires_name");
generator.write(this.destructiveRequiresName);

}

// ---------------------------------------------------------------------------------------------

/**
* Builder for {@link NodeInfoAction}.
*/

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<NodeInfoAction> {
private String destructiveRequiresName;

/**
* Required - API name: {@code destructive_requires_name}
*/
public final Builder destructiveRequiresName(String value) {
this.destructiveRequiresName = value;
return this;
}

/**
* Builds a {@link NodeInfoAction}.
*
* @throws NullPointerException if some of the required fields are null.
*/
public NodeInfoAction build() {
_checkSingleUse();

return new NodeInfoAction(this);
}
}

// ---------------------------------------------------------------------------------------------

/**
* Json deserializer for {@link NodeInfoAction}
*/
public static final JsonpDeserializer<NodeInfoAction> _DESERIALIZER = ObjectBuilderDeserializer.lazy(
Builder::new,
NodeInfoAction::setupNodeInfoActionDeserializer
);

protected static void setupNodeInfoActionDeserializer(ObjectDeserializer<NodeInfoAction.Builder> op) {

op.add(Builder::destructiveRequiresName, JsonpDeserializer.stringDeserializer(), "destructive_requires_name");

}

}
Loading
Loading