private Task StartInfrastructureTaskAsyncHelper(InfrastructureTaskDescription description, TimeSpan timeout, CancellationToken cancellationToken) { return(Utility.WrapNativeAsyncInvokeInMTA( (callback) => this.StartInfrastructureTaskBeginWrapper(description, timeout, callback), this.StartInfrastructureTaskEndWrapper, cancellationToken, "InfrastructureServiceAgent.StartInfrastructureTaskAsync")); }
internal static InfrastructureTaskResultItem FromNative(NativeInfrastructureService.FABRIC_INFRASTRUCTURE_TASK_QUERY_RESULT_ITEM casted) { var managed = new InfrastructureTaskResultItem(); managed.Description = InfrastructureTaskDescription.FromNative(casted.Description); managed.State = FromNativeTaskState(casted.State); return(managed); }
public Task StartInfrastructureTaskAsync(InfrastructureTaskDescription description, TimeSpan timeout, CancellationToken cancellationToken) { return(Task.Factory.StartNew( () => { if (StartInfrastructureTaskAsyncAction != null) { StartInfrastructureTaskAsyncAction(description, timeout, cancellationToken); } else { DefaultStartInfrastructureTask(description, timeout, cancellationToken); } }, cancellationToken)); }
public static StartTaskCommand TryParseCommand(Guid partitionId, Queue <string> tokens) { if (tokens.Count <= 0) { Trace.WriteWarning(TraceType, "Command missing Task Id"); return(null); } string taskId = tokens.Dequeue(); if (tokens.Count <= 0) { Trace.WriteWarning(TraceType, "Command missing Task Timeout"); return(null); } var nodeTasks = new List <NodeTaskDescription>(); while (tokens.Count > 0) { var nodeTask = new NodeTaskDescription { NodeName = tokens.Dequeue() }; if (tokens.Count <= 0) { Trace.WriteWarning(TraceType, "Command missing Node Task Type"); return(null); } string command = tokens.Dequeue(); if (command == InfrastructureServiceCommand.RestartCommand) { nodeTask.TaskType = NodeTask.Restart; } else if (command == InfrastructureServiceCommand.RelocateCommand) { nodeTask.TaskType = NodeTask.Relocate; } else if (command == InfrastructureServiceCommand.RemoveCommand) { nodeTask.TaskType = NodeTask.Remove; } else { Trace.WriteWarning(TraceType, "Invalid Node Task Type '{0}'", command); return(null); } nodeTasks.Add(nodeTask); } var description = new InfrastructureTaskDescription( partitionId, taskId, DateTime.UtcNow.Ticks, new ReadOnlyCollection <NodeTaskDescription>(nodeTasks)); return(new StartTaskCommand(description)); }
public StartTaskCommand(InfrastructureTaskDescription description) { this.taskDescription = description; }
public static int OnVMRemove() { //step 1: create fabircClientLocal that connects to local node Logger.LogInfo(LogTag, "OnVMRemove: creating local FabricClient"); FabricClient fabircClientLocal = null; for (int i = 1; i <= 5; i++) { try { fabircClientLocal = new FabricClient(); } catch (Exception e) { if (i < 5) { Logger.LogInfo(LogTag, "creating local client throw execption: {0}. Retrying: {1}", e.ToString(), i); } } } if (fabircClientLocal == null) { return((int)ErrorCode.Unexpected); } //step 2: query nodes in the cluster that is up, and use them to create fabricClient that actually sends infraStructureService Command. var nodeResult = fabircClientLocal.QueryManager.GetNodeListAsync().Result; IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName()); string ipAddressLocal = (host.AddressList.First(ip => ip.AddressFamily == AddressFamily.InterNetwork)).ToString(); string localNodeName = ""; List <string> ipAddressesList = new List <string>(); for (int idx = 0; idx < nodeResult.Count; idx++) { if (nodeResult[idx].NodeStatus != NodeStatus.Up) { continue; } string[] result = nodeResult[idx].IpAddressOrFQDN.Split(':'); string IpAddressOrFQDN = result[0]; Logger.LogInfo(LogTag, "FQDN is {0}, ipAddressLocal is {1}, IpAddressOrFQDN is {2}", VMMNodeList.GetFQDN(), ipAddressLocal, IpAddressOrFQDN); if (VMMNodeList.GetFQDN().Equals(IpAddressOrFQDN, StringComparison.CurrentCultureIgnoreCase) || ipAddressLocal.Equals(IpAddressOrFQDN, StringComparison.CurrentCultureIgnoreCase)) { localNodeName = nodeResult[idx].NodeName; } else { Logger.LogInfo(LogTag, "node {0} address is {1}", idx, IpAddressOrFQDN); ipAddressesList.Add(IpAddressOrFQDN + ":19000"); //todo: query clientconnectionendpoints when available. } } Logger.LogInfo(LogTag, "localNodeName: {0}", localNodeName); string[] ipAddressesUp = new string[ipAddressesList.Count]; ipAddressesList.CopyTo(ipAddressesUp, 0); FabricClient fabricClient = null; for (int i = 1; i <= 5; i++) { try { fabricClient = new FabricClient(ipAddressesUp); } catch (Exception e) { if (i < 5) { Logger.LogInfo(LogTag, "creating client (connecting to cluster) throw execption: {0}. Retrying: {1}", e.ToString(), i); } } } if (fabricClient == null) { return((int)ErrorCode.Unexpected); } //step 3: send StartInfrastructureTask NodeTaskDescription nodeTaskDescription = new NodeTaskDescription(); nodeTaskDescription.NodeName = localNodeName; nodeTaskDescription.TaskType = NodeTask.Remove; string taskId = "remove" + localNodeName; Int64 instanceId = DateTime.Now.Ticks; List <NodeTaskDescription> nodeTasks = new List <NodeTaskDescription>(); nodeTasks.Add(nodeTaskDescription); ReadOnlyCollection <NodeTaskDescription> readonlyNodeTasks = new ReadOnlyCollection <NodeTaskDescription>(nodeTasks); InfrastructureTaskDescription infrastructureTaskDesp = new InfrastructureTaskDescription(taskId, instanceId, readonlyNodeTasks); bool taskCompleted = false; while (taskCompleted == false) { try { Task <bool> taskStart = fabricClient.ClusterManager.StartInfrastructureTaskAsync(infrastructureTaskDesp); taskCompleted = taskStart.Result; if (taskCompleted == false) { Logger.LogInfo(LogTag, "StartInfrastructureTaskAsync returned false, sleep for 3 second and retry"); System.Threading.Thread.Sleep(3000); } } catch (Exception e) { Logger.LogInfo(LogTag, "StartInfrastructureTaskAsync throw execption: {0}. Retrying...", e.ToString()); } } Logger.LogInfo(LogTag, "StartInfrastructureTaskAsync returned true"); //step 4: kill local fabric.exe by stoping fabrichostsvc ServiceController service = new ServiceController("FabricHostSvc"); try { TimeSpan timeout = TimeSpan.FromMilliseconds(10000); service.Stop(); service.WaitForStatus(ServiceControllerStatus.Stopped, timeout); } catch (Exception e) { Logger.LogInfo(LogTag, "failed to stop service with exception {0}", e.ToString()); } //step 5: send FinishInfrastructureTask taskCompleted = false; while (taskCompleted == false) { try { Task <bool> taskFinish = fabricClient.ClusterManager.FinishInfrastructureTaskAsync(taskId, instanceId); taskCompleted = taskFinish.Result; if (taskCompleted == false) { Logger.LogInfo(LogTag, "FinishInfrastructureTaskAsync returned false, sleep for 3 second and retry"); System.Threading.Thread.Sleep(3000); } } catch (Exception e) { Logger.LogInfo(LogTag, "StartInfrastructureTaskAsync throw execption: {0}. Retrying...", e.ToString()); } } Logger.LogInfo(LogTag, "FinishInfrastructureTaskAsync returned true"); return((int)ErrorCode.Success); }
private static void DefaultStartInfrastructureTask(InfrastructureTaskDescription description, TimeSpan timeout, CancellationToken cancellationToken) { }
public Task StartInfrastructureTaskAsync(InfrastructureTaskDescription description, TimeSpan timeout, CancellationToken cancellationToken) { return(agent.StartInfrastructureTaskAsync(description, timeout, cancellationToken)); }
public Task StartInfrastructureTaskAsync(InfrastructureTaskDescription description, TimeSpan timeout, CancellationToken cancellationToken) { Requires.Argument <InfrastructureTaskDescription>("description", description).NotNull(); return(this.StartInfrastructureTaskAsyncHelper(description, timeout, cancellationToken)); }
public Task StartInfrastructureTask(InfrastructureTaskDescription description) { return(this.StartInfrastructureTaskAsync(description, FabricInfrastructureServiceAgent.DefaultTimeout, CancellationToken.None)); }
private NativeCommon.IFabricAsyncOperationContext StartInfrastructureTaskBeginWrapper(InfrastructureTaskDescription description, TimeSpan timeout, NativeCommon.IFabricAsyncOperationCallback callback) { using (var pin = new PinCollection()) { return(this.nativeAgent.BeginStartInfrastructureTask( description.ToNative(pin), Utility.ToMilliseconds(timeout, "timeout"), callback)); } }
public Task StartInfrastructureTaskAsync(InfrastructureTaskDescription description, TimeSpan timeout, CancellationToken cancellationToken) { throw new NotImplementedException(); }