public NodeTracker(IOperationTracker operationTracker, IReadOnlyList <string> nodes) { _operationTracker = operationTracker; _nodes = nodes; _operationTrackers = new Dictionary <string, OperationTracker>(); _syncRoot = new object(); }
/// <summary> /// /// </summary> /// <param name="consoleWriter"></param> /// <param name="scriptFilePath"></param> /// <returns></returns> public static ExitCode ListEntryPoints(IOperationTracker consoleWriter, string scriptFilePath) { var script = LoadAndCompileScript(consoleWriter, scriptFilePath); var runMethods = FindMethods(script, RunEntryPointName); var deployMethods = FindMethods(script, DeployEntryPointName); if (runMethods.Any()) { Console.WriteLine("Found {0} 'run' entry points:", runMethods.Count); foreach (var method in runMethods) { Console.WriteLine("\t{0}", FormatMethod(method)); } } if (deployMethods.Any()) { Console.WriteLine("Found {0} 'deploy' entry points:", deployMethods.Count); foreach (var method in deployMethods) { Console.WriteLine("\t{0}", FormatMethod(method)); } } if (runMethods.Count == 0 && deployMethods.Count == 0) { Console.WriteLine("The script doesn't contain any entry point"); } return(ExitCode.Success); }
private static int Deploy(object script, IOperationTracker operationTracker, IReadOnlyList <string> nodeAddresses, IEnumerable <string> arguments, TimeSpan connectTimeout) { var method = FindDeployMethod(script); if (nodeAddresses.Count == 1) { return(DeployTo(script, method, operationTracker, nodeAddresses[0], arguments, connectTimeout)); } var tracker = new NodeTracker(operationTracker, nodeAddresses); Parallel.ForEach(nodeAddresses, nodeAddress => { var nodeTracker = tracker.Get(nodeAddress); try { DeployTo(script, method, nodeTracker, nodeAddress, arguments, connectTimeout); nodeTracker.Success(); } catch (Exception e) { // We want keep track of failures on individual nodes // and only rethrow those exceptions after everything's done. nodeTracker.Failed(e); } }); tracker.ThrowOnFailure(); return(0); }
protected DomainEventSourcedActor(IConstructAggregates aggregateConstructor, IConstructSnapshots snapshotsConstructor, ISnapshotsPersistencePolicy policy) { _snapshotsConstructor = snapshotsConstructor; _snapshotsPolicy = policy; _snapshotsSaveTracker = (policy as ISnapshotsSavePolicy).Tracking; _snapshotsDeleteTracker = (policy as ISnapshotsDeletePolicy).Tracking; PersistenceId = Self.Path.Name; Id = EntityActorName.Parse <T>(Self.Path.Name).Id; State = (T)aggregateConstructor.Build(typeof(T), Id, null); Monitor = new ActorMonitor(Context, typeof(T).Name); Behavior = new BehaviorQueue(Become); DefaultBehavior(); Recover <DomainEvent>(e => State.Apply(e)); Recover <SnapshotOffer>(offer => { _snapshotsPolicy.MarkSnapshotApplied(offer.Metadata.SequenceNr); State = (T)aggregateConstructor.Build(typeof(T), Id, (IMemento)offer.Snapshot); Log.Debug("Built state from snapshot #{snapshotNum}", offer.Metadata.SequenceNr); }); Recover <RecoveryCompleted>(message => { Log.Debug("Recovery completed"); NotifyPersistenceWatchers(message); }); }
public virtual FluentOperationsConfigurator With([NotNull] IOperationTracker tracker) { if (tracker == null) { throw new ArgumentNullException(nameof(tracker)); } _addTracker(tracker); return(_configurator); }
/// <summary> /// Executes the given script's Run(string[]) method. /// </summary> /// <param name="operationTracker"></param> /// <param name="scriptFilePath"></param> /// <param name="scriptArguments"></param> /// <returns></returns> public static int Run(IOperationTracker operationTracker, string scriptFilePath, IReadOnlyList <string> scriptArguments) { var script = LoadAndCompileScript(operationTracker, scriptFilePath); Log.InfoFormat("Executing '{0}'...", scriptFilePath); var exitCode = RunPrivate(operationTracker, script, scriptArguments); Log.InfoFormat("'{0}' returned '{1}'", scriptFilePath, exitCode); return(exitCode); }
private async Task <ActionResult <string> > HandleGetAsync(int id, IOperationTracker tracker) { if (tracker == null) { tracker = _contextAccessor.OperationTracker ?? tracker; } _contextAccessor.MetricsContext.AddTag("test", "tag"); tracker.SetSuccess("testing"); await Task.Delay(500); return("value"); }
protected AbstractNode(IOperationTracker operationTracker, IFiles files, IShell shell, IServices services, IProcesses processes, IRegistry registry) { _operationTracker = operationTracker; _files = files; _shell = shell; _services = services; _processes = processes; _registry = registry; }
public static RemoteNode Create(IOperationTracker operationTracker, IPEndPoint endPoint) { var operation = operationTracker.BeginConnect(endPoint.ToString()); try { var node = CreatePrivate(operationTracker, endPoint); operation.Success(); return(node); } catch (Exception e) { operation.Failed(e); throw; } }
/// <summary> /// Executes the given script's Deploy(INode) method. /// </summary> /// <param name="operationTracker"></param> /// <param name="scriptFilePath"></param> /// <param name="nodeAddresses"></param> /// <param name="arguments"></param> /// <param name="connectTimeout"></param> /// <returns></returns> public static int Deploy(IOperationTracker operationTracker, string scriptFilePath, IReadOnlyList <string> nodeAddresses, IEnumerable <string> arguments, TimeSpan connectTimeout) { var script = LoadAndCompileScript(operationTracker, scriptFilePath); Log.InfoFormat("Executing '{0}'...", scriptFilePath); var exitCode = Deploy(script, operationTracker, nodeAddresses, arguments, connectTimeout); Log.InfoFormat("'{0}' returned '{1}'", scriptFilePath, exitCode); return(exitCode); }
private RemoteNode(IOperationTracker operationTracker, SocketEndPoint socket, string remoteMachineName) : base(operationTracker, new FilesWrapper(socket.GetExistingOrCreateNewProxy <IFiles>(ObjectIds.File), remoteMachineName), new ShellWrapper(socket.GetExistingOrCreateNewProxy <IShell>(ObjectIds.Shell), remoteMachineName), new ServicesWrapper(socket.GetExistingOrCreateNewProxy <IServices>(ObjectIds.Services), remoteMachineName), new ProcessesWrapper(socket.GetExistingOrCreateNewProxy <IProcesses>(ObjectIds.Processes), remoteMachineName), new RegistryWrapper(socket.GetExistingOrCreateNewProxy <IRegistry>(ObjectIds.Registry), remoteMachineName)) { _operationTracker = operationTracker; _socket = socket; ThrowIfIncompatible(socket); _files = new FilesWrapper(_socket.GetExistingOrCreateNewProxy <IFiles>(ObjectIds.File), remoteMachineName); _network = new NetworkWrapper(_socket.GetExistingOrCreateNewProxy <INetwork>(ObjectIds.Network), remoteMachineName); }
private static RemoteNode CreatePrivate(IOperationTracker operationTracker, IPEndPoint endPoint) { var socket = new SocketEndPoint(EndPointType.Client, "Distributor", clientAuthenticator: MachineNameAuthenticator.CreateClient(), heartbeatSettings: new HeartbeatSettings { AllowRemoteHeartbeatDisable = true }); try { socket.Connect(endPoint); return(new RemoteNode(operationTracker, socket, endPoint.ToString())); } catch (Exception) { socket.Dispose(); throw; } }
private static string LoadAndPreprocessScript(IOperationTracker operationTracker, string scriptFilePath) { Log.InfoFormat("Loading '{0}'...", scriptFilePath); var operation = operationTracker.BeginLoadScript(scriptFilePath); string script; try { using (var taskScheduler = new DefaultTaskScheduler()) { var filesystem = new Filesystem(taskScheduler); var processor = new ScriptPreprocessor(filesystem); script = processor.ProcessFile(scriptFilePath, new string[0]); } operation.Success(); } catch (AggregateException e) { var exceptions = Unpack(e); if (exceptions.Count == 1) { var exception = exceptions.First(); operation.Failed(exception); throw exception; } operation.Failed(e); throw; } catch (Exception e) { operation.Failed(e); throw; } return(script); }
private static int DeployTo(object script, MethodInfo method, IOperationTracker operationTracker, string nodeAddress, IEnumerable <string> arguments, TimeSpan connectTimeout) { Log.InfoFormat("Executing '{0}' for '{1}'", method, nodeAddress); using (var taskScheduler = new DefaultTaskScheduler()) { var filesystem = new Filesystem(taskScheduler); using (var distributor = new Distributor(operationTracker)) using (var localNode = new LocalNode(operationTracker, filesystem)) using (var remoteNode = distributor.ConnectTo(nodeAddress, connectTimeout)) { var args = new List <object>(); var parameters = method.GetParameters(); if (parameters[0].ParameterType == typeof(INode) && parameters.Length >= 2 && parameters[1].ParameterType == typeof(INode)) { args.Add(localNode); } args.Add(remoteNode); if (parameters[parameters.Length - 1].ParameterType == typeof(string[])) { args.Add(arguments); } var ret = InvokeMethod(script, method, args.ToArray()); if (method.ReturnType == typeof(int)) { return((int)ret); } return(0); } } }
public static RemoteNode Create(IOperationTracker operationTracker, string address, TimeSpan connectTimeout) { var operation = operationTracker.BeginConnect(address); try { var node = CreatePrivate(operationTracker, address, connectTimeout); operation.Success(); return(node); } catch (SharpRemoteException e) { operation.Failed(e); throw new NotConnectedException(e); } catch (Exception e) { operation.Failed(e); throw; } }
private static object CompileScript(IOperationTracker operationTracker, string scriptFilePath, string script) { Log.InfoFormat("Compiling '{0}'...", scriptFilePath); var evaluator = CSScript.Evaluator; evaluator.ReferenceAssembly(typeof(INode).Assembly); var operation = operationTracker.BeginCompileScript(scriptFilePath); try { var tmp = evaluator.LoadCode(script); operation.Success(); return(tmp); } catch (CompilerException e) { var tmp = new ScriptCompilationException(scriptFilePath, e); operation.Failed(e); throw tmp; } }
private static int RunPrivate(IOperationTracker operationTracker, object script, IReadOnlyList <string> args) { var method = FindMethod(script, RunEntryPointName); if (method == null) { throw new ScriptExecutionException($"The script is missing a main entry point"); } using (var taskScheduler = new DefaultTaskScheduler()) { var filesystem = new Filesystem(taskScheduler); using (var node = new LocalNode(operationTracker, filesystem)) { var parameters = method.GetParameters(); var scriptArguments = new List <object>(); if (parameters.Length > 1 && parameters[0].ParameterType == typeof(INode)) { scriptArguments.Add(node); } scriptArguments.Add(args); if (method.ReturnType == typeof(void)) { InvokeMethod(script, method, scriptArguments); return(0); } if (method.ReturnType == typeof(int)) { return((int)InvokeMethod(script, method, scriptArguments)); } } } throw new ScriptExecutionException($"Expected main entry point to either return no value or to return an Int32, but found: {method.ReturnType.Name}"); }
public LocalNode(IOperationTracker operationTracker, IFilesystem filesystem) : base(operationTracker, new Files(filesystem), new Shell(), new Services(), new Processes(), new Registry()) { _operationTracker = operationTracker; _filesystem = filesystem; }
public Distributor(IOperationTracker operationTracker) { _operationTracker = operationTracker; _clients = new List <RemoteNode>(); }
public OperationGrouper(IOperationTracker tracker) { _tracker = tracker; }
private async Task <T> ExecuteAsync <T>(Func <IOperationTracker, Task <T> > asyncOperation, IOperationTracker tracker) { try { var result = await asyncOperation(tracker); if (string.IsNullOrWhiteSpace(tracker.Result)) { tracker.SetSuccess(); } return(result); } catch (Exception ex) { tracker.Tags.Add($"exception:{ex.GetType().Name}"); if (string.IsNullOrWhiteSpace(tracker.Result)) { tracker.SetFailure("exception"); } throw; } }
private static object LoadAndCompileScript(IOperationTracker operationTracker, string scriptFilePath) { var script = LoadAndPreprocessScript(operationTracker, scriptFilePath); return(CompileScript(operationTracker, scriptFilePath, script)); }