/// <summary> /// RequestMaintenance:[RoleInstanceName]:[RepairActionTypeEnum][:optional Reason] /// E.g. /// RequestMaintenance:ServiceFabricRole_IN_2:Reboot:mitigating_incident_123456 /// </summary> private async Task <string> HandleCommandRequestMaintenanceAsync(string args) { traceType.WriteInfo("Requesting maintenance. Input: {0}", args); string[] tokens = args.Split(CommandTokenDelimiter, 3); if (tokens.Length < 2) { throw new ArgumentException("Invalid command arguments"); } string roleInstanceName = tokens[0]; RepairActionTypeEnum action; if (!Enum.TryParse(tokens[1], out action)) { throw new ArgumentException("Invalid command arguments"); } var activityId = Guid.NewGuid(); // Bond doesn't like a null value for RepairRequest.Reason string reason = tokens.Length >= 3 ? reason = tokens[2] : string.Empty; try { var repairRequest = new RepairRequest { RoleInstanceId = roleInstanceName, ContextId = activityId.ToString(), Action = action, Reason = reason }; string requestJson = repairRequest.ToJson(); traceType.WriteInfo("Requesting maintenance. {0}", requestJson); await policyAgentClient.RequestRepairAsync(activityId, repairRequest, CancellationToken.None).ConfigureAwait(false); traceType.WriteInfo("Successfully requested maintenance. {0}", requestJson); return(requestJson); } catch (ManagementException) { traceType.WriteWarning( "Error in management protocol while requesting maintenance of role instance: {0} with action: {1} and reason: {2}", roleInstanceName, action, reason); throw; } }