You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by we...@apache.org on 2016/01/06 19:53:20 UTC
reef git commit: [REEF-1080] Add ITempFileCreator
Repository: reef
Updated Branches:
refs/heads/master 928a043fb -> 67894d51b
[REEF-1080] Add ITempFileCreator
* Add ITempFileCreator interface and WorkingDirectoryTempFileCreator similar as
Java did without creating File object as it doesn't make sense in C#
* Add WorkingDirectoryTempFileConfigModule and WorkingDirectoryTempFileConfigProvider
* Add ITempFileCreator as a parameter of FileSystemInputPartition injectable constructor
* Add and modifies test cases
JIRA:
[REEF-1080](https://issues.apache.org/jira/browse/REEF-1080)
Pull Request:
This closes #742
Project: http://git-wip-us.apache.org/repos/asf/reef/repo
Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/67894d51
Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/67894d51
Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/67894d51
Branch: refs/heads/master
Commit: 67894d51b25fb84afa26374620741951f4ac17e0
Parents: 928a043
Author: Julia Wang <ju...@microsoft.com>
Authored: Thu Dec 17 14:37:58 2015 -0800
Committer: Markus Weimer <we...@apache.org>
Committed: Wed Jan 6 10:35:27 2016 -0800
----------------------------------------------------------------------
.../Org.Apache.REEF.IO.Tests.csproj | 3 +-
.../TestFilePartitionInputDataSet.cs | 46 +++++++++++
.../TestTempFolderCreator.cs | 78 ++++++++++++++++++
.../Org.Apache.REEF.IO.csproj | 8 +-
.../FileSystem/FileSystemInputPartition.cs | 10 ++-
.../TempFileCreation/ITempFileCreator.cs | 46 +++++++++++
.../TempFileConfigurationModule.cs | 47 +++++++++++
.../TempFileConfigurationProvider.cs | 58 ++++++++++++++
.../TempFileCreation/TempFileCreator.cs | 84 ++++++++++++++++++++
.../TempFileCreation/TempFileFolder.cs | 31 ++++++++
10 files changed, 406 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/reef/blob/67894d51/lang/cs/Org.Apache.REEF.IO.Tests/Org.Apache.REEF.IO.Tests.csproj
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.IO.Tests/Org.Apache.REEF.IO.Tests.csproj b/lang/cs/Org.Apache.REEF.IO.Tests/Org.Apache.REEF.IO.Tests.csproj
index fb5145b..5a6c3b6 100644
--- a/lang/cs/Org.Apache.REEF.IO.Tests/Org.Apache.REEF.IO.Tests.csproj
+++ b/lang/cs/Org.Apache.REEF.IO.Tests/Org.Apache.REEF.IO.Tests.csproj
@@ -78,6 +78,7 @@ under the License.
<Compile Include="TestHadoopFileSystem.cs" />
<Compile Include="TestLocalFileSystem.cs" />
<Compile Include="TestRandomInputDataSet.cs" />
+ <Compile Include="TestTempFolderCreator.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Common\Org.Apache.REEF.Common.csproj">
@@ -118,4 +119,4 @@ under the License.
<Error Condition="!Exists('$(SolutionDir)\packages\xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '$(PackagesDir)\xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props'))" />
<Error Condition="!Exists('$(SolutionDir)\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '$(PackagesDir)\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
-</Project>
+</Project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/reef/blob/67894d51/lang/cs/Org.Apache.REEF.IO.Tests/TestFilePartitionInputDataSet.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.IO.Tests/TestFilePartitionInputDataSet.cs b/lang/cs/Org.Apache.REEF.IO.Tests/TestFilePartitionInputDataSet.cs
index df80e6d..24f8d47 100644
--- a/lang/cs/Org.Apache.REEF.IO.Tests/TestFilePartitionInputDataSet.cs
+++ b/lang/cs/Org.Apache.REEF.IO.Tests/TestFilePartitionInputDataSet.cs
@@ -25,6 +25,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
using Org.Apache.REEF.IO.PartitionedData;
using Org.Apache.REEF.IO.PartitionedData.FileSystem;
using Org.Apache.REEF.IO.PartitionedData.FileSystem.Parameters;
+using Org.Apache.REEF.IO.TempFileCreation;
using Org.Apache.REEF.Tang.Annotations;
using Org.Apache.REEF.Tang.Formats;
using Org.Apache.REEF.Tang.Implementations.Tang;
@@ -222,6 +223,51 @@ namespace Org.Apache.REEF.IO.Tests
Assert.AreEqual(count, 5);
}
+ /// <remarks>
+ /// This test is to test injected IPartition with TempFileFolerParameter
+ /// </remarks>
+ [TestMethod]
+ public void TestTempFileFolderWithRowDeserializer()
+ {
+ MakeLocalTestFile(sourceFilePath1, new byte[] { 111, 112, 113 });
+ MakeLocalTestFile(sourceFilePath2, new byte[] { 114, 115 });
+
+ var c1 = FileSystemInputPartitionConfiguration<IEnumerable<Row>>.ConfigurationModule
+ .Set(FileSystemInputPartitionConfiguration<IEnumerable<Row>>.FilePathForPartitions, sourceFilePath1)
+ .Set(FileSystemInputPartitionConfiguration<IEnumerable<Row>>.FilePathForPartitions, sourceFilePath2)
+ .Set(FileSystemInputPartitionConfiguration<IEnumerable<Row>>.FileSerializerConfig,
+ GetRowSerializerConfigString())
+ .Build();
+
+ var c2 = TempFileConfigurationModule.ConfigurationModule
+ .Set(TempFileConfigurationModule.TempFileFolerParameter, @".\test2\abc\")
+ .Build();
+
+ var dataSet = TangFactory.GetTang()
+ .NewInjector(c1)
+ .GetInstance<IPartitionedInputDataSet>();
+
+ int count = 0;
+ foreach (var partitionDescriptor in dataSet)
+ {
+ var partition =
+ TangFactory.GetTang()
+ .NewInjector(partitionDescriptor.GetPartitionConfiguration(), c2)
+ .GetInstance<IInputPartition<IEnumerable<Row>>>();
+ using (partition as IDisposable)
+ {
+ IEnumerable<Row> e = partition.GetPartitionHandle();
+
+ foreach (var row in e)
+ {
+ Logger.Log(Level.Info, string.Format(CultureInfo.CurrentCulture, "Data read {0}: ", row.GetValue()));
+ count++;
+ }
+ }
+ }
+ Assert.AreEqual(count, 5);
+ }
+
private void MakeLocalTestFile(string filePath, byte[] bytes)
{
if (File.Exists(filePath))
http://git-wip-us.apache.org/repos/asf/reef/blob/67894d51/lang/cs/Org.Apache.REEF.IO.Tests/TestTempFolderCreator.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.IO.Tests/TestTempFolderCreator.cs b/lang/cs/Org.Apache.REEF.IO.Tests/TestTempFolderCreator.cs
new file mode 100644
index 0000000..4f1ae22
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.IO.Tests/TestTempFolderCreator.cs
@@ -0,0 +1,78 @@
+// 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.IO;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Org.Apache.REEF.IO.TempFileCreation;
+using Org.Apache.REEF.Tang.Implementations.Tang;
+
+namespace Org.Apache.REEF.IO.Tests
+{
+ [TestClass]
+ public class TestTempFolderCreator
+ {
+ /// <summary>
+ /// This is to test default TempFileFolder and ITempFileCreator
+ /// </summary>
+ [TestMethod]
+ public void TestDefaultTempFolder()
+ {
+ var b = TempFileConfigurationModule.ConfigurationModule.Build();
+ var i = TangFactory.GetTang().NewInjector(b);
+ var tempFileCreator = i.GetInstance<ITempFileCreator>();
+ var f1 = tempFileCreator.GetTempFileName();
+ var f2 = (string)i.GetNamedInstance(typeof(TempFileFolder));
+ var f = Path.GetFullPath(f2);
+ Assert.IsTrue(f1.StartsWith(f));
+ }
+
+ /// <summary>
+ /// This is to test setting a value to TempFileFolder
+ /// </summary>
+ [TestMethod]
+ public void TestTempFileFolerParameter()
+ {
+ var b = TempFileConfigurationModule.ConfigurationModule
+ .Set(TempFileConfigurationModule.TempFileFolerParameter, @".\test1\abc\")
+ .Build();
+ var i = TangFactory.GetTang().NewInjector(b);
+ var tempFileCreator = i.GetInstance<ITempFileCreator>();
+ var f1 = tempFileCreator.GetTempFileName();
+ var f2 = (string)i.GetNamedInstance(typeof(TempFileFolder));
+ var f = Path.GetFullPath(f2);
+ Assert.IsTrue(f1.StartsWith(f));
+ }
+
+ /// <summary>
+ /// This is to test CreateTempDirectory() by providing a subfolder
+ /// </summary>
+ [TestMethod]
+ public void TestCreateTempFileFoler()
+ {
+ var b = TempFileConfigurationModule.ConfigurationModule
+ .Set(TempFileConfigurationModule.TempFileFolerParameter, @"./test1/abc/")
+ .Build();
+ var i = TangFactory.GetTang().NewInjector(b);
+ var tempFileCreator = i.GetInstance<ITempFileCreator>();
+ var f1 = tempFileCreator.CreateTempDirectory("ddd\\fff");
+ var f3 = tempFileCreator.CreateTempDirectory("ddd\\fff", "bbb");
+ var f2 = Path.GetFullPath(@"./test1/abc/" + "ddd\\fff");
+ Assert.IsTrue(f1.StartsWith(f2));
+ Assert.IsTrue(f3.EndsWith("bbb"));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/reef/blob/67894d51/lang/cs/Org.Apache.REEF.IO/Org.Apache.REEF.IO.csproj
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.IO/Org.Apache.REEF.IO.csproj b/lang/cs/Org.Apache.REEF.IO/Org.Apache.REEF.IO.csproj
index a67086c..f33d656 100644
--- a/lang/cs/Org.Apache.REEF.IO/Org.Apache.REEF.IO.csproj
+++ b/lang/cs/Org.Apache.REEF.IO/Org.Apache.REEF.IO.csproj
@@ -117,6 +117,11 @@ under the License.
<Compile Include="PartitionedData\Random\RandomInputPartition.cs" />
<Compile Include="PartitionedData\Random\RandomInputPartitionDescriptor.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="TempFileCreation\ITempFileCreator.cs" />
+ <Compile Include="TempFileCreation\TempFileFolder.cs" />
+ <Compile Include="TempFileCreation\TempFileConfigurationModule.cs" />
+ <Compile Include="TempFileCreation\TempFileConfigurationProvider.cs" />
+ <Compile Include="TempFileCreation\TempFileCreator.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Org.Apache.REEF.IO.nuspec" />
@@ -141,4 +146,5 @@ under the License.
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
-</Project>
+ <ItemGroup />
+</Project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/reef/blob/67894d51/lang/cs/Org.Apache.REEF.IO/PartitionedData/FileSystem/FileSystemInputPartition.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.IO/PartitionedData/FileSystem/FileSystemInputPartition.cs b/lang/cs/Org.Apache.REEF.IO/PartitionedData/FileSystem/FileSystemInputPartition.cs
index 76cb128..1edf11f 100644
--- a/lang/cs/Org.Apache.REEF.IO/PartitionedData/FileSystem/FileSystemInputPartition.cs
+++ b/lang/cs/Org.Apache.REEF.IO/PartitionedData/FileSystem/FileSystemInputPartition.cs
@@ -24,6 +24,7 @@ using System.IO;
using Org.Apache.REEF.IO.FileSystem;
using Org.Apache.REEF.IO.PartitionedData.FileSystem.Parameters;
using Org.Apache.REEF.IO.PartitionedData.Random.Parameters;
+using Org.Apache.REEF.IO.TempFileCreation;
using Org.Apache.REEF.Tang.Annotations;
using Org.Apache.REEF.Utilities.Diagnostics;
using Org.Apache.REEF.Utilities.Logging;
@@ -41,17 +42,20 @@ namespace Org.Apache.REEF.IO.PartitionedData.FileSystem
private bool _isInitialized;
private readonly object _lock = new object();
private string _localFileFolder;
+ private readonly ITempFileCreator _tempFileCreator;
[Inject]
private FileSystemInputPartition([Parameter(typeof(PartitionId))] string id,
[Parameter(typeof(FilePathsInInputPartition))] ISet<string> filePaths,
IFileSystem fileSystem,
+ ITempFileCreator tempFileCreator,
IFileDeSerializer<T> fileSerializer)
{
_id = id;
_fileSystem = fileSystem;
_fileSerializer = fileSerializer;
_filePaths = filePaths;
+ _tempFileCreator = tempFileCreator;
_isInitialized = false;
}
@@ -89,8 +93,8 @@ namespace Org.Apache.REEF.IO.PartitionedData.FileSystem
private void CopyFromRemote()
{
- _localFileFolder = Path.GetTempPath() + "-partition-" + Guid.NewGuid().ToString("N").Substring(0, 8);
- Directory.CreateDirectory(_localFileFolder);
+ _localFileFolder = _tempFileCreator.CreateTempDirectory("-partition-");
+ Logger.Log(Level.Info, string.Format(CultureInfo.CurrentCulture, "Local file temp folder: {0}", _localFileFolder));
foreach (var sourceFilePath in _filePaths)
{
@@ -103,7 +107,7 @@ namespace Org.Apache.REEF.IO.PartitionedData.FileSystem
}
var localFilePath = _localFileFolder + "\\" + Guid.NewGuid().ToString("N").Substring(0, 8);
- Logger.Log(Level.Info, string.Format(CultureInfo.CurrentCulture, "localFilePath {0}: ", localFilePath));
+ Logger.Log(Level.Info, string.Format(CultureInfo.CurrentCulture, "LocalFilePath {0}: ", localFilePath));
if (File.Exists(localFilePath))
{
File.Delete(localFilePath);
http://git-wip-us.apache.org/repos/asf/reef/blob/67894d51/lang/cs/Org.Apache.REEF.IO/TempFileCreation/ITempFileCreator.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.IO/TempFileCreation/ITempFileCreator.cs b/lang/cs/Org.Apache.REEF.IO/TempFileCreation/ITempFileCreator.cs
new file mode 100644
index 0000000..f0b348c
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.IO/TempFileCreation/ITempFileCreator.cs
@@ -0,0 +1,46 @@
+/**
+ * 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 Org.Apache.REEF.Tang.Annotations;
+
+namespace Org.Apache.REEF.IO.TempFileCreation
+{
+ /// <summary>
+ /// Provide interface to wrap temp file folder and temp file folder creation
+ /// </summary>
+ [DefaultImplementation(typeof(TempFileCreator))]
+ public interface ITempFileCreator
+ {
+ /// <summary>
+ /// Return the full path of a temp file name
+ /// </summary>
+ /// <param name="prefix"></param>
+ /// <param name="suffix"></param>
+ /// <returns></returns>
+ string GetTempFileName(string prefix = "", string suffix = "");
+
+ /// <summary>
+ /// Create a temp folder with given prefix and suffix as part of the name
+ /// </summary>
+ /// <param name="prefix"></param>
+ /// <param name="suffix"></param>
+ /// <returns></returns>
+ string CreateTempDirectory(string prefix = "", string suffix = "");
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/reef/blob/67894d51/lang/cs/Org.Apache.REEF.IO/TempFileCreation/TempFileConfigurationModule.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.IO/TempFileCreation/TempFileConfigurationModule.cs b/lang/cs/Org.Apache.REEF.IO/TempFileCreation/TempFileConfigurationModule.cs
new file mode 100644
index 0000000..b915ab5
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.IO/TempFileCreation/TempFileConfigurationModule.cs
@@ -0,0 +1,47 @@
+/**
+ * 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 Org.Apache.REEF.Common.Client.Parameters;
+using Org.Apache.REEF.Tang.Formats;
+using Org.Apache.REEF.Tang.Interface;
+using Org.Apache.REEF.Tang.Util;
+
+namespace Org.Apache.REEF.IO.TempFileCreation
+{
+ /// <summary>
+ /// Configuration Module for TempFileCreator.
+ /// </summary>
+ public sealed class TempFileConfigurationModule : ConfigurationModuleBuilder
+ {
+ /// <summary>
+ /// Temp file folder optional parameter. The default is @"./reef/tmp/" set in TempFileFolder class.
+ /// </summary>
+ public static readonly OptionalParameter<string> TempFileFolerParameter = new OptionalParameter<string>();
+
+ /// <summary>
+ /// It binds TempFileConfigurationProvider to DriverConfigurationProviders so that the configuration is set for
+ /// Driver configuration automatically. TempFileFolerParameter is set as an optional parameter for TempFileFolder.
+ /// </summary>
+ public static readonly ConfigurationModule ConfigurationModule = new TempFileConfigurationModule()
+ .BindSetEntry<DriverConfigurationProviders, TempFileConfigurationProvider, IConfigurationProvider>(
+ GenericType<DriverConfigurationProviders>.Class, GenericType<TempFileConfigurationProvider>.Class)
+ .BindNamedParameter(GenericType<TempFileFolder>.Class, TempFileFolerParameter)
+ .Build();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/reef/blob/67894d51/lang/cs/Org.Apache.REEF.IO/TempFileCreation/TempFileConfigurationProvider.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.IO/TempFileCreation/TempFileConfigurationProvider.cs b/lang/cs/Org.Apache.REEF.IO/TempFileCreation/TempFileConfigurationProvider.cs
new file mode 100644
index 0000000..e8222ea
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.IO/TempFileCreation/TempFileConfigurationProvider.cs
@@ -0,0 +1,58 @@
+/*
+ * 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 Org.Apache.REEF.Common.Evaluator.Parameters;
+using Org.Apache.REEF.Tang.Annotations;
+using Org.Apache.REEF.Tang.Implementations.Tang;
+using Org.Apache.REEF.Tang.Interface;
+using Org.Apache.REEF.Tang.Util;
+
+namespace Org.Apache.REEF.IO.TempFileCreation
+{
+ /// <summary>
+ /// A configuration provider for tem file
+ /// </summary>
+ internal sealed class TempFileConfigurationProvider : IConfigurationProvider
+ {
+ private readonly IConfiguration _configuration;
+
+ /// <summary>
+ /// Create configuration for for temp file
+ /// </summary>
+ /// <param name="tempFileFolder"></param>
+ [Inject]
+ private TempFileConfigurationProvider([Parameter(typeof(TempFileFolder))] string tempFileFolder)
+ {
+ _configuration = TangFactory.GetTang().NewConfigurationBuilder()
+ .BindImplementation(GenericType<ITempFileCreator>.Class, GenericType<TempFileCreator>.Class)
+ .BindStringNamedParam<TempFileFolder>(tempFileFolder)
+ .BindSetEntry<EvaluatorConfigurationProviders, TempFileConfigurationProvider, IConfigurationProvider>()
+ .Build();
+ }
+
+ /// <summary>
+ /// Returns temp file configuration
+ /// </summary>
+ /// <returns></returns>
+ IConfiguration IConfigurationProvider.GetConfiguration()
+ {
+ return _configuration;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/reef/blob/67894d51/lang/cs/Org.Apache.REEF.IO/TempFileCreation/TempFileCreator.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.IO/TempFileCreation/TempFileCreator.cs b/lang/cs/Org.Apache.REEF.IO/TempFileCreation/TempFileCreator.cs
new file mode 100644
index 0000000..c68d3e7
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.IO/TempFileCreation/TempFileCreator.cs
@@ -0,0 +1,84 @@
+/**
+ * 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.Globalization;
+using System.IO;
+using Org.Apache.REEF.Tang.Annotations;
+using Org.Apache.REEF.Utilities.Logging;
+
+namespace Org.Apache.REEF.IO.TempFileCreation
+{
+ /// <summary>
+ /// This class that wraps yemp file folder and provides an implementation of temp file folder creation
+ /// </summary>
+ internal sealed class TempFileCreator : ITempFileCreator
+ {
+ private static readonly Logger Logger = Logger.GetLogger(typeof(TempFileCreator));
+
+ private readonly string _tempFileFolder;
+
+ /// <summary>
+ /// Create a file folder for given tempFileFolder name
+ /// </summary>
+ /// <param name="tempFileFolder"></param>
+ [Inject]
+ private TempFileCreator(
+ [Parameter(typeof(TempFileFolder))] string tempFileFolder)
+ {
+ _tempFileFolder = tempFileFolder;
+ if (!Directory.Exists(_tempFileFolder))
+ {
+ Directory.CreateDirectory(Path.GetFullPath(tempFileFolder));
+ }
+ Logger.Log(Level.Verbose, string.Format(CultureInfo.CurrentCulture, "Temp directory: {0} is created", Path.GetFullPath(tempFileFolder)));
+ }
+
+ /// <summary>
+ /// Return a full path of a temp file name with a radom generated file name wraped with prefix and suffix
+ /// and the temp folder as the file folder
+ /// </summary>
+ /// <param name="prefix"></param>
+ /// <param name="suffix"></param>
+ /// <returns></returns>
+ public string GetTempFileName(string prefix, string suffix)
+ {
+ return Path.GetFullPath(Path.Combine(_tempFileFolder, prefix + Guid.NewGuid().ToString("N").Substring(0, 8) + suffix));
+ }
+
+ /// <summary>
+ /// Create a unique subfolder under the _tempFileFolder with given prefix and suffix
+ /// </summary>
+ /// <param name="prefix"></param>
+ /// <param name="suffix"></param>
+ /// <returns></returns>
+ public string CreateTempDirectory(string prefix, string suffix)
+ {
+ string fullPathOfSubFolder = GetTempFileName(prefix, suffix);
+ if (!Directory.Exists(fullPathOfSubFolder))
+ {
+ Directory.CreateDirectory(fullPathOfSubFolder);
+ }
+
+ Logger.Log(Level.Verbose, string.Format(CultureInfo.CurrentCulture, "Temp directory: {0} is created", fullPathOfSubFolder));
+
+ return fullPathOfSubFolder;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/reef/blob/67894d51/lang/cs/Org.Apache.REEF.IO/TempFileCreation/TempFileFolder.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.IO/TempFileCreation/TempFileFolder.cs b/lang/cs/Org.Apache.REEF.IO/TempFileCreation/TempFileFolder.cs
new file mode 100644
index 0000000..ace5f0c
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.IO/TempFileCreation/TempFileFolder.cs
@@ -0,0 +1,31 @@
+/**
+ * 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 Org.Apache.REEF.Tang.Annotations;
+
+namespace Org.Apache.REEF.IO.TempFileCreation
+{
+ /// <summary>
+ /// Folder for local temp file
+ /// </summary>
+ [NamedParameter("TempFileFolder", "TempFileFolder", @"./reef/tmp/")]
+ public sealed class TempFileFolder : Name<string>
+ {
+ }
+}
\ No newline at end of file