Repository: incubator-ignite Updated Branches: refs/heads/ignite-1108 [created] affce40be
IGNITE-1108 Added methods on PluginProvide interface. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/affce40b Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/affce40b Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/affce40b Branch: refs/heads/ignite-1108 Commit: affce40bed8726388e0b856f696cd61b3273615e Parents: aa2d7cb Author: nikolay_tikhonov <ntikho...@gridgain.com> Authored: Mon Jul 13 20:04:08 2015 +0300 Committer: nikolay_tikhonov <ntikho...@gridgain.com> Committed: Mon Jul 13 20:04:08 2015 +0300 ---------------------------------------------------------------------- .../ignite/internal/GridPluginComponent.java | 4 +- .../apache/ignite/internal/IgniteKernal.java | 14 +++ .../plugin/IgnitePluginProcessor.java | 3 + .../apache/ignite/plugin/PluginProvider.java | 30 +++-- .../ignite/plugin/PluginProviderAdapter.java | 105 ++++++++++++++++ .../org.apache.ignite.plugin.PluginProvider | 1 + .../internal/IgnitePluginLifecycleSelfTest.java | 124 +++++++++++++++++++ .../testsuites/IgniteComputeGridTestSuite.java | 1 + 8 files changed, 272 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/affce40b/modules/core/src/main/java/org/apache/ignite/internal/GridPluginComponent.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridPluginComponent.java b/modules/core/src/main/java/org/apache/ignite/internal/GridPluginComponent.java index b438bc1..0087a19 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridPluginComponent.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridPluginComponent.java @@ -60,12 +60,12 @@ public class GridPluginComponent implements GridComponent { /** {@inheritDoc} */ @Override public void onKernalStart() throws IgniteCheckedException { - plugin.onIgniteStart(); + plugin.onAfterStart(); } /** {@inheritDoc} */ @Override public void onKernalStop(boolean cancel) { - plugin.onIgniteStop(cancel); + plugin.onBeforeStop(cancel); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/affce40b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java index 024dc7b..5af2f21 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java @@ -1801,6 +1801,20 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable { } } + for (PluginProvider plugin : ctx.plugins().allProviders()) { + try { + plugin.onAfterStop(cancel); + } + catch (Throwable e) { + errOnStop = true; + + U.error(log, "Failed to stop component (ignoring): " + plugin, e); + + if (e instanceof Error) + throw (Error)e; + } + } + // Stops lifecycle aware components. U.stopLifecycleAware(log, lifecycleAwares(cfg)); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/affce40b/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/IgnitePluginProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/IgnitePluginProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/IgnitePluginProcessor.java index 5e24b4b..f8d65c2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/IgnitePluginProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/IgnitePluginProcessor.java @@ -132,6 +132,9 @@ public class IgnitePluginProcessor extends GridProcessorAdapter { /** {@inheritDoc} */ @Override public void start() throws IgniteCheckedException { + for (PluginProvider plugin : plugins.values()) + plugin.onBeforeStart(); + ackPluginsInfo(); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/affce40b/modules/core/src/main/java/org/apache/ignite/plugin/PluginProvider.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/PluginProvider.java b/modules/core/src/main/java/org/apache/ignite/plugin/PluginProvider.java index f064fde..a020991 100644 --- a/modules/core/src/main/java/org/apache/ignite/plugin/PluginProvider.java +++ b/modules/core/src/main/java/org/apache/ignite/plugin/PluginProvider.java @@ -75,6 +75,13 @@ public interface PluginProvider<C extends PluginConfiguration> { @Nullable public <T> T createComponent(PluginContext ctx, Class<T> cls); /** + * Callback that notifies that Ignite prepares to start plugin. + * + * @throws IgniteCheckedException Thrown in case of any errors. + */ + public void onBeforeStart() throws IgniteCheckedException; + + /** * Starts grid component. * * @param ctx Plugin context. @@ -83,28 +90,35 @@ public interface PluginProvider<C extends PluginConfiguration> { public void start(PluginContext ctx) throws IgniteCheckedException; /** - * Stops grid component. + * Callback that notifies that Ignite has successfully started, + * including all internal components. * - * @param cancel If {@code true}, then all ongoing tasks or jobs for relevant - * components need to be cancelled. * @throws IgniteCheckedException Thrown in case of any errors. */ - public void stop(boolean cancel) throws IgniteCheckedException; + public void onAfterStart() throws IgniteCheckedException; /** - * Callback that notifies that Ignite has successfully started, - * including all internal components. + * Callback that notifies that internal components have successfully stopped. * + * @param cancel Flag indicating whether jobs should be canceled. + */ + public void onAfterStop(boolean cancel) throws IgniteCheckedException; + + /** + * Stops grid component. + * + * @param cancel If {@code true}, then all ongoing tasks or jobs for relevant + * components need to be cancelled. * @throws IgniteCheckedException Thrown in case of any errors. */ - public void onIgniteStart() throws IgniteCheckedException; + public void stop(boolean cancel) throws IgniteCheckedException; /** * Callback to notify that Ignite is about to stop. * * @param cancel Flag indicating whether jobs should be canceled. */ - public void onIgniteStop(boolean cancel); + public void onBeforeStop(boolean cancel); /** * Gets plugin discovery data object that will be sent to the new node http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/affce40b/modules/core/src/main/java/org/apache/ignite/plugin/PluginProviderAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/PluginProviderAdapter.java b/modules/core/src/main/java/org/apache/ignite/plugin/PluginProviderAdapter.java new file mode 100644 index 0000000..bef7000 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/plugin/PluginProviderAdapter.java @@ -0,0 +1,105 @@ +/* + * 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.*; +import org.apache.ignite.cluster.*; +import org.jetbrains.annotations.*; + +import java.io.*; +import java.util.*; + +/** + * Adapter for {@link PluginProvider}. + */ +public class PluginProviderAdapter<C extends PluginConfiguration> implements PluginProvider<C> { + /** {@inheritDoc} */ + @Override public String name() { + return null; + } + + /** {@inheritDoc} */ + @Override public String version() { + return null; + } + + /** {@inheritDoc} */ + @Override public String copyright() { + return null; + } + + /** {@inheritDoc} */ + @Override public <T extends IgnitePlugin> T plugin() { + return null; + } + + /** {@inheritDoc} */ + @Override public void initExtensions(PluginContext ctx, ExtensionRegistry registry) { + // No-op. + } + + /** {@inheritDoc} */ + @Nullable @Override public <T> T createComponent(PluginContext ctx, Class<T> cls) { + return null; + } + + /** {@inheritDoc} */ + @Override public void onBeforeStart() throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void start(PluginContext ctx) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void onAfterStart() throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void onAfterStop(boolean cancel) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void stop(boolean cancel) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void onBeforeStop(boolean cancel) { + // No-op. + } + + /** {@inheritDoc} */ + @Nullable @Override public Serializable provideDiscoveryData(UUID nodeId) { + return null; + } + + /** {@inheritDoc} */ + @Override public void receiveDiscoveryData(UUID nodeId, Serializable data) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void validateNewNode(ClusterNode node) throws PluginValidationException { + // No-op. + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/affce40b/modules/core/src/test/java/META-INF/services/org.apache.ignite.plugin.PluginProvider ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/META-INF/services/org.apache.ignite.plugin.PluginProvider b/modules/core/src/test/java/META-INF/services/org.apache.ignite.plugin.PluginProvider new file mode 100644 index 0000000..ed68caf --- /dev/null +++ b/modules/core/src/test/java/META-INF/services/org.apache.ignite.plugin.PluginProvider @@ -0,0 +1 @@ +org.apache.ignite.internal.IgnitePluginLifecycleSelfTest$TestPluginProvider \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/affce40b/modules/core/src/test/java/org/apache/ignite/internal/IgnitePluginLifecycleSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgnitePluginLifecycleSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgnitePluginLifecycleSelfTest.java new file mode 100644 index 0000000..43c1c05 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/IgnitePluginLifecycleSelfTest.java @@ -0,0 +1,124 @@ +/* + * 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.internal; + +import org.apache.ignite.*; +import org.apache.ignite.plugin.*; +import org.apache.ignite.testframework.*; +import org.apache.ignite.testframework.junits.common.*; + +import java.util.concurrent.*; + +/** + * + */ +@GridCommonTest(group = "Kernal Self") +public class IgnitePluginLifecycleSelfTest extends GridCommonAbstractTest { + /** */ + public IgnitePluginLifecycleSelfTest() { + super(false); + } + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return 10000; + } + + /** + * @throws Exception If an error occurs. + */ + public void testStopGrid() throws Exception { + try { + startGrid("testGrid"); + } + finally { + stopGrid("testGrid", true); + } + + assertTrue(TestPluginProvider.bfStart && TestPluginProvider.start && TestPluginProvider.afStart + && TestPluginProvider.bfStop && TestPluginProvider.stop && TestPluginProvider.afStop + ); + } + + /** */ + public static class TestPluginCfg implements PluginConfiguration { + } + + /** */ + public static class TestPluginProvider extends PluginProviderAdapter<TestPluginCfg> { + /** */ + IgniteKernal ignite; + + public static boolean bfStart, start, afStart, bfStop, stop, afStop; + + + /** {@inheritDoc} */ + @Override public String name() { + return "TestPlugin"; + } + + /** {@inheritDoc} */ + @Override public IgnitePlugin plugin() { + return new IgnitePlugin() {}; + } + + /** {@inheritDoc} */ + @Override public void onBeforeStart() throws IgniteCheckedException { + bfStart = true; + + assertFalse(start || afStart || bfStop || stop || afStop); + } + + /** {@inheritDoc} */ + @Override public void start(PluginContext ctx) throws IgniteCheckedException { + ignite = (IgniteKernal)ctx.grid(); + + start = true; + + assertFalse(afStart || bfStop || stop || afStop); + } + + @Override public void onAfterStart() throws IgniteCheckedException { + afStart = true; + + assertFalse(bfStop || stop || afStop); + } + + @Override public void onBeforeStop(boolean cancel) { + bfStop = true; + + assertFalse(stop || afStop); + } + + @Override public void stop(boolean cancel) throws IgniteCheckedException { + stop = true; + + assertFalse(afStop); + } + + @Override public void onAfterStop(boolean cancel) { + GridTestUtils.assertThrows(null, new Callable<Object>() { + @Override public Object call() throws Exception { + return ignite.cache(null); + } + }, IllegalStateException.class, null); + + afStop = true; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/affce40b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java index baf425c8..2f81d6f 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java @@ -94,6 +94,7 @@ public class IgniteComputeGridTestSuite { suite.addTestSuite(IgniteComputeEmptyClusterGroupTest.class); suite.addTestSuite(IgniteComputeTopologyExceptionTest.class); suite.addTestSuite(GridTaskFailoverAffinityRunTest.class); + suite.addTestSuite(IgnitePluginLifecycleSelfTest.class); return suite; }