fix triggertransport
This commit is contained in:
Родитель
c30ab3e368
Коммит
7141a805d7
|
@ -55,10 +55,10 @@ namespace PerformanceTests.Transport
|
|||
try
|
||||
{
|
||||
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
|
||||
string[] hosts = JsonConvert.DeserializeObject<string[]>(requestBody);
|
||||
var placement = JsonConvert.DeserializeObject<Placement>(requestBody);
|
||||
//TriggerTransport transport = ((TriggerTransportFactory)transportFactory).Instance;
|
||||
TriggerTransport transport = TriggerTransportFactory.Instance;
|
||||
await transport.StartLocalAsync(hosts, index);
|
||||
await transport.StartLocalAsync(placement.Hosts, placement.Clients, index);
|
||||
return new OkResult();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -7,35 +7,21 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
class Placement
|
||||
public class Placement
|
||||
{
|
||||
string[] hosts;
|
||||
readonly Dictionary<Guid, string> clients;
|
||||
public string[] Hosts { get; set; }
|
||||
|
||||
public Placement()
|
||||
{
|
||||
this.clients = new Dictionary<Guid, string>();
|
||||
}
|
||||
|
||||
public void SetHosts(string[] hosts)
|
||||
{
|
||||
this.hosts = hosts;
|
||||
}
|
||||
|
||||
public void SetClientLocation(Guid clientId, int index)
|
||||
{
|
||||
this.clients[clientId] = this.hosts[index];
|
||||
}
|
||||
|
||||
public IList<string> Hosts => this.hosts;
|
||||
public IEnumerable<Guid> Clients => this.clients.Keys;
|
||||
public Dictionary<Guid, string> Clients { get; set; } = new Dictionary<Guid, string>();
|
||||
|
||||
public string PartitionHost(int partitionId)
|
||||
=> this.hosts[partitionId % this.hosts.Length];
|
||||
=> this.Hosts[partitionId % this.Hosts.Length];
|
||||
|
||||
public string LoadMonitorHost()
|
||||
=> this.hosts[0];
|
||||
=> this.Hosts[0];
|
||||
|
||||
public string ClientHost(Guid clientId)
|
||||
=> this.clients[clientId];
|
||||
=> this.Clients[clientId];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,10 +54,10 @@
|
|||
return Guid.Parse((string) responseJson.GetValue("clientId"));
|
||||
}
|
||||
|
||||
public async Task StartLocalAsync(string[] hosts, int index)
|
||||
public async Task StartLocalAsync(Placement placement, int index)
|
||||
{
|
||||
string hostUri = this.placement.PartitionHost(index);
|
||||
string content = JsonConvert.SerializeObject(hosts);
|
||||
string content = JsonConvert.SerializeObject(placement);
|
||||
var response = await this.client.PostAsync($"{hostUri}/triggertransport/startlocal/{index}", new StringContent(content));
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
|
||||
public async Task StartAllAsync(string[] hosts)
|
||||
{
|
||||
this.placement.SetHosts(hosts);
|
||||
this.placement.Hosts = hosts;
|
||||
{
|
||||
var tasks = new List<Task<Guid>>();
|
||||
for (int i = 0; i < hosts.Length; i++)
|
||||
|
@ -74,31 +74,33 @@
|
|||
await Task.WhenAll(tasks);
|
||||
for (int i = 0; i < hosts.Length; i++)
|
||||
{
|
||||
this.placement.SetClientLocation(tasks[i].Result, i);
|
||||
this.placement.Clients[tasks[i].Result] = this.placement.Hosts[i];
|
||||
}
|
||||
}
|
||||
{
|
||||
var tasks = new List<Task>();
|
||||
for (int i = 0; i < hosts.Length; i++)
|
||||
{
|
||||
tasks.Add(this.httpClient.StartLocalAsync(hosts, i));
|
||||
tasks.Add(this.httpClient.StartLocalAsync(this.placement, i));
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task StartLocalAsync(string[] hosts, int index)
|
||||
public async Task StartLocalAsync(string[] hosts, Dictionary<Guid,string> clients, int index)
|
||||
{
|
||||
this.placement.SetHosts(hosts);
|
||||
this.placement.Hosts = hosts;
|
||||
this.placement.Clients = clients;
|
||||
|
||||
var tasks = new List<Task>();
|
||||
for (int partitionId = 0; partitionId < this.Parameters.PartitionCount; partitionId++)
|
||||
{
|
||||
if (this.placement.PartitionHost(partitionId) == hosts[index])
|
||||
if (this.placement.PartitionHost(partitionId) == this.placement.Hosts[index])
|
||||
{
|
||||
tasks.Add(this.StartPartitionAsync(partitionId));
|
||||
}
|
||||
}
|
||||
if (this.placement.LoadMonitorHost() == hosts[index])
|
||||
if (this.placement.LoadMonitorHost() == this.placement.Hosts[index])
|
||||
{
|
||||
tasks.Add(this.StartLoadMonitorAsync());
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче