in src/HttpRequestHelper/HttpClientHelper.cs [193:257]
public async Task<bool> CreateGroup(UserInput userInputObj, KeyValuePair<string, List<string>> groupInformation, Dictionary<string, GroupPollResponse> GroupStatusMap)
{
userInputObj.LoggerObj.LogInformation($"Creating container for group {groupInformation.Key}");
HttpResponseMessage createResponse = await SendGroupCreationRequest(userInputObj, groupInformation);
if (createResponse == null)
throw new Exception($"Could not obtain a HTTP response for group {groupInformation.Key} creation.");
else if (!createResponse.IsSuccessStatusCode)
{
string createResponseContent = await createResponse.Content.ReadAsStringAsync();
throw new Exception($"HTTP create group response for {groupInformation.Key} was not successful: {createResponse.StatusCode}: {createResponseContent}");
}
else if (createResponse.StatusCode != HttpStatusCode.Created)
throw new Exception($"Received response: {createResponse.StatusCode} for group {groupInformation.Key} is not as expected: {HttpStatusCode.Created}");
userInputObj.LoggerObj.LogInformation($"Group {groupInformation.Key} container created");
userInputObj.LoggerObj.LogInformation($"Updating group {groupInformation.Key} with {groupInformation.Value.Count} machines");
GroupPollResponse pollResponse = GroupPollResponse.Invalid;
List<List<string>> updatedGroupMachines = UpdateTo5kMachinesPerRequest(userInputObj, groupInformation);
if (updatedGroupMachines.Count > 1)
{
userInputObj.LoggerObj.LogInformation($"Group {groupInformation.Key} has more than 5000 machines, will be updated in {updatedGroupMachines.Count} batches");
}
int index = 0;
foreach (var updatedMachine in updatedGroupMachines)
{
// Reset global variable
NumberOfTries = 0;
KeyValuePair<string, List<string>> groupInformationPerRequest = new KeyValuePair<string, List<string>>(groupInformation.Key, updatedMachine);
if (updatedGroupMachines.Count > 1)
{
userInputObj.LoggerObj.LogInformation($"Updating group {groupInformationPerRequest.Key} Batch {++index} with {updatedMachine.Count} machines");
}
HttpResponseMessage updateResponse = await SendMachineUpdationInGroupRequest(userInputObj, groupInformationPerRequest);
if (updateResponse == null)
throw new Exception($"Could not obtain a HTTP response for machine updation in group {groupInformationPerRequest.Key}");
else if (!updateResponse.IsSuccessStatusCode)
{
string updateResponseContent = await updateResponse.Content.ReadAsStringAsync();
throw new Exception($"HTTP update machines in group {groupInformationPerRequest.Key} response was not successful: {updateResponse.StatusCode}: {updateResponseContent}");
}
else if (updateResponse.StatusCode != HttpStatusCode.OK)
throw new Exception($"Received response: {updateResponse.StatusCode} for update machines in group {groupInformationPerRequest.Key} is not as expected: {HttpStatusCode.OK}");
pollResponse = WaitForGroupUpdateCompletion(userInputObj, groupInformation.Key);
if (pollResponse != GroupPollResponse.Completed)
{
userInputObj.LoggerObj.LogError($"Failed to update the group {groupInformation.Key} with machine batch {index - 1}, process will be terminated.");
return false;
}
}
GroupStatusMap[groupInformation.Key] = pollResponse;
userInputObj.LoggerObj.LogInformation($"Updated group {groupInformation.Key} with machines");
return true;
}