Repository: reef Updated Branches: refs/heads/master 273029b0b -> 6d4e4012f
[REEF-1228] Fix TestDriverConfigGenerator failure on the first test run This change modifies TestDriverConfigGenerator to extract reef-bridge-java-<version>-shaded.jar from O.A.R.Client assembly resources before running tests. JIRA: [REEF-1228](https://issues.apache.org/jira/browse/REEF-1228) Pull request: This closes #, #869 Project: http://git-wip-us.apache.org/repos/asf/reef/repo Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/6d4e4012 Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/6d4e4012 Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/6d4e4012 Branch: refs/heads/master Commit: 6d4e4012f8e7729d317fbbe45017acb4d5658b85 Parents: 273029b Author: Mariia Mykhailova <[email protected]> Authored: Tue Mar 1 16:23:45 2016 -0800 Committer: Dongjoon Hyun <[email protected]> Committed: Wed Mar 2 11:38:33 2016 -0800 ---------------------------------------------------------------------- .../Common/DriverFolderPreparationHelper.cs | 26 +---- .../Common/ResourceHelper.cs | 89 --------------- .../Org.Apache.REEF.Client.csproj | 1 - .../Jar/ResourceHelper.cs | 111 +++++++++++++++++++ .../Org.Apache.REEF.Common.csproj | 1 + .../Utility/TestDriverConfigGenerator.cs | 14 +++ 6 files changed, 131 insertions(+), 111 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/reef/blob/6d4e4012/lang/cs/Org.Apache.REEF.Client/Common/DriverFolderPreparationHelper.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Client/Common/DriverFolderPreparationHelper.cs b/lang/cs/Org.Apache.REEF.Client/Common/DriverFolderPreparationHelper.cs index 7c63498..f579ee1 100644 --- a/lang/cs/Org.Apache.REEF.Client/Common/DriverFolderPreparationHelper.cs +++ b/lang/cs/Org.Apache.REEF.Client/Common/DriverFolderPreparationHelper.cs @@ -21,6 +21,7 @@ using System.Linq; using Org.Apache.REEF.Client.API; using Org.Apache.REEF.Common; using Org.Apache.REEF.Common.Files; +using Org.Apache.REEF.Common.Jar; using Org.Apache.REEF.Tang.Annotations; using Org.Apache.REEF.Tang.Formats; using Org.Apache.REEF.Tang.Implementations.Configuration; @@ -35,8 +36,6 @@ namespace Org.Apache.REEF.Client.Common { private const string DLLFileNameExtension = ".dll"; private const string EXEFileNameExtension = ".exe"; - private const string BridgeExe = "Org.Apache.REEF.Bridge.exe"; - private const string ClrDriverFullName = "ClrDriverFullName"; private const string DefaultDriverConfigurationFileContents = @"<configuration>" + @" <runtime>" + @@ -46,21 +45,6 @@ namespace Org.Apache.REEF.Client.Common @" </runtime>" + @"</configuration>"; - // We embed certain binaries in client dll. - // Following items in tuples refer to resource names in Org.Apache.REEF.Client.dll - // The first resource item contains the name of the file - // such as "reef-bridge-java-0.13.0-SNAPSHOT-shaded.jar". The second resource - // item contains the byte contents for said file. - // Please note that the identifiers below need to be in sync with 2 other files - // 1. $(SolutionDir)\Org.Apache.REEF.Client\Properties\Resources.xml - // 2. $(SolutionDir)\Org.Apache.REEF.Client\Org.Apache.REEF.Client.csproj - private readonly static Tuple<string, string>[] clientFileResources = new Tuple<string, string>[] - { - new Tuple<string, string>("ClientJarFullName", "reef_bridge_client"), - new Tuple<string, string>("DriverJarFullName", "reef_bridge_driver"), - new Tuple<string, string>(ClrDriverFullName, "reef_clrdriver"), - }; - private static readonly Logger Logger = Logger.GetLogger(typeof(DriverFolderPreparationHelper)); private readonly AvroConfigurationSerializer _configurationSerializer; private readonly REEFFileNames _fileNames; @@ -135,14 +119,14 @@ namespace Org.Apache.REEF.Client.Common Directory.CreateDirectory(Path.Combine(driverFolderPath, _fileNames.GetGlobalFolderPath())); var resourceHelper = new ResourceHelper(typeof(DriverFolderPreparationHelper).Assembly); - foreach (var fileResources in clientFileResources) + foreach (var fileResources in ResourceHelper.FileResources) { - var fileName = resourceHelper.GetString(fileResources.Item1); - if (ClrDriverFullName == fileResources.Item1) + var fileName = resourceHelper.GetString(fileResources.Key); + if (ResourceHelper.ClrDriverFullName == fileResources.Key) { fileName = Path.Combine(driverFolderPath, _fileNames.GetBridgeExePath()); } - File.WriteAllBytes(fileName, resourceHelper.GetBytes(fileResources.Item2)); + File.WriteAllBytes(fileName, resourceHelper.GetBytes(fileResources.Value)); } var config = DefaultDriverConfigurationFileContents; http://git-wip-us.apache.org/repos/asf/reef/blob/6d4e4012/lang/cs/Org.Apache.REEF.Client/Common/ResourceHelper.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Client/Common/ResourceHelper.cs b/lang/cs/Org.Apache.REEF.Client/Common/ResourceHelper.cs deleted file mode 100644 index 84920fa..0000000 --- a/lang/cs/Org.Apache.REEF.Client/Common/ResourceHelper.cs +++ /dev/null @@ -1,89 +0,0 @@ -// 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. - -using System; -using System.Reflection; -using System.Resources; - -namespace Org.Apache.REEF.Client.Common -{ - /// <summary> - /// Helps with retrieval of embedded resources. - /// See Org.Apache.REEF.Client.csproj for embedding resources and use this class to retrieve them. - /// </summary> - internal class ResourceHelper - { - private const string CouldNotRetrieveResource = "Could not retrieve resource '{0}'"; - private readonly ResourceSet _resourceSet; - - /// <summary> - /// Given an assembly, returns a ResourceSet for it. - /// </summary> - /// <param name="assembly"></param> - /// <returns>ResourceSet</returns> - internal ResourceHelper(Assembly assembly) - { - var names = assembly.GetManifestResourceNames(); - if (null == names[0]) - { - throw new ApplicationException("Could not retrieve Assembly Manifest Resource names"); - } - var manifestResources = assembly.GetManifestResourceStream(names[0]); - if (null == manifestResources) - { - throw new ApplicationException("Could not retrieve Assembly Manifest Resource stream"); - } - - _resourceSet = new ResourceSet(manifestResources); - } - - /// <summary> - /// Given resource name, returns corresponding resource - /// </summary> - /// <param name="resourceName"></param> - /// <returns>T</returns> - internal T GetResource<T>(string resourceName) - { - var resource = _resourceSet.GetObject(resourceName); - if (null == resource) - { - throw new ApplicationException(string.Format(CouldNotRetrieveResource, resourceName)); - } - return (T)resource; - } - - /// <summary> - /// Given resource name, returns corresponding resource - /// </summary> - /// <param name="resourceName"></param> - /// <returns>T</returns> - internal string GetString(string resourceName) - { - return GetResource<string>(resourceName); - } - - /// <summary> - /// Given resource name, returns corresponding resource - /// </summary> - /// <param name="resourceName"></param> - /// <returns>T</returns> - internal byte[] GetBytes(string resourceName) - { - return GetResource<byte[]>(resourceName); - } - } -} http://git-wip-us.apache.org/repos/asf/reef/blob/6d4e4012/lang/cs/Org.Apache.REEF.Client/Org.Apache.REEF.Client.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Client/Org.Apache.REEF.Client.csproj b/lang/cs/Org.Apache.REEF.Client/Org.Apache.REEF.Client.csproj index a492a68..14184c4 100644 --- a/lang/cs/Org.Apache.REEF.Client/Org.Apache.REEF.Client.csproj +++ b/lang/cs/Org.Apache.REEF.Client/Org.Apache.REEF.Client.csproj @@ -92,7 +92,6 @@ under the License. <Compile Include="Common\JobSubmissionResult.cs" /> <Compile Include="Common\JavaClientLauncher.cs" /> <Compile Include="Common\ResourceArchiveFileGenerator.cs" /> - <Compile Include="Common\ResourceHelper.cs" /> <Compile Include="Local\LocalClient.cs" /> <Compile Include="Local\LocalJobSubmissionResult.cs" /> <Compile Include="Local\LocalRuntimeClientConfiguration.cs" /> http://git-wip-us.apache.org/repos/asf/reef/blob/6d4e4012/lang/cs/Org.Apache.REEF.Common/Jar/ResourceHelper.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Jar/ResourceHelper.cs b/lang/cs/Org.Apache.REEF.Common/Jar/ResourceHelper.cs new file mode 100644 index 0000000..e6aafec --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/Jar/ResourceHelper.cs @@ -0,0 +1,111 @@ +// 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. + +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Resources; +using Org.Apache.REEF.Utilities.Attributes; + +namespace Org.Apache.REEF.Common.Jar +{ + /// <summary> + /// Helps with retrieval of embedded resources. + /// See Org.Apache.REEF.Client.csproj for embedding resources and use this class to retrieve them. + /// </summary> + [Private] + public class ResourceHelper + { + public const string ClientJarFullName = "ClientJarFullName"; + public const string DriverJarFullName = "DriverJarFullName"; + public const string ClrDriverFullName = "ClrDriverFullName"; + + // We embed certain binaries in client dll. + // Following items in tuples refer to resource names in Org.Apache.REEF.Client.dll + // The first resource item contains the name of the file + // such as "reef-bridge-java-<version>-shaded.jar". The second resource + // item contains the byte contents for said file. + // Please note that the identifiers below need to be in sync with 2 other files + // 1. $(SolutionDir)\Org.Apache.REEF.Client\Properties\Resources.xml + // 2. $(SolutionDir)\Org.Apache.REEF.Client\Org.Apache.REEF.Client.csproj + public readonly static Dictionary<string, string> FileResources = new Dictionary<string, string> + { + { ClientJarFullName, "reef_bridge_client" }, + { DriverJarFullName, "reef_bridge_driver" }, + { ClrDriverFullName, "reef_clrdriver" }, + }; + + private const string CouldNotRetrieveResource = "Could not retrieve resource '{0}'"; + private readonly ResourceSet _resourceSet; + + /// <summary> + /// Given an assembly, returns a ResourceSet for it. + /// </summary> + /// <param name="assembly"></param> + /// <returns>ResourceSet</returns> + public ResourceHelper(Assembly assembly) + { + var names = assembly.GetManifestResourceNames(); + if (null == names[0]) + { + throw new ApplicationException("Could not retrieve Assembly Manifest Resource names"); + } + var manifestResources = assembly.GetManifestResourceStream(names[0]); + if (null == manifestResources) + { + throw new ApplicationException("Could not retrieve Assembly Manifest Resource stream"); + } + + _resourceSet = new ResourceSet(manifestResources); + } + + /// <summary> + /// Given resource name, returns corresponding resource + /// </summary> + /// <param name="resourceName"></param> + /// <returns>T</returns> + internal T GetResource<T>(string resourceName) + { + var resource = _resourceSet.GetObject(resourceName); + if (null == resource) + { + throw new ApplicationException(string.Format(CouldNotRetrieveResource, resourceName)); + } + return (T)resource; + } + + /// <summary> + /// Given resource name, returns corresponding resource + /// </summary> + /// <param name="resourceName"></param> + /// <returns>T</returns> + public string GetString(string resourceName) + { + return GetResource<string>(resourceName); + } + + /// <summary> + /// Given resource name, returns corresponding resource + /// </summary> + /// <param name="resourceName"></param> + /// <returns>T</returns> + public byte[] GetBytes(string resourceName) + { + return GetResource<byte[]>(resourceName); + } + } +} http://git-wip-us.apache.org/repos/asf/reef/blob/6d4e4012/lang/cs/Org.Apache.REEF.Common/Org.Apache.REEF.Common.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Org.Apache.REEF.Common.csproj b/lang/cs/Org.Apache.REEF.Common/Org.Apache.REEF.Common.csproj index b5d53cf..dcb0c1f 100644 --- a/lang/cs/Org.Apache.REEF.Common/Org.Apache.REEF.Common.csproj +++ b/lang/cs/Org.Apache.REEF.Common/Org.Apache.REEF.Common.csproj @@ -107,6 +107,7 @@ under the License. <Compile Include="Io\NamingConfiguration.cs" /> <Compile Include="Io\NamingConfigurationOptions.cs" /> <Compile Include="Io\TcpPortConfigurationProvider.cs" /> + <Compile Include="Jar\ResourceHelper.cs" /> <Compile Include="ITaskSubmittable.cs" /> <Compile Include="Client\Parameters\DriverConfigurationProviders.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> http://git-wip-us.apache.org/repos/asf/reef/blob/6d4e4012/lang/cs/Org.Apache.REEF.Tests/Utility/TestDriverConfigGenerator.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tests/Utility/TestDriverConfigGenerator.cs b/lang/cs/Org.Apache.REEF.Tests/Utility/TestDriverConfigGenerator.cs index 6b89232..7d55f41 100644 --- a/lang/cs/Org.Apache.REEF.Tests/Utility/TestDriverConfigGenerator.cs +++ b/lang/cs/Org.Apache.REEF.Tests/Utility/TestDriverConfigGenerator.cs @@ -16,13 +16,27 @@ // under the License. using System; +using System.IO; using Org.Apache.REEF.Driver; +using Org.Apache.REEF.Client.Common; +using Org.Apache.REEF.Common.Jar; using Xunit; namespace Org.Apache.REEF.Tests.Utility { public class TestDriverConfigGenerator { + public TestDriverConfigGenerator() + { + var resourceHelper = new ResourceHelper(typeof(IJobSubmissionResult).Assembly); + var fileName = resourceHelper.GetString(ResourceHelper.DriverJarFullName); + if (!File.Exists(fileName)) + { + File.WriteAllBytes(fileName, + resourceHelper.GetBytes(ResourceHelper.FileResources[ResourceHelper.DriverJarFullName])); + } + } + [Fact] public void TestGeneratingFullDriverConfigFile() {
