http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/defaults/DefaultTaskRunningHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/defaults/DefaultTaskRunningHandler.cs b/lang/cs/Source/REEF/reef-common/ReefDriver/defaults/DefaultTaskRunningHandler.cs new file mode 100644 index 0000000..0811967 --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/defaults/DefaultTaskRunningHandler.cs @@ -0,0 +1,54 @@ +/** + * 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.Driver.Task; +using Org.Apache.Reef.Utilities.Logging; +using Org.Apache.Reef.Tang.Annotations; +using System; + +namespace Org.Apache.Reef.Driver.Defaults +{ + /// <summary> + /// Default event handler for TaskRuntime: Logging it. + /// </summary> + public class DefaultTaskRunningHandler : IObserver<IRunningTask> + { + private static readonly Logger LOGGER = Logger.GetLogger(typeof(DefaultTaskRunningHandler)); + + [Inject] + public DefaultTaskRunningHandler() + { + } + + public void OnNext(IRunningTask runningTask) + { + LOGGER.Log(Level.Info, "Received TaskRuntime: " + runningTask.Id); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + } +}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/defaults/DefaultTaskSuspensionHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/defaults/DefaultTaskSuspensionHandler.cs b/lang/cs/Source/REEF/reef-common/ReefDriver/defaults/DefaultTaskSuspensionHandler.cs new file mode 100644 index 0000000..328b745 --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/defaults/DefaultTaskSuspensionHandler.cs @@ -0,0 +1,53 @@ +/** + * 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; +using Org.Apache.Reef.Utilities.Diagnostics; +using Org.Apache.Reef.Utilities.Logging; +using Org.Apache.Reef.Tang.Annotations; +using System; + +namespace Org.Apache.Reef.Driver.Defaults +{ + /// <summary> + /// Default event handler used for SuspendedTask: It crashes the driver. + /// </summary> + public class DefaultTaskSuspensionHandler : IObserver<ISuspendedTask> + { + [Inject] + public DefaultTaskSuspensionHandler() + { + } + + public void OnNext(ISuspendedTask value) + { + Exceptions.Throw(new InvalidOperationException("No handler bound for SuspendedTask: " + value.Id), Logger.GetLogger(typeof(DefaultTaskSuspensionHandler))); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/EvaluatorDescriptorImpl.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/EvaluatorDescriptorImpl.cs b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/EvaluatorDescriptorImpl.cs new file mode 100644 index 0000000..a43337e --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/EvaluatorDescriptorImpl.cs @@ -0,0 +1,218 @@ +/** + * 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.Catalog; +using Org.Apache.Reef.Common.Evaluator; +using Org.Apache.Reef.Driver.Bridge; +using Org.Apache.Reef.Utilities.Diagnostics; +using Org.Apache.Reef.Utilities.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; + +namespace Org.Apache.Reef.Driver.Evaluator +{ + public class EvaluatorDescriptorImpl : IEvaluatorDescriptor + { + private static readonly Logger LOGGER = Logger.GetLogger(typeof(EvaluatorDescriptorImpl)); + + private INodeDescriptor _nodeDescriptor; + + private EvaluatorType _type; + + private int _megaBytes; + + private int _virtualCore; + + private string _rack = "default_rack"; + + public EvaluatorDescriptorImpl(string serializedString) + { + FromString(serializedString); + } + + public EvaluatorDescriptorImpl(INodeDescriptor nodeDescriptor, EvaluatorType type, int megaBytes, int core) + { + _nodeDescriptor = nodeDescriptor; + _type = type; + _megaBytes = megaBytes; + _virtualCore = core; + } + + public INodeDescriptor NodeDescriptor + { + get + { + return _nodeDescriptor; + } + + set + { + } + } + + public EvaluatorType EvaluatorType + { + get + { + return _type; + } + + set + { + } + } + + public int Memory + { + get + { + return _megaBytes; + } + + set + { + } + } + + public int VirtualCore + { + get + { + return _virtualCore; + } + + set + { + } + } + + public string Rack + { + get + { + return _rack; + } + + set + { + } + } + + public void FromString(string str) + { + Dictionary<string, string> settings = new Dictionary<string, string>(); + string[] components = str.Split(','); + foreach (string component in components) + { + string[] pair = component.Trim().Split('='); + if (pair == null || pair.Length != 2) + { + var e = new ArgumentException("invalid component to be used as key-value pair:", component); + Exceptions.Throw(e, LOGGER); + } + settings.Add(pair[0], pair[1]); + } + string ipAddress; + if (!settings.TryGetValue("IP", out ipAddress)) + { + Exceptions.Throw(new ArgumentException("cannot find IP entry"), LOGGER); + } + ipAddress = ipAddress.Split('/').Last(); + string port; + if (!settings.TryGetValue("Port", out port)) + { + Exceptions.Throw(new ArgumentException("cannot find Port entry"), LOGGER); + } + int portNumber = 0; + int.TryParse(port, out portNumber); + string hostName; + if (!settings.TryGetValue("HostName", out hostName)) + { + Exceptions.Throw(new ArgumentException("cannot find HostName entry"), LOGGER); + } + string memory; + if (!settings.TryGetValue("Memory", out memory)) + { + Exceptions.Throw(new ArgumentException("cannot find Memory entry"), LOGGER); + } + int memoryInMegaBytes = 0; + int.TryParse(memory, out memoryInMegaBytes); + + string core; + if (!settings.TryGetValue("Core", out core)) + { + Exceptions.Throw(new ArgumentException("cannot find Core entry"), LOGGER); + } + int vCore = 0; + int.TryParse(core, out vCore); + + IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse(ipAddress), portNumber); + + _nodeDescriptor = new NodeDescriptorImpl(); + _nodeDescriptor.InetSocketAddress = ipEndPoint; + _nodeDescriptor.HostName = hostName; + _type = EvaluatorType.CLR; + _megaBytes = memoryInMegaBytes; + _virtualCore = vCore; + } + + public void SetType(EvaluatorType type) + { + lock (this) + { + if (_type != EvaluatorType.UNDECIDED) + { + var e = new InvalidOperationException("Cannot change a set evaluator type: " + _type); + Exceptions.Throw(e, LOGGER); + } + _type = type; + } + } + + public override bool Equals(object obj) + { + EvaluatorDescriptorImpl other = obj as EvaluatorDescriptorImpl; + if (other == null) + { + return false; + } + + return EquivalentMemory(other); + // we don't care about rack now; + // && string.Equals(_rack, other.Rack, StringComparison.OrdinalIgnoreCase); + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + + private bool EquivalentMemory(EvaluatorDescriptorImpl other) + { + int granularity = ClrHandlerHelper.MemoryGranularity == 0 + ? Constants.DefaultMemoryGranularity + : ClrHandlerHelper.MemoryGranularity; + int m1 = (Memory - 1) / granularity; + int m2 = (other.Memory - 1 ) / granularity; + return (m1 == m2); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/EvaluatorRequest.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/EvaluatorRequest.cs b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/EvaluatorRequest.cs new file mode 100644 index 0000000..fda7d5b --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/EvaluatorRequest.cs @@ -0,0 +1,108 @@ +/** + * 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.Catalog; +using Org.Apache.Reef.Driver.Evaluator; +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace Org.Apache.Reef.Driver.Bridge +{ + [DataContract] + public class EvaluatorRequest : IEvaluatorRequest + { + public EvaluatorRequest() + : this(0, 0, 1, string.Empty, Guid.NewGuid().ToString("N")) + { + } + + public EvaluatorRequest(int number, int megaBytes) + : this(number, megaBytes, 1, string.Empty, Guid.NewGuid().ToString("N")) + { + } + + public EvaluatorRequest(int number, int megaBytes, int core) + : this(number, megaBytes, core, string.Empty, Guid.NewGuid().ToString("N")) + { + } + + public EvaluatorRequest(int number, int megaBytes, string rack) + : this(number, megaBytes, 1, rack, Guid.NewGuid().ToString("N")) + { + } + + public EvaluatorRequest(int number, int megaBytes, int core, string rack) + : this(number, megaBytes, core, rack, Guid.NewGuid().ToString("N")) + { + } + + public EvaluatorRequest(int number, int megaBytes, int core, string rack, string evaluatorBatchId) + { + Number = number; + MemoryMegaBytes = megaBytes; + VirtualCore = core; + Rack = rack; + EvaluatorBatchId = evaluatorBatchId; + } + + public EvaluatorRequest(int number, int megaBytes, int core, List<ICapability> capabilitieses, IResourceCatalog catalog) + { + Number = number; + MemoryMegaBytes = megaBytes; + Capabilities = capabilitieses; + VirtualCore = core; + Catalog = catalog; + EvaluatorBatchId = Guid.NewGuid().ToString("N"); + } + + [DataMember] + public string InstanceId { get; set; } + + [DataMember] + public int MemoryMegaBytes { get; set; } + + [DataMember] + public int Number { get; set; } + + [DataMember] + public int VirtualCore { get; set; } + + [DataMember] + public string Rack { get; set; } + + [DataMember] + public string EvaluatorBatchId { get; set; } + + public List<ICapability> Capabilities { get; set; } + + public IResourceCatalog Catalog { get; set; } + + public static EvaluatorRequestBuilder NewBuilder() + { + return new EvaluatorRequestBuilder(); + } + + public static EvaluatorRequestBuilder NewBuilder(EvaluatorRequest request) + { + return new EvaluatorRequestBuilder(request); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/EvaluatorRequestBuilder.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/EvaluatorRequestBuilder.cs b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/EvaluatorRequestBuilder.cs new file mode 100644 index 0000000..475d9af --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/EvaluatorRequestBuilder.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 Org.Apache.Reef.Common.Capabilities; +using Org.Apache.Reef.Common.Catalog; +using Org.Apache.Reef.Driver.Bridge; +using System.Collections.Generic; + +namespace Org.Apache.Reef.Driver.Evaluator +{ + public class EvaluatorRequestBuilder + { + public EvaluatorRequestBuilder(EvaluatorRequest request) + { + foreach (ICapability capability in request.Capabilities) + { + Capabilities.Add(capability); + } + Number = request.Number; + Catalog = request.Catalog; + MegaBytes = request.MemoryMegaBytes; + VirtualCore = request.VirtualCore; + } + + internal EvaluatorRequestBuilder() + { + } + + public int Number { get; set; } + + public List<ICapability> Capabilities { get; set; } + + public IResourceCatalog Catalog { get; set; } + + public int MegaBytes { get; set; } + + public int VirtualCore { get; set; } + + public EvaluatorRequest Build() + { + return new EvaluatorRequest(Number, MegaBytes, VirtualCore, Capabilities, Catalog); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IAllocatedEvaluator.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IAllocatedEvaluator.cs b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IAllocatedEvaluator.cs new file mode 100644 index 0000000..ce2bf08 --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IAllocatedEvaluator.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.Common; +using Org.Apache.Reef.Common.Evaluator; +using Org.Apache.Reef.Utilities; +using System; +using System.Net; + +namespace Org.Apache.Reef.Driver.Evaluator +{ + /// <summary> + /// Represents an Evaluator that is allocated, but is not running yet. + /// </summary> + public interface IAllocatedEvaluator : IDisposable, IIdentifiable, IContextSubmittable, IContextAndTaskSubmittable + { + EvaluatorType Type { get; set; } + + string NameServerInfo { get; set; } + + string EvaluatorBatchId { get; set; } + + IEvaluatorDescriptor GetEvaluatorDescriptor(); + + /// <summary> + /// Puts the given file into the working directory of the Evaluator. + /// </summary> + /// <param name="file">the file to be copied</param> + void AddFile(string file); + + /// <summary> + /// Puts the given file into the working directory of the Evaluator and adds it to its classpath. + /// </summary> + /// <param name="file">the file to be copied</param> + void AddLibrary(string file); + + void AddFileResource(string file); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/ICompletedEvaluator.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/ICompletedEvaluator.cs b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/ICompletedEvaluator.cs new file mode 100644 index 0000000..5c5fb62 --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/ICompletedEvaluator.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 Org.Apache.Reef.Utilities; + +namespace Org.Apache.Reef.Driver.Evaluator +{ + /// <summary> + /// Represents an Evaluator that has completed + /// </summary> + public interface ICompletedEvaluator : IIdentifiable + { + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IEvaluatorDescriptor.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IEvaluatorDescriptor.cs b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IEvaluatorDescriptor.cs new file mode 100644 index 0000000..29e822f --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IEvaluatorDescriptor.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.Common.Catalog; +using Org.Apache.Reef.Common.Evaluator; + +namespace Org.Apache.Reef.Driver.Evaluator +{ + /// <summary> + /// Metadata about an Evaluator. + /// </summary> + public interface IEvaluatorDescriptor + { + /// <summary> + /// NodeDescriptor of the node where this Evaluator is running. + /// </summary> + INodeDescriptor NodeDescriptor { get; set; } + + /// <summary> + /// type of Evaluator. + /// </summary> + EvaluatorType EvaluatorType { get; set; } + + /// <summary> + /// the amount of memory allocated to this Evaluator. + /// </summary> + int Memory { get; set; } + + /// <summary> + /// the virtual core allocated to this Evaluator. + /// </summary> + int VirtualCore { get; set; } + + /// <summary> + /// rack on which the evaluator was allocated + /// </summary> + string Rack { get; set; } + + void FromString(string str); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IEvaluatorRequest .cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IEvaluatorRequest .cs b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IEvaluatorRequest .cs new file mode 100644 index 0000000..4a9633a --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IEvaluatorRequest .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.Common.Capabilities; +using Org.Apache.Reef.Common.Catalog; +using System.Collections.Generic; + +namespace Org.Apache.Reef.Driver.Evaluator +{ + public interface IEvaluatorRequest + { + int MemoryMegaBytes { get; set; } + + int Number { get; set; } + + int VirtualCore { get; set; } + + string Rack { get; set; } + + string EvaluatorBatchId { get; set; } + + List<ICapability> Capabilities { get; set; } + + IResourceCatalog Catalog { get; set; } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IEvaluatorRequestor.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IEvaluatorRequestor.cs b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IEvaluatorRequestor.cs new file mode 100644 index 0000000..e562f96 --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IEvaluatorRequestor.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 System.Collections.Generic; + +using Org.Apache.Reef.Common.Catalog; + +namespace Org.Apache.Reef.Driver.Evaluator +{ + /// <summary> + /// Interface through which Evaluators can be requested. + /// </summary> + public interface IEvaluatorRequestor + { + /// <summary> + /// Access to the {@link ResourceCatalog} for the cluster this Factory has access to + /// </summary> + IResourceCatalog ResourceCatalog { get; set; } + + /// <summary> + /// Map between user evaluator id and evaluator information + /// </summary> + //IDictionary<string, IEvaluatorDescriptor> Evaluators { get; } + + /// <summary> + /// Submit the request for new evaluator. The response will surface in the AllocatedEvaluator message handler. + /// </summary> + /// <param name="request"></param> + void Submit(IEvaluatorRequest request); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IFailedEvaluator.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IFailedEvaluator.cs b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IFailedEvaluator.cs new file mode 100644 index 0000000..328d3ca --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/evaluator/IFailedEvaluator.cs @@ -0,0 +1,41 @@ +/** + * 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.Exceptions; +using Org.Apache.Reef.Driver.Bridge; +using Org.Apache.Reef.Driver.Task; +using Org.Apache.Reef.Utilities; +using System.Collections.Generic; + +namespace Org.Apache.Reef.Driver.Evaluator +{ + /// <summary> + /// Represents an Evaluator that became unavailable. + /// </summary> + public interface IFailedEvaluator : IIdentifiable + { + EvaluatorException EvaluatorException { get; set; } + + List<FailedContext> FailedContexts { get; set; } + + Optional<IFailedTask> FailedTask { get; set; } + + IEvaluatorRequestor GetEvaluatorRequetor(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/packages.config ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/packages.config b/lang/cs/Source/REEF/reef-common/ReefDriver/packages.config new file mode 100644 index 0000000..933b7e1 --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/packages.config @@ -0,0 +1,24 @@ +<?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. +--> +<packages> + <package id="Microsoft.Hadoop.Avro" version="1.4.0.0" targetFramework="net45" /> + <package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" /> + <package id="protobuf-net" version="2.0.0.668" targetFramework="net45" /> +</packages> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/task/ICompletedTask.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/task/ICompletedTask.cs b/lang/cs/Source/REEF/reef-common/ReefDriver/task/ICompletedTask.cs new file mode 100644 index 0000000..336fd5c --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/task/ICompletedTask.cs @@ -0,0 +1,29 @@ +/** + * 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.Driver.Context; +using Org.Apache.Reef.Utilities; + +namespace Org.Apache.Reef.Driver.Task +{ + public interface ICompletedTask : IMessage, IIdentifiable + { + IActiveContext ActiveContext { get; set; } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/task/IFailedTask.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/task/IFailedTask.cs b/lang/cs/Source/REEF/reef-common/ReefDriver/task/IFailedTask.cs new file mode 100644 index 0000000..f85f28d --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/task/IFailedTask.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 Org.Apache.Reef.Common.Api; +using Org.Apache.Reef.Driver.Context; +using Org.Apache.Reef.Utilities; + +namespace Org.Apache.Reef.Driver.Task +{ + public interface IFailedTask : IAbstractFailure + { + Optional<IActiveContext> GetActiveContext(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/task/IRunningTask.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/task/IRunningTask.cs b/lang/cs/Source/REEF/reef-common/ReefDriver/task/IRunningTask.cs new file mode 100644 index 0000000..7870777 --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/task/IRunningTask.cs @@ -0,0 +1,65 @@ +/** + * 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.Driver.Context; +using Org.Apache.Reef.Utilities; +using System; + +namespace Org.Apache.Reef.Driver.Task +{ + /// <summary> + /// Represents a running Task + /// </summary> + public interface IRunningTask : IIdentifiable, IDisposable + { + /// <summary> + /// the context the task is running on. + /// </summary> + IActiveContext ActiveContext { get; set; } + + /// <summary> + /// Sends the message to the running task. + /// </summary> + /// <param name="message"></param> + void OnNext(byte[] message); + + /// <summary> + /// Sends the message + /// </summary> + /// <param name="message"></param> + void Send(byte[] message); + + /// <summary> + /// Signal the task to suspend. + /// </summary> + /// <param name="message">a message that is sent to the Task.</param> + void Suspend(byte[] message); + + /// <summary> + /// Sends the message to the running task. + /// </summary> + void Suspend(); + + /// <summary> + /// Signal the task to shut down. + /// </summary> + /// <param name="message">a message that is sent to the Task.</param> + void Dispose(byte[] message); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/task/ISuspendedTask.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/task/ISuspendedTask.cs b/lang/cs/Source/REEF/reef-common/ReefDriver/task/ISuspendedTask.cs new file mode 100644 index 0000000..c6b769a --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/task/ISuspendedTask.cs @@ -0,0 +1,29 @@ +/** + * 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.Driver.Context; +using Org.Apache.Reef.Utilities; + +namespace Org.Apache.Reef.Driver +{ + public interface ISuspendedTask : IMessage, IIdentifiable + { + IActiveContext ActiveContext { get; set; } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/task/ITaskMessage.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/task/ITaskMessage.cs b/lang/cs/Source/REEF/reef-common/ReefDriver/task/ITaskMessage.cs new file mode 100644 index 0000000..e6fb7a1 --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/task/ITaskMessage.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. + */ + +namespace Org.Apache.Reef.Driver.Task +{ + public interface ITaskMessage + { + byte[] Message { get; set; } + + string TaskId { get; set; } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-common/ReefDriver/task/RunningTaskImpl.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-common/ReefDriver/task/RunningTaskImpl.cs b/lang/cs/Source/REEF/reef-common/ReefDriver/task/RunningTaskImpl.cs new file mode 100644 index 0000000..277e742 --- /dev/null +++ b/lang/cs/Source/REEF/reef-common/ReefDriver/task/RunningTaskImpl.cs @@ -0,0 +1,127 @@ +/** + * 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; +using Org.Apache.Reef.Common.ProtoBuf.EvaluatorRunTimeProto; +using Org.Apache.Reef.Driver.Context; +using Org.Apache.Reef.Utilities.Logging; +using System.Globalization; + +namespace Org.Apache.Reef.Driver.Task +{ + public class RunningTaskImpl : IRunningTask + { + private static readonly Logger LOGGER = Logger.GetLogger(typeof(RunningTaskImpl)); + + private string _id; + + private EvaluatorManager _evaluatorManager; + + private EvaluatorContext _evaluatorContext; + + public RunningTaskImpl(EvaluatorManager evaluatorManager, string taskId, EvaluatorContext evaluatorContext) + { + LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "INIT: TaskRuntime id [{0}] on evaluator id [{1}]", taskId, evaluatorManager.Id)); + _id = taskId; + _evaluatorManager = evaluatorManager; + _evaluatorContext = evaluatorContext; + } + + public string Id + { + get + { + return _id; + } + + set + { + } + } + + public IActiveContext ActiveContext + { + get + { + return _evaluatorContext; + } + + set + { + } + } + + public void Dispose() + { + LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "DISPOSE: TaskRuntime id [{0}] on evaluator id [{1}]", _id, _evaluatorManager.Id)); + ContextControlProto contextControlProto = new ContextControlProto(); + contextControlProto.stop_task = new StopTaskProto(); + _evaluatorManager.Handle(contextControlProto); + } + + public void Dispose(byte[] message) + { + LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "DISPOSE: TaskRuntime id [{0}] on evaluator id [{1}] with message", _id, _evaluatorManager.Id)); + ContextControlProto contextControlProto = new ContextControlProto(); + contextControlProto.stop_task = new StopTaskProto(); + contextControlProto.task_message = message; + _evaluatorManager.Handle(contextControlProto); + } + + public void OnNext(byte[] message) + { + LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "MESSAGE: TaskRuntime id [{0}] on evaluator id [{1}]", _id, _evaluatorManager.Id)); + ContextControlProto contextControlProto = new ContextControlProto(); + contextControlProto.task_message = message; + _evaluatorManager.Handle(contextControlProto); + } + + public void Suspend(byte[] message) + { + LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "SUSPEND: TaskRuntime id [{0}] on evaluator id [{1}] with message", _id, _evaluatorManager.Id)); + ContextControlProto contextControlProto = new ContextControlProto(); + contextControlProto.suspend_task = new SuspendTaskProto(); + contextControlProto.task_message = message; + _evaluatorManager.Handle(contextControlProto); + } + + public void Suspend() + { + LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "SUSPEND: TaskRuntime id [{0}] on evaluator id [{1}]", _id, _evaluatorManager.Id)); + ContextControlProto contextControlProto = new ContextControlProto(); + contextControlProto.suspend_task = new SuspendTaskProto(); + _evaluatorManager.Handle(contextControlProto); + } + + public override string ToString() + { + return "TaskRuntime with taskId = " + _id; + } + + public override int GetHashCode() + { + return _id.GetHashCode(); + } + + public void Send(byte[] message) + { + LOGGER.Log(Level.Info, "RunningTaskImpl.Send() is called"); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/HelloCLRBridge.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/HelloCLRBridge.csproj b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/HelloCLRBridge.csproj new file mode 100644 index 0000000..09c8b0b --- /dev/null +++ b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/HelloCLRBridge.csproj @@ -0,0 +1,118 @@ +<?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>{A78DD8E8-31D0-4506-8738-DAA9DA86D55B}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Org.Apache.Reef.Examples.HelloCLRBridge</RootNamespace> + <AssemblyName>Org.Apache.Reef.Examples.HelloCLRBridge</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>..\..\..\..\bin\Debug\Org.Apache.Reef.Examples.HelloCLRBridge\</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>..\..\..\..\bin\Release\Microsoft.Reef.Examples.HelloCLRBridge\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <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="handlers\AnotherHelloAllocatedEvaluatorHandler.cs" /> + <Compile Include="handlers\HelloActiveContextHandler.cs" /> + <Compile Include="handlers\HelloAllocatedEvaluatorHandler.cs" /> + <Compile Include="handlers\HelloCompletedEvaluatorHandler.cs" /> + <Compile Include="handlers\HelloDriverRestartActiveContextHandler.cs" /> + <Compile Include="handlers\HelloDriverRestartRunningTaskHandler.cs" /> + <Compile Include="handlers\HelloEvaluatorRequestorHandler.cs" /> + <Compile Include="handlers\HelloFailedEvaluatorHandler.cs" /> + <Compile Include="handlers\HelloFailedTaskHandler.cs" /> + <Compile Include="handlers\HelloHttpHandler.cs" /> + <Compile Include="handlers\HelloRestartHandler.cs" /> + <Compile Include="handlers\HelloRunningTaskHandler.cs" /> + <Compile Include="handlers\HelloSimpleEventHandlers.cs" /> + <Compile Include="handlers\HelloStartHandler.cs" /> + <Compile Include="handlers\HelloTaskMessageHandler.cs" /> + <Compile Include="HelloTraceListener.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\..\Tang\Tang\Tang.csproj"> + <Project>{97dbb573-3994-417a-9f69-ffa25f00d2a6}</Project> + <Name>Tang</Name> + </ProjectReference> + <ProjectReference Include="..\..\..\Utilities\Utilities.csproj"> + <Project>{79e7f89a-1dfb-45e1-8d43-d71a954aeb98}</Project> + <Name>Utilities</Name> + </ProjectReference> + <ProjectReference Include="..\..\..\WAKE\Wake\Wake.csproj"> + <Project>{cdfb3464-4041-42b1-9271-83af24cd5008}</Project> + <Name>Wake</Name> + </ProjectReference> + <ProjectReference Include="..\..\reef-common\ReefCommon\ReefCommon.csproj"> + <Project>{545a0582-4105-44ce-b99c-b1379514a630}</Project> + <Name>ReefCommon</Name> + </ProjectReference> + <ProjectReference Include="..\..\reef-common\ReefDriver\ReefDriver.csproj"> + <Project>{a6baa2a7-f52f-4329-884e-1bcf711d6805}</Project> + <Name>ReefDriver</Name> + </ProjectReference> + <ProjectReference Include="..\..\reef-io\NetWork\NetWork.csproj"> + <Project>{883ce800-6a6a-4e0a-b7fe-c054f4f2c1dc}</Project> + <Name>NetWork</Name> + </ProjectReference> + <ProjectReference Include="..\..\reef-tasks\Tasks\Tasks.csproj"> + <Project>{75503f90-7b82-4762-9997-94b5c68f15db}</Project> + <Name>Tasks</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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/2ae282de/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/HelloTraceListener.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/HelloTraceListener.cs b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/HelloTraceListener.cs new file mode 100644 index 0000000..18bcd7b --- /dev/null +++ b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/HelloTraceListener.cs @@ -0,0 +1,48 @@ +/** + * 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.Diagnostics; + +namespace Org.Apache.Reef.Examples.HelloCLRBridge +{ + /// <summary> + /// This is a sample implemenation on how custom trace listner can be implemented + /// </summary> + public class HelloTraceListener : TraceListener + { + private TraceListener _listener; + + [Inject] + public HelloTraceListener() + { + _listener = new ConsoleTraceListener(); + } + + public override void Write(string message) + { + _listener.Write("[helloTrace]" + message ); + } + + public override void WriteLine(string message) + { + _listener.WriteLine("[helloTrace]" + message); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/Properties/AssemblyInfo.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/Properties/AssemblyInfo.cs b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6c1a298 --- /dev/null +++ b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/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("HelloCLRBridge")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("HelloCLRBridge")] +[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("aedd2853-36a1-4a95-ac5c-1535374fa90c")] + +// 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/2ae282de/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/AnotherHelloAllocatedEvaluatorHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/AnotherHelloAllocatedEvaluatorHandler.cs b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/AnotherHelloAllocatedEvaluatorHandler.cs new file mode 100644 index 0000000..5fff7b0 --- /dev/null +++ b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/AnotherHelloAllocatedEvaluatorHandler.cs @@ -0,0 +1,48 @@ +/** + * 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.Driver.Evaluator; +using Org.Apache.Reef.Tang.Annotations; +using System; + +namespace Org.Apache.Reef.Examples.HelloCLRBridge +{ + public class AnotherHelloAllocatedEvaluatorHandler : IObserver<IAllocatedEvaluator> + { + [Inject] + public AnotherHelloAllocatedEvaluatorHandler() + { + } + + public void OnNext(IAllocatedEvaluator allocatedEvaluator) + { + Console.WriteLine("I am just here for the ride."); + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloActiveContextHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloActiveContextHandler.cs b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloActiveContextHandler.cs new file mode 100644 index 0000000..98cf687 --- /dev/null +++ b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloActiveContextHandler.cs @@ -0,0 +1,82 @@ +/** + * 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.Driver.Context; +using Org.Apache.Reef.Driver.Evaluator; +using Org.Apache.Reef.Tasks; +using Org.Apache.Reef.Tang.Annotations; +using Org.Apache.Reef.Tang.Formats; +using Org.Apache.Reef.Tang.Interface; +using Org.Apache.Reef.Tang.Util; +using System; +using System.Globalization; + +namespace Org.Apache.Reef.Examples.HelloCLRBridge +{ + public class HelloActiveContextHandler : IObserver<IActiveContext> + { + [Inject] + public HelloActiveContextHandler() + { + } + + public void OnNext(IActiveContext activeContext) + { + Console.WriteLine( + string.Format( + CultureInfo.InvariantCulture, + "Active context {0} received from evaluator {1}", + activeContext.Id, + activeContext.EvaluatorId)); + + IEvaluatorDescriptor evaluatorDescriptor = activeContext.EvaluatorDescriptor; + string ipAddress = evaluatorDescriptor.NodeDescriptor.InetSocketAddress.Address.ToString(); + int port = evaluatorDescriptor.NodeDescriptor.InetSocketAddress.Port; + string hostName = evaluatorDescriptor.NodeDescriptor.HostName; + + Console.WriteLine( + string.Format( + CultureInfo.InvariantCulture, + "The running evaluator is assigned with {0} MB of memory and is running at ip: {1} and port {2}, with hostname {3}", + evaluatorDescriptor.Memory, + ipAddress, + port, + hostName)); + + IConfiguration taskConfiguration = TaskConfiguration.ConfigurationModule + .Set(TaskConfiguration.Identifier, "bridgeCLRHelloTask_" + DateTime.Now.Ticks) + .Set(TaskConfiguration.Task, GenericType<HelloTask>.Class) + .Set(TaskConfiguration.OnMessage, GenericType<HelloTask.HelloDriverMessageHandler>.Class) + .Set(TaskConfiguration.OnSendMessage, GenericType<HelloTaskMessage>.Class) + .Build(); + + activeContext.SubmitTask(taskConfiguration); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloAllocatedEvaluatorHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloAllocatedEvaluatorHandler.cs b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloAllocatedEvaluatorHandler.cs new file mode 100644 index 0000000..a4e4d46 --- /dev/null +++ b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloAllocatedEvaluatorHandler.cs @@ -0,0 +1,131 @@ +/** + * 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.io; +using Org.Apache.Reef.Driver.Bridge; +using Org.Apache.Reef.Driver.Context; +using Org.Apache.Reef.Driver.Evaluator; +using Org.Apache.Reef.IO.Network.Naming; +using Org.Apache.Reef.Services; +using Org.Apache.Reef.Tasks; +using Org.Apache.Reef.Utilities; +using Org.Apache.Reef.Tang.Annotations; +using Org.Apache.Reef.Tang.Implementations; +using Org.Apache.Reef.Tang.Implementations.Configuration; +using Org.Apache.Reef.Tang.Interface; +using Org.Apache.Reef.Tang.Util; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Net; + +namespace Org.Apache.Reef.Examples.HelloCLRBridge +{ + public class HelloAllocatedEvaluatorHandler : IObserver<IAllocatedEvaluator> + { + [Inject] + public HelloAllocatedEvaluatorHandler() + { + } + + public void OnNext(IAllocatedEvaluator allocatedEvaluator) + { + string control = string.Empty; + + ISet<string> arguments = ClrHandlerHelper.GetCommandLineArguments(); + + if (arguments != null && arguments.Any()) + { + foreach (string argument in arguments) + { + Console.WriteLine("testing argument: " + argument); + } + + control = arguments.Last(); + } + + IEvaluatorDescriptor descriptor = allocatedEvaluator.GetEvaluatorDescriptor(); + + IConfiguration serviceConfiguration = ServiceConfiguration.ConfigurationModule + .Set(ServiceConfiguration.Services, GenericType<HelloService>.Class) + .Build(); + + IConfiguration contextConfiguration = ContextConfiguration.ConfigurationModule + .Set(ContextConfiguration.Identifier, "bridgeHelloCLRContextId_" + Guid.NewGuid().ToString("N")) + .Build(); + + IConfiguration taskConfiguration = TaskConfiguration.ConfigurationModule + .Set(TaskConfiguration.Identifier, "bridgeHelloCLRTaskId_" + Guid.NewGuid().ToString("N")) + .Set(TaskConfiguration.Task, GenericType<HelloTask>.Class) + .Set(TaskConfiguration.OnMessage, GenericType<HelloTask.HelloDriverMessageHandler>.Class) + .Set(TaskConfiguration.OnSendMessage, GenericType<HelloTaskMessage>.Class) + .Build(); + + IConfiguration mergedTaskConfiguration = taskConfiguration; + + if (allocatedEvaluator.NameServerInfo != null) + { + IPEndPoint nameServerEndpoint = NetUtilities.ParseIpEndpoint(allocatedEvaluator.NameServerInfo); + + IConfiguration nameClientConfiguration = TangFactory.GetTang().NewConfigurationBuilder( + NamingConfiguration.ConfigurationModule + .Set(NamingConfiguration.NameServerAddress, nameServerEndpoint.Address.ToString()) + .Set(NamingConfiguration.NameServerPort, + nameServerEndpoint.Port.ToString(CultureInfo.InvariantCulture)) + .Build()) + .BindImplementation(GenericType<INameClient>.Class, + GenericType<NameClient>.Class) + .Build(); + + mergedTaskConfiguration = Configurations.Merge(taskConfiguration, nameClientConfiguration); + } + + string ipAddress = descriptor.NodeDescriptor.InetSocketAddress.Address.ToString(); + int port = descriptor.NodeDescriptor.InetSocketAddress.Port; + string hostName = descriptor.NodeDescriptor.HostName; + Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Alloated evaluator {0} with ip {1}:{2}. Hostname is {3}", allocatedEvaluator.Id, ipAddress, port, hostName)); + Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Evaluator is assigned with {0} MB of memory and {1} cores.", descriptor.Memory, descriptor.VirtualCore)); + + if (control.Equals("submitContext", StringComparison.OrdinalIgnoreCase)) + { + allocatedEvaluator.SubmitContext(contextConfiguration); + } + else if (control.Equals("submitContextAndServiceAndTask", StringComparison.OrdinalIgnoreCase)) + { + allocatedEvaluator.SubmitContextAndServiceAndTask(contextConfiguration, serviceConfiguration, mergedTaskConfiguration); + } + else + { + // default behavior + allocatedEvaluator.SubmitContextAndTask(contextConfiguration, mergedTaskConfiguration); + } + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloCompletedEvaluatorHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloCompletedEvaluatorHandler.cs b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloCompletedEvaluatorHandler.cs new file mode 100644 index 0000000..3eeef00 --- /dev/null +++ b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloCompletedEvaluatorHandler.cs @@ -0,0 +1,59 @@ +/** + * 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.Driver.Context; +using Org.Apache.Reef.Driver.Evaluator; +using Org.Apache.Reef.Driver.Task; +using Org.Apache.Reef.Utilities; +using Org.Apache.Reef.Tang.Annotations; +using System; +using System.Globalization; + +namespace Org.Apache.Reef.Examples.HelloCLRBridge.Handlers +{ + /// <summary> + /// Sample implementaion of RunningTaskHandler + /// </summary> + public class HelloCompletedEvaluatorHandler : IObserver<ICompletedEvaluator> + { + [Inject] + public HelloCompletedEvaluatorHandler() + { + } + + public void OnNext(ICompletedEvaluator completedEvaluator) + { + string messageStr = string.Format( + CultureInfo.InvariantCulture, + "HelloCompletedEvaluatorHandler: Evaluator [{0}] is done.", + completedEvaluator.Id); + Console.WriteLine(messageStr); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloDriverRestartActiveContextHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloDriverRestartActiveContextHandler.cs b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloDriverRestartActiveContextHandler.cs new file mode 100644 index 0000000..f60daf2 --- /dev/null +++ b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloDriverRestartActiveContextHandler.cs @@ -0,0 +1,69 @@ +/** + * 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.Driver.Context; +using Org.Apache.Reef.Driver.Evaluator; +using Org.Apache.Reef.Tang.Annotations; +using System; +using System.Globalization; + +namespace Org.Apache.Reef.Examples.HelloCLRBridge +{ + public class HelloDriverRestartActiveContextHandler : IObserver<IActiveContext> + { + [Inject] + public HelloDriverRestartActiveContextHandler() + { + } + + public void OnNext(IActiveContext activeContext) + { + Console.WriteLine( + string.Format( + CultureInfo.InvariantCulture, + "Active context {0} received after driver restart, from evaluator {1}", + activeContext.Id, + activeContext.EvaluatorId)); + + IEvaluatorDescriptor evaluatorDescriptor = activeContext.EvaluatorDescriptor; + string ipAddress = evaluatorDescriptor.NodeDescriptor.InetSocketAddress.Address.ToString(); + int port = evaluatorDescriptor.NodeDescriptor.InetSocketAddress.Port; + string hostName = evaluatorDescriptor.NodeDescriptor.HostName; + + Console.WriteLine( + string.Format( + CultureInfo.InvariantCulture, + "The running evaluator allocated by previous driver is assigned with {0} MB of memory and is running at ip: {1} and port {2}, with hostname {3}", + evaluatorDescriptor.Memory, + ipAddress, + port, + hostName)); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloDriverRestartRunningTaskHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloDriverRestartRunningTaskHandler.cs b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloDriverRestartRunningTaskHandler.cs new file mode 100644 index 0000000..26f72b8 --- /dev/null +++ b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloDriverRestartRunningTaskHandler.cs @@ -0,0 +1,67 @@ +/** + * 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.Driver.Context; +using Org.Apache.Reef.Driver.Task; +using Org.Apache.Reef.Utilities; +using Org.Apache.Reef.Tang.Annotations; + +namespace Org.Apache.Reef.Examples.HelloCLRBridge.Handlers +{ + /// <summary> + /// Sample implementaion of RunningTaskHandler + /// </summary> + public class HelloDriverRestartRunningTaskHandler : IObserver<IRunningTask> + { + [Inject] + public HelloDriverRestartRunningTaskHandler() + { + } + + public void OnNext(IRunningTask runningTask) + { + IActiveContext context = runningTask.ActiveContext; + + Console.WriteLine(string.Format( + CultureInfo.InvariantCulture, + "HelloDriverRestartRunningTaskHandler: Task [{0}] is running after driver restart. Evaluator id: [{1}].", + runningTask.Id, + context.EvaluatorId)); + + runningTask.Send(ByteUtilities.StringToByteArrays( + string.Format( + CultureInfo.InvariantCulture, + "Hello, task {0}! Glad to know that you are still running in Evaluator {1} after driver restart!", + runningTask.Id, + context.EvaluatorId))); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloEvaluatorRequestorHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloEvaluatorRequestorHandler.cs b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloEvaluatorRequestorHandler.cs new file mode 100644 index 0000000..08f2308 --- /dev/null +++ b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloEvaluatorRequestorHandler.cs @@ -0,0 +1,65 @@ +/** + * 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.Driver.Bridge; +using Org.Apache.Reef.Driver.Evaluator; +using System; + +using Org.Apache.Reef.Tang.Annotations; + +namespace Org.Apache.Reef.Examples.HelloCLRBridge +{ + public class HelloEvaluatorRequestorHandler : IObserver<IEvaluatorRequestor> + { + [Inject] + public HelloEvaluatorRequestorHandler() + { + } + + public void OnNext(IEvaluatorRequestor evalutorRequestor) + { + int evaluatorsNumber = 1; + int memory = 512; + int core = 2; + string rack = "WonderlandRack"; + string evaluatorBatchId = "evaluatorThatRequires512MBofMemory"; + EvaluatorRequest request = new EvaluatorRequest(evaluatorsNumber, memory, core, rack, evaluatorBatchId); + + evalutorRequestor.Submit(request); + + evaluatorsNumber = 1; + memory = 1999; + core = 2; + rack = "WonderlandRack"; + evaluatorBatchId = "evaluatorThatRequires1999MBofMemory"; + request = new EvaluatorRequest(evaluatorsNumber, memory, core, rack, evaluatorBatchId); + evalutorRequestor.Submit(request); + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloFailedEvaluatorHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloFailedEvaluatorHandler.cs b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloFailedEvaluatorHandler.cs new file mode 100644 index 0000000..22732e6 --- /dev/null +++ b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloFailedEvaluatorHandler.cs @@ -0,0 +1,68 @@ +/** + * 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.Driver.Bridge; +using Org.Apache.Reef.Driver.Evaluator; +using Org.Apache.Reef.Tang.Annotations; +using System; + +namespace Org.Apache.Reef.Examples.HelloCLRBridge +{ + public class HelloFailedEvaluatorHandler : IObserver<IFailedEvaluator> + { + private static int _failureCount = 0; + + private static int _maxTrial = 2; + + [Inject] + public HelloFailedEvaluatorHandler() + { + } + + public void OnNext(IFailedEvaluator failedEvaluator) + { + Console.WriteLine("Receive a failed evaluator: " + failedEvaluator.Id); + if (++_failureCount < _maxTrial) + { + Console.WriteLine("Requesting another evaluator"); + EvaluatorRequest newRequest = new EvaluatorRequest(1, 512, "somerack"); + IEvaluatorRequestor requestor = failedEvaluator.GetEvaluatorRequetor(); + if (failedEvaluator.GetEvaluatorRequetor() != null) + { + requestor.Submit(newRequest); + } + } + else + { + Console.WriteLine("Exceed max retries number"); + throw new Exception("Unrecoverable evaluator failure."); + } + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloFailedTaskHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloFailedTaskHandler.cs b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloFailedTaskHandler.cs new file mode 100644 index 0000000..541a419 --- /dev/null +++ b/lang/cs/Source/REEF/reef-examples/HelloCLRBridge/handlers/HelloFailedTaskHandler.cs @@ -0,0 +1,67 @@ +/** + * 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.Driver.Task; +using Org.Apache.Reef.Utilities; +using Org.Apache.Reef.Tang.Annotations; +using System; +using System.Globalization; + +namespace Org.Apache.Reef.Examples.HelloCLRBridge +{ + public class HelloFailedTaskHandler : IObserver<IFailedTask> + { + [Inject] + public HelloFailedTaskHandler() + { + } + + public void OnNext(IFailedTask failedTask) + { + string errorMessage = string.Format( + CultureInfo.InvariantCulture, + "Task [{0}] has failed caused by [{1}], with message [{2}] and description [{3}]. The raw data for failure is [{4}].", + failedTask.Id, + failedTask.Reason.IsPresent() ? failedTask.Reason.Value : string.Empty, + failedTask.Message, + failedTask.Description.IsPresent() ? failedTask.Description.Value : string.Empty, + failedTask.Data.IsPresent() ? ByteUtilities.ByteArrarysToString(failedTask.Data.Value) : string.Empty); + + Console.WriteLine(errorMessage); + + if (failedTask.GetActiveContext().IsPresent()) + { + Console.WriteLine("Disposing the active context the failed task ran in."); + + // we must do something here: either close the context or resubmit a task to the active context + failedTask.GetActiveContext().Value.Dispose(); + } + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + } +}
