http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/EvaluatorHeartBeatSanityChecker.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/EvaluatorHeartBeatSanityChecker.cs b/lang/cs/Org.Apache.REEF.Common/EvaluatorHeartBeatSanityChecker.cs new file mode 100644 index 0000000..845e50c --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/EvaluatorHeartBeatSanityChecker.cs @@ -0,0 +1,55 @@ +/** + * 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.Utilities.Logging; +using System; +using System.Collections.Generic; +using System.Globalization; + +namespace Org.Apache.REEF.Common +{ + public class EvaluatorHeartBeatSanityChecker + { + private static readonly Logger LOGGER = Logger.GetLogger(typeof(EvaluatorHeartBeatSanityChecker)); + + Dictionary<string, long> _timeStamps = new Dictionary<string, long>(); + + public void check(string id, long timeStamp) + { + lock (this) + { + if (_timeStamps.ContainsKey(id)) + { + long oldTimeStamp = _timeStamps[id]; + LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "TIMESTAMP CHECKER: id [{0}], old timestamp [{1}], new timestamp [{2}]", id, oldTimeStamp, timeStamp)); + if (oldTimeStamp > timeStamp) + { + string msg = string.Format( + CultureInfo.InvariantCulture, + "Received an old heartbeat with timestamp [{0}] while timestamp [{1}] was received earlier", + oldTimeStamp, + timeStamp); + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new InvalidOperationException(msg), LOGGER); + } + } + _timeStamps.Add(id, timeStamp); + } + } + } +}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/FailedRuntime.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/FailedRuntime.cs b/lang/cs/Org.Apache.REEF.Common/FailedRuntime.cs new file mode 100644 index 0000000..078feb8 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/FailedRuntime.cs @@ -0,0 +1,49 @@ +/** + * 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.Api; +using Org.Apache.REEF.Common.ProtoBuf.ReefServiceProto; +using Org.Apache.REEF.Utilities; +using System; + +namespace Org.Apache.REEF.Common +{ + public class FailedRuntime : AbstractFailure + { + public FailedRuntime(RuntimeErrorProto error) + : base(error.identifier, error.message, null, GetException(error), error.exception) + { + } + + /// <summary> + /// Get the exception from error + /// </summary> + /// <param name="error"></param> + /// <returns>excetpiont from error</returns> + private static Exception GetException(RuntimeErrorProto error) + { + byte[] data = error.exception; + if (data != null) + { + return new InvalidOperationException(ByteUtilities.ByteArrarysToString(error.exception)); + } + return null; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/IContextAndTaskSubmittable.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/IContextAndTaskSubmittable.cs b/lang/cs/Org.Apache.REEF.Common/IContextAndTaskSubmittable.cs new file mode 100644 index 0000000..19d684b --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/IContextAndTaskSubmittable.cs @@ -0,0 +1,55 @@ +/** + * 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.Interface; + +namespace Org.Apache.REEF.Common +{ + /// <summary> + /// Base interface for classes that support the simultaneous submission of both Context and Task configurations. + /// </summary> + public interface IContextAndTaskSubmittable + { + /// <summary> + /// Submit a Context and an Task. + /// The semantics of this call are the same as first submitting the context and then, on the fired ActiveContext event + /// to submit the Task. The performance of this will be better, though as it potentially saves some roundtrips on + /// the network. + /// REEF will not fire an ActiveContext as a result of this. Instead, it will fire a TaskRunning event. + /// </summary> + /// <param name="contextConfiguration"> the Configuration of the EvaluatorContext. See ContextConfiguration for details.</param> + /// <param name="taskConfiguration">the Configuration of the Task. See TaskConfiguration for details.</param> + void SubmitContextAndTask(IConfiguration contextConfiguration, IConfiguration taskConfiguration); + + /// <summary> + /// Submit a Context with Services and an Task. + /// The semantics of this call are the same as first submitting the context and services and then, on the fired + /// ActiveContext event to submit the Task. The performance of this will be better, though as it potentially saves + /// some roundtrips on the network. + /// REEF will not fire an ActiveContext as a result of this. Instead, it will fire a TaskRunning event. + /// </summary> + /// <param name="contextConfiguration"></param> + /// <param name="serviceConfiguration"></param> + /// <param name="taskConfiguration"></param> + void SubmitContextAndServiceAndTask( + IConfiguration contextConfiguration, + IConfiguration serviceConfiguration, + IConfiguration taskConfiguration); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/IContextSubmittable.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/IContextSubmittable.cs b/lang/cs/Org.Apache.REEF.Common/IContextSubmittable.cs new file mode 100644 index 0000000..469df06 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/IContextSubmittable.cs @@ -0,0 +1,42 @@ +/** + * 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.Interface; + +namespace Org.Apache.REEF.Common +{ + /// <summary> + /// Base interface for classes that support Context submission. + /// </summary> + public interface IContextSubmittable + { + /// <summary> + /// Submit a Context. + /// </summary> + /// <param name="contextConfiguration">the Configuration of the EvaluatorContext. See ContextConfiguration for details.</param> + void SubmitContext(IConfiguration contextConfiguration); + + /// <summary> + /// Submit a Context and a Service Configuration. + /// </summary> + /// <param name="contextConfiguration">the Configuration of the EvaluatorContext. See ContextConfiguration for details.</param> + /// <param name="serviceConfiguration">the Configuration for the Services. See ServiceConfiguration for details.</param> + void SubmitContextAndService(IConfiguration contextConfiguration, IConfiguration serviceConfiguration); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/IJobMessageObserver.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/IJobMessageObserver.cs b/lang/cs/Org.Apache.REEF.Common/IJobMessageObserver.cs new file mode 100644 index 0000000..0de5039 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/IJobMessageObserver.cs @@ -0,0 +1,30 @@ +/** + * 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; + +namespace Org.Apache.REEF.Common.Client +{ + /// <summary> + /// The driver uses this interface to communicate with the job client. + /// </summary> + public interface IJobMessageObserver : IObserver<byte[]> + { + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/ITaskSubmittable.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/ITaskSubmittable.cs b/lang/cs/Org.Apache.REEF.Common/ITaskSubmittable.cs new file mode 100644 index 0000000..be8b60f --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/ITaskSubmittable.cs @@ -0,0 +1,35 @@ +/** + * 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.Interface; + +namespace Org.Apache.REEF.Common +{ + /// <summary> + /// Base interface for classes that support Task submission. + /// </summary> + public interface ITaskSubmittable + { + /// <summary> + /// Submits an Task (encoded in the Configuration) for execution. + /// </summary> + /// <param name="taskConf">the Configuration. See TaskConfiguration for details</param> + void SubmitTask(IConfiguration taskConf); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/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 new file mode 100644 index 0000000..d707d48 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/Org.Apache.REEF.Common.csproj @@ -0,0 +1,233 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +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. +--> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{545A0582-4105-44CE-B99C-B1379514A630}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Org.Apache.REEF.Common</RootNamespace> + <AssemblyName>Org.Apache.REEF.Common</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <RestorePackages>true</RestorePackages> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\..</SolutionDir> + </PropertyGroup> + <Import Project="$(SolutionDir)\Source\build.props" /> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>$(BinDir)\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>$(BinDir)\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>$(BinDir)\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>$(BinDir)\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="Microsoft.Hadoop.Avro"> + <HintPath>$(PackagesDir)\Microsoft.Hadoop.Avro.1.4.0.0\lib\net40\Microsoft.Hadoop.Avro.dll</HintPath> + </Reference> + <Reference Include="Newtonsoft.Json"> + <HintPath>$(PackagesDir)\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath> + </Reference> + <Reference Include="protobuf-net"> + <HintPath>$(PackagesDir)\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll</HintPath> + </Reference> + <Reference Include="System.Reactive.Core"> + <HintPath>$(PackagesDir)\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll</HintPath> + </Reference> + <Reference Include="System.Reactive.Interfaces"> + <HintPath>$(PackagesDir)\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll</HintPath> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Runtime.Serialization" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="api\AbstractFailure.cs" /> + <Compile Include="api\IAbstractFailure.cs" /> + <Compile Include="api\IFailure.cs" /> + <Compile Include="api\IResourceLaunchHandler.cs" /> + <Compile Include="api\IResourceReleaseHandler.cs" /> + <Compile Include="api\IResourceRequestHandler.cs" /> + <Compile Include="avro\AvroDriverInfo.cs" /> + <Compile Include="avro\AvroHttpRequest.cs" /> + <Compile Include="avro\AvroHttpSerializer.cs" /> + <Compile Include="avro\AvroJsonSerializer.cs" /> + <Compile Include="avro\AvroReefServiceInfo.cs" /> + <Compile Include="catalog\capabilities\CPU.cs" /> + <Compile Include="catalog\capabilities\ICapability.cs" /> + <Compile Include="catalog\capabilities\RAM.cs" /> + <Compile Include="catalog\INodeDescriptor.cs" /> + <Compile Include="catalog\IRackDescriptor.cs" /> + <Compile Include="catalog\IResourceCatalog.cs" /> + <Compile Include="catalog\NodeDescriptorImpl.cs" /> + <Compile Include="catalog\RackDescriptorImpl.cs" /> + <Compile Include="catalog\ResourceCatalogImpl.cs" /> + <Compile Include="ClientJobStatusHandler.cs" /> + <Compile Include="Constants.cs" /> + <Compile Include="context\ContextMessage.cs" /> + <Compile Include="context\IContextMessage.cs" /> + <Compile Include="context\IContextMessageHandler.cs" /> + <Compile Include="context\IContextMessageSource.cs" /> + <Compile Include="EvaluatorHeartBeatSanityChecker.cs" /> + <Compile Include="evaluator\DefaultLocalHttpDriverConnection.cs" /> + <Compile Include="evaluator\DefaultYarnClusterHttpDriverConnection.cs" /> + <Compile Include="evaluator\DefaultYarnOneBoxHttpDriverConnection.cs" /> + <Compile Include="evaluator\DriverInformation.cs" /> + <Compile Include="evaluator\EvaluatorOperationState.cs" /> + <Compile Include="evaluator\EvaluatorRuntimeState.cs" /> + <Compile Include="evaluator\EvaluatorType.cs" /> + <Compile Include="evaluator\IDriverConnection.cs" /> + <Compile Include="events\IContextStart.cs" /> + <Compile Include="events\IContextStop.cs" /> + <Compile Include="exceptions\EvaluatorException.cs" /> + <Compile Include="exceptions\JobException.cs" /> + <Compile Include="FailedRuntime.cs" /> + <Compile Include="IContextAndTaskSubmittable.cs" /> + <Compile Include="IContextSubmittable.cs" /> + <Compile Include="IJobMessageObserver.cs" /> + <Compile Include="io\INameClient.cs" /> + <Compile Include="io\NameAssignment.cs" /> + <Compile Include="io\NamingConfiguration.cs" /> + <Compile Include="io\NamingConfigurationOptions.cs" /> + <Compile Include="ITaskSubmittable.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="protobuf\cs\ClientRuntime.pb.cs" /> + <Compile Include="protobuf\cs\codec\EvaluatorHeartbeatProtoCodec.cs" /> + <Compile Include="protobuf\cs\codec\REEFMessageCodec.cs" /> + <Compile Include="protobuf\cs\DriverRuntime.pb.cs" /> + <Compile Include="protobuf\cs\EvaluatorRunTime.pb.cs" /> + <Compile Include="protobuf\cs\ReefProtocol.pb.cs" /> + <Compile Include="protobuf\cs\ReefService.pb.cs" /> + <Compile Include="protobuf\cs\Serializer.cs" /> + <Compile Include="runtime\evaluator\Constants.cs" /> + <Compile Include="runtime\evaluator\context\ContextClientCodeException.cs" /> + <Compile Include="runtime\evaluator\context\ContextConfiguration.cs" /> + <Compile Include="runtime\evaluator\context\ContextLifeCycle.cs" /> + <Compile Include="runtime\evaluator\context\ContextManager.cs" /> + <Compile Include="runtime\evaluator\context\ContextRuntime.cs" /> + <Compile Include="runtime\evaluator\context\ContextStartImpl.cs" /> + <Compile Include="runtime\evaluator\context\ContextStopImpl.cs" /> + <Compile Include="runtime\evaluator\context\RootContextLauncher.cs" /> + <Compile Include="runtime\evaluator\EvaluatorRuntime.cs" /> + <Compile Include="runtime\evaluator\EvaluatorSettings.cs" /> + <Compile Include="runtime\evaluator\HeartBeatManager.cs" /> + <Compile Include="runtime\evaluator\ReefMessageProtoObserver.cs" /> + <Compile Include="runtime\evaluator\task\CloseEventImpl.cs" /> + <Compile Include="runtime\evaluator\task\DriverMessageImpl.cs" /> + <Compile Include="runtime\evaluator\task\SuspendEventImpl.cs" /> + <Compile Include="runtime\evaluator\task\TaskClientCodeException.cs" /> + <Compile Include="runtime\evaluator\task\TaskLifeCycle.cs" /> + <Compile Include="runtime\evaluator\task\TaskRuntime.cs" /> + <Compile Include="runtime\evaluator\task\TaskStartImpl.cs" /> + <Compile Include="runtime\evaluator\task\TaskState.cs" /> + <Compile Include="runtime\evaluator\task\TaskStatus.cs" /> + <Compile Include="runtime\evaluator\task\TaskStopImpl.cs" /> + <Compile Include="runtime\evaluator\utils\EvaluatorConfigurations.cs" /> + <Compile Include="runtime\evaluator\utils\RemoteManager.cs" /> + <Compile Include="runtime\MachineStatus.cs" /> + <Compile Include="services\IService.cs" /> + <Compile Include="services\ServiceConfiguration.cs" /> + <Compile Include="services\ServicesConfigurationOptions.cs" /> + <Compile Include="tasks\defaults\DefaultDriverMessageHandler.cs" /> + <Compile Include="tasks\defaults\DefaultTaskMessageSource.cs" /> + <Compile Include="tasks\events\ICloseEvent.cs" /> + <Compile Include="tasks\events\IDriverMessage.cs" /> + <Compile Include="tasks\events\ISuspendEvent.cs" /> + <Compile Include="tasks\events\ITaskStart.cs" /> + <Compile Include="tasks\events\ITaskStop.cs" /> + <Compile Include="tasks\IDriverMessageHandler.cs" /> + <Compile Include="tasks\IRunningTask.cs" /> + <Compile Include="tasks\ITask.cs" /> + <Compile Include="tasks\ITaskMessageSource.cs" /> + <Compile Include="tasks\TaskConfiguration.cs" /> + <Compile Include="tasks\TaskConfigurationOptions.cs" /> + <Compile Include="tasks\TaskMessage.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + <None Include="protobuf\proto\client_runtime.proto" /> + <None Include="protobuf\proto\driver_runtime.proto" /> + <None Include="protobuf\proto\evaluator_runtime.proto" /> + <None Include="protobuf\proto\reef_protocol.proto" /> + <None Include="protobuf\proto\reef_service_protos.proto" /> + </ItemGroup> + <ItemGroup> + <Folder Include="protobuf\tools\" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Tang\Org.Apache.REEF.Tang.csproj"> + <Project>{97dbb573-3994-417a-9f69-ffa25f00d2a6}</Project> + <Name>Org.Apache.REEF.Tang</Name> + </ProjectReference> + <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Utilities\Org.Apache.REEF.Utilities.csproj"> + <Project>{79e7f89a-1dfb-45e1-8d43-d71a954aeb98}</Project> + <Name>Org.Apache.REEF.Utilities</Name> + </ProjectReference> + <ProjectReference Include="..\Org.Apache.REEF.Wake\Org.Apache.REEF.Wake.csproj"> + <Project>{cdfb3464-4041-42b1-9271-83af24cd5008}</Project> + <Name>Org.Apache.REEF.Wake</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/Properties/AssemblyInfo.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Properties/AssemblyInfo.cs b/lang/cs/Org.Apache.REEF.Common/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2e74594 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +/** + * 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.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Org.Apache.REEF.Common")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Org.Apache.REEF.Common")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a810ee4a-fe13-4536-9e9c-5275b16e0842")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/api/AbstractFailure.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/api/AbstractFailure.cs b/lang/cs/Org.Apache.REEF.Common/api/AbstractFailure.cs new file mode 100644 index 0000000..50fd6b7 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/api/AbstractFailure.cs @@ -0,0 +1,142 @@ +/** + * 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.Utilities; +using System; +using System.Globalization; +using Org.Apache.REEF.Utilities.Logging; + +namespace Org.Apache.REEF.Common.Api +{ + public abstract class AbstractFailure : IFailure + { + private static readonly Logger LOGGER = Logger.GetLogger(typeof(AbstractFailure)); + + public AbstractFailure() + { + } + + /// <summary> + /// Most detailed error message constructor that takes all parameters possible. + /// </summary> + /// <param name="id">Identifier of the entity that produced the error. Cannot be null.</param> + /// <param name="message">One-line error message. Cannot be null.</param> + /// <param name="description">Long error description. Can be null.</param> + /// <param name="cause">Exception that caused the error. Can be null.</param> + /// <param name="data">byte array that contains serialized version of the error. Can be null.</param> + public AbstractFailure(string id, string message, string description, Exception cause, byte[] data) + { + if (string.IsNullOrEmpty(id)) + { + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new ArgumentException("id"), LOGGER); + } + if (string.IsNullOrEmpty(message)) + { + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new ArgumentException("message"), LOGGER); + } + Id = id; + Message = message; + Description = Optional<string>.OfNullable(string.IsNullOrEmpty(description) ? GetStackTrace(cause) : description); + Cause = Optional<Exception>.OfNullable(cause); + Data = Optional<byte[]>.OfNullable(data); + } + + /// <summary> + /// Build error message given the entity ID and the short error message. + /// </summary> + /// <param name="id"></param> + /// <param name="message"></param> + public AbstractFailure(string id, string message) + : this(id, message, null, null, null) + { + } + + /// <summary> + /// Build error message given the failed entity ID and Exception. + /// Populates the message with the Exception.getMessage() result, and stores + /// the exception stack trace in the description. + /// </summary> + /// <param name="id"></param> + /// <param name="cause"></param> + public AbstractFailure(string id, Exception cause) + { + if (string.IsNullOrEmpty(id)) + { + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new ArgumentException("id"), LOGGER); + } + Id = id; + Message = cause.Message; + Description = Optional<string>.Of(GetStackTrace(cause)); + Cause = Optional<Exception>.Of(cause); + Data = Optional<byte[]>.Empty(); + } + + /// <summary> + /// Build error message given the entity ID plus short and long error message. + /// </summary> + /// <param name="id"></param> + /// <param name="message"></param> + /// <param name="description"></param> + public AbstractFailure(string id, string message, string description) + : this(id, message, description, null, null) + { + } + + /// <summary> + /// Identifier of the entity that produced the error. Cannot be null. + /// </summary> + public string Id { get; set; } + + public string Message { get; set; } + + public Optional<string> Description { get; set; } + + public Optional<string> Reason { get; set; } + + public Optional<Exception> Cause { get; set; } + + public Optional<byte[]> Data { get; set; } + + public Exception AsError() + { + return Cause.IsPresent() ? Cause.Value : new InvalidOperationException(ToString()); + } + + /// <summary> + /// Helper function: produce the string that contains the given exception's stack trace. Returns null if the argument is null. + /// </summary> + /// <param name="ex"></param> + public string GetStackTrace(Exception ex) + { + if (ex == null) + { + return null; + } + else + { + return ex.StackTrace; + } + } + + public override string ToString() + { + return string.Format(CultureInfo.InvariantCulture, "{0} with id={1} failed: {2}", GetType(), Id, Message); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/api/IAbstractFailure.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/api/IAbstractFailure.cs b/lang/cs/Org.Apache.REEF.Common/api/IAbstractFailure.cs new file mode 100644 index 0000000..fd94b62 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/api/IAbstractFailure.cs @@ -0,0 +1,25 @@ +/** + * 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. + */ + +namespace Org.Apache.REEF.Common.Api +{ + public interface IAbstractFailure : IFailure + { + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/api/IFailure.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/api/IFailure.cs b/lang/cs/Org.Apache.REEF.Common/api/IFailure.cs new file mode 100644 index 0000000..454bdf4 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/api/IFailure.cs @@ -0,0 +1,57 @@ +/** + * 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.Utilities; +using System; + +namespace Org.Apache.REEF.Common.Api +{ + /// <summary> + /// Common interface for all error messages in REEF. + /// Most of its functionality is generic and implemented in the AbstractFailure class. + /// </summary> + public interface IFailure : IIdentifiable + { + /// <summary> + /// One-line error message. Should never be null. + /// </summary> + string Message { get; set; } + + /// <summary> + /// Optional long error description. + /// </summary> + Optional<string> Description { get; set; } + + /// <summary> + /// Exception that caused the error, or null. + /// </summary> + Optional<string> Reason { get; set; } + + /// <summary> + /// Optional serialized version of the error message. + /// </summary> + Optional<byte[]> Data { get; set; } + + /// <summary> + /// Return the original Java Exception, or generate a new one if it does not exists. + /// ALWAYS returns an exception, never null + /// </summary> + Exception AsError(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/api/IResourceLaunchHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/api/IResourceLaunchHandler.cs b/lang/cs/Org.Apache.REEF.Common/api/IResourceLaunchHandler.cs new file mode 100644 index 0000000..3287407 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/api/IResourceLaunchHandler.cs @@ -0,0 +1,28 @@ +/** + * 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.ProtoBuf.DriverRuntimeProto; +using System; + +namespace Org.Apache.REEF.Common.Api +{ + public interface IResourceLaunchHandler : IObserver<ResourceLaunchProto> + { + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/api/IResourceReleaseHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/api/IResourceReleaseHandler.cs b/lang/cs/Org.Apache.REEF.Common/api/IResourceReleaseHandler.cs new file mode 100644 index 0000000..5d807ad --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/api/IResourceReleaseHandler.cs @@ -0,0 +1,28 @@ +/** + * 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.ProtoBuf.DriverRuntimeProto; +using System; + +namespace Org.Apache.REEF.Common.Api +{ + public interface IResourceReleaseHandler : IObserver<ResourceReleaseProto> + { + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/api/IResourceRequestHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/api/IResourceRequestHandler.cs b/lang/cs/Org.Apache.REEF.Common/api/IResourceRequestHandler.cs new file mode 100644 index 0000000..4932e5e --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/api/IResourceRequestHandler.cs @@ -0,0 +1,28 @@ +/** + * 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.ProtoBuf.DriverRuntimeProto; +using System; + +namespace Org.Apache.REEF.Common.Api +{ + public interface IResourceRequestHandler : IObserver<ResourceRequestProto> + { + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/avro/AvroDriverInfo.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/avro/AvroDriverInfo.cs b/lang/cs/Org.Apache.REEF.Common/avro/AvroDriverInfo.cs new file mode 100644 index 0000000..2f0ae95 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/avro/AvroDriverInfo.cs @@ -0,0 +1,65 @@ +//<auto-generated /> +namespace Org.Apache.REEF.Common.Avro +{ + using System.Collections.Generic; + using System.Runtime.Serialization; + + /// <summary> + /// Used to serialize and deserialize Avro record org.apache.reef.webserver.AvroDriverInfo. + /// </summary> + [DataContract(Namespace = "org.apache.reef.webserver")] + [KnownType(typeof(List<Org.Apache.REEF.Common.Avro.AvroReefServiceInfo>))] + public partial class AvroDriverInfo + { + private const string JsonSchema = @"{""type"":""record"",""name"":""org.apache.reef.webserver.AvroDriverInfo"",""fields"":[{""name"":""remoteId"",""type"":""string""},{""name"":""startTime"",""type"":""string""},{""name"":""services"",""type"":{""type"":""array"",""items"":{""type"":""record"",""name"":""org.apache.reef.webserver.AvroReefServiceInfo"",""fields"":[{""name"":""serviceName"",""type"":""string""},{""name"":""serviceInfo"",""type"":""string""}]}}}]}"; + + /// <summary> + /// Gets the schema. + /// </summary> + public static string Schema + { + get + { + return JsonSchema; + } + } + + /// <summary> + /// Gets or sets the remoteId field. + /// </summary> + [DataMember] + public string remoteId { get; set; } + + /// <summary> + /// Gets or sets the startTime field. + /// </summary> + [DataMember] + public string startTime { get; set; } + + /// <summary> + /// Gets or sets the services field. + /// </summary> + [DataMember] + public IList<Org.Apache.REEF.Common.Avro.AvroReefServiceInfo> services { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="AvroDriverInfo"/> class. + /// </summary> + public AvroDriverInfo() + { + } + + /// <summary> + /// Initializes a new instance of the <see cref="AvroDriverInfo"/> class. + /// </summary> + /// <param name="remoteId">The remoteId.</param> + /// <param name="startTime">The startTime.</param> + /// <param name="services">The services.</param> + public AvroDriverInfo(string remoteId, string startTime, IList<Org.Apache.REEF.Common.Avro.AvroReefServiceInfo> services) + { + this.remoteId = remoteId; + this.startTime = startTime; + this.services = services; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/avro/AvroHttpRequest.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/avro/AvroHttpRequest.cs b/lang/cs/Org.Apache.REEF.Common/avro/AvroHttpRequest.cs new file mode 100644 index 0000000..3767c2b --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/avro/AvroHttpRequest.cs @@ -0,0 +1,79 @@ +//<auto-generated /> +namespace Org.Apache.REEF.Common.Avro +{ + using System.Runtime.Serialization; + + /// <summary> + /// Used to serialize and deserialize Avro record org.apache.reef.webserver.AvroHttpRequest. + /// </summary> + [DataContract(Namespace = "org.apache.reef.webserver")] + public partial class AvroHttpRequest + { + private const string JsonSchema = @"{""type"":""record"",""name"":""org.apache.reef.webserver.AvroHttpRequest"",""fields"":[{""name"":""requestUrl"",""type"":""string""},{""name"":""pathInfo"",""type"":""string""},{""name"":""queryString"",""type"":""string""},{""name"":""httpMethod"",""type"":""string""},{""name"":""inputStream"",""type"":""bytes""}]}"; + + /// <summary> + /// Gets the schema. + /// </summary> + public static string Schema + { + get + { + return JsonSchema; + } + } + + /// <summary> + /// Gets or sets the requestUrl field. + /// </summary> + [DataMember] + public string RequestUrl { get; set; } + + /// <summary> + /// Gets or sets the pathInfo field. + /// </summary> + [DataMember] + public string PathInfo { get; set; } + + /// <summary> + /// Gets or sets the queryString field. + /// </summary> + [DataMember] + public string QueryString { get; set; } + + /// <summary> + /// Gets or sets the httpMethod field. + /// </summary> + [DataMember] + public string HttpMethod { get; set; } + + /// <summary> + /// Gets or sets the inputStream field. + /// </summary> + [DataMember] + public byte[] InputStream { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="AvroHttpRequest"/> class. + /// </summary> + public AvroHttpRequest() + { + } + + /// <summary> + /// Initializes a new instance of the <see cref="AvroHttpRequest"/> class. + /// </summary> + /// <param name="requestUrl">The requestUrl.</param> + /// <param name="pathInfo">The pathInfo.</param> + /// <param name="queryString">The queryString.</param> + /// <param name="httpMethod">The httpMethod.</param> + /// <param name="inputStream">The inputStream.</param> + public AvroHttpRequest(string requestUrl, string pathInfo, string queryString, string httpMethod, byte[] inputStream) + { + RequestUrl = requestUrl; + PathInfo = pathInfo; + QueryString = queryString; + HttpMethod = httpMethod; + InputStream = inputStream; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/avro/AvroHttpSerializer.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/avro/AvroHttpSerializer.cs b/lang/cs/Org.Apache.REEF.Common/avro/AvroHttpSerializer.cs new file mode 100644 index 0000000..2d1fb53 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/avro/AvroHttpSerializer.cs @@ -0,0 +1,36 @@ +/** + * 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 Microsoft.Hadoop.Avro; +using System.IO; + +namespace Org.Apache.REEF.Common.Avro +{ + public class AvroHttpSerializer + { + public static AvroHttpRequest FromBytes(byte[] serializedBytes) + { + var serializer = AvroSerializer.Create<AvroHttpRequest>(); + using (var stream = new MemoryStream(serializedBytes)) + { + return serializer.Deserialize(stream); + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/avro/AvroJsonSerializer.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/avro/AvroJsonSerializer.cs b/lang/cs/Org.Apache.REEF.Common/avro/AvroJsonSerializer.cs new file mode 100644 index 0000000..a3c0007 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/avro/AvroJsonSerializer.cs @@ -0,0 +1,52 @@ +/** + * 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.Utilities; + +using Newtonsoft.Json; + +namespace Org.Apache.REEF.Common.Avro +{ + /// <summary> + /// Wrapper class for serialize/deserialize Avro json. This avoids having to reference Avro dll in every project + /// </summary> + /// <typeparam name="T"> the deserialized type</typeparam> + public class AvroJsonSerializer<T> + { + public static T FromString(string str) + { + return JsonConvert.DeserializeObject<T>(str); + } + + public static string ToString(T obj) + { + return JsonConvert.SerializeObject(obj); + } + + public static T FromBytes(byte[] bytes) + { + return FromString(ByteUtilities.ByteArrarysToString(bytes)); + } + + public static byte[] ToBytes(T obj) + { + return ByteUtilities.StringToByteArrays(JsonConvert.SerializeObject(obj)); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/avro/AvroReefServiceInfo.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/avro/AvroReefServiceInfo.cs b/lang/cs/Org.Apache.REEF.Common/avro/AvroReefServiceInfo.cs new file mode 100644 index 0000000..9b65c62 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/avro/AvroReefServiceInfo.cs @@ -0,0 +1,55 @@ +//<auto-generated /> +namespace Org.Apache.REEF.Common.Avro +{ + using System.Runtime.Serialization; + + /// <summary> + /// Used to serialize and deserialize Avro record org.apache.reef.webserver.AvroReefServiceInfo. + /// </summary> + [DataContract(Namespace = "org.apache.reef.webserver")] + public partial class AvroReefServiceInfo + { + private const string JsonSchema = @"{""type"":""record"",""name"":""org.apache.reef.webserver.AvroReefServiceInfo"",""fields"":[{""name"":""serviceName"",""type"":""string""},{""name"":""serviceInfo"",""type"":""string""}]}"; + + /// <summary> + /// Gets the schema. + /// </summary> + public static string Schema + { + get + { + return JsonSchema; + } + } + + /// <summary> + /// Gets or sets the serviceName field. + /// </summary> + [DataMember] + public string serviceName { get; set; } + + /// <summary> + /// Gets or sets the serviceInfo field. + /// </summary> + [DataMember] + public string serviceInfo { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="AvroReefServiceInfo"/> class. + /// </summary> + public AvroReefServiceInfo() + { + } + + /// <summary> + /// Initializes a new instance of the <see cref="AvroReefServiceInfo"/> class. + /// </summary> + /// <param name="serviceName">The serviceName.</param> + /// <param name="serviceInfo">The serviceInfo.</param> + public AvroReefServiceInfo(string serviceName, string serviceInfo) + { + this.serviceName = serviceName; + this.serviceInfo = serviceInfo; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/catalog/INodeDescriptor.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/catalog/INodeDescriptor.cs b/lang/cs/Org.Apache.REEF.Common/catalog/INodeDescriptor.cs new file mode 100644 index 0000000..967995a --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/catalog/INodeDescriptor.cs @@ -0,0 +1,36 @@ +/** + * 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.Net; + +using Org.Apache.REEF.Common.Capabilities; + +namespace Org.Apache.REEF.Common.Catalog +{ + public interface INodeDescriptor + { + IPEndPoint InetSocketAddress { get; set; } + + string HostName { get; set; } + + CPU Cpu { get; set; } + + RAM Ram { get; set; } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/catalog/IRackDescriptor.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/catalog/IRackDescriptor.cs b/lang/cs/Org.Apache.REEF.Common/catalog/IRackDescriptor.cs new file mode 100644 index 0000000..5e6bb32 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/catalog/IRackDescriptor.cs @@ -0,0 +1,25 @@ +/** + * 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. + */ + +namespace Org.Apache.REEF.Common.Catalog +{ + public interface IRackDescriptor : IResourceCatalog + { + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/catalog/IResourceCatalog.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/catalog/IResourceCatalog.cs b/lang/cs/Org.Apache.REEF.Common/catalog/IResourceCatalog.cs new file mode 100644 index 0000000..c972f73 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/catalog/IResourceCatalog.cs @@ -0,0 +1,37 @@ +/** + * 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.Capabilities; +using System.Collections.Generic; + +namespace Org.Apache.REEF.Common.Catalog +{ + public interface IResourceCatalog + { + string Name { get; set; } + + ICollection<ICapability> Capabilities { get; set; } + + ICollection<INodeDescriptor> Nodes { get; set; } + + ICollection<IRackDescriptor> Racks { get; set; } + + INodeDescriptor GetNode(string nodeId); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/catalog/NodeDescriptorImpl.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/catalog/NodeDescriptorImpl.cs b/lang/cs/Org.Apache.REEF.Common/catalog/NodeDescriptorImpl.cs new file mode 100644 index 0000000..696248b --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/catalog/NodeDescriptorImpl.cs @@ -0,0 +1,116 @@ +/** + * 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.Capabilities; +using System.Collections.Generic; +using System.Net; + +namespace Org.Apache.REEF.Common.Catalog +{ + public class NodeDescriptorImpl : INodeDescriptor + { + private RackDescriptorImpl _rack; + + private string _id; + + private IPEndPoint _address; + + private RAM _ram; + + private IList<ICapability> _capabilities; + + public NodeDescriptorImpl() + { + } + + public NodeDescriptorImpl(string id, IPEndPoint addresss, RackDescriptorImpl rack, RAM ram) + { + _id = id; + _address = addresss; + _rack = rack; + _ram = ram; + _capabilities = new List<ICapability>(); + _rack.AddNodeDescriptor(this); + } + + public RackDescriptorImpl Rack + { + get + { + return _rack; + } + } + + public string Id + { + get + { + return _id; + } + } + + public string HostName { get; set; } + + public CPU Cpu + { + get + { + return new CPU(1); + } + + set + { + } + } + + public RAM Ram + { + get + { + return _ram; + } + + set + { + _ram = value; + } + } + + public IList<ICapability> Capabilities + { + get + { + return _capabilities; + } + } + + public IPEndPoint InetSocketAddress + { + get + { + return _address; + } + + set + { + _address = value; + } + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/catalog/RackDescriptorImpl.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/catalog/RackDescriptorImpl.cs b/lang/cs/Org.Apache.REEF.Common/catalog/RackDescriptorImpl.cs new file mode 100644 index 0000000..b6d89d8 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/catalog/RackDescriptorImpl.cs @@ -0,0 +1,75 @@ +/** + * 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.Capabilities; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Org.Apache.REEF.Common.Catalog +{ + public class RackDescriptorImpl : IRackDescriptor + { + public RackDescriptorImpl(string name) + { + Name = name; + Capabilities = new List<ICapability>(); + Nodes = new List<INodeDescriptor>(); + } + + public string Name { get; set; } + + public ICollection<ICapability> Capabilities { get; set; } + + public ICollection<INodeDescriptor> Nodes { get; set; } + + public ICollection<IRackDescriptor> Racks { get; set; } + + public INodeDescriptor GetNode(string nodeId) + { + throw new NotImplementedException(); + } + + public void AddNodeDescriptor(NodeDescriptorImpl node) + { + Nodes.Add(node); + } + + public override string ToString() + { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.Append("Rack " + Name); + foreach (INodeDescriptor nodeDescriptor in Nodes) + { + stringBuilder.Append(Environment.NewLine + nodeDescriptor); + } + return stringBuilder.ToString(); + } + + public override int GetHashCode() + { + return Name.GetHashCode(); + } + + public override bool Equals(object obj) + { + return base.Equals(obj); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/catalog/ResourceCatalogImpl.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/catalog/ResourceCatalogImpl.cs b/lang/cs/Org.Apache.REEF.Common/catalog/ResourceCatalogImpl.cs new file mode 100644 index 0000000..7d9e7ca --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/catalog/ResourceCatalogImpl.cs @@ -0,0 +1,95 @@ +/** + * 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.Capabilities; +using Org.Apache.REEF.Common.ProtoBuf.DriverRuntimeProto; +using Org.Apache.REEF.Utilities.Logging; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Net; +using System.Text; + +namespace Org.Apache.REEF.Common.Catalog +{ + public class ResourceCatalogImpl : IResourceCatalog + { + private static readonly Logger LOGGER = Logger.GetLogger(typeof(ResourceCatalogImpl)); + + private static string defaultRackName = "default-rack"; + + private Dictionary<string, RackDescriptorImpl> _racks = new Dictionary<string, RackDescriptorImpl>(); + + private Dictionary<string, NodeDescriptorImpl> _nodes = new Dictionary<string, NodeDescriptorImpl>(); + + public string Name { get; set; } + + public ICollection<ICapability> Capabilities { get; set; } + + public ICollection<INodeDescriptor> Nodes { get; set; } + + public ICollection<IRackDescriptor> Racks { get; set; } + + public INodeDescriptor GetNode(string nodeId) + { + return _nodes[nodeId]; + } + + public void Handle(NodeDescriptorProto node) + { + string rackName = node.rack_name == null ? node.rack_name : defaultRackName; + string message = string.Format( + CultureInfo.InvariantCulture, + "Catalog new node: id[{0}], rack[{1}], host[{2}], port[{3}], memory[{4}]", + node.identifier, + rackName, + node.host_name, + node.port, + node.memory_size); + LOGGER.Log(Level.Info, message); + if (!string.IsNullOrWhiteSpace(rackName) && !_racks.ContainsKey(rackName)) + { + RackDescriptorImpl newRack = new RackDescriptorImpl(rackName); + _racks.Add(rackName, newRack); + } + RackDescriptorImpl rack = _racks[rackName]; + IPAddress ipAddress = null; + IPAddress.TryParse(node.host_name, out ipAddress); + if (ipAddress == null) + { + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new ArgumentException("cannot parse host ipaddress: " + node.host_name), LOGGER); + } + IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, node.port); + RAM ram = new RAM(node.memory_size); + NodeDescriptorImpl nodeDescriptor = new NodeDescriptorImpl(node.identifier, ipEndPoint, rack, ram); + _nodes.Add(nodeDescriptor.Id, nodeDescriptor); + } + + public override string ToString() + { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.Append("=== Resource Catalog ==="); + foreach (IRackDescriptor rackDescriptor in Racks) + { + stringBuilder.Append(Environment.NewLine + rackDescriptor); + } + return stringBuilder.ToString(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/catalog/capabilities/CPU.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/catalog/capabilities/CPU.cs b/lang/cs/Org.Apache.REEF.Common/catalog/capabilities/CPU.cs new file mode 100644 index 0000000..599db2e --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/catalog/capabilities/CPU.cs @@ -0,0 +1,60 @@ +/** + * 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 Org.Apache.REEF.Common.Api; +using Org.Apache.REEF.Utilities.Logging; + +namespace Org.Apache.REEF.Common.Capabilities +{ + public class CPU : ICapability + { + private static readonly Logger LOGGER = Logger.GetLogger(typeof(CPU)); + + private int _cores; + + public CPU(int cores) + { + if (cores <= 0) + { + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new ArgumentException("cores cannot be non-positive"), LOGGER); + } + _cores = cores; + } + + public int Cores + { + get + { + return _cores; + } + } + + public override string ToString() + { + return string.Format(CultureInfo.InvariantCulture, "CPU Cores = [{0}]", Cores); + } + + public override int GetHashCode() + { + return Cores.GetHashCode(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/catalog/capabilities/ICapability.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/catalog/capabilities/ICapability.cs b/lang/cs/Org.Apache.REEF.Common/catalog/capabilities/ICapability.cs new file mode 100644 index 0000000..4c838f7 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/catalog/capabilities/ICapability.cs @@ -0,0 +1,25 @@ +/** + * 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. + */ + +namespace Org.Apache.REEF.Common.Capabilities +{ + public interface ICapability + { + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/catalog/capabilities/RAM.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/catalog/capabilities/RAM.cs b/lang/cs/Org.Apache.REEF.Common/catalog/capabilities/RAM.cs new file mode 100644 index 0000000..68f5a08 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/catalog/capabilities/RAM.cs @@ -0,0 +1,51 @@ +/** + * 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.Globalization; + +namespace Org.Apache.REEF.Common.Capabilities +{ + public class RAM : ICapability + { + private int _megaBytes; + + public RAM(int megaBytes) + { + _megaBytes = megaBytes; + } + + public int MegaBytes + { + get + { + return _megaBytes; + } + } + + public override string ToString() + { + return string.Format(CultureInfo.InvariantCulture, "RAM(in mega bytes) = [{0}]", MegaBytes); + } + + public override int GetHashCode() + { + return MegaBytes.GetHashCode(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/context/ContextMessage.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/context/ContextMessage.cs b/lang/cs/Org.Apache.REEF.Common/context/ContextMessage.cs new file mode 100644 index 0000000..7f9b226 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/context/ContextMessage.cs @@ -0,0 +1,66 @@ +/** + * 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 Org.Apache.REEF.Utilities.Logging; + +namespace Org.Apache.REEF.Common.Context +{ + public class ContextMessage + { + private static readonly Logger LOGGER = Logger.GetLogger(typeof(ContextMessage)); + private readonly string _messageSourcId; + private readonly byte[] _bytes; + + private ContextMessage(string messageSourceId, byte[] bytes) + { + _messageSourcId = messageSourceId; + _bytes = bytes; + } + + public string MessageSourceId + { + get { return _messageSourcId; } + } + + public byte[] Bytes + { + get { return _bytes; } + } + + /// <summary> + /// construt a new new ContextMessage with the given content. + /// </summary> + /// <param name="messageSourceId">The message's sourceID. This will be accessible in the Driver for routing.</param> + /// <param name="bytes">The actual content of the message, serialized into a byte[]</param> + /// <returns>new ContextMessage with the given content.</returns> + public static ContextMessage From(string messageSourceId, byte[] bytes) + { + if (string.IsNullOrEmpty(messageSourceId)) + { + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new ArgumentNullException("messageSourceId"), LOGGER); + } + if (bytes == null) + { + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new ArgumentNullException("bytes"), LOGGER); + } + return new ContextMessage(messageSourceId, bytes); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/context/IContextMessage.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/context/IContextMessage.cs b/lang/cs/Org.Apache.REEF.Common/context/IContextMessage.cs new file mode 100644 index 0000000..7d7a298 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/context/IContextMessage.cs @@ -0,0 +1,28 @@ +/** + * 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.Utilities; + +namespace Org.Apache.REEF.Common.Context +{ + public interface IContextMessage : IMessage, IIdentifiable + { + string MessageSourceId { get; } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/context/IContextMessageHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/context/IContextMessageHandler.cs b/lang/cs/Org.Apache.REEF.Common/context/IContextMessageHandler.cs new file mode 100644 index 0000000..044d0af --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/context/IContextMessageHandler.cs @@ -0,0 +1,27 @@ +/** + * 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; + +namespace Org.Apache.REEF.Common.Context +{ + public interface IContextMessageHandler : IObserver<byte[]> + { + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/context/IContextMessageSource.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/context/IContextMessageSource.cs b/lang/cs/Org.Apache.REEF.Common/context/IContextMessageSource.cs new file mode 100644 index 0000000..d1eb08c --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/context/IContextMessageSource.cs @@ -0,0 +1,28 @@ +/** + * 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.Utilities; + +namespace Org.Apache.REEF.Common.Context +{ + public interface IContextMessageSource + { + Optional<ContextMessage> Message { get; set; } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/evaluator/DefaultLocalHttpDriverConnection.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/evaluator/DefaultLocalHttpDriverConnection.cs b/lang/cs/Org.Apache.REEF.Common/evaluator/DefaultLocalHttpDriverConnection.cs new file mode 100644 index 0000000..26049e6 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/evaluator/DefaultLocalHttpDriverConnection.cs @@ -0,0 +1,45 @@ +/** + * 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; +using System; + +namespace Org.Apache.REEF.Common.Evaluator +{ + public class DefaultLocalHttpDriverConnection : IDriverConnection + { + private readonly Uri _queryUri; + + [Inject] + public DefaultLocalHttpDriverConnection() + { + _queryUri = new Uri( + string.Concat( + Constants.LocalHttpEndpointBaseUri, + Constants.HttpReefUriSpecification, + Constants.HttpDriverUriTarget)); + } + + public DriverInformation GetDriverInformation(string applicationId) + { + // application id not needed for local runtime + return DriverInformation.GetDriverInformationFromHttp(_queryUri); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Common/evaluator/DefaultYarnClusterHttpDriverConnection.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/evaluator/DefaultYarnClusterHttpDriverConnection.cs b/lang/cs/Org.Apache.REEF.Common/evaluator/DefaultYarnClusterHttpDriverConnection.cs new file mode 100644 index 0000000..e0076e7 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/evaluator/DefaultYarnClusterHttpDriverConnection.cs @@ -0,0 +1,44 @@ +/** + * 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; +using System; + +namespace Org.Apache.REEF.Common.Evaluator +{ + public class DefaultYarnClusterHttpDriverConnection : IDriverConnection + { + [Inject] + public DefaultYarnClusterHttpDriverConnection() + { + } + + public DriverInformation GetDriverInformation(string applicationId) + { + // e.g., http://headnodehost:9014/proxy/application_1407519727821_0012/reef/v1/driver + Uri queryUri = new Uri( + string.Concat( + Constants.HDInsightClusterHttpEndpointBaseUri, + applicationId, + Constants.HttpReefUriSpecification, + Constants.HttpDriverUriTarget)); + return DriverInformation.GetDriverInformationFromHttp(queryUri); + } + } +}
