You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2016/03/09 15:17:46 UTC
[2/6] ignite git commit: IGNITE-2740: .NET: Improved IGNITE_HOME
handling. This closes #531.
IGNITE-2740: .NET: Improved IGNITE_HOME handling. This closes #531.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e92aba47
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e92aba47
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e92aba47
Branch: refs/heads/ignite-1786
Commit: e92aba47a39d8fa0ee920a0bcfd98c3e94fe2080
Parents: 057dfa7
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Wed Mar 9 13:10:15 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Mar 9 13:10:15 2016 +0300
----------------------------------------------------------------------
.../Apache.Ignite.Core.Tests.csproj | 1 +
.../Apache.Ignite.Core.Tests/DeploymentTest.cs | 180 +++++++++++++++++++
.../Process/IgniteProcess.cs | 15 +-
.../Apache.Ignite.Core/Impl/Common/Classpath.cs | 18 +-
.../Impl/Common/IgniteHome.cs | 2 +-
.../Apache.Ignite.Core/Impl/IgniteManager.cs | 11 +-
6 files changed, 193 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/e92aba47/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
index e72fb85..bb25536 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
@@ -111,6 +111,7 @@
<Compile Include="DataStructures\AtomicLongTest.cs" />
<Compile Include="DataStructures\AtomicReferenceTest.cs" />
<Compile Include="DataStructures\AtomicSequenceTest.cs" />
+ <Compile Include="DeploymentTest.cs" />
<Compile Include="EventsTest.cs" />
<Compile Include="Examples\Example.cs" />
<Compile Include="Examples\ExamplesTest.cs" />
http://git-wip-us.apache.org/repos/asf/ignite/blob/e92aba47/modules/platforms/dotnet/Apache.Ignite.Core.Tests/DeploymentTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/DeploymentTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/DeploymentTest.cs
new file mode 100644
index 0000000..bc764c7
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/DeploymentTest.cs
@@ -0,0 +1,180 @@
+/*
+ * 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.
+ */
+
+#pragma warning disable 649
+#pragma warning disable 169
+#pragma warning disable 618
+namespace Apache.Ignite.Core.Tests
+{
+ using System;
+ using System.IO;
+ using System.Linq;
+ using Apache.Ignite.Core.Compute;
+ using Apache.Ignite.Core.Impl.Common;
+ using Apache.Ignite.Core.Resource;
+ using Apache.Ignite.Core.Tests.Process;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Tests custom JAR deployment, classpath and IgniteHome logic.
+ /// </summary>
+ public class DeploymentTest
+ {
+ /// <summary>
+ /// Tests the custom deployment where IGNITE_HOME can't be resolved, and there is a user-defined classpath.
+ /// </summary>
+ [Test]
+ public void TestCustomDeployment()
+ {
+ // Create temp folder
+ var folder = GetTempFolder();
+
+ // Copy jars
+ var home = IgniteHome.Resolve(null);
+
+ var jarNames = new[] {@"\ignite-core-", @"\cache-api-1.0.0.jar", @"\modules\spring\" };
+
+ var jars = Directory.GetFiles(home, "*.jar", SearchOption.AllDirectories)
+ .Where(jarPath => jarNames.Any(jarPath.Contains)).ToArray();
+
+ Assert.Greater(jars.Length, 3);
+
+ foreach (var jar in jars)
+ // ReSharper disable once AssignNullToNotNullAttribute
+ File.Copy(jar, Path.Combine(folder, Path.GetFileName(jar)), true);
+
+ // Build classpath
+ var classpath = string.Join(";", Directory.GetFiles(folder).Select(Path.GetFileName));
+
+ // Copy .NET binaries
+ foreach (var asm in new[] {typeof (IgniteRunner).Assembly, typeof (Ignition).Assembly, GetType().Assembly})
+ File.Copy(asm.Location, Path.Combine(folder, Path.GetFileName(asm.Location)));
+
+ // Copy config
+ var springPath = Path.GetFullPath("config\\compute\\compute-grid2.xml");
+ var springFile = Path.GetFileName(springPath);
+ File.Copy(springPath, Path.Combine(folder, springFile));
+
+ // Start a node and make sure it works properly
+ var exePath = Path.Combine(folder, "Apache.Ignite.exe");
+
+ var proc = IgniteProcess.Start(exePath, string.Empty, args: new[]
+ {
+ "-springConfigUrl=" + springFile,
+ "-jvmClasspath=" + classpath,
+ "-J-ea",
+ "-J-Xcheck:jni",
+ "-J-Xms512m",
+ "-J-Xmx512m"
+ });
+
+ Assert.IsNotNull(proc);
+
+ try
+ {
+ VerifyNodeStarted(exePath);
+ }
+ finally
+ {
+ proc.Kill();
+
+ Assert.IsTrue(
+ TestUtils.WaitForCondition(() =>
+ {
+ try
+ {
+ Directory.Delete(folder, true);
+ return true;
+ }
+ catch (Exception)
+ {
+ return false;
+ }
+ }, 1000), "Failed to remove temp directory: " + folder);
+ }
+ }
+
+ /// <summary>
+ /// Verifies that custom-deployed node has started.
+ /// </summary>
+ private static void VerifyNodeStarted(string exePath)
+ {
+ using (var ignite = Ignition.Start(new IgniteConfiguration
+ {
+ SpringConfigUrl = "config\\compute\\compute-grid1.xml",
+ JvmClasspath = TestUtils.CreateTestClasspath(),
+ JvmOptions = TestUtils.TestJavaOptions()
+ }))
+ {
+ Assert.IsTrue(ignite.WaitTopology(2));
+
+ var remoteProcPath = ignite.GetCluster().ForRemotes().GetCompute().Call(new ProcessPathFunc());
+
+ Assert.AreEqual(exePath, remoteProcPath);
+ }
+ }
+
+ /// <summary>
+ /// Gets the temporary folder.
+ /// </summary>
+ private static string GetTempFolder()
+ {
+ const string prefix = "ig-test-";
+ var temp = Path.GetTempPath();
+
+ for (int i = 0; i < int.MaxValue; i++)
+ {
+ {
+ try
+ {
+ var path = Path.Combine(temp, prefix + i);
+
+ if (Directory.Exists(path))
+ Directory.Delete(path, true);
+
+ return Directory.CreateDirectory(path).FullName;
+ }
+ catch (Exception)
+ {
+ // Ignore
+ }
+ }
+ }
+
+ throw new InvalidOperationException();
+ }
+
+ /// <summary>
+ /// Function that returns process path.
+ /// </summary>
+ [Serializable]
+ private class ProcessPathFunc : IComputeFunc<string>
+ {
+ [InstanceResource]
+ private IIgnite _ignite;
+
+ /** <inheritdoc /> */
+ public string Invoke()
+ {
+ // Should be null
+ var igniteHome = _ignite.GetConfiguration().IgniteHome;
+
+ return typeof(IgniteRunner).Assembly.Location + igniteHome;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e92aba47/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Process/IgniteProcess.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Process/IgniteProcess.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Process/IgniteProcess.cs
index 85464e9..852551a 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Process/IgniteProcess.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Process/IgniteProcess.cs
@@ -162,7 +162,6 @@ namespace Apache.Ignite.Core.Tests.Process
params string[] args)
{
Debug.Assert(!string.IsNullOrEmpty(exePath));
- Debug.Assert(!string.IsNullOrEmpty(ggHome));
// 1. Define process start configuration.
var sb = new StringBuilder();
@@ -173,20 +172,18 @@ namespace Apache.Ignite.Core.Tests.Process
var procStart = new ProcessStartInfo
{
FileName = exePath,
- Arguments = sb.ToString()
+ Arguments = sb.ToString(),
+ CreateNoWindow = true,
+ UseShellExecute = false,
+ RedirectStandardOutput = true,
+ RedirectStandardError = true
};
- if (!string.IsNullOrEmpty(ggHome))
+ if (ggHome != null)
procStart.EnvironmentVariables[IgniteHome.EnvIgniteHome] = ggHome;
procStart.EnvironmentVariables[Classpath.EnvIgniteNativeTestClasspath] = "true";
- procStart.CreateNoWindow = true;
- procStart.UseShellExecute = false;
-
- procStart.RedirectStandardOutput = true;
- procStart.RedirectStandardError = true;
-
var workDir = Path.GetDirectoryName(exePath);
if (workDir != null)
http://git-wip-us.apache.org/repos/asf/ignite/blob/e92aba47/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/Classpath.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/Classpath.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/Classpath.cs
index f1c8627..be68074 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/Classpath.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/Classpath.cs
@@ -36,26 +36,12 @@ namespace Apache.Ignite.Core.Impl.Common
/// Creates classpath from the given configuration, or default classpath if given config is null.
/// </summary>
/// <param name="cfg">The configuration.</param>
- /// <param name="forceTestClasspath">Append test directories even if <see cref="EnvIgniteNativeTestClasspath" /> is not set.</param>
- /// <returns>
- /// Classpath string.
- /// </returns>
- public static string CreateClasspath(IgniteConfiguration cfg = null, bool forceTestClasspath = false)
- {
- return CreateClasspath(IgniteHome.Resolve(cfg), cfg, forceTestClasspath);
- }
-
- /// <summary>
- /// Creates classpath from the given configuration, or default classpath if given config is null.
- /// </summary>
- /// <param name="ggHome">The home dir.</param>
- /// <param name="cfg">The configuration.</param>
/// <param name="forceTestClasspath">Append test directories even if
/// <see cref="EnvIgniteNativeTestClasspath" /> is not set.</param>
/// <returns>
/// Classpath string.
/// </returns>
- internal static string CreateClasspath(string ggHome, IgniteConfiguration cfg, bool forceTestClasspath)
+ internal static string CreateClasspath(IgniteConfiguration cfg = null, bool forceTestClasspath = false)
{
var cpStr = new StringBuilder();
@@ -67,6 +53,8 @@ namespace Apache.Ignite.Core.Impl.Common
cpStr.Append(';');
}
+ var ggHome = IgniteHome.Resolve(cfg);
+
if (!string.IsNullOrWhiteSpace(ggHome))
AppendHomeClasspath(ggHome, forceTestClasspath, cpStr);
http://git-wip-us.apache.org/repos/asf/ignite/blob/e92aba47/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/IgniteHome.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/IgniteHome.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/IgniteHome.cs
index ebf5e0f..6485201 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/IgniteHome.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/IgniteHome.cs
@@ -78,7 +78,7 @@ namespace Apache.Ignite.Core.Impl.Common
}
}
- throw new IgniteException("Failed to resolve Ignite home.");
+ return null;
}
/// <summary>
http://git-wip-us.apache.org/repos/asf/ignite/blob/e92aba47/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
index a61edf4..b35c46f 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
@@ -120,23 +120,16 @@ namespace Apache.Ignite.Core.Impl
/// <returns>JVM.</returns>
private static void* CreateJvm(IgniteConfiguration cfg, UnmanagedCallbacks cbs)
{
- var ggHome = IgniteHome.Resolve(cfg);
-
- var cp = Classpath.CreateClasspath(ggHome, cfg, false);
+ var cp = Classpath.CreateClasspath(cfg);
var jvmOpts = GetMergedJvmOptions(cfg);
- var hasGgHome = !string.IsNullOrWhiteSpace(ggHome);
-
- var opts = new sbyte*[1 + jvmOpts.Count + (hasGgHome ? 1 : 0)];
+ var opts = new sbyte*[1 + jvmOpts.Count];
int idx = 0;
opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cp);
- if (hasGgHome)
- opts[idx++] = IgniteUtils.StringToUtf8Unmanaged("-DIGNITE_HOME=" + ggHome);
-
foreach (string cfgOpt in jvmOpts)
opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cfgOpt);