This repository was archived by the owner on Aug 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathElasticBroadcastClient.cs
More file actions
149 lines (133 loc) · 6.45 KB
/
ElasticBroadcastClient.cs
File metadata and controls
149 lines (133 loc) · 6.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
using System;
using System.Globalization;
using System.IO;
using Org.Apache.REEF.Driver;
using Org.Apache.REEF.Tang.Implementations.Configuration;
using Org.Apache.REEF.Tang.Implementations.Tang;
using Org.Apache.REEF.Tang.Interface;
using Org.Apache.REEF.Tang.Util;
using Org.Apache.REEF.Utilities.Logging;
using Org.Apache.REEF.Client.API;
using Org.Apache.REEF.Client.Local;
using Org.Apache.REEF.Client.Yarn;
using Org.Apache.REEF.Network.Elastic.Config;
using Org.Apache.REEF.Network.Elastic.Driver.Default;
namespace Org.Apache.REEF.Network.Examples.Client
{
internal class JobIdentifiers
{
public const string ElastiBroadcast = "ElasticBroadcast";
public const string ElastiBroadcastWithFailure = "ElasticBroadcastWithFailure";
}
public sealed class ElasticBroadcastClient<T> where T : DefaultElasticDriver
{
private const string Local = "local";
private const string Yarn = "yarn";
private const string DefaultRuntimeFolder = "REEF_LOCAL_RUNTIME";
private const string stage = "Broadcast";
public ElasticBroadcastClient(
bool runOnYarn,
int numTasks,
int startingPortNo,
int portRange,
string jobIdentifier)
{
string driverId = typeof(T).Name;
JobIdentifier = jobIdentifier;
IConfiguration driverConfig = TangFactory.GetTang()
.NewConfigurationBuilder(GetDriverConf())
.BindNamedParameter<ElasticServiceConfigurationOptions.NumEvaluators, int>(
GenericType<ElasticServiceConfigurationOptions.NumEvaluators>.Class,
numTasks.ToString(CultureInfo.InvariantCulture))
.BindNamedParameter<ElasticServiceConfigurationOptions.StartingPort, int>(
GenericType<ElasticServiceConfigurationOptions.StartingPort>.Class,
startingPortNo.ToString(CultureInfo.InvariantCulture))
.BindNamedParameter<ElasticServiceConfigurationOptions.PortRange, int>(
GenericType<ElasticServiceConfigurationOptions.PortRange>.Class,
portRange.ToString(CultureInfo.InvariantCulture))
.Build();
IConfiguration elsticGroupCommServiceDriverConfig = TangFactory.GetTang()
.NewConfigurationBuilder()
.BindStringNamedParam<ElasticServiceConfigurationOptions.DriverId>(driverId)
.BindStringNamedParam<ElasticServiceConfigurationOptions.DefaultStageName>(stage)
.BindIntNamedParam<ElasticServiceConfigurationOptions.NumberOfTasks>(
numTasks.ToString(CultureInfo.InvariantCulture))
.Build();
IConfiguration merged = Configurations
.Merge(driverConfig, elsticGroupCommServiceDriverConfig);
string runPlatform = runOnYarn ? "yarn" : "local";
TestRun(merged, typeof(T), numTasks, JobIdentifier, runPlatform);
}
private static void TestRun(
IConfiguration driverConfig,
Type globalAssemblyType,
int numberOfEvaluator,
string jobIdentifier = "myDriver",
string runOnYarn = "local",
string runtimeFolder = DefaultRuntimeFolder)
{
IInjector injector = TangFactory.GetTang()
.NewInjector(GetRuntimeConfiguration(runOnYarn, numberOfEvaluator, runtimeFolder));
var reefClient = injector.GetInstance<IREEFClient>();
var jobRequestBuilder = injector.GetInstance<JobRequestBuilder>();
var jobSubmission = jobRequestBuilder
.AddDriverConfiguration(driverConfig)
.AddGlobalAssemblyForType(globalAssemblyType)
.SetJobIdentifier(jobIdentifier)
.Build();
reefClient.SubmitAndGetJobStatus(jobSubmission);
}
private static IConfiguration GetRuntimeConfiguration(
string runOnYarn,
int numberOfEvaluator,
string runtimeFolder)
{
switch (runOnYarn)
{
case Local:
var dir = Path.Combine(".", runtimeFolder);
return LocalRuntimeClientConfiguration.ConfigurationModule
.Set(
LocalRuntimeClientConfiguration.NumberOfEvaluators,
numberOfEvaluator.ToString())
.Set(LocalRuntimeClientConfiguration.RuntimeFolder, dir)
.Build();
case Yarn:
return YARNClientConfiguration.ConfigurationModule.Build();
default:
throw new ArgumentException("Unknown runtime: " + runOnYarn);
}
}
private string JobIdentifier { get; set; }
private IConfiguration GetDriverConf()
{
return DriverConfiguration.ConfigurationModule
.Set(DriverConfiguration.OnDriverStarted, GenericType<T>.Class)
.Set(DriverConfiguration.OnEvaluatorAllocated, GenericType<T>.Class)
.Set(DriverConfiguration.OnEvaluatorFailed, GenericType<T>.Class)
.Set(DriverConfiguration.OnContextActive, GenericType<T>.Class)
.Set(DriverConfiguration.OnTaskRunning, GenericType<T>.Class)
.Set(DriverConfiguration.OnTaskCompleted, GenericType<T>.Class)
.Set(DriverConfiguration.OnTaskFailed, GenericType<T>.Class)
.Set(DriverConfiguration.OnTaskMessage, GenericType<T>.Class)
.Set(DriverConfiguration.CustomTraceLevel, Level.Info.ToString())
.Build();
}
}
}