-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport 2.x] Pass localNode info to all plugins on node start (#8192)
* [Enhancement] Pass localNode info to all plugins on node start (#7919) * Updates Node start to now pass localNode info so that it is available directly to a plugin instead of hacky implementation Signed-off-by: Darshit Chanpura <dchanp@amazon.com> * Adds this PR to changelog Signed-off-by: Darshit Chanpura <dchanp@amazon.com> * Makes onNodeStarted call plugin agnostic Signed-off-by: Darshit Chanpura <dchanp@amazon.com> * Marking onNodeStarted() as deprecated Signed-off-by: Darshit Chanpura <dchanp@amazon.com> * Adds a test to verify the behaviour of new signature of onNodeStarted Signed-off-by: Darshit Chanpura <dchanp@amazon.com> * Updates test to also check for nodeId Signed-off-by: Darshit Chanpura <dchanp@amazon.com> * Adds instructions to use the overloaded implementation of onNodeStarted and adds a test to check that current plugins are not affect with this implementation Signed-off-by: Darshit Chanpura <dchanp@amazon.com> --------- Signed-off-by: Darshit Chanpura <dchanp@amazon.com> Signed-off-by: Darshit Chanpura <35282393+DarshitChanpura@users.noreply.github.com> (cherry picked from commit 40d7583) * Adds a CHANGELOG entry Signed-off-by: Darshit Chanpura <dchanp@amazon.com> --------- Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
- Loading branch information
1 parent
efd12df
commit fced6d4
Showing
4 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
server/src/test/java/org/opensearch/plugins/ClusterPluginTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.opensearch.plugins; | ||
|
||
import org.opensearch.cluster.node.DiscoveryNode; | ||
import org.opensearch.test.OpenSearchSingleNodeTestCase; | ||
|
||
import java.util.Collection; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
public class ClusterPluginTests extends OpenSearchSingleNodeTestCase { | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> getPlugins() { | ||
return pluginList(DummyClusterPlugin.class, DummyClusterPlugin2.class); | ||
} | ||
|
||
public void testOnNodeStarted_shouldContainLocalNodeInfo() { | ||
|
||
DiscoveryNode localNode = DummyClusterPlugin.getLocalNode(); | ||
|
||
assertTrue(localNode != null); | ||
// TODO Figure out if there is a way to check ephemeralId | ||
assertTrue(localNode.getId().equals(node().getNodeEnvironment().nodeId())); | ||
} | ||
|
||
public void testOnNodeStarted_shouldCallDeprecatedMethod() { | ||
DummyClusterPlugin2 dummyClusterPlugin2 = mock(DummyClusterPlugin2.class); | ||
dummyClusterPlugin2.onNodeStarted(); | ||
verify(dummyClusterPlugin2, times(1)).onNodeStarted(); | ||
|
||
DiscoveryNode localNode = DummyClusterPlugin2.getLocalNode(); | ||
assertTrue(localNode != null); | ||
} | ||
|
||
} | ||
|
||
final class DummyClusterPlugin extends Plugin implements ClusterPlugin { | ||
|
||
private static volatile DiscoveryNode localNode; | ||
|
||
public DummyClusterPlugin() {} | ||
|
||
@Override | ||
public void onNodeStarted(DiscoveryNode localNode) { | ||
DummyClusterPlugin.localNode = localNode; | ||
} | ||
|
||
public static DiscoveryNode getLocalNode() { | ||
return localNode; | ||
} | ||
} | ||
|
||
class DummyClusterPlugin2 extends Plugin implements ClusterPlugin { | ||
|
||
private static volatile DiscoveryNode localNode; | ||
|
||
public DummyClusterPlugin2() {} | ||
|
||
@Override | ||
public void onNodeStarted() { | ||
localNode = mock(DiscoveryNode.class); | ||
} | ||
|
||
public static DiscoveryNode getLocalNode() { | ||
return localNode; | ||
} | ||
|
||
} |