Following is an example. In my future post, I may write how to customize YARN Container Executor to execute your own logic to create application, for example, creating in-process application which runs inside Resource Manager process rather than a new process. Let's put that aside for now, and see how to submit application in C#.
Define JSON Classes for YARN REST API
YARN REST API supports JSON or XML request. Here we create several classes which are used to serialize JSON request. We use Newtonsoft JSON library.
#region Classes for JSON serialization
public class SubmitApplicationRequest
{
[JsonProperty("application-id")]
public string ApplicationId { get; set; }
[JsonProperty("application-name")]
public string ApplicationName { get; set; }
[JsonProperty("am-container-spec")]
public AMContainerSpec AMContainerSpec { get; set; }
[JsonProperty("unmanaged-AM")]
public string UnmanagedAM { get; set; }
[JsonProperty("max-app-attempts")]
public string MaxAppAttempts { get; set; }
[JsonProperty("resource")]
public Resource Resource { get; set; }
[JsonProperty("application-type")]
public string ApplicationType { get; set; }
[JsonProperty("keep-containers-across-application-attempts")]
public string KeepContainersAcrossApplicationAttempts { get; set; }
}
public class AMContainerSpec
{
[JsonProperty("local-resources")]
public LocalResources LocalResources { get; set; }
[JsonProperty("commands")]
public Commands Commands { get; set; }
}
public class LocalResources
{
[JsonProperty("entry")]
public LocalResourceEntry[] Entry { get; set; }
}
public class LocalResourceEntry
{
[JsonProperty("key")]
public string Key { get; set; }
[JsonProperty("value")]
public LocalResourceEntryValue Value { get; set; }
}
public class LocalResourceEntryValue
{
[JsonProperty("resource")]
public string Resource { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("visibility")]
public string Visibility { get; set; }
[JsonProperty("size")]
public string Size { get; set; }
[JsonProperty("timestamp")]
public string Timestamp { get; set; }
}
public class Commands
{
[JsonProperty("command")]
public string Command { get; set; }
}
public class Resource
{
[JsonProperty("memory")]
public string Memory { get; set; }
[JsonProperty("vCores")]
public string VCores { get; set; }
}
#endregion
Codes to Submit Application
The default REST service url is like http://localhost:8088/ws/v1/cluster/... It accepts POST or PUT on different APIs. We can use WebClient class in C# to either post data or put data to the server side.
Below are the sample code. It submit an application to launch notepad.exe.
class Program
{
public const string NewApplicationUrl = "http://localhost:8088/ws/v1/cluster/apps/new-application";
public const string SubmitApplicationUrl = "http://localhost:8088/ws/v1/cluster/apps";
public const string ApplicationStateUrl = "http://localhost:8088/ws/v1/cluster/apps/{0}/state";
static void Main(string[] args)
{
var submitApplicationRequest = new SubmitApplicationRequest()
{
ApplicationId = "", // will assign real application id later
ApplicationName = "TestApp",
AMContainerSpec = new AMContainerSpec()
{
Commands = new Commands()
{
Command = "notepad.exe"
}
},
UnmanagedAM = "false",
MaxAppAttempts = "2",
Resource = new Resource()
{
Memory = "1024",
VCores = "1"
},
ApplicationType = "YARN",
KeepContainersAcrossApplicationAttempts = "false"
};
using (WebClient client = new WebClient())
{
client.Headers[HttpRequestHeader.Accept] = "application/json";
client.Headers[HttpRequestHeader.ContentType] = "application/json";
byte[] responseBytes = client.UploadData(NewApplicationUrl, "POST", Encoding.UTF8.GetBytes(""));
string responseString = Encoding.UTF8.GetString(responseBytes);
Console.WriteLine(responseString);
var json = (JObject)JsonConvert.DeserializeObject(responseString);
var applicationId = (string)json["application-id"];
submitApplicationRequest.ApplicationId = applicationId;
string requestString = JsonConvert.SerializeObject(submitApplicationRequest);
client.Headers[HttpRequestHeader.Accept] = "application/json";
client.Headers[HttpRequestHeader.ContentType] = "application/json";
responseBytes = client.UploadData(SubmitApplicationUrl, "POST", Encoding.UTF8.GetBytes(requestString));
responseString = Encoding.UTF8.GetString(responseBytes);
Console.WriteLine(responseString);
}
}
}
10th result 2017, hsc result 2017, intermediate result 2017, sslc result 2017, ssc result 2017, 12th result 2017, http://www.resultsnic2017.in/ 2017, cbseresults.nic.in 2017
ReplyDeletecisce.org 2017, icse 10th result 2017, icse 12th result 2017, bseap.org 2017, ap 10th results 2017, ap intermediate results 2017, biharboard.ac.in 2017
ReplyDeletecgbse.nic.in 2017, cg board 10th result 2017, cgbse 12th result 2017, gseb.org 2017, gseb ssc result 2017, gujarat board 12th result 2017, goaresults.nic.in 2017
ReplyDeletebseh.org.in 2017, haryana board 10th result 2017, hbse 12th result 2017, hpresults.nic.in 2017, hp 10th result 2017, hpbose 12th result 2017, jkbose board 2017
ReplyDeletejharresults.nic.in 2017, jharkhand 10th result 2017, jharkhand intermediate result 2017, karresults.nic.in 2017, karnataka sslc results 2017, karnataka 2nd puc results 2017, keralaresults.nic.in 2017, kerala sslc result 2017
ReplyDeletempbse board 10th result 2017, mpbse 12th result 2017, mahresult.nic.in 2017, mah ssc result 2017, mah hsc result 2017, orissaresults.nic.in 2017, orissa 10th result 2017, orissa 12th class plus 2 result 2017
ReplyDeletewbresults.nic.in 2017, wb madhyamik result 2017, wb board hs result 2017, telangana results 2017, icse 10th result 2017, icse 12th result, 201710th results 2017, 12th results 2017
ReplyDeleteThat appears to be excellent however i am still not too sure that I like it. At any rate will look far more into it and decide personally!
ReplyDeleteHbse 10th result 2018
I enjoyed over read your blog post. Your blog have nice information, I got good ideas from this amazing blog. I am always searching like this type blog post. I hope I will see again...
ReplyDeleteIPEM is one of the Best MCA Institutes in Ghaziabad. To know more just visit : http://www.ipemgzb.ac.in
Best law college in ghaziabad
top BCA college in ghaziabad
Best BCA college in ghaziabad
1 No BCA college in ghaziabad
top 10 BCA college in ghaziabad
list of top bca colleges in gzb
Best BCA Institutes in Ghaziabad
top 10 BCA college in Noida
PGDM college in Delh NCR
best bca college in delhi
top BCA college in NCR
BBA college in NCR
BBA college in ghaziabad
Best BBA college in ghaziabad
Best BBA college in Noida
BBA college in Delhi Ncr
MBA college in ghaziabad
MBA college in Delhi
Top MBA college in NCR
Top MBA college in Noida
Best MBA college in ghaziabad
PGDM college in ghaziabad
Top PGDM college in ghaziabad
Best PGDM college in ghaziabad
PGDM college in Noida
PGDM college in Delh NCR
MCA college in ghaziabad
MCA institute in Ghaziabad
Top MCA institute in Ghaziabad
Best mca college in ghaziabad
Best mca college in india
Top mca college in ghaziabad
Top 10 mca college in ghaziabad
Top mca college in delhi
MCA college in NCR
Top mca placements college in gzb
List of top mca colleges in gzb