Exemplo n.º 1
0
 /// <summary>
 /// Creates the JVM if necessary.
 /// </summary>
 public static void EnsureJvmCreated()
 {
     if (Jvm.Get(true) == null)
     {
         var logger = new TestContextLogger();
         JvmDll.Load(null, logger);
         IgniteManager.CreateJvm(GetTestConfiguration(), logger);
     }
 }
Exemplo n.º 2
0
        public void TestStopFromJava()
        {
            var startTime = DateTime.Now.AddSeconds(-1);

            var exePath    = typeof(IgniteRunner).Assembly.Location;
            var springPath = Path.GetFullPath(@"config\compute\compute-grid1.xml");

            JvmDll.Load(null, new NoopLogger());
            var jvmDll = System.Diagnostics.Process.GetCurrentProcess().Modules
                         .OfType <ProcessModule>()
                         .Single(x => JvmDll.FileJvmDll.Equals(x.ModuleName, StringComparison.OrdinalIgnoreCase));

            IgniteProcess.Start(exePath, string.Empty, args: new[]
            {
                "/install",
                "ForceTestClasspath=true",
                "-springConfigUrl=" + springPath,
                "-jvmDll=" + jvmDll.FileName
            }).WaitForExit();

            var service = GetIgniteService();

            Assert.IsNotNull(service);

            service.Start();  // see IGNITE_HOME\work\log for service instance logs
            WaitForStatus(service, startTime, ServiceControllerStatus.Running);

            using (var ignite = Ignition.Start(new IgniteConfiguration(TestUtils.GetTestConfiguration())
            {
                SpringConfigUrl = springPath
            }))
            {
                Assert.IsTrue(ignite.WaitTopology(2), "Failed to join with service node");

                // Stop remote node via Java task
                // Doing so will fail the task execution
                Assert.Throws <ClusterGroupEmptyException>(() =>
                                                           ignite.GetCluster().ForRemotes().GetCompute().ExecuteJavaTask <object>(
                                                               "org.apache.ignite.platform.PlatformStopIgniteTask", ignite.Name));

                Assert.IsTrue(ignite.WaitTopology(1), "Failed to stop remote node");

                // Check that service has stopped.
                WaitForStatus(service, startTime, ServiceControllerStatus.Stopped);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Starts Ignite with given configuration.
        /// </summary>
        /// <returns>Started Ignite.</returns>
        public static IIgnite Start(IgniteConfiguration cfg)
        {
            IgniteArgumentCheck.NotNull(cfg, "cfg");

            cfg = new IgniteConfiguration(cfg);  // Create a copy so that config can be modified and reused.

            lock (SyncRoot)
            {
                // 0. Init logger
                var log = cfg.Logger ?? new JavaLogger();

                log.Debug("Starting Ignite.NET " + Assembly.GetExecutingAssembly().GetName().Version);

                // 1. Check GC settings.
                CheckServerGc(cfg, log);

                // 2. Create context.
                JvmDll.Load(cfg.JvmDllPath, log);

                var cbs = IgniteManager.CreateJvmContext(cfg, log);
                var env = cbs.Jvm.AttachCurrentThread();
                log.Debug("JVM started.");

                var gridName = cfg.IgniteInstanceName;

                if (cfg.AutoGenerateIgniteInstanceName)
                {
                    gridName = (gridName ?? "ignite-instance-") + Guid.NewGuid();
                }

                // 3. Create startup object which will guide us through the rest of the process.
                _startup = new Startup(cfg, cbs);

                PlatformJniTarget interopProc = null;

                try
                {
                    // 4. Initiate Ignite start.
                    UU.IgnitionStart(env, cfg.SpringConfigUrl, gridName, ClientMode, cfg.Logger != null, cbs.IgniteId,
                                     cfg.RedirectJavaConsoleOutput);

                    // 5. At this point start routine is finished. We expect STARTUP object to have all necessary data.
                    var node = _startup.Ignite;
                    interopProc = (PlatformJniTarget)node.InteropProcessor;

                    var javaLogger = log as JavaLogger;
                    if (javaLogger != null)
                    {
                        javaLogger.SetIgnite(node);
                    }

                    // 6. On-start callback (notify lifecycle components).
                    node.OnStart();

                    Nodes[new NodeKey(_startup.Name)] = node;

                    return(node);
                }
                catch (Exception ex)
                {
                    // 1. Perform keys cleanup.
                    string name = _startup.Name;

                    if (name != null)
                    {
                        NodeKey key = new NodeKey(name);

                        if (Nodes.ContainsKey(key))
                        {
                            Nodes.Remove(key);
                        }
                    }

                    // 2. Stop Ignite node if it was started.
                    if (interopProc != null)
                    {
                        UU.IgnitionStop(gridName, true);
                    }

                    // 3. Throw error further (use startup error if exists because it is more precise).
                    if (_startup.Error != null)
                    {
                        // Wrap in a new exception to preserve original stack trace.
                        throw new IgniteException("Failed to start Ignite.NET, check inner exception for details",
                                                  _startup.Error);
                    }

                    var jex = ex as JavaException;

                    if (jex == null)
                    {
                        throw;
                    }

                    throw ExceptionUtils.GetException(null, jex);
                }
                finally
                {
                    var ignite = _startup.Ignite;

                    _startup = null;

                    if (ignite != null)
                    {
                        ignite.ProcessorReleaseStart();
                    }
                }
            }
        }