-
Notifications
You must be signed in to change notification settings - Fork 1.9k
IGNITE-10944: Plugin discovery data from PluginProvider.provideDiscoveryData should be available in PluginProvider.validateNewNode #5865
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a100cf0
Added validateNode method with discoData argument.
mcherkasov 8aef0e4
Added tests.
mcherkasov 26d9daa
Fixed platform tests.
mcherkasov 4b4d09c
CC fixed.
mcherkasov 786404c
Test added directly to basic suite and suite for plugin api is removed.
mcherkasov 83ca82e
Removed changes in existent plugins, no changes is required, because …
mcherkasov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
192 changes: 192 additions & 0 deletions
192
modules/core/src/test/java/org/apache/ignite/plugin/NodeValidationPluginProvider.java
This file contains hidden or 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,192 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF 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. | ||
| */ | ||
|
|
||
| package org.apache.ignite.plugin; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.UUID; | ||
| import org.apache.ignite.IgniteCheckedException; | ||
| import org.apache.ignite.cluster.ClusterNode; | ||
| import org.apache.ignite.configuration.IgniteConfiguration; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| /** | ||
| * Validates node on join, it requires nodes to provide token that matches configured on primary node. | ||
| */ | ||
| public class NodeValidationPluginProvider implements PluginProvider, IgnitePlugin { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add comments everywhere as per CC |
||
|
|
||
| /** */ | ||
| private NodeValidationPluginConfiguration pluginConfiguration; | ||
| /** */ | ||
| private static volatile boolean enabled; | ||
|
|
||
| /** */ | ||
| public static boolean isEnabled() { | ||
| return enabled; | ||
| } | ||
|
|
||
| /** */ | ||
| public static void setEnabled(boolean enabled) { | ||
| NodeValidationPluginProvider.enabled = enabled; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public String name() { | ||
| return "NodeValidationPluginProvider"; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public String version() { | ||
| return "1.0"; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public String copyright() { | ||
| return ""; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public IgnitePlugin plugin() { | ||
| return this; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public void initExtensions(PluginContext ctx, ExtensionRegistry registry) { | ||
| if (!enabled) | ||
| return; | ||
|
|
||
| IgniteConfiguration igniteCfg = ctx.igniteConfiguration(); | ||
|
|
||
| if (igniteCfg.getPluginConfigurations() != null) { | ||
| for (PluginConfiguration pluginCfg : igniteCfg.getPluginConfigurations()) { | ||
| if (pluginCfg instanceof NodeValidationPluginConfiguration) { | ||
| pluginConfiguration = (NodeValidationPluginConfiguration)pluginCfg; | ||
|
|
||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Nullable @Override public Object createComponent(PluginContext ctx, Class cls) { | ||
| return null; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public CachePluginProvider createCacheProvider(CachePluginContext ctx) { | ||
| return null; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public void start(PluginContext ctx) throws IgniteCheckedException { | ||
| //no-op | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public void stop(boolean cancel) throws IgniteCheckedException { | ||
| //no-op | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public void onIgniteStart() throws IgniteCheckedException { | ||
| //no-op | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public void onIgniteStop(boolean cancel) { | ||
| //no-op | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Nullable @Override public Serializable provideDiscoveryData(UUID nodeId) { | ||
| if (!enabled) | ||
| return null; | ||
|
|
||
| MyDiscoData data = new MyDiscoData(pluginConfiguration.getToken()); | ||
|
|
||
| return data; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public void receiveDiscoveryData(UUID nodeId, Serializable data) { | ||
| if (!enabled) | ||
| return; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public void validateNewNode(ClusterNode node) throws PluginValidationException { | ||
| // no-op | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public void validateNewNode(ClusterNode node, Serializable serializable) { | ||
| if (!enabled) | ||
| return; | ||
|
|
||
| MyDiscoData newNodeDiscoData = serializable instanceof MyDiscoData ? (MyDiscoData)serializable : null; | ||
|
|
||
| if (newNodeDiscoData == null || !newNodeDiscoData.getToken().equals(pluginConfiguration.getToken())) { | ||
| String msg = newNodeDiscoData == null ? "no token provided" : "bad token provided: " + newNodeDiscoData.getToken(); | ||
|
|
||
| throw new PluginValidationException(msg, msg, node.id()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| private static class MyDiscoData implements Serializable { | ||
| /** */ | ||
| String token; | ||
|
|
||
| /** */ | ||
| MyDiscoData(String token) { | ||
| this.token = token; | ||
| } | ||
|
|
||
| /** */ | ||
| public String getToken() { | ||
| return token; | ||
| } | ||
|
|
||
| /** */ | ||
| @Override public String toString() { | ||
| return "MyDiscoData{" + | ||
| "token='" + token + '\'' + | ||
| '}'; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| public static class NodeValidationPluginConfiguration implements PluginConfiguration { | ||
| /** */ | ||
| private final String token; | ||
|
|
||
| /** */ | ||
| NodeValidationPluginConfiguration(String token) { | ||
| this.token = token; | ||
| } | ||
|
|
||
| /** */ | ||
| public String getToken() { | ||
| return token; | ||
| } | ||
| } | ||
| } | ||
104 changes: 104 additions & 0 deletions
104
modules/core/src/test/java/org/apache/ignite/plugin/PluginNodeValidationTest.java
This file contains hidden or 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,104 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF 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. | ||
| */ | ||
|
|
||
| package org.apache.ignite.plugin; | ||
|
|
||
| import org.apache.ignite.configuration.DataRegionConfiguration; | ||
| import org.apache.ignite.configuration.DataStorageConfiguration; | ||
| import org.apache.ignite.configuration.IgniteConfiguration; | ||
| import org.apache.ignite.internal.util.typedef.X; | ||
| import org.apache.ignite.spi.IgniteSpiException; | ||
| import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; | ||
| import org.junit.After; | ||
| import org.junit.AfterClass; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.JUnit4; | ||
|
|
||
| /** | ||
| * Test node validation on join by plugin. | ||
| */ | ||
| @RunWith(JUnit4.class) | ||
| public class PluginNodeValidationTest extends GridCommonAbstractTest { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add comments as per CC |
||
|
|
||
| /** */ | ||
| private volatile String token; | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { | ||
| IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); | ||
|
|
||
| cfg.setDataStorageConfiguration(new DataStorageConfiguration() | ||
| .setDefaultDataRegionConfiguration(new DataRegionConfiguration() | ||
| .setMaxSize(100L * 1024 * 1024) | ||
| .setPersistenceEnabled(true))); | ||
|
|
||
| cfg.setConsistentId(igniteInstanceName); | ||
|
|
||
| cfg.setPluginConfigurations(new NodeValidationPluginProvider.NodeValidationPluginConfiguration(token)); | ||
|
|
||
| return cfg; | ||
| } | ||
|
|
||
| /** Tests that node join fails due failure in node validation. */ | ||
| @Test | ||
| public void testValidationException() throws Exception { | ||
| token = "123456"; | ||
|
|
||
| startGrid(0); | ||
|
|
||
| token = "abcdef"; | ||
|
|
||
| try { | ||
| startGrid(1); | ||
| } catch (Exception ex) { | ||
| assertTrue("Wrong exception type for validation error", X.hasCause(ex, IgniteSpiException.class)); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| fail("Exception is expected due validation error in plugin"); | ||
| } | ||
|
|
||
| /** Tests that node joins on successful node validation by plugin. */ | ||
| @Test | ||
| public void testSuccessfulValidation() throws Exception { | ||
| token = "123456"; | ||
|
|
||
| startGrid(0); | ||
| startGrid(1); | ||
| } | ||
|
|
||
| /** Stop all nodes after each test. */ | ||
| @After | ||
| public void after() { | ||
| stopAllGrids(); | ||
| } | ||
|
|
||
| /** Enables plugin before test start. */ | ||
| @BeforeClass | ||
| public static void enablePlugin() { | ||
| NodeValidationPluginProvider.setEnabled(true); | ||
| } | ||
|
|
||
| /** Disable plugin after test end. */ | ||
| @AfterClass | ||
| public static void disablePlugin() { | ||
| NodeValidationPluginProvider.setEnabled(false); | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
License is desired